(function e$$0(ga,xa,K){function w(ya,e){if(!xa[ya]){if(!ga[ya]){var M="function"==typeof require&&require;if(!e&&M)return M(ya,!0);if(s)return s(ya,!0);throw Error("Cannot find module '"+ya+"'");}M=xa[ya]={exports:{}};ga[ya][0].call(M.exports,function(e){var s=ga[ya][1][e];return w(s?s:e)},M,M.exports,e$$0,ga,xa,K)}return xa[ya].exports}for(var s="function"==typeof require&&require,P=0;P<K.length;P++)w(K[P]);return w})({1:[function(R,ga,xa){(function(){if(!nrdp.js){nrdp.js={};nrdjs={debug:!0};nrdp.js.setDebug=
function(s){nrdjs.debug=s};setTimeout=function(s,e){return nrdp.gibbon.setTimeout(s,e||0)};clearTimeout=function(s){nrdp.gibbon.clearTimeout(s)};setInterval=function(s,e){return nrdp.gibbon.setTimeout(s,e||0,!1)};clearInterval=function(s){nrdp.gibbon.clearTimeout(s)};var K=nrdp.utf8toa,w=R("nf_promise"),s=R("nf_underscore"),P=R("nf_console")(nrdp.log,"NRDJS",{utf8toa:nrdp.utf8toa});(function(){function s(e,K){return w.attempt(function(){var s=K.length;if(s)return M.log("Running "+s+" "+e+" hook(s)"),
w.resolve(K.map(function(s){var K=s[0],ba=s[1],P;return w.attempt(function(){M.log("Starting "+e+' hook "'+K+'"');P=nrdp.mono();return ba()}).then(function(){M.log("Finished "+e+' hook "'+K+'" ('+(nrdp.mono()-P)+"ms)")},function(e){M.error('Hook "'+K+'" failed : '+e+"\n"+e.stack);throw e;})})).all().then(function(){M.log("Finished running "+s+" "+e+" hook(s)")})})}function e(e){var w=nrdp.instrumentation,P=w.SWITCHED;w.generateEvent(P,"nrdjs.init");nrdp.js.options=nrdp.options.js_opts.split(",").reduce(function(e,
s){var w=s.split("="),y=w.shift(),w=w.join("=")||!0;y.length&&("true"===w?w=!0:"false"===w&&(w=!1),e[y]=w);return e},{});nrdp.js.setDebug(nrdp.debug||nrdp.js.options.debug);nrdp.nrdjs&&M.warn("NRDJS version "+nrdp.nrdjs+" loaded.");w.startInterval(P,"nrdjs.init-hooks");s("init",K).fin(function(){K=void 0;w.endInterval(P,"nrdjs.init-hooks")}).then(function(){nrdp.js.init=function(e){e&&e()};w.startInterval(P,"nrdjs.forward-init");e&&e();w.endInterval(P,"nrdjs.forward-init");w.startInterval(P,"nrdjs.post-init-hooks");
s("post-init",R).fin(function(){R=void 0;w.endInterval(P,"nrdjs.post-init-hooks")})},function(e){var s={ERROR_CATEGORY:"AppBoot",ERROR_FRAME_URL:nrdp.gibbon.location,ERROR_ACTIONID:"",ERROR_STAGE:2},w="http://localcontrol.netflix.com/js/error.js",y="?",K,c;for(K in s)c=s[K],"string"===typeof c&&(c=c.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,'\\"')),w+=y+K+"="+encodeURIComponent(c),y="&";M.error("Something went very wrong running NRDJS init hooks : "+e.toString());nrdp.gibbon.location=
w}).done()}var M=new P,K=[],R=[];nrdp.js.init=e;nrdp.js.addInitHook=function(e,s){if(!K)throw Error("Cannot add init hooks after they have run");K.push([e,s]);M.log('Added init hook "'+e+'", have '+K.length)};nrdp.js.addPostInitHook=function(e,s){if(!R)throw Error("Cannot add post-init hooks after they have run");R.push([e,s]);M.log('Added post-init hook "'+e+'", have '+R.length)};nrdp.hookInit(e)})();(function(){function ya(){function R(){if(!V&&!nrdp.storage.transientData){var a=nrdp.device,c={appid:nrdp.log.appid,
nrdlib_version:""+a.SDKVersion.components.nrdlib,nrdapp_version:""+a.SDKVersion.components.nrdapp,mdxlib_version:""+a.SDKVersion.components.mdxlib,sdk_version:""+a.SDKVersion.components.sdk},a=a.startupTags;if(s.isObject(a))for(var f in a)a.hasOwnProperty(f)&&(c[f]=a[f]);nrdp.log.info(void 0,"BOOT","startup",c,!0,!0)}}function c(a){var c=Fa||nrdp.options.appboot_url||Sa.appboot.url;"/"!=c[c.length-1]&&(c+="/");a&&(c+=escape(nrdp.device.ESNPrefix));return c}function f(a){var c=nrdp.storage;a&&(Fa=
a);V++;c.removeItem(c.NO_DEVICE_ACCOUNT,ja);V<=Sa.appboot.maxRetries?nrdp.gibbon.setTimeout(ya,1E3*V):(a=da.ERROR_DESCRIPTION,da.ERROR_DESCRIPTION=a?"Retry Count Exceeded, last error: "+a:"Retry Count Exceeded",da.ERROR_STAGE=0,xa())}function a(a){var c,f={},e=nrdp.js.options.appboot_extra_params;f.url=a.url;if(!f.url)throw Error('"ui" element is missing "url"');nrdp.options.ui_url?f.url=nrdp.options.ui_url:(c=a.hashvalue||"",a=a.hashalgorithm||"",0!==c.length&&0!==a.length&&"xasfa43r23552"!=c&&(f.headers=
{"X-Gibbon-Hash":a+"="+c}));e&&(f.url+=(0<f.url.indexOf("?")?"&":"?")+decodeURIComponent(e));return f}function xa(){V=0;var a="error.js",f="?",e,N;N=nrdp.storage;var J;71680>nrdp.storage.size&&(J=N.getItem(N.NO_DEVICE_ACCOUNT,"AppbootErrors")||[],J.push({description:da.ERROR_DESCRIPTION,stage:da.ERROR_STAGE,appid:nrdp.log.appid,clienttime:Date().toString(),url:c(!0),device:JSON.stringify(nrdp.device._syncData),options:JSON.stringify(nrdp.options)}),N.setItem(N.NO_DEVICE_ACCOUNT,"AppbootErrors",J));
da.ERROR_DESCRIPTION="Error loading UI";for(e in da)N=da[e],s.isString(N)&&(N=N.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,'\\"').replace(/\n/g,"\\n")),a+=f+e+"="+encodeURIComponent(N),f="&";nrdp.gibbon.loadScript({url:a})}var da={ERROR_CATEGORY:"AppBoot",ERROR_FRAME_URL:"",ERROR_DESCRIPTION:"",ERROR_STATUS_CODE:"",ERROR_GROUP:"",ERROR_CODE:"",ERROR_URL:"",ERROR_ACTIONID:"",ERROR_TEXT:"",ERROR_BCP47:"",ERROR_STAGE:""},fa,ea=new P("BOOT"),Sa={msl:{verifyServer:!0},appboot:{maxRetries:5}},
Wa,Xa=[];w.attempt(function(){da.ERROR_STAGE=1;return nrdp.isReady?void 0:new w(function(a){nrdp.addEventListener("init",a);nrdp.init()})}).then(function(){var c=nrdp.storage;nrdp.gibbon._loadSplash(c.getItem("s",ga));var f=c.getItem("s",ba);f&&(fa=a(f),ea.trace("beginning speculative download of "+fa.url),nrdp.gibbon.load({url:fa.url,headers:fa.headers,format:"arraybuffer"},function(a){ea.trace("speculative download status code is "+a.statusCode);fa.finalURL=a.finalURL;200==a.statusCode&&(fa.data=
a.data);fa.setLocation&&(ea.info("now really setting location to speculatively downloaded data"),nrdp.gibbon.location={url:fa.finalURL,headers:fa.headers,source:fa.data,reuse:!0});fa.finished=!0}));f=nrdp.js.options;da.ERROR_STAGE++;da.ERROR_FRAME_URL=nrdp.gibbon.location;f.hasOwnProperty("noverify")&&(Sa.msl.verifyServer=!f.noverify);Sa.msl.unauth=f.unauth;try{delete c.transientData.appboot.msltruststore,ea.trace("Deleted previous MSL trust store")}catch(s){ea.trace("No previous MSL trust store")}R();
c=new w(function(a){nrdp.log.addEventListener("criticalMsgsReady",function S(c){nrdp.log.removeEventListener("criticalMsgsReady",S);Wa=c.data;ea.trace("Got "+Wa.length+" critical messages");a()});nrdp.log.getCriticalMessages()});return[e(Sa),c]}).all().spread(function(a){da.ERROR_STAGE++;var f=nrdp.device,e=nrdp.options,s=nrdp.storage,J=c(!0),w=!!J.match(/^https:/),y,K=f.UILanguages,P={aid:nrdp.log.appid,client_info:{certification_version:""+f.certificationVersion,nrdlib_version:""+f.SDKVersion.components.nrdlib,
nrdapp_version:""+f.SDKVersion.components.nrdapp,mdxlib_version:""+f.SDKVersion.components.mdxlib,sdk_version:""+f.SDKVersion.components.nrdlib,sw_version:""+f.softwareVersion,languages:0>K.indexOf(f.language)?K.concat(f.language):K},ui:{app:"gibbontvui",query_params:{dw:""+e.ui_width,dh:""+e.ui_height,dar:""+e.ui_aspect_ratio,reg:""+f.registered,q:""+nrdp.uiQueryString}}};0<nrdp.gibbon.location.indexOf("?")&&nrdp.gibbon.location.replace(/[^?]*\?/,"").split("&").forEach(function(a){a&&(a=a.split("="),
P.ui.query_params[a[0]]=1<a.length?decodeURIComponent(a[1]):!0)});e.appboot_params.split(/[&,]/).forEach(function(a){a&&(a=a.split("="),P.ui.query_params[a[0]]=1<a.length?decodeURIComponent(a[1]):!0)});P.ui.cookies=nrdp.gibbon.cookie.split("; ").map(function(a){return a.split("=")}).reduce(function(a,c){a[c[0]]=c[1];return a},{});e=nrdp.trustStoreHash||"";P.ssltruststore=0===e.length?{}:{hash:e};P.msltruststore={};y=[];var M=nrdp.device.SDKVersion.components.platform,w={level:"info",type:"appboot",
esn:f.ESN,appid:nrdp.log.appid,msg:"appboot request made "+(w?"with":"without")+" SSL",ssl:w,clienttime:Date().toString(),app_uptime:""+(nrdp.mono()-nrdp.started),retrycount:V};if(M)for(var Y in M)"string"===typeof Y&&"string"===typeof M[Y]&&(w[Y]=M[Y]);y.push(w);(s.getItem(s.NO_DEVICE_ACCOUNT,"AppbootErrors")||[]).forEach(function(a){a={level:"error",type:"networkerror",esn:f.ESN,appid:a.appid,msg:"Appboot displayed BIEP",description:a.description,stage:a.stage,clienttime:a.clienttime,url:a.url,
device:a.device,options:a.options};if(M)for(var c in M)"string"===typeof c&&"string"===typeof M[c]&&(a[c]=M[c]);y.push(a)});Wa.forEach(function(a){if(!0==a.sendtoappboot){ea.log("Adding critical message to appboot logblob");if(M)for(var c in M)"string"!==typeof c||"string"!==typeof M[c]||a[c]||(a[c]=M[c]);y.push(a);Xa.push(a)}});ea.log("criticalmessage length "+Wa.length);P.log=y;P.responseparams="loglevel retrycontrol loginterval maxlogsize testdriveripaddr instrumentationparams".split(" ");ea.log("Sending AppBoot request to "+
J+"\n"+JSON.stringify(P,null," "));s=s.getItem(s.NO_DEVICE_ACCOUNT,ja)||null;ea.log("making appboot request with userId "+s);return a.request(J,s,JSON.stringify(P),2E4)}).then(function(c){da.ERROR_STAGE++;var e;e=nrdp.storage;var y=e.transientData||{};c=JSON.parse(K(c.body));ea.log("AppBoot response is\n"+JSON.stringify(c,null," "));y.appboot=c;e.transientData=y;e.removeItem(e.NO_DEVICE_ACCOUNT,"AppbootErrors");nrdp.log.deleteCriticalMessages(Xa);Wa=[];Xa=[];if(e=c.error)switch(e.actionid){case 7:da.ERROR_DESCRIPTION=
"toplevel: Redirect to "+e.appbootendpoint;f(e.appbootendpoint);break;case 2:da.ERROR_DESCRIPTION="toplevel: Error 2";f();break;case 13:nrdp.device.factoryReset(function(){nrdp.log.error("appboot factory reset device due to actionid 13","BOOT","appboot",void 0,!0,!0);nrdp.gibbon.location=nrdp.bootURL});break;default:throw da.ERROR_ACTIONID=e.actionid,e.usertextgroup&&(da.ERROR_TEXT=e.usertextgroup.text,da.ERROR_BCP47=e.usertextgroup.bcp47),Error("AID "+e.actionid);}else return w.attempt(function(){var a=
c.servertime_seconds,f=Math.floor(nrdp.now()/1E3),e=Math.floor(Date.now()/1E3);s.isNumber(a)&&(ea.info("AppBoot server time "+a),ea.info("nrdp.now            "+f+" : "+(f-a)),ea.info("Date.now            "+e+" : "+(e-a)),nrdp.setServerTime(a))}).then(function(){var a=c.responseparams.loglevel,f=c.responseparams.testdriveripaddr,e=c.responseparams.instrumentationparams,w=c.responseparams.retrycontrol;s.isNumber(a)?nrdp.log.level=a:s.isString(a)&&(nrdp.log.level=nrdp.log.levels[a]);f&&nrdp.setTestDriverIpAddress(f);
e&&nrdp.instrumentation.setParams(e.enabled,e.events);s.isNumber(w)&&(Sa.maxRetries=w)}).then(function(){var a,f=c.ssltruststore;f&&((a=f.error)?ea.error('AppBoot server returned an error for "ssltruststore" : '+JSON.stringify(a)):(ea.info("Updating app trust store"),nrdp.setTrustStore(f.data)))}).then(function(){da.ERROR_STAGE++;var a;a=c.msltruststore;if(!a)throw Error('response is missing "msltruststore"');if(a=a.error)throw ea.error('AppBoot server returned an error for "msltruststore" : '+JSON.stringify(a)),
Error(JSON.stringify(a));ea.info("Updating MSL trust store")}).then(function(){da.ERROR_STAGE++;var e,s;s=c.ui;if(!s)throw Error('"ui" element is missing from AppBoot response');if(e=s.error){if(2==e){da.ERROR_DESCRIPTION="ui: Error 2";f();return}throw Error('"ui" response includes an error : '+JSON.stringify(e));}e=a(s);V=0;delete nrdp.js;nrdp._init=!1;s.splash&&(nrdp.storage.setItem("s",ga,s.splash),delete s.splash);nrdp.storage.setItem("s",ba,s);fa&&e.url==fa.url?(ea.trace("remembered ui is the same, using speculative download data"),
fa.finished?(ea.trace("speculative download is already complete, setting location now"),nrdp.gibbon.location={url:fa.finalURL,headers:fa.headers,source:fa.data,reuse:!0}):(ea.trace("speculative download still in progress, deferring setting location"),fa.setLocation=!0)):(ea.trace('unusable speculative download data, loading UI from "'+e.url+'"'),nrdp.gibbon.location={url:e.url,headers:e.headers,reuse:!0})})}).fail(function(a){var e,s=!1,w;w=a.toString()+(a.cause?" (caused by "+a.cause.toString()+
")":"");ea.fatal("App boot failed: "+w,a);da.ERROR_DESCRIPTION=w;if(a instanceof y)e=c(),/^http:/.test(e)?(ea.warn("Retrying using SSL"),s=!0,e=e.replace(/^http:/,"https:")):/^https:/.test(e)&&(ea.warn("Retrying without SSL"),s=!0,e=e.replace(/^https:/,"http:"));else if(a instanceof Tb)s=!0;else if(a instanceof M)da.ERROR_STAGE=0,V||(s=!0);else if(a instanceof Sb&&a.error)switch(a.error.responseCode){case ua.TRANSIENT_FAILURE:s=!0}s?(ea.warn("Retrying this request"),f(e)):xa()}).done()}var e=R("nf-gibbon-mslclient"),
M=e.TimeoutError,Sb=e.MslException,Tb=e.MslEncodingException,y=e.MslIoException,ua=e.MslConstants$ResponseCode,Fa,V=0,ga="appsplash",ba="appbootui",ja="AppbootUserId";ya()})()}})(this)},{"nf-gibbon-mslclient":3,nf_console:4,nf_promise:5,nf_underscore:6}],2:[function(R,ga,xa){R=ga.exports={};R.nextTick=function(){if("undefined"!==typeof window&&window.setImmediate)return function(w){return window.setImmediate(w)};if("undefined"!==typeof window&&window.postMessage&&window.addEventListener){var K=[];
window.addEventListener("message",function(w){var s=w.source;s!==window&&null!==s||"process-tick"!==w.data||(w.stopPropagation(),0<K.length&&K.shift()())},!0);return function(w){K.push(w);window.postMessage("process-tick","*")}}return function(w){setTimeout(w,0)}}();R.title="browser";R.browser=!0;R.env={};R.argv=[];R.binding=function(K){throw Error("process.binding is not supported");};R.cwd=function(){return"/"};R.chdir=function(K){throw Error("process.chdir is not supported");}},{}],3:[function(R,
ga,xa){var K,w,s,P,ya,e,M,Sb,Tb,y,ua,Fa,V,Eb;function ba(a,b){if(a===b)return!0;if(!a||!b||a.length!=b.length)return!1;for(var c=0;c<a.length;++c)if(a[c]!=b[c])return!1;return!0}function ja(a){if(!(a&&a.constructor==Uint8Array||Array.isArray(a)))throw new TypeError("Cannot compute the hash code of "+a);for(var b=1,c=0;c<a.length;++c){var d=a[c];if("number"!==typeof d)throw new TypeError("Cannot compute the hash code over non-numeric elements: "+d);b=31*b+d&4294967295}return b}function Ga(a,b){if(a===
b)return!0;if(!a||!b)return!1;b instanceof Array||(b=[b]);for(var c=0;c<b.length;++c){for(var d=b[c],e=!1,f=0;f<a.length;++f){var k=a[f];if(d.equals&&"function"===typeof d.equals&&d.equals(k)||d==k){e=!0;break}}if(!e)return!1}return!0}function c(a,b,c){var d;c&&(d=c);if("object"!==typeof a||"function"!==typeof a.result||"function"!==typeof a.error)throw new TypeError("callback must be an object with function properties 'result' and 'error'.");try{var e=b.call(d,a);void 0!==e&&a.result(e)}catch(f){try{a.error(f)}catch(k){}}}
function f(a,b,d){if("object"!==typeof a||"function"!==typeof a.timeout)throw new TypeError("callback must be an object with function properties 'result', 'timeout', and 'error'.");c(a,b,d)}function a(a,b,c){1E5>a&&(a=1E5+a);Object.defineProperties(this,{internalCode:{value:a,writable:!1,configurable:!1},responseCode:{value:b,writable:!1,configurable:!1},message:{value:c,writable:!1,configurable:!1}})}function xb(a){switch(a){case $.PSK:case $.MGK:return!0;default:return!1}}function da(a){switch(a){case $.PSK:case $.MGK:case $.X509:case $.RSA:case $.NPTICKET:case $.ECC:return!0;
default:return!1}}function fa(a){this.name="TimeoutError";this.message=a||"Operation timed out";this.errorCode=nrdp.network.ERRORCODE.TIMEOUTERROR;this.mesg="TIMED_OUT_ERROR";try{throw Error();}catch(b){this.stack=b.stack}}setTimeout=function(a,b){return nrdp.gibbon.setTimeout(a,b||0)};clearTimeout=function(a){nrdp.gibbon.clearTimeout(a)};setInterval=function(a,b){return nrdp.gibbon.setTimeout(a,b||0,!1)};clearInterval=function(a){nrdp.gibbon.clearTimeout(a)};var ea=nrdp.btoa,Sa=nrdp.atob,Wa=nrdp.utf8toa,
Xa=nrdp.atoutf8,aa=R("nf_promise"),ia=R("nf_underscore"),Ub=R("nf_console")(nrdp.log,"NRDJS",{utf8toa:nrdp.utf8toa}),N;(function(){function a(b,h){if(b==O)return{process:function(a,b,h){g.exportKey(b.key,b.format,h)}};if(b==L)return{process:function(a,b,h){"raw"==b.format?g.aesUnwrap(b.buffer,b.algorithm,b.key,b.usages,h):g.unwrapJwe(b.buffer,b.key,b.algorithm,b.extractable,b.usages,h)}};if(b==x)return{process:function(a,b,h){g.wrapJwe(b.wrappingKey,b.key,b.algorithm,g.A128GCM,h)}};if(b==D)return{process:function(a,
b,h){g.importKey(b.buffer,b.format,b.algorithm,b.extractable,b.usages,h)}};if(b==G)return{process:function(a,b,h){g.getKeyByName(b.name,h)}};if(b==r)return{process:function(a,b,h){g.getKeyInfo(b.handle,h)}};switch(h.toUpperCase()){case "AES-CBC":return{process:function(a,b,h){switch(a){case t:a=b.algorithm.params?b.algorithm.params.iv:b.algorithm.iv;g.aesEncrypt(b.key,a,b.buffer,h);break;case F:a=b.algorithm.params?b.algorithm.params.iv:b.algorithm.iv;g.aesDecrypt(b.key,a,b.buffer,h);break;case W:g.symKeyGen(b.algorithm,
b.extractable,b.usages,h);break;default:throw new c;}}};case "SHA-1":case "SHA-224":case "SHA-256":case "SHA-384":case "SHA-512":return{process:function(a,b,h){switch(a){case l:g.digest(b.buffer,b.algorithm,h);break;default:throw new c;}}};case "RSASSA-PKCS1-V1_5":return{process:function(a,b,h){switch(a){case n:b.algorithm.hash&&!b.algorithm.params&&(b.algorithm.params={hash:b.algorithm.hash.name});g.rsaSign(b.key,b.buffer,b.algorithm,h);break;case z:b.algorithm.hash&&!b.algorithm.params&&(b.algorithm.params=
{hash:b.algorithm.hash.name});g.rsaVerify(b.key,b.buffer,b.algorithm,b.signature,h);break;case W:g.rsaKeyGen(b.algorithm,b.extractable,b.usages,h);break;default:throw new c;}}};case "RSA-OAEP":case "RSAES-PKCS1-V1_5":return{process:function(a,b,h){switch(a){case t:g.rsaEncrypt(b.key,b.buffer,h);break;case F:g.rsaDecrypt(b.key,b.buffer,h);break;case W:g.rsaKeyGen(b.algorithm,b.extractable,b.usages,h);break;default:throw new c;}}};case "HMAC":return{process:function(a,b,h){switch(a){case n:b.algorithm.hash&&
!b.algorithm.params&&(b.algorithm.params={hash:b.algorithm.hash.name});g.hmac(b.key,b.buffer,b.algorithm,h);break;case z:b.algorithm.hash&&!b.algorithm.params&&(b.algorithm.params={hash:b.algorithm.hash.name});g.hmacVerify(b.key,b.buffer,b.algorithm,b.signature,h);break;case W:g.symKeyGen(b.algorithm,b.extractable,b.usages,h);break;default:throw new c;}}};case "DH":return{process:function(a,b,h){switch(a){case W:g.dhKeyGen(b.algorithm,b.extractable,b.usages,h);break;case u:g.dhDerive(b.key,b.algorithm.params["public"],
b.derivedAlgorithm,b.extractable,b.usages,h);break;default:throw new c;}}};case "NFLX-DH":return{process:function(a,b,h){switch(a){case W:g.dhKeyGen(b.algorithm,b.extractable,b.usages,h);break;case u:if(!g.nflxDhDerive)throw new c;g.nflxDhDerive(b.key,b.algorithm.params["public"],qa(b.algorithm.params.kd),h);break;default:throw new c;}}};case "AES-KW":return{process:function(a,b,h){switch(a){case W:g.symKeyGen(b.algorithm,b.extractable,b.usages,h);break;default:throw new c;}}}}}function b(a){this.name=
"InvalidAlgorithmError";this.message=a||"Invalid algorithm"}function c(a){this.name="NotSupportedError";this.message=a||"Not supported"}function d(a){this.name="NotImplementedError";this.message=a||"Not implemented yet"}function e(g,h){var l,p,m;if("string"==typeof h)return e(g,{name:h});if(h&&"object"==typeof h){l=h.name;if("string"!=typeof l)throw new b("Algorithm has bad or missing name");p=a(g,l);if(void 0===p)throw new b('Invalid algorithm "'+h.name+'"');m=h.params;if(void 0!==m&&(null===m||
"object"!=typeof m))throw new b('Invalid algorithm parameters for "'+h.name+'", expecting undefined or an object');return{algorithm:{name:l,params:m},process:p.process}}throw new b("Invalid algorithm : "+JSON.stringify(h));}function f(a){var b=v[a];if(void 0===b)throw new SyntaxError('Invalid key format "'+a+'"');return b}function k(a){return Array.isArray(a)?a.map(function(a){var b=wa[a];if(void 0===b)throw new SyntaxError('Invalid key usage "'+a+'"');return b}):[]}function qa(a){if(a&&"object"==
typeof a&&1<=a.handle)return a.handle;throw new SyntaxError("Invalid key");}function Ja(a){if("string"==typeof a&&0<=a.length||a&&"object"==typeof a&&a.buffer&&0<=a.byteLength)return a;throw new SyntaxError("Invalid buffer or key data");}function Ma(a,b,g,h){a._listeners=[];a._result=null;a._operation=b;a._args=g;a._info=h;switch(b){case l:a._name="DIGEST";break;case t:a._name="ENCRYPT";break;case F:a._name="DECRYPT";break;case n:a._name="SIGN";break;case z:a._name="VERIFY";break;case D:a._name="IMPORT_KEY";
break;case O:a._name="EXPORT_KEY";break;case W:a._name="GENERATE_KEY";break;case u:a._name="DERIVE_KEY";break;case x:a._name="WRAP_KEY";break;case L:a._name="UNWRAP_KEY";break;case G:a._name="GET_KEY";break;case r:a._name="KEY_INFO"}}function ra(a,b,g){Ma(this,a,b,g)}function I(a,b,g){Ma(this,a,b,g)}function p(a){function b(a,g){return"object"==typeof g&&g&&g.byteLength?"["+g.byteLength+" bytes]":"string"==typeof g&&"data"==a?"["+g.length+" chars]":g}function p(b,g){var h,l=a._listeners.slice(0),
m=l.length,t;for(h=0;h<m;++h)t=l[h],t.type==b&&t.callback(g)}function E(a){var b={handle:a.handle,extractable:a.extractable,algorithm:a.algorithm,name:a.name};switch(a.type){case g.SECRET:b.type="secret";break;case g.PUBLIC:b.type="public";break;case g.PRIVATE:b.type="private"}b.keyUsage=a.usage.map(function(a){switch(a){case g.ENCRYPT:return"encrypt";case g.DECRYPT:return"decrypt";case g.SIGN:return"sign";case g.VERIFY:return"verify";case g.DERIVE:return"derive";case g.WRAP:return"wrap";case g.UNWRAP:return"unwrap"}});
b.keyUsages=b.keyUsage;return b}function c(a){switch(ha){case l:case t:case F:case n:case O:case x:return a.data instanceof ArrayBuffer?new Uint8Array(a.data):Sa(a.data,!0);case z:return a.verified?!0:!1;case D:case L:case W:case u:return a.key?E(a.key):a.wrappingKey?{encryptionKey:E(a.encryptionKey),hmacKey:E(a.hmacKey),wrappingKey:E(a.wrappingKey)}:{publicKey:E(a.publickey),privateKey:E(a.privatekey)};case G:case r:return a.key?E(a.key):null;default:throw new d;}}function I(a){h.error("FAILED "+
v+"\n"+a);wa.error=a;p("error",wa)}var v=a._name,ha=a._operation,jc=a._info,Ba=a._args,wa={target:a},e=nrdp.mono();m&&(m=!1,g.setBinary&&g.setBinary(!0));DEBUG&&h.trace("STARTING "+v+": "+JSON.stringify(Ba,b));a._result=null;try{jc.process(ha,Ba,function(g){try{h.trace("FINISHED "+v+" IN "+(nrdp.mono()-e)+" ms: ");DEBUG&&h.trace(JSON.stringify(g,b));if(!g.success)throw Error("WebCrypto operation "+v+" failed");a._result=c(g);DEBUG&&h.trace("RESULT: "+JSON.stringify(a._result,b));p("complete",wa)}catch(l){I(l)}})}catch(f){setTimeout(function(){I(f)},
0)}return a}var g=nrdp.webcrypto,h=new Ub("CRYPTO"),m=!0,l=1,t=2,F=3,n=4,z=5,D=101,O=102,W=103,u=104,x=105,L=106,G=500,r=600,v={raw:g.RAW,pkcs8:g.PKCS8,spki:g.SPKI,jwk:g.JWK},wa={encrypt:g.ENCRYPT,decrypt:g.DECRYPT,sign:g.SIGN,verify:g.VERIFY,derive:g.DERIVE,deriveKey:g.DERIVE,wrap:g.WRAP,unwrap:g.UNWRAP};b.prototype=Error();b.prototype.constructor=b;c.prototype=Error();c.prototype.constructor=c;d.prototype=Error();d.prototype.constructor=d;ra.prototype.constructor=ra;ra.prototype.addEventListener=
function(a,b){this._listeners.push({type:a,callback:b})};ra.prototype.removeEventListener=function(a,b){this._listeners=this._listeners.filter(function(g){return!(g.type==a&&g.callback==b)})};Object.defineProperties(ra.prototype,{result:{enumerable:!0,get:function(){return this._result}},onerror:{enumerable:!0,configurable:!1,set:function(a){this.addEventListener("error",a)}},oncomplete:{enumerable:!0,configurable:!0,set:function(a){this.addEventListener("complete",a)}}});I.prototype=new ra;I.prototype.constructor=
I;I.prototype.process=function(a){throw new d("process not supported on CryptoOperation");};I.prototype.finish=function(){throw new d("finish not supported on CryptoOperation");};I.prototype.abort=function(){throw new d("abort not supported on CryptoOperation");};Object.defineProperties(I.prototype,{algorithm:{enumerable:!0,get:function(){return this._args.algorithm}},key:{enumerable:!0,get:function(){return this._args.key||null}},onabort:{enumerable:!0,configurable:!1,set:function(a){this.addEventListener("abort",
a)}},onprogress:{enumerable:!0,configurable:!1,set:function(a){this.addEventListener("progress",a)}}});N={getRandomValues:function(a){nrdp.random(a);return a},getKeyByName:function(b){var g=G,h=a(g);return p(new ra(g,{name:b},h))},getKeyInfo:function(b){var g=r,h=a(g);return p(new ra(g,{handle:b},h))},digest:function(a,b){var g=l,h=e(g,a),m={algorithm:a,buffer:Ja(b)};return p(new I(g,m,h))},encrypt:function(a,b,g){var h=t,l=e(h,a);a={algorithm:a,key:qa(b),buffer:Ja(g)};return p(new I(h,a,l))},decrypt:function(a,
b,g){var h=F,l=e(h,a);a={algorithm:a,key:qa(b),buffer:Ja(g)};return p(new I(h,a,l))},sign:function(a,b,g){var h=n,l=e(h,a);a={algorithm:a,key:qa(b),buffer:Ja(g)};return p(new I(h,a,l))},verify:function(a,b,g,h){var l=z,m=e(l,a);a={algorithm:a,key:qa(b),signature:Ja(g),buffer:Ja(h)};return p(new I(l,a,m))},importKey:function(a,b,g,h,l){var m=D,t=e(m,g);a={format:f(a),buffer:Ja(b),algorithm:g,extractable:h?!0:!1,usages:k(l)};return p(new ra(m,a,t))},exportKey:function(b,g){var h=O,l=a(h),m={format:f(b),
key:qa(g)};return p(new ra(h,m,l))},generateKey:function(a,b,g){var h=W,l=e(h,a);a={algorithm:a,extractable:b?!0:!1,usages:k(g)};return p(new ra(h,a,l))},deriveKey:function(a,b,g,h,l){var m=u,t=e(m,a);a={algorithm:a,key:qa(b),derivedAlgorithm:g,extractable:h,usages:k(l)};return p(new ra(m,a,t))},wrapKey:function(a,b,g){var h=x,l=e(h,g);a={algorithm:g,key:qa(a),wrappingKey:qa(b)};return p(new ra(h,a,l))},unwrapKey:function(b,g,h,l,m,t){var n=L,r=a(n);b={algorithm:g,buffer:Ja(b),key:qa(h),extractable:l?
!0:!1,usages:k(m),format:t};return p(new ra(n,b,r))}};N.subtle=N})();var J=ea,S=function(a){return Sa(a,!0)},va=N.subtle,ka=function(a,b){if(!b||"utf-8"===b)return Wa(a);throw Error("unsupported encoding");},na=function(a,b){if(!b||"utf-8"===b)return Xa(a);throw Error("unsupported encoding");},ca,Y,La,Fb,Za,kb,gb,Ib,b;(function(){ca="utf-8";Y=9007199254740992;var a=La={GZIP:"GZIP",LZW:"LZW"};Object.freeze(La);Fb=function(b){for(var c=[a.GZIP,a.LZW],d=0;d<c.length&&0<b.length;++d)for(var e=c[d],f=
0;f<b.length;++f)if(b[f]==e)return e;return null};var c=Za={AES_CBC_PKCS5Padding:"AES/CBC/PKCS5Padding",AESWrap:"AESWrap",RSA_ECB_PKCS1Padding:"RSA/ECB/PKCS1Padding"};Object.freeze(Za);kb=function(a){return c.AES_CBC_PKCS5Padding==a?c.AES_CBC_PKCS5Padding:c.RSA_ECB_PKCS1Padding==a?c.RSA_ECB_PKCS1Padding:c[a]};var d=gb={HmacSHA256:"HmacSHA256",SHA256withRSA:"SHA256withRSA"};Object.freeze(gb);Ib=function(a){return d[a]};b={FAIL:1,TRANSIENT_FAILURE:2,ENTITY_REAUTH:3,USER_REAUTH:4,KEYX_REQUIRED:5,ENTITYDATA_REAUTH:6,
USERDATA_REAUTH:7,EXPIRED:8,REPLAYED:9,SSOTOKEN_REJECTED:10};Object.freeze(b)})();var d={isObjectLiteral:function(a){return null!==a&&"object"===typeof a&&a.constructor===Object},extendDeep:function(){var a=arguments[0],b=1,c=arguments.length,e=!1,f,k,q,qa;"boolean"===typeof a&&(e=a,a=arguments[1],b=2);for(;b<c;b++)if(null!=(f=arguments[b]))for(k in f)e&&k in a||(qa=f[k],a!==qa&&void 0!==qa&&(q=a[k],a[k]=null!==q&&null!==qa&&"object"===typeof q&&"object"===typeof qa?d.extendDeep(e,{},q,qa):qa));return a}};
(function(){function a(b,c){return function(){var a=b.base,I;b.base=c;I=b.apply(this,arguments);b.base=a;return I}}function b(c,e,f){var I,p,g,h;f=f||qa;h=!!f.extendAll;for(I in e)p=e.__lookupGetter__(I),g=e.__lookupSetter__(I),p||g?(p&&c.__defineGetter__(I,p),g&&c.__defineSetter__(I,g)):(p=e[I],g=c[I],"function"===typeof p&&"function"===typeof g&&p!==g?(p.base!==Function.prototype.base&&(p=a(p,g)),p.base=g):(h||f[I])&&d.isObjectLiteral(p)&&d.isObjectLiteral(g)&&(p=d.extendDeep({},g,p)),c[I]=p)}function c(){var a=
Array.prototype.slice,b=a.call(arguments,1);return this.extend({init:function I(){var p=a.call(arguments,0);I.base.apply(this,b.concat(p))}})}function e(a,c){var d=new this(q);b(d,a,c);return k(d)}function f(a,c){b(this.prototype,a,c);return this}function k(a){var b=function(){var a=this.init;a&&arguments[0]!==q&&a.apply(this,arguments)};a&&(b.prototype=a);b.prototype.constructor=b;b.extend=e;b.bind=c;b.mixin=f;return b}var q={},qa={actions:!0};Function.prototype.base=function(){};d.Class={create:k,
mixin:b,extend:function(a,b){var c=k();c.prototype=new a;return c.extend(b)}};d.mixin=function(){d.log&&d.log.warn("util.mixin is deprecated.  Please change your code to use util.Class.mixin()");b.apply(null,arguments)}})();var C;(function(){function a(b){if(0===Object.keys(b._waiters).length)return 0;for(var c=b._nextWaiter==Y?1:b._nextWaiter+1;!b._waiters[c];)c=c==Y?1:c+1;return c}C=d.Class.create({init:function(){Object.defineProperties(this,{_queue:{value:[],writable:!1,enumerable:!1,configurable:!1},
_waiters:{value:{},writable:!1,enumerable:!1,configurable:!1},_nextWaiter:{value:0,writable:!0,enumerable:!1,configurable:!1},_lastWaiter:{value:0,writable:!0,enumerable:!1,configurable:!1}})},cancel:function(b){if(this._waiters[b]){var c=this._waiters[b];delete this._waiters[b];b==this._nextWaiter&&(this._nextWaiter=a(this));c.call(this,void 0)}},cancelAll:function(){for(;0!==this._nextWaiter;)this.cancel(this._nextWaiter)},poll:function(b,c){var d=this,e=this._lastWaiter==Y?1:this._lastWaiter+1;
this._lastWaiter=e;f(c,function(){if(0<this._queue.length){var f=this._queue.shift();setTimeout(function(){c.result(f)},0)}else{var k;-1!=b&&(k=setTimeout(function(){delete d._waiters[e];e==d._nextWaiter&&(d._nextWaiter=a(d));c.timeout()},b));this._waiters[e]=function(a){clearTimeout(k);setTimeout(function(){c.result(a)},0)};this._nextWaiter||(this._nextWaiter=e)}},d);return e},add:function(b){if(this._nextWaiter){var c=this._waiters[this._nextWaiter];delete this._waiters[this._nextWaiter];this._nextWaiter=
a(this);c.call(this,b)}else this._queue.push(b)}})})();var Vb;(function(){var a=0-Y;Vb=d.Class.create({nextBoolean:function(){var a=new Uint8Array(1);N.getRandomValues(a);return a[0]&1?!0:!1},nextInt:function(a){if(null!==a&&void 0!==a){if("number"!==typeof a)throw new TypeError("n must be of type number");if(1>a)throw new RangeError("n must be greater than zero");a-=1;var b=new Uint8Array(4);N.getRandomValues(b);return Math.floor(((b[3]&127)<<24|b[2]<<16|b[1]<<8|b[0])/2147483648*(a-0+1)+0)}a=new Uint8Array(4);
N.getRandomValues(a);b=(a[3]&127)<<24|a[2]<<16|a[1]<<8|a[0];return a[3]&128?-b:b},nextLong:function(){for(var b=a;b==a;){b=new Uint8Array(7);N.getRandomValues(b);var c=16777216*((b[6]&31)<<24|b[5]<<16|b[4]<<8|b[3])+(b[2]<<16|b[1]<<8|b[0]),b=b[6]&128?-c-1:c}return b},nextBytes:function(a){N.getRandomValues(a)}})})();var kc;(function(){function a(b){return b==Y?1:b+1}function b(c){if(0===Object.keys(c._waitingReaders).length)return 0;for(var d=a(c._nextReader);!c._waitingReaders[d];)d=a(d);return d}
function c(b){if(0===Object.keys(b._waitingWriters).length)return 0;for(var d=a(b._nextWriter);!b._waitingWriters[d];)d=a(d);return d}kc=d.Class.create({init:function(){Object.defineProperties(this,{_readers:{value:{},writable:!1,enumerable:!1,configurable:!1},_waitingReaders:{value:{},writable:!1,enumerable:!1,configurable:!1},_writer:{value:null,writable:!0,enumerable:!1,configurable:!1},_waitingWriters:{value:{},writable:!1,enumerable:!1,configurable:!1},_nextReader:{value:0,writable:!0,enumerable:!1,
configurable:!1},_nextWriter:{value:0,writable:!0,enumerable:!1,configurable:!1},_lastNumber:{value:0,writable:!0,enumerable:!1,configurable:!1}})},cancel:function(a){if(this._waitingReaders[a]){var d=this._waitingReaders[a];delete this._waitingReaders[a];a==this._nextReader&&(this._nextReader=b(this));d.call(this,!0)}this._waitingWriters[a]&&(d=this._waitingWriters[a],delete this._waitingWriters[a],a==this._nextWriter&&(this._nextWriter=c(this)),d.call(this,!0))},cancelAll:function(){for(;0!==this._nextWriter;)this.cancel(this._nextWriter);
for(;0!==this._nextReader;)this.cancel(this._nextReader)},readLock:function(c,d){var e=this,k=a(this._lastNumber);this._lastNumber=k;f(d,function(){if(!this._writer&&0===Object.keys(this._waitingWriters).length)return this._readers[k]=!0,k;var a;-1!=c&&(a=setTimeout(function(){delete e._waitingReaders[k];k==e._nextReader&&(e._nextReader=b(e));d.timeout()},c));this._waitingReaders[k]=function(b){clearTimeout(a);b?setTimeout(function(){d.result(void 0)},0):(e._readers[k]=!0,setTimeout(function(){d.result(k)},
0))};this._nextReader||(this._nextReader=k)},e);return k},writeLock:function(b,d){var e=this,k=a(this._lastNumber);this._lastNumber=k;f(d,function(){if(0===Object.keys(this._readers).length&&0===Object.keys(this._waitingReaders).length&&!this._writer)return this._writer=k;var a;-1!=b&&(a=setTimeout(function(){delete e._waitingWriters[k];k==e._nextWriter&&(e._nextWriter=c(e));d.timeout()},b));this._waitingWriters[k]=function(b){clearTimeout(a);b?setTimeout(function(){d.result(void 0)},0):(e._writer=
k,setTimeout(function(){d.result(k)},0))};this._nextWriter||(this._nextWriter=k)},e);return k},unlock:function(b){if(b==this._writer)this._writer=null;else{if(!this._readers[b])throw new B("There is no reader or writer with ticket number "+b+".");delete this._readers[b]}if(this._nextWriter)0<Object.keys(this._readers).length||(b=this._waitingWriters[this._nextWriter],delete this._waitingWriters[this._nextWriter],this._nextWriter=c(this),b.call(this,!1));else{for(var d=this._nextReader;0<Object.keys(this._waitingReaders).length;d=
a(d))this._waitingReaders[d]&&(b=this._waitingReaders[d],delete this._waitingReaders[d],b.call(this,!1));this._nextReader=0}}})})();d.Class.mixin(a,{JSON_PARSE_ERROR:new a(0,b.FAIL,"Error parsing JSON."),JSON_ENCODE_ERROR:new a(1,b.FAIL,"Error encoding JSON."),ENVELOPE_HASH_MISMATCH:new a(2,b.FAIL,"Computed hash does not match envelope hash."),INVALID_PUBLIC_KEY:new a(3,b.FAIL,"Invalid public key provided."),INVALID_PRIVATE_KEY:new a(4,b.FAIL,"Invalid private key provided."),PLAINTEXT_ILLEGAL_BLOCK_SIZE:new a(5,
b.FAIL,"Plaintext is not a multiple of the block size."),PLAINTEXT_BAD_PADDING:new a(6,b.FAIL,"Plaintext contains incorrect padding."),CIPHERTEXT_ILLEGAL_BLOCK_SIZE:new a(7,b.FAIL,"Ciphertext is not a multiple of the block size."),CIPHERTEXT_BAD_PADDING:new a(8,b.FAIL,"Ciphertext contains incorrect padding."),ENCRYPT_NOT_SUPPORTED:new a(9,b.FAIL,"Encryption not supported."),DECRYPT_NOT_SUPPORTED:new a(10,b.FAIL,"Decryption not supported."),ENVELOPE_KEY_ID_MISMATCH:new a(11,b.FAIL,"Encryption envelope key ID does not match crypto context key ID."),
CIPHERTEXT_ENVELOPE_PARSE_ERROR:new a(12,b.FAIL,"Error parsing ciphertext envelope."),CIPHERTEXT_ENVELOPE_ENCODE_ERROR:new a(13,b.FAIL,"Error encoding ciphertext envelope."),SIGN_NOT_SUPPORTED:new a(14,b.FAIL,"Sign not supported."),VERIFY_NOT_SUPPORTED:new a(15,b.FAIL,"Verify not suppoprted."),SIGNATURE_ERROR:new a(16,b.FAIL,"Signature not initialized or unable to process data/signature."),HMAC_ERROR:new a(17,b.FAIL,"Error computing HMAC."),ENCRYPT_ERROR:new a(18,b.FAIL,"Error encrypting plaintext."),
DECRYPT_ERROR:new a(19,b.FAIL,"Error decrypting ciphertext."),INSUFFICIENT_CIPHERTEXT:new a(20,b.FAIL,"Insufficient ciphertext for decryption."),SESSION_KEY_CREATION_FAILURE:new a(21,b.FAIL,"Error when creating session keys."),INVALID_SYMMETRIC_KEY:new a(24,b.FAIL,"Invalid symmetric key provided."),INVALID_ENCRYPTION_KEY:new a(25,b.FAIL,"Invalid encryption key."),INVALID_HMAC_KEY:new a(26,b.FAIL,"Invalid HMAC key."),WRAP_NOT_SUPPORTED:new a(27,b.FAIL,"Wrap not supported."),UNWRAP_NOT_SUPPORTED:new a(28,
b.FAIL,"Unwrap not supported."),UNIDENTIFIED_JWK_TYPE:new a(29,b.FAIL,"Unidentified JSON web key type."),UNIDENTIFIED_JWK_USAGE:new a(30,b.FAIL,"Unidentified JSON web key usage."),UNIDENTIFIED_JWK_ALGORITHM:new a(31,b.FAIL,"Unidentified JSON web key algorithm."),WRAP_ERROR:new a(32,b.FAIL,"Error wrapping plaintext."),UNWRAP_ERROR:new a(33,b.FAIL,"Error unwrapping ciphertext."),INVALID_JWK:new a(34,b.FAIL,"Invalid JSON web key."),INVALID_JWK_KEYDATA:new a(35,b.FAIL,"Invalid JSON web key keydata."),
UNSUPPORTED_JWK_ALGORITHM:new a(36,b.FAIL,"Unsupported JSON web key algorithm."),WRAP_KEY_CREATION_FAILURE:new a(37,b.FAIL,"Error when creating wrapping key."),INVALID_WRAP_CIPHERTEXT:new a(38,b.FAIL,"Invalid wrap ciphertext."),UNSUPPORTED_JWE_ALGORITHM:new a(39,b.FAIL,"Unsupported JSON web encryption algorithm."),JWE_ENCODE_ERROR:new a(40,b.FAIL,"Error encoding JSON web encryption header."),JWE_PARSE_ERROR:new a(41,b.FAIL,"Error parsing JSON web encryption header."),INVALID_ALGORITHM_PARAMS:new a(42,
b.FAIL,"Invalid algorithm parameters."),JWE_ALGORITHM_MISMATCH:new a(43,b.FAIL,"JSON web encryption header algorithms mismatch."),KEY_IMPORT_ERROR:new a(44,b.FAIL,"Error importing key."),KEY_EXPORT_ERROR:new a(45,b.FAIL,"Error exporting key."),DIGEST_ERROR:new a(46,b.FAIL,"Error in digest."),UNSUPPORTED_KEY:new a(47,b.FAIL,"Unsupported key type or algorithm."),UNSUPPORTED_JWE_SERIALIZATION:new a(48,b.FAIL,"Unsupported JSON web encryption serialization."),INVALID_WRAPPING_KEY:new a(51,b.FAIL,"Invalid wrapping key."),
UNIDENTIFIED_CIPHERTEXT_ENVELOPE:new a(52,b.FAIL,"Unidentified ciphertext envelope version."),UNIDENTIFIED_SIGNATURE_ENVELOPE:new a(53,b.FAIL,"Unidentified signature envelope version."),UNSUPPORTED_CIPHERTEXT_ENVELOPE:new a(54,b.FAIL,"Unsupported ciphertext envelope version."),UNSUPPORTED_SIGNATURE_ENVELOPE:new a(55,b.FAIL,"Unsupported signature envelope version."),UNIDENTIFIED_CIPHERSPEC:new a(56,b.FAIL,"Unidentified cipher specification."),UNIDENTIFIED_ALGORITHM:new a(57,b.FAIL,"Unidentified algorithm."),
SIGNATURE_ENVELOPE_PARSE_ERROR:new a(58,b.FAIL,"Error parsing signature envelope."),SIGNATURE_ENVELOPE_ENCODE_ERROR:new a(59,b.FAIL,"Error encoding signature envelope."),INVALID_SIGNATURE:new a(60,b.FAIL,"Invalid signature."),DERIVEKEY_ERROR:new a(61,b.FAIL,"Error deriving key."),UNIDENTIFIED_JWK_KEYOP:new a(62,b.FAIL,"Unidentified JSON web key key operation."),GENERATEKEY_ERROR:new a(63,b.FAIL,"Error generating key."),INVALID_IV:new a(64,b.FAIL,"Invalid initialization vector."),INVALID_CIPHERTEXT:new a(65,
b.FAIL,"Invalid ciphertext."),MASTERTOKEN_UNTRUSTED:new a(1E3,b.ENTITY_REAUTH,"Master token is not trusted."),MASTERTOKEN_KEY_CREATION_ERROR:new a(1001,b.ENTITY_REAUTH,"Unable to construct symmetric keys from master token."),MASTERTOKEN_EXPIRES_BEFORE_RENEWAL:new a(1002,b.ENTITY_REAUTH,"Master token expiration timestamp is before the renewal window opens."),MASTERTOKEN_SESSIONDATA_MISSING:new a(1003,b.ENTITY_REAUTH,"No master token session data found."),MASTERTOKEN_SEQUENCE_NUMBER_OUT_OF_RANGE:new a(1004,
b.ENTITY_REAUTH,"Master token sequence number is out of range."),MASTERTOKEN_SERIAL_NUMBER_OUT_OF_RANGE:new a(1005,b.ENTITY_REAUTH,"Master token serial number is out of range."),MASTERTOKEN_TOKENDATA_INVALID:new a(1006,b.ENTITY_REAUTH,"Invalid master token data."),MASTERTOKEN_SIGNATURE_INVALID:new a(1007,b.ENTITY_REAUTH,"Invalid master token signature."),MASTERTOKEN_SESSIONDATA_INVALID:new a(1008,b.ENTITY_REAUTH,"Invalid master token session data."),MASTERTOKEN_SEQUENCE_NUMBER_OUT_OF_SYNC:new a(1009,
b.ENTITY_REAUTH,"Master token sequence number does not have the expected value."),MASTERTOKEN_TOKENDATA_MISSING:new a(1010,b.ENTITY_REAUTH,"No master token data found."),MASTERTOKEN_TOKENDATA_PARSE_ERROR:new a(1011,b.ENTITY_REAUTH,"Error parsing master token data."),MASTERTOKEN_SESSIONDATA_PARSE_ERROR:new a(1012,b.ENTITY_REAUTH,"Error parsing master token session data."),MASTERTOKEN_IDENTITY_REVOKED:new a(1013,b.ENTITY_REAUTH,"Master token entity identity is revoked."),MASTERTOKEN_REJECTED_BY_APP:new a(1014,
b.ENTITY_REAUTH,"Master token is rejected by the application."),USERIDTOKEN_MASTERTOKEN_MISMATCH:new a(2E3,b.USER_REAUTH,"User ID token master token serial number does not match master token serial number."),USERIDTOKEN_NOT_DECRYPTED:new a(2001,b.USER_REAUTH,"User ID token is not decrypted or verified."),USERIDTOKEN_MASTERTOKEN_NULL:new a(2002,b.USER_REAUTH,"User ID token requires a master token."),USERIDTOKEN_EXPIRES_BEFORE_RENEWAL:new a(2003,b.USER_REAUTH,"User ID token expiration timestamp is before the renewal window opens."),
USERIDTOKEN_USERDATA_MISSING:new a(2004,b.USER_REAUTH,"No user ID token user data found."),USERIDTOKEN_MASTERTOKEN_NOT_FOUND:new a(2005,b.USER_REAUTH,"User ID token is bound to an unknown master token."),USERIDTOKEN_MASTERTOKEN_SERIAL_NUMBER_OUT_OF_RANGE:new a(2006,b.USER_REAUTH,"User ID token master token serial number is out of range."),USERIDTOKEN_SERIAL_NUMBER_OUT_OF_RANGE:new a(2007,b.USER_REAUTH,"User ID token serial number is out of range."),USERIDTOKEN_TOKENDATA_INVALID:new a(2008,b.USER_REAUTH,
"Invalid user ID token data."),USERIDTOKEN_SIGNATURE_INVALID:new a(2009,b.USER_REAUTH,"Invalid user ID token signature."),USERIDTOKEN_USERDATA_INVALID:new a(2010,b.USER_REAUTH,"Invalid user ID token user data."),USERIDTOKEN_IDENTITY_INVALID:new a(2011,b.USER_REAUTH,"Invalid user ID token user identity."),RESERVED_2012:new a(2012,b.USER_REAUTH,"The entity is not associated with the user."),USERIDTOKEN_IDENTITY_NOT_FOUND:new a(2013,b.USER_REAUTH,"The user identity was not found."),USERIDTOKEN_PASSWORD_VERSION_CHANGED:new a(2014,
b.USER_REAUTH,"The user identity must be reauthenticated because the password version changed."),USERIDTOKEN_USERAUTH_DATA_MISMATCH:new a(2015,b.USER_REAUTH,"The user ID token and user authentication data user identities do not match."),USERIDTOKEN_TOKENDATA_MISSING:new a(2016,b.USER_REAUTH,"No user ID token data found."),USERIDTOKEN_TOKENDATA_PARSE_ERROR:new a(2017,b.USER_REAUTH,"Error parsing user ID token data."),USERIDTOKEN_USERDATA_PARSE_ERROR:new a(2018,b.USER_REAUTH,"Error parsing user ID token user data."),
USERIDTOKEN_REVOKED:new a(2019,b.USER_REAUTH,"User ID token is revoked."),USERIDTOKEN_REJECTED_BY_APP:new a(2020,b.USER_REAUTH,"User ID token is rejected by the application."),SERVICETOKEN_MASTERTOKEN_MISMATCH:new a(3E3,b.FAIL,"Service token master token serial number does not match master token serial number."),SERVICETOKEN_USERIDTOKEN_MISMATCH:new a(3001,b.FAIL,"Service token user ID token serial number does not match user ID token serial number."),SERVICETOKEN_SERVICEDATA_INVALID:new a(3002,b.FAIL,
"Service token data invalid."),SERVICETOKEN_MASTERTOKEN_NOT_FOUND:new a(3003,b.FAIL,"Service token is bound to an unknown master token."),SERVICETOKEN_USERIDTOKEN_NOT_FOUND:new a(3004,b.FAIL,"Service token is bound to an unknown user ID token."),SERVICETOKEN_MASTERTOKEN_SERIAL_NUMBER_OUT_OF_RANGE:new a(3005,b.FAIL,"Service token master token serial number is out of range."),SERVICETOKEN_USERIDTOKEN_SERIAL_NUMBER_OUT_OF_RANGE:new a(3006,b.FAIL,"Service token user ID token serial number is out of range."),
SERVICETOKEN_TOKENDATA_INVALID:new a(3007,b.FAIL,"Invalid service token data."),SERVICETOKEN_SIGNATURE_INVALID:new a(3008,b.FAIL,"Invalid service token signature."),SERVICETOKEN_TOKENDATA_MISSING:new a(3009,b.FAIL,"No service token data found."),UNIDENTIFIED_ENTITYAUTH_SCHEME:new a(4E3,b.FAIL,"Unable to identify entity authentication scheme."),ENTITYAUTH_FACTORY_NOT_FOUND:new a(4001,b.FAIL,"No factory registered for entity authentication scheme."),X509CERT_PARSE_ERROR:new a(4002,b.ENTITYDATA_REAUTH,
"Error parsing X.509 certificate data."),X509CERT_ENCODE_ERROR:new a(4003,b.ENTITYDATA_REAUTH,"Error encoding X.509 certificate data."),X509CERT_VERIFICATION_FAILED:new a(4004,b.ENTITYDATA_REAUTH,"X.509 certificate verification failed."),ENTITY_NOT_FOUND:new a(4005,b.FAIL,"Entity not recognized."),INCORRECT_ENTITYAUTH_DATA:new a(4006,b.FAIL,"Entity used incorrect entity authentication data type."),RSA_PUBLICKEY_NOT_FOUND:new a(4007,b.ENTITYDATA_REAUTH,"RSA public key not found."),UNSUPPORTED_ENTITYAUTH_DATA:new a(4023,
b.FAIL,"Unsupported entity authentication data."),ENTITY_REVOKED:new a(4025,b.FAIL,"Entity is revoked."),ENTITY_REJECTED_BY_APP:new a(4026,b.ENTITYDATA_REAUTH,"Entity is rejected by the application."),X509CERT_EXPIRED:new a(4028,b.ENTITYDATA_REAUTH,"X.509 certificate is expired."),X509CERT_NOT_YET_VALID:new a(4029,b.ENTITYDATA_REAUTH,"X.509 certificate is not yet valid."),X509CERT_INVALID:new a(4030,b.ENTITYDATA_REAUTH,"X.509 certificate is invalid."),UNIDENTIFIED_USERAUTH_SCHEME:new a(5003,b.FAIL,
"Unable to identify user authentication scheme."),USERAUTH_FACTORY_NOT_FOUND:new a(5004,b.FAIL,"No factory registered for user authentication scheme."),EMAILPASSWORD_BLANK:new a(5005,b.USERDATA_REAUTH,"Email or password is blank."),EMAILPASSWORD_INCORRECT:new a(5007,b.USERDATA_REAUTH,"Email or password is incorrect."),UNSUPPORTED_USERAUTH_DATA:new a(5008,b.FAIL,"Unsupported user authentication data."),USERAUTH_USERIDTOKEN_INVALID:new a(5011,b.USERDATA_REAUTH,"User authentication data user ID token is invalid."),
UNIDENTIFIED_USERAUTH_MECHANISM:new a(5013,b.FAIL,"Unable to identify user authentication mechanism."),UNSUPPORTED_USERAUTH_MECHANISM:new a(5014,b.FAIL,"Unsupported user authentication mechanism."),USERAUTH_MASTERTOKEN_MISSING:new a(5016,b.USERDATA_REAUTH,"User authentication required master token is missing."),USERAUTH_USERIDTOKEN_NOT_DECRYPTED:new a(5021,b.USERDATA_REAUTH,"User authentication data user ID token is not decrypted or verified."),USERAUTH_MASTERTOKEN_INVALID:new a(5024,b.USERDATA_REAUTH,
"User authentication data master token is invalid."),USERAUTH_MASTERTOKEN_NOT_DECRYPTED:new a(5025,b.USERDATA_REAUTH,"User authentication data master token is not decrypted or verified."),USERAUTH_USERIDTOKEN_MISSING:new a(5030,b.USERDATA_REAUTH,"User authentication required user ID token is missing."),USERAUTH_ENTITY_MISMATCH:new a(5032,b.USERDATA_REAUTH,"User authentication data does not match entity identity."),USERAUTH_INCORRECT_DATA:new a(5033,b.FAIL,"Entity used incorrect user authentication data type."),
USER_REJECTED_BY_APP:new a(5037,b.USERDATA_REAUTH,"User is rejected by the application."),USERIDTOKEN_IDENTITY_NOT_ASSOCIATED_WITH_ENTITY:new a(5040,b.USER_REAUTH,"The entity is not associated with the user."),UNSUPPORTED_COMPRESSION:new a(6E3,b.FAIL,"Unsupported compression algorithm."),COMPRESSION_ERROR:new a(6001,b.FAIL,"Error compressing data."),UNCOMPRESSION_ERROR:new a(6002,b.FAIL,"Error uncompressing data."),MESSAGE_ENTITY_NOT_FOUND:new a(6003,b.FAIL,"Message header entity authentication data or master token not found."),
PAYLOAD_MESSAGE_ID_MISMATCH:new a(6004,b.FAIL,"Payload chunk message ID does not match header message ID ."),PAYLOAD_SEQUENCE_NUMBER_MISMATCH:new a(6005,b.FAIL,"Payload chunk sequence number does not match expected sequence number."),PAYLOAD_VERIFICATION_FAILED:new a(6006,b.FAIL,"Payload chunk payload signature verification failed."),MESSAGE_DATA_MISSING:new a(6007,b.FAIL,"No message data found."),MESSAGE_FORMAT_ERROR:new a(6008,b.FAIL,"Malformed message data."),MESSAGE_VERIFICATION_FAILED:new a(6009,
b.FAIL,"Message header/error data signature verification failed."),HEADER_DATA_MISSING:new a(6010,b.FAIL,"No header data found."),PAYLOAD_DATA_MISSING:new a(6011,b.FAIL,"No payload data found in non-EOM payload chunk."),PAYLOAD_DATA_CORRUPT:new a(6012,b.FAIL,"Corrupt payload data found in non-EOM payload chunk."),UNIDENTIFIED_COMPRESSION:new a(6013,b.FAIL,"Unidentified compression algorithm."),MESSAGE_EXPIRED:new a(6014,b.EXPIRED,"Message expired and not renewable. Rejected."),MESSAGE_ID_OUT_OF_RANGE:new a(6015,
b.FAIL,"Message ID is out of range."),INTERNAL_CODE_NEGATIVE:new a(6016,b.FAIL,"Error header internal code is negative."),UNEXPECTED_RESPONSE_MESSAGE_ID:new a(6017,b.FAIL,"Unexpected response message ID. Possible replay."),RESPONSE_REQUIRES_ENCRYPTION:new a(6018,b.KEYX_REQUIRED,"Message response requires encryption."),PAYLOAD_SEQUENCE_NUMBER_OUT_OF_RANGE:new a(6019,b.FAIL,"Payload chunk sequence number is out of range."),PAYLOAD_MESSAGE_ID_OUT_OF_RANGE:new a(6020,b.FAIL,"Payload chunk message ID is out of range."),
MESSAGE_REPLAYED:new a(6021,b.REPLAYED,"Non-replayable message replayed."),INCOMPLETE_NONREPLAYABLE_MESSAGE:new a(6022,b.FAIL,"Non-replayable message sent non-renewable or without key request data or without a master token."),HEADER_SIGNATURE_INVALID:new a(6023,b.FAIL,"Invalid Header signature."),HEADER_DATA_INVALID:new a(6024,b.FAIL,"Invalid header data."),PAYLOAD_INVALID:new a(6025,b.FAIL,"Invalid payload."),PAYLOAD_SIGNATURE_INVALID:new a(6026,b.FAIL,"Invalid payload signature."),RESPONSE_REQUIRES_MASTERTOKEN:new a(6027,
b.KEYX_REQUIRED,"Message response requires a master token."),RESPONSE_REQUIRES_USERIDTOKEN:new a(6028,b.USER_REAUTH,"Message response requires a user ID token."),REQUEST_REQUIRES_USERAUTHDATA:new a(6029,b.FAIL,"User-associated message requires user authentication data."),UNEXPECTED_MESSAGE_SENDER:new a(6030,b.FAIL,"Message sender is equal to the local entity or not the master token entity."),NONREPLAYABLE_MESSAGE_REQUIRES_MASTERTOKEN:new a(6031,b.FAIL,"Non-replayable message requires a master token."),
NONREPLAYABLE_ID_OUT_OF_RANGE:new a(6032,b.FAIL,"Non-replayable message non-replayable ID is out of range."),MESSAGE_SERVICETOKEN_MISMATCH:new a(6033,b.FAIL,"Service token master token or user ID token serial number does not match the message token serial numbers."),MESSAGE_PEER_SERVICETOKEN_MISMATCH:new a(6034,b.FAIL,"Peer service token master token or user ID token serial number does not match the message peer token serial numbers."),RESPONSE_REQUIRES_INTEGRITY_PROTECTION:new a(6035,b.KEYX_REQUIRED,
"Message response requires integrity protection."),HANDSHAKE_DATA_MISSING:new a(6036,b.FAIL,"Handshake message is not renewable or does not contain key request data."),MESSAGE_RECIPIENT_MISMATCH:new a(6037,b.FAIL,"Message recipient does not match local identity."),MESSAGE_ENTITYDATABASED_VERIFICATION_FAILED:new a(6038,b.ENTITYDATA_REAUTH,"Message header entity-based signature verification failed."),MESSAGE_MASTERTOKENBASED_VERIFICATION_FAILED:new a(6039,b.ENTITY_REAUTH,"Message header master token-based signature verification failed."),
UNIDENTIFIED_KEYX_SCHEME:new a(7E3,b.FAIL,"Unable to identify key exchange scheme."),KEYX_FACTORY_NOT_FOUND:new a(7001,b.FAIL,"No factory registered for key exchange scheme."),KEYX_REQUEST_NOT_FOUND:new a(7002,b.FAIL,"No key request found matching header key response data."),UNIDENTIFIED_KEYX_KEY_ID:new a(7003,b.FAIL,"Unable to identify key exchange key ID."),UNSUPPORTED_KEYX_KEY_ID:new a(7004,b.FAIL,"Unsupported key exchange key ID."),UNIDENTIFIED_KEYX_MECHANISM:new a(7005,b.FAIL,"Unable to identify key exchange mechanism."),
UNSUPPORTED_KEYX_MECHANISM:new a(7006,b.FAIL,"Unsupported key exchange mechanism."),KEYX_RESPONSE_REQUEST_MISMATCH:new a(7007,b.FAIL,"Key exchange response does not match request."),KEYX_PRIVATE_KEY_MISSING:new a(7008,b.FAIL,"Key exchange private key missing."),UNKNOWN_KEYX_PARAMETERS_ID:new a(7009,b.FAIL,"Key exchange parameters ID unknown or invalid."),KEYX_MASTER_TOKEN_MISSING:new a(7010,b.FAIL,"Master token required for key exchange is missing."),KEYX_INVALID_PUBLIC_KEY:new a(7011,b.FAIL,"Key exchange public key is invalid."),
KEYX_PUBLIC_KEY_MISSING:new a(7012,b.FAIL,"Key exchange public key missing."),KEYX_WRAPPING_KEY_MISSING:new a(7013,b.FAIL,"Key exchange wrapping key missing."),KEYX_WRAPPING_KEY_ID_MISSING:new a(7014,b.FAIL,"Key exchange wrapping key ID missing."),KEYX_INVALID_WRAPPING_KEY:new a(7015,b.FAIL,"Key exchange wrapping key is invalid."),KEYX_INCORRECT_DATA:new a(7016,b.FAIL,"Entity used incorrect key exchange data type."),KEYX_INCORRECT_MECHANISM:new a(7017,b.FAIL,"Entity used incorrect key exchange mecahnism."),
KEYX_DERIVATION_KEY_MISSING:new a(7018,b.FAIL,"Key exchange derivation key missing."),KEYX_INVALID_ENCRYPTION_KEY:new a(7019,b.FAIL,"Key exchange encryption key is invalid."),KEYX_INVALID_HMAC_KEY:new a(7020,b.FAIL,"Key exchange HMAC key is invalid."),KEYX_INVALID_WRAPDATA:new a(7021,b.FAIL,"Key exchange wrap data is invalid."),INTERNAL_EXCEPTION:new a(9E3,b.TRANSIENT_FAILURE,"Internal exception."),MSL_COMMS_FAILURE:new a(9001,b.FAIL,"Error communicating with MSL entity."),NONE:new a(9999,b.FAIL,
"Special unit test error.")});Object.freeze(a);var k;(function(){k=d.Class.create(Error());k.mixin({init:function(a,b,c){function d(){if(f)return f;if(this.cause&&this.cause instanceof k)return this.cause.messageId}Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor);var e=a.message;b&&(e+=" ["+b+"]");var f,q=this.stack;Object.defineProperties(this,{message:{value:e,writable:!1,configurable:!0},error:{value:a,writable:!1,configurable:!0},cause:{value:c,writable:!1,configurable:!0},
name:{value:"MslException",writable:!1,configurable:!0},masterToken:{value:null,writable:!0,configurable:!1},entityAuthenticationData:{value:null,writable:!0,configurable:!1},userIdToken:{value:null,writable:!0,configurable:!1},userAuthenticationData:{value:null,writable:!0,configurable:!1},messageId:{get:d,set:function(a){if(0>a||a>Y)throw new RangeError("Message ID "+a+" is outside the valid range.");d()||(f=a)},configurable:!0},stack:{get:function(){var a=this.toString();q&&(a+="\n"+q);c&&c.stack&&
(a+="\nCaused by "+c.stack);return a},configurable:!0}})},setEntity:function(a){!a||this.masterToken||this.entityAuthenticationData||(a instanceof Da?this.masterToken=a:a instanceof hb&&(this.entityAuthenticationData=a));return this},setUser:function(a){!a||this.userIdToken||this.userAuthenticationData||(a instanceof yb?this.userIdToken=a:a instanceof ib&&(this.userAuthenticationData=a));return this},setMessageId:function(a){this.messageId=a;return this},toString:function(){return this.name+": "+
this.message}})})();var q=k.extend({init:function Qd(a,b,c){Qd.base.call(this,a,b,c);Object.defineProperties(this,{name:{value:"MslCryptoException",writable:!1,configurable:!0}})}}),A=k.extend({init:function Rd(a,b,c){Rd.base.call(this,a,b,c);Object.defineProperties(this,{name:{value:"MslEncodingException",writable:!1,configurable:!0}})}}),$a=k.extend({init:function Sd(a,b,c){Sd.base.call(this,a,b,c);Object.defineProperties(this,{name:{value:"MslEntityAuthException",writable:!1,configurable:!0}})}}),
Pa;(function(){Pa=d.Class.create(Error());Pa.mixin({init:function(a,b,c){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor);var d=this.stack;Object.defineProperties(this,{message:{value:a,writable:!1,configurable:!1},cause:{value:b,writable:!1,configurable:!1},requestCause:{value:c,writable:!1,configurable:!1},name:{value:"MslErrorResponseException",writable:!1,configurable:!0},stack:{get:function(){var a=this.toString();d&&(a+="\n"+d);b&&b.stack&&(a+="\nCaused by "+b.stack);
return a},configurable:!0}})},toString:function(){return this.name+": "+this.message}})})();var oa;(function(){oa=d.Class.create(Error());oa.mixin({init:function(a,b){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor);var c=this.stack;Object.defineProperties(this,{message:{value:a,writable:!1,configurable:!1},cause:{value:b,writable:!1,configurable:!1},name:{value:"MslIoException",writable:!1,configurable:!0},stack:{get:function(){var a=this.toString();c&&(a+="\n"+c);b&&b.stack&&
(a+="\nCaused by "+b.stack);return a},configurable:!0}})},toString:function(){return this.name+": "+this.message}})})();var B;(function(){B=d.Class.create(Error());B.mixin({init:function(a,b){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor);var c=this.stack;Object.defineProperties(this,{message:{value:a,writable:!1,configurable:!1},cause:{value:b,writable:!1,configurable:!1},name:{value:"MslInternalException",writable:!1,configurable:!0},stack:{get:function(){var a=this.toString();
c&&(a+="\n"+c);b&&b.stack&&(a+="\nCaused by "+b.stack);return a},configurable:!0}})},toString:function(){return this.name+": "+this.message}})})();var T=k.extend({init:function Td(a,b,c){Td.base.call(this,a,b,c);Object.defineProperties(this,{name:{value:"MslKeyExchangeException",writable:!1,configurable:!0}})}}),Qa=k.extend({init:function Ud(a,b){Ud.base.call(this,a);Object.defineProperties(this,{masterToken:{value:b,writable:!1,configurable:!1},name:{value:"MslMasterTokenException",writable:!1,configurable:!0}})}}),
X=k.extend({init:function Vd(a,b,c){Vd.base.call(this,a,b,c);Object.defineProperties(this,{name:{value:"MslMessageException",writable:!1,configurable:!0}})}}),U=k.extend({init:function qa(a,b,c){qa.base.call(this,a,b,c);Object.defineProperties(this,{name:{value:"MslUserAuthException",writable:!1,configurable:!0}})}}),Ka;(function(){Ka=d.Class.create(Error());Ka.mixin({init:function(a,b){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor);var c=this.stack;Object.defineProperties(this,
{message:{value:a,writable:!1,configurable:!1},cause:{value:b,writable:!1,configurable:!1},name:{value:"MslInterruptedException",writable:!1,configurable:!0},stack:{get:function(){var a=this.toString();c&&(a+="\n"+c);b&&b.stack&&(a+="\nCaused by "+b.stack);return a},configurable:!0}})},toString:function(){return this.name+": "+this.message}})})();var ma,Ia,lc;(function(){function a(b){return"undefined"===typeof b?!1:b}function b(a){return a&&a.length?(Ia===c.V2014_02&&(a=a.map(function(a){return"wrap"==
a?"wrapKey":"unwrap"==a?"unwrapKey":a})),a):Ia===c.V2014_02?"encrypt decrypt sign verify deriveKey wrapKey unwrapKey".split(" "):"encrypt decrypt sign verify deriveKey wrap unwrap".split(" ")}var c=lc={LEGACY:1,V2014_01:2,V2014_02:3,LATEST:3};Object.freeze(lc);Ia=c.LATEST;ma={encrypt:function(a,b,p){switch(Ia){case c.LEGACY:return new aa(function(g,h){var c=N.encrypt(a,b,p);c.oncomplete=function(a){g(a.target.result)};c.onerror=function(a){h(a)}});case c.V2014_01:case c.V2014_02:return va.encrypt(a,
b,p);default:throw Error("Unsupported Web Crypto version "+WEB_CRYPTO_VERSION+".");}},decrypt:function(a,b,p){switch(Ia){case c.LEGACY:return new aa(function(g,h){var c=N.decrypt(a,b,p);c.oncomplete=function(a){g(a.target.result)};c.onerror=function(a){h(a)}});case c.V2014_01:case c.V2014_02:return va.decrypt(a,b,p);default:throw Error("Unsupported Web Crypto version "+WEB_CRYPTO_VERSION+".");}},sign:function(a,b,p){switch(Ia){case c.LEGACY:return new aa(function(g,h){var c=N.sign(a,b,p);c.oncomplete=
function(a){g(a.target.result)};c.onerror=function(a){h(a)}});case c.V2014_01:case c.V2014_02:return va.sign(a,b,p);default:throw Error("Unsupported Web Crypto version "+WEB_CRYPTO_VERSION+".");}},verify:function(a,b,p,g){switch(Ia){case c.LEGACY:return new aa(function(h,c){var l=N.verify(a,b,p,g);l.oncomplete=function(a){h(a.target.result)};l.onerror=function(a){c(a)}});case c.V2014_01:case c.V2014_02:return va.verify(a,b,p,g);default:throw Error("Unsupported Web Crypto version "+WEB_CRYPTO_VERSION+
".");}},digest:function(a,b){switch(Ia){case c.LEGACY:return new aa(function(c,g){var h=va.digest(a,b);h.oncomplete=function(a){c(a.target.result)};h.onerror=function(a){g(a)}});case c.V2014_01:case c.V2014_02:return va.digest(a,b);default:throw Error("Unsupported Web Crypto version "+WEB_CRYPTO_VERSION+".");}},generateKey:function(d,I,p){var g=a(I),h=b(p);switch(Ia){case c.LEGACY:return new aa(function(a,b){var c=N.generateKey(d,g,h);c.oncomplete=function(b){a(b.target.result)};c.onerror=function(a){b(a)}});
case c.V2014_01:case c.V2014_02:return va.generateKey(d,g,h);default:throw Error("Unsupported Web Crypto version "+WEB_CRYPTO_VERSION+".");}},deriveKey:function(d,I,p,g,h){var m=a(g),l=b(h);switch(Ia){case c.LEGACY:return new aa(function(a,b){var g=N.deriveKey(d,I,p,m,l);g.oncomplete=function(b){a(b.target.result)};g.onerror=function(a){b(a)}});case c.V2014_01:case c.V2014_02:return va.deriveKey(d,I,p,m,l);default:throw Error("Unsupported Web Crypto version "+WEB_CRYPTO_VERSION+".");}},importKey:function(d,
I,p,g,h){var m=a(g),l=b(h);switch(Ia){case c.LEGACY:return new aa(function(a,b){var g=N.importKey(d,I,p,m,l);g.oncomplete=function(b){a(b.target.result)};g.onerror=function(a){b(a)}});case c.V2014_01:case c.V2014_02:return va.importKey(d,I,p,m,l);default:throw Error("Unsupported Web Crypto version "+WEB_CRYPTO_VERSION+".");}},exportKey:function(a,b){switch(Ia){case c.LEGACY:return new aa(function(c,g){var h=N.exportKey(a,b);h.oncomplete=function(a){c(a.target.result)};h.onerror=function(a){g(a)}});
case c.V2014_01:case c.V2014_02:return va.exportKey(a,b);default:throw Error("Unsupported Web Crypto version "+WEB_CRYPTO_VERSION+".");}},wrapKey:function(a,b,p,g){switch(Ia){case c.LEGACY:return new aa(function(a,c){var l=va.wrapKey(b,p,g);l.oncomplete=function(b){a(b.target.result)};l.onerror=function(a){c(a)}});case c.V2014_01:case c.V2014_02:return va.wrapKey(a,b,p,g);default:throw Error("Unsupported Web Crypto version "+WEB_CRYPTO_VERSION+".");}},unwrapKey:function(d,I,p,g,h,m,l){switch(Ia){case c.LEGACY:return new aa(function(a,
b){var h=va.unwrapKey(I,g,p);h.oncomplete=function(b){a(b.target.result)};h.onerror=function(a){b(a)}});case c.V2014_01:case c.V2014_02:return va.unwrapKey(d,I,p,g,h,a(m),b(l));default:throw Error("Unsupported Web Crypto version "+WEB_CRYPTO_VERSION+".");}}}})();ua=["encrypt","decrypt"];Fa=["wrap","unwrap"];V=["sign","verify"];Eb=["deriveKey"];w={name:"AES-KW"};s={name:"AES-CBC"};P={name:"HMAC",hash:{name:"SHA-256"}};ya={name:"RSA-OAEP",hash:{name:"SHA-1"}};e={name:"RSAES-PKCS1-v1_5"};M={name:"RSASSA-PKCS1-v1_5"};
Sb={name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};Tb={name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};y={name:"NFLX-DH"};var mc,Ta,bb;(function(){mc=d.Class.create({init:function(b,d,e){function f(a){c(d,function(){var g=a?J(a):void 0;Object.defineProperties(I,{rawKey:{value:b,writable:!1,configurable:!1},keyData:{value:a,writable:!1,configurable:!1},keyDataB64:{value:g,writable:!1,configurable:!1}});return this},I)}var I=this;c(d,function(){if(!b||"object"!=typeof b)throw new q(a.INVALID_SYMMETRIC_KEY);
!e&&b.extractable?ma.exportKey("raw",b).then(function(a){f(new Uint8Array(a))},function(b){d.error(new q(a.KEY_EXPORT_ERROR,"raw"))}):f(e)},I)},size:function(){return this.keyData.length},toByteArray:function(){return this.keyData},toBase64:function(){return this.keyDataB64}});Ta=function(a,b){new mc(a,b)};bb=function(b,d,e,f){c(f,function(){try{b="string"==typeof b?S(b):b}catch(c){throw new q(a.INVALID_SYMMETRIC_KEY,"keydata "+b,c);}ma.importKey("raw",b,d,!0,e).then(function(a){new mc(a,f,b)},function(b){f.error(new q(a.INVALID_SYMMETRIC_KEY))})})}})();
var Wb,jb,nc;(function(){Wb=d.Class.create({init:function(b,d,e){function f(a){c(d,function(){Object.defineProperties(I,{rawKey:{value:b,writable:!1,configurable:!1},encoded:{value:a,writable:!1,configurable:!1}});return this},I)}var I=this;c(d,function(){if(!b||"object"!=typeof b||"public"!=b.type)throw new TypeError("Only original public crypto keys are supported.");!e&&b.extractable?ma.exportKey("spki",b).then(function(a){f(new Uint8Array(a))},function(b){d.error(new q(a.KEY_EXPORT_ERROR,"spki"))}):
f(e)})},getEncoded:function(){return this.encoded}});jb=function(a,b){new Wb(a,b)};nc=function(b,d,e,f){c(f,function(){try{b="string"==typeof b?S(b):b}catch(c){throw new q(a.INVALID_PUBLIC_KEY,"spki "+b,c);}ma.importKey("spki",b,d,!0,e).then(function(a){new Wb(a,f,b)},function(b){f.error(new q(a.INVALID_PUBLIC_KEY))})})}})();var Rc,lb;(function(){Rc=d.Class.create({init:function(b,d,e){function f(a){c(d,function(){Object.defineProperties(I,{rawKey:{value:b,writable:!1,configurable:!1},encoded:{value:a,
writable:!1,configurable:!1}});return this},I)}var I=this;c(d,function(){if(!b||"object"!=typeof b||"private"!=b.type)throw new TypeError("Only original private crypto keys are supported.");!e&&b.extractable?ma.exportKey("pkcs8",b).then(function(a){f(new Uint8Array(a))},function(b){d.error(new q(a.KEY_EXPORT_ERROR,"pkcs8"))}):f(e)})},getEncoded:function(){return this.encoded}});lb=function(a,b){new Rc(a,b)}})();var cb,oc,pc,qc;(function(){var b=qc={V1:1,V2:2};cb=d.Class.create({init:function(a,c,
d){var I;switch(a){case b.V1:I=d;break;case b.V2:I={};I.version=a;I.algorithm=c;I.signature=J(d);I=na(JSON.stringify(I),ca);break;default:throw new B("Signature envelope version "+a+" encoding unsupported.");}Object.defineProperties(this,{version:{value:a,writable:!1,enumerable:!1,configurable:!1},algorithm:{value:c,writable:!1,configurable:!1},signature:{value:d,writable:!1,configurable:!1},bytes:{value:I,writable:!1,configurable:!1}})}});oc=function(){var a,d,e,I;2==arguments.length?(a=b.V1,d=arguments[0],
e=null,I=arguments[1]):3==arguments.length&&(a=b.V2,e=arguments[0],d=arguments[1],I=arguments[2]);c(I,function(){return new cb(a,e,d)})};pc=function(d,e,f){c(f,function(){if(e)switch(e){case b.V1:return new cb(b.V1,null,d);case b.V2:try{var c=ka(d,ca),p=JSON.parse(c),g=parseInt(p.version),h=p.algorithm,m=p.signature;if(!g||"number"!==typeof g||g!=g||"string"!==typeof h||"string"!==typeof m)throw new A(a.JSON_PARSE_ERROR,"signature envelope "+J(d));if(b.V2!=g)throw new q(a.UNSUPPORTED_SIGNATURE_ENVELOPE,
"signature envelope "+J(d));var l=Ib(h);if(!l)throw new q(a.UNIDENTIFIED_ALGORITHM,"signature envelope "+J(d));var t=S(m);if(!t)throw new q(a.INVALID_SIGNATURE,"signature envelope "+Base64Util.encode(d));return new cb(b.V2,l,t)}catch(F){if(F instanceof SyntaxError)throw new A(a.JSON_PARSE_ERROR,"signature envelope "+J(d),F);throw F;}default:throw new q(a.UNSUPPORTED_SIGNATURE_ENVELOPE,"signature envelope "+J(d));}try{c=ka(d,ca),p=JSON.parse(c)}catch(n){p=null}if(p&&p.version){if(c=p.version,"number"!==
typeof c||c!==c)c=b.V1}else c=b.V1;switch(c){case b.V1:return new cb(c,null,d);case b.V2:l=p.algorithm;m=p.signature;if("string"!==typeof l||"string"!==typeof m)return new cb(b.V1,null,d);l=Ib(l);if(!l)return new cb(b.V1,null,d);try{t=S(m)}catch(z){return new cb(b.V1,null,d)}return new cb(c,l,t);default:throw new q(a.UNSUPPORTED_SIGNATURE_ENVELOPE,"signature envelope "+d);}})}})();var rc,sc,tc,uc;(function(){var b=uc={V1:1,V2:2};rc=d.Class.create({init:function(a,d,e,I){c(I,function(){var c=b.V1,
g=a,h=null,m;for(m in Za)if(Za[m]==a){c=b.V2;g=null;h=a;break}Object.defineProperties(this,{version:{value:c,writable:!1,enumerable:!1,configurable:!1},keyId:{value:g,writable:!1,configurable:!1},cipherSpec:{value:h,writable:!1,configurable:!1},iv:{value:d,writable:!1,configurable:!1},ciphertext:{value:e,writable:!1,configurable:!1}});return this},this)},toJSON:function(){var a={};switch(this.version){case b.V1:a.keyid=this.keyId;this.iv&&(a.iv=J(this.iv));a.ciphertext=J(this.ciphertext);a.sha256=
"AA==";break;case b.V2:a.version=this.version;a.cipherspec=this.cipherSpec;this.iv&&(a.iv=J(this.iv));a.ciphertext=J(this.ciphertext);break;default:throw new B("Ciphertext envelope version "+this.version+" encoding unsupported.");}return a}});sc=function(a,b,c,d){new rc(a,b,c,d)};tc=function(d,e,f){c(f,function(){var c=d.keyid,p=d.cipherspec,g=d.iv,h=d.ciphertext,m=d.sha256;if(!e)if((e=d.version)&&"number"===typeof e&&e===e){var l=!1,t;for(t in b)if(b[t]==e){l=!0;break}if(!l)throw new q(a.UNIDENTIFIED_CIPHERTEXT_ENVELOPE,
"ciphertext envelope "+JSON.stringify(d));}else e=b.V1;switch(e){case b.V1:if("string"!==typeof c||g&&"string"!==typeof g||"string"!==typeof h||"string"!==typeof m)throw new A(a.JSON_PARSE_ERROR,"ciphertext envelope "+JSON.stringify(d));break;case b.V2:t=d.version;if(t!=b.V2)throw new q(a.UNIDENTIFIED_CIPHERTEXT_ENVELOPE,"ciphertext envelope "+JSON.stringify(d));if("string"!==typeof p||g&&"string"!==typeof g||"string"!==typeof h)throw new A(a.JSON_PARSE_ERROR,"ciphertext envelope "+JSON.stringify(d));
p=kb(p);if(!p)throw new q(a.UNIDENTIFIED_CIPHERSPEC,"ciphertext envelope "+JSON.stringify(d));c=p;break;default:throw new q(a.UNSUPPORTED_CIPHERTEXT_ENVELOPE,"ciphertext envelope "+JSON.stringify(d));}try{g&&(g=S(g)),h=S(h)}catch(F){throw new q(a.CIPHERTEXT_ENVELOPE_PARSE_ERROR,"encryption envelope "+JSON.stringify(d),F);}new rc(c,g,h,f)})}})();var mb=d.Class.create({encrypt:function(a,b){},decrypt:function(a,b){},wrap:function(a,b){},unwrap:function(a,b,c,d){},sign:function(a,b){},verify:function(a,
b,c){}}),zb=mb.extend({encrypt:function(a,b){b.result(a)},decrypt:function(a,b){b.result(a)},wrap:function(a,b){b.result(a)},unwrap:function(a,b,c,d){d.result(a)},sign:function(a,b){b.result(new Uint8Array(0))},verify:function(a,b,c){c.result(!0)}}),Xb,Yb;(function(){var b=Yb={ENCRYPT_DECRYPT_OAEP:1,ENCRYPT_DECRYPT_PKCS1:2,WRAP_UNWRAP_OAEP:3,WRAP_UNWRAP_PKCS1:4,SIGN_VERIFY:5};Xb=mb.extend({init:function Ma(a,c,p,g,h){Ma.base.call(this);p&&(p=p.rawKey);g&&(g=g.rawKey);Object.defineProperties(this,
{id:{value:c,writable:!1,enumerable:!1,configurable:!1},privateKey:{value:p,writable:!1,enumerable:!1,configurable:!1},publicKey:{value:g,writable:!1,enumerable:!1,configurable:!1},transform:{value:h==b.ENCRYPT_DECRYPT_PKCS1?e:h==b.ENCRYPT_DECRYPT_OAEP?ya:"nullOp",writable:!1,enumerable:!1,configurable:!1},wrapTransform:{value:h==b.WRAP_UNWRAP_PKCS1?e:h==b.WRAP_UNWRAP_OAEP?ya:"nullOp",writable:!1,enumerable:!1,configurable:!1},algo:{value:h==b.SIGN_VERIFY?Sb:"nullOp",writable:!1,enumerable:!1,configurable:!1}})},
encrypt:function(b,d){var e=this;c(d,function(){if("nullOp"==this.transform)return b;if(!this.publicKey)throw new q(a.ENCRYPT_NOT_SUPPORTED,"no public key");if(0==b.length)return b;ma.encrypt(e.transform,e.publicKey,b).then(function(b){sc(e.id,null,new Uint8Array(b),{result:function(b){try{var h=JSON.stringify(b);d.result(na(h,ca))}catch(c){d.error(new q(a.ENCRYPT_ERROR,null,c))}},error:function(b){b instanceof k||(b=new q(a.ENCRYPT_ERROR,null,b));d.error(b)}})},function(b){d.error(new q(a.ENCRYPT_ERROR))})},
this)},decrypt:function(b,d){var e=this;c(d,function(){if("nullOp"==this.transform)return b;if(!this.privateKey)throw new q(a.DECRYPT_NOT_SUPPORTED,"no private key");if(0==b.length)return b;var c;try{var g=ka(b,ca);c=JSON.parse(g)}catch(h){if(h instanceof SyntaxError)throw new q(a.CIPHERTEXT_ENVELOPE_PARSE_ERROR,null,h);throw new q(a.DECRYPT_ERROR,null,h);}tc(c,uc.V1,{result:function(b){try{if(b.keyId!=e.id)throw new q(a.ENVELOPE_KEY_ID_MISMATCH);ma.decrypt(e.transform,e.privateKey,b.ciphertext).then(function(a){d.result(new Uint8Array(a))},
function(b){d.error(new q(a.DECRYPT_ERROR))})}catch(g){g instanceof k?d.error(g):d.error(new q(a.DECRYPT_ERROR,null,g))}},error:function(b){b instanceof A&&(b=new q(a.CIPHERTEXT_ENVELOPE_ENCODE_ERROR,null,b));b instanceof k||(b=new q(a.DECRYPT_ERROR,null,b));d.error(b)}})},this)},wrap:function(b,d){c(d,function(){if("nullOp"==this.wrapTransform||!this.publicKey)throw new q(a.WRAP_NOT_SUPPORTED,"no public key");ma.wrapKey("jwk",b.rawKey,this.publicKey,this.wrapTransform).then(function(a){d.result(new Uint8Array(a))},
function(b){d.error(new q(a.WRAP_ERROR))})},this)},unwrap:function(b,d,e,p){function g(b){c(p,function(){switch(b.type){case "secret":Ta(b,p);break;case "public":jb(b,p);break;case "private":lb(b,p);break;default:throw new q(a.UNSUPPORTED_KEY,"type: "+b.type);}})}c(p,function(){if("nullOp"==this.wrapTransform||!this.privateKey)throw new q(a.UNWRAP_NOT_SUPPORTED,"no private key");ma.unwrapKey("jwk",b,this.privateKey,this.privateKey.algorithm,d,!1,e).then(g,function(b){p.error(new q(a.UNWRAP_ERROR))})},
this)},sign:function(b,d){c(d,function(){if("nullOp"==this.algo)return new Uint8Array(0);if(!this.privateKey)throw new q(a.SIGN_NOT_SUPPORTED,"no private key");ma.sign(this.algo,this.privateKey,b).then(function(a){oc(new Uint8Array(a),{result:function(a){d.result(a.bytes)},error:d.error})},function(b){d.error(new q(a.SIGNATURE_ERROR))})},this)},verify:function(b,d,e){var p=this;c(e,function(){if("nullOp"==this.algo)return!0;if(!this.publicKey)throw new q(a.VERIFY_NOT_SUPPORTED,"no public key");pc(d,
qc.V1,{result:function(g){c(e,function(){var h=e.result;ma.verify(this.algo,this.publicKey,g.signature,b).then(h,function(b){e.error(new q(a.SIGNATURE_ERROR))})},p)},error:e.error})},this)}})})();var Jb;(function(){Jb=mb.extend({init:function Ja(a,b,c,p,g){Ja.base.call(this);c=c&&c.rawKey;p=p&&p.rawKey;g=g&&g.rawKey;Object.defineProperties(this,{ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},id:{value:b,writable:!1,enumerable:!1,configurable:!1},encryptionKey:{value:c,writable:!1,enumerable:!1,
configurable:!1},hmacKey:{value:p,writable:!1,enumerable:!1,configurable:!1},wrapKey:{value:g,writable:!1,enumerable:!1,configurable:!1}})},encrypt:function(b,d){var e=this;c(d,function(){if(!this.encryptionKey)throw new q(a.ENCRYPT_NOT_SUPPORTED,"no encryption/decryption key");if(0==b.length)return b;var c=new Uint8Array(16);this.ctx.getRandom().nextBytes(c);ma.encrypt({name:s.name,iv:c},e.encryptionKey,b).then(function(b){sc(e.id,c,new Uint8Array(b),{result:function(b){try{var h=JSON.stringify(b);
d.result(na(h,ca))}catch(c){d.error(new q(a.ENCRYPT_ERROR,null,c))}},error:function(b){b instanceof k||(b=new q(a.ENCRYPT_ERROR,null,b));d.error(b)}})},function(b){d.error(new q(a.ENCRYPT_ERROR))})},this)},decrypt:function(b,d){var e=this;c(d,function(){if(!this.encryptionKey)throw new q(a.DECRYPT_NOT_SUPPORTED,"no encryption/decryption key");if(0==b.length)return b;var c;try{var p=ka(b,ca);c=JSON.parse(p)}catch(g){if(g instanceof SyntaxError)throw new q(a.CIPHERTEXT_ENVELOPE_PARSE_ERROR,null,g);
throw new q(a.DECRYPT_ERROR,null,g);}tc(c,uc.V1,{result:function(b){try{if(b.keyId!=e.id)throw new q(a.ENVELOPE_KEY_ID_MISMATCH);ma.decrypt({name:s.name,iv:b.iv},e.encryptionKey,b.ciphertext).then(function(a){d.result(new Uint8Array(a))},function(){d.error(new q(a.DECRYPT_ERROR))})}catch(g){g instanceof k?d.error(g):d.error(new q(a.DECRYPT_ERROR,null,g))}},error:function(b){b instanceof A&&(b=new q(a.CIPHERTEXT_ENVELOPE_ENCODE_ERROR,null,b));b instanceof k||(b=new q(a.DECRYPT_ERROR,null,b));d.error(b)}})},
this)},wrap:function(b,d){c(d,function(){if(!this.wrapKey)throw new q(a.WRAP_NOT_SUPPORTED,"no wrap/unwrap key");ma.wrapKey("raw",b.rawKey,this.wrapKey,this.wrapKey.algorithm).then(function(a){d.result(new Uint8Array(a))},function(b){d.error(new q(a.WRAP_ERROR))})},this)},unwrap:function(b,d,e,I){function p(b){c(I,function(){switch(b.type){case "secret":Ta(b,I);break;case "public":jb(b,I);break;case "private":lb(b,I);break;default:throw new q(a.UNSUPPORTED_KEY,"type: "+b.type);}})}c(I,function(){if(!this.wrapKey)throw new q(a.UNWRAP_NOT_SUPPORTED,
"no wrap/unwrap key");ma.unwrapKey("raw",b,this.wrapKey,this.wrapKey.algorithm,d,!1,e).then(function(a){p(a)},function(b){I.error(new q(a.UNWRAP_ERROR))})},this)},sign:function(b,d){var e=this;c(d,function(){if(!this.hmacKey)throw new q(a.SIGN_NOT_SUPPORTED,"no HMAC key.");ma.sign(P,this.hmacKey,b).then(function(a){c(d,function(){oc(new Uint8Array(a),{result:function(a){d.result(a.bytes)},error:d.error})},e)},function(){d.error(new q(a.HMAC_ERROR))})},this)},verify:function(b,d,e){var I=this;c(e,
function(){if(!this.hmacKey)throw new q(a.VERIFY_NOT_SUPPORTED,"no HMAC key.");pc(d,qc.V1,{result:function(d){c(e,function(){var g=e.result;ma.verify(P,this.hmacKey,d.signature,b).then(g,function(b){e.error(new q(a.HMAC_ERROR))})},I)},error:e.error})},this)}})})();var ta=Jb.extend({init:function Ja(b,c,d,p,g){if(d||p||g)Ja.base.call(this,b,d+"_"+c.sequenceNumber,p,g,null);else{if(!c.isDecrypted())throw new Qa(a.MASTERTOKEN_UNTRUSTED,c);Ja.base.call(this,b,c.identity+"_"+c.sequenceNumber,c.encryptionKey,
c.hmacKey,null)}}}),Yd=mb.extend({encrypt:function(a,b){b.result(a)},decrypt:function(a,b){b.result(a)},wrap:function(a,b){b.error(new B("Wrap is unsupported by the MSL token crypto context."))},unwrap:function(a,b,c,d){d.error(new B("Unwrap is unsupported by the MSL token crypto context."))},sign:function(a,b){b.result(new Uint8Array(0))},verify:function(a,b,c){c.result(!1)}}),db,eb;(function(){var b=eb={RSA_OAEP:ya.name,A128KW:w.name};K="A128GCM";db=d.Class.create({init:function(a,c,d,p,g){switch(c){case b.RSA_OAEP:g=
g&&(g.rawKey||g);p=p&&(p.rawKey||p);break;case b.A128KW:g=p=p&&(p.rawKey||p);break;default:throw new B("Unsupported algorithm: "+c);}Object.defineProperties(this,{_ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},_algo:{value:c,writable:!1,enumerable:!1,configurable:!1},_enc:{value:d,writable:!1,enumerable:!1,configurable:!1},_wrapKey:{value:g,writable:!1,enumerable:!1,configurable:!1},_unwrapKey:{value:p,writable:!1,enumerable:!1,configurable:!1}})},encrypt:function(b,c){c.error(new q(a.ENCRYPT_NOT_SUPPORTED))},
decrypt:function(b,c){c.error(new q(a.DECRYPT_NOT_SUPPORTED))},wrap:function(b,d){c(d,function(){ma.wrapKey("jwe+jwk",b.rawKey,this._wrapKey,this._wrapKey.algorithm).then(function(a){d.result(new Uint8Array(a))},function(b){d.error(new q(a.WRAP_ERROR))})},this)},unwrap:function(b,d,e,p){function g(b){c(p,function(){switch(b.type){case "secret":Ta(b,p);break;case "public":jb(b,p);break;case "private":lb(b,p);break;default:throw new q(a.UNSUPPORTED_KEY,"type: "+b.type);}})}c(p,function(){ma.unwrapKey("jwe+jwk",
b,this._unwrapKey,this._unwrapKey.algorithm,d,!1,e).then(function(a){g(a)},function(){p.error(new q(a.UNWRAP_ERROR))})},this)},sign:function(b,c){c.error(new q(a.SIGN_NOT_SUPPORTED))},verify:function(b,c,d){d.error(new q(a.VERIFY_NOT_SUPPORTED))}})})();var $={PSK:"PSK",MGK:"MGK",X509:"X509",RSA:"RSA",NPTICKET:"NPTICKET",ECC:"ECC",NONE:"NONE"};Object.freeze($);var hb,Sc;(function(){hb=d.Class.create({init:function(a){Object.defineProperties(this,{scheme:{value:a,writable:!1,configurable:!1}})},getIdentity:function(){},
getAuthData:function(){},equals:function(a){return this===a?!0:a instanceof hb?this.scheme==a.scheme:!1},toJSON:function(){var a={};a.scheme=this.scheme;a.authdata=this.getAuthData();return a}});Sc=function(b,c){var d=c.scheme,e=c.authdata;if(!d||!e)throw new A(a.JSON_PARSE_ERROR,"entityauthdata "+JSON.stringify(c));if(!$[d])throw new $a(a.UNIDENTIFIED_ENTITYAUTH_SCHEME,d);var p=b.getEntityAuthenticationFactory(d);if(!p)throw new $a(a.ENTITYAUTH_FACTORY_NOT_FOUND,d);return p.createData(b,e)}})();
var Ua,Tc;(function(){Ua=hb.extend({init:function Ma(a){Ma.base.call(this,$.PSK);Object.defineProperties(this,{identity:{value:a,writable:!1}})},getIdentity:function(){return this.identity},getAuthData:function(){var a={};a.identity=this.identity;return a},equals:function ra(a){return this===a?!0:a instanceof Ua?ra.base.call(this,this,a)&&this.identity==a.identity:!1}});Tc=function(b){var c=b.identity;if(!c)throw new A(a.JSON_PARSE_ERROR,"psk authdata"+JSON.stringify(b));return new Ua(c)}})();var Zb,
Uc;(function(){Zb=hb.extend({init:function Ma(a,b){Ma.base.call(this,$.RSA);Object.defineProperties(this,{identity:{value:a,writable:!1,configurable:!1},publicKeyId:{value:b,writable:!1,configurable:!1}})},getIdentity:function(){return this.identity},getAuthData:function(){var a={};a.identity=this.identity;a.pubkeyid=this.publicKeyId;return a},equals:function ra(a){return this===a?!0:a instanceof Zb?ra.base.call(this,this,a)&&this.identity==a.identity&&this.publicKeyId==a.publicKeyId:!1}});Uc=function(b){var c=
b.identity,d=b.pubkeyid;if(!c||"string"!==typeof c||!d||"string"!==typeof d)throw new A(a.JSON_PARSE_ERROR,"RSA authdata"+JSON.stringify(b));return new Zb(c,d)}})();var Kb,Vc;(function(){Kb=hb.extend({init:function Ma(a){Ma.base.call(this,$.NONE);Object.defineProperties(this,{identity:{value:a,writable:!1}})},getIdentity:function(){return this.identity},getAuthData:function(){var a={};a.identity=this.identity;return a},equals:function ra(a){return this===a?!0:a instanceof Kb?ra.base.call(this,this,
a)&&this.identity==a.identity:!1}});Vc=function(b){var c=b.identity;if(!c)throw new A(a.JSON_PARSE_ERROR,"Unauthenticated authdata"+JSON.stringify(b));return new Kb(c)}})();var Lb=d.Class.create({init:function(a){Object.defineProperties(this,{scheme:{value:a,writable:!1,configurable:!1}})},createData:function(a,b){},getCryptoContext:function(a,b){}}),Wc;Wc=Lb.extend({init:function Ma(a){Ma.base.call(this,$.PSK);Object.defineProperties(this,{localIdentity:{value:a,writable:!1,enumerable:!1,configurable:!1}})},
createData:function(a,b){return Tc(b)},getCryptoContext:function(b,c){if(!(c instanceof Ua))throw new B("Incorrect authentication data type "+JSON.stringify(c)+".");if(c.getIdentity()!=this.localIdentity)throw(new $a(a.ENTITY_NOT_FOUND,"psk "+c.identity)).setEntity(c);return new zb}});var Zd=d.Class.create({init:function(){Object.defineProperties(this,{rsaKeys:{value:{},writable:!1,enumerable:!1,configurable:!1}})},addPublicKey:function(a,b){if(!(b instanceof Wb))throw new B("Incorrect key data type "+
b+".");this.rsaKeys[a]=b},getIdentities:function(){return Object.keys(this.rsaKeys)},removePublicKey:function(a){delete this.rsaKeys[a]},getPublicKey:function(a){return this.rsaKeys[a]}}),Xc=Lb.extend({init:function ra(a){ra.base.call(this,$.RSA);Object.defineProperties(this,{store:{value:a,writable:!1,enumerable:!1,configurable:!1}})},createData:function(a,b){return Uc(b)},getCryptoContext:function(b,c){if(!(c instanceof Zb))throw new B("Incorrect authentication data type "+c+".");var d=c.identity,
g=c.publicKeyId,h=this.store.getPublicKey(g);if(!h)throw(new $a(a.RSA_PUBLICKEY_NOT_FOUND,g)).setEntity(c);return new Xb(b,d,null,h,Yb.SIGN_VERIFY)}}),$d=Lb.extend({init:function I(){I.base.call(this,$.NONE)},createData:function(a,b){return Vc(b)},getCryptoContext:function(a,b){if(!(b instanceof Kb))throw new B("Incorrect authentication data type "+JSON.stringify(b)+".");return new zb}}),Yc=d.Class.create({abort:function(){},close:function(a,b){},mark:function(){},reset:function(){},markSupported:function(){},
read:function(a,b,g){}}),vc=d.Class.create({abort:function(){},close:function(a,b){},write:function(a,b,g,c,d){},flush:function(a,b){}}),ae=d.Class.create({init:function(a){Object.defineProperties(this,{_data:{value:a,writable:!1,enumerable:!1,configurable:!1},_closed:{value:!1,writable:!0,enumerable:!1,configurable:!1},_currentPosition:{value:0,writable:!0,enumerable:!1,configurable:!1},_mark:{value:-1,writable:!0,enumerable:!1,configurable:!1}})},abort:function(){},close:function(){this._closed=
!0},mark:function(){this._mark=this._currentPosition},reset:function(){if(-1==this._mark)throw new oa("Stream has not been marked.");this._currentPosition=this._mark},markSupported:function(){return!0},read:function(a,b,g){f(g,function(){if(this._closed)throw new oa("Stream is already closed.");if(this._currentPosition==this._data.length)return null;-1==a&&(a=this._data.length-this._currentPosition);var b=this._data.subarray(this._currentPosition,this._currentPosition+a);this._currentPosition+=b.length;
return b},this)}}),be=d.Class.create({init:function(){var a={_closed:{value:!1,writable:!0,enumerable:!1,configurable:!1},_result:{value:new Uint8Array(0),writable:!0,enuemrable:!1,configurable:!1},_buffered:{value:[],writable:!1,enumerable:!1,configurable:!1}};Object.defineProperties(this,a)},abort:function(){},close:function(a,b){this._closed=!0;b.result(!0)},write:function(a,b,g,c,d){f(d,function(){if(this._closed)throw new oa("Stream is already closed.");if(0>b)throw new RangeError("Offset cannot be negative.");
if(0>g)throw new RangeError("Length cannot be negative.");if(b+g>a.length)throw new RangeError("Offset plus length cannot be greater than the array length.");var c=a.subarray(b,g);this._buffered.push(c);return c.length},this)},flush:function(a,b){for(;0<this._buffered.length;){var g=this._buffered.shift();if(this._result){var c=new Uint8Array(this._result.length+g.length);c.set(this._result);c.set(g,this._result.length);this._result=c}else this._result=new Uint8Array(g)}b.result(!0)},size:function(){this.flush(1,
{result:function(){}});return this._result.length},toByteArray:function(){this.flush(1,{result:function(){}});return this._result}}),Zc=function(a,b,g){function c(a){a=new ClarinetParser(ka(a,"utf-8"));var b=[],g;for(g=a.nextValue();void 0!==g;)b.push(g),g=a.nextValue();return b}(function(a,b,c){a.read(-1,b,{result:function(a){a&&a.length?c(null,a):c(null,null)},timeout:function(){g.timeout()},error:function(a){c(a,null)}})})(a,b,function(b,l){b?g.error(b):l?void 0!==a.getJSON&&"function"===typeof a.getJSON?
g.result(a.getJSON()):g.result(c(l)):g.result(null)})},$c,ce=d.Class.create({getResponse:function(a,b,g){}});(function(){var a=vc.extend({init:function(a,b){var c={_httpLocation:{value:a,writable:!1,enumerable:!1,configurable:!1},_timeout:{value:b,writable:!0,enumerable:!1,configurable:!1},_buffer:{value:new be,writable:!1,enumerable:!1,configurable:!1},_response:{value:void 0,writable:!0,enumerable:!1,configurable:!1},_abortToken:{value:void 0,writable:!0,enumerable:!1,configurable:!1},_responseQueue:{value:new C,
writable:!0,enumerable:!1,configurable:!1},_aborted:{value:!1,writable:!0,enumerable:!1,configurable:!1}};Object.defineProperties(this,c)},setTimeout:function(a){this._timeout=a},getResponse:function(a,b){var c=this;this._responseQueue.poll(a,{result:function(a){f(b,function(){a&&this._responseQueue.add(a);return a},c)},timeout:function(){f(b,function(){this._response={isTimeout:!0};this._responseQueue.add(this._response);this.abort();b.timeout()},c)},error:function(a){f(b,function(){this._response=
{isError:!0};this._responseQueue.add(this._response);throw a;},c)}})},abort:function(){this._abortToken&&this._abortToken.abort();this._aborted=!0},close:function(a,b){var c=this;f(b,function(){if(this._response||this._abortToken||this._aborted)return!0;var a=this._buffer.toByteArray();0<a.length&&(this._abortToken=this._httpLocation.getResponse({body:a},this._timeout,{result:function(a){c._response={response:a};c._responseQueue.add(c._response)},timeout:function(){c._response={isTimeout:!0};c._responseQueue.add(c._response)},
error:function(a){c._response={isError:!0,error:a};c._responseQueue.add(c._response)}}));return!0},this)},write:function(a,b,c,d,p){f(p,function(){if(this._response)throw new oa("HttpOutputStream already closed.");this._buffer.write(a,b,c,d,p)},this)},flush:function(a,b){f(b,function(){if(this._response)return!0;this._buffer.flush(a,b)},this)}}),b=Yc.extend({init:function(a){Object.defineProperties(this,{_out:{value:a,writable:!1,enumerable:!1,configurable:!1},_buffer:{value:void 0,writable:!0,enumerable:!1,
configurable:!1},_exception:{value:void 0,writable:!0,enumerable:!1,configurable:!1},_timedout:{value:!1,writable:!0,enumerable:!1,configurable:!1},_aborted:{value:!1,writable:!0,enumerable:!1,configurable:!1},_json:{value:void 0,writable:!0,enumerable:!1,configurable:!1}})},abort:function(){this._out.abort()},close:function(a,b){f(b,function(){this._buffer&&this._buffer.close();return!0},this)},mark:function(){this._buffer||this._buffer.mark()},reset:function(){this._buffer&&this._buffer.reset()},
markSupported:function(){if(this._buffer)return this._buffer.markSupported()},read:function(a,b,c){function d(l){f(c,function(){if(!l)return new Uint8Array(0);this._out.getResponse(b,{result:function(d){f(c,function(){var l;if(d.isTimeout)this._timedout=!0,c.timeout();else{if(d.isError)throw this._exception=d.error||new oa("Unknown HTTP exception."),this._exception;if(!d.response)throw this._exception=new oa("Missing HTTP response."),this._exception;void 0!==d.response.json?(this._json=d.response.json,
this.getJSON=function(){return p._json},l=new Uint8Array([0])):l=d.response.content||Xa(d.response.body);this._buffer=new ae(l);this._buffer.read(a,b,c)}},p)},timeout:function(){c.timeout()},error:function(a){c.error(a)}})},p)}var p=this;f(c,function(){if(this._exception)throw this._exception;if(this._timedout)c.timeout();else{if(this._aborted)return new Uint8Array(0);this._buffer?this._buffer.read(a,b,c):this._out.close(b,{result:function(a){d(a)},timeout:function(){c.timeout()},error:function(a){c.error(a)}})}},
p)}});$c=d.Class.create({init:function(a,b){Object.defineProperties(this,{_httpLocation:{value:a,writable:!1,enumerable:!1,configurable:!1},_timeout:{value:b,writable:!0,enumerable:!1,configurable:!1}})},setTimeout:function(a){this._timeout=a},openConnection:function(){var c=new a(this._httpLocation,this._timeout);return{input:new b(c),output:c}}})})();var za={SYMMETRIC_WRAPPED:"SYMMETRIC_WRAPPED",ASYMMETRIC_WRAPPED:"ASYMMETRIC_WRAPPED",DIFFIE_HELLMAN:"DIFFIE_HELLMAN",JWE_LADDER:"JWE_LADDER",JWK_LADDER:"JWK_LADDER",
AUTHENTICATED_DH:"AUTHENTICATED_DH"};Object.freeze(za);var nb,ad;(function(){nb=d.Class.create({init:function(a){Object.defineProperties(this,{keyExchangeScheme:{value:a,writable:!1,configurable:!1}})},getKeydata:function(){},toJSON:function(){var a={};a.scheme=this.keyExchangeScheme;a.keydata=this.getKeydata();return a},equals:function(a){return this===a?!0:a instanceof nb?this.keyExchangeScheme==a.keyExchangeScheme:!1},uniqueKey:function(){return this.keyExchangeScheme}});ad=function(b,d,g){c(g,
function(){var c=d.scheme,m=d.keydata;if(!c||!m||"object"!==typeof m)throw new A(a.JSON_PARSE_ERROR,"keyrequestdata "+JSON.stringify(d));if(!za[c])throw new T(a.UNIDENTIFIED_KEYX_SCHEME,c);var l=b.getKeyExchangeFactory(c);if(!l)throw new T(a.KEYX_FACTORY_NOT_FOUND,c);l.createRequestData(b,m,g)})}})();var ob,bd;(function(){ob=d.Class.create({init:function(a,b){Object.defineProperties(this,{masterToken:{value:a,writable:!1,configurable:!1},keyExchangeScheme:{value:b,wrtiable:!1,configurable:!1}})},
getKeydata:function(){},toJSON:function(){var a={};a.mastertoken=this.masterToken;a.scheme=this.keyExchangeScheme;a.keydata=this.getKeydata();return a},equals:function(a){return this===a?!0:a instanceof ob?this.masterToken.equals(a.masterToken)&&this.keyExchangeScheme==a.keyExchangeScheme:!1},uniqueKey:function(){return this.masterToken.uniqueKey()+":"+this.keyExchangeScheme}});bd=function(b,d,g){c(g,function(){var h=d.mastertoken,m=d.scheme,l=d.keydata;if(!m||!h||"object"!==typeof h||!l||"object"!==
typeof l)throw new A(a.JSON_PARSE_ERROR,"keyresponsedata "+JSON.stringify(d));if(!za[m])throw new T(a.UNIDENTIFIED_KEYX_SCHEME,m);pb(b,h,{result:function(h){c(g,function(){var c=b.getKeyExchangeFactory(m);if(!c)throw new T(a.KEYX_FACTORY_NOT_FOUND,m);return c.createResponseData(b,h,l)})},error:function(a){g.error(a)}})})}})();var Ea;(function(){var b=d.Class.create({init:function(a,b){Object.defineProperties(this,{keyResponseData:{value:a,writable:!1,configurable:!1},cryptoContext:{value:b,writable:!1,
configurable:!1}})}});Ea=d.Class.create({init:function(a){Object.defineProperties(this,{scheme:{value:a,writable:!1,configurable:!1}})},createRequestData:function(a,b,c){},createResponseData:function(a,b,c){},generateResponse:function(a,b,c,d){},getCryptoContext:function(a,b,c,d,l){},generateSessionKeys:function(b,g){c(g,function(){var c=new Uint8Array(16),d=new Uint8Array(32);b.getRandom().nextBytes(c);b.getRandom().nextBytes(d);bb(c,s,ua,{result:function(b){bb(d,P,V,{result:function(a){g.result({encryptionKey:b,
hmacKey:a})},error:function(b){g.error(new q(a.SESSION_KEY_CREATION_FAILURE,null,b))}})},error:function(b){g.error(new q(a.SESSION_KEY_CREATION_FAILURE,null,b))}})})},importSessionKeys:function(a,b,c){bb(a,s,ua,{result:function(a){bb(b,P,V,{result:function(b){c.result({encryptionKey:a,hmacKey:b})},error:function(a){c.error(a)}})},error:function(a){c.error(a)}})}});Ea.KeyExchangeData=b})();var wc,xc,$b,cd;(function(){function b(c,g,h,n,m){switch(h){case d.JWE_RSA:case d.JWEJS_RSA:return new db(c,eb.RSA_OAEP,
K,n,m);case d.JWK_RSA:return new Xb(c,g,n,m,Yb.WRAP_UNWRAP_OAEP);case d.JWK_RSAES:return new Xb(c,g,n,m,Yb.WRAP_UNWRAP_PKCS1);default:throw new q(a.UNSUPPORTED_KEYX_MECHANISM,h);}}var d=xc={RSA:"RSA",ECC:"ECC",JWE_RSA:"JWE_RSA",JWEJS_RSA:"JWEJS_RSA",JWK_RSA:"JWK_RSA",JWK_RSAES:"JWK_RSAES"},g=$b=nb.extend({init:function t(a,b,c,g){t.base.call(this,za.ASYMMETRIC_WRAPPED);Object.defineProperties(this,{keyPairId:{value:a,writable:!1,configurable:!1},mechanism:{value:b,writable:!1,configurable:!1},publicKey:{value:c,
writable:!1,configurable:!1},privateKey:{value:g,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.keypairid=this.keyPairId;a.mechanism=this.mechanism;a.publickey=J(this.publicKey.getEncoded());return a},equals:function F(a){if(a===this)return!0;if(!(a instanceof $b))return!1;var b=this.privateKey===a.privateKey||this.privateKey&&a.privateKey&&ba(this.privateKey.getEncoded(),a.privateKey.getEncoded());return F.base.call(this,a)&&this.keyPairId==a.keyPairId&&this.mechanism==a.mechanism&&
ba(this.publicKey.getEncoded(),a.publicKey.getEncoded())&&b},uniqueKey:function n(){var a=this.publicKey.getEncoded(),b=this.privateKey&&this.privateKey.getEncoded(),a=n.base.call(this)+":"+this.keyPairId+":"+this.mechanism+":"+ja(a);b&&(a+=":"+ja(b));return a}}),h=function(b,h){c(h,function(){var c=b.keypairid,m=b.mechanism,f=b.publickey;if(!c||"string"!==typeof c||!m||!f||"string"!==typeof f)throw new A(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(b));if(!d[m])throw new T(a.UNIDENTIFIED_KEYX_MECHANISM,
m);try{var u=S(f);switch(m){case d.JWE_RSA:case d.JWEJS_RSA:case d.JWK_RSA:nc(u,ya,Fa,{result:function(a){h.result(new g(c,m,a,null))},error:function(a){h.error(a)}});break;case d.JWK_RSAES:nc(u,e,Fa,{result:function(a){h.result(new g(c,m,a,null))},error:function(a){h.error(a)}});break;default:throw new q(a.UNSUPPORTED_KEYX_MECHANISM,m);}}catch(x){if(!(x instanceof k))throw new q(a.INVALID_PUBLIC_KEY,"keydata "+JSON.stringify(b),x);throw x;}})},m=cd=ob.extend({init:function z(a,b,c,g){z.base.call(this,
a,za.ASYMMETRIC_WRAPPED);Object.defineProperties(this,{keyPairId:{value:b,writable:!1,configurable:!1},encryptionKey:{value:c,writable:!1,configurable:!1},hmacKey:{value:g,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.keypairid=this.keyPairId;a.encryptionkey=J(this.encryptionKey);a.hmackey=J(this.hmacKey);return a},equals:function D(a){return this===a?!0:a instanceof cd?D.base.call(this,a)&&this.keyPairId==a.keyPairId&&ba(this.encryptionKey,a.encryptionKey)&&ba(this.hmacKey,a.hmacKey):
!1},uniqueKey:function O(){return O.base.call(this)+":"+this.keyPairId+":"+ja(this.encryptionKey)+":"+ja(this.hmacKey)}});wc=Ea.extend({init:function W(){W.base.call(this,za.ASYMMETRIC_WRAPPED)},createRequestData:function(a,b,c){h(b,c)},createResponseData:function(b,c,g){b=g.keypairid;var h=g.encryptionkey,d=g.hmackey;if(!b||"string"!==typeof b||!h||"string"!==typeof h||!d||"string"!==typeof d)throw new A(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(g));var r;try{r=S(h)}catch(p){throw new q(a.INVALID_ENCRYPTION_KEY,
"keydata "+JSON.stringify(g),p);}var e;try{e=S(d)}catch(f){throw new q(a.INVALID_HMAC_KEY,"keydata "+JSON.stringify(g),f);}return new m(c,b,r,e)},generateResponse:function(a,h,d,p){function e(g,m){c(p,function(){var e=h,G=b(a,e.keyPairId,e.mechanism,null,e.publicKey);G.wrap(g,{result:function(a){c(p,function(){G.wrap(m,{result:function(b){r(g,a,m,b)},error:function(a){c(p,function(){a instanceof k&&d instanceof Da&&a.setEntity(d);throw a;},v)}})},v)},error:function(a){c(p,function(){a instanceof k&&
d instanceof Da&&a.setEntity(d);throw a;},v)}})},v)}function r(b,g,r,e){c(p,function(){var E=h,G=a.getTokenFactory();d instanceof Da?G.renewMasterToken(a,d,b,r,{result:function(b){c(p,function(){var c=new ta(a,b),h=new m(b,E.keyPairId,g,e);return new Ea.KeyExchangeData(h,c,p)},v)},error:function(a){c(p,function(){a instanceof k&&a.setEntity(d);throw a;},v)}}):G.createMasterToken(a,d,b,r,{result:function(b){c(p,function(){var c=new ta(a,b),h=new m(b,E.keyPairId,g,e);return new Ea.KeyExchangeData(h,
c,p)},v)},error:p.error})},v)}var v=this;c(p,function(){if(!(h instanceof g))throw new B("Key request data "+JSON.stringify(h)+" was not created by this factory.");this.generateSessionKeys(a,{result:function(a){e(a.encryptionKey,a.hmacKey)},error:function(a){c(p,function(){a instanceof k&&d instanceof Da&&a.setEntity(d);throw a;},v)}})},v)},getCryptoContext:function(h,d,p,e,G){var r=this;c(G,function(){if(!(d instanceof g))throw new B("Key request data "+JSON.stringify(d)+" was not created by this factory.");
if(!(p instanceof m))throw new B("Key response data "+JSON.stringify(p)+" was not created by this factory.");var v=d.keyPairId,f=p.keyPairId;if(v!=f)throw(new T(a.KEYX_RESPONSE_REQUEST_MISMATCH,"request "+v+"; response "+f)).setEntity(e);f=d.privateKey;if(!f)throw(new T(a.KEYX_PRIVATE_KEY_MISSING,"request Asymmetric private key")).setEntity(e);var Gb=b(h,v,d.mechanism,f,null);Gb.unwrap(p.encryptionKey,s,ua,{result:function(a){Gb.unwrap(p.hmacKey,P,V,{result:function(b){h.getEntityAuthenticationData(null,
{result:function(g){c(G,function(){var c=g.getIdentity();return new ta(h,p.masterToken,c,a,b)},r)},error:function(a){c(G,function(){a instanceof k&&a.setEntity(e);throw a;},r)}})},error:function(a){c(G,function(){a instanceof k&&a.setEntity(e);throw a;},r)}})},error:function(a){c(G,function(){a instanceof k&&a.setEntity(e);throw a;},r)}})},r)}})})();var dd,yc,ed,fd,gd,zc;(function(){var b=yc="entityauthdata",d=ed="mastertoken",g=fd="headerdata",h=gd="errordata",m=zc="signature";dd=function(l,t,e,
n){c(n,function(){var c=t[b],f=t[d],O=t[m];if(c&&"object"!==typeof c||f&&"object"!==typeof f||"string"!==typeof O)throw new A(a.JSON_PARSE_ERROR,"header/errormsg "+JSON.stringify(t));var W;try{W=S(O)}catch(u){throw new X(a.HEADER_SIGNATURE_INVALID,"header/errormsg "+JSON.stringify(t),u);}var x=null;c&&(x=Sc(l,c));var L=t[g];if(void 0!=L&&null!=L){if("string"!==typeof L)throw new A(a.JSON_PARSE_ERROR,"header/errormsg "+JSON.stringify(t));f?pb(l,f,{result:function(a){Ac(l,L,x,a,W,e,n)},error:function(a){n.error(a)}}):
Ac(l,L,x,null,W,e,n)}else if(c=t[h],void 0!=c&&null!=c){if("string"!==typeof c)throw new A(a.JSON_PARSE_ERROR,"header/errormsg "+JSON.stringify(t));hd(l,c,x,W,n)}else throw new A(a.JSON_PARSE_ERROR,JSON.stringify(t));})}})();var qb,id,hd;(function(){function e(a,b){this.errordata=a;this.signature=b}qb=d.Class.create({init:function(b,g,h,d,l,t,e,n,f,D){var O=this;c(D,function(){0>t&&(t=-1);if(0>d||d>Y)throw new B("Message ID "+d+" is out of range.");if(!g)throw new X(a.MESSAGE_ENTITY_NOT_FOUND);if(f)return Object.defineProperties(this,
{entityAuthenticationData:{value:g,writable:!1,configurable:!1},recipient:{value:h,writable:!1,configurable:!1},messageId:{value:d,writable:!1,configurable:!1},errorCode:{value:l,writable:!1,configurable:!1},internalCode:{value:t,writable:!1,configurable:!1},errorMessage:{value:e,writable:!1,configurable:!1},userMessage:{value:n,writable:!1,configurable:!1},errordata:{value:f.errordata,writable:!1,enumerable:!1,configurable:!1},signature:{value:f.signature,writable:!1,enumerable:!1,configurable:!1}}),
this;var W={};h&&(W.recipient=h);W.messageid=d;W.errorcode=l;0<t&&(W.internalcode=t);e&&(W.errormsg=e);n&&(W.usermsg=n);var u;try{u=b.getEntityAuthenticationFactory(g.scheme).getCryptoContext(b,g)}catch(x){throw x instanceof k&&(x.setEntity(g),x.setMessageId(d)),x;}W=na(JSON.stringify(W),ca);u.encrypt(W,{result:function(a){c(D,function(){u.sign(a,{result:function(b){c(D,function(){Object.defineProperties(this,{entityAuthenticationData:{value:g,writable:!1,configurable:!1},recipient:{value:h,writable:!1,
configurable:!1},messageId:{value:d,writable:!1,configurable:!1},errorCode:{value:l,writable:!1,configurable:!1},internalCode:{value:t,writable:!1,configurable:!1},errorMessage:{value:e,writable:!1,configurable:!1},userMessage:{value:n,writable:!1,configurable:!1},errordata:{value:a,writable:!1,enumerable:!1,configurable:!1},signature:{value:b,writable:!1,enumerable:!1,configurable:!1}});return this},O)},error:function(a){c(D,function(){a instanceof k&&(a.setEntity(g),a.setMessageId(d));throw a;},
O)}})},O)},error:function(a){c(D,function(){a instanceof k&&(a.setEntity(g),a.setMessageId(d));throw a;},O)}})},O)},toJSON:function(){var a={};a[yc]=this.entityAuthenticationData;a[gd]=J(this.errordata);a[zc]=J(this.signature);return a}});id=function(a,b,c,d,l,e,f,n,z){new qb(a,b,c,d,l,e,f,n,null,z)};hd=function(d,g,h,m,l){c(l,function(){if(!h)throw new X(a.MESSAGE_ENTITY_NOT_FOUND);var t;try{var f=h.scheme,n=d.getEntityAuthenticationFactory(f);if(!n)throw new $a(a.ENTITYAUTH_FACTORY_NOT_FOUND,f);
t=n.getCryptoContext(d,h)}catch(z){throw z instanceof k&&z.setEntity(h),z;}try{g=S(g)}catch(D){throw(new X(a.HEADER_DATA_INVALID,g,D)).setEntity(h);}if(!g||0==g.length)throw(new X(a.HEADER_DATA_MISSING,g)).setEntity(h);t.verify(g,m,{result:function(n){c(l,function(){if(!n)throw(new q(a.MESSAGE_VERIFICATION_FAILED)).setEntity(h);t.decrypt(g,{result:function(t){c(l,function(){var c=ka(t,ca),n;try{n=JSON.parse(c)}catch(f){if(f instanceof SyntaxError)throw(new A(a.JSON_PARSE_ERROR,"errordata "+c,f)).setEntity(h);
throw f;}var G=void 0!==n.recipient?n.recipient:null,r=parseInt(n.messageid),v=parseInt(n.errorcode),F=parseInt(n.internalcode),z=n.errormsg,O=n.usermsg;if(G&&"string"!==typeof G||!r||r!=r||!v||v!=v||n.internalcode&&F!=F||z&&"string"!==typeof z||O&&"string"!==typeof O)throw(new A(a.JSON_PARSE_ERROR,"errordata "+c)).setEntity(h);if(0>r||r>Y)throw(new X(a.MESSAGE_ID_OUT_OF_RANGE,"errordata "+c)).setEntity(h);n=!1;for(var D in b)if(b[D]==v){n=!0;break}n||(v=b.FAIL);if(F){if(0>F)throw(new X(a.INTERNAL_CODE_NEGATIVE,
"errordata "+c)).setEntity(h).setMessageId(r);}else F=-1;c=new e(g,m);new qb(d,h,G,r,v,F,z,O,c,l)})},error:function(a){c(l,function(){a instanceof k&&a.setEntity(h);throw a;})}})})},error:function(a){c(l,function(){a instanceof k&&a.setEntity(h);throw a;})}})})}})();var de=d.Class.create({getUserMessage:function(a,b){}}),Mb,jd,Bc;(function(){function b(a,c){var d={},e=[],l;for(l=0;l<a.length;++l)d[a[l]]=!0;for(l=0;l<c.length;++l)d[c[l]]&&e.push(c[l]);return e}Bc=function(a,c){if(!a||!c)return null;
var d=b(a.compressionAlgorithms,c.compressionAlgorithms),e=b(a.languages,c.languages);return new Mb(d,e)};Mb=d.Class.create({init:function(a,b){a||(a=[]);b||(b=[]);a.sort();Object.defineProperties(this,{compressionAlgorithms:{value:a,writable:!1,enumerable:!0,configurable:!1},languages:{value:b,writable:!1,enumerable:!0,configurable:!1}})},toJSON:function(){var a={};a.compressionalgos=this.compressionAlgorithms;a.languages=this.languages;return a},equals:function(a){return this===a?!0:a instanceof
Mb?Ga(this.compressionAlgorithms,a.compressionAlgorithms)&&(this.compressionAlgorithms.length==a.compressionAlgorithms.length||Ga(a.compressionAlgorithms,this.compressionAlgorithms))&&Ga(this.languages,a.languages)&&(this.languages.length==a.languages.length||Ga(a.languages,this.languages)):!1},uniqueKey:function(){return this.compressionAlgorithms.join(":")+"|"+this.languages.join(":")}});jd=function(b){var c=b.compressionalgos,d=b.languages;if(c&&!(c instanceof Array)||d&&!(d instanceof Array))throw new A(a.JSON_PARSE_ERROR,
"capabilities "+JSON.stringify(b));b=[];for(var e=0;c&&e<c.length;++e){var l=c[e];La[l]&&b.push(l)}return new Mb(b,d)}})();var Ab,kd,Ac,ld,md;(function(){function b(a,c,g,d,h,l){this.user=a;this.sender=c;this.messageCryptoContext=g;this.headerdata=d;this.signature=h;this.nonReplayable=l}function e(a,b,c,g,d,h,l,n,t,m,p,f,E,F,Ya,z,ha,D,Ba,k,Ca,Ha,Na){return{cryptoContext:{value:b,writable:!1,configurable:!1},user:{value:c,writable:!1,configurable:!1},entityAuthenticationData:{value:g,writable:!1,configurable:!1},
masterToken:{value:d,writable:!1,configurable:!1},sender:{value:h,writable:!1,configurable:!1},recipient:{value:l,writable:!1,configurable:!1},messageId:{value:n,writable:!1,configurable:!1},nonReplayableId:{value:ha,writable:!1,configurable:!1},keyRequestData:{value:t,writable:!1,configurable:!1},keyResponseData:{value:m,writable:!1,configurable:!1},userAuthenticationData:{value:p,writable:!1,configurable:!1},userIdToken:{value:f,writable:!1,configurable:!1},serviceTokens:{value:E,writable:!1,configurable:!1},
peerMasterToken:{value:F,writable:!1,configurable:!1},peerUserIdToken:{value:Ya,writable:!1,configurable:!1},peerServiceTokens:{value:z,writable:!1,configurable:!1},messageCapabilities:{value:Ca,writable:!1,configurable:!1},nonReplayable:{value:D,writable:!1,enumerable:!1,configurable:!1},renewable:{value:Ba,writable:!1,enumerable:!1,configurable:!1},handshake:{value:k,writable:!1,enumerable:!1,configurable:!1},headerdata:{value:Ha,writable:!1,enumerable:!1,configurable:!1},signature:{value:Na,writable:!1,
enumerable:!1,configurable:!1}}}function g(b,c,g){if(g){if(c=b.getMslStore().getCryptoContext(g))return c;if(!g.isVerified()||!g.isDecrypted())throw new Qa(a.MASTERTOKEN_UNTRUSTED,g);return new ta(b,g)}g=c.scheme;var d=b.getEntityAuthenticationFactory(g);if(!d)throw new $a(a.ENTITYAUTH_FACTORY_NOT_FOUND,g);return d.getCryptoContext(b,c)}function h(a,b,g){c(g,function(){if(b)bd(a,b,g);else return null})}function m(a,b,g,d){c(d,function(){if(b)rb(a,b,g,d);else return null})}function l(a,b,g,d){c(d,
function(){if(g)nd(a,b,g,d);else return null})}function t(b,g,d,h,l,e,r){function n(g,r,m){if(r>=g.length){var E=[],p;for(p in t)E.push(t[p]);m.result(E)}else{E=g[r];if("object"!==typeof E)throw new A(a.JSON_PARSE_ERROR,"headerdata "+e);Cc(b,E,d,h,l,{result:function(a){c(m,function(){t[a.uniqueKey()]=a;n(g,r+1,m)})},error:function(a){m.error(a)}})}}var t={};c(r,function(){if(g){if(!(g instanceof Array))throw new A(a.JSON_PARSE_ERROR,"headerdata "+e);n(g,0,r)}else return[]})}function f(b,g,d,h,l,e){function r(b,
g,d){c(d,function(){var c=g.peermastertoken;if(c&&"object"!==typeof c)throw new A(a.JSON_PARSE_ERROR,"headerdata "+l);if(!c)return null;pb(b,c,d)})}function n(b,g,d,h){c(h,function(){var c=g.peeruseridtoken;if(c&&"object"!==typeof c)throw new A(a.JSON_PARSE_ERROR,"headerdata "+l);if(!c)return null;rb(b,c,d,h)})}c(e,function(){if(!b.isPeerToPeer())return{peerMasterToken:null,peerUserIdToken:null,peerServiceTokens:[]};r(b,g,{result:function(a){c(e,function(){var r=d?d.masterToken:a;n(b,g,r,{result:function(d){c(e,
function(){t(b,g.peerservicetokens,r,d,h,l,{result:function(b){c(e,function(){return{peerMasterToken:a,peerUserIdToken:d,peerServiceTokens:b}})},error:function(a){c(e,function(){a instanceof k&&(a.setEntity(r),a.setUser(d));throw a;})}})})},error:function(a){c(e,function(){a instanceof k&&a.setEntity(r);throw a;})}})})},error:e.error})})}function n(b,g,d,h){function l(a,g){c(h,function(){if(g>=a.length)return e;ad(b,a[g],{result:function(b){c(h,function(){e.push(b);l(a,g+1)})},error:function(a){h.error(a)}})})}
var e=[];c(h,function(){var b=g.keyrequestdata;if(!b)return e;if(!(b instanceof Array))throw new A(a.JSON_PARSE_ERROR,"headerdata "+d);l(b,0)})}var z=ld=d.Class.create({init:function(a,b,c,g,d,h,l,e,n,t,m){Object.defineProperties(this,{recipient:{value:a,writable:!1,configurable:!1},messageId:{value:b,writable:!1,configurable:!1},nonReplayableId:{value:c,writable:!1,configurable:!1},renewable:{value:g,writable:!1,configurable:!1},handshake:{value:d,writable:!1,configurable:!1},capabilities:{value:h,
writable:!1,configurable:!1},keyRequestData:{value:l,writable:!1,configurable:!1},keyResponseData:{value:e,writable:!1,configurable:!1},userAuthData:{value:n,writable:!1,configurable:!1},userIdToken:{value:t,writable:!1,configurable:!1},serviceTokens:{value:m,writable:!1,configurable:!1}})}}),D=md=d.Class.create({init:function(a,b,c){Object.defineProperties(this,{peerMasterToken:{value:a,writable:!1,configurable:!1},peerUserIdToken:{value:b,writable:!1,configurable:!1},peerServiceTokens:{value:c,
writable:!1,configurable:!1}})}});Ab=d.Class.create({init:function(a,b,d,h,l,n,r){function t(f){c(r,function(){b=d?null:b;var t=h.nonReplayableId,F=!1,E=h.renewable,z=h.handshake,Ya=h.capabilities,v=h.recipient,ha=h.messageId,D=h.keyRequestData?h.keyRequestData:[],Ba=h.keyResponseData,Aa=h.userAuthData,Ca=h.userIdToken,Ha=h.serviceTokens?h.serviceTokens:[],Na,Oa,I;a.isPeerToPeer()?(Na=l.peerMasterToken,Oa=l.peerUserIdToken,I=l.peerServiceTokens?l.peerServiceTokens:[]):(Oa=Na=null,I=[]);if(0>ha||ha>
Y)throw new B("Message ID "+ha+" is out of range.");if(!b&&!d)throw new B("Message entity authentication data or master token must be provided.");var q,ab;Ba?a.isPeerToPeer()?(q=d,ab=Ba.masterToken):(q=Ba.masterToken,ab=Na):(q=d,ab=Na);if(Ca&&(!q||!Ca.isBoundTo(q)))throw new B("User ID token must be bound to a master token.");if(Oa&&(!ab||!Oa.isBoundTo(ab)))throw new B("Peer user ID token must be bound to a peer master token.");Ha.forEach(function(a){if(a.isMasterTokenBound()&&(!q||!a.isBoundTo(q)))throw new B("Master token bound service tokens must be bound to the provided master token.");
if(a.isUserIdTokenBound()&&(!Ca||!a.isBoundTo(Ca)))throw new B("User ID token bound service tokens must be bound to the provided user ID token.");},this);I.forEach(function(a){if(a.isMasterTokenBound()&&(!ab||!a.isBoundTo(ab)))throw new B("Master token bound peer service tokens must be bound to the provided peer master token.");if(a.isUserIdTokenBound()&&(!Oa||!a.isBoundTo(Oa)))throw new B("User ID token bound peer service tokens must be bound to the provided peer user ID token.");},this);if(n){var Hb=
n.user,Bb=n.messageCryptoContext,pa=n.headerdata,ac=n.signature,F=n.nonReplayable,pa=e(a,Bb,Hb,b,d,f,v,ha,D,Ba,Aa,Ca,Ha,Na,Oa,I,t,F,E,z,Ya,pa,ac);Object.defineProperties(this,pa);return this}var Hb=Ca?Ca.user:null,pa={};f&&(pa.sender=f);v&&(pa.recipient=v);pa.messageid=ha;pa.nonreplayable=F;"number"===typeof t&&(pa.nonreplayableid=t);pa.renewable=E;pa.handshake=z;Ya&&(pa.capabilities=Ya);0<D.length&&(pa.keyrequestdata=D);Ba&&(pa.keyresponsedata=Ba);Aa&&(pa.userauthdata=Aa);Ca&&(pa.useridtoken=Ca);
0<Ha.length&&(pa.servicetokens=Ha);Na&&(pa.peermastertoken=Na);Oa&&(pa.peeruseridtoken=Oa);0<I.length&&(pa.peerservicetokens=I);var Bb;try{Bb=g(a,b,d)}catch(sb){throw sb instanceof k&&(sb.setEntity(d),sb.setEntity(b),sb.setUser(Ca),sb.setUser(Aa),sb.setMessageId(ha)),sb;}pa=na(JSON.stringify(pa),ca);Bb.encrypt(pa,{result:function(g){c(r,function(){Bb.sign(g,{result:function(h){c(r,function(){var c=e(a,Bb,Hb,b,d,f,v,ha,D,Ba,Aa,Ca,Ha,Na,Oa,I,t,F,E,z,Ya,g,h);Object.defineProperties(this,c);return this},
m)},error:function(a){c(r,function(){a instanceof k&&(a.setEntity(d),a.setEntity(b),a.setUser(Ca),a.setUser(Aa),a.setMessageId(ha));throw a;},m)}})},m)},error:function(a){c(r,function(){a instanceof k&&(a.setEntity(d),a.setEntity(b),a.setUser(Ca),a.setUser(Aa),a.setMessageId(ha));throw a;},m)}})},m)}var m=this;c(r,function(){n?t(n.sender):d?a.getEntityAuthenticationData(null,{result:function(a){a=a.getIdentity();t(a)},error:r.error}):t(null)},m)},isEncrypting:function(){return this.masterToken||xb(this.entityAuthenticationData.scheme)},
isNonReplayable:function(){return this.nonReplayable},isRenewable:function(){return this.renewable},isHandshake:function(){return this.handshake},toJSON:function(){var a={};this.masterToken?a[ed]=this.masterToken:a[yc]=this.entityAuthenticationData;a[fd]=J(this.headerdata);a[zc]=J(this.signature);return a}});kd=function(a,b,c,g,d,h){new Ab(a,b,c,g,d,null,h)};Ac=function(d,e,p,x,L,G,r){function v(g,v){c(r,function(){var Z;try{Z=JSON.parse(v)}catch(la){if(la instanceof SyntaxError)throw(new A(a.JSON_PARSE_ERROR,
"headerdata "+v,la)).setEntity(x).setEntity(p);throw la;}var E=parseInt(Z.messageid);if(!E||E!=E)throw(new A(a.JSON_PARSE_ERROR,"headerdata "+v)).setEntity(x).setEntity(p);if(0>E||E>Y)throw(new X(a.MESSAGE_ID_OUT_OF_RANGE,"headerdata "+v)).setEntity(x).setEntity(p);var ic=x?Z.sender:null;if(x&&(!ic||"string"!==typeof ic))throw(new A(a.JSON_PARSE_ERROR,"headerdata "+v)).setEntity(x).setEntity(p).setMessageId(E);var Ya="undefined"!==Z.recipient?Z.recipient:null;if(Ya&&"string"!==typeof Ya)throw(new A(a.JSON_PARSE_ERROR,
"headerdata "+v)).setEntity(x).setEntity(p).setMessageId(E);var sa=Z.keyresponsedata;if(sa&&"object"!==typeof sa)throw(new A(a.JSON_PARSE_ERROR,"headerdata "+v)).setEntity(x).setEntity(p).setMessageId(E);var ha=r;r={result:function(a){ha.result(a)},error:function(a){a instanceof k&&(a.setEntity(x),a.setEntity(p),a.setMessageId(E));ha.error(a)}};h(d,sa,{result:function(h){c(r,function(){var ha=!d.isPeerToPeer()&&h?h.masterToken:x,sa=Z.useridtoken;if(sa&&"object"!==typeof sa)throw new A(a.JSON_PARSE_ERROR,
"headerdata "+v);m(d,sa,ha,{result:function(m){c(r,function(){var sa=Z.userauthdata;if(sa&&"object"!==typeof sa)throw new A(a.JSON_PARSE_ERROR,"headerdata "+v);l(d,ha,sa,{result:function(l){c(r,function(){var sa;if(l){var Aa=l.scheme,Ha=d.getUserAuthenticationFactory(Aa);if(!Ha)throw(new U(a.USERAUTH_FACTORY_NOT_FOUND,Aa)).setUser(m).setUser(l);Aa=x?x.identity:p.getIdentity();sa=Ha.authenticate(d,Aa,l,m)}else sa=m?m.user:null;t(d,Z.servicetokens,ha,m,G,v,{result:function(t){c(r,function(){var ha=
void 0!==Z.nonreplayableid?parseInt(Z.nonreplayableid):null,Ba=void 0!==Z.nonreplayable?Z.nonreplayable:!1,Aa=Z.renewable,ac=void 0!==Z.handshake?Z.handshake:!1;if(ha!=ha||"boolean"!==typeof Ba||"boolean"!==typeof Aa||"boolean"!==typeof ac)throw new A(a.JSON_PARSE_ERROR,"headerdata "+v);if(0>ha||ha>Y)throw new X(a.NONREPLAYABLE_ID_OUT_OF_RANGE,"headerdata "+v);var Ha=null,la=Z.capabilities;if(la){if("object"!==typeof la)throw new A(a.JSON_PARSE_ERROR,"headerdata "+v);Ha=jd(la)}n(d,Z,v,{result:function(a){f(d,
Z,h,G,v,{result:function(n){c(r,function(){var c=n.peerMasterToken,f=n.peerUserIdToken,v=n.peerServiceTokens,F=new z(Ya,E,ha,Aa,ac,Ha,a,h,l,m,t),c=new D(c,f,v),f=new b(sa,ic,g,e,L,Ba);new Ab(d,p,x,F,c,f,r)})},error:r.error})},error:function(a){c(r,function(){a instanceof k&&(a.setUser(m),a.setUser(l));throw a;})}})})},error:function(a){c(r,function(){a instanceof k&&(a.setEntity(ha),a.setUser(m),a.setUser(l));throw a;})}})})},error:r.error})})},error:r.error})})},error:r.error})})}c(r,function(){p=
x?null:p;if(!p&&!x)throw new X(a.MESSAGE_ENTITY_NOT_FOUND);var b=e;try{e=S(b)}catch(h){throw new X(a.HEADER_DATA_INVALID,b,h);}if(!e||0==e.length)throw new X(a.HEADER_DATA_MISSING,b);var l;try{l=g(d,p,x)}catch(n){throw n instanceof k&&(n.setEntity(x),n.setEntity(p)),n;}l.verify(e,L,{result:function(b){c(r,function(){if(!b){if(x)throw new q(a.MESSAGE_MASTERTOKENBASED_VERIFICATION_FAILED);throw new q(a.MESSAGE_ENTITYDATABASED_VERIFICATION_FAILED);}l.decrypt(e,{result:function(a){c(r,function(){var b=
ka(a,ca);v(l,b)})},error:function(a){r.error(a)}})})},error:function(a){r.error(a)}})})}})();var Gc,od,pd;(function(){function b(a,c){this.payload=a;this.signature=c}Gc=d.Class.create({init:function(a,b,d,e,l,t,f,n){var z=this;c(n,function(){if(0>a||a>Y)throw new B("Sequence number "+a+" is outside the valid range.");if(0>b||b>Y)throw new B("Message ID "+b+" is outside the valid range.");if(f)return Object.defineProperties(this,{sequenceNumber:{value:a,writable:!1,configurable:!1},messageId:{value:b,
writable:!1,configurable:!1},compressionAlgo:{value:e,writable:!1,configurable:!1},data:{value:l,writable:!1,configurable:!1},endofmsg:{value:d,writable:!1,enumerable:!1,configurable:!1},payload:{value:f.payload,writable:!1,enumerable:!1,configurable:!1},signature:{value:f.signature,writable:!1,enumerable:!1,configurable:!1}}),this;var D;e?(D=Hc(e,l),D||(e=null,D=l)):(e=null,D=l);var k={};k.sequencenumber=a;k.messageid=b;d&&(k.endofmsg=d);e&&(k.compressionalgo=e);k.data=J(D);D=na(JSON.stringify(k),
ca);t.encrypt(D,{result:function(f){c(n,function(){t.sign(f,{result:function(t){c(n,function(){Object.defineProperties(this,{sequenceNumber:{value:a,writable:!1,configurable:!1},messageId:{value:b,writable:!1,configurable:!1},compressionAlgo:{value:e,writable:!1,configurable:!1},data:{value:l,writable:!1,configurable:!1},endofmsg:{value:d,writable:!1,enumerable:!1,configurable:!1},payload:{value:f,writable:!1,enumerable:!1,configurable:!1},signature:{value:t,writable:!1,enumerable:!1,configurable:!1}});
return this},z)},error:function(a){n.error(a)}})},z)},error:function(a){n.error(a)}})},z)},isEndOfMessage:function(){return this.endofmsg},toJSON:function(){var a={};a.payload=J(this.payload);a.signature=J(this.signature);return a}});od=function(a,b,c,d,l,e,f){new Gc(a,b,c,d,l,e,null,f)};pd=function(d,g,h){c(h,function(){var e=d.payload,l=d.signature;if(!e||"string"!==typeof e||"string"!==typeof l)throw new A(a.JSON_PARSE_ERROR,"payload chunk "+JSON.stringify(d));var t,f;try{t=S(e)}catch(n){throw new X(a.PAYLOAD_INVALID,
"payload chunk "+JSON.stringify(d),n);}try{f=S(l)}catch(z){throw new X(a.PAYLOAD_SIGNATURE_INVALID,"payload chunk "+JSON.stringify(d),z);}g.verify(t,f,{result:function(d){c(h,function(){if(!d)throw new q(a.PAYLOAD_VERIFICATION_FAILED);g.decrypt(t,{result:function(d){c(h,function(){var c=ka(d,ca),l;try{l=JSON.parse(c)}catch(e){if(e instanceof SyntaxError)throw new A(a.JSON_PARSE_ERROR,"payload chunk payload "+c,e);throw e;}var n=parseInt(l.sequencenumber),m=parseInt(l.messageid),r=l.endofmsg,p=l.compressionalgo;
l=l.data;if(!n||n!=n||!m||m!=m||r&&"boolean"!==typeof r||p&&"string"!==typeof p||"string"!==typeof l)throw new A(a.JSON_PARSE_ERROR,"payload chunk payload "+c);if(0>n||n>Y)throw new k(a.PAYLOAD_SEQUENCE_NUMBER_OUT_OF_RANGE,"payload chunk payload "+c);if(0>m||m>Y)throw new k(a.PAYLOAD_MESSAGE_ID_OUT_OF_RANGE,"payload chunk payload "+c);r||(r=!1);if(p&&!La[p])throw new X(a.UNIDENTIFIED_COMPRESSION,p);var z;try{z=S(l)}catch(D){throw new X(a.PAYLOAD_DATA_CORRUPT,l,D);}if(z&&0!=z.length)c=p?bc(p,z):z;
else{if(0<l.length)throw new X(a.PAYLOAD_DATA_CORRUPT,l);if(r)c=new Uint8Array(0);else throw new X(a.PAYLOAD_DATA_MISSING,l);}z=new b(t,f);new Gc(n,m,r,p,c,g,z,h)})},error:function(a){h.error(a)}})})},error:function(a){h.error(a)}})})}})();var cc,tb,Cb,ub,qd,rd;(function(){function b(d,g,h,e,m){function p(){c(m,function(){W>=g.length&&(W=0,++f);if(f>=u.length){if(x)throw x;throw new T(a.KEYX_FACTORY_NOT_FOUND,JSON.stringify(g));}var b=u[f],h=g[W];b.scheme!=h.keyExchangeScheme?(++W,p()):b.generateResponse(d,
h,L,{result:function(a){m.result(a)},error:function(a){c(m,function(){if(!(a instanceof k))throw a;x=a;++W;p()})}})})}var f=0,W=0,u=d.getKeyExchangeFactories(),x,L=h?h:e;p()}function e(a,d,g,h,m){c(m,function(){var e=d.keyRequestData;if(d.isRenewable()&&0<e.length)h?h.isRenewable()||h.isExpired()||d.isNonReplayable()?b(a,e,h,null,m):a.getTokenFactory().isNewestMasterToken(a,h,{result:function(d){c(m,function(){if(d)return null;b(a,e,h,null,m)})},error:m.error}):b(a,e,null,g.getIdentity(),m);else return null})}
function g(b,d,g,h){c(h,function(){var c=d.userIdToken,e=d.userAuthenticationData,m=d.messageId;if(c&&c.isVerified()){if(c.isRenewable()&&d.isRenewable()||c.isExpired()||!c.isBoundTo(g)){e=b.getTokenFactory();e.renewUserIdToken(b,c,g,h);return}}else if(d.isRenewable()&&g&&e){c=d.user;if(!c){var c=e.scheme,p=b.getUserAuthenticationFactory(c);if(!p)throw(new U(a.USERAUTH_FACTORY_NOT_FOUND,c)).setEntity(g).setUser(e).setMessageId(m);c=p.authenticate(b,g.identity,e,null)}e=b.getTokenFactory();e.createUserIdToken(b,
c,g,h);return}return c})}var h=new Uint8Array(0),m=tb=function(a){if(0>a||a>Y)throw new B("Message ID "+a+" is outside the valid range.");return a==Y?0:a+1};Cb=function(a){if(0>a||a>Y)throw new B("Message ID "+a+" is outside the valid range.");return 0==a?Y:a-1};ub=function(a,b,d,g,h,e){c(e,function(){if(void 0==h||null==h){var m=a.getRandom();do h=m.nextLong();while(0>h||h>Y)}else if(0>h||h>Y)throw new B("Message ID "+h+" is outside the valid range.");a.getEntityAuthenticationData(null,{result:function(m){c(e,
function(){var c=a.getMessageCapabilities();return new cc(a,g,h,c,m,b,d,null,null,null,null,null)})},error:function(a){e.error(a)}})})};qd=function(a,b,d){c(d,function(){function h(a){c(d,function(){a instanceof k&&(a.setEntity(f),a.setEntity(D),a.setUser(O),a.setUser(W),a.setMessageId(x));throw a;})}var f=b.masterToken,D=b.entityAuthenticationData,O=b.userIdToken,W=b.userAuthenticationData,u=f?f.identity:D.getIdentity(),x=b.messageId,L=m(x);e(a,b,D,f,{result:function(e){c(d,function(){var m=e?e.keyResponseData.masterToken:
m=f;a.getEntityAuthenticationData(null,{result:function(p){c(d,function(){g(a,b,m,{result:function(g){c(d,function(){O=g;var c=Bc(b.messageCapabilities,a.getMessageCapabilities()),d=b.keyResponseData,h=b.serviceTokens;return a.isPeerToPeer()?new cc(a,u,L,c,p,d?d.masterToken:b.peerMasterToken,b.peerUserIdToken,b.peerServiceTokens,f,O,h,e):new cc(a,u,L,c,p,d?d.masterToken:f,O,h,null,null,null,e)})},error:h})})},error:h})})},error:h})})};rd=function(a,b,d,g,h,e){c(e,function(){a.getEntityAuthenticationData(null,
{result:function(p){c(e,function(){var c;if(void 0!=d&&null!=d)c=m(d);else{var f=a.getRandom();do c=f.nextInt();while(0>c||c>Y)}id(a,p,b,c,g.responseCode,g.internalCode,g.message,h,e)})},error:function(a){e.error(a)}})})};cc=d.Class.create({init:function(a,b,c,d,g,h,e,m,p,f,k,G){if(!a.isPeerToPeer()&&(p||f))throw new B("Cannot set peer master token or peer user ID token when not in peer-to-peer mode.");var r;r=G&&!a.isPeerToPeer()?G.keyResponseData.masterToken:h;var v={};a.getMslStore().getServiceTokens(r,
e).forEach(function(a){v[a.name]=a},this);m&&m.forEach(function(a){v[a.name]=a},this);var wa,Gb,Z={};a.isPeerToPeer()&&(wa=p,Gb=f,m=G?G.keyResponseData.masterToken:p,a.getMslStore().getServiceTokens(m,f).forEach(function(a){Z[a.name]=a},this),k&&k.forEach(function(a){Z[a.name]=a},this));Object.defineProperties(this,{_ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},_entityAuthData:{value:g,writable:!1,enumerable:!1,configurable:!1},_masterToken:{value:h,writable:!0,enumerable:!1,configurable:!1},
_recipient:{value:b,writable:!1,enumerable:!1,configurable:!1},_messageId:{value:c,writable:!1,enumerable:!1,configurable:!1},_capabilities:{value:d,writable:!1,enumerable:!1,configurable:!1},_keyExchangeData:{value:G,writable:!1,enumerable:!1,configurable:!1},_nonReplayable:{value:!1,writable:!0,enumerable:!1,configurable:!1},_handshake:{value:!1,writable:!0,enumerable:!1,configurable:!1},_renewable:{value:!1,writable:!0,enumerable:!1,configurable:!1},_keyRequestData:{value:{},writable:!1,enumerable:!1,
configurable:!1},_userAuthData:{value:null,writable:!0,enumerable:!1,configurable:!1},_userIdToken:{value:e,writable:!0,enumerable:!1,configurable:!1},_serviceTokens:{value:v,writable:!1,enumerable:!1,configurable:!1},_peerMasterToken:{value:wa,writable:!0,enumerable:!1,configurable:!1},_peerUserIdToken:{value:Gb,writable:!0,enumerable:!1,configurable:!1},_peerServiceTokens:{value:Z,writable:!1,enumerable:!1,configurable:!1}})},getMessageId:function(){return this._messageId},getMasterToken:function(){return this._masterToken},
getUserIdToken:function(){return this._userIdToken},getKeyExchangeData:function(){return this._keyExchangeData},willEncryptHeader:function(){return this._masterToken||xb(this._entityAuthData.scheme)},willEncryptPayloads:function(){return this._masterToken||!this._ctx.isPeerToPeer()&&this._keyExchangeData||xb(this._entityAuthData.scheme)},willIntegrityProtectHeader:function(){return this._masterToken||da(this._entityAuthData.scheme)},willIntegrityProtectPayloads:function(){return this._masterToken||
!this._ctx.isPeerToPeer()&&this._keyExchangeData||da(this._entityAuthData.scheme)},getHeader:function(b){c(b,function(){var c=this._keyExchangeData?this._keyExchangeData.keyResponseData:null,d=[],g;for(g in this._serviceTokens)d.push(this._serviceTokens[g]);var h=[],e;for(e in this._keyRequestData)h.push(this._keyRequestData[e]);if(this._nonReplayable){if(!this._masterToken)throw new X(a.NONREPLAYABLE_MESSAGE_REQUIRES_MASTERTOKEN);e=this._ctx.getMslStore().getNonReplayableId(this._masterToken)}else e=
null;c=new ld(this._recipient,this._messageId,e,this._renewable,this._handshake,this._capabilities,h,c,this._userAuthData,this._userIdToken,d);d=[];for(g in this._peerServiceTokens)d.push(this._peerServiceTokens[g]);g=new md(this._peerMasterToken,this._peerUserIdToken,d);kd(this._ctx,this._entityAuthData,this._masterToken,c,g,b)},this)},isNonReplayable:function(){return this._nonReplayable},setNonReplayable:function(a){if(this._nonReplayable=a)this._handshake=!1;return this},isRenewable:function(){return this._renewable},
setRenewable:function(a){this._renewable=a;this._renewable||(this._handshake=!1);return this},isHandshake:function(){return this._handshake},setHandshake:function(a){if(this._handshake=a)this._nonReplayable=!1,this._renewable=!0;return this},setAuthTokens:function(a,b){if(b&&!b.isBoundTo(a))throw new B("User ID token must be bound to master token.");if(this._keyExchangeData&&!this._ctx.isPeerToPeer())throw new B("Attempt to set message builder master token when key exchange data exists as a trusted network server.");
var c;try{c=this._ctx.getMslStore().getServiceTokens(a,b)}catch(d){if(d instanceof k)throw new B("Invalid master token and user ID token combination despite checking above.",d);throw d;}var g=[],h;for(h in this._serviceTokens)g.push(this._serviceTokens[h]);g.forEach(function(c){(c.isUserIdTokenBound()&&!c.isBoundTo(b)||c.isMasterTokenBound()&&!c.isBoundTo(a))&&delete this._serviceTokens[c.name]},this);c.forEach(function(a){this._serviceTokens[a.name]=a},this);this._masterToken=a;this._userIdToken=
b},setUserAuthenticationData:function(a){this._userAuthData=a;return this},setUser:function(a,b){var d=this;c(b,function(){if(!this._ctx.isPeerToPeer()&&null!=this._userIdToken||this._ctx.isPeerToPeer()&&null!=this._peerUserIdToken)throw new B("User ID token or peer user ID token already exists for the remote user.");var g;g=this._keyExchangeData?this._keyExchangeData.keyResponseData.masterToken:this._ctx.isPeerToPeer()?this._peerMasterToken:this._masterToken;if(!g)throw new B("User ID token or peer user ID token cannot be created because no corresponding master token exists.");
this._ctx.getTokenFactory().createUserIdToken(this._ctx,a,g,{result:function(a){c(b,function(){this._ctx.isPeerToPeer()?this._peerUserIdToken=a:(this._userIdToken=a,this._userAuthData=null);return!0},d)},error:function(a){b.error(a)}})},d)},addKeyRequestData:function(a){this._keyRequestData[a.uniqueKey()]=a;return this},removeKeyRequestData:function(a){delete this._keyRequestData[a.uniqueKey()];return this},addServiceToken:function(b){var c;c=this._keyExchangeData&&!this._ctx.isPeerToPeer()?this._keyExchangeData.keyResponseData.masterToken:
this._masterToken;if(b.isMasterTokenBound()&&!b.isBoundTo(c))throw(new X(a.SERVICETOKEN_MASTERTOKEN_MISMATCH,"st "+JSON.stringify(b)+"; mt "+JSON.stringify(c))).setEntity(c);if(b.isUserIdTokenBound()&&!b.isBoundTo(this._userIdToken))throw(new X(a.SERVICETOKEN_USERIDTOKEN_MISMATCH,"st "+JSON.stringify(b)+"; uit "+JSON.stringify(this._userIdToken))).setEntity(c).setUser(this._userIdToken);this._serviceTokens[b.name]=b;return this},addServiceTokenIfAbsent:function(a){this._serviceTokens[a.name]||this.addServiceToken(a);
return this},excludeServiceToken:function(a){delete this._serviceTokens[a];return this},deleteServiceToken:function(a,b){var d=this;c(b,function(){var g=this._serviceTokens[a];if(!g)return this;var e=g.isMasterTokenBound()?this._masterToken:null,g=g.isUserIdTokenBound()?this._userIdToken:null;fb(this._ctx,a,h,e,g,!1,null,new zb,{result:function(a){c(b,function(){return this.addServiceToken(a)},d)},error:function(a){a instanceof k&&(a=new B("Failed to create and add empty service token to message.",
a));b.error(a)}})},d)},getServiceTokens:function(){var a=[],b;for(b in this._serviceTokens)a.push(this._serviceTokens[b]);return a},getPeerMasterToken:function(){return this._peerMasterToken},getPeerUserIdToken:function(){return this._peerUserIdToken},setPeerAuthTokens:function(b,c){if(!this._ctx.isPeerToPeer())throw new B("Cannot set peer master token or peer user ID token when not in peer-to-peer mode.");if(c&&!b)throw new B("Peer master token cannot be null when setting peer user ID token.");if(c&&
!c.isBoundTo(b))throw(new X(a.USERIDTOKEN_MASTERTOKEN_MISMATCH,"uit "+c+"; mt "+b)).setEntity(b).setUser(c);var d;try{d=this._ctx.getMslStore().getServiceTokens(b,c)}catch(g){if(g instanceof k)throw new B("Invalid peer master token and user ID token combination despite proper check.",g);throw g;}Object.keys(this._peerServiceTokens).forEach(function(a){var d=this._peerServiceTokens[a];d.isUserIdTokenBound()&&!d.isBoundTo(c)?delete this._peerServiceTokens[a]:d.isMasterTokenBound()&&!d.isBoundTo(b)&&
delete this._peerServiceTokens[a]},this);d.forEach(function(a){var b=a.name;this._peerServiceTokens[b]||(this._peerServiceTokens[b]=a)},this);this._peerUserIdToken=c;this._peerMasterToken=b;return this},addPeerServiceToken:function(b){if(!this._ctx.isPeerToPeer())throw new B("Cannot set peer service tokens when not in peer-to-peer mode.");if(b.isMasterTokenBound()&&!b.isBoundTo(this._peerMasterToken))throw(new X(a.SERVICETOKEN_MASTERTOKEN_MISMATCH,"st "+JSON.stringify(b)+"; mt "+JSON.stringify(this._peerMasterToken))).setEntity(this._peerMasterToken);
if(b.isUserIdTokenBound()&&!b.isBoundTo(this._peerUserIdToken))throw(new X(a.SERVICETOKEN_USERIDTOKEN_MISMATCH,"st "+JSON.stringify(b)+"; uit "+JSON.stringify(this._peerUserIdToken))).setEntity(this._peerMasterToken).setUser(this._peerUserIdToken);this._peerServiceTokens[b.name]=b;return this},addPeerServiceTokenIfAbsent:function(a){this._peerServiceTokens[a.name]||this.addPeerServiceToken(a);return this},excludePeerServiceToken:function(a){delete this._peerServiceTokens[a];return this},deletePeerServiceToken:function(a,
b){var d=this;c(b,function(){var g=this._peerServiceTokens[a];if(!g)return this;var e=g.isMasterTokenBound()?this._peerMasterToken:null,g=g.isUserIdTokenBound()?this._peerUserIdToken:null;fb(this._ctx,a,h,e,g,!1,null,new zb,{result:function(a){c(b,function(){return this.addPeerServiceToken(a)},d)},error:function(a){a instanceof k&&(a=new B("Failed to create and add empty peer service token to message.",a));b.error(a)}})},d)},getPeerServiceTokens:function(){var a=[],b;for(b in this._peerServiceTokens)a.push(this._peerServiceTokens[b]);
return a}})})();var sd;(function(){function a(b,c){return c[b]?c[b]:c[""]}function b(a){var c=a.builder.getKeyExchangeData();return c&&!a.ctx.isPeerToPeer()?c.keyResponseData.masterToken:a.builder.getMasterToken()}sd=d.Class.create({init:function(a,b,c){a={ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},cryptoContexts:{value:b.getCryptoContexts(),writable:!1,enumerable:!1,configurable:!1},builder:{value:c,writable:!1,enumerable:!1,configurable:!1}};Object.defineProperties(this,a)},isPrimaryMasterTokenAvailable:function(){return b(this)?
!0:!1},isPrimaryUserIdTokenAvailable:function(){return this.builder.getUserIdToken()?!0:!1},isPeerMasterTokenAvailable:function(){return this.builder.getPeerMasterToken()?!0:!1},isPeerUserIdTokenAvailable:function(){return this.builder.getPeerUserIdToken()?!0:!1},getPrimaryServiceTokens:function(){return this.builder.getServiceTokens()},getPeerServiceTokens:function(){return this.builder.getPeerServiceTokens()},addPrimaryServiceToken:function(a){try{return this.builder.addServiceToken(a),!0}catch(b){if(b instanceof
X)return!1;throw b;}},addPeerServiceToken:function(a){try{return this.builder.addPeerServiceToken(a),!0}catch(b){if(b instanceof X)return!1;throw b;}},addUnboundPrimaryServiceToken:function(b,d,e,l,p){var f=this;c(p,function(){var n=a(b,this.cryptoContexts);if(!n)return!1;fb(this.ctx,b,d,null,null,e,l,n,{result:function(a){c(p,function(){try{this.builder.addServiceToken(a)}catch(b){if(b instanceof X)throw new B("Service token bound to incorrect authentication tokens despite being unbound.",b);throw b;
}return!0},f)},error:function(a){p.error(a)}})},f)},addUnboundPeerServiceToken:function(b,d,e,l,p){var f=this;c(p,function(){var n=a(b,this.cryptoContexts);if(!n)return!1;fb(this.ctx,b,d,null,null,e,l,n,{result:function(a){c(p,function(){try{this.builder.addPeerServiceToken(a)}catch(b){if(b instanceof X)throw new B("Service token bound to incorrect authentication tokens despite being unbound.",b);throw b;}return!0},f)},error:function(a){p.error(a)}})},f)},addMasterBoundPrimaryServiceToken:function(d,
h,e,l,f){var k=this;c(f,function(){var n=b(this);if(!n)return!1;var z=a(d,this.cryptoContexts);if(!z)return!1;fb(this.ctx,d,h,n,null,e,l,z,{result:function(a){c(f,function(){try{this.builder.addServiceToken(a)}catch(b){if(b instanceof X)throw new B("Service token bound to incorrect authentication tokens despite setting correct master token.",b);throw b;}return!0},k)},error:function(a){f.error(a)}})},k)},addMasterBoundPeerServiceToken:function(b,d,e,l,p){var f=this;c(p,function(){var n=this.builder.getPeerMasterToken();
if(!n)return!1;var k=a(b,this.cryptoContexts);if(!k)return!1;fb(this.ctx,b,d,n,null,e,l,k,{result:function(a){c(p,function(){try{this.builder.addPeerServiceToken(a)}catch(b){if(b instanceof X)throw new B("Service token bound to incorrect authentication tokens despite setting correct master token.",b);throw b;}return!0},f)},error:function(a){p.error(a)}})},f)},addUserBoundPrimaryServiceToken:function(d,h,e,l,f){var k=this;c(f,function(){var n=b(this);if(!n)return!1;var z=this.builder.getUserIdToken();
if(!z)return!1;var D=a(d,this.cryptoContexts);if(!D)return!1;fb(this.ctx,d,h,n,z,e,l,D,{result:function(a){c(f,function(){try{this.builder.addServiceToken(a)}catch(b){if(b instanceof X)throw new B("Service token bound to incorrect authentication tokens despite setting correct master token and user ID token.",b);throw b;}return!0},k)},error:function(a){f.error(a)}})},k)},addUserBoundPeerServiceToken:function(b,d,e,l,p){var f=this;c(p,function(){var n=this.builder.getPeerMasterToken();if(!n)return!1;
var k=this.builder.getPeerUserIdToken();if(!k)return!1;var D=a(b,this.cryptoContexts);if(!D)return!1;fb(this.ctx,b,d,n,k,e,l,D,{result:function(a){c(p,function(){try{this.builder.addPeerServiceToken(a)}catch(b){if(b instanceof X)throw new B("Service token bound to incorrect authentication tokens despite setting correct master token and user ID token.",b);throw b;}return!0},f)},error:function(a){p.error(a)}})},f)},excludePrimaryServiceToken:function(a){for(var b=this.builder.getServiceTokens(),c=0;c<
b.length;++c)if(b[c].name==a)return this.builder.excludeServiceToken(a),!0;return!1},excludePeerServiceToken:function(a){for(var b=this.builder.getPeerServiceTokens(),c=0;c<b.length;++c)if(b[c].name==a)return this.builder.excludePeerServiceToken(a),!0;return!1},deletePrimaryServiceToken:function(a,b){c(b,function(){for(var c=this.builder.getServiceTokens(),d=0;d<c.length;++d)if(c[d].name==a){this.builder.deleteServiceToken(a,{result:function(){b.result(!0)},error:function(a){b.error(a)}});return}return!1},
this)},deletePeerServiceToken:function(a,b){c(b,function(){for(var c=this.builder.getPeerServiceTokens(),d=0;d<c.length;++d)if(c[d].name==a){this.builder.deletePeerServiceToken(a,{result:function(){b.result(!0)},error:function(a){b.error(a)}});return}return!1},this)}})})();var td,ud;(function(){function b(d,g,h,e){c(e,function(){function b(){c(e,function(){if(O>=h.length){if(D)throw D;throw new T(a.KEYX_RESPONSE_REQUEST_MISMATCH,JSON.stringify(h));}var g=h[O];n!=g.keyExchangeScheme?(++O,b()):z.getCryptoContext(d,
g,F,f,{result:e.result,error:function(a){c(e,function(){if(!(a instanceof k))throw a;D=a;++O;b()})}})})}var f=g.masterToken,F=g.keyResponseData;if(!F)return null;var n=F.keyExchangeScheme,z=d.getKeyExchangeFactory(n);if(!z)throw new T(a.KEYX_FACTORY_NOT_FOUND,n);var D,O=0;b()})}td=Yc.extend({init:function(c,d,h,e,l,t,F){var n=this;f(F,function(){function f(){n._ready=!0;n._readyQueue.add(!0)}function F(a,b){try{var c=b.masterToken;a.getTokenFactory().isMasterTokenRevoked(a,c,{result:function(d){d?
(n._errored=(new Qa(d,c)).setUser(b.userIdToken).setUser(b.userAuthenticationData).setMessageId(b.messageId),f()):O(a,b)},error:function(a){a instanceof k&&(a.setEntity(b.masterToken),a.setUser(b.userIdToken),a.setUser(b.userAuthenticationData),a.setMessageId(b.messageId));n._errored=a;f()}})}catch(d){d instanceof k&&(d.setEntity(b.masterToken),d.setUser(b.userIdToken),d.setUser(b.userAuthenticationData),d.setMessageId(b.messageId)),n._errored=d,f()}}function O(a,b){try{var c=b.masterToken,d=b.userIdToken;
d?a.getTokenFactory().isUserIdTokenRevoked(a,c,d,{result:function(g){g?(n._errored=(new MslUserIdTokenException(g,d)).setEntity(c).setUser(d).setMessageId(b.messageId),f()):W(a,b)},error:function(a){a instanceof k&&(a.setEntity(b.masterToken),a.setUser(b.userIdToken),a.setUser(b.userAuthenticationData),a.setMessageId(b.messageId));n._errored=a;f()}}):W(a,b)}catch(g){g instanceof k&&(g.setEntity(b.masterToken),g.setUser(b.userIdToken),g.setUser(b.userAuthenticationData),g.setMessageId(b.messageId)),
n._errored=g,f()}}function W(b,c){try{var d=c.masterToken;d.isExpired()?c.isRenewable()&&0!=c.keyRequestData.length?b.getTokenFactory().isMasterTokenRenewable(b,d,{result:function(a){a?(n._errored=(new X(a,"Master token is expired and not renewable.")).setEntity(d).setUser(c.userIdToken).setUser(c.userAuthenticationData).setMessageId(c.messageId),f()):u(b,c)},error:function(a){a instanceof k&&(a.setEntity(c.masterToken),a.setUser(c.userIdToken),a.setUser(c.userAuthenticationData),a.setMessageId(c.messageId));
n._errored=a;f()}}):(n._errored=(new X(a.MESSAGE_EXPIRED,JSON.stringify(c))).setEntity(d).setUser(c.userIdToken).setUser(c.userAuthenticationData).setMessageId(c.messageId),f()):u(b,c)}catch(g){g instanceof k&&(g.setEntity(c.masterToken),g.setUser(c.userIdToken),g.setUser(c.userAuthenticationData),g.setMessageId(c.messageId)),n._errored=g,f()}}function u(b,c){try{var d=c.masterToken;c.isNonReplayable()?c.isRenewable()&&0!=c.keyRequestData.length&&d?b.getTokenFactory().isNewestMasterToken(b,d,{result:function(g){g?
x(b,c):(n._errored=(new X(a.MESSAGE_REPLAYED,JSON.stringify(c))).setEntity(d).setUser(c.userIdToken).setUser(c.userAuthenticationData).setMessageId(c.messageId),f())},error:function(a){a instanceof k&&(a.setEntity(d),a.setUser(c.userIdToken),a.setUser(c.userAuthenticationData),a.setMessageId(c.messageId));n._errored=a;f()}}):(n._errored=(new X(a.INCOMPLETE_NONREPLAYABLE_MESSAGE,JSON.stringify(c))).setEntity(d).setEntity(c.entityAuthenticationData).setUser(c.userIdToken).setUser(c.userAuthenticationData).setMessageId(c.messageId),
f()):x(b,c)}catch(g){g instanceof k&&(g.setEntity(c.masterToken),g.setEntity(c.entityAuthenticationData),g.setUser(c.userIdToken),g.setUser(c.userAuthenticationData),g.setMessageId(c.messageId)),n._errored=g,f()}}function x(b,c){try{var d=c.masterToken,g=c.nonReplayableId;"number"===typeof g?d?b.getTokenFactory().acceptNonReplayableId(b,d,g,{result:function(b){b||(n._errored=(new X(a.MESSAGE_REPLAYED,JSON.stringify(c))).setEntity(d).setUser(c.userIdToken).setUser(c.userAuthenticationData).setMessageId(c.messageId));
f()},error:function(a){a instanceof k&&(a.setEntity(d),a.setUser(c.userIdToken),a.setUser(c.userAuthenticationData),a.setMessageId(c.messageId));n._errored=a;f()}}):(n._errored=(new X(a.INCOMPLETE_NONREPLAYABLE_MESSAGE,JSON.stringify(c))).setEntity(c.entityAuthenticationData).setUser(c.userIdToken).setUser(c.userAuthenticationData).setMessageId(c.messageId),f()):f()}catch(h){h instanceof k&&(h.setEntity(c.masterToken),h.setEntity(c.entityAuthenticationData),h.setUser(c.userIdToken),h.setUser(c.userAuthenticationData),
h.setMessageId(c.messageId)),n._errored=h,f()}}var L={_source:{value:d,writable:!1,enumerable:!1,configurable:!1},_parser:{value:void 0,writable:!0,enumerable:!1,configurable:!1},_charset:{value:h,writable:!1,enumerable:!1,configurable:!1},_remainingData:{value:"",writable:!0,enumerable:!1,configurable:!1},_timeout:{value:t,writable:!1,enumerable:!1,configurable:!1},_header:{value:void 0,writable:!0,enumerable:!1,configurable:!1},_cryptoContext:{value:void 0,writable:!0,enumerable:!1,configurable:!1},
_keyxCryptoContext:{value:void 0,writable:!0,enumerable:!1,configurable:!1},_payloadSequenceNumber:{value:1,writable:!0,enuemrable:!1,configurable:!1},_eom:{value:!1,writable:!0,enumerable:!1,configurable:!1},_handshake:{value:null,writable:!0,enumerable:!1,configurable:!1},_closeSource:{value:!1,writable:!0,enumerable:!1,configurable:!1},_payloads:{value:[],writable:!0,enumerable:!1,configurable:!1},_payloadIndex:{value:-1,writable:!0,enumerable:!1,configurable:!1},_payloadOffset:{value:0,writable:!0,
enuemrable:!1,configurable:!1},_markOffset:{value:0,writable:!0,enumerable:!1,configurable:!1},_currentPayload:{value:null,writable:!0,enumerable:!1,configurable:!1},_readException:{value:null,writable:!0,enumerable:!1,configurable:!1},_ready:{value:!1,writable:!0,enumerable:!1,configurable:!1},_readyQueue:{value:new C,writable:!1,enumerable:!1,configurable:!1},_aborted:{value:!1,writable:!0,enumerable:!1,configurable:!1},_timedout:{value:!1,writable:!0,enumerable:!1,configurable:!1},_errored:{value:null,
writable:!0,enumerable:!1,configurable:!1}};Object.defineProperties(this,L);Zc(n._source,t,{result:function(d){n._json=d;n._jsonIndex=0;null===n._json?(n._errored=new A(a.MESSAGE_DATA_MISSING),f()):dd(c,n._json[n._jsonIndex++],l,{result:function(d){n._header=d;if(n._header instanceof qb)n._keyxCryptoContext=null,n._cryptoContext=null,f();else{var g=n._header;b(c,g,e,{result:function(b){try{n._keyxCryptoContext=b;c.isPeerToPeer()||!n._keyxCryptoContext?n._cryptoContext=g.cryptoContext:n._cryptoContext=
n._keyxCryptoContext;try{if(g.isHandshake()&&(!g.isRenewable()||0==g.keyRequestData.length))throw new X(a.HANDSHAKE_DATA_MISSING,JSON.stringify(g));try{var d=g.masterToken;d&&(c.isPeerToPeer()||d.isVerified())?F(c,g):u(c,g)}catch(h){h instanceof k&&(h.setEntity(g.masterToken),h.setUser(g.userIdToken),h.setUser(g.userAuthenticationData),h.setMessageId(g.messageId)),n._errored=h,f()}}catch(e){e instanceof k&&(e.setEntity(g.masterToken),e.setEntity(g.entityAuthenticationData),e.setUser(g.userIdToken),
e.setUser(g.userAuthenticationData),e.setMessageId(g.messageId)),n._errored=e,f()}}catch(l){l instanceof k&&(l.setEntity(g.masterToken),l.setEntity(g.entityAuthenticationData),l.setUser(g.userIdToken),l.setUser(g.userAuthenticationData),l.setMessageId(g.messageId)),n._errored=l,f()}},error:function(a){a instanceof k&&(a.setEntity(g.masterToken),a.setEntity(g.entityAuthenticationData),a.setUser(g.userIdToken),a.setUser(g.userAuthenticationData),a.setMessageId(g.messageId));n._errored=a;f()}})}},error:function(a){n._errored=
a;f()}})},timeout:function(){n._timedout=!0;f()},error:function(a){n._errored=a;f()}});return this},n)},nextData:function(b,c){var d=this;f(c,function(){function b(a){f(a,function(){var c;if(this._jsonIndex<this._json.length)return c=this._json[this._jsonIndex++];Zc(this._source,this._timeout,{result:function(c){c&&c.length&&0<c.length?(c.forEach(function(a){this._json.push(a)}),b(a)):(this._eom=!0,a.result(null))},timeout:a.timeout,error:a.error})},d)}var e=this.getMessageHeader();if(!e)throw new B("Read attempted with error message.");
if(-1!=this._payloadIndex&&this._payloadIndex<this._payloads.length)return this._payloads[this._payloadIndex++];if(this._eom)return null;b({result:function(b){f(c,function(){if(!b)return null;if("object"!==typeof b)throw new A(a.MESSAGE_FORMAT_ERROR);pd(b,this._cryptoContext,{result:function(b){f(c,function(){var c=e.masterToken,d=e.entityAuthenticationData,g=e.userIdToken,h=e.getUserAuthenticationData;if(b.messageId!=e.messageId)throw(new X(a.PAYLOAD_MESSAGE_ID_MISMATCH,"payload mid "+b.messageId+
" header mid "+e.messageId)).setEntity(c).setEntity(d).setUser(g).setUser(h);if(b.sequenceNumber!=this._payloadSequenceNumber)throw(new X(a.PAYLOAD_SEQUENCE_NUMBER_MISMATCH,"payload seqno "+b.sequenceNumber+" expected seqno "+this._payloadSequenceNumber)).setEntity(c).setEntity(d).setUser(g).setUser(h);++this._payloadSequenceNumber;null==this._handshake&&(this._handshake=e.isRenewable()&&0<e.keyRequestData.length&&b.isEndOfMessage()&&0==b.data.length);b.isEndOfMessage()&&(this._eom=!0);c=b.data;this._payloads.push(c);
this._payloadIndex=-1;return c},d)},error:function(b){b instanceof SyntaxError&&(b=new A(a.JSON_PARSE_ERROR,"payloadchunk",b));c.error(b)}})},d)},timeout:function(){c.timeout()},error:function(a){c.error(a)}})},d)},isReady:function(a,b){function c(){f(b,function(){if(this._aborted)return!1;if(this._timedout)b.timeout();else{if(this._errored)throw this._errored;return!0}},d)}var d=this;f(b,function(){this._ready?c():this._readyQueue.poll(a,{result:function(a){f(b,function(){if(void 0===a)return!1;
c()},d)},timeout:function(){b.timeout()},error:function(a){b.error(a)}})},d)},isHandshake:function(a,b){var c=this;f(b,function(){var d=this.getMessageHeader();if(!d)return!1;if(d.isHandshake())return!0;if(null==this._handshake)this.nextData(a,{result:function(a){f(b,function(){if(!this._aborted)return this._currentPayload=a,this._payloadOffset=0,this._currentPayload||(this._handshake=!1),this._handshake},c)},timeout:b.timeout,error:function(a){f(b,function(){a instanceof k&&(this._readException=
new oa("Error reading the payload chunk.",a));throw a;},c)}});else return this._handshake},c)},getMessageHeader:function(){return this._header instanceof Ab?this._header:null},getErrorHeader:function(){return this._header instanceof qb?this._header:null},getIdentity:function(){var a=this.getMessageHeader();if(a){var b=a.masterToken;return b?b.identity:a.entityAuthenticationData.getIdentity()}return this.getErrorHeader().entityAuthenticationData.getIdentity()},getUser:function(){var a=this.getMessageHeader();
return a?a.user:null},getPayloadCryptoContext:function(){return this._cryptoContext},getKeyExchangeCryptoContext:function(){return this._keyxCryptoContext},closeSource:function(a){this._closeSource=a},abort:function(){this._aborted=!0;this._source.abort();this._readyQueue.cancelAll()},close:function(a,b){var c=this;f(b,function(){function d(){c.nextData(a,{result:function(a){a?d():b.result(!0)},timeout:b.timeout,error:function(){b.result(!0)}})}if(this._closeSource)this._source.close(a,b);else{if(!this.getMessageHeader())return!0;
this.isHandshake(a,{result:function(a){a?b.result(!0):d()},timeout:b.timeout,error:function(){b.result(!0)}})}},c)},mark:function(){if(this._currentPayload){for(;0<this._payloads.length&&this._payloads[0]!==this._currentPayload;)this._payloads.shift();this._payloadIndex=0;this._currentPayload=this._payloads[this._payloadIndex++];this._markOffset=this._payloadOffset}else this._payloadIndex=-1,this._payloads=[]},markSupported:function(){return!0},read:function(a,b,c){function d(){f(c,function(){if(this._aborted)return new Uint8Array(0);
if(this._timedout)c.timeout(new Uint8Array(0));else{if(this._errored)throw this._errored;if(null!=this._readException){var a=this._readException;this._readException=null;throw a;}this.isHandshake(b,{result:function(a){f(c,function(){if(void 0===a)return new Uint8Array(0);if(a)return null;e()},t)},timeout:c.timeout,error:function(a){f(c,function(){this._readException=null;throw new oa("Error reading the payload chunk.",a);},t)}})}},t)}function e(){f(c,function(){function d(c){f(c,function(){if(e&&
m>=e.length)return e.subarray(0,m);var h=-1;if(this._currentPayload){var u=this._currentPayload.length-this._payloadOffset;if(!e){var x=u;if(-1!=this._payloadIndex)for(var L=this._payloadIndex;L<this._payloads.length;++L)x+=this._payloads[L].length;0<x&&(e=new Uint8Array(x))}u=Math.min(u,e?e.length-m:0);0<u&&(h=this._currentPayload.subarray(this._payloadOffset,this._payloadOffset+u),e.set(h,l),h=u,l+=u,this._payloadOffset+=u)}-1!=h?(m+=h,d(c)):this.nextData(b,{result:function(b){f(c,function(){if(this._aborted)return e?
e.subarray(0,m):new Uint8Array(0);this._currentPayload=b;this._payloadOffset=0;if(this._currentPayload)d(c);else return 0==m&&0!=a?null:e?e.subarray(0,m):new Uint8Array(0)},t)},timeout:function(){c.timeout(e?e.subarray(0,m):new Uint8Array(0))},error:function(a){f(c,function(){a instanceof k&&(a=new oa("Error reading the payload chunk.",a));if(0<m)return t._readException=a,e.subarray(0,m);throw a;},t)}})},t)}var e=-1!=a?new Uint8Array(a):void 0,l=0,m=0;d(c)},t)}var t=this;f(c,function(){if(-1>a)throw new RangeError("read requested with illegal length "+
a);this._ready?d():this._readyQueue.poll(b,{result:function(a){void 0===a?c.result(!1):d()},timeout:function(){c.timeout(new Uint8Array(0))},error:function(a){c.error(a)}})},t)},reset:function(){this._payloadIndex=0;0<this._payloads.length?(this._currentPayload=this._payloads[this._payloadIndex++],this._payloadOffset=this._markOffset):this._currentPayload=null}});ud=function(a,b,c,d,e,f,k){new td(a,b,c,d,e,f,k)}})();var vd,Ic;(function(){vd=vc.extend({init:function(a,b,c,d,e,l,t){var k=this;f(t,function(){function f(){k._ready=
!0;k._readyQueue.add(!0)}var t=Bc(a.getMessageCapabilities(),d.messageCapabilities),D=null;t&&(D=Fb(t.compressionAlgorithms));t={_destination:{value:b,writable:!1,enumerable:!1,configurable:!1},_charset:{value:c,writable:!1,enumerable:!1,configurable:!1},_capabilities:{value:t,writable:!1,enumerable:!1,configurable:!1},_header:{value:d,writable:!1,enumerable:!1,configurable:!1},_compressionAlgo:{value:D,writable:!0,enumerable:!1,configurable:!1},_cryptoContext:{value:e,writable:!1,enumerable:!1,configurable:!1},
_payloadSequenceNumber:{value:1,writable:!0,enumerable:!1,configurable:!1},_currentPayload:{value:[],writable:!0,enumerable:!1,configurable:!1},_closed:{value:!1,writable:!0,enumerable:!1,configurable:!1},_closeDestination:{value:!1,writable:!0,enuemrable:!1,configurable:!1},_caching:{value:!0,writable:!0,enumerable:!1,configurable:!1},_payloads:{value:[],writable:!1,enumerable:!1,configurable:!1},_ready:{value:!1,writable:!0,enumerable:!1,configurable:!1},_readyQueue:{value:new C,writable:!1,enumerable:!1,
configurable:!1},_aborted:{value:!1,writable:!0,enumerable:!1,configurable:!1},_timedout:{value:!1,writable:!0,enumerable:!1,configurable:!1},_errored:{value:null,writable:!0,enumerable:!1,configurable:!1}};Object.defineProperties(this,t);var O=na(JSON.stringify(d),c);b.write(O,0,O.length,l,{result:function(a){try{k._aborted?f():a<O.length?(k._timedout=!0,f()):b.flush(l,{result:function(a){k._aborted||(k._timedout=!a);f()},timeout:function(){k._timedout=!0;f()},error:function(a){k._errored=a;f()}})}catch(c){k._errored=
c,f()}},timeout:function(){k._timedout=!0;f()},error:function(a){k._errored=a;f()}});return this},k)},setCompressionAlgorithm:function(a,b,c){function d(){e.flush(b,{result:function(b){f(c,function(){if(!b)throw new oa("flush() aborted");this._compressionAlgo=a;return!0},e)},timeout:function(){c.timeout()},error:function(a){c.error(a)}})}var e=this;f(c,function(){if(!this.getMessageHeader())throw new B("Cannot write payload data for an error message.");if(this._compressionAlgo==a)return!0;if(a){if(!this._capabilities)return!1;
for(var b=this._capabilities.compressionAlgorithms,c=0;c<b.length;++c)if(b[c]==a){d();return}return!1}d()},e)},getMessageHeader:function(){return this._header instanceof Ab?this._header:null},getErrorMessage:function(){return this._header instanceof qb?this._header:null},getPayloads:function(){return this._payloads},stopCaching:function(){this._caching=!1;this._payloads.length=0},abort:function(){this._aborted=!0;this._destination.abort();this._readyQueue.cancelAll()},closeDestination:function(a){this._closeDestination=
a},close:function(a,b){var c=this;f(b,function(){if(this._aborted)return!1;if(this._timedout)b.timeout();else{if(this._errored)throw this._errored;if(this._closed)return!0;this._closed=!0;this.flush(a,{result:function(d){f(b,function(){d&&(this._currentPayload=null);if(this._closeDestination)this._destination.close(a,b);else return d},c)},timeout:b.timeout,error:b.error})}},c)},flush:function(a,b){function c(){f(b,function(){if(this._aborted)return!1;if(this._timedout)b.timeout();else{if(this._errored)throw this._errored;
if(!this._currentPayload||!this._closed&&0==this._currentPayload.length)return!0;var c=this.getMessageHeader();if(!c||c.isHandshake())return!0;var g=0;this._currentPayload&&this._currentPayload.forEach(function(a){g+=a.length});for(var e=new Uint8Array(g),F=0,n=0;this._currentPayload&&n<this._currentPayload.length;++n){var z=this._currentPayload[n];e.set(z,F);F+=z.length}od(this._payloadSequenceNumber,c.messageId,this._closed,this._compressionAlgo,e,this._cryptoContext,{result:function(c){f(b,function(){this._caching&&
this._payloads.push(c);var g=na(JSON.stringify(c),this._charset);this._destination.write(g,0,g.length,a,{result:function(g){f(b,function(){if(this._aborted)return!1;g<c.length?b.timeout():this._destination.flush(a,{result:function(a){f(b,function(){if(this._aborted)return!1;if(a)return++this._payloadSequenceNumber,this._currentPayload=this._closed?null:[],!0;b.timeout()},d)},timeout:function(){b.timeout()},error:function(a){a instanceof k&&(a=new oa("Error encoding payload chunk [sequence number "+
d._payloadSequenceNumber+"].",a));b.error(a)}})},d)},timeout:function(a){b.timeout()},error:function(a){a instanceof k&&(a=new oa("Error encoding payload chunk [sequence number "+d._payloadSequenceNumber+"].",a));b.error(a)}})},d)},error:function(a){a instanceof k&&(a=new oa("Error encoding payload chunk [sequence number "+d._payloadSequenceNumber+"].",a));b.error(a)}})}},d)}var d=this;f(b,function(){this._ready?c():this._readyQueue.poll(a,{result:function(a){void 0===a?b.result(!1):c()},timeout:function(){b.timeout()},
error:function(a){b.error(a)}})},d)},write:function(a,b,c,d,e){f(e,function(){if(this._aborted)return!1;if(this._timedout)e.timeout();else{if(this._errored)throw this._errored;if(this._closed)throw new oa("Message output stream already closed.");if(0>b)throw new RangeError("Offset cannot be negative.");if(0>c)throw new RangeError("Length cannot be negative.");if(b+c>a.length)throw new RangeError("Offset plus length cannot be greater than the array length.");var d=this.getMessageHeader();if(!d)throw new B("Cannot write payload data for an error message.");
if(d.isHandshake())throw new B("Cannot write payload data for a handshake message.");d=a.subarray(b,b+c);this._currentPayload.push(d);return d.length}},this)}});Ic=function(a,b,c,d,e,f,k){new vd(a,b,c,d,e,f,k)}})();Object.freeze({USERDATA_REAUTH:b.USERDATA_REAUTH,SSOTOKEN_REJECTED:b.SSOTOKEN_REJECTED});var wd=d.Class.create({getCryptoContexts:function(){},getRecipient:function(){},isEncrypted:function(){},isIntegrityProtected:function(){},isNonReplayable:function(){},isRequestingTokens:function(){},
getUserId:function(){},getUserAuthData:function(a,b,c,d){},getUser:function(){},getKeyRequestData:function(a){},updateServiceTokens:function(a,b,c){},write:function(a,b,c){},getDebugContext:function(){}}),ee=d.Class.create({sentHeader:function(a){},receivedHeader:function(a){}});d.Class.create({getInputStream:function(a){},getOutputStream:function(a){}});var xd;(function(){function e(a){return function(){a.abort()}}function p(a,b){Object.defineProperties(this,{masterToken:{value:a,writable:!1,configurable:!1},
ticket:{value:b,writable:!1,configurable:!1}})}function g(a,b){Object.defineProperties(this,{builder:{value:a,writable:!1,configurable:!1},msgCtx:{value:b,writable:!1,configurable:!1}})}function h(a,b){Object.defineProperties(this,{request:{value:a,writable:!1,configurable:!1},handshake:{value:b,writable:!1,configurable:!1}})}function m(a,b){Object.defineProperties(this,{request:{value:b.request,writable:!1,configurable:!1},handshake:{value:b.handshake,writable:!1,configurable:!1},response:{value:a,
writable:!1,configurable:!1}})}function l(a){for(;a;){if(a instanceof Ka)return!0;a=a instanceof k?a.cause:void 0}return!1}function t(a){var b=a.masterToken;return b?b.identity:a.entityAuthenticationData.getIdentity()}function F(a,b,c,d,g,h,e,l,m,p){rd(b,d,g,h,e,{result:function(d){c&&c.sentHeader(d);Ic(b,l,ca,d,null,null,m,{result:function(b){a.setAbort(function(){b.abort()});b.close(m,{result:function(a){f(p,function(){if(!a)throw new Ka("sendError aborted.");return a})},timeout:function(){p.timeout()},
error:function(a){p.error(a)}})},timeout:function(){},error:function(a){p.error(a)}})},error:function(a){p.error(a)}})}var n=function(a,b){Object.defineProperties(this,{input:{value:a,writable:!1,configurable:!1},output:{value:b,writable:!1,configurable:!1}});return this};vc.extend({close:function(a,b){b.result(!0)},write:function(a,b,d,g,h){c(h,function(){return Math.min(a.length-b,d)})},flush:function(a,b){b.result(!0)}});var z=de.extend({getUserMessage:function(a,b){return null}}),D=wd.extend({init:function(a){Object.defineProperties(this,
{_appCtx:{value:a,writable:!1,enumerable:!1,configurable:!1}})},getCryptoContexts:function(){return this._appCtx.getCryptoContexts()},getRecipient:function(){return this._appCtx.getRecipient()},isEncrypted:function(){return this._appCtx.isEncrypted()},isIntegrityProtected:function(){return this._appCtx.isIntegrityProtected()},isNonReplayable:function(){return this._appCtx.isNonReplayable()},isRequestingTokens:function(){return this._appCtx.isRequestingTokens()},getUserId:function(){return this._appCtx.getUserId()},
getUserAuthData:function(a,b,c,d){this._appCtx.getUserAuthData(a,b,c,d)},getUser:function(){return this._appCtx.getUser()},getKeyRequestData:function(a){this._appCtx.getKeyRequestData(a)},updateServiceTokens:function(a,b,c){this._appCtx.updateServiceTokens(a,b,c)},write:function(a,b,c){this._appCtx.write(a,b,c)},getDebugContext:function(){return this._appCtx.getDebugContext()}}),O=D.extend({init:function Z(a,b){Z.base.call(this,b);Object.defineProperties(this,{_payloads:{value:a,writable:!1,enumerable:!1,
configurable:!1}})},write:function la(a,b,c){function d(h){if(h==g._payloads.length)c.result(!0);else{var e=g._payloads[h];a.setCompressionAlgorithm(e.compressionAlgo,b,{result:function(l){a.write(e.data,0,e.data.length,b,{result:function(l){f(c,function(){e.isEndOfMessage()?a.close(b,{result:function(a){a?d(h+1):c.result(a)},timeout:c.timeout,error:c.error}):a.flush(b,{result:function(a){a?d(h+1):c.result(a)},timeout:c.timeout,error:c.error})},g)},timeout:c.timeout,error:c.error})},timeout:c.timeout,
error:c.error})}}var g=this;this._payloads?d(0):la.base.call(this,a,b,c)}}),q=D.extend({init:function E(a){E.base.call(this,a)},isEncrypted:function(){return!1},isIntegrityProtected:function(){return!1},isNonReplayable:function(){return!1},write:function(a,b,c){c.result(!0)}}),u={},x,L,G,r,v=d.Class.create({init:function(a){a||(a=new z);Object.defineProperties(this,{_filterFactory:{value:null,writable:!0,enumerable:!1,configurable:!1},_renewingContexts:{value:[],writable:!1,enumerable:!1,configurable:!1},
_masterTokenLocks:{value:{},writable:!1,enumerable:!1,configurable:!1},_messageRegistry:{value:a,writable:!1,enumerable:!1,configurable:!1}})},setFilterFactory:function(a){this._filterFactory=a},getNewestMasterToken:function(a,b,c,d){var g=this;f(d,function(){var h=b.getMslStore().getMasterToken();if(!h)return null;var e=h.uniqueKey(),l=this._masterTokenLocks[e];l||(l=new kc,this._masterTokenLocks[e]=l);var m=l.readLock(c,{result:function(a){f(d,function(){if(void 0===a)throw new Ka("getNewestMasterToken aborted.");
return new p(h,a)},g)},timeout:function(){d.timeout()},error:function(a){d.error(a)}});a.setAbort(function(){m&&(l.cancel(m),m=void 0)})},g)},deleteMasterToken:function(a,b){if(b){var c=this;setTimeout(function(){var d=b.uniqueKey(),g=c._masterTokenLocks[d];g||(g=new kc,c._masterTokenLocks[d]=g);g.writeLock(-1,{result:function(h){a.getMslStore().removeCryptoContext(b);delete c._masterTokenLocks[d];g.unlock(h)},timeout:function(){throw new B("Unexpected timeout received.");},error:function(a){throw a;
}})},0)}},releaseMasterToken:function(a){if(a&&a.masterToken){var b=a.masterToken.uniqueKey();this._masterTokenLocks[b].unlock(a.ticket)}},updateOutgoingCryptoContexts:function(a,b,c){var d=a.getMslStore();!a.isPeerToPeer()&&c&&(d.setCryptoContext(c.keyResponseData.masterToken,c.cryptoContext),this.deleteMasterToken(a,b.masterToken))},updateIncomingCryptoContexts:function(a,b,c){var d=c.getMessageHeader();if(d){var g=a.getMslStore();if(d=d.keyResponseData)g.setCryptoContext(d.masterToken,c.getKeyExchangeCryptoContext()),
this.deleteMasterToken(a,b.masterToken)}},storeServiceTokens:function(a,b,c,d){a=a.getMslStore();for(var g=[],h=0;h<d.length;++h){var e=d[h];if(!e.isBoundTo(b)||!b.isVerified()){var f=e.data;f&&0==f.length?a.removeServiceTokens(e.name,e.isMasterTokenBound()?b:null,e.isUserIdTokenBound()?c:null):g.push(e)}}0<g.length&&a.addServiceTokens(g)},buildRequest:function(a,b,d,g,h){var e=this;this.getNewestMasterToken(a,b,g,{result:function(a){c(h,function(){var g=b.getMslStore(),f=g.getMasterToken();if(f)var l=
d.getUserId(),g=(g=l?g.getUserIdToken(l):null)&&g.isBoundTo(f)?g:null;else g=null;l=d.getRecipient();ub(b,f,g,l,null,{result:function(b){c(h,function(){b.setNonReplayable(d.isNonReplayable());return{builder:b,tokenTicket:a}})},error:function(b){c(h,function(){this.releaseMasterToken(a);b instanceof k&&(b=new B("User ID token not bound to master token despite internal check.",b));throw b;},e)}})},e)},timeout:function(){h.timeout()},error:function(a){h.error(a)}})},buildResponse:function(a,b,c,d,g,
h){var e=this;qd(b,d,{result:function(l){f(h,function(){l.setNonReplayable(c.isNonReplayable());if(!b.isPeerToPeer()&&!d.keyResponseData)return{builder:l,tokenTicket:null};this.getNewestMasterToken(a,b,g,{result:function(a){f(h,function(){var d=a&&a.masterToken,g;if(d){g=c.getUserId();var h=b.getMslStore();g=(g=g?h.getUserIdToken(g):null)&&g.isBoundTo(d)?g:null}else g=null;l.setAuthTokens(d,g);return{builder:l,tokenTicket:a}},e)},timeout:function(){h.timeout()},error:function(a){h.error(a)}})},e)},
error:function(a){h.error(a)}})},buildErrorResponse:function(a,c,d,h,e,l,m){function p(a,b){f(m,function(){var h=tb(e.messageId),l=new O(b,d),p=l.getRecipient();ub(c,null,null,p,h,{result:function(b){f(m,function(){c.isPeerToPeer()&&b.setPeerAuthTokens(a.peerMasterToken,a.peerUserIdToken);b.setNonReplayable(l.isNonReplayable());return{errorResult:new g(b,l),tokenTicket:null}},r)},error:function(a){m.error(a)}})},r)}function n(b,h){r.getNewestMasterToken(a,c,l,{result:function(a){f(m,function(){var l=
a&&a.masterToken,p=tb(e.messageId),n=new O(h,d),E=n.getRecipient();ub(c,l,null,E,p,{result:function(d){f(m,function(){c.isPeerToPeer()&&d.setPeerAuthTokens(b.peerMasterToken,b.peerUserIdToken);d.setNonReplayable(n.isNonReplayable());return{errorResult:new g(d,n),tokenTicket:a}},r)},error:function(a){m.error(a)}})},r)},timeout:function(){m.timeout()},error:function(a){m.error(a)}})}var r=this;f(m,function(){var x=h.request.getMessageHeader(),k=h.request.getPayloads(),t=e.errorCode;switch(t){case b.ENTITYDATA_REAUTH:case b.ENTITY_REAUTH:c.getEntityAuthenticationData(t,
{result:function(a){f(m,function(){if(!a)return null;p(x,k)},r)},error:function(a){m.error(a)}});break;case b.USERDATA_REAUTH:case b.SSOTOKEN_REJECTED:d.getUserAuthData(t,!1,!0,{result:function(a){f(m,function(){if(!a)return null;n(x,k)},r)},error:function(a){m.error(a)}});break;case b.USER_REAUTH:n(x,k);break;case b.KEYX_REQUIRED:var t=tb(e.messageId),v=new O(k,d),u=v.getRecipient();ub(c,null,null,u,t,{result:function(a){f(m,function(){c.isPeerToPeer()&&a.setPeerAuthTokens(x.peerMasterToken,x.peerUserIdToken);
a.setRenewable(!0);a.setNonReplayable(v.isNonReplayable());return{errorResult:new g(a,v),tokenTicket:null}},r)},error:function(a){m.error(a)}});break;case b.EXPIRED:this.getNewestMasterToken(a,c,l,{result:function(a){f(m,function(){var b=a&&a.masterToken,h=x.userIdToken,l=tb(e.messageId),p=new O(k,d),n=p.getRecipient();ub(c,b,h,n,l,{result:function(d){f(m,function(){c.isPeerToPeer()&&d.setPeerAuthTokens(x.peerMasterToken,x.peerUserIdToken);x.masterToken.equals(b)&&d.setRenewable(!0);d.setNonReplayable(p.isNonReplayable());
return{errorResult:new g(d,p),tokenTicket:a}},r)},error:function(a){m.error(a)}},r)},r)},timeout:function(){m.timeout()},error:function(a){m.error(a)}});break;case b.REPLAYED:this.getNewestMasterToken(a,c,l,{result:function(a){f(m,function(){var b=a&&a.masterToken,h=x.userIdToken,l=tb(e.messageId),p=new O(k,d),n=p.getRecipient();ub(c,b,h,n,l,{result:function(d){f(m,function(){c.isPeerToPeer()&&d.setPeerAuthTokens(x.peerMasterToken,x.peerUserIdToken);x.masterToken.equals(b)?(d.setRenewable(!0),d.setNonReplayable(!1)):
d.setNonReplayable(p.isNonReplayable());return{errorResult:new g(d,p),tokenTicket:a}},r)},error:function(a){m.error(a)}})},r)},timeout:function(){m.timeout()},error:function(a){m.error(a)}});break;default:return null}},r)},cleanupContext:function(a,c,d){switch(d.errorCode){case b.ENTITY_REAUTH:this.deleteMasterToken(a,c.masterToken);break;case b.USER_REAUTH:d=c.userIdToken,c.masterToken&&d&&a.getMslStore().removeUserIdToken(d)}},send:function(a,b,c,d,g,e,l,m){function p(a,d,h){f(m,function(){var e=
g.getPeerUserIdToken();!b.isPeerToPeer()&&!d||b.isPeerToPeer()&&!e?(e=c.getUser())?g.setUser(e,{result:function(b){f(m,function(){d=g.getUserIdToken();n(a,d,h)},k)},error:function(a){m.error(a)}}):n(a,d,h):n(a,d,h)},k)}function n(a,b,d){f(m,function(){var h=!(!(d||c.isEncrypted()&&!g.willEncryptPayloads()||c.isIntegrityProtected()&&!g.willIntegrityProtectPayloads())&&(!c.isNonReplayable()||g.isNonReplayable()&&a));g.setHandshake(h);var e=[];g.isRenewable()&&(!a||a.isRenewable()||c.isNonReplayable())?
c.getKeyRequestData({result:function(c){f(m,function(){for(var d=0;d<c.length;++d){var f=c[d];e.push(f);g.addKeyRequestData(f)}r(a,b,h,e)},k)},error:function(a){m.error(a)}}):r(a,b,h,e)},k)}function r(h,p,n,t){f(m,function(){var r=new sd(b,c,g);c.updateServiceTokens(r,n,{result:function(r){g.getHeader({result:function(r){f(m,function(){var t=c.getDebugContext();t&&t.sentHeader(r);t=g.getKeyExchangeData();this.updateOutgoingCryptoContexts(b,r,t);this.storeServiceTokens(b,h,p,r.serviceTokens);t=!b.isPeerToPeer()&&
t?t.cryptoContext:r.cryptoContext;if(a.isAborted())throw new Ka("send aborted.");var v=null!=this._filterFactory?this._filterFactory.getOutputStream(d):d;Ic(b,v,ca,r,t,l,{result:function(b){f(m,function(){a.setAbort(function(){b.abort()});b.closeDestination(e);x(b,n)},k)},timeout:function(){m.timeout()},error:function(a){m.error(a)}})},k)},timeout:function(){m.timeout()},error:function(a){m.error(a)}})},error:function(a){m.error(a)}})},k)}function x(b,d){d?f(m,function(){return new h(b,d)},k):c.write(b,
l,{result:function(c){f(m,function(){if(a.isAborted())throw new Ka("MessageOutputStream write aborted.");return new h(b,d)},k)},timeout:function(){m.timeout()},error:function(a){m.error(a)}})}var k=this;f(m,function(){var a=g.getMasterToken(),b=g.getUserIdToken(),d=!1;if(c.getUserId()){var h=!b;c.getUserAuthData(null,g.isRenewable(),h,{result:function(c){f(m,function(){c&&(g.willEncryptHeader()&&g.willIntegrityProtectHeader()?g.setUserAuthenticationData(c):d=!0);p(a,b,d)},k)},error:function(a){m.error(a)}})}else p(a,
b,d)},k)},receive:function(c,d,g,h,e,l,m){var p=this;f(m,function(){if(c.isAborted())throw new Ka("receive aborted.");var n=[];e&&(n=e.keyRequestData.filter(function(){return!0}));var r=g.getCryptoContexts(),x=this._filterFactory?this._filterFactory.getInputStream(h):h;ud(d,x,ca,n,r,l,{result:function(h){c.setAbort(function(){h.abort()});h.isReady(l,{result:function(c){f(m,function(){if(!c)throw new Ka("MessageInputStream aborted.");var l=h.getMessageHeader(),n=h.getErrorHeader(),r=g.getDebugContext();
r&&r.receivedHeader(l?l:n);var E,x,t;l?(r=l.masterToken,E=l.entityAuthenticationData,x=l.userIdToken,t=l.userAuthenticationData):(r=null,E=n.entityAuthenticationData,t=x=null);if(e){var v=n?n.errorCode:null;if(l||v!=b.FAIL&&v!=b.TRANSIENT_FAILURE&&v!=b.ENTITY_REAUTH&&v!=b.ENTITYDATA_REAUTH){var v=l?l.messageId:n.messageId,u=tb(e.messageId);if(v!=u)throw(new X(a.UNEXPECTED_RESPONSE_MESSAGE_ID,"expected "+u+"; received "+v)).setEntity(r).setEntity(E).setUser(x).setUser(t);}}d.getEntityAuthenticationData(null,
{result:function(b){f(m,function(){var c=b.getIdentity(),f;try{if(l){var m=l.entityAuthenticationData,p=l.masterToken;f=p?l.sender:m.getIdentity();if(p&&p.isDecrypted()&&p.identity!=f||c==f)throw new X(a.UNEXPECTED_MESSAGE_SENDER,f);var r=l.recipient;if(r&&r!=c)throw new X(a.MESSAGE_RECIPIENT_MISMATCH,r);e&&this.updateIncomingCryptoContexts(d,e,h);var E=l.keyResponseData,v,u,sa;d.isPeerToPeer()?(v=E?E.masterToken:l.peerMasterToken,u=l.peerUserIdToken,sa=l.peerServiceTokens):(v=E?E.masterToken:l.masterToken,
u=l.userIdToken,sa=l.serviceTokens);var G=g.getUserId();G&&u&&!u.isVerified()&&d.getMslStore().addUserIdToken(G,u);this.storeServiceTokens(d,v,u,sa)}else if(f=n.entityAuthenticationData.getIdentity(),c==f)throw new X(a.UNEXPECTED_MESSAGE_SENDER,f);}catch(L){throw L instanceof k&&(L.setEntity(p),L.setEntity(m),L.setUser(x),L.setUser(t)),L;}return h},p)},error:m.error})},p)},timeout:function(){m.timeout()},error:function(a){m.error(a)}})},timeout:function(){m.timeout()},error:function(a){m.error(a)}})},
p)},sendReceive:function(a,b,c,d,g,h,e,l,p,n){function r(k,t){f(n,function(){h.setRenewable(t);this.send(a,b,c,g,h,l,p,{result:function(g){f(n,function(){var h=g.request.getMessageHeader(),r=h.keyRequestData;e||g.handshake||!r.isEmpty()||h.isRenewable()&&h.masterToken&&h.userAuthenticationData?this.receive(a,b,c,d,h,p,{result:function(a){f(n,function(){t&&this.releaseRenewalLock(b,k,a);a.closeSource(l);return new m(a,g)},x)},timeout:function(){f(n,function(){t&&this.releaseRenewalLock(b,k,null);n.timeout()},
x)},error:function(a){f(n,function(){t&&this.releaseRenewalLock(b,k,null);throw a;},x)}}):f(n,function(){t&&this.releaseRenewalLock(b,k,null);return new m(null,g)},x)},x)},timeout:function(){f(n,function(){t&&this.releaseRenewalLock(b,k,null);n.timeout()},x)},error:function(a){f(n,function(){t&&this.releaseRenewalLock(b,k,null);throw a;},x)}})},x)}var x=this;f(n,function(){var d=new C;this.acquireRenewalLock(a,b,c,d,h,p,{result:function(a){r(d,a)},timeout:function(){n.timeout()},error:function(a){a instanceof
Ka?n.result(null):n.error(a)}})},x)},acquireRenewalLock:function(a,b,c,d,g,h,e){function l(p,r,x){f(e,function(){if(a.isAborted())throw new Ka("acquireRenewalLock aborted.");for(var k=null,t=0;t<this._renewingContexts.length;++t){var v=this._renewingContexts[t];if(v.ctx===b){k=v.queue;break}}if(!k)return this._renewingContexts.push({ctx:b,queue:d}),!0;var G=k.poll(h,{result:function(a){f(e,function(){if(void 0===a)throw new Ka("acquireRenewalLock aborted.");k.add(a);if(a===u||a.isExpired())l(a,r,
x);else{if(x&&!r||r&&!r.isBoundTo(a)){var d=b.getMslStore().getUserIdToken(x);r=d&&d.isBoundTo(a)?d:null}g.setAuthTokens(a,r);g.isRenewable()&&a.equals(p)?l(a,r,x):c.isRequestingTokens()&&!r?l(a,r,x):m(a,r)}},n)},timeout:function(){},error:function(a){}});a.setAbort(function(){G&&(k.cancel(G),G=void 0)})},n)}function m(g,h){f(e,function(){if(a.isAborted())throw new Ka("acquireRenewalLock aborted.");if(!g||g.isRenewable()||!h&&c.getUserId()||h&&h.isRenewable()){for(var e=null,l=0;l<this._renewingContexts.length;++l){var f=
this._renewingContexts[l];if(f.ctx===b){e=f.queue;break}}if(!e)return this._renewingContexts.push({ctx:b,queue:d}),!0}return!1},n)}var n=this;f(e,function(){var a=g.getMasterToken(),b=g.getUserIdToken(),d=c.getUserId();c.isEncrypted()&&!g.willEncryptPayloads()||c.isIntegrityProtected()&&!g.willIntegrityProtectPayloads()||g.isRenewable()||!a&&c.isNonReplayable()||a&&a.isExpired()||!(b||!d||g.willEncryptHeader()&&g.willIntegrityProtectHeader())||c.isRequestingTokens()&&(!a||d&&!b)?l(a,b,d):m(a,b)},
n)},releaseRenewalLock:function(a,b,c){for(var d,g,h=0;h<this._renewingContexts.length;++h){var e=this._renewingContexts[h];if(e.ctx===a){d=h;g=e.queue;break}}if(g!==b)throw new B("Attempt to release renewal lock that is not owned by this queue.");c?(c=c.messageHeader)?(g=c.keyResponseData)?b.add(g.masterToken):(a=a.isPeerToPeer()?c.peerMasterToken:c.masterToken)?b.add(a):b.add(u):b.add(u):b.add(u);this._renewingContexts.splice(d,1)}});xd=d.Class.create({init:function(){var a={_impl:{value:new v,
writable:!1,enumerable:!1,configurable:!1},_shutdown:{value:!1,writable:!1,enumerable:!1,configurable:!1}};Object.defineProperties(this,a)},setFilterFactory:function(a){this._impl.setFilterFactory(a)},shutdown:function(){this._shutdown=!0},receive:function(a,b,c,d,g,h){if(this._shutdown)throw new k("MslControl is shutdown.");var l=new x(this._impl,a,b,c,d,g);setTimeout(function(){l.call(h)},0);return e(l)},respond:function(a,b,c,d,g,h,l){if(this._shutdown)throw new k("MslControl is shutdown.");var f=
new L(this._impl,a,b,c,d,g,h);setTimeout(function(){f.call(l)},0);return e(f)},error:function(a,b,c,d,g,h,l){if(this._shutdown)throw new k("MslControl is shutdown.");var f=new G(this._impl,a,b,c,d,g,h);setTimeout(function(){f.call(l)},0);return e(f)},request:function(a,b){if(this._shutdown)throw new k("MslControl is shutdown.");var c,d,g,h,l;if(5==arguments.length){if(c=arguments[2],g=d=null,h=arguments[3],l=arguments[4],a.isPeerToPeer()){l.error(new B("This method cannot be used in peer-to-peer mode."));
return}}else if(6==arguments.length&&(c=null,d=arguments[2],g=arguments[3],h=arguments[4],l=arguments[5],!a.isPeerToPeer())){l.error(new B("This method cannot be used in trusted network mode."));return}var f=new r(this._impl,a,b,c,d,g,null,0,h);setTimeout(function(){f.call(l)},0);return e(f)}});x=d.Class.create({init:function(a,b,c,d,g,h){Object.defineProperties(this,{_ctrl:{value:a,writable:!1,enumerable:!1,configurable:!1},_ctx:{value:b,writable:!1,enumerable:!1,configurable:!1},_msgCtx:{value:c,
writable:!1,enumerable:!1,configurable:!1},_input:{value:d,writable:!1,enumerable:!1,configurable:!1},_output:{value:g,writable:!1,enumerable:!1,configurable:!1},_timeout:{value:h,writable:!1,enumerable:!1,configurable:!1},_aborted:{value:!1,writable:!0,enumerable:!1,configurable:!1},_abortFunc:{value:void 0,writable:!0,enumerable:!1,configurable:!1}})},isAborted:function(){return this._aborted},abort:function(){this._aborted=!0;this._abortFunc&&this._abortFunc.call(this)},setAbort:function(a){this._abortFunc=
a},call:function(b){function c(g){f(b,function(){var c=g.messageHeader;if(!c)return g;this.setAbort(function(){g.abort()});g.isHandshake(this._timeout,{result:function(a){f(b,function(){if(void 0===a)return null;if(!a)return g;d(g)},h)},timeout:b.timeout,error:function(d){f(b,function(){if(l(d))return null;var e=g.getIdentity(),m=c?c.messageId:null,n=a.INTERNAL_EXCEPTION,p=new B("Error peeking into the message payloads.");F(this,this._ctx,this._msgCtx.getDebugContext(),e,m,n,null,this._output,this._timeout,
{result:function(a){b.error(p)},timeout:function(){b.timeout()},error:function(a){f(b,function(){if(l(a))return null;throw new Pa("Error peeking into the message payloads.",a,d);},h)}})},h)}})},h)}function d(c){f(b,function(){c.close();this._ctrl.buildResponse(this,this._ctx,this._msgCtx,c.messageHeader,this._timeout,{result:function(a){f(b,function(){var d=a.builder,h=a.tokenTicket,e=c.messageHeader,l=new q(this._msgCtx);if(this._ctx.isPeerToPeer()){var m=new r(this._ctrl,this._ctx,l,null,this._input,
this._output,a,1,this._timeout);this.setAbort(function(){m.abort()});m.call({result:function(a){f(b,function(){return a?a.input:null})},timeout:b.timeout,error:b.error})}else g(e,d,l,h)},h)},timeout:b.timeout,error:function(d){f(b,function(){if(l(d))return null;var g=c.getIdentity(),e,m,n,p;d instanceof k?(e=d.messageId,m=d.error,n=c.messageHeader.messageCapabilities,n=this._ctrl.messageRegistry.getUserMessage(m,n?n.languages:null),p=d):(e=requestHeader?requestHeader.messageId:null,m=a.INTERNAL_EXCEPTION,
n=null,p=new B("Error creating an automatic handshake response.",d));F(this,this._ctx,this._msgCtx.getDebugContext(),g,e,m,n,this._output,this._timeout,{result:function(a){b.error(p)},timeout:function(){b.timeout()},error:function(a){f(b,function(){if(l(a))return null;throw new Pa("Error creating an automatic handshake response.",a,d);},h)}})},h)}})},h)}function g(c,d,e,m){f(b,function(){d.setRenewable(!1);this._ctrl.send(this._ctx,e,this._output,d,!1,this._timeout,{result:function(a){f(b,function(){this._ctx.isPeerToPeer()&&
this._ctrl.releaseMasterToken(m);return null},h)},timeout:function(){f(b,function(){this._ctx.isPeerToPeer()&&this._ctrl.releaseMasterToken(m);b.timeout()},h)},error:function(d){f(b,function(){this._ctx.isPeerToPeer()&&this._ctrl.releaseMasterToken(m);if(l(d))return null;var g=request.getIdentity(),e,n,p,r;d instanceof k?(e=d.messageId,n=d.error,p=c?c.messageCapabilities:null,p=this._ctrl.messageRegistry.getUserMessage(n,p?p.languages:null),r=d):d instanceof oa?(e=c?c.messageId:null,n=a.MSL_COMMS_FAILURE,
p=null,r=d):(e=c?c.messageId:null,n=a.INTERNAL_EXCEPTION,p=null,r=new B("Error sending an automatic handshake response.",d));F(this,this._ctx,this._msgCtx.getDebugContext(),g,e,n,p,this._output,this._timeout,{result:function(a){b.error(r)},timeout:function(){b.timeout()},error:function(a){f(b,function(){if(l(a))return null;throw new Pa("Error sending an automatic handshake response.",a,d);},h)}})},h)}})},h)}var h=this;f(b,function(){this._ctrl.receive(this,this._ctx,this._msgCtx,this._input,null,
this._timeout,{result:function(a){c(a)},timeout:function(){b.timeout()},error:function(c){f(b,function(){if(l(c))return null;var d,g,e,m,n;c instanceof k?(d=c.masterToken,g=c.entityAuthenticationData,d=d?d.identity:g?g.getIdentity():null,g=c.messageId,e=c.error,m=this._ctrl.messageRegistry.getUserMessage(e,null),n=c):(g=d=null,e=a.INTERNAL_EXCEPTION,m=null,n=new B("Error receiving the message header.",c));F(this,this._ctx,this._msgCtx.getDebugContext(),d,g,e,m,this._output,this._timeout,{result:function(a){b.error(n)},
timeout:function(){b.timeout()},error:function(a){f(b,function(){if(l(a))return null;throw new Pa("Error receiving the message header.",a,c);},h)}})},h)}})},h)}});L=d.Class.create({init:function(a,b,c,d,g,h,e){Object.defineProperties(this,{_ctrl:{value:a,writable:!1,enumerable:!1,configurable:!1},_ctx:{value:b,writable:!1,enumerable:!1,configurable:!1},_msgCtx:{value:c,writable:!1,enumerable:!1,configurable:!1},_input:{value:d,writable:!1,enumerable:!1,configurable:!1},_output:{value:g,writable:!1,
enumerable:!1,configurable:!1},_request:{value:h,writable:!1,enumerable:!1,configurable:!1},_timeout:{value:e,writable:!1,enumerable:!1,configurable:!1},_aborted:{value:!1,writable:!0,enumerable:!1,configurable:!1},_abortFunc:{value:void 0,writable:!0,enumerable:!1,configurable:!1}})},isAborted:function(){return this._aborted},abort:function(){this._aborted=!0;this._abortFunc&&this._abortFunc.call(this)},setAbort:function(a){this._abortFunc=a},trustedNetworkExecute:function(b,c,d){var g=this;f(d,
function(){if(12<c+1)return null;var h;if(h=this._msgCtx.isIntegrityProtected()&&!b.willIntegrityProtectHeader()?a.RESPONSE_REQUIRES_INTEGRITY_PROTECTION:this._msgCtx.isEncrypted()&&!b.willEncryptPayloads()?a.RESPONSE_REQUIRES_ENCRYPTION:null){var e=t(this._request),m=Cb(b.getMessageId());F(this,this._ctx,this._msgCtx.getDebugContext(),e,m,h,null,this._output,this._timeout,{result:function(a){d.result(null)},timeout:d.timeout,error:function(a){f(d,function(){if(l(a))return null;throw new Pa("Response requires encryption or integrity protection but cannot be protected: "+
h,a,null);},g)}})}else!this._msgCtx.getUser()||b.getMasterToken()||b.getKeyExchangeData()?(b.setRenewable(!1),this._ctrl.send(this._ctx,this._msgCtx,this._output,b,!1,this._timeout,{result:function(a){f(d,function(){return new n(this._request,a.request)})},timeout:d.timeout,error:d.error})):(e=t(this._request),m=Cb(b.getMessageId()),F(this,this._ctx,this._msgCtx.getDebugContext(),e,m,a.RESPONSE_REQUIRES_MASTERTOKEN,null,this._output,this._timeout,{result:function(a){d.result(null)},timeout:d.timeout,
error:function(a){f(d,function(){if(l(a))return null;throw new Pa("Response wishes to attach a user ID token but there is no master token.",a,null);},g)}}))},g)},peerToPeerExecute:function(b,c,d,g){function h(a){f(g,function(){a.response.close(this._timeout,{result:function(b){f(g,function(){if(!b)return null;e(a)},m)},timeout:function(){e(a)},error:function(b){f(g,function(){if(l(b))return null;e(a)},m)}})},m)}function e(a){f(g,function(){var c=response.getErrorHeader();this._ctrl.cleanupContext(this._ctx,
a.request.getMessageHeader(),c);this._ctrl.buildErrorResponse(this,this._ctx,b,a,c,{result:function(a){f(g,function(){if(!a)return null;var b=a.errorResult,c=a.tokenTicket;this.peerToPeerExecute(b.msgCtx,b.builder,d,{result:function(a){f(g,function(){this._ctrl.releaseMasterToken(c);return a},m)},timeout:function(){f(g,function(){this._ctrl.releaseMasterToken(c);g.timeout()},m)},error:function(a){f(g,function(){this._ctrl.releaseMasterToken(c);throw a;},m)}})},m)}})},m)}var m=this;f(g,function(){if(12<
d+2)return null;if(null!=b.getUser()&&null==c.getPeerMasterToken()&&null==c.getKeyExchangeData()){var e=t(this._request),p=Cb(c.getMessageId());F(this,this._ctx,b.getDebugContext(),e,p,a.RESPONSE_REQUIRES_MASTERTOKEN,null,this._output,this._timeout,{result:function(a){g.result(null)},timeout:g.timeout,error:function(a){f(g,function(){if(l(a))return null;throw new Pa("Response wishes to attach a user ID token but there is no master token.",re,null);},m)}})}else this._ctrl.sendReceive(this._ctx,b,this._input,
this._output,c,!1,!1,this._timeout,{result:function(a){f(g,function(){function c(){p.close(m._timeout,{result:function(a){f(g,function(){if(!a)return null;e()},m)},timeout:function(){e()},error:function(a){f(g,function(){if(l(a))return null;e()},m)}})}function e(){f(g,function(){var a=new O(null,b);this._ctrl.buildResponse(this,this._ctx,a,r,this._timeout,{result:function(b){f(g,function(){var c=b.tokenTicket;this.peerToPeerExecute(a,b.builder,d,{result:function(a){f(g,function(){this._ctrl.releaseMasterToken(c);
return a},m)},timeout:function(){f(g,function(){this._ctrl.releaseMasterToken(c);g.timeout()},m)},error:function(a){f(g,function(){this._ctrl.releaseMasterToken(c);throw a;},m)}})},m)},timeout:g.timeout,error:g.error})},m)}var p=a.response;d+=2;if(!p)return new n(this._request,a.request);var r=p.getMessageHeader();if(r)if(a.handshake)c();else return new n(a.response,a.request);else h(a)},m)},timeout:g.timeout,error:g.error})},m)},call:function(b){var c=this;f(b,function(){var d=this._request.getMessageHeader();
this._ctrl.buildResponse(this,this._ctx,this._msgCtx,d,this._timeout,{result:function(d){f(b,function(){var g=d.builder,h=d.tokenTicket;this._ctx.isPeerToPeer()?this.peerToPeerExecute(this._msgCtx,g,3,{result:function(a){f(b,function(){a&&a.output.stopCaching();this._ctx.isPeerToPeer()&&this.releaseMasterToken(h);return a},c)},timeout:function(){f(b,function(){this._ctx.isPeerToPeer()&&this.releaseMasterToken(h);b.timeout()},c)},error:function(d){f(b,function(){this._ctx.isPeerToPeer()&&this.releaseMasterToken(h);
if(l(d))return null;var e=t(this._request),m=Cb(g.getMessageId()),n,p,r;d instanceof k?(n=d.error,p=this._request.messageCapabilities,p=this._ctrl.messageRegistry.getUserMessage(n,p?p.languages:null),r=d):d instanceof oa?(n=a.MSL_COMMS_FAILURE,p=null,r=d):(n=a.INTERNAL_EXCEPTION,p=null,r=new B("Error sending the response.",d));F(this,this._ctx,this._msgCtx.getDebugContext(),e,m,n,p,this._output,this._timeout,{result:function(a){b.error(r)},timeout:function(){b.timeout()},error:function(a){f(b,function(){if(l(a))return!1;
throw new Pa("Error sending the response.",a,null);},c)}})},c)}}):this.trustedNetworkExecute(g,3,{result:function(a){f(b,function(){a&&a.output.stopCaching();this._ctx.isPeerToPeer()&&this.releaseMasterToken(h);return a},c)},timeout:function(){f(b,function(){this._ctx.isPeerToPeer()&&this.releaseMasterToken(h);b.timeout()},c)},error:function(d){f(b,function(){this._ctx.isPeerToPeer()&&this.releaseMasterToken(h);if(l(d))return null;var e=t(this._request),m=Cb(g.getMessageId()),n,p,r;d instanceof k?
(n=d.error,p=messageHeader.messageCapabilities,p=this._ctrl.messageRegistry.getUserMessage(n,p?p.languages:null),r=d):d instanceof oa?(n=a.MSL_COMMS_FAILURE,p=null,r=d):(n=a.INTERNAL_EXCEPTION,p=null,r=new B("Error sending the response.",d));F(this,this._ctx,this._msgCtx.getDebugContext(),e,m,n,p,this._output,this._timeout,{result:function(a){b.error(r)},timeout:function(){b.timeout()},error:function(a){f(b,function(){if(l(a))return null;throw new Pa("Error sending the response.",a,null);},c)}})},
c)}})},c)},timeout:b.timeout,error:function(g){f(b,function(){if(l(g))return null;var h=t(this._request),e,m,p,n;g instanceof k?(e=g.messageId,m=g.error,p=d.messageCapabilities,p=this._ctrl.messageRegistry.getUserMessage(m,p?p.languages:null),n=g):(e=null,m=a.INTERNAL_EXCEPTION,p=null,n=new B("Error building the response.",g));F(this,this._ctx,this._msgCtx.getDebugContext(),h,e,m,p,this._output,this._timeout,{result:function(a){b.error(n)},timeout:b.timeout,error:function(a){f(b,function(){if(l(a))return null;
throw new Pa("Error building the response.",a,g);},c)}})},c)}})},c)}});G=d.Class.create({init:function(a,b,c,d,g,h,e){Object.defineProperties(this,{_ctrl:{value:a,writable:!1,enumerable:!1,configurable:!1},_ctx:{value:b,writable:!1,enumerable:!1,configurable:!1},_msgCtx:{value:c,writable:!1,enumerable:!1,configurable:!1},_appError:{value:d,writable:!1,enumerable:!1,configurable:!1},_output:{value:output,writable:!1,enumerable:!1,configurable:!1},_request:{value:h,writable:!1,enumerable:!1,configurable:!1},
_timeout:{value:e,writable:!1,enumerable:!1,configurable:!1},_aborted:{value:!1,writable:!0,enumerable:!1,configurable:!1},_abortFunc:{value:void 0,writable:!0,enumerable:!1,configurable:!1}})},isAborted:function(){return this._aborted},abort:function(){this._aborted=!0;this._abortFunc&&this._abortFunc.call(this)},setAbort:function(a){this._abortFunc=a},call:function(b){var c=this;f(b,function(){var d;if(this._appError==ENTITY_REJECTED)d=this._request.masterToken?a.MASTERTOKEN_REJECTED_BY_APP:a.ENTITY_REJECTED_BY_APP;
else if(this._appError==USER_REJECTED)d=this._request.userIdToken?a.USERIDTOKEN_REJECTED_BY_APP:a.USER_REJECTED_BY_APP;else throw new B("Unhandled application error "+this._appError+".");var g=this._request.messageCapabilities,g=this._ctrl.messageRegistry.getUserMessage(d,g?g.languages:null);F(this,this._ctx,this._msgCtx.getDebugContext(),this._request.messageId,d,g,this._output,this._timeout,{result:function(a){b.result(a)},timeout:b.timeout,error:function(a){f(b,function(){if(l(a))return!1;if(a instanceof
k)throw a;throw new B("Error building the error response.",a);},c)}})},c)}});var wa={result:function(){},timeout:function(){},error:function(){}};r=d.Class.create({init:function(a,b,c,d,g,h,e,m,l){var f;e?(f=e.builder,e=e.tokenTicket):e=f=null;Object.defineProperties(this,{_ctrl:{value:a,writable:!1,enumerable:!1,configurable:!1},_ctx:{value:b,writable:!1,enumerable:!1,configurable:!1},_msgCtx:{value:c,writable:!1,enumerable:!1,configurable:!1},_remoteEntity:{value:d,writable:!1,enumerable:!1,configurable:!1},
_input:{value:g,writable:!0,enumerable:!1,configurable:!1},_output:{value:h,writable:!0,enumerable:!1,configurable:!1},_openedStreams:{value:!1,writable:!0,enumerable:!1,configurable:!1},_builder:{value:f,writable:!0,enumerable:!1,configurable:!1},_tokenTicket:{value:e,writable:!0,enumerable:!1,configurable:!1},_timeout:{value:l,writable:!1,enumerable:!1,configurable:!1},_msgCount:{value:m,writable:!1,enumerable:!1,configurable:!1},_aborted:{value:!1,writable:!0,enumerable:!1,configurable:!1},_abortFunc:{value:void 0,
writable:!0,enumerable:!1,configurable:!1}})},isAborted:function(){return this._aborted},abort:function(){this._aborted=!0;this._abortFunc&&this._abortFunc.call(this)},setAbort:function(a){this._abortFunc=a},execute:function(a,b,c,d,g){function h(a,b){a.request.close(k._timeout,{result:function(a){b.call(k,a)},timeout:function(){b.call(k,!0)},error:function(a){l(a)&&b.call(k,!1);b.call(k,!0)}})}function e(a,b){h(a,function(c){c?a.response.close(k._timeout,{result:function(a){b.call(k,a)},timeout:function(){b.call(k,
!0)},error:function(a){l(a)&&b.call(k,!1);b.call(k,!0)}}):b.call(k,!1)})}function m(a){f(g,function(){e(a,function(b){b?p(a):g.result(null)})},k)}function p(b){function h(a,b){f(g,function(){return b?b.input?b:new n(a.response,null):null},k)}f(g,function(){var e=b.request,m=b.response,l=m.getErrorHeader();this._ctrl.cleanupContext(this._ctx,e.getMessageHeader(),l);this._ctrl.buildErrorResponse(this,this._ctx,a,b,l,c,{result:function(a){f(g,function(){if(!a)return new n(m,null);var c=a.errorResult,
e=a.tokenTicket,l=c.builder,c=c.msgCtx;if(this._ctx.isPeerToPeer())this.execute(c,l,this._timeout,d,{result:function(a){f(g,function(){this._ctrl.releaseMasterToken(e);h(b,a)},k)},timeout:function(){f(g,function(){this._ctrl.releaseMasterToken(e);g.timeout()},k)},error:function(a){f(g,function(){this._ctrl.releaseMasterToken(e);g.error(a)},k)}});else{var p=new r(this._ctrl,this._ctx,c,this._remoteEntity,null,null,{builder:l,tokenTicket:e},d,this._timeout);this.setAbort(function(){p.abort()});p.call({result:function(a){h(b,
a)},timeout:g.timeout,error:g.error})}},k)},timeout:function(){g.timeout()},error:function(a){g.error(a)}})},k)}function x(b){f(g,function(){var m=b.request,l=b.response,p=l.getMessageHeader();if(this._ctx.isPeerToPeer())if(b.handshake)e(b,function(b){f(g,function(){if(!b)return null;var h=new O(null,a);this._ctrl.buildResponse(this,this._ctx,a,p,c,{result:function(a){f(g,function(){var b=a.tokenTicket;this.execute(h,a.builder,this._timeout,d,{result:function(a){f(g,function(){this._ctrl.releaseMasterToken(b);
return a},k)},timeout:function(){f(g,function(){this._ctrl.releaseMasterToken(b);g.timeout()},k)},error:function(a){f(g,function(){this._ctrl.releaseMasterToken(b);throw a;},k)}})},k)},timeout:function(){g.timeout()},error:function(a){g.error(a)}})},k)});else if(0<p.keyRequestData.length||p.isRenewable()&&p.masterToken&&p.userAuthenticationData){var x=new q(a);this._ctrl.buildResponse(this,this._ctx,x,p,c,{result:function(a){f(g,function(){var c=a.builder,m=a.tokenTicket;l.isHandshake(this._timeout,
{result:function(a){f(g,function(){a?e(b,function(){f(g,function(){if(!success)return this.releaseMasterToken(m),null;k.execute(x,c,this._timeout,d,{result:function(a){f(g,function(){this._ctrl.releaseMasterToken(m);return a},k)},timeout:function(){f(g,function(){this._ctrl.releaseMasterToken(m);g.timeout()},k)},error:function(a){f(g,function(){this._ctrl.releaseMasterToken(m);throw a;},k)}})},k)}):h(b,function(a){f(g,function(){if(!a)return this.releaseMasterToken(m),null;c.setRenewable(!1);this._ctrl.send(this,
this._ctx,x,this._output,c,this._timeout,{result:function(a){f(g,function(){this.releaseMasterToken(m);return new n(l,a.request)},k)},timeout:g.timeout,error:g.error})},k)})},k)},timeout:function(){f(g,function(){this.releaseMasterToken(m);g.timeout()},k)},error:function(a){f(g,function(){this.releaseMasterToken(m);throw a;},k)}})},k)},timeout:g.timeout,error:g.error})}else return new n(l,m);else{if(!b.handshake)return new n(l,m);e(b,function(b){f(g,function(){if(!b)return null;var h=new O(null,a);
this._ctrl.buildResponse(this,this._ctx,a,p,c,{result:function(a){f(g,function(){var b=new r(this._ctrl,this._ctx,h,this._remoteEntity,null,null,a,d,this._timeout);this.setAbort(function(){b.abort()});b.call(g)},k)},timeout:g.timeout,error:g.error})},k)})}},k)}var k=this;f(g,function(){if(12<d+2)return null;this._ctrl.sendReceive(this,this._ctx,a,this._input,this._output,b,!0,this._openedStreams,c,{result:function(a){f(g,function(){if(!a)return null;var b=a.response;d+=2;b.getMessageHeader()?x(a):
m(a)},k)},timeout:function(){g.timeout()},error:function(a){g.error(a)}})},k)},call:function(a){function b(d,g,h){f(a,function(){this.execute(this._msgCtx,d,h,this._msgCount,{result:function(b){f(a,function(){b&&b.output&&b.output.stopCaching();this._ctrl.releaseMasterToken(g);return b},c)},timeout:function(){f(a,function(){this._ctrl.releaseMasterToken(g);this._openedStreams&&(this._output.close(h,wa),this._input.close(h,wa));a.timeout()},c)},error:function(b){f(a,function(){this._ctrl.releaseMasterToken(g);
this._openedStreams&&(this._output.close(h,wa),this._input.close(h,wa));if(l(b))return null;throw b;},c)}})},c)}var c=this;f(a,function(){var d=this._timeout;if(!this._input||!this._output)try{this._remoteEntity.setTimeout(this._timeout);var g=Date.now(),h=this._remoteEntity.openConnection();this._output=h.output;this._input=h.input;-1!=d&&(d=this._timeout-(Date.now()-g));this._openedStreams=!0}catch(e){this._builder&&this._ctrl.releaseMasterToken(this._builder.getMasterToken());this._output&&this._output.close(this._timeout,
wa);this._input&&this._input.close(this._timeout,wa);if(l(e))return null;throw e;}this._builder?b(this._builder,this._tokenTicket,d):this._ctrl.buildRequest(this,this._ctx,this._msgCtx,this._timeout,{result:function(g){f(a,function(){b(g.builder,g.tokenTicket,d)},c)},timeout:function(){f(a,function(){this._openedStreams&&(this._output.close(this._timeout,wa),this._input.close(this._timeout,wa));a.timeout()},c)},error:function(b){f(a,function(){this._openedStreams&&(this._output.close(this._timeout,
wa),this._input.close(this._timeout,wa));if(l(b))return null;throw b;},c)}})},c)}})})();d.Class.create({isNewestMasterToken:function(a,b,c){},isMasterTokenRevoked:function(a,b){},acceptNonReplayableId:function(a,b,c,d){},createMasterToken:function(a,b,c,d,e){},isMasterTokenRenewable:function(a,b,c){},renewMasterToken:function(a,b,c,d,e){},isUserIdTokenRevoked:function(a,b,c,d){},createUserIdToken:function(a,b,c,d){},renewUserIdToken:function(a,b,c,d){},createUser:function(a,b,c){}});var Da,pb;(function(){function b(a,
c,d,e){this.sessiondata=a;this.tokendata=c;this.signature=d;this.verified=e}Da=d.Class.create({init:function(a,b,d,e,l,f,k,n,z,D,O){var q=this;c(O,function(){if(d.getTime()<b.getTime())throw new B("Cannot construct a master token that expires before its renewal window opens.");if(0>e||e>Y)throw new B("Sequence number "+e+" is outside the valid range.");if(0>l||l>Y)throw new B("Serial number "+l+" is outside the valid range.");var u=Math.floor(b.getTime()/1E3),x=Math.floor(d.getTime()/1E3),L;if(D)L=
D.sessiondata;else{var G={};f&&(G.issuerdata=f);G.identity=k;G.encryptionkey=J(n.toByteArray());G.hmackey=J(z.toByteArray());L=na(JSON.stringify(G),ca)}if(D)return Object.defineProperties(this,{ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},renewalWindowSeconds:{value:u,writable:!1,enumerable:!1,configurable:!1},expirationSeconds:{value:x,writable:!1,enumerable:!1,configurable:!1},sequenceNumber:{value:e,writable:!1,configurable:!1},serialNumber:{value:l,writable:!1,configurable:!1},issuerData:{value:f,
writable:!1,configurable:!1},identity:{value:k,writable:!1,configurable:!1},encryptionKey:{value:n,writable:!1,configurable:!1},hmacKey:{value:z,writable:!1,configurable:!1},sessiondata:{value:L,writable:!1,enumerable:!1,configurable:!1},verified:{value:D.verified,writable:!1,enumerable:!1,configurable:!1},tokendata:{value:D.tokendata,writable:!1,enumerable:!1,configurable:!1},signature:{value:D.signature,writable:!1,enumerable:!1,configurable:!1}}),this;var r=a.getMslCryptoContext();r.encrypt(L,
{result:function(b){c(O,function(){var d={};d.renewalwindow=u;d.expiration=x;d.sequencenumber=e;d.serialnumber=l;d.sessiondata=J(b);var g=na(JSON.stringify(d),ca);r.sign(g,{result:function(b){c(O,function(){Object.defineProperties(this,{ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},renewalWindowSeconds:{value:u,writable:!1,enumerable:!1,configurable:!1},expirationSeconds:{value:x,writable:!1,enumerable:!1,configurable:!1},sequenceNumber:{value:e,writable:!1,enumerable:!1,configurable:!1},
serialNumber:{value:l,writable:!1,enumerable:!1,configurable:!1},issuerData:{value:f,writable:!1,configurable:!1},identity:{value:k,writable:!1,configurable:!1},encryptionKey:{value:n,writable:!1,configurable:!1},hmacKey:{value:z,writable:!1,configurable:!1},sessiondata:{value:L,writable:!1,enumerable:!1,configurable:!1},verified:{value:!0,writable:!1,enumerable:!1,configurable:!1},tokendata:{value:g,writable:!1,enumerable:!1,configurable:!1},signature:{value:b,writable:!1,enumerable:!1,configurable:!1}});
return this},q)},error:function(a){O.error(a)}})},q)},error:function(a){O.error(a)}})},this)},get renewalWindow(){return new Date(1E3*this.renewalWindowSeconds)},get expiration(){return new Date(1E3*this.expirationSeconds)},isDecrypted:function(){return this.sessiondata?!0:!1},isVerified:function(){return this.verified},isRenewable:function(a){return this.isVerified()?this.renewalWindow.getTime()<=this.ctx.getTime():!0},isExpired:function(a){return this.isVerified()?this.expiration.getTime()<=this.ctx.getTime():
!1},isNewerThan:function(a){if(this.sequenceNumber==a.sequenceNumber)return this.expiration>a.expiration;if(this.sequenceNumber>a.sequenceNumber){var b=this.sequenceNumber-Y+127;return a.sequenceNumber>=b}b=a.sequenceNumber-Y+127;return this.sequenceNumber<b},toJSON:function(){var a={};a.tokendata=J(this.tokendata);a.signature=J(this.signature);return a},equals:function(a){return this===a?!0:a instanceof Da?this.serialNumber==a.serialNumber&&this.sequenceNumber==a.sequenceNumber&&this.expiration.getTime()==
a.expiration.getTime():!1},uniqueKey:function(){return this.serialNumber+":"+this.sequenceNumber+this.expiration.getTime()}});pb=function(d,g,h){c(h,function(){var e=d.getMslCryptoContext(),l=g.tokendata,f=g.signature;if("string"!==typeof l||"string"!==typeof f)throw new A(a.JSON_PARSE_ERROR,"mastertoken "+JSON.stringify(g));var F,n;try{F=S(l)}catch(z){throw new k(a.MASTERTOKEN_TOKENDATA_INVALID,"mastertoken "+JSON.stringify(g),z);}if(!F||0==F.length)throw new A(a.MASTERTOKEN_TOKENDATA_MISSING,"mastertoken "+
JSON.stringify(g));try{n=S(f)}catch(D){throw new k(a.MASTERTOKEN_SIGNATURE_INVALID,"mastertoken "+JSON.stringify(g),D);}e.verify(F,n,{result:function(g){c(h,function(){var l,f,x,t,G,r=ka(F,ca);try{var v=JSON.parse(r);l=parseInt(v.renewalwindow);f=parseInt(v.expiration);x=parseInt(v.sequencenumber);t=parseInt(v.serialnumber);G=v.sessiondata}catch(z){if(z instanceof SyntaxError)throw new A(a.MASTERTOKEN_TOKENDATA_PARSE_ERROR,"mastertokendata "+r,z);throw z;}if(!l||l!=l||!f||f!=f||"number"!==typeof x||
x!=x||"number"!==typeof t||t!=t||"string"!==typeof G)throw new A(a.MASTERTOKEN_TOKENDATA_PARSE_ERROR,"mastertokendata "+r);if(f<l)throw new k(a.MASTERTOKEN_EXPIRES_BEFORE_RENEWAL,"mastertokendata "+r);if(0>x||x>Y)throw new k(a.MASTERTOKEN_SEQUENCE_NUMBER_OUT_OF_RANGE,"mastertokendata "+r);if(0>t||t>Y)throw new k(a.MASTERTOKEN_SERIAL_NUMBER_OUT_OF_RANGE,"mastertokendata "+r);var D=new Date(1E3*l),Z=new Date(1E3*f),C;try{C=S(G)}catch(E){throw new k(a.MASTERTOKEN_SESSIONDATA_INVALID,G,E);}if(!C||0==
C.length)throw new k(a.MASTERTOKEN_SESSIONDATA_MISSING,G);g?e.decrypt(C,{result:function(e){c(h,function(){var l,m,f,r,k=ka(e,ca);try{var v=JSON.parse(k);l=v.issuerdata;m=v.identity;f=v.encryptionkey;r=v.hmackey}catch(u){if(u instanceof SyntaxError)throw new A(a.MASTERTOKEN_SESSIONDATA_PARSE_ERROR,"sessiondata "+k,u);throw u;}if(l&&"object"!==typeof l||!m||"string"!==typeof f||"string"!==typeof r)throw new A(a.MASTERTOKEN_SESSIONDATA_PARSE_ERROR,"sessiondata "+k);bb(f,s,ua,{result:function(f){bb(r,
P,V,{result:function(a){c(h,function(){var c=new b(e,F,n,g);new Da(d,D,Z,x,t,l,m,f,a,c,h)})},error:function(b){h.error(new q(a.MASTERTOKEN_KEY_CREATION_ERROR,b))}})},error:function(b){h.error(new q(a.MASTERTOKEN_KEY_CREATION_ERROR,b))}})})},error:function(a){h.error(a)}}):(l=new b(null,F,n,g),new Da(d,D,Z,x,t,null,null,null,null,l,h))})},error:function(a){h.error(a)}})})}})();var yb,rb;(function(){function b(a,c,d){this.tokendata=a;this.signature=c;this.verified=d}yb=d.Class.create({init:function(a,
b,d,e,l,f,F,n,z){var D=this;c(z,function(){if(d.getTime()<b.getTime())throw new B("Cannot construct a user ID token that expires before its renewal window opens.");if(!e)throw new B("Cannot construct a user ID token without a master token.");if(0>l||l>Y)throw new B("Serial number "+l+" is outside the valid range.");var q=Math.floor(b.getTime()/1E3),C=Math.floor(d.getTime()/1E3),u=e.serialNumber;if(n){var x=n.tokendata,L=n.signature,G=n.verified,u=e.serialNumber;Object.defineProperties(this,{ctx:{value:a,
writable:!1,enumerable:!1,configurable:!1},renewalWindowSeconds:{value:q,writable:!1,enumerable:!1,configurable:!1},expirationSeconds:{value:C,writable:!1,enumerable:!1,configurable:!1},mtSerialNumber:{value:u,writable:!1,configurable:!1},serialNumber:{value:l,writable:!1,configurable:!1},issuerData:{value:f,writable:!1,configurable:!1},user:{value:F,writable:!1,configurable:!1},verified:{value:G,writable:!1,enumerable:!1,configurable:!1},tokendata:{value:x,writable:!1,enumerable:!1,configurable:!1},
signature:{value:L,writable:!1,enumerable:!1,configurable:!1}});return this}x={};f&&(x.issuerdata=f);x.identity=J(F.getEncoded());var x=na(JSON.stringify(x),ca),r=a.getMslCryptoContext();r.encrypt(x,{result:function(b){c(z,function(){var d={};d.renewalwindow=q;d.expiration=C;d.mtserialnumber=u;d.serialnumber=l;d.userdata=J(b);var g=na(JSON.stringify(d),ca);r.sign(g,{result:function(b){c(z,function(){Object.defineProperties(this,{ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},renewalWindowSeconds:{value:q,
writable:!1,enumerable:!1,configurable:!1},expirationSeconds:{value:C,writable:!1,enumerable:!1,configurable:!1},mtSerialNumber:{value:e.serialNumber,writable:!1,configurable:!1},serialNumber:{value:l,writable:!1,configurable:!1},issuerData:{value:f,writable:!1,configurable:!1},user:{value:F,writable:!1,configurable:!1},verified:{value:!0,writable:!1,enumerable:!1,configurable:!1},tokendata:{value:g,writable:!1,enumerable:!1,configurable:!1},signature:{value:b,writable:!1,enumerable:!1,configurable:!1}});
return this},D)},error:function(a){c(z,function(){a instanceof k&&a.setEntity(e);throw a;},D)}})},D)},error:function(a){c(z,function(){a instanceof k&&a.setEntity(e);throw a;},D)}})},this)},get renewalWindow(){return new Date(1E3*this.renewalWindowSeconds)},get expiration(){return new Date(1E3*this.expirationSeconds)},isVerified:function(){return this.verified},isDecrypted:function(){return this.user?!0:!1},isRenewable:function(){return this.renewalWindow.getTime()<=this.ctx.getTime()},isExpired:function(){return this.expiration.getTime()<=
this.ctx.getTime()},isBoundTo:function(a){return a&&a.serialNumber==this.mtSerialNumber},toJSON:function(){var a={};a.tokendata=J(this.tokendata);a.signature=J(this.signature);return a},equals:function(a){return this===a?!0:a instanceof yb?this.serialNumber==a.serialNumber&&this.mtSerialNumber==a.mtSerialNumber:!1},uniqueKey:function(){return this.serialNumber+":"+this.mtSerialNumber}});rb=function(d,g,h,e){c(e,function(){var l=d.getMslCryptoContext(),f=g.tokendata,F=g.signature;if("string"!==typeof f||
"string"!==typeof F)throw(new A(a.JSON_PARSE_ERROR,"useridtoken "+JSON.stringify(g))).setEntity(h);var n,z;try{n=S(f)}catch(D){throw(new k(a.USERIDTOKEN_TOKENDATA_INVALID,"useridtoken "+JSON.stringify(g),D)).setEntity(h);}if(!n||0==n.length)throw(new A(a.USERIDTOKEN_TOKENDATA_MISSING,"useridtoken "+JSON.stringify(g))).setEntity(h);try{z=S(F)}catch(q){throw(new k(a.USERIDTOKEN_TOKENDATA_INVALID,"useridtoken "+JSON.stringify(g),q)).setEntity(h);}l.verify(n,z,{result:function(g){c(e,function(){var f,
x,t,G,r,v=ka(n,ca);try{var F=JSON.parse(v);f=parseInt(F.renewalwindow);x=parseInt(F.expiration);t=parseInt(F.mtserialnumber);G=parseInt(F.serialnumber);r=F.userdata}catch(D){if(D instanceof SyntaxError)throw(new A(a.USERIDTOKEN_TOKENDATA_PARSE_ERROR,"usertokendata "+v,D)).setEntity(h);throw D;}if(!f||f!=f||!x||x!=x||"number"!==typeof t||t!=t||"number"!==typeof G||G!=G||"string"!==typeof r)throw(new A(a.USERIDTOKEN_TOKENDATA_PARSE_ERROR,"usertokendata "+v)).setEntity(h);if(x<f)throw(new k(a.USERIDTOKEN_EXPIRES_BEFORE_RENEWAL,
"mastertokendata "+v)).setEntity(h);if(0>t||t>Y)throw(new k(a.USERIDTOKEN_MASTERTOKEN_SERIAL_NUMBER_OUT_OF_RANGE,"usertokendata "+v)).setEntity(h);if(0>G||G>Y)throw(new k(a.USERIDTOKEN_SERIAL_NUMBER_OUT_OF_RANGE,"usertokendata "+v)).setEntity(h);var q=new Date(1E3*f),O=new Date(1E3*x);if(!h||t!=h.serialNumber)throw(new k(a.USERIDTOKEN_MASTERTOKEN_MISMATCH,"uit mtserialnumber "+t+"; mt "+JSON.stringify(h))).setEntity(h);var E;try{E=S(r)}catch(C){throw(new k(a.USERIDTOKEN_USERDATA_INVALID,r,C)).setEntity(h);
}if(!E||0==E.length)throw(new k(a.USERIDTOKEN_USERDATA_MISSING,r)).setEntity(h);g?l.decrypt(E,{result:function(l){c(e,function(){var f,r,x=ka(l,ca);try{var t=JSON.parse(x);f=t.issuerdata;r=t.identity}catch(v){if(v instanceof SyntaxError)throw(new A(a.USERIDTOKEN_USERDATA_PARSE_ERROR,"userdata "+x)).setEntity(h);throw v;}if(f&&"object"!==typeof f||"string"!==typeof r)throw(new A(a.USERIDTOKEN_USERDATA_PARSE_ERROR,"userdata "+x)).setEntity(h);var u;try{u=S(r)}catch(L){throw(new k(a.USERIDTOKEN_IDENTITY_INVALID,
"userdata "+x,L)).setEntity(h);}if(!u||0==u.length)throw(new k(a.USERIDTOKEN_IDENTITY_INVALID,"userdata "+x)).setEntity(h);d.getTokenFactory().createUser(d,u,{result:function(a){c(e,function(){var c=new b(n,z,g);new yb(d,q,O,h,G,f,a,c,e)})},error:function(a){c(e,function(){a instanceof k&&a.setEntity(h);throw a;})}})})},error:function(a){c(e,function(){a instanceof k&&a.setEntity(h);throw a;})}}):(f=new b(n,z,g),new yb(d,q,O,h,G,null,null,f,e))})},error:function(a){c(e,function(){a instanceof k&&
a.setEntity(h);throw a;})}})})}})();var vb,fb,Cc;(function(){function b(c,d){var e=c.tokendata;if("string"!==typeof e)throw new A(a.JSON_PARSE_ERROR,"servicetoken "+JSON.stringify(c));var l;try{l=S(e)}catch(f){throw new k(a.SERVICETOKEN_TOKENDATA_INVALID,"servicetoken "+JSON.stringify(c),f);}if(!l||0==l.length)throw new A(a.SERVICETOKEN_TOKENDATA_MISSING,"servicetoken "+JSON.stringify(c));var p;try{p=JSON.parse(ka(l,ca)).name}catch(n){if(n instanceof SyntaxError)throw new A(a.JSON_PARSE_ERROR,"servicetoken "+
JSON.stringify(c),n);throw n;}if(!p)throw new A(a.JSON_PARSE_ERROR,"servicetoken "+JSON.stringify(c));return d[p]?d[p]:d[""]}function e(a,b,c){this.tokendata=a;this.signature=b;this.verified=c}vb=d.Class.create({init:function(a,b,d,e,f,p,n,z,D,q){var C=this;c(q,function(){if(e&&f&&!f.isBoundTo(e))throw new B("Cannot construct a service token bound to a master token and user ID token where the user ID token is not bound to the same master token.");var u=e?e.serialNumber:-1,x=f?f.serialNumber:-1;if(D)return r=
D.tokendata,Object.defineProperties(this,{ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},name:{value:b,writable:!1,configurable:!1},mtSerialNumber:{value:u,writable:!1,configurable:!1},uitSerialNumber:{value:x,writable:!1,configurable:!1},data:{value:d,writable:!1,configurable:!1},encrypted:{value:p,writable:!1,enumerable:!1,configurable:!1},compressionAlgo:{value:n,writable:!1,configurable:!1},verified:{value:D.verified,writable:!1,enumerable:!1,configurable:!1},tokendata:{value:r,writable:!1,
enumerable:!1,configurable:!1},signature:{value:D.signature,writable:!1,enumerable:!1,configurable:!1}}),this;var L;n?(L=Hc(n,d),L.length<d.length||(n=null,L=d)):(n=null,L=d);var G={};G.name=b;-1!=u&&(G.mtserialnumber=u);-1!=x&&(G.uitserialnumber=x);G.encrypted=p;n&&(G.compressionalgo=n);if(p&&0<L.length)z.encrypt(L,{result:function(r){c(q,function(){G.servicedata=J(r);var L=na(JSON.stringify(G),ca);z.sign(L,{result:function(e){c(q,function(){Object.defineProperties(this,{ctx:{value:a,writable:!1,
enumerable:!1,configurable:!1},name:{value:b,writable:!1,configurable:!1},mtSerialNumber:{value:u,writable:!1,configurable:!1},uitSerialNumber:{value:x,writable:!1,configurable:!1},data:{value:d,writable:!1,configurable:!1},encrypted:{value:p,writable:!1,enumerable:!1,configurable:!1},compressionAlgo:{value:n,writable:!1,configurable:!1},verified:{value:!0,writable:!1,enumerable:!1,configurable:!1},tokendata:{value:L,writable:!1,enumerable:!1,configurable:!1},signature:{value:e,writable:!1,enumerable:!1,
configurable:!1}});return this},C)},error:function(a){c(q,function(){a instanceof k&&(a.setEntity(e),a.setUser(f));throw a;})}})},C)},error:function(a){c(q,function(){a instanceof k&&(a.setEntity(e),a.setUser(f));throw a;})}});else{G.servicedata=J(L);var r=na(JSON.stringify(G),ca);z.sign(r,{result:function(e){c(q,function(){Object.defineProperties(this,{ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},name:{value:b,writable:!1,configurable:!1},mtSerialNumber:{value:u,writable:!1,configurable:!1},
uitSerialNumber:{value:x,writable:!1,configurable:!1},data:{value:d,writable:!1,configurable:!1},encrypted:{value:p,writable:!1,enumerable:!1,configurable:!1},compressionAlgo:{value:n,writable:!1,configurable:!1},verified:{value:!0,writable:!1,enumerable:!1,configurable:!1},tokendata:{value:r,writable:!1,enumerable:!1,configurable:!1},signature:{value:e,writable:!1,enumerable:!1,configurable:!1}});return this},C)},error:function(a){c(q,function(){a instanceof k&&(a.setEntity(e),a.setUser(f));throw a;
})}})}},this)},isEncrypted:function(){return this.encrypted},isVerified:function(){return this.verified},isDecrypted:function(){return this.data?!0:!1},isDeleted:function(){return this.data&&0==this.data.length},isMasterTokenBound:function(){return-1!=this.mtSerialNumber},isBoundTo:function(a){return a?a instanceof Da?a.serialNumber==this.mtSerialNumber:a instanceof yb?a.serialNumber==this.uitSerialNumber:!1:!1},isUserIdTokenBound:function(){return-1!=this.uitSerialNumber},isUnbound:function(){return-1==
this.mtSerialNumber&&-1==this.uitSerialNumber},toJSON:function(){var a={};a.tokendata=J(this.tokendata);a.signature=J(this.signature);return a},equals:function(a){return this===a?!0:a instanceof vb?this.name==a.name&&this.mtSerialNumber==a.mtSerialNumber&&this.uitSerialNumber==a.uitSerialNumber:!1},uniqueKey:function(){return this.name+":"+this.mtSerialNumber+":"+this.uitSerialNumber}});fb=function(a,b,c,d,e,f,n,k,p){new vb(a,b,c,d,e,f,n,k,null,p)};Cc=function(d,h,f,l,t,F){c(F,function(){!t||t instanceof
mb||(t=b(h,t));var n=h.tokendata,z=h.signature;if("string"!==typeof n||"string"!==typeof z)throw(new A(a.JSON_PARSE_ERROR,"servicetoken "+JSON.stringify(h))).setEntity(f).setEntity(l);var D,q;try{D=S(n)}catch(C){throw(new k(a.SERVICETOKEN_TOKENDATA_INVALID,"servicetoken "+JSON.stringify(h),C)).setEntity(f).setEntity(l);}if(!D||0==D.length)throw(new A(a.SERVICETOKEN_TOKENDATA_MISSING,"servicetoken "+JSON.stringify(h))).setEntity(f).setEntity(l);try{q=S(z)}catch(u){throw(new k(a.SERVICETOKEN_SIGNATURE_INVALID,
"servicetoken "+JSON.stringify(h),u)).setEntity(f).setEntity(l);}var x,L,G,r,v,s,w=ka(D,ca);try{var Z=JSON.parse(w);x=Z.name;L=Z.mtserialnumber?parseInt(Z.mtserialnumber):-1;G=Z.uitserialnumber?parseInt(Z.uitserialnumber):-1;r=Z.encrypted;v=Z.compressionalgo;s=Z.servicedata}catch(la){if(la instanceof SyntaxError)throw(new A(a.JSON_PARSE_ERROR,"servicetokendata "+w,la)).setEntity(f).setEntity(l);throw la;}if(!x||"number"!==typeof L||L!=L||"number"!==typeof G||G!=G||"boolean"!==typeof r||v&&"string"!==
typeof v||"string"!==typeof s)throw(new A(a.JSON_PARSE_ERROR,"servicetokendata "+w)).setEntity(f).setEntity(l);if(Z.mtserialnumber&&0>L||L>Y)throw(new k(a.SERVICETOKEN_MASTERTOKEN_SERIAL_NUMBER_OUT_OF_RANGE,"servicetokendata "+w)).setEntity(f).setEntity(l);if(Z.uitserialnumber&&0>G||G>Y)throw(new k(a.SERVICETOKEN_USERIDTOKEN_SERIAL_NUMBER_OUT_OF_RANGE,"servicetokendata "+w)).setEntity(f).setEntity(l);if(-1!=L&&(!f||L!=f.serialNumber))throw(new k(a.SERVICETOKEN_MASTERTOKEN_MISMATCH,"st mtserialnumber "+
L+"; mt "+f)).setEntity(f).setEntity(l);if(-1!=G&&(!l||G!=l.serialNumber))throw(new k(a.SERVICETOKEN_USERIDTOKEN_MISMATCH,"st uitserialnumber "+G+"; uit "+l)).setEntity(f).setEntity(l);r=!0===r;var E;if(v){if(!La[v])throw new k(a.UNIDENTIFIED_COMPRESSION,v);E=v}else E=null;t?t.verify(D,q,{result:function(b){c(F,function(){if(b){var h;try{h=S(s)}catch(n){throw(new k(a.SERVICETOKEN_SERVICEDATA_INVALID,"servicetokendata "+w,n)).setEntity(f).setEntity(l);}if(!h||0!=s.length&&0==h.length)throw(new k(a.SERVICETOKEN_SERVICEDATA_INVALID,
"servicetokendata "+w)).setEntity(f).setEntity(l);if(r&&0<h.length)t.decrypt(h,{result:function(a){c(F,function(){var c=E?bc(E,a):a,h=new e(D,q,b);new vb(d,x,c,-1!=L?f:null,-1!=G?l:null,r,E,t,h,F)})},error:function(a){c(F,function(){a instanceof k&&(a.setEntity(f),a.setUser(l));throw a;})}});else{h=E?bc(E,h):h;var v=new e(D,q,b);new vb(d,x,h,-1!=L?f:null,-1!=G?l:null,r,E,t,v,F)}}else h=""==s?new Uint8Array(0):null,v=new e(D,q,b),new vb(d,x,h,-1!=L?f:null,-1!=G?l:null,r,E,t,v,F)})},error:function(a){c(F,
function(){a instanceof k&&(a.setEntity(f),a.setUser(l));throw a;})}}):(n=""==s?new Uint8Array(0):null,z=new e(D,q,!1),new vb(d,x,n,-1!=L?f:null,-1!=G?l:null,r,E,t,z,F))})}})();var Ra={EMAIL_PASSWORD:"EMAIL_PASSWORD",NETFLIXID:"NETFLIXID",SSO:"SSO",SWITCH_PROFILE:"SWITCH_PROFILE",MDX:"MDX"};Object.freeze(Ra);var ib,nd;(function(){ib=d.Class.create({init:function(a){Object.defineProperties(this,{scheme:{value:a,writable:!1,configurable:!1}})},getAuthData:function(){},equals:function(a){return this===
a?!0:a instanceof ib?this.scheme==a.scheme:!1},toJSON:function(){var a={};a.scheme=this.scheme;a.authdata=this.getAuthData();return a}});nd=function(b,d,g,e){c(e,function(){var c=g.scheme,f=g.authdata;if(!c||!f)throw new A(a.JSON_PARSE_ERROR,"userauthdata "+JSON.stringify(g));if(!Ra[c])throw new U(a.UNIDENTIFIED_USERAUTH_SCHEME,c);var k=b.getUserAuthenticationFactory(c);if(!k)throw new U(a.USERAUTH_FACTORY_NOT_FOUND,c);k.createData(b,d,f,e)})}})();var Nb=d.Class.create({init:function(a){Object.defineProperties(this,
{scheme:{value:a,writable:!1,configurable:!1}})},createData:function(a,b,c,d){},authenticate:function(a,b,c,d){}}),Ob,yd;(function(){Ob=ib.extend({init:function p(a,b){p.base.call(this,Ra.EMAIL_PASSWORD);Object.defineProperties(this,{email:{value:a,writable:!1,configurable:!1},password:{value:b,writable:!1,configurable:!1}})},getAuthData:function(){var a={};a.email=this.email;a.password=this.password;return a},equals:function g(a){return this===a?!0:a instanceof Ob?g.base.call(this,this,a)&&this.email==
a.email&&this.password==a.password:!1}});yd=function(b){var c=b.email,d=b.password;if("string"!==typeof c||"string"!==typeof d)throw new A(a.JSON_PARSE_ERROR,"email/password authdata "+JSON.stringify(b));return new Ob(c,d)}})();Nb.extend({init:function p(a){p.base.call(this,Ra.EMAIL_PASSWORD);Object.defineProperties(this,{_store:{value:a,writable:!1,enumerable:!1,configurable:!1}})},createData:function(a,b,d,e){c(e,function(){return yd(d)})},authenticate:function(b,c,d,e){if(!(d instanceof Ob))throw new B("Incorrect authentication data type "+
d+".");b=d.email;c=d.password;if(!b||0==b.trim().length||!c||0==c.trim().length)throw(new U(a.EMAILPASSWORD_BLANK)).setUser(d);b=this._store.isUser(b,c);if(null==b)throw(new U(a.EMAILPASSWORD_INCORRECT)).setUser(d);if(e&&(e=e.user,!b.equals(e)))throw(new U(a.USERIDTOKEN_USERAUTH_DATA_MISMATCH,"uad user "+b+"; uit user "+e)).setUser(d);return b}});Object.freeze({ENTITY_REAUTH:b.ENTITY_REAUTH,ENTITYDATA_REAUTH:b.ENTITYDATA_REAUTH});var fe=d.Class.create({getTime:function(){},getRandom:function(){},
isPeerToPeer:function(){},getMessageCapabilities:function(){},getEntityAuthenticationData:function(a,b){},getMslCryptoContext:function(){},getEntityAuthenticationFactory:function(a){},getUserAuthenticationFactory:function(a){},getTokenFactory:function(){},getKeyExchangeFactory:function(a){},getKeyExchangeFactories:function(){},getMslStore:function(){}}),ge=d.Class.create({setCryptoContext:function(a,b){},getMasterToken:function(){},getNonReplayableId:function(a){},getCryptoContext:function(a){},removeCryptoContext:function(a){},
clearCryptoContexts:function(){},addUserIdToken:function(a,b){},getUserIdToken:function(a){},removeUserIdToken:function(a){},clearUserIdTokens:function(){},addServiceTokens:function(a){},getServiceTokens:function(a,b){},removeServiceTokens:function(a,b,c){},clearServiceTokens:function(){}}),zd;(function(){zd=ge.extend({init:function g(){g.base.call(this);Object.defineProperties(this,{masterTokens:{value:{},writable:!1,enumerable:!1,configurable:!1},cryptoContexts:{value:{},writable:!1,enumerable:!1,
configurable:!1},userIdTokens:{value:{},writable:!1,enumerable:!1,configurable:!1},nonReplayableIds:{value:{},writable:!1,enumerable:!1,configurable:!1},unboundServiceTokens:{value:{},writable:!1,enumerable:!1,configurable:!1},mtServiceTokens:{value:{},writable:!1,enumerable:!1,configurable:!1},uitServiceTokens:{value:{},writable:!1,enumerable:!1,configurable:!1}})},setCryptoContext:function(a,b){if(b){var c=a.uniqueKey();this.masterTokens[c]=a;this.cryptoContexts[c]=b}else this.removeCryptoContext(a)},
getMasterToken:function(){var a=null,b;for(b in this.masterTokens){var c=this.masterTokens[b];if(!a||c.isNewerThan(a))a=c}return a},getNonReplayableId:function(a){a=a.serialNumber;var b;b=void 0!==this.nonReplayableIds[a]?this.nonReplayableIds[a]:0;if(0>b||b>Y)throw new B("Non-replayable ID "+b+" is outside the valid range.");b=b==Y?0:b+1;return this.nonReplayableIds[a]=b},getCryptoContext:function(a){return this.cryptoContexts[a.uniqueKey()]},removeCryptoContext:function(a){var b=a.uniqueKey();if(this.masterTokens[b]){delete this.masterTokens[b];
delete this.cryptoContexts[b];var b=a.serialNumber,c;for(c in this.masterTokens)if(this.masterTokens[c].serialNumber==b)return;delete this.nonReplayableIds[b];Object.keys(this.userIdTokens).forEach(function(b){b=this.userIdTokens[b];b.isBoundTo(a)&&this.removeUserIdToken(b)},this);try{this.removeServiceTokens(null,a,null)}catch(d){if(d instanceof k)throw new B("Unexpected exception while removing master token bound service tokens.",d);throw d;}}},clearCryptoContexts:function(){[this.masterTokens,
this.cryptoContexts,this.nonReplayableIds,this.userIdTokens,this.uitServiceTokens,this.mtServiceTokens].forEach(function(a){for(var b in a)delete a[b]},this)},addUserIdToken:function(b,c){var d=!1,e;for(e in this.masterTokens)if(c.isBoundTo(this.masterTokens[e])){d=!0;break}if(!d)throw new k(a.USERIDTOKEN_MASTERTOKEN_NOT_FOUND,"uit mtserialnumber "+c.mtSerialNumber);this.userIdTokens[b]=c},getUserIdToken:function(a){return this.userIdTokens[a]},removeUserIdToken:function(a){var b=null,c;for(c in this.masterTokens){var d=
this.masterTokens[c];if(a.isBoundTo(d)){b=d;break}}Object.keys(this.userIdTokens).forEach(function(c){if(this.userIdTokens[c].equals(a)){delete this.userIdTokens[c];try{this.removeServiceTokens(null,b,a)}catch(d){if(d instanceof k)throw new B("Unexpected exception while removing user ID token bound service tokens.",d);throw d;}}},this)},clearUserIdTokens:function(){for(var a in this.userIdTokens){var b=this.userIdTokens[a];try{this.removeServiceTokens(null,null,b)}catch(c){if(c instanceof k)throw new B("Unexpected exception while removing user ID token bound service tokens.",
c);throw c;}delete this.userIdTokens[a]}},addServiceTokens:function(b){b.forEach(function(b){if(b.isUnbound())this.unboundServiceTokens[b.uniqueKey()]=b;else{if(b.isMasterTokenBound()){var c=!1,d;for(d in this.masterTokens)if(b.isBoundTo(this.masterTokens[d])){c=!0;break}if(!c)throw new k(a.SERVICETOKEN_MASTERTOKEN_NOT_FOUND,"st mtserialnumber "+b.mtSerialNumber);}if(b.isUserIdTokenBound()){var c=!1,g;for(g in this.userIdTokens)if(b.isBoundTo(this.userIdTokens[g])){c=!0;break}if(!c)throw new k(a.SERVICETOKEN_USERIDTOKEN_NOT_FOUND,
"st uitserialnumber "+b.uitSerialNumber);}b.isMasterTokenBound()&&((g=this.mtServiceTokens[b.mtSerialNumber])||(g={}),g[b.uniqueKey()]=b,this.mtServiceTokens[b.mtSerialNumber]=g);b.isUserIdTokenBound()&&((g=this.uitServiceTokens[b.uitSerialNumber])||(g={}),g[b.uniqueKey()]=b,this.uitServiceTokens[b.uitSerialNumber]=g)}},this)},getServiceTokens:function(b,c){if(c){if(!b)throw new k(a.USERIDTOKEN_MASTERTOKEN_NULL);if(!c.isBoundTo(b))throw new k(a.USERIDTOKEN_MASTERTOKEN_MISMATCH,"uit mtserialnumber "+
c.mtSerialNumber+"; mt "+b.serialNumber);}var d={},e;for(e in this.unboundServiceTokens){var f=this.unboundServiceTokens[e];d[f.uniqueKey()]=f}if(b&&(f=this.mtServiceTokens[b.serialNumber]))for(e in f){var q=f[e];q.isUserIdTokenBound()||(d[e]=q)}if(c&&(f=this.uitServiceTokens[c.serialNumber]))for(e in f)q=f[e],q.isBoundTo(b)&&(d[e]=q);f=[];for(e in d)f.push(d[e]);return f},removeServiceTokens:function(b,c,d){if(d&&c&&!d.isBoundTo(c))throw new k(a.USERIDTOKEN_MASTERTOKEN_MISMATCH,"uit mtserialnumber "+
d.mtSerialNumber+"; mt "+c.serialNumber);if(b&&!c&&!d){Object.keys(this.unboundServiceTokens).forEach(function(a){this.unboundServiceTokens[a].name==b&&delete this.unboundServiceTokens[a]},this);for(var e in this.mtServiceTokens){var f=this.mtServiceTokens[e],q=Object.keys(f);q.forEach(function(a){f[a].name==b&&delete f[a]},this);this.mtServiceTokens[e]=f}for(var n in this.uitServiceTokens)f=this.uitServiceTokens[n],e=Object.keys(f),e.forEach(function(a){f[a].name==b&&delete f[a]},this),this.uitServiceTokens[n]=
f}if(c&&!d){if(f=this.mtServiceTokens[c.serialNumber])q=Object.keys(f),q.forEach(function(a){var c=f[a];b&&c.name!=b||delete f[a]},this),this.mtServiceTokens[c.serialNumber]=f;for(n in this.uitServiceTokens){var z=this.uitServiceTokens[n];e=Object.keys(z);e.forEach(function(a){var d=z[a];b&&d.name!=b||d.isBoundTo(c)&&delete z[a]},this);this.uitServiceTokens[n]=z}}d&&(f=this.uitServiceTokens[d.serialNumber])&&(e=Object.keys(f),e.forEach(function(a){var d=f[a];b&&d.name!=b||c&&!d.isBoundTo(c)||delete f[a]},
this),this.uitServiceTokens[d.serialNumber]=f)},clearServiceTokens:function(){[this.unboundServiceTokens,this.mtServiceTokens,this.uitServiceTokens].forEach(function(a){for(var b in a)delete a[b]},this)}})})();var Hc,bc;(function(){var b=La;Hc=function(c,d){switch(c){case b.LZW:return nrdp.compress(d,"lzw",!0);case b.GZIP:return nrdp.compress(d,"gzip",!0);default:throw new k(a.UNSUPPORTED_COMPRESSION,c);}};bc=function(c,d,e){switch(c){case b.LZW:return nrdp.uncompress(d,"lzw",!0);case b.GZIP:return nrdp.uncompress(d,
"gzip",!0);default:throw new k(a.UNSUPPORTED_COMPRESSION,c.name());}}})();var H;(function(){H=function(b,c,d){a.call(this,1E5+b,c,d)}})();d.Class.mixin(H,{ASN1_PARSE_ERROR:new H(22,b.FAIL,"Error parsing ASN.1."),ASN1_ENCODE_ERROR:new H(23,b.FAIL,"Error encoding ASN.1."),XML_PARSE_ERROR:new H(49,b.FAIL,"Error parsing XML."),XML_ENCODE_ERROR:new H(50,b.FAIL,"Error encoding XML."),MASTERTOKEN_SEQUENCE_NUMBER_OUT_OF_SYNC:new H(1009,b.ENTITY_REAUTH,"Master token sequence number does not have the expected value."),
MASTERTOKEN_IDENTITY_REVOKED:new H(1013,b.ENTITY_REAUTH,"Master token entity identity is revoked."),USERIDTOKEN_IDENTITY_NOT_FOUND:new H(2013,b.USER_REAUTH,"The user identity was not found."),USERIDTOKEN_PASSWORD_VERSION_CHANGED:new H(2014,b.USER_REAUTH,"The user identity must be reauthenticated because the password version changed."),USERIDTOKEN_INCORRECT_MSLUSER:new H(2015,b.FAIL,"The user ID token MSL user type is incorrect."),NPTICKET_GRACE_PERIOD_EXCEEDED:new H(4008,b.ENTITYDATA_REAUTH,"Fake NP-Tickets cannot be used after the grace period when the Playstation Network is up."),
NPTICKET_SERVICE_ID_MISSING:new H(4009,b.ENTITYDATA_REAUTH,"NP-Ticket service ID is missing."),NPTICKET_SERVICE_ID_DISALLOWED:new H(4010,b.ENTITYDATA_REAUTH,"NP-Ticket service ID is not allowed."),NPTICKET_NOT_YET_VALID:new H(4011,b.ENTITYDATA_REAUTH,"NP-Ticket issuance date is in the future."),NPTICKET_EXPIRED:new H(4012,b.ENTITYDATA_REAUTH,"NP-Ticket has expired."),NPTICKET_PRIVATE_KEY_NOT_FOUND:new H(4013,b.ENTITYDATA_REAUTH,"No private key found for NP-Ticket GUID."),NPTICKET_COOKIE_VERIFICATION_FAILED:new H(4014,
b.ENTITYDATA_REAUTH,"NP-Ticket cookie signature verification failed."),NPTICKET_INCORRECT_COOKIE_VERSION:new H(4015,b.ENTITYDATA_REAUTH,"Incorrect NP-Ticket cookie version."),NPTICKET_BROKEN:new H(4016,b.ENTITYDATA_REAUTH,"NP-Ticket broken."),NPTICKET_VERIFICATION_FAILED:new H(4017,b.ENTITYDATA_REAUTH,"NP-Ticket signature verification failed."),NPTICKET_ERROR:new H(4018,b.ENTITYDATA_REAUTH,"Unknown NP-Ticket TCM error."),NPTICKET_CIPHER_INFO_NOT_FOUND:new H(4019,b.ENTITYDATA_REAUTH,"No cipher information found for NP-Ticket."),
NPTICKET_INVALID_CIPHER_INFO:new H(4020,b.ENTITYDATA_REAUTH,"Cipher information for NP-Ticket is invalid."),NPTICKET_UNSUPPORTED_VERSION:new H(4021,b.ENTITYDATA_REAUTH,"Unsupported NP-Ticket version."),NPTICKET_INCORRECT_KEY_LENGTH:new H(4022,b.ENTITYDATA_REAUTH,"Incorrect NP-Ticket public key length."),CRYPTEX_RSA_KEY_SET_NOT_FOUND:new H(4024,b.FAIL,"Cryptex RSA key set not found."),NPTICKET_COOKIE_PARSE_ERROR:new H(4027,b.ENTITYDATA_REAUTH,"Error parsing NP-Ticket cookie."),FORCE_LOGIN:new H(5E3,
b.USERDATA_REAUTH,"User must login again."),NETFLIXID_COOKIES_EXPIRED:new H(5001,b.USERDATA_REAUTH,"Netflix ID cookie identity has expired."),NETFLIXID_COOKIES_BLANK:new H(5002,b.USERDATA_REAUTH,"Netflix ID or Secure Netflix ID cookie is blank."),AUTHMGR_COMMS_FAILURE:new H(5006,b.TRANSIENT_FAILURE,"Error communicating with authentication manager."),SSOTOKEN_BLANK:new H(5009,b.SSOTOKEN_REJECTED,"SSO token is blank."),SSOTOKEN_NOT_ASSOCIATED:new H(5010,b.USERDATA_REAUTH,"SSO token is not associated with a Netflix user."),
PROFILEGUID_BLANK:new H(5012,b.USERDATA_REAUTH,"Profile GUID is blank."),SSOTOKEN_INVALID:new H(5015,b.SSOTOKEN_REJECTED,"SSO token invalid."),ACCTMGR_COMMS_FAILURE:new H(5017,b.TRANSIENT_FAILURE,"Error communicating with the account manager."),SSO_ASSOCIATION_FAILURE:new H(5018,b.TRANSIENT_FAILURE,"SSO user association failed."),SSO_DISASSOCIATION_FAILURE:new H(5019,b.TRANSIENT_FAILURE,"SSO user disassociation failed."),MDX_USERAUTH_VERIFICATION_FAILED:new H(5020,b.USERDATA_REAUTH,"MDX user authentication data verification failed."),
MDX_USERAUTH_ACTION_INVALID:new H(5022,b.USERDATA_REAUTH,"MDX user authentication data action is invalid."),CTICKET_DECRYPT_ERROR:new H(5023,b.USERDATA_REAUTH,"CTicket decryption failed."),CTICKET_CRYPTOCONTEXT_ERROR:new H(5026,b.USERDATA_REAUTH,"Error creating CTicket crypto context."),MDX_PIN_BLANK:new H(5027,b.USERDATA_REAUTH,"MDX controller or target PIN is blank."),MDX_PIN_MISMATCH:new H(5028,b.USERDATA_REAUTH,"MDX controller and target PIN mismatch."),MDX_USER_UNKNOWN:new H(5029,b.USERDATA_REAUTH,
"MDX controller user ID token or CTicket is not decrypted or verified."),MDX_CONTROLLERDATA_INVALID:new H(5031,b.USERDATA_REAUTH,"MDX controller authentication data is invalid."),SSO_ASSOCIATION_WITH_NONMEMBER:new H(5034,b.USERDATA_REAUTH,"SSO user association failed because the customer is not a member."),SSO_ASSOCIATION_WITH_FORMERMEMBER:new H(5035,b.USERDATA_REAUTH,"SSO user association failed because the customer is a former member."),SSO_ASSOCIATION_CONFLICT:new H(5036,b.USERDATA_REAUTH,"SSO user association failed because the token identifies a different member."),
PROFILE_SWITCH_DISALLOWED:new H(5038,b.TRANSIENT_FAILURE,"Unable to switch user profile."),MEMBERSHIPCLIENT_COMMS_FAILURE:new H(5039,b.TRANSIENT_FAILURE,"Error communicating with the membership manager."),USERIDTOKEN_IDENTITY_NOT_ASSOCIATED_WITH_ENTITY:new H(5040,b.USERDATA_REAUTH,"The entity is not associated with the user."),INCORRECT_MSLUSER:new H(5041,b.FAIL,"The MSL user type is incorrect."),NONREPLAYABLE_ID_OUT_OF_RANGE:new H(6032,b.FAIL,"Non-replayable message non-replayable ID is out of range."),
CRYPTEX_ENCRYPTION_ERROR:new H(8E3,b.FAIL,"Error encrypting data with cryptex."),CRYPTEX_DECRYPTION_ERROR:new H(8001,b.FAIL,"Error decrypting data with cryptex."),CRYPTEX_MAC_ERROR:new H(8002,b.FAIL,"Error computing MAC with cryptex."),CRYPTEX_VERIFY_ERROR:new H(8003,b.FAIL,"Error verifying MAC or signature with cryptex."),CRYPTEX_CONTEXT_CREATION_FAILURE:new H(8004,b.FAIL,"Error creating cryptex cipher or MAC context."),DATAMODEL_DEVICE_ACCESS_ERROR:new H(8005,b.TRANSIENT_FAILURE,"Error accessing data model device."),
DATAMODEL_DEVICETYPE_NOT_FOUND:new H(8006,b.FAIL,"Data model device type not found."),CRYPTEX_KEYSET_UNSUPPORTED:new H(8007,b.FAIL,"Cryptex key set not supported."),CRYPTEX_PRIVILEGE_EXCEPTION:new H(8008,b.FAIL,"Insufficient privileges for cryptex operation."),CRYPTEX_WRAP_ERROR:new H(8009,b.FAIL,"Error wrapping data with cryptex."),CRYPTEX_UNWRAP_ERROR:new H(8010,b.FAIL,"Error unwrapping data with cryptex."),CRYPTEX_COMMS_FAILURE:new H(8011,b.TRANSIENT_FAILURE,"Error comunicating with cryptex."),
CRYPTEX_SIGN_ERROR:new H(8012,b.FAIL,"Error computing signature with cryptex."),CRYPTEX_FINGERPRINT_ERROR:new H(8013,b.FAIL,"Error computing key fingerprint with cryptex.")});Object.freeze(H);var Ad;(function(){Ad=mb.extend({init:function g(a,b,c){g.base.call(this);Object.defineProperties(this,{id:{value:b,writable:!1,enumerable:!1,configurable:!1},privateKey:{value:c,writable:!1,enumerable:!1,configurable:!1}})},encrypt:function(a,b){b.result(a)},decrypt:function(a,b){b.result(a)},wrap:function(b,
c){c.error(new q(a.WRAP_NOT_SUPPORTED))},unwrap:function(b,c,d){d.error(new q(a.UNWRAP_NOT_SUPPORTED))},sign:function(b,d){c(d,function(){if(!this.privateKey)throw new q(a.SIGN_NOT_SUPPORTED,"no private key");var c=va.sign(Tb,this.privateKey,b);c.oncomplete=function(){d.result(c.result)};c.onerror=function(){d.error(new q(a.SIGNATURE_ERROR))}},this)},verify:function(a,b,c){c.result(a)}})})();var Va,Bd;(function(){Va=hb.extend({init:function g(a){g.base.call(this,$.MGK);Object.defineProperties(this,
{identity:{value:a,writable:!1,configurable:!1}})},getIdentity:function(){return this.identity},getAuthData:function(){var a={};a.identity=this.identity;return a},equals:function h(a){return this===a?!0:a instanceof Va?h.base.call(this,this,a)&&this.identity==a.identity:!1}});Bd=function(b){var c=b.identity;if(!c)throw new A(a.JSON_PARSE_ERROR,"mgk authdata"+JSON.stringify(b));return new Va(c)}})();var he=Lb.extend({init:function g(a){g.base.call(this,$.MGK);Object.defineProperties(this,{localIdentity:{value:a,
writable:!1,enumerable:!1,configurable:!1}})},createData:function(a,b){return Bd(b)},getCryptoContext:function(b,c){if(!(c instanceof Va))throw new B("Incorrect authentication data type "+JSON.stringify(c)+".");if(c.identity!=this.localIdentity)throw(new $a(a.ENTITY_NOT_FOUND,"mgk "+c.identity)).setEntity(c);return new zb}}),Db,Cd;(function(){Db=hb.extend({init:function h(a,b){h.base.call(this,$.NPTICKET);var c=b.algorithm.npTicketExpiration,d=b.algorithm.npTicket,e=b.algorithm.npTicketIssue,f=b.algorithm.npTicketFake;
if(c<e)throw new B("Cannot construct an NP-Ticket that expires before it was issued.");Object.defineProperties(this,{identity:{value:a,writable:!1,configurable:!1},privateKey:{value:b,writable:!1,configurable:!1},npticket:{value:d,writable:!1,enumerable:!0,configuration:!1},issuance:{value:e,writable:!1,configurable:!1},expiration:{value:c,writable:!1,configurable:!1},fake:{value:f,writable:!1,configurable:!1}})},isNetflixGenerated:function(){return this.fake},isValid:function(a){return Date.now()+
a>=1E3*this.issuance},isExpired:function(a){return Date.now()-a>1E3*this.expiration},getIssuance:function(){return new Date(1E3*this.issuance)},getExpiration:function(){return new Date(1E3*this.expiration)},getAuthData:function(){var a={};a.npticket=this.npticket;return a},equals:function m(a){return this===a?!0:a instanceof Db?m.base.call(this,this,a)&&ba(this.npticket,a.npticket):!1},getIdentity:function(){return this.identity},getPrivateKey:function(){return this.privateKey}});Cd=function(){throw new $a(a.UNSUPPORTED_ENTITY_AUTH,
"npticket");}})();var ie=Lb.extend({init:function h(a){h.base.call(this,$.NPTICKET)},createData:function(a,b){return Cd(b)},getCryptoContext:function(b,c){if(!(c instanceof Db))throw new B("Incorrect authentication data type "+c+".");var d=c.getIdentity(),e=c.getPrivateKey();if(!d)throw(new $a(a.ENTITY_NOT_FOUND,"npticket "+d)).setEntity(c);if(!e)throw(new $a(a.NPTICKET_PRIVATE_KEY_NOT_FOUND,"npticket "+d)).setEntity(c);return new Ad(b,d,e)}}),Dd,Jc,Kc,Ed,Fd;(function(){function b(a){var c=a;c&&c.length&&
c[0]&&(c=new Uint8Array(a.length+1),c[0]=0,c.set(a,1));return c}function e(a,b,d,h){c(h,function(){Ta(a,{result:function(a){Ta(b,{result:function(b){Ta(d,{result:function(c){h.result({encryptionKey:a,hmacKey:b,wrappingKey:c})},error:h.error})},error:h.error})},error:h.error})})}var f=Jc={PSK:"PSK",MGK:"MGK",WRAP:"WRAP"};Fd=d.Class.create({addDerivationKey:function(a,b){},getDerivationKey:function(a){},removeDerivationKey:function(a){}});var t=Kc=nb.extend({init:function z(a,b,c,d,e){z.base.call(this,
za.AUTHENTICATED_DH);switch(a){case f.WRAP:if(!e)throw new B("Previous wrapping key based key exchange requires the previous wrapping key data and ID.");break;default:e=null}Object.defineProperties(this,{mechanism:{value:a,writable:!1,configurable:!1},wrapdata:{value:e,writable:!1,configurable:!1},parametersId:{value:b,writable:!1,configurable:!1},publicKey:{value:c,writable:!1,configurable:!1},privateKey:{value:d,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.mechanism=this.mechanism;
a.publickey=J(b(this.publicKey));a.parametersid=this.parametersId;this.wrapdata&&(a.wrapdata=J(this.wrapdata));return a},equals:function D(a){if(a===this)return!0;if(!(a instanceof Kc))return!1;var b=this.privateKey===a.privateKey||this.privateKey&&a.privateKey&&ba(this.privateKey.getEncoded(),a.privateKey.getEncoded());return D.base.call(this,a)&&this.mechanism==a.mechanism&&this.parametersId==a.parametersId&&ba(this.publicKey,a.publicKey)&&ba(this.wrapdata,a.wrapdata)&&b},uniqueKey:function O(){var a=
O.base.call(this)+":"+this.mechanism+":"+this.parametersId+":"+ja(this.publicKey);this.wrapdata&&(a+=":"+ja(this.wrapdata));return a}}),F=Ed=ob.extend({init:function W(a,b,c,d){W.base.call(this,a,za.AUTHENTICATED_DH);Object.defineProperties(this,{parametersId:{value:b,writable:!1,configurable:!1},publicKey:{value:c,writable:!1,configurable:!1},wrapdata:{value:d,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.parametersid=this.parametersId;a.wrapdata=J(this.wrapdata);var c=b(this.publicKey);
a.publickey=J(c);return a},equals:function u(a){return this===a?!0:a instanceof Ed?u.base.call(this,a)&&this.parametersId==a.parametersId&&ba(this.publicKey,a.publicKey)&&ba(this.wrapdata,a.wrapdata):!1},uniqueKey:function x(){return x.base.call(this)+":"+this.parametersId+":"+ja(this.publicKey)+":"+ja(this.wrapdata)}});Dd=Ea.extend({init:function L(a,b){L.base.call(this,za.AUTHENTICATED_DH);Object.defineProperties(this,{repository:{value:a,writable:!1,enumerable:!1,configurable:!1},params:{value:b,
writable:!1,enumerable:!1,configurable:!1}})},createRequestData:function(a,b,d){c(d,function(){return RequestData$parse(b)})},createResponseData:function(c,d,e){c=e.wrapdata;var f=e.parametersid,l=e.publickey;if("string"!==typeof c||"string"!==typeof f||"string"!==typeof l)throw new A(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(e));var k;try{k=S(c)}catch(m){throw new T(a.KEYX_WRAPPING_KEY_MISSING,"keydata "+e.toString(),m);}if(!k||0==k.length)throw new T(a.KEYX_WRAPPING_KEY_MISSING,"keydata "+e.toString());
var t;try{var q=S(l);t=b(q)}catch(C){throw new T(a.KEYX_INVALID_PUBLIC_KEY,"keydata "+JSON.stringify(e),C);}if(!t||0==t.length)throw new T(a.KEYX_INVALID_PUBLIC_KEY,"keydata "+JSON.stringify(e));return new F(d,f,t,k)},generateResponse:function(b,d,h,v){function C(b,d,h){c(v,function(){var b=request.mechanism,c=request.wrapdata,k=request.publicKey;switch(b){case f.PSK:case f.MGK:c=this.repository.getDerivationKey();if(!c)throw new T(a.UNSUPPORTED_KEYX_MECHANISM,b);break;case f.WRAP:c=this.repository.getDerivationKey(c);
if(!c)throw new T(a.KEYX_DERIVATION_KEY_MISSING,J(requestWrapdata));break;default:throw new T(a.UNSUPPORTED_KEYX_MECHANISM,b);}ma.deriveKey({name:y.name,params:{"public":k,kd:c}},h).then(function(a){e(a.encryptionKey,a.hmacKey,a.wrappingKey,{result:function(a){s(d,a)},error:v.error})},function(b){v.error(new q(a.DERIVEKEY_ERROR,"",b))})},A)}function s(a,d){c(v,function(){var e=request.parametersId;b.getMslCryptoContext().wrap(d.derivationKey,{result:function(f){f=b.getTokenFactory();h instanceof Da?
f.renewMasterToken(b,h,d.encryptionKey,d.hmacKey,{result:function(d){c(v,function(){var c=new ta(b,d),h=new F(d,e,a);return new Ea.KeyExchangeData(h,c)},A)},error:function(a){c(v,function(){a instanceof k&&a.setEntity(h);throw a;},A)}}):f.createMasterToken(b,h,d.encryptionKey,d.hmacKey,{result:function(d){c(v,function(){var c=new ta(b,d),h=new F(d,e,a);return new Ea.KeyExchangeData(h,c)},A)},error:v.error})},error:v.error})},A)}var A=this;c(v,function(){if(!(d instanceof t))throw new B("Key request data "+
JSON.stringify(d)+" was not created by this factory.");var b;if(h instanceof Da){if(!masterToken.isVerified())throw new Qa(a.MASTERTOKEN_UNTRUSTED,masterToken);b=masterToken.identity}else b=h;var c=this.params.getParameterSpec(d.parametersId);ma.generateKey({name:y,prime:c.p,generator:c.g},!1,Eb).then(function(a){C(b,a.publicKey,a.privateKey)},function(b){v.error(new q(a.GENERATEKEY_ERROR,"Error generating Diffie-Hellman key pair.",b))})},A)},getCryptoContext:function(b,d,h,v,C){function s(d,h,f,
l){c(C,function(){ma.deriveKey({name:y.name,params:{"public":f.publicKey,kd:l.rawKey}},h.privateKey).then(function(a){e(a.encryptionKey,a.hmacKey,a.wrappingKey,{result:function(a){c(C,function(){this.repository.addDerivationKey(f.wrapdata,a.derivationKey);h.wrapdata&&this.repository.removeDerivationKey(h.wrapdata);var c=f.masterToken,e=d.getIdentity();return new ta(b,c,e,a.encryptionKey,a.hmacKey)},A)},error:function(a){c(C,function(){a instanceof k&&a.setEntity(d);throw a;})}})},function(b){C.error((new q(a.DERIVEKEY_ERROR,
"",b)).setEntity(d))})},A)}var A=this;c(C,function(){if(!(d instanceof t))throw new B("Key request data "+JSON.stringify(d)+" was not created by this factory.");if(!(h instanceof F))throw new B("Key response data "+JSON.stringify(h)+" was not created by this factory.");var e=d.parametersId,k=h.parametersId;if(e!=k)throw(new T(a.KEYX_RESPONSE_REQUEST_MISMATCH,"request "+e+"; response "+k)).setEntity(v);var m=d.mechanism,q=d.wrapdata;b.getEntityAuthenticationData(null,{result:function(b){c(C,function(){var c;
switch(m){case f.WRAP:c=this.repository.getDerivationKey(q);if(!c)throw new T(a.KEYX_DERIVATION_KEY_MISSING,J(q));break;case f.PSK:case f.MGK:c=this.repository.getDerivationKey();if(!c)throw new T(a.UNSUPPORTED_KEYX_MECHANISM,m);break;default:throw new B("Key request data mechanism "+m+" is not supported but it should be.");}s(b,d,h,c)},A)},error:C.error})},A)}})})();var Lc,dc,Gd,Mc;(function(){function b(d,h,f,l,k){c(k,function(){switch(h){case e.PSK:var b=new Ua(l),t=d.getEntityAuthenticationFactory($.PSK);
if(!t)throw new T(a.UNSUPPORTED_KEYX_MECHANISM,h);b=t.getCryptoContext(d,b);return new db(d,eb.A128KW,K,t._kpw);case e.MGK:b=new Va(l);t=d.getEntityAuthenticationFactory($.MGK);if(!t)throw new T(a.UNSUPPORTED_KEYX_MECHANISM,h);b=t.getCryptoContext(d,b);return new db(d,eb.A128KW,K,t._kdw);case e.WRAP:b=d.getMslCryptoContext();b.unwrap(f,w,Fa,{result:function(a){c(k,function(){return new db(d,eb.A128KW,K,a)})},error:k.error});break;default:throw new T(a.UNSUPPORTED_KEYX_MECHANISM,h);}})}var e={PSK:"PSK",
MGK:"MGK",WRAP:"WRAP"},f=dc=nb.extend({init:function n(a,b){n.base.call(this,za.JWE_LADDER);switch(a){case e.WRAP:if(!b)throw new B("Previous wrapping key based key exchange requires the previous wrapping key data and ID.");break;default:b=null}Object.defineProperties(this,{mechanism:{value:a,writable:!1,configurable:!1},wrapdata:{value:b,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.mechanism=this.mechanism;this.wrapdata&&(a.wrapdata=J(this.wrapdata));return a},equals:function z(a){return a===
this?!0:a instanceof dc?z.base.call(this,a)&&this.mechanism==a.mechanism&&ba(this.wrapdata,a.wrapdata):!1},uniqueKey:function D(){var a=D.base.call(this)+":"+this.mechanism;this.wrapdata&&(a+=":"+ja(this.wrapdata));return a}}),t=Gd=ob.extend({init:function O(a,b,c,d,e){O.base.call(this,a,za.JWE_LADDER);Object.defineProperties(this,{wrapKey:{value:b,writable:!1,configurable:!1},wrapdata:{value:c,writable:!1,configurable:!1},encryptionKey:{value:d,writable:!1,configurable:!1},hmacKey:{value:e,writable:!1,
configurable:!1}})},getKeydata:function(){var a={};a.wrapkey=J(this.wrapKey);a.wrapdata=J(this.wrapdata);a.encryptionkey=J(this.encryptionKey);a.hmackey=J(this.hmacKey);return a},equals:function W(a){return this===a?!0:a instanceof Gd?W.base.call(this,a)&&ba(this.wrapKey,a.wrapKey)&&ba(this.wrapdata,a.wrapdata)&&ba(this.encryptionKey,a.encryptionKey)&&ba(this.hmacKey,a.hmacKey):!1},uniqueKey:function u(){return u.base.call(this)+":"+ja(this.wrapKey)+":"+ja(this.wrapdata)+":"+ja(this.encryptionKey)+
":"+ja(this.hmacKey)}});Mc=d.Class.create({addCryptoContext:function(a,b){},getCryptoContext:function(a){},removeCryptoContext:function(a){}});Lc=Ea.extend({init:function x(a){x.base.call(this,za.JWE_LADDER);Object.defineProperties(this,{repository:{value:a,writable:!1,enumerable:!1,configurable:!1}})},createRequestData:function(b,d,h){c(h,function(){var b=d.mechanism,c=d.wrapdata;if(!b||b==e.WRAP&&(!c||"string"!==typeof c))throw new A(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(d));if(!e[b])throw new T(a.UNIDENTIFIED_KEYX_MECHANISM,
b);var h;switch(b){case e.WRAP:try{h=S(c)}catch(k){throw new T(a.KEYX_WRAPPING_KEY_MISSING,"keydata "+d.toString());}if(null==h||0==h.length)throw new T(a.KEYX_WRAPPING_KEY_MISSING,"keydata "+d.toString());break;default:h=null}return new f(b,h)})},createResponseData:function(b,c,d){b=d.wrapkey;var e=d.wrapdata,h=d.encryptionkey,f=d.hmackey;if(!(b&&"string"===typeof b&&e&&"string"===typeof e&&h&&"string"===typeof h&&f&&"string"===typeof f))throw new A(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(d));
var l,k,m,E;try{l=S(b),k=S(e)}catch(C){throw new q(a.INVALID_SYMMETRIC_KEY,"keydata "+JSON.stringify(d),C);}try{m=S(h)}catch(s){throw new q(a.INVALID_ENCRYPTION_KEY,"keydata "+JSON.stringify(d),s);}try{E=S(f)}catch(sa){throw new q(a.INVALID_HMAC_KEY,"keydata "+JSON.stringify(d),sa);}return new t(c,l,k,m,E)},generateResponse:function(d,e,m,r){function v(a,b,e){la.generateSessionKeys(d,{result:function(d){c(r,function(){C(a,b,e,d.encryptionKey,d.hmacKey)},la)},error:function(a){c(r,function(){a instanceof
k&&a.setEntity(E);throw a;})}})}function C(a,f,l,m,t){c(r,function(){var v=e;b(d,v.mechanism,v.wrapdata,a,{result:function(a){a.wrap(f,{result:function(a){s(f,l,m,t,a)},error:function(a){c(r,function(){a instanceof k&&a.setEntity(E);throw a;})}})},error:function(a){c(r,function(){a instanceof k&&a.setEntity(E);throw a;})}})},la)}function s(a,b,e,h,f){c(r,function(){var l=new db(d,eb.A128KW,K,a);l.wrap(e,{result:function(a){l.wrap(h,{result:function(c){A(b,f,e,a,h,c)},error:function(a){c(r,function(){a instanceof
k&&a.setEntity(E);throw a;})}})},error:function(a){c(r,function(){a instanceof k&&a.setEntity(E);throw a;})}})},la)}function A(a,b,e,h,f,l){c(r,function(){var v=d.getTokenFactory();E?v.renewMasterToken(d,E,e,f,{result:function(e){c(r,function(){var c=new ta(d,e),f=new t(e,b,a,h,l);return new Ea.KeyExchangeData(f,c,r)},la)},error:function(a){c(r,function(){a instanceof k&&a.setEntity(E);throw a;})}}):v.createMasterToken(d,m,e,f,{result:function(e){c(r,function(){var c=new ta(d,e),f=new t(e,b,a,h,l);
return new Ea.KeyExchangeData(f,c,r)},la)},error:r.error})},la)}var la=this,E;c(r,function(){if(!(e instanceof f))throw new B("Key request data "+JSON.stringify(e)+" was not created by this factory.");var b=m;if(m instanceof Da){if(!m.isVerified())throw new Qa(a.MASTERTOKEN_UNTRUSTED,m);E=m;b=m.identity}var h=new Uint8Array(16);d.getRandom().nextBytes(h);bb(h,w,Fa,{result:function(a){c(r,function(){d.getMslCryptoContext().wrap(a,{result:function(c){v(b,a,c)},error:function(a){c(r,function(){a instanceof
k&&a.setEntity(E);throw a;},la)}})},la)},error:function(b){c(r,function(){throw(new q(a.WRAP_KEY_CREATION_FAILURE,null,b)).setEntity(E);},la)}})},la)},getCryptoContext:function(b,d,h,r,v){function q(a,d,e,h,f){c(v,function(){var l=new db(b,eb.A128KW,K,f);l.unwrap(d.encryptionKey,s,ua,{result:function(f){l.unwrap(d.hmacKey,P,V,{result:function(a){c(v,function(){this.repository.addCryptoContext(d.wrapdata,l);this.repository.removeCryptoContext(e);return new ta(b,d.masterToken,h,f,a)},C)},error:function(b){c(v,
function(){b instanceof k&&b.setEntity(a);throw b;})}})},error:function(b){c(v,function(){b instanceof k&&b.setEntity(a);throw b;})}})},C)}var C=this;c(v,function(){if(!(d instanceof f))throw new B("Key request data "+JSON.stringify(d)+" was not created by this factory.");if(!(h instanceof t))throw new B("Key response data "+JSON.stringify(h)+" was not created by this factory.");var r=d.mechanism,s=d.wrapdata;b.getEntityAuthenticationData(null,{result:function(d){c(v,function(){var f=d.getIdentity(),
l;switch(r){case e.PSK:l=new Ua(f);var t=b.getEntityAuthenticationFactory($.PSK);if(!t)throw(new T(a.UNSUPPORTED_KEYX_MECHANISM,r)).setEntity(d);t.getCryptoContext(b,l);l=new db(b,eb.A128KW,K,t._kpw);break;case e.MGK:l=new Va(f);t=b.getEntityAuthenticationFactory($.MGK);if(!t)throw(new T(a.UNSUPPORTED_KEYX_MECHANISM,r)).setEntity(d);t.getCryptoContext(b,l);l=new db(b,eb.A128KW,K,t._kdw);break;case e.WRAP:l=this.repository.getCryptoContext(s);if(!l)throw(new T(a.KEYX_WRAPPING_KEY_MISSING,J(s))).setEntity(d);
break;default:throw(new T(a.UNSUPPORTED_KEYX_MECHANISM,r)).setEntity(d);}l.unwrap(h.wrapKey,w,Fa,{result:function(a){q(d,h,s,f,a)},error:function(a){c(v,function(){a instanceof k&&a.setEntity(d);throw a;})}})},C)},error:v.error})},C)}})})();var Hd,Id;(function(){function b(e,h,f,l,k){c(k,function(){switch(h){case d.PSK:var b=new Ua(l),x=e.getEntityAuthenticationFactory($.PSK);if(!x)throw new T(a.UNSUPPORTED_KEYX_MECHANISM,h);b=x.getCryptoContext(e,b);return new C(void 0);case d.MGK:b=new Va(l);x=
e.getEntityAuthenticationFactory($.MGK);if(!x)throw new T(a.UNSUPPORTED_KEYX_MECHANISM,h);b=x.getCryptoContext(e,b);return new C(void 0);case d.WRAP:b=e.getMslCryptoContext();b.unwrap(f,w,Fa,{result:function(a){c(k,function(){return new C(a)})},error:k.error});break;default:throw new T(a.UNSUPPORTED_KEYX_MECHANISM,h);}})}var d={PSK:"PSK",MGK:"MGK",WRAP:"WRAP"},e=Hd=nb.extend({init:function z(a,b){z.base.call(this,za.JWK_LADDER);switch(a){case d.WRAP:if(!b)throw new B("Previous wrapping key based key exchange requires the previous wrapping key data and ID.");
break;default:b=null}Object.defineProperties(this,{mechanism:{value:a,writable:!1,configurable:!1},wrapdata:{value:b,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.mechanism=this.mechanism;this.wrapdata&&(a.wrapdata=J(this.wrapdata));return a},equals:function D(a){return a===this?!0:a instanceof Hd?D.base.call(this,a)&&this.mechanism==a.mechanism&&ba(this.wrapdata,a.wrapdata):!1},uniqueKey:function O(){var a=O.base.call(this)+":"+this.mechanism;this.wrapdata&&(a+=":"+ja(this.wrapdata));
return a}}),f=Id=ob.extend({init:function W(a,b,c,d,e){W.base.call(this,a,za.JWK_LADDER);Object.defineProperties(this,{wrapKey:{value:b,writable:!1,configurable:!1},wrapdata:{value:c,writable:!1,configurable:!1},encryptionKey:{value:d,writable:!1,configurable:!1},hmacKey:{value:e,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.wrapkey=J(this.wrapKey);a.wrapdata=J(this.wrapdata);a.encryptionkey=J(this.encryptionKey);a.hmackey=J(this.hmacKey);return a},equals:function u(a){return this===
a?!0:a instanceof Id?u.base.call(this,a)&&ba(this.wrapKey,a.wrapKey)&&ba(this.wrapdata,a.wrapdata)&&ba(this.encryptionKey,a.encryptionKey)&&ba(this.hmacKey,a.hmacKey):!1},uniqueKey:function x(){return x.base.call(this)+":"+ja(this.wrapKey)+":"+ja(this.wrapdata)+":"+ja(this.encryptionKey)+":"+ja(this.hmacKey)}}),C=mb.extend({init:function(a){a&&(a=a.rawKey);Object.defineProperties(this,{_wrapKey:{value:a,writable:!1,enumerable:!1,configurable:!1}})},encrypt:function(b,c){c.error(new q(a.ENCRYPT_NOT_SUPPORTED))},
decrypt:function(b,c){c.error(new q(a.DECRYPT_NOT_SUPPORTED))},wrap:function(b,d){c(d,function(){ma.wrapKey("jwk",b.rawKey,this._wrapKey,w).then(function(a){d.result(a)},function(b){d.error(new q(a.WRAP_ERROR))})},this)},unwrap:function(b,d,e,h){function f(b){c(h,function(){switch(b.type){case "secret":Ta(b,h);break;case "public":jb(b,h);break;case "private":lb(b,h);break;default:throw new q(a.UNSUPPORTED_KEY,"type: "+b.type);}})}c(h,function(){ma.unwrapKey("jwk",b,this._wrapKey,w,d,!1,e).then(function(a){f(a)},
function(b){h.error(new q(a.UNWRAP_ERROR))})},this)},sign:function(b,c){c.error(new q(a.SIGN_NOT_SUPPORTED))},verify:function(b,c,d){d.error(new q(a.VERIFY_NOT_SUPPORTED))}});Ea.extend({init:function L(a){L.base.call(this,za.JWK_LADDER);Object.defineProperties(this,{repository:{value:a,writable:!1,enumerable:!1,configurable:!1}})},createRequestData:function(b,h,f){c(f,function(){var b=h.mechanism,c=h.wrapdata;if(!b||b==d.WRAP&&(!c||"string"!==typeof c))throw new A(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(h));
if(!d[b])throw new T(a.UNIDENTIFIED_KEYX_MECHANISM,b);var f;switch(b){case d.WRAP:try{f=S(c)}catch(k){throw new T(a.KEYX_WRAPPING_KEY_MISSING,"keydata "+h.toString());}if(null==f||0==f.length)throw new T(a.KEYX_WRAPPING_KEY_MISSING,"keydata "+h.toString());break;default:f=null}return new e(b,f)})},createResponseData:function(b,c,d){b=d.wrapkey;var e=d.wrapdata,h=d.encryptionkey,l=d.hmackey;if(!(b&&"string"===typeof b&&e&&"string"===typeof e&&h&&"string"===typeof h&&l&&"string"===typeof l))throw new A(a.JSON_PARSE_ERROR,
"keydata "+JSON.stringify(d));var k,m,C,F;try{k=S(b),m=S(e)}catch(s){throw new q(a.INVALID_SYMMETRIC_KEY,"keydata "+JSON.stringify(d),s);}try{C=S(h)}catch(w){throw new q(a.INVALID_ENCRYPTION_KEY,"keydata "+JSON.stringify(d),w);}try{F=S(l)}catch(B){throw new q(a.INVALID_HMAC_KEY,"keydata "+JSON.stringify(d),B);}return new f(c,k,m,C,F)},generateResponse:function(d,m,r,v){function s(a,b,e){E.generateSessionKeys(d,{result:function(d){c(v,function(){A(a,b,e,d.encryptionKey,d.hmacKey)},E)},error:function(a){c(v,
function(){a instanceof k&&a.setEntity(y);throw a;})}})}function A(a,e,f,l,r){c(v,function(){var t=m;b(d,t.mechanism,t.wrapdata,a,{result:function(a){a.wrap(e,{result:function(a){Z(e,f,l,r,a)},error:function(a){c(v,function(){a instanceof k&&a.setEntity(y);throw a;})}})},error:function(a){c(v,function(){a instanceof k&&a.setEntity(y);throw a;})}})},E)}function Z(a,b,d,e,h){c(v,function(){var f=new C(a);f.wrap(d,{result:function(a){f.wrap(e,{result:function(c){Vb(b,h,d,a,e,c)},error:function(a){c(v,
function(){a instanceof k&&a.setEntity(y);throw a;})}})},error:function(a){c(v,function(){a instanceof k&&a.setEntity(y);throw a;})}})},E)}function Vb(a,b,e,h,l,m){c(v,function(){var q=d.getTokenFactory();y?q.renewMasterToken(d,y,e,l,{result:function(e){c(v,function(){var c=new ta(d,e),l=new f(e,b,a,h,m);return new Ea.KeyExchangeData(l,c,v)},E)},error:function(a){c(v,function(){a instanceof k&&a.setEntity(y);throw a;})}}):q.createMasterToken(d,r,e,l,{result:function(e){c(v,function(){var c=new ta(d,
e),l=new f(e,b,a,h,m);return new Ea.KeyExchangeData(l,c,v)},E)},error:v.error})},E)}var E=this,y;c(v,function(){if(!(m instanceof e))throw new B("Key request data "+JSON.stringify(m)+" was not created by this factory.");var b=r;if(r instanceof Da){if(!r.isVerified())throw new Qa(a.MASTERTOKEN_UNTRUSTED,r);y=r;b=r.identity}var h=new Uint8Array(16);d.getRandom().nextBytes(h);bb(h,w,Fa,{result:function(a){c(v,function(){d.getMslCryptoContext().wrap(a,{result:function(c){s(b,a,c)},error:function(a){c(v,
function(){a instanceof k&&a.setEntity(y);throw a;},E)}})},E)},error:function(b){c(v,function(){throw(new q(a.WRAP_KEY_CREATION_FAILURE,null,b)).setEntity(y);},E)}})},E)},getCryptoContext:function(b,h,r,v,q){function A(a,d,e,h,f){c(q,function(){var l=new C(f);l.unwrap(d.encryptionKey,s,ua,{result:function(f){l.unwrap(d.hmacKey,P,V,{result:function(a){c(q,function(){this.repository.addCryptoContext(d.wrapdata,l);this.repository.removeCryptoContext(e);return new ta(b,d.masterToken,h,f,a)},y)},error:function(b){c(q,
function(){b instanceof k&&b.setEntity(a);throw b;})}})},error:function(b){c(q,function(){b instanceof k&&b.setEntity(a);throw b;})}})},y)}var y=this;c(q,function(){if(!(h instanceof e))throw new B("Key request data "+JSON.stringify(h)+" was not created by this factory.");if(!(r instanceof f))throw new B("Key response data "+JSON.stringify(r)+" was not created by this factory.");var v=h.mechanism,s=h.wrapdata;b.getEntityAuthenticationData(null,{result:function(e){c(q,function(){var h=e.getIdentity(),
f;switch(v){case d.PSK:f=new Ua(h);var l=b.getEntityAuthenticationFactory($.PSK);if(!l)throw(new T(a.UNSUPPORTED_KEYX_MECHANISM,v)).setEntity(e);l.getCryptoContext(b,f);f=new C(void 0);break;case d.MGK:f=new Va(h);l=b.getEntityAuthenticationFactory($.MGK);if(!l)throw(new T(a.UNSUPPORTED_KEYX_MECHANISM,v)).setEntity(e);l.getCryptoContext(b,f);f=new C(void 0);break;case d.WRAP:f=this.repository.getCryptoContext(s);if(!f)throw(new T(a.KEYX_WRAPPING_KEY_MISSING,J(s))).setEntity(e);break;default:throw(new T(a.UNSUPPORTED_KEYX_MECHANISM,
v)).setEntity(e);}f.unwrap(r.wrapKey,w,Fa,{result:function(a){A(e,r,s,h,a)},error:function(a){c(q,function(){a instanceof k&&a.setEntity(e);throw a;})}})},y)},error:q.error})},y)}})})();var Nc,ec,Jd;(function(){function b(e,h,f,l,k){c(k,function(){switch(h){case d.SESSION:if(!f)throw new T(a.KEYX_MASTER_TOKEN_MISSING,h);var b=e.getMslStore().getCryptoContext(f);if(b)return b;if(!f.isDecrypted())throw new Qa(a.MASTERTOKEN_UNTRUSTED,f);return new ta(e,f);case d.PSK:var b=new Ua(l),c=e.getEntityAuthenticationFactory($.PSK);
if(!c)throw new T(a.UNSUPPORTED_KEYX_KEY_ID,h);return c.getCryptoContext(e,b);case d.MGK:b=new Va(l);c=e.getEntityAuthenticationFactory($.MGK);if(!c)throw new T(a.UNSUPPORTED_KEYX_KEY_ID,h);return c.getCryptoContext(e,b);default:throw new T(a.UNSUPPORTED_KEYX_KEY_ID,h);}})}var d={PSK:"PSK",MGK:"MGK",SESSION:"SESSION"},e=ec=nb.extend({init:function n(a){n.base.call(this,za.SYMMETRIC_WRAPPED);Object.defineProperties(this,{keyId:{value:a,writable:!1,configurable:!1}})},getKeydata:function(){var a={};
a.keyid=this.keyId;return a},equals:function z(a){return this===a?!0:a instanceof ec?z.base.call(this,a)&&this.keyId==a.keyId:!1},uniqueKey:function D(){return D.base.call(this)+":"+this.keyId}}),f=Jd=ob.extend({init:function O(a,b,c,d){O.base.call(this,a,za.SYMMETRIC_WRAPPED);Object.defineProperties(this,{keyId:{value:b,writable:!1,configurable:!1},encryptionKey:{value:c,writable:!1,configurable:!1},hmacKey:{value:d,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.keyid=this.keyId;
a.encryptionkey=J(this.encryptionKey);a.hmackey=J(this.hmacKey);return a},equals:function W(a){return this===a?!0:a instanceof Jd?W.base.call(this,a)&&this.keyId==a.keyId&&ba(this.encryptionKey,a.encryptionKey)&&ba(this.hmacKey,a.hmacKey):!1},uniqueKey:function u(){return u.base.call(this)+":"+this.keyId+":"+ja(this.encryptionKey)+":"+ja(this.hmacKey)}});Nc=Ea.extend({init:function x(){x.base.call(this,za.SYMMETRIC_WRAPPED)},createRequestData:function(b,h,f){c(f,function(){var b=h.keyid;if(!b||"string"!==
typeof b)throw new A(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(h));if(!d[b])throw new T(a.UNIDENTIFIED_KEYX_KEY_ID,b);return new e(b)},this)},createResponseData:function(b,c,e){b=e.keyid;var h=e.encryptionkey,l=e.hmackey;if(!b||"string"!==typeof b||!h||"string"!==typeof h||!l||"string"!==typeof l)throw new A(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(e));if(!d[b])throw new T(a.UNIDENTIFIED_KEYX_KEY_ID,b);var k;try{k=S(h)}catch(C){throw new q(a.INVALID_ENCRYPTION_KEY,"keydata "+JSON.stringify(e),
C);}var s;try{s=S(l)}catch(w){throw new q(a.INVALID_HMAC_KEY,"keydata "+JSON.stringify(e),w);}return new f(c,b,k,s)},generateResponse:function(d,m,q,r){function v(e,f){c(r,function(){var l=m,t,v;if("string"!==typeof q){if(!q.isVerified())throw new Qa(a.MASTERTOKEN_UNTRUSTED,q);t=q;v=t.identity}else t=null,v=q;b(d,l.keyId,t,v,{result:function(a){a.wrap(e,{result:function(b){a.wrap(f,{result:function(a){C(e,b,f,a)},error:function(a){c(r,function(){a instanceof k&&a.setEntity(t);throw a;},s)}})},error:function(a){c(r,
function(){a instanceof k&&a.setEntity(t);throw a;},s)}})},error:function(a){c(r,function(){a instanceof k&&a.setEntity(t);throw a;},s)}})},s)}function C(a,b,e,h){c(r,function(){var l=m,v=d.getTokenFactory();q instanceof Da?v.renewMasterToken(d,q,a,e,{result:function(a){c(r,function(){var c;try{c=new ta(d,a)}catch(e){if(e instanceof Qa)throw new B("Master token constructed by token factory is not trusted.",e);e instanceof k&&e.setEntity(q);throw e;}var m=new f(a,l.keyId,b,h);return new Ea.KeyExchangeData(m,
c)},s)},error:function(a){c(r,function(){a instanceof k&&a.setEntity(q);throw a;},s)}}):v.createMasterToken(d,q,a,e,{result:function(a){c(r,function(){var c;try{c=new ta(d,a)}catch(e){if(e instanceof Qa)throw new B("Master token constructed by token factory is not trusted.",e);throw e;}var k=new f(a,l.keyId,b,h);return new Ea.KeyExchangeData(k,c)},s)},error:r.error})},s)}var s=this;c(r,function(){if(!(m instanceof e))throw new B("Key request data "+JSON.stringify(m)+" was not created by this factory.");
this.generateSessionKeys(d,{result:function(a){v(a.encryptionKey,a.hmacKey)},error:function(a){c(r,function(){a instanceof k&&q instanceof Da&&a.setEntity(q);throw a;},s)}})},s)},getCryptoContext:function(d,m,q,r,v){function C(a){c(v,function(){a instanceof k&&(a.setEntity(r),a.setEntity(w));throw a;},A)}var A=this,w;c(v,function(){if(!(m instanceof e))throw new B("Key request data "+JSON.stringify(m)+" was not created by this factory.");if(!(q instanceof f))throw new B("Key response data "+JSON.stringify(q)+
" was not created by this factory.");var k=m.keyId,E=q.keyId;if(k!=E)throw(new T(a.KEYX_RESPONSE_REQUEST_MISMATCH,"request "+k+"; response "+E)).setEntity(r);d.getEntityAuthenticationData(null,{result:function(a){c(v,function(){w=a;var e=w.getIdentity();b(d,E,r,e,{result:function(a){a.unwrap(q.encryptionKey,s,ua,{result:function(b){a.unwrap(q.hmacKey,P,V,{result:function(a){d.getEntityAuthenticationData(null,{result:function(e){c(v,function(){var c=e.getIdentity();return new ta(d,q.masterToken,c,
b,a)},A)},error:C})},error:C})},error:C})},error:C})},A)},error:C})},A)}})})();var Pb,Kd,fc,Oc,gc,Pc;(function(){function b(a,c){return"<"+a+">"+c+"</"+a+">"}function e(a){return a.replace(/[<>&"']/g,function(a){return D[a]})}function f(a){return encodeURIComponent(a).replace("%20","+").replace(/[!'()]/g,escape).replace(/\*/g,"%2A")}var t=fc={MSL:"MSL",NTBA:"NTBA",MSL_LEGACY:"MSL_LEGACY"},C=d.Class.create({getAction:function(){},getNonce:function(){},getPin:function(){},getSignature:function(){},
getEncoding:function(){},equals:function(){}}),n=Oc=C.extend({init:function(b,d,e,h,f,l,k){function n(h){c(k,function(){var c;try{var l={};l.useridtoken=b;l.action=d;l.nonce=e;l.pin=J(h);c=na(JSON.stringify(l),ca)}catch(n){throw new A(a.JSON_ENCODE_ERROR,"MSL-based MDX authdata",n);}f.sign(c,{result:function(a){m(c,a)},error:k.error})},t)}function m(a,f){c(k,function(){Object.defineProperties(this,{_userIdToken:{value:b,writable:!1,enumerable:!1,configurable:!1},_action:{value:d,writable:!1,enumerable:!1,
configurable:!1},_nonce:{value:e,writable:!1,enumerable:!1,configurable:!1},_pin:{value:h,writable:!1,enumerable:!1,configurable:!1},_encoding:{value:a,writable:!1,enumerable:!1,configurable:!1},_signature:{value:f,writable:!1,enumerable:!1,configurable:!1}});return this},t)}var t=this;c(k,function(){l?m(l.encoding,l.signature):f.encrypt(na(h,ca),{result:function(a){n(a)},error:k.error})},t)},getUserIdToken:function(){return this._userIdToken},getAction:function(){return this._action},getNonce:function(){return this._nonce},
getPin:function(){return this._pin},getSignature:function(){return this._signature},getEncoding:function(){return this._encoding},equals:function(a){return this===a?!0:a instanceof n?this._action==a._action&&this._nonce==a._nonce&&this._pin==a._pin&&this._userIdToken.equals(a._userIdToken):!1}});Oc.ACTION="userauth";var s=function(b,d,e,h,f){function l(h){c(f,function(){var l=ka(e,ca),n,r,t,q;try{var u=JSON.parse(l);n=u.useridtoken;r=u.action;t=u.nonce;q=u.pin}catch(C){if(C instanceof SyntaxError)throw new A(a.JSON_PARSE_ERROR,
"MDX authdata "+l,C);throw C;}if(!(n&&"object"===typeof n&&r&&"string"===typeof r&&t&&"number"===typeof t&&q&&"string"===typeof q))throw new A(a.JSON_PARSE_ERROR,"MDX authdata "+l);rb(b,n,d,{result:function(b){c(f,function(){if(!b.isDecrypted())throw new U(a.USERAUTH_USERIDTOKEN_NOT_DECRYPTED,"MDX authdata "+l);m(h,b,r,t,q)})},error:function(b){c(f,function(){if(b instanceof k)throw new U(a.USERAUTH_USERIDTOKEN_INVALID,"MDX authdata "+l,b);throw b;})}})})}function m(a,b,d,l,k){c(f,function(){var m=
S(k);a.decrypt(m,{result:function(a){c(f,function(){var c=ka(a,ca);new n(b,d,l,c,null,{encoding:e,signature:h},f)})},error:f.error})})}c(f,function(){var k;try{var n=b.getMslStore().getCryptoContext(d);k=n?n:new ta(b,d)}catch(m){if(m instanceof Qa)throw new U(a.USERAUTH_MASTERTOKEN_NOT_DECRYPTED,"MDX authdata "+J(e));throw m;}k.verify(e,h,{result:function(a){c(f,function(){if(!a)throw new q(H.MDX_USERAUTH_VERIFICATION_FAILED,"MDX authdata "+J(e));l(k)})},error:f.error})})},D={"<":"&lt;",">":"&gt;",
"&":"&amp;",'"':"&quot;","'":"&apos;"},w=gc=C.extend({init:function(a,c,d,f){var l=b("action",e(a)),k=b("nonce",c.toString());d=b("pin",d);l=b("registerdata",l+k+d);l=na(l,"utf-8");Object.defineProperties(this,{_action:{value:a,writable:!1,enumerable:!1,configurable:!1},_nonce:{value:c,writable:!1,enumerable:!1,configurable:!1},_pin:{value:null,writable:!1,enumerable:!1,configurable:!1},_encoding:{value:l,writable:!1,enumerable:!1,configurable:!1},_signature:{value:f,writable:!1,enumerable:!1,configurable:!1}})},
getAction:function(){return this._action},getNonce:function(){return this._nonce},getPin:function(){return this._pin},getSignature:function(){return this._signature},getEncoding:function(){return this._encoding},equals:function(a){return this===a?!0:a instanceof w?this._action==a._action&&this._nonce==a._nonce&&this._pin==a._pin:!1}});gc.ACTION="regpairrequest";var y=Pc=C.extend({init:function(a,d,k,n,t,q){function u(k){c(q,function(){var c=J(k),t=b("action",e(a)),v=b("nonce",d.toString()),u=b("pin",
c),t=b("registerdata",t+v+u),s=na(t,"utf-8"),c="action="+f(a)+"&nonce="+f(d.toString())+"&pin="+f(c);n.sign(na(c,"utf-8"),{result:function(a){C(s,a)},error:q.error})},s)}function C(b,e){c(q,function(){Object.defineProperties(this,{_action:{value:a,writable:!1,enumerable:!1,configurable:!1},_nonce:{value:d,writable:!1,enumerable:!1,configurable:!1},_pin:{value:k,writable:!1,enumerable:!1,configurable:!1},_encoding:{value:b,writable:!1,enumerable:!1,configurable:!1},_signature:{value:e,writable:!1,
enumerable:!1,configurable:!1}});return this},s)}var s=this;c(q,function(){t?C(t.encoding,t.signature):n.encrypt(na(k,"utf-8"),{result:function(a){u(a)},error:q.error})},s)},getAction:function(){return this._action},getNonce:function(){return this._nonce},getPin:function(){return this._pin},getSignature:function(){return this._signature},getEncoding:function(){return this._encoding},equals:function(a){return this===a?!0:a instanceof y?this._action==a._action&&this._nonce==a._nonce&&this._pin==a._pin:
!1}});Pc.ACTION=gc.ACTION;var u=function(a,b,d,e,h){c(h,function(){var k=a.getMslStore().getCryptoContext(b),n=k?k:new ta(a,b),k=ka(d,"utf-8"),m=(new DOMParser).parseFromString(k,"application/xml"),k=m.getElementsByTagName("action"),t=m.getElementsByTagName("nonce"),m=m.getElementsByTagName("pin"),u=k&&1==k.length&&k[0].firstChild?k[0].firstChild.nodeValue:null,C=t&&1==t.length&&t[0].firstChild?parseInt(t[0].firstChild.nodeValue):null,s=m&&1==m.length&&m[0].firstChild?m[0].firstChild.nodeValue:null;
if(!u||!C||!s)throw new A(H.XML_PARSE_ERROR,"MDX authdata "+J(d));k="action="+f(u)+"&nonce="+f(C.toString())+"&pin="+f(s);n.verify(na(k,"utf-8"),e,{result:function(a){c(h,function(){if(!a)throw new q(H.MDX_USERAUTH_VERIFICATION_FAILED,"MDX authdata "+J(d));var b=S(s);n.decrypt(b,{result:function(a){c(h,function(){var b=ka(a,"utf-8");new y(u,C,b,null,{encoding:d,signature:e},h)})},error:h.error})})},error:h.error})})};Pb=ib.extend({init:function L(a,b,c,d,e,h){L.base.call(this,Ra.MDX);var f=null,l=
null,k=null;if("string"===typeof c)a=t.MSL_LEGACY,k=c;else if(c instanceof Uint8Array)a=t.NTBA,l=c;else if(c instanceof Da)a=t.MSL,f=c;else throw new TypeError("Controller token "+c+" is not a master token, encrypted CTicket, or MSL token construct.");var m=c=null,q=null,u=null;if(h){var C=h.controllerAuthData;c=C.getAction();m=C.getPin();q=h.userIdToken;C instanceof n?u=C.getUserIdToken().user:q&&(u=q.user)}Object.defineProperties(this,{mechanism:{value:a,writable:!1,configurable:!1},action:{value:c,
writable:!1,configurable:!1},targetPin:{value:b,writable:!1,configurable:!1},controllerPin:{value:m,writable:!1,configurable:!1},user:{value:u,writable:!1,configurable:!1},_masterToken:{value:f,writable:!1,enumerable:!1,configurable:!1},_encryptedCTicket:{value:l,writable:!1,enumerable:!1,configurable:!1},_mslTokens:{value:k,writable:!1,enumerable:!1,configurable:!1},_controllerEncoding:{value:d,writable:!1,enumerable:!1,configurable:!1},_signature:{value:e,writable:!1,enumerable:!1,configurable:!1}})},
getAuthData:function(){var a={};switch(this.mechanism){case t.MSL:var b=JSON.parse(JSON.stringify(this._masterToken));a.mastertoken=b;break;case t.NTBA:b=ka(this._encryptedCTicket,"utf-8");a.cticket=b;break;case t.MSL_LEGACY:a.cticket=this._mslTokens;break;default:throw new B("Unsupported MDX mechanism.");}a.pin=this.targetPin;a.mdxauthdata=J(this._controllerEncoding);a.signature=J(this._signature);return a},equals:function G(a){return this===a?!0:a instanceof Pb?G.base.call(this,a)&&(this._masterToken==
a._masterToken||this._masterToken&&this._masterToken.equals(a._masterToken))&&(this._encryptedCTicket==a._encryptedCTicket||this._encryptedCTicket&&ba(this._encryptedCTicket,a._encryptedCTicket))&&this._mslTokens==a._mslTokens&&ba(this._controllerEncoding,a._controllerEncoding)&&ba(this._signature,a._signature):!1}});Kd=function(b,d,e){function h(f,l,n,m){pb(b,l,{result:function(h){c(e,function(){if(!h.isDecrypted())throw new U(a.USERAUTH_MASTERTOKEN_NOT_DECRYPTED,"MDX authdata "+d.toString());s(b,
h,n,m,{result:function(a){c(e,function(){var c=a.getEncoding(),d=a.getSignature();return new Pb(b,f,h,c,d,{controllerAuthData:a,userIdToken:null})})},error:e.error})})},error:function(b){c(e,function(){if(b instanceof k)throw new U(a.USERAUTH_MASTERTOKEN_INVALID,"MDX authdata "+JSON.stringify(d),b);throw b;})}})}function f(b,d,h,l){c(e,function(){throw new U(a.UNSUPPORTED_USERAUTH_MECHANISM,"NtbaControllerData$parse");})}function l(h,f,n,m){function t(e,h){c(h,function(){var f;try{f=S(e)}catch(l){throw new U(a.USERAUTH_MASTERTOKEN_INVALID,
"MDX authdata "+JSON.stringify(d),l);}if(!f||0==f.length)throw new U(a.USERAUTH_MASTERTOKEN_MISSING,"MDX authdata "+JSON.stringify(d));try{var n=JSON.parse(ka(f,"utf-8"));pb(b,n,{result:function(b){c(h,function(){if(!b.isDecrypted())throw new U(a.USERAUTH_MASTERTOKEN_NOT_DECRYPTED,"MDX authdata "+d.toString());return b})},error:function(b){c(h,function(){if(b instanceof k)throw new U(a.USERAUTH_MASTERTOKEN_INVALID,"MDX authdata "+JSON.stringify(d),b);throw b;})}})}catch(m){if(m instanceof SyntaxError)throw new A(a.JSON_PARSE_ERROR,
"MDX authdata "+JSON.stringify(d),m);throw m;}})}function q(e,h,f){c(f,function(){var l;try{l=S(e)}catch(n){throw new U(a.USERAUTH_USERIDTOKEN_INVALID,"MDX authdata "+JSON.stringify(d),n);}if(!l||0==l.length)throw new U(a.USERAUTH_USERIDTOKEN_MISSING,"MDX authdata "+JSON.stringify(d));try{var m=JSON.parse(ka(l,"utf-8"));rb(b,m,h,{result:function(b){c(f,function(){if(!b.isDecrypted())throw new U(a.USERAUTH_USERIDTOKEN_NOT_DECRYPTED,"MDX authdata "+JSON.stringify(d));return b})},error:function(b){c(f,
function(){if(b instanceof k)throw new U(a.USERAUTH_USERIDTOKEN_INVALID,"MDX authdata "+JSON.stringify(d),b);throw b;})}})}catch(t){if(t instanceof SyntaxError)throw new A(a.JSON_PARSE_ERROR,"MDX authdata "+JSON.stringify(d),t);throw t;}})}c(e,function(){var l=f.split(",");if(3!=l.length||"1"!=l[0])throw new U(a.UNIDENTIFIED_USERAUTH_MECHANISM,"MDX authdata "+JSON.stringify(d));t(l[1],{result:function(k){q(l[2],k,{result:function(l){u(b,k,n,m,{result:function(a){c(e,function(){return new Pb(b,h,f,
n,m,{controllerAuthData:a,userIdToken:l})})},error:function(b){c(e,function(){if(b instanceof Qa)throw new U(a.USERAUTH_MASTERTOKEN_NOT_DECRYPTED,"MDX authdata "+JSON.stringify(d),b);throw b;})}})},error:e.error})},error:e.error})})}c(e,function(){var b=d.pin,c=d.mdxauthdata,e=d.signature;if(!b||"string"!==typeof b||!c||"string"!==typeof c||!e||"string"!==typeof e)throw new A(a.JSON_PARSE_ERROR,"MDX authdata "+JSON.stringify(d));var k,n;try{k=S(c),n=S(e)}catch(m){throw new U(H.MDX_CONTROLLERDATA_INVALID,
"MDX authdata "+JSON.stringify(d),m);}if(d.mastertoken){c=d.mastertoken;if(!c||"object"!==typeof c)throw new A(a.JSON_PARSE_ERROR,"MDX authdata "+JSON.stringify(d));h(b,c,k,n)}else if(d.cticket){c=d.cticket;if(!c||"string"!==typeof c)throw new A(a.JSON_PARSE_ERROR,"MDX authdata "+JSON.stringify(d));-1==c.indexOf(",")?f(b,c,k,n):l(b,c,k,n)}else throw new U(a.UNIDENTIFIED_USERAUTH_MECHANISM,"MDX authdata "+JSON.stringify(d));})}})();(function(){var b=Oc.ACTION,c=gc.ACTION,d=Pc.ACTION;Nb.extend({init:function F(){F.base.call(this,
Ra.MDX)},createData:function(a,b,c,d){Kd(a,c,d)},authenticate:function(e,f,k,q){if(!(k instanceof Pb))throw new B("Incorrect authentication data type "+k.getClass().getName()+".");e=k.action;switch(k.mechanism){case fc.MSL:if(b!=e)throw(new U(H.MDX_USERAUTH_ACTION_INVALID)).setUser(k);break;case fc.NTBA:if(c!=e)throw(new U(H.MDX_USERAUTH_ACTION_INVALID)).setUser(k);break;case fc.MSL_LEGACY:if(d!=e)throw(new U(H.MDX_USERAUTH_ACTION_INVALID)).setUser(k);}e=k.controllerPin;f=k.targetPin;if(!e||!f)throw(new U(H.MDX_PIN_BLANK)).setUser(k);
if(e!=f)throw(new U(H.MDX_PIN_MISMATCH)).setUser(k);e=k.user;if(!e)throw(new U(H.MDX_USER_UNKNOWN)).setUser(k);if(q&&(q=q.user,!e.equals(q)))throw(new U(a.USERIDTOKEN_USERAUTH_DATA_MISMATCH,"uad user "+e+"; uit user "+q)).setUser(k);return e}})})();var Qb,Ld;(function(){Qb=ib.extend({init:function m(a,b){m.base.call(this,Ra.NETFLIXID);Object.defineProperties(this,{netflixId:{value:a,writable:!1,configurable:!1},secureNetflixId:{value:b,writable:!1,configurable:!1}})},getAuthData:function(){var a=
{};a.netflixid=this.netflixId;this.secureNetflixId&&(a.securenetflixid=this.secureNetflixId);return a},equals:function l(a){return this===a?!0:a instanceof Qb?l.base.call(this,a)&&this.netflixId==a.netflixId&&this.secureNetflixId==a.secureNetflixId:!1}});Ld=function(b){var c=b.netflixid,d=b.securenetflixid;if(!c)throw new A(a.JSON_PARSE_ERROR,"NetflixId authdata "+JSON.stringify(b));return new Qb(c,d)}})();Nb.extend({init:function m(){m.base.call(this,Ra.NETFLIXID)},createData:function(a,b,d,e){c(e,
function(){return Ld(d)})},authenticate:function(b,c,d,e){if(!(d instanceof Qb))throw new B("Incorrect authentication data type "+d+".");b=d.secureNetflixId;if(!d.netflixId||!b)throw(new U(H.NETFLIXID_COOKIES_BLANK)).setUser(d);throw(new U(a.UNSUPPORTED_USERAUTH_DATA,this.scheme)).setUser(d);}});var Rb,Md,Qc,Nd,Od;(function(){var b=Qc={MICROSOFT_SAML:"MICROSOFT_SAML",SAMSUNG:"SAMSUNG",MICROSOFT_JWT:"MICROSOFT_JWT"},c=Nd=d.Class.create({init:function(a,b){Object.defineProperties(this,{email:{value:a,
writable:!1,enumerable:!0,configurable:!1},password:{value:b,writable:!1,enumerable:!0,configurable:!1}})}}),e=Od=d.Class.create({init:function(a,b){Object.defineProperties(this,{netflixId:{value:a,writable:!1,enumerable:!0,configurable:!1},secureNetflixId:{value:b,writable:!1,enumerable:!0,configurable:!1}})}});Rb=ib.extend({init:function n(a,b,d){n.base.call(this,Ra.SSO);var f=null,k=null,m=null,q=null;d instanceof c?(f=d.email,k=d.password):d instanceof e&&(m=d.netflixId,q=d.secureNetflixId);Object.defineProperties(this,
{mechanism:{value:a,writable:!1,configurable:!1},token:{value:b,writable:!1,configurable:!1},email:{value:f,writable:!1,configurable:!1},password:{value:k,writable:!1,configurable:!1},netflixId:{value:m,writable:!1,configurable:!1},secureNetflixId:{value:q,writable:!1,configurable:!1}})},getAuthData:function(){var a={};a.mechanism=this.mechanism;a.token=J(this.token);this.email&&this.password?(a.email=this.email,a.password=this.password):this.netflixId&&this.secureNetflixId&&(a.netflixid=this.netflixId,
a.securenetflixid=this.secureNetflixId);return a},equals:function z(a){return this===a?!0:a instanceof Rb?z.base.call(this,a)&&this.mechanism==a.mechanism&&ba(this.token,a.token)&&this.email==a.email&&this.password==a.password&&this.netflixId==a.netflixId&&this.secureNetflixId==a.secureNetflixId:!1}});Md=function(d){var f=d.mechanism,k=d.token;if(!f||!k||"string"!==typeof k)throw new A(a.JSON_PARSE_ERROR,"SSO authdata "+JSON.stringify(d));if(!b[f])throw new U(a.UNIDENTIFIED_USERAUTH_MECHANISM,"SSO authdata "+
JSON.stringify(d));var q=d.email,C=d.password,x=d.netflixid,s=d.securenetflixid;if(q&&!C||!q&&C||x&&!s||!x&&s||q&&x)throw new A(a.JSON_PARSE_ERROR,"SSO authdata "+JSON.stringify(d));var w;try{w=S(k)}catch(r){throw new U(H.SSOTOKEN_INVALID,"SSO authdata "+JSON.stringify(d),r);}var v;q&&C?v=new c(q,C):x&&s&&(v=new e(x,s));return new Rb(f,w,v)}})();Nb.extend({init:function l(){l.base.call(this,Ra.SSO)},createData:function(a,b,d,e){c(e,function(){return Md(d)})},authenticate:function(b,c,d,e){if(!(d instanceof
Rb))throw new B("Incorrect authentication data type "+d+".");b=d.token;c=d.email;e=d.password;var f=d.netflixId,k=d.secureNetflixId;if(!b||0==b.length)throw new U(H.SSOTOKEN_BLANK);if(!(null===c&&null===e||c&&e))throw new U(a.EMAILPASSWORD_BLANK);if(!(null===f&&null===k||f&&k))throw(new U(H.NETFLIXID_COOKIES_BLANK)).setUser(d);throw(new U(a.UNSUPPORTED_USERAUTH_DATA,this.scheme)).setUser(d);}});var hc,Pd;(function(){hc=ib.extend({init:function t(a,b){t.base.call(this,Ra.SWITCH_PROFILE);Object.defineProperties(this,
{userIdToken:{value:a,writable:!1,configurable:!1},profileGuid:{value:b,writable:!1,configurable:!1}})},getAuthData:function(){var a={};a.useridtoken=JSON.parse(JSON.stringify(this.userIdToken));a.profileguid=this.profileGuid;return a},equals:function F(a){return this==a?!0:a instanceof hc?F.base.call(this,a)&&this.userIdToken.equals(a.userIdToken)&&this.profileGuid==a.profileGuid:!1}});Pd=function(b,d,e,f){c(f,function(){if(!d)throw new U(a.USERAUTH_MASTERTOKEN_MISSING);var k=e.useridtoken,q=e.profileguid;
if("object"!==typeof k||"string"!==typeof q)throw new A(a.JSON_PARSE_ERROR,"switch profile authdata "+JSON.stringify(e));rb(b,k,d,{result:function(b){c(f,function(){if(!b.isDecrypted())throw new U(a.USERAUTH_USERIDTOKEN_NOT_DECRYPTED,"switch profile authdata "+JSON.stringify(e));return new hc(b,q)})},error:function(b){f.error(new U(a.USERAUTH_USERIDTOKEN_INVALID,"switch profile authdata "+JSON.stringify(e),b))}})})}})();Nb.extend({init:function t(){t.base.call(this,Ra.SWITCH_PROFILE)},createData:function(a,
b,c,d){Pd(a,b,c,d)},authenticate:function(b,c,d,e){if(!(d instanceof hc))throw new B("Incorrect authentication data type "+d+".");b=d.userIdToken;if(!d.profileGuid)throw(new U(H.PROFILEGUID_BLANK)).setUser(d);if(e&&!e.equals(b))throw(new U(a.USERAUTH_USERIDTOKEN_INVALID)).setUser(d);if(!b.user)throw(new U(a.USERAUTH_USERIDTOKEN_NOT_DECRYPTED)).setUser(d);throw(new U(a.UNSUPPORTED_USERAUTH_DATA,this.scheme)).setUser(d);}});fa.prototype=Error();fa.prototype.constructor=fa;var wb;(function(){function c(a,
b,d){for(var e=0,f=b?b.length:0;void 0!==a&&e<f;)a=a[b[e++]];return void 0===a?d:a}function d(a){return new aa(function(b,c){a.oncomplete=b;a.onerror=function(a){c(a.error)}})}function e(a){var b=this;this.promise=new aa(function(c,d){b.result=ia.isUndefined(a)?c:function(b){c([b,a])};b.error=d;b.timeout=function(){d(new fa)}})}function f(a){if(a instanceof fa)return 1;if(a instanceof oa)return 2;if(a instanceof k&&a.error)switch(a.error.responseCode){case b.TRANSIENT_FAILURE:return 2;case b.USERDATA_REAUTH:return a.error.internalCode==
H.NETFLIXID_COOKIES_EXPIRED.internalCode?12:8}return 1}function q(a){return a?""+a.sequenceNumber+":"+a.serialNumber+":"+a.expiration.toISOString()+":"+a.renewalWindow.toISOString():"null"}function C(a){return a?""+a.serialNumber+":"+a.mtSerialNumber+":"+a.expiration.toISOString()+":"+a.renewalWindow.toISOString():"null"}function s(x){function A(a,b,c,d,e){var f=[];c&&(f=c.slice(0));d&&(c=d.getMslStore(),d=c.getMasterToken())&&(f=f.concat(c.getServiceTokens(d,null)),e&&(e=e.getUserId())&&(e=c.getUserIdToken(e))&&
(f=f.concat(c.getServiceTokens(d,e))));0==f.length?u.trace("No "+a+" service tokens for request ("+b.n+")"):f.forEach(function(c,d){c?(u.trace(a+" service token "+d+" for request ("+b.n+") : "+c.name),u.dump(c.toJSON())):u.error("st is undefined, wtf.")})}var w=!1,r=!1,v=!1,B=1,y=nrdp.device.setRegistered||function(){},H=zd.extend({init:function jc(a){jc.base.call(this);this._deviceIdentity=a},_hasUserIdTokens:function(){return!!Object.keys(this.userIdTokens).length},setCryptoContext:function Ba(a,
b){function c(a){return a?a.sequenceNumber+":"+a.serialNumber+":"+a.expiration.getTime():"<null>"}var d=this.getMasterToken();Ba.base.call(this,a,b);this.markDirty("setCryptoContext ["+c(d)+" TO "+c(a)+"]")},removeCryptoContext:function Aa(a){Aa.base.call(this,a);this.markDirty("removeCryptoContext")},clearCryptoContexts:function Ca(){Ca.base.call(this);this.markDirty("clearCryptoContexts")},addUserIdToken:function Ha(a,b){Ha.base.call(this,a,b);this.markDirty("addUserIdToken")},removeUserIdToken:function Na(a){Na.base.call(this,
a);this.markDirty("removeUserIdToken")},clearUserIdTokens:function Oa(){Oa.base.call(this);this.markDirty("clearUserIdTokens")},addServiceTokens:function Wd(a){var b={"streaming.servicetokens.movie":!0,"streaming.servicetokens.license":!0};a=a.filter(function(a){return a&&!b[a.name]});0<a.length&&Wd.base.call(this,a)},removeServiceTokens:function Xd(a,b,c){Xd.base.call(this,a,b,c)},clearServiceTokens:function ab(){ab.base.call(this)},setNpTicket:function(a){if(a)this._npTicketWCKey=a;else{if(!this._npTicketWCKey)return;
delete this._npTicketWCKey}this.markDirty("setNpTicket")},getNpTicket:function(){return this._npTicketWCKey},markDirty:function(a){this._loading||(u.log("MslStore dirty ("+a+")"),this._dirty=!0)},load:function(a){var b=this,c,f;return aa.attempt(function(){c=nrdp.storage.getItem(nrdp.storage.NO_DEVICE_ACCOUNT,"mslstore");u.log("Attempting to load MslStore");if(c)if(f=JSON.parse(c),u.log("Loaded MslStore"),v&&u.dump(f),f.di!==b._deviceIdentity)u.warn("MslStore is for a different device: "+f.di),nrdp.storage.removeItem(nrdp.storage.NO_DEVICE_ACCOUNT,
"mslstore");else return aa.attempt(function(){var c=f.mt,d;b._loading=!0;if(!c)throw Error("No master token found");d=new e;pb(a,c,d);return d.promise}).then(function(c){switch(f.cc){case "symmetric":return aa.resolve([f.ek,f.hk].map(function(a){return d(N.getKeyInfo(a))})).all().then(function(a){return a.map(function(a){var b=new e;Ta(a.target.result,b);return b.promise})}).all().spread(function(d,e){var f=new ta(a,c,b._deviceIdentity,d,e);b.setCryptoContext(c,f)}).thenResolve(c);default:throw Error("Unable to load crypto context");
}}).then(function(c){var d=f.uit;if(d)return u.log("Parsing user id tokens"),aa.attempt(function(){return d.map(function(b){var d=new e(b.id);rb(a,b.t,c,d);return d.promise})}).all().then(function(a){a.forEach(function(a){b.addUserIdToken(a[1],a[0])})})}).then(function(){var a=f.npk;if(a)return u.log("Loading NP Ticket..."),d(N.getKeyInfo(a)).then(function(a){(a=a.target.result)&&b.setNpTicket(a)})}).then(function(){u.log("Finished loading MslStore");b._lastSaved||(b._lastSaved=c)}).fin(function(){delete b._dirty;
delete b._loading});else u.warn("No MslStore to load")}).fail(function(a){u.warn("Failed to load MslStore : "+a);nrdp.storage.removeItem(nrdp.storage.NO_DEVICE_ACCOUNT,"mslstore")}).thenResolve()},save:function(a){var b=this,c=b.getMasterToken(),d,e=[],f,k=b._lastSaved;if(this._dirty){delete this._dirty;u.log("Saving MslStore..."+(a?"("+a+")":""));if(c){f={};f.di=b._deviceIdentity;f.mt=c.toJSON();d=[];Object.keys(b.userIdTokens).forEach(function(a){var e=b.getUserIdToken(a);e.isBoundTo(c)&&d.push({id:a,
t:e.toJSON()})});f.uit=d;if(a=b.getCryptoContext(c))a instanceof Jb?([a.encryptionKey,a.hmacKey].forEach(function(a){a&&e.push(a)}),f.cc="symmetric",f.ek=a.encryptionKey.handle,f.hk=a.hmacKey.handle):u.error("NrdpMslStore does not know how to persist this kind of CryptoContext");this._npTicketWCKey&&(e.push(this._npTicketWCKey),f.npk=this._npTicketWCKey.handle)}if(f){a=JSON.stringify(f);if(k&&k===a){u.log("Already saved this, skipping it");return}v&&(u.trace("This is what I will save:"),u.dump(f));
nrdp.storage.setItem(nrdp.storage.NO_DEVICE_ACCOUNT,"mslstore",a);b._lastSaved=a;u.log("Finished saving MslStore")}else nrdp.storage.removeItem(nrdp.storage.NO_DEVICE_ACCOUNT,"mslstore"),delete b._lastSaved;nrdp.webcrypto.persistKeys(e,function(a){a.success?u.log("Finished persisting MslStore keys"):u.warn("Failed to persist MslStore keys")});y(b._hasUserIdTokens())}}}),K=fe.extend({init:function(a){this._client=a;this._entityAuthFactories={};this._keyRequestData=[];this._keyExchangeFactories=[];
this._mslCryptoContext=new Yd;x.msl.unauth&&ia.isString(x.msl.unauth)?this._deviceIdentity=x.msl.unauth:this._deviceIdentity=nrdp.device.ESN;u.warn("ESN: "+this._deviceIdentity);this._store=new H(this._deviceIdentity);this._random=new Vb},_generateNPTicket:function(){var a=this,b={name:"RSASSA-PKCS1-v1_5",params:{npticket:!0}};return aa.attempt(function(){if(a._generatingNPTicket)throw Error("Already waiting for NP ticket generation, cannot make a new one now");u.log("Creating NP-Ticket");a._generatingNPTicket=
!0;return d(N.generateKey(b,!0)).fin(function(){delete a._generatingNPTicket}).then(function(b){var c=b.target.result.privateKey;u.log("Created NP-Ticket: "+JSON.stringify(b));if(c.algorithm.npTicketFake&&(b=a.getMslStore().getNpTicket())&&!b.algorithm.npTicketFake){var d=1E3*b.algorithm.npTicketExpiration,e=nrdp.now();if(d>e){u.log("Tried to get a new NP-Ticket, but got a fake one, and the old one was real and isn't expired yet, so I'm keeping it");a._entityAuthData||(a._entityAuthData=new Db(a._deviceIdentity,
b));return}}a.getMslStore().setNpTicket(c);a._entityAuthData=new Db(a._deviceIdentity,c)})})},_generateADHExchangeRequestData:function(a,b){var c=new Uint8Array([150,148,233,216,217,58,90,199,76,80,155,75,188,232,94,146,19,44,209,156,206,71,125,26,126,71,213,39,217,236,41,21,21,240,184,179,225,234,237,80,6,225,177,185,30,162,91,145,160,27,16,226,232,52,184,214,96,178,227,33,173,100,76,225,168,59,50,141,144,20,238,126,22,241,228,79,254,137,87,154,195,238,71,214,104,182,183,102,135,194,254,144,163,
91,94,96,40,253,4,239,234,136,35,115,236,246,11,162,246,55,228,205,170,27,96,137,214,192,181,97,168,229,32,231,150,222,39,223]),e=new Uint8Array([5]);u.log("Generating DH key");return d(N.generateKey({name:"NFLX-DH",params:{prime:c,generator:e}},!1,["derive"])).then(function(b){var c=b.target.result.publicKey,e=b.target.result.privateKey;u.log("Exporting DH public key");return d(N.exportKey("raw",c)).then(function(b){return new Kc(a,"1",b.target.result,e,null)})})},_makeADHExchange:function(a){var b=
Fd.extend({getDerivationKey:function(b){if(!b)return a}});return new Dd(new b)},prepare:function(){var a=this;u.info("Preparing MslContext...");return aa.resolve(a._store.load(a)).then(function(){var b,c;u.info("Server entity auth keys...");if(x.msl.verifyServer){try{b=nrdp.storage.transientData.appboot.msltruststore.keys,c=Object.getOwnPropertyNames(b).map(function(a){return{identity:a,type:"downloaded",op:N.importKey("spki",b[a],M,!1,["verify"])}})}catch(d){c=nrdp.js.options.appboot_key?[{identity:"APPBOOT",
type:"overridden",op:N.importKey("spki",nrdp.js.options.appboot_key,M,!1,["verify"])}]:[{identity:"APPBOOT",type:"baked in",op:N.getKeyByName("ABKP")}]}return aa.all(c.map(function(a){return new aa(function(b,c){var d=a.op;u.info("Importing "+a.type+" key for "+a.identity);d.onerror=function(a){c(a.error)};d.oncomplete=function(c){b({identity:a.identity,key:c.target.result})}})})).then(function(a){return aa.all(a.map(function(a){var b=new e,c;u.info("Creating MSL PublicKey for "+a.identity);c=b.result;
b.result=function(b){c({identity:a.identity,key:b})};jb(a.key,b);return b.promise}))}).then(function(b){var c=new Zd;b.forEach(function(a){u.info("Adding key to RSA store "+a.identity);c.addPublicKey(a.identity,a.key)});a._entityAuthFactories[$.RSA]=new Xc(c)}).fail(function(a){u.error("Failed to set-up server entity auth keys : "+a.toString())})}c=Xc.extend({getCryptoContext:function(a,b){this._cryptoContext||(this._cryptoContext=new zb);return this._cryptoContext}});u.warn("Added NULL RSA auth factory because we are not verifying the server");
a._entityAuthFactories[$.RSA]=new c}).then(function(){switch(x.msl.unauth?"UNKNOWN":nrdp.webcrypto.authenticationType){case "PSK":return u.info("Device authentication using PSK"),aa.attempt(function(){return["DKE","DKH","DKW"].map(function(a){return d(N.getKeyByName(a))})}).all().then(function(a){return a.map(function(a){var b;a=a.target.result;if(ia.isNull(a))throw Error("Failed to get device key by name");b=new e;Ta(a,b);return b.promise})}).spread(function(b,c,d){var e=Wc.extend({init:function Dc(a,
b,c,d){Dc.base.call(this,a);Object.defineProperties(this,{_kpe:{value:b,writable:!1,enumerable:!1,configurable:!1},_kph:{value:c,writable:!1,enumerable:!1,configurable:!1},_kpw:{value:d,writable:!1,enumerable:!1,configurable:!1}})},getCryptoContext:function Ec(a,b){return b instanceof Ua&&this.localIdentity==b.identity?new Jb(a,this.localIdentity,this._kpe,this._kph,this._kpw):Ec.base.call(this,a,b)}});u.info("Created PSK auth factory");a._entityAuthFactories[$.PSK]=new e(a._deviceIdentity,b,c,d);
a._entityAuthData=new Ua(a._deviceIdentity);if(nrdp.js.options.swex)u.info("Using symmetric wrapped exchange"),a._keyRequestData.push(new ec($.PSK)),a._keyExchangeFactories.push(new Nc);else{if(nrdp.webcrypto.nflxDhDerive)return u.info("Using ADH exchange"),a._generateADHExchangeRequestData(Jc.PSK,d.rawKey).then(function(b){a._keyRequestData.push(b);a._keyExchangeFactories.push(a._makeADHExchange(d))});u.info("Using JWE ladder exchange");b=Mc.extend({init:function Fc(){Fc.base.call(this);Object.defineProperties(this,
{_contextMap:{value:{},writable:!1,enumerable:!1,configurable:!1}})},addCryptoContext:function(a,b){b&&a&&a.length&&(this._contextMap[J(a)]=b)},getCryptoContext:function(a){return a&&a.length?this._contextMap[J(a)]||null:null},removeCryptoContext:function(a){a&&a.length&&delete this._contextMap[J(a)]}});a._keyExchangeFactories.push(new Lc(new b));a._keyRequestData.push(new dc($.PSK))}});case "MGK":return u.info("Device authentication using MGK"),aa.attempt(function(){return["DKE","DKH","DKW"].map(function(a){return d(N.getKeyByName(a))})}).all().then(function(a){return a.map(function(a){var b;
a=a.target.result;if(ia.isNull(a))throw Error("Failed to get device key by name");b=new e;Ta(a,b);return b.promise})}).spread(function(b,c,d){var e=he.extend({init:function Dc(a,b,c,d){Dc.base.call(this,a);Object.defineProperties(this,{_kde:{value:b,writable:!1,enumerable:!1,configurable:!1},_kdh:{value:c,writable:!1,enumerable:!1,configurable:!1},_kdw:{value:d,writable:!1,enumerable:!1,configurable:!1}})},getCryptoContext:function Ec(a,b){return b instanceof Va&&this.localIdentity==b.identity?new Jb(a,
this.localIdentity,this._kde,this._kdh,this._kdw):Ec.base.call(this,a,b)}});u.info("Created MGK auth factory");a._entityAuthFactories[$.MGK]=new e(a._deviceIdentity,b,c,d);a._entityAuthData=new Va(a._deviceIdentity);if(nrdp.js.options.swex)u.info("Using symmetric wrapped exchange"),a._keyRequestData.push(new ec($.MGK)),a._keyExchangeFactories.push(new Nc);else{if(nrdp.webcrypto.nflxDhDerive)return u.info("Using ADH exchange"),a._generateADHExchangeRequestData(Jc.MGK,d.rawKey).then(function(b){a._keyRequestData.push(b);
a._keyExchangeFactories.push(a._makeADHExchange(d))});u.info("Using JWE ladder exchange");b=Mc.extend({init:function Fc(){Fc.base.call(this);Object.defineProperties(this,{_contextMap:{value:{},writable:!1,enumerable:!1,configurable:!1}})},addCryptoContext:function(a,b){b&&a&&a.length&&(this._contextMap[J(a)]=b)},getCryptoContext:function(a){return a&&a.length?this._contextMap[J(a)]||null:null},removeCryptoContext:function(a){a&&a.length&&delete this._contextMap[J(a)]}});a._keyExchangeFactories.push(new Lc(new b));
a._keyRequestData.push(new dc($.MGK))}});case "npticket":return u.info("Device authentication using NP-Ticket"),aa.attempt(function(){var b=a.getMslStore().getNpTicket(),c,d,e;if(b)if(u.info("Checking saved NP-Ticket"),e=nrdp.now(),c=1E3*b.algorithm.npTicketIssue,d=1E3*b.algorithm.npTicketExpiration,c+nrdp.js.options.npticket_interval<e)u.warn("NP-Ticket was issued more than 4 hours ago : issued="+c+"ms, now="+e+"ms, expiration="+d+"ms");else if(d<=e)u.warn("NP-Ticket is expired : issued="+c+"ms, now="+
e+"ms, expiration="+d+"ms");else{u.info("Saved NP-Ticket seems good");a._entityAuthData=new Db(a._deviceIdentity,b);return}else u.info("No saved NP-Ticket, making a new one");return a._generateNPTicket()}).then(function(){a._entityAuthFactories[$.NPTICKET]=new ie;a._keyExchangeFactories.push(new wc);u.info("Generating AsymmetricWrappedExchange keys for key request data");var b={name:"RSA-OAEP",params:{modulusLength:1024,publicExponent:new Uint8Array([1,0,1])}};return d(N.generateKey(b,!0))}).then(function(a){var b=
new e,c=new e;lb(a.target.result.privateKey,b);jb(a.target.result.publicKey,c);return[b.promise,c.promise]}).spread(function(b,c){a._keyRequestData.push(new $b("rsaKeypairId",xc.JWE_RSA,c,b))});case "UNKNOWN":var b={name:"RSA-OAEP",params:{modulusLength:1024,publicExponent:new Uint8Array([1,0,1])}};u.warn("Using unauthenticated auth factory - NOT using device keys");a._entityAuthFactories[$.NONE]=new $d;a._entityAuthData=new Kb(a._deviceIdentity);a._keyExchangeFactories.push(new wc);u.info("Generating AsymmetricWrappedExchange keys for key request data");
return d(N.generateKey(b,!0)).then(function(a){var b=new e,c=new e;lb(a.target.result.privateKey,b);jb(a.target.result.publicKey,c);return[b.promise,c.promise]}).spread(function(b,c){a._keyRequestData.push(new $b("rsaKeypairId",xc.JWE_RSA,c,b))});default:throw Error('Unrecognized authentication type "'+nrdp.webcrypto.authenticationType+'" from nrdp.webcrypto.authenticationType');}})},getTime:function(){return clock$getTime()},getRandom:function(){return this._random},isPeerToPeer:function(){return!1},
getMessageCapabilities:function(){var a=[],b=[];nrdp.registration&&(b=nrdp.registration.UILanguages);b=b.concat(nrdp.device.language);x.msl.useLzw&&a.push(La.LZW);x.msl.useGzip&&a.push(La.GZIP);return new Mb(a,b)},getEntityAuthenticationData:function(a,b){var c=this;aa.attempt(function(){if(a&&(u.log("Entity re-auth"),"npticket"==nrdp.webcrypto.authenticationType))return c._generateNPTicket()}).then(function(){b.result(c._entityAuthData)},function(a){b.error(a)}).done()},getMslCryptoContext:function(){return this._mslCryptoContext},
getEntityAuthenticationFactory:function(a){return this._entityAuthFactories[a]},getUserAuthenticationFactory:function(a){return null},getTokenFactory:function(){return null},getKeyExchangeFactory:function(a){return this.getKeyExchangeFactories().filter(function(b){return b.scheme==a})[0]},getKeyExchangeFactories:function(){return this._keyExchangeFactories},getMslStore:function(){return this._store},getKeyRequestData:function(){return this._keyRequestData}}),E=ee.extend({init:function(a){this._requestInfo=
a},sentHeader:function(a){try{var b=a.masterToken,c=a.userIdToken,d,e,f,k="-> ["+this._requestInfo.n+"."+ ++this._requestInfo.r+"] "+this._requestInfo.url,k=k+(" mid="+a.messageId+" mt="+q(b)),k=k+(" nrp="+!!a.nonReplayable+" ren="+!!a.renewable),k=k+(" uit="+C(c));if(d=a.userAuthenticationData)k+=" uad="+d.scheme;(e=a.serviceTokens)&&e.length&&(k+=" st=[",e.forEach(function(a,b){b&&(k+=",");k+=a.uniqueKey()}),k+="]");(f=a.keyRequestData)&&f.length&&(k+=" krd=[",f.forEach(function(a,b){b&&(k+=",");
k+=JSON.stringify(a.toJSON())}),k+="]");u.log(k)}catch(n){}},receivedHeader:function(a){try{var b,c,d,e,f="<- ["+this._requestInfo.n+"."+this._requestInfo.r+"] "+this._requestInfo.url;a instanceof qb?f+=" mid="+a.messageId+" error="+a.internalCode+" ["+a.errorCode+"] "+a.errorMessage:a instanceof Ab&&(b=a.masterToken,c=a.userIdToken,f+=" mid="+a.messageId+" mt="+q(b),f+=" nrp="+!!a.nonReplayable+" ren="+!!a.renewable,f+=" uit="+C(c),(d=a.serviceTokens)&&d.length&&(f+=" st=[",d.forEach(function(a,
b){b&&(f+=",");f+=a.uniqueKey()}),f+="]"),e=a.keyResponseData)&&(b=e.masterToken,f+=" krd-mt="+q(b));u.log(f)}catch(k){}}}),P=wd.extend({init:function(a,b,c,d,e,f,k,n,q){var r=null,t,C=nrdp.registration;e=ia.isUndefined(e)||ia.isNull(e)?!0:!!e;f=ia.isUndefined(f)||ia.isNull(f)?!0:!!f;k=!!k;if(C)if(ia.isUndefined(c)){if(t=C.activationTokens,C.registered||t&&(t.NetflixId&&t.SecureNetflixId||t.email&&t.password||t.ssoService&&t.ssoToken))r={id:C.currentDeviceAccount,tokens:t}}else ia.isNull(c)||(t=C.deviceAccounts.filter(function(a){return a.accountKey==
c}).reduce(function(a,b){return b.tokens},void 0),r={id:c,tokens:t});else ia.isNull(c)||(r={id:c});Object.defineProperties(this,{_client:{value:a,writable:!1},_account:{value:r,writable:!1},_payload:{value:d,writable:!1},_encrypted:{value:e,writable:!1},_replayable:{value:f,writable:!1},_requestingTokens:{value:k,writable:!1},_serviceTokens:{value:n,writable:!1},_requestInfo:{value:b,writable:!1},_forceUserAuthData:{value:!!q,writable:!1}})},getCryptoContexts:function(){this._cryptoContexts||(this._cryptoContexts=
{});return this._cryptoContexts},getRecipient:function(){},isEncrypted:function(){return this._encrypted},isIntegrityProtected:function(){return!0},isNonReplayable:function(){return!this._replayable},isRequestingTokens:function(){return this._requestingTokens},getUserId:function(){if(this._account)return this._account.id;u.log("No account associated with this request");return null},getUserAuthData:function(a,b,c,d){b=null;var e=this._account,f,k;e?a?u.error("Asked to reauth user auth data, need to log in again"):
this._forceUserAuthData||c||!this._client.getUserIdToken(e.id,!0)?(this._forceUserAuthData&&u.log("User auth data is being forced for this message"),c&&u.log("User auth data is required for this message"),a=e.tokens,a)?a.ssoService&&a.ssoToken?("xboxsaml"==a.ssoService.toLowerCase()?(k=Qc.MICROSOFT_SAML,u.log("Will use XBox SAML SSO user auth data")):"xboxjwt"==a.ssoService.toLowerCase()&&(k=Qc.MICROSOFT_JWT,u.log("Will use XBox JWT SSO user auth data")),k&&(a.email&&a.password?(u.log("Including SSO email/password user auth data for "+
e.id),f=new Nd(a.email,a.password)):a.NetflixId&&a.SecureNetflixId&&(u.log("Including SSO netflix id user auth data for "+e.id),f=new Od(a.NetflixId,a.SecureNetflixId)),b=new Rb(k,a.ssoToken,f))):a.email&&a.password?(u.log("Including email/password user auth data for "+e.id),b=new Ob(a.email,a.password)):a.NetflixId&&a.SecureNetflixId&&(u.log("Including netflix id user auth data for "+e.id),b=new Qb(a.NetflixId,a.SecureNetflixId)):u.log("User id "+e.id+" does not have email/password or netflix"):
u.log("Already have a user id token for "+e.id+" and this is not a reauth - will not send auth data"):u.log("No account associated with this request");d.result(b)},getUser:function(){return null},getKeyRequestData:function(a){a.result(this._client.getKeyRequestData())},updateServiceTokens:function(a,b,c){var d=!0;b||this._serviceTokens&&this._serviceTokens.forEach(function(b){b?(u.log("Adding service token to outbound message : "+b.name),d=d&&a.addPrimaryServiceToken(b)):u.error(">>> MSL message has NULL service token <<<")});
d?c.result(!0):c.error(Error("Failed to update all service tokens"))},write:function(a,b,c){var d=this._payload;aa.attempt(function(){var c;if(!x.msl.useLzw&&!x.msl.useGzip)return c=new e,u.trace("Configuring output stream without compression"),a.setCompressionAlgorithm(null,b,c),c.promise}).then(function(){var c,f=new e;ia.isObject(d)&&d.constructor==Uint8Array||(d=Xa(d));c=d.length;a.write(d,0,c,b,f);return f.promise.then(function(d){var f=new e;if(d!==c)throw new oa("Message context did not write all bytes");
a.close(b,f);return f.promise})}).then(function(){c.result(!0)}).fail(function(a){u.error("Exception writing : "+a);a instanceof fa?c.timeout():c.error(a)}).done()},getDebugContext:function(){return DEBUG?new E(this._requestInfo):null}}),V=oa.extend({init:function Hb(a,b){this.mesg=a;this.url=b.url;this.errorCode=b.errorcode;this.errorGroup=b.errorgroup;this.nativeerrorCode=b.nativeerrorCode;this.finalUrl=b.finalURL;this.serverIp=b.serverIp;this.httpCode=b.statusCode;Hb.base.call(this,a)}}),S=ce.extend({init:function(a,
b){this._url=a;this._info=b},getResponse:function(a,b,c){var d=this,e=nrdp.gibbon,f=this._url,k=""+Math.floor(nrdp.now()/1E3)+Math.floor(1E8*Math.random());b={url:f,headers:{"X-Gibbon-Cache-Control":"no-cache","X-AllowCompression":"true","X-Client-Request-Id":k},body:a.body,async:!0,secure:!0,timeout:b||void 0,connectTimeout:b/2||void 0,stallTimeout:b||void 0,format:"jsonstream"};var n,q=nrdp.mono(),r=a.body.length;nrdp.device.deviceModel&&(b.headers["X-DeviceModel"]=nrdp.device.deviceModel);d._info.clientRequestId=
k;u.log("  Making HTTP request ("+d._info.n+") ["+k+"] request body is "+a.body.length+" bytes "+f);w&&u.dump(b);nrdp.instrumentation.endInterval(nrdp.instrumentation.SWITCHED,"nrdjs.prepare-msl-request/"+d._info.n);n=e.load(b,function(a){var b={dt:a.dnsTime||0,ct:a.connectTime||0,tt:a.transactionTime||0,du:a.duration||0,serverIp:a.serverIp};nrdp.instrumentation.startInterval(nrdp.instrumentation.SWITCHED,"nrdjs.handle-msl-response/"+d._info.n);d._info.networkTime=nrdp.mono()-q;d._info.netStats=b;
w&&u.dump(a);u.log("  HTTP took "+d._info.networkTime+" ms ("+r+","+a.size+" bytes) ["+b.dt+","+b.ct+","+b.tt+"="+b.du+" ("+(d._info.networkTime-b.du)+")] for request ("+d._info.n+") "+f);try{switch(a.reason){case e.SUCCESS:b={};if(200===a.statusCode){b.json=a.json||null;c.result(b);break}throw new V("HTTP status code "+a.statusCode,a);case e.TIMEOUTERROR:throw new V("TIMED_OUT_ERROR",a);case e.NOTSECUREERROR:throw new V("NOT_SECURE_ERROR",a);case e.FILEACCESSERROR:throw new V("FILE_ACCESS_ERROR",
a);case e.DATAURIERROR:throw new V("DATA_URI_ERROR",a);case e.DNS_ERROR:throw new V("DNS_ERROR",a);case e.CONNECT_ERROR:throw new V("CONNECT_ERROR",a);case e.SSLHANDSHAKEERROR:throw new V("SSL_HANDSHAKE_ERROR",a);case e.SSLCACERTERROR:throw new V("SSL_CA_CERT_ERROR",a);case e.SSLCACERTFILEERROR:throw new V("SSL_CA_CERT_FILE_ERROR",a);case e.CERTSTATUSSSLERROR:throw new V("CERT_STATUS_ERROR",a);case e.CERTSTATUSREVOKED:throw new V("CERT_REVOKED_ERROR",a);case e.CERTSTATUSPEWREVOKED:throw new V("CERT_PEW_REVOKED_ERROR",
a);case e.SENDERROR:throw new V("SEND_ERROR",a);case e.RECVERROR:throw new V("RECV_ERROR",a);case e.COMPRESSIONERROR:throw new V("COMPRESSION_ERROR",a);case e.SECURITYERROR:throw new V("SECURITY_ERROR",a);case e.NETWORKERROR:throw new V("NETWORK_ERROR",a);default:throw new V(200<a.statusCode?"HTTP_ERROR":"UNKNOWN ["+a.reason+"]",a);}}catch(k){u.warn("Request ("+d._info.n+") to "+f+" failed : "+k.mesg),nrdp.pbr&&nrdp.pbr.reportMslFailure(k),a.reason==e.TIMEOUTERROR?(u.fatal("This is a REAL timeout"),
c.timeout()):c.error(k)}});return{abort:function(){u.warn("Aborting request ("+d._info.n+") : ID "+n);e.stopLoad(n)}}}});this._prepare=function(){w=!!nrdp.js.options.trace_msl_requests;r=!!nrdp.js.options.trace_msl_service_tokens;v=!!nrdp.js.options.trace_msl_store;u.info("Creating MslControl...");this._mslControl=new xd;u.info("Creating MslContext...");this._mslContext=new K;return this._mslContext.prepare().thenResolve(this)};this.request=function(b,c,d,f,q,t,C,v,s,x,w){var y=this,D=nrdp.mono(),
z={url:b,n:B++,r:0};nrdp.instrumentation.startInterval(nrdp.instrumentation.SWITCHED,"nrdjs.prepare-msl-request/"+z.n,{url:b,n:z.n});u.log("Making MSL request ("+z.n+") payload is "+(d.byteLength||d.length)+" bytes "+b);return aa.attempt(function(){var a=new P(y,z,c,d,q,t,C,v,s),k=new e,B=new $c(new S(b,z));x&&(u.info("Getting new message context from message context factory"),a=x(y._mslContext,a)||a,nrdp.assert(ia.isObject(a)));r&&A("outbound",z,v,y._mslContext,a);w&&(u.info("Getting URL from URL factory"),
B=w(y._mslContext,a,b,z,B)||B,nrdp.assert(ia.isObject(B)));y._mslControl.request(y._mslContext,a,B,f||-1,k);return k.promise}).fail(function(a){u.log("<- ["+z.n+"."+z.r+"] "+z.url+" e="+a.toString());throw a;}).then(function(b){b=b.input;var c=b.getErrorHeader(),d=b.getMessageHeader();if(c)throw u.error("MSL response has error header : "+c.internalCode+" ["+c.errorCode+"] "+c.errorMessage),new k(new a(c.internalCode,c.errorCode,c.errorMessage));c=d.serviceTokens;r&&A("inbound",z,c);d=new e;b.read(-1,
f,d);return[d.promise,aa.resolve(c)]}).spread(function(a,b){return{body:a||new Uint8Array,serviceTokens:b,requestInfo:z}}).fin(function(){y._mslContext.getMslStore().save("After a request");u.log("  MSL took "+(nrdp.mono()-D-(z.networkTime||0))+" ms for request ("+z.n+") "+b);nrdp.instrumentation.endInterval(nrdp.instrumentation.SWITCHED,"nrdjs.handle-msl-response/"+z.n,{url:b,n:z.n})})};this.send=function(a,c){var d=this;aa.attempt(function(){return d.request(a.url,a.userId,a.body,a.timeout,a.encrypted,
a.replayable,a.requestingTokens,a.serviceTokens,a.forceUserAuthData)}).then(function(a){try{u.trace("MSL networkstats:"+JSON.stringify(a.requestInfo.netStats)),c({success:!0,body:Wa(a.body),serviceTokens:a.serviceTokens,requestInfo:a.requestInfo})}catch(b){u.error("Exception in MSL callback : "+b.toString()+"\n"+b.stack)}}).fail(function(e){var n=nrdp.registration,q=a.userId,r,t,C={mslError:e,errorActionId:f(e),errorIsTimeout:e instanceof fa,errorSubCode:1300};u.error("MSL request failed : "+e.toString()+
(e.cause&&e.cause.toString?" (caused by "+e.cause.toString()+")":"")+" : ACTION ID "+C.errorActionId);try{r="undefined"!==typeof n?n.currentDeviceAccount:null,t="undefined"!==typeof q&&null!==q?q:r,e instanceof k&&e.error&&e.error.responseCode===b.USERDATA_REAUTH&&null!==r&&(n.deviceAccounts.filter(function(a){return t===a.accountKey}).forEach(function(a){u.log("Clearing device account tokens for user "+t);a.tokens={}}),u.log("Dropping user id token for user "+t),d.removeUserIdToken(t)),c(C)}catch(v){u.error("Exception in MSL error callback : "+
v.toString()+"\n"+v.stack)}}).done()};this.getRandom=function(){return this._mslContext.getRandom()};this.getKeyRequestData=function(){return this._mslContext.getKeyRequestData()};this.getMslStore=function(){return this._mslContext.getMslStore()};this.getUserIdToken=function(a,b){var c=this.getMslStore(),d=c.getUserIdToken(a);d&&b&&((c=c.getMasterToken())&&d.isBoundTo(c)||(d=null));return d};this.removeUserIdToken=function(a){var b=this.getMslStore();if(a=b.getUserIdToken(a))b.removeUserIdToken(a),
b.save()};this.clearUserIdTokens=function(){var a=this.getMslStore();a.clearUserIdTokens();a.save()};this.parseServiceToken=function(a,b,c){var d=this;aa.attempt(function(){var c=d.getMslStore(),f=c.getMasterToken(),c=c.getUserIdToken(a),k;if(b&&f&&c)return k=new e,Cc(this._mslContext,b,f,c,null,k),k.promise}).fail(function(a){u.warn("Failed to parse service token",a)}).then(function(b){b?u.trace("Parsed service token "+b.name+" for account "+a):u.trace("Did not parse the service token for account "+
a);c(b)}).done()};this.getNpTicketCookie=function(){var a=this.getMslStore().getNpTicket();return c(a,["algorithm","npTicket"])};this.isNpTicketFake=function(){var a=this.getMslStore().getNpTicket();return c(a,["algorithm","npTicketFake"])};this.generateNpTicket=function(a,b){var c=this;aa.attempt(function(){if("npticket"!=nrdp.webcrypto.authenticationType)throw Error("Not npticket authentication type");a&&(u.warn("Dropping existing NP-Ticket"),c.getMslStore().setNpTicket(null));return c._mslContext._generateNPTicket()}).then(function(){return c.getNpTicketCookie()},
function(a){u.error("Failed to make new NP-Ticket : "+a.toString())}).then(function(a){b&&b(a)}).done()}}var u=new Ub("MSL");wb=function(a){return aa.attempt(function(){DEBUG=nrdp.debug;return(new s(a))._prepare()})}})();Ia=lc.LEGACY;wb.TimeoutError=fa;wb.MslException=k;wb.MslEncodingException=A;wb.MslIoException=oa;wb.MslConstants$ResponseCode=b;ga.exports=wb},{nf_console:4,nf_promise:5,nf_underscore:6}],4:[function(R,ga,xa){var K=R("nf_underscore");ga.exports=function(w,s,P){function R(e){return function(){(!nrdp||
!nrdp.isReady||nrdp.debug||nrdp.log.haveTracing||nrdjs.debug)&&e.apply(this,arguments)}}var e=P.utf8toa;P=function(e,K){this._traceArea=e||s||"CONSOLE";"function"===typeof w.createArea&&w.createArea(e,K?K+"|nrdjs":"nrdjs")};P.prototype={info:function(){w.info(this.stringify(arguments),this._traceArea)},error:function(){w.error(this.stringify(arguments),this._traceArea)},warn:function(){w.warn(this.stringify(arguments),this._traceArea)},trace:R(function(){w.trace(this.stringify(arguments),this._traceArea)}),
log:w.debug?R(function(){w.debug(this.stringify(arguments),this._traceArea)}):w.info,debug:w.debug?R(function(){w.debug(this.stringify(arguments),this._traceArea)}):w.info,fatal:w.fatal?function(){w.fatal(this.stringify(arguments),this._traceArea)}:w.error};P.prototype.stringify=function(e){return Array.prototype.slice.call(e).reduce(function(e,s){var w=e;0<w.length&&(w+="\n");return w=K.isObject(s)?null!==s&&/^\w*Error$/.test(s.name)?w+(s.toString()+"\n"+s.stack):w+("("+JSON.stringify(s)+")"):w+
s},"")};P.prototype.dump=function(s){function w(e){return K.isString(e)&&2<=e.length&&"{"==e[0]&&"}"==e[e.length-1]}function P(e){var s=e.split("}{");1<s.length&&(e="["+s.join("},{")+"]");return JSON.parse(e,R)}function y(e){var s;if(K.isString(e))try{s=atob(e);if(w(s))return P(s);if(K.isString(s)&&2<=s.length&&"<"==s[0]&&">"==s[s.length-1])return s}catch(y){}}function R(e,s){var w=y(s);return w?w:s}this.trace("\n"+JSON.stringify(s,function(s,M){var R;K.isObject(M)&&M.constructor==Uint8Array&&(M=
e(M));return w(M)?P(M):(R=y(M))?R:M},"  "))};return P}},{nf_underscore:6}],5:[function(R,ga,xa){ga.exports=function(){var K=R("q"),w=function(s){var w=K.defer(),R=w.resolve.bind(w),e=w.reject.bind(w);try{s(R,e)}catch(M){e(M)}return w.promise};w.attempt=function(s){return K.fcall(s)};w.resolve=function(s){return K(s)};w.all=function(s){return K.all(s)};return w}()},{q:7}],6:[function(R,ga,xa){var K=Object.prototype.hasOwnProperty,w={isNumber:function(s){return"number"===typeof s},isObject:function(s){return"object"===
typeof s},isString:function(s){return"string"===typeof s},isUndefined:function(s){return"undefined"===typeof s},isBoolean:function(s){return"boolean"===typeof s},isFunction:function(s){return"function"===typeof s},isNull:function(s){return null===s},isArray:function(s){return"[object Array]"===Object.prototype.toString.call(s)},isFinite:function(s){return isFinite(s)&&!isNaN(parseFloat(s))},has:function(s,w){return null!=s&&K.call(s,w)},pairs:function(s){var K,R=[];if(!w.isObject(s))throw new TypeError("Object.pairs called on non-object");
for(K in s)s.hasOwnProperty(K)&&R.push([K,s[K]]);return R}};w.each=w.forEach=function(s,K,R){if(null==s)return s;if(s.length===+s.length)for(var e=0,M=s.length;e<M;e++)K.call(R,s[e],e,s);else for(e in s)w.has(s,e)&&K.call(R,s[e],e,s);return s};ga.exports=w},{}],7:[function(R,ga,xa){var K=R("__browserify_process");(function(w){"function"===typeof bootstrap?bootstrap("promise",w):"object"===typeof xa?ga.exports=w():"function"===typeof define&&define.amd?define(w):"undefined"!==typeof ses?ses.ok()&&
(ses.makeQ=w):Q=w()})(function(){function w(a){return function(){return Ub.apply(a,arguments)}}function s(a,c){if(ea&&c.stack&&"object"===typeof a&&null!==a&&a.stack&&-1===a.stack.indexOf(Fb)){for(var e=[],f=c;f;f=f.source)f.stack&&e.unshift(f.stack);e.unshift(a.stack);for(var e=e.join("\n"+Fb+"\n").split("\n"),f=[],s=0;s<e.length;++s){var k=e[s],q;if(q=P(k)){var w=q[1];q=q[0]===Xa&&w>=Wa&&w<=Ib}else q=!1;q||-1!==k.indexOf("(module.js:")||-1!==k.indexOf("(node.js:")||!k||f.push(k)}e=f.join("\n");
a.stack=e}}function P(a){var c=/at .+ \((.+):(\d+):(?:\d+)\)$/.exec(a);if(c||(c=/at ([^ ]+):(\d+):(?:\d+)$/.exec(a)))return[c[1],Number(c[2])];if(a=/.*@(.+):(\d+)$/.exec(a))return[a[1],Number(a[2])]}function R(){if(ea)try{throw Error();}catch(a){var c=a.stack.split("\n"),c=0<c[0].indexOf("@")?c[1]:c[2];if(c=P(c))return Xa=c[0],c[1]}}function e(a){return V(a)?a:Eb(a)?f(a):c(a)}function M(){function a(b){s=b;k.source=b;J(d,function(a,c){ia(function(){b.promiseDispatch.apply(b,c)})},void 0);f=d=void 0}
var d=[],f=[],s,w=ka(M.prototype),k=ka(y.prototype);k.promiseDispatch=function(a,b,c){var e=N(arguments);d?(d.push(e),"when"===b&&c[1]&&f.push(c[1])):ia(function(){s.promiseDispatch.apply(s,e)})};k.valueOf=function(){if(d)return k;var a=Fa(s);V(a)&&(s=a);return a};k.inspect=function(){return s?s.inspect():{state:"pending"}};if(e.longStackSupport&&ea)try{throw Error();}catch(q){k.stack=q.stack.substring(q.stack.indexOf("\n")+1)}w.promise=k;w.resolve=function(c){s||a(e(c))};w.fulfill=function(d){s||
a(c(d))};w.reject=function(c){s||a(Ga(c))};w.notify=function(a){s||J(f,function(b,c){ia(function(){c(a)})},void 0)};return w}function ga(a){if("function"!==typeof a)throw new TypeError("resolver must be a function.");var c=M();try{a(c.resolve,c.reject,c.notify)}catch(e){c.reject(e)}return c.promise}function xa(a){return ga(function(c,f){for(var s=0,w=a.length;s<w;s++)e(a[s]).then(c,f)})}function y(a,c,e){void 0===c&&(c=function(a){return Ga(Error("Promise does not support operation: "+a))});void 0===
e&&(e=function(){return{state:"unknown"}});var f=ka(y.prototype);f.promiseDispatch=function(e,q,s){var C;try{C=a[q]?a[q].apply(f,s):c.call(f,q,s)}catch(w){C=Ga(w)}e&&e(C)};if(f.inspect=e){var s=e();"rejected"===s.state&&(f.exception=s.reason);f.valueOf=function(){var a=e();return"pending"===a.state||"rejected"===a.state?f:a.value}}return f}function ua(a,c,f,s){return e(a).then(c,f,s)}function Fa(a){if(V(a)){var c=a.inspect();if("fulfilled"===c.state)return c.value}return a}function V(a){return a===
Object(a)&&"function"===typeof a.promiseDispatch&&"function"===typeof a.inspect}function Eb(a){return a===Object(a)&&"function"===typeof a.then}function ba(){Za.length=0;kb.length=0;gb||(gb=!0)}function ja(a,c){gb&&(kb.push(a),c&&"undefined"!==typeof c.stack?Za.push(c.stack):Za.push("(no stack) "+c))}function Ga(a){var c=y({when:function(c){if(c&&gb){var d=S(kb,this);-1!==d&&(kb.splice(d,1),Za.splice(d,1))}return c?c(a):this}},function(){return this},function(){return{state:"rejected",reason:a}});
ja(c,a);return c}function c(a){return y({when:function(){return a},get:function(c){return a[c]},set:function(c,e){a[c]=e},"delete":function(c){delete a[c]},post:function(c,e){return null===c||void 0===c?a.apply(void 0,e):a[c].apply(a,e)},apply:function(c,e){return a.apply(c,e)},keys:function(){return ca(a)}},void 0,function(){return{state:"fulfilled",value:a}})}function f(a){var c=M();ia(function(){try{a.then(c.resolve,c.reject,c.notify)}catch(e){c.reject(e)}});return c.promise}function a(a,c,f){return e(a).spread(c,
f)}function xb(a,c,f){return e(a).dispatch(c,f)}function da(a){return ua(a,function(a){var b=0,c=M();J(a,function(e,f,q){var s;V(f)&&"fulfilled"===(s=f.inspect()).state?a[q]=s.value:(++b,ua(f,function(e){a[q]=e;0===--b&&c.resolve(a)},c.reject,function(a){c.notify({index:q,value:a})}))},void 0);0===b&&c.resolve(a);return c.promise})}function fa(a){return ua(a,function(a){a=va(a,e);return ua(da(va(a,function(a){return ua(a,aa,aa)})),function(){return a})})}var ea=!1;try{throw Error();}catch(Sa){ea=
!!Sa.stack}var Wa=R(),Xa,aa=function(){},ia=function(){function a(){for(;c.next;){c=c.next;var e=c.task;c.task=void 0;var q=c.domain;q&&(c.domain=void 0,q.enter());try{e()}catch(s){if(k)throw q&&q.exit(),setTimeout(a,0),q&&q.enter(),s;setTimeout(function(){throw s;},0)}q&&q.exit()}f=!1}var c={task:void 0,next:null},e=c,f=!1,s=void 0,k=!1;ia=function(a){e=e.next={task:a,domain:k&&K.domain,next:null};f||(f=!0,s())};if("undefined"!==typeof K&&K.nextTick)k=!0,s=function(){K.nextTick(a)};else if("function"===
typeof setImmediate)s="undefined"!==typeof window?setImmediate.bind(window,a):function(){setImmediate(a)};else if("undefined"!==typeof MessageChannel){var q=new MessageChannel;q.port1.onmessage=function(){s=w;q.port1.onmessage=a;a()};var w=function(){q.port2.postMessage(0)},s=function(){setTimeout(a,0);w()}}else s=function(){setTimeout(a,0)};return ia}(),Ub=Function.call,N=w(Array.prototype.slice),J=w(Array.prototype.reduce||function(a,c){var e=0,f=this.length;if(1===arguments.length){do{if(e in this){c=
this[e++];break}if(++e>=f)throw new TypeError;}while(1)}for(;e<f;e++)e in this&&(c=a(c,this[e],e));return c}),S=w(Array.prototype.indexOf||function(a){for(var c=0;c<this.length;c++)if(this[c]===a)return c;return-1}),va=w(Array.prototype.map||function(a,c){var e=this,f=[];J(e,function(s,k,q){f.push(a.call(c,k,q,e))},void 0);return f}),ka=Object.create||function(a){function c(){}c.prototype=a;return new c},na=w(Object.prototype.hasOwnProperty),ca=Object.keys||function(a){var c=[],e;for(e in a)na(a,
e)&&c.push(e);return c},Y=w(Object.prototype.toString),La;La="undefined"!==typeof ReturnValue?ReturnValue:function(a){this.value=a};var Fb="From previous event:";e.resolve=e;e.nextTick=ia;e.longStackSupport=!1;e.defer=M;M.prototype.makeNodeResolver=function(){var a=this;return function(c,e){c?a.reject(c):2<arguments.length?a.resolve(N(arguments,1)):a.resolve(e)}};e.Promise=ga;e.promise=ga;ga.race=xa;ga.all=da;ga.reject=Ga;ga.resolve=e;e.passByCopy=function(a){return a};y.prototype.passByCopy=function(){return this};
e.join=function(a,c){return e(a).join(c)};y.prototype.join=function(a){return e([this,a]).spread(function(a,b){if(a===b)return a;throw Error("Can't join: not the same: "+a+" "+b);})};e.race=xa;y.prototype.race=function(){return this.then(e.race)};e.makePromise=y;y.prototype.toString=function(){return"[object Promise]"};y.prototype.then=function(a,c,f){function w(c){try{return"function"===typeof a?a(c):c}catch(d){return Ga(d)}}function y(a){if("function"===typeof c){s(a,k);try{return c(a)}catch(b){return Ga(b)}}return Ga(a)}
var k=this,q=M(),A=!1;ia(function(){k.promiseDispatch(function(a){A||(A=!0,q.resolve(w(a)))},"when",[function(a){A||(A=!0,q.resolve(y(a)))}])});k.promiseDispatch(void 0,"when",[void 0,function(a){var b,c=!1;try{b="function"===typeof f?f(a):a}catch(d){if(c=!0,e.onerror)e.onerror(d);else throw d;}c||q.notify(b)}]);return q.promise};e.when=ua;y.prototype.thenResolve=function(a){return this.then(function(){return a})};e.thenResolve=function(a,c){return e(a).thenResolve(c)};y.prototype.thenReject=function(a){return this.then(function(){throw a;
})};e.thenReject=function(a,c){return e(a).thenReject(c)};e.nearer=Fa;e.isPromise=V;e.isPromiseAlike=Eb;e.isPending=function(a){return V(a)&&"pending"===a.inspect().state};y.prototype.isPending=function(){return"pending"===this.inspect().state};e.isFulfilled=function(a){return!V(a)||"fulfilled"===a.inspect().state};y.prototype.isFulfilled=function(){return"fulfilled"===this.inspect().state};e.isRejected=function(a){return V(a)&&"rejected"===a.inspect().state};y.prototype.isRejected=function(){return"rejected"===
this.inspect().state};var Za=[],kb=[],gb=!0;e.resetUnhandledRejections=ba;e.getUnhandledReasons=function(){return Za.slice()};e.stopUnhandledRejectionTracking=function(){ba();gb=!1};ba();e.reject=Ga;e.fulfill=c;e.master=function(a){return y({isDef:function(){}},function(c,e){return xb(a,c,e)},function(){return e(a).inspect()})};e.spread=a;y.prototype.spread=function(a,c){return this.all().then(function(c){return a.apply(void 0,c)},c)};e.async=function(a){return function(){function c(a,b){var d;if("undefined"===
typeof StopIteration){try{d=e[a](b)}catch(w){return Ga(w)}return d.done?d.value:ua(d.value,f,s)}try{d=e[a](b)}catch(y){return"[object StopIteration]"===Y(y)||y instanceof La?y.value:Ga(y)}return ua(d,f,s)}var e=a.apply(this,arguments),f=c.bind(c,"next"),s=c.bind(c,"throw");return f()}};e.spawn=function(a){e.done(e.async(a)())};e["return"]=function(a){throw new La(a);};e.promised=function(b){return function(){return a([this,da(arguments)],function(a,c){return b.apply(a,c)})}};e.dispatch=xb;y.prototype.dispatch=
function(a,c){var e=this,f=M();ia(function(){e.promiseDispatch(f.resolve,a,c)});return f.promise};e.get=function(a,c){return e(a).dispatch("get",[c])};y.prototype.get=function(a){return this.dispatch("get",[a])};e.set=function(a,c,f){return e(a).dispatch("set",[c,f])};y.prototype.set=function(a,c){return this.dispatch("set",[a,c])};e.del=e["delete"]=function(a,c){return e(a).dispatch("delete",[c])};y.prototype.del=y.prototype["delete"]=function(a){return this.dispatch("delete",[a])};e.mapply=e.post=
function(a,c,f){return e(a).dispatch("post",[c,f])};y.prototype.mapply=y.prototype.post=function(a,c){return this.dispatch("post",[a,c])};e.send=e.mcall=e.invoke=function(a,c){return e(a).dispatch("post",[c,N(arguments,2)])};y.prototype.send=y.prototype.mcall=y.prototype.invoke=function(a){return this.dispatch("post",[a,N(arguments,1)])};e.fapply=function(a,c){return e(a).dispatch("apply",[void 0,c])};y.prototype.fapply=function(a){return this.dispatch("apply",[void 0,a])};e["try"]=e.fcall=function(a){return e(a).dispatch("apply",
[void 0,N(arguments,1)])};y.prototype.fcall=function(){return this.dispatch("apply",[void 0,N(arguments)])};e.fbind=function(a){var c=e(a),f=N(arguments,1);return function(){return c.dispatch("apply",[this,f.concat(N(arguments))])}};y.prototype.fbind=function(){var a=this,c=N(arguments);return function(){return a.dispatch("apply",[this,c.concat(N(arguments))])}};e.keys=function(a){return e(a).dispatch("keys",[])};y.prototype.keys=function(){return this.dispatch("keys",[])};e.all=da;y.prototype.all=
function(){return da(this)};e.allResolved=function(a,c,e){return function(){"undefined"!==typeof console&&"function"===typeof console.warn&&console.warn(c+" is deprecated, use "+e+" instead.",Error("").stack);return a.apply(a,arguments)}}(fa,"allResolved","allSettled");y.prototype.allResolved=function(){return fa(this)};e.allSettled=function(a){return e(a).allSettled()};y.prototype.allSettled=function(){return this.then(function(a){return da(va(a,function(a){function b(){return a.inspect()}a=e(a);
return a.then(b,b)}))})};e.fail=e["catch"]=function(a,c){return e(a).then(void 0,c)};y.prototype.fail=y.prototype["catch"]=function(a){return this.then(void 0,a)};e.progress=function(a,c){return e(a).then(void 0,void 0,c)};y.prototype.progress=function(a){return this.then(void 0,void 0,a)};e.fin=e["finally"]=function(a,c){return e(a)["finally"](c)};y.prototype.fin=y.prototype["finally"]=function(a){a=e(a);return this.then(function(c){return a.fcall().then(function(){return c})},function(c){return a.fcall().then(function(){throw c;
})})};e.done=function(a,c,f,s){return e(a).done(c,f,s)};y.prototype.done=function(a,c,f){var w=function(a){ia(function(){s(a,y);if(e.onerror)e.onerror(a);else throw a;})},y=a||c||f?this.then(a,c,f):this;"object"===typeof K&&K&&K.domain&&(w=K.domain.bind(w));y.then(void 0,w)};e.timeout=function(a,c,f){return e(a).timeout(c,f)};y.prototype.timeout=function(a,c){var e=M(),f=setTimeout(function(){e.reject(Error(c||"Timed out after "+a+" ms"))},a);this.then(function(a){clearTimeout(f);e.resolve(a)},function(a){clearTimeout(f);
e.reject(a)},e.notify);return e.promise};e.delay=function(a,c){void 0===c&&(c=a,a=void 0);return e(a).delay(c)};y.prototype.delay=function(a){return this.then(function(c){var e=M();setTimeout(function(){e.resolve(c)},a);return e.promise})};e.nfapply=function(a,c){return e(a).nfapply(c)};y.prototype.nfapply=function(a){var c=M();a=N(a);a.push(c.makeNodeResolver());this.fapply(a).fail(c.reject);return c.promise};e.nfcall=function(a){var c=N(arguments,1);return e(a).nfapply(c)};y.prototype.nfcall=function(){var a=
N(arguments),c=M();a.push(c.makeNodeResolver());this.fapply(a).fail(c.reject);return c.promise};e.nfbind=e.denodeify=function(a){var c=N(arguments,1);return function(){var f=c.concat(N(arguments)),s=M();f.push(s.makeNodeResolver());e(a).fapply(f).fail(s.reject);return s.promise}};y.prototype.nfbind=y.prototype.denodeify=function(){var a=N(arguments);a.unshift(this);return e.denodeify.apply(void 0,a)};e.nbind=function(a,c){var f=N(arguments,2);return function(){var s=f.concat(N(arguments)),w=M();s.push(w.makeNodeResolver());
e(function(){return a.apply(c,arguments)}).fapply(s).fail(w.reject);return w.promise}};y.prototype.nbind=function(){var a=N(arguments,0);a.unshift(this);return e.nbind.apply(void 0,a)};e.nmapply=e.npost=function(a,c,f){return e(a).npost(c,f)};y.prototype.nmapply=y.prototype.npost=function(a,c){var e=N(c||[]),f=M();e.push(f.makeNodeResolver());this.dispatch("post",[a,e]).fail(f.reject);return f.promise};e.nsend=e.nmcall=e.ninvoke=function(a,c){var f=N(arguments,2),s=M();f.push(s.makeNodeResolver());
e(a).dispatch("post",[c,f]).fail(s.reject);return s.promise};y.prototype.nsend=y.prototype.nmcall=y.prototype.ninvoke=function(a){var c=N(arguments,1),e=M();c.push(e.makeNodeResolver());this.dispatch("post",[a,c]).fail(e.reject);return e.promise};e.nodeify=function(a,c){return e(a).nodeify(c)};y.prototype.nodeify=function(a){if(a)this.then(function(c){ia(function(){a(null,c)})},function(c){ia(function(){a(c)})});else return this};var Ib=R();return e})},{__browserify_process:2}]},{},[1]);
