(function e$$0(Y,fa,V){function f(u,b){if(!fa[u]){if(!Y[u]){var e="function"==typeof require&&require;if(!b&&e)return e(u,!0);if(z)return z(u,!0);e=Error("Cannot find module '"+u+"'");throw e.code="MODULE_NOT_FOUND",e;}e=fa[u]={exports:{}};Y[u][0].call(e.exports,function(a){var b=Y[u][1][a];return f(b?b:a)},e,e.exports,e$$0,Y,fa,V)}return fa[u].exports}for(var z="function"==typeof require&&require,E=0;E<V.length;E++)f(V[E]);return f})({1:[function(I,Y,fa){function V(f,z){return nrdp.gibbon.setTimeout(f,
z||0)}(function(){(function(){this.setTimeout=V;this.clearTimeout||(this.clearTimeout=function(f){nrdp.gibbon.clearTimeout(f)});this.setInterval||(this.setInterval=function(f,z){return nrdp.gibbon.setTimeout(f,z||0,!1)});this.clearInterval||(this.clearInterval=function(f){nrdp.gibbon.clearTimeout(f)})})();nrdp.js={};nrdp.js.init=function(f){f&&f()}})();(function(){function f(a){this.name="NasVerifyFailedError";this.message=a}function z(a){this.name="OperatorVaultError";this.message=a}function E(){nrdp.boot||
(nrdp.boot={addEventListener:function(a,b){nrdp._addEventListener(this,a,b)},removeEventListener:function(a,b){nrdp._removeEventListener(this,a,b)},sendBIEPNotification:function(a){nrdp._callEventListeners(this,{type:"appreloadfailed",errorparams:a})},makeAppbootRequest:l})}function u(){if(!(P||nrdp.storage.transientData||fa)){var a=nrdp.device,b={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,timeElapsed:""+(nrdp.mono()-nrdp.started)},a=a.startupTags;if(ja.isObject(a))for(var e in a)a.hasOwnProperty(e)&&(b[e]=a[e]);nrdp.log.info("","BOOT","startup",b,!0,!0)}}function b(a){var b=Na||nrdp.options.appboot_url;"/"!=b[b.length-1]&&(b+="/");a&&(b+=encodeURIComponent(nrdp.device.ESNPrefix));return b}function e(a){var b,e={},l=ia.appboot_extra_params;e.url=a.url;if(!e.url)throw Error('"ui" element is missing "url"');nrdp.options.ui_request&&nrdp.options.ui_request.url?
(e.url=nrdp.options.ui_request.url,e.headers=nrdp.options.ui_request.headers):nrdp.options.ui_url?e.url=nrdp.options.ui_url:(b=a.hashvalue||"",a=a.hashalgorithm||"",0!==b.length&&0!==a.length&&"xasfa43r23552"!=b&&(e.headers={"X-Gibbon-Hash":a+"="+b}));l&&(e.url+=(0<e.url.indexOf("?")?"&":"?")+decodeURIComponent(l));return e}function a(a){return a&&200<=a.statusCode&&300>a.statusCode&&a.data&&(a.data.byteLength||/^file:/.test(a.finalURL))}function wa(a){var b,e=nrdp.started,l=nrdp.device.SDKVersion.components.platform,
f,O,c,z;try{ja.isArray(a)?(b=a.filter(function(a){return a.sendtoichnaea}),0===b.length?L.info("No critical messages to send to Ichnaea"):(L.trace("Have "+b.length+" message(s) for Ichnaea: "+JSON.stringify(b)),f=b.map(function(a){try{return{version:a.platformVersion,elapsedTime:a.monotime-(a.basemonotime||e),msg:a.msg,tags:a.tags}}catch(b){return{msg:"Failed to construct milestone: "+(b.toString?b.toString():b)}}}),O=JSON.stringify({events:[{name:"nrdp",data:{source:"netflixApp",type:"milestone",
esn:nrdp.device.ESN,platformVersion:l.platformVersion,softwareVersion:nrdp.device.softwareVersion,elapsedTime:nrdp.mono()-e,appid:nrdp.log.appid,milestones:f}}]}),L.trace("Sending to Ichnaea: "+O),z=ia.appboot_milestone_timeout,c={url:ia.appboot_milestone_url,headers:{"X-Netflix.Ichnaea.Request.Type":"IchnaeaRequest","X-Gibbon-Cache-Control":"no-cache"},body:O,async:!0,timeout:z},L.trace("Ichnaea request: "+JSON.stringify(c)),nrdp.gibbon.load(c,function(a){var c=a?a.statusCode:0;L.log("Ichnaea response: "+
JSON.stringify(a));200<=c&&300>c&&(L.log("Ichnaea success, deleting "+b.length+" critical message(s)"),nrdp.log.deleteCriticalMessages(b))}))):L.error("Critical messages are not an array : "+typeof a)}catch(N){L.error("Failed to send milestones to Ichnaea : "+N)}}function l(){function I(a){var b=nrdp.storage;a&&(Na=a);P++;b.removeItem(b.NO_DEVICE_ACCOUNT,"AppbootUserId");P<=Ua?(a=1E3*P,L.warn("Retrying AppBoot request in "+a+" ms..."),nrdp.gibbon.setTimeout(l,a)):(a=K.ERROR_DESCRIPTION,K.ERROR_DESCRIPTION=
a?"Retry Count Exceeded, last error: "+a:"Retry Count Exceeded",aa(),K.ERROR_STAGE=0)}function aa(){wa(Ja);Y=P=0;E();nrdp.js.options||(nrdp.js.options=ia);R&&!a(R.response)&&(L.trace("Discarding previous SD"),R=null);var d="http://localcontrol.netflix.com/js/error.js",c="?",e,G;G=nrdp.storage;var x;x=G.secureStoreSize;var r=G.getUsedSecureStoreSize(),l=x-r;L.info("Secure store size = "+x+" : used = "+r+" : free = "+l);5E3<=l?(x=G.getItem(G.NO_DEVICE_ACCOUNT,"AppbootErrors")||[],x.push({description:K.ERROR_DESCRIPTION,
stage:K.ERROR_STAGE,appid:nrdp.log.appid,clienttime:Date().toString(),url:b(!0)}),G.setItem(G.NO_DEVICE_ACCOUNT,"AppbootErrors",x)):L.warn("Not enough storage left to save more errors  : secure store size = "+x+" : used = "+r+" : free = "+l);K.ERROR_DESCRIPTION="Error loading UI";L.warn("Error parameters for BIEP:\n"+JSON.stringify(K,null,"  "));if(fa)L.trace("Notifying BIEP"),nrdp.boot.sendBIEPNotification(K);else{fa=!0;L.log("Loading BIEP");for(e in K)G=K[e],ja.isString(G)&&(G=G.replace(/\\/g,"\\\\").replace(/'/g,
"\\'").replace(/"/g,'\\"').replace(/\n/g,"\\n")),d+=c+e+"="+encodeURIComponent(G),c="&";nrdp.gibbon.loadScript({url:d})}}function Ma(b,c){var e=b.url,r=b.headers;ka.attempt(function(){return b.response?b.response:(new ka(function(a){L.info("Starting UI download with:\nurl:        "+e+"\nheaders:    "+JSON.stringify(r)+"\nUI tries:   "+Y+"\nAB retries: "+P);++Y;nrdp.gibbon.load({url:e,headers:r,format:"arraybuffer"},a)})).delay(ia.appboot_ui_delay).then(function(b){var d;d="Finished UI download with:\nrequest url:  "+
e+"\nresponse url: "+b.url+"\nfinal url:    "+b.finalURL+"\nstate:        "+b.state+"\nstatus:       "+b.statusCode+"\nsource:       "+!!b.data+"\nUI tries:     "+Y+"\nAB retries:   "+P;a(b)?L.info(d):(L.warn(d),d={appid:nrdp.log.appid,url:e,errorCode:b.errorcode,errorGroup:b.errorGroup,nativeErrorCode:b.nativeerrorCode,serverIp:b.serverIp,statusCode:b.statusCode,retryCount:""+Y,timeElapsed:""+(nrdp.mono()-nrdp.started)},nrdp.log.error("UI download failed","BOOT","networkerror",d,!0,!0));return b})}).then(function(a){return c?
c(a):a}).then(function(b){var d=!fa;d&&ia.appboot_no_reuse&&(d=!1);if(b){if(!a(b))throw b;Y=P=0;delete nrdp.js;delete nrdp.boot;nrdp._init=!1;var c=b.finalURL;e!=b.url&&(L.warn("Using request URL because finalURL points to a cached response"),c=e);L.info("Really, truly setting location now with reuse="+d+' to "'+c+'"');nrdp.gibbon.location={url:c,headers:r,source:b.data,reuse:d}}}).fail(function(a){if(6<=Y+P)throw L.warn("Maximum total retries exceeded, going to error page"),a;a=1E3*(P+Y);L.warn("Retrying UI download in "+
a+" ms...");setTimeout(function(){Ma({url:e,headers:r})},a)}).fail(function(a){K.ERROR_CATEGORY="Network";K.ERROR_DESCRIPTION="AppBoot client failed to download UI";K.ERROR_URL=a.url;K.ERROR_CODE=a.errorcode;K.ERROR_GROUP=a.errorgroup;K.NATIVE_ERROR_CODE=a.nativeerrorCode;K.ERROR_FRAME_URL=a.finalURL;K.SERVER_IP=a.serverIp;K.ERROR_STATUS_CODE=a.statusCode;aa()})}function mb(){var b;ia.appboot_no_speculative_ui?L.trace("SD is turned off"):R?L.trace("Already have an SD"):(b=nrdp.storage.getItem("s",
"appbootui"))?(R=e(b),L.trace("Beginning SD"),Ma(R,function(b){if(R)if(a(b)||R.setLocation){if(L.trace("SD status code is "+b.statusCode),R.response=b,R.setLocation)return L.info("Now really setting location to SD data"),b}else L.warn("SD failed"),R=null;else L.trace("SD finished but was discarded")})):L.trace("No previous URL found for SD")}function Qa(){return!!(ia.appboot_install_opvault&&nrdp.system&&ja.isFunction(nrdp.system.installOperatorVault))}function jb(){var a=nrdp.storage,b;r=null;if(b=
a.getItem(a.NO_DEVICE_ACCOUNT,"AppbootOperatorVault")){L.trace("Loaded existing operator vault from storage :",b);if(ja.isObject(b)&&ja.isString(b.hash)&&b.hash.length)return L.trace("Operator vault hash is",b.hash),r={hash:b.hash,data:b.data};L.warn("Operator vault invalid or missing hash, removing from storage");a.removeItem(a.NO_DEVICE_ACCOUNT,"AppbootOperatorVault")}else L.trace("No existing operator vault in storage")}function c(a){Qa()&&(L.info("Requesting PRM operator vault"),a.prmopvault=
{},r&&(a.prmopvault.hash=r.hash))}function J(a){return new ka(function(b,c){if(a&&ja.isObject(a)&&ja.isString(a.hash)&&a.hash.length&&ja.isString(a.data)&&a.data.length)L.trace("Installing operator vault",a);else return c("Invalid operator vault");var e=nrdp.mono();nrdp.system.installOperatorVault(a.data,function(a){var d=nrdp.storage;if(!a||!a.success)return L.error("Failed to install stored operator vault, removing it"),d.removeItem(d.NO_DEVICE_ACCOUNT,"AppbootOperatorVault"),c(new z("Failed to install operator vault, result = "+
JSON.stringify(a)));L.warn("Operator vault installed in",nrdp.mono()-e,"ms");b()})})}var K={ERROR_CATEGORY:"AppBoot",ERROR_FRAME_URL:"",ERROR_DESCRIPTION:"",ERROR_STATUS_CODE:"",ERROR_GROUP:"",ERROR_CODE:"",NATIVE_ERROR_CODE:"",ERROR_URL:"",ERROR_ACTIONID:"",ERROR_TEXT:"",ERROR_BCP47:"",ERROR_STAGE:""},Ja=[],Oa=[],Ra=!1;L||(L=new Ka("BOOT","ui|gibbon"));(function(){this.setTimeout!==V&&(L.warn("Our setTimeout has been clobbered, restoring"),this.setTimeout=V)})();L.trace("Making app boot request"+
(fa?" from BIEP":""));var r,v=!1;ka.attempt(function(){K.ERROR_STAGE=1;return new ka(function(a){nrdp.gibbon.init(a)})}).then(function(){var a=nrdp.storage;nrdp.gibbon._loadSplash(a.getItem("s","appsplash"));L.warn("BOOT version","v2.6.3");ia=(new N).initialize();Ua||(Ua=ia.appboot_max_retries);mb();K.ERROR_STAGE++;K.ERROR_FRAME_URL=nrdp.gibbon.location;try{delete a.transientData.appboot.msltruststore,L.trace("Deleted previous MSL trust store")}catch(b){L.trace("No previous MSL trust store")}u();
a=new ka(function(a){nrdp.log.addEventListener("criticalMsgsReady",function x(b){nrdp.log.removeEventListener("criticalMsgsReady",x);Ja=b.data;L.trace("Got "+Ja.length+" critical messages");a()});nrdp.log.getCriticalMessages()});return[ka.resolve().then(function(){function a(){v=!0;var b=Object.create(ia);b.unauth=!0;b.mslClear=!0;return O(b)}var b;if(!Qa())return O(ia);b=jb();if(!b)return a();L.log("Have existing operator vault in secure store");return J(b).then(function(){return O(ia)},function(b){L.warn("Failed to install operator vault",
b);r=null;return a()})}),a]}).all().spread(function(a){K.ERROR_STAGE++;var g=nrdp.device,e=nrdp.options,r=nrdp.storage,x=b(!0),l=!!x.match(/^https:/),f,O,z=g.UILanguages,N={aid:nrdp.log.appid,client_info:{certification_version:""+g.certificationVersion,nrdlib_version:""+g.SDKVersion.components.nrdlib,nrdapp_version:""+g.SDKVersion.components.nrdapp,mdxlib_version:""+g.SDKVersion.components.mdxlib,sdk_version:""+g.SDKVersion.components.nrdlib,sw_version:""+g.softwareVersion,languages:0>z.indexOf(g.language)?
z.concat(g.language):z},ui:{app:"gibbontvui",query_params:{dw:""+e.ui_width,dh:""+e.ui_height,dar:""+e.ui_aspect_ratio,reg:""+g.registered,q:""+nrdp.uiQueryString}}};0<nrdp.gibbon.location.indexOf("?")&&nrdp.gibbon.location.replace(/[^?]*\?/,"").split("&").forEach(function(a){a&&(a=a.split("="),N.ui.query_params[a[0]]=1<a.length?decodeURIComponent(a[1]):!0)});e.appboot_params.split(/[&,]/).forEach(function(a){a&&(a=a.split("="),N.ui.query_params[a[0]]=1<a.length?decodeURIComponent(a[1]):!0)});v||
(N.ui.cookies=nrdp.gibbon.cookie.split("; ").map(function(a){return a.split("=")}).reduce(function(a,b){a[b[0]]=b[1];return a},{}));e=nrdp.trustStoreHash||"";N.ssltruststore=0===e.length?{}:{hash:e};N.msltruststore={};e=nrdp.nova&&nrdp.nova.wiiu&&nrdp.nova.wiiu.nasToken;if(Ra=!(!ja.isString(e)||!e.length))L.log("NAS token is",e),N.nas_token=e;c(N);f=[];var u=nrdp.device.SDKVersion.components.platform,l={level:"info",type:"appboot",esn:g.ESN,appid:nrdp.log.appid,msg:"appboot request made "+(l?"with":
"without")+" SSL",ssl:l,clienttime:Date().toString(),app_uptime:""+(nrdp.mono()-nrdp.started),retrycount:P};if(u)for(O in u)"string"===typeof O&&"string"===typeof u[O]&&(l[O]=u[O]);f.push(l);v||(O=r.getItem(r.NO_DEVICE_ACCOUNT,"AppbootErrors")||[],O.forEach(function(a){a={level:"error",type:"networkerror",esn:g.ESN,appid:a.appid,msg:"Appboot displayed BIEP",description:a.description,stage:a.stage,clienttime:a.clienttime,url:a.url,device:a.device};if(u)for(var b in u)"string"===typeof b&&"string"===
typeof u[b]&&(a[b]=u[b]);f.push(a)}),Ja.forEach(function(a){if(a.sendtoappboot){L.log("Adding critical message to appboot logblob");if(u&&!a.sendtoichnaea)for(var b in u)"string"!==typeof b||"string"!==typeof u[b]||a[b]||(a[b]=u[b]);a.sendtoichnaea&&"milestone"===a.logtype&&(a.type="milestone",a.level="info",a.tags&&a.tags.appid&&(a.appid=a.tags.appid));f.push(a);Oa.push(a)}}),L.log("criticalmessage length "+Ja.length));N.log=f;N.responseparams="loglevel retrycontrol loginterval maxlogsize testdriveripaddr instrumentationparams".split(" ");
L.log("Sending AppBoot request to "+x+"\n"+JSON.stringify(N,null," "));O=null;v||(O=r.getItem(r.NO_DEVICE_ACCOUNT,"AppbootUserId")||null);L.log("making appboot request with userId "+O);return a.request(x,O,JSON.stringify(N),2E4)}).then(function(a){K.ERROR_STAGE++;var b;b=nrdp.storage;var c=b.transientData||{};a=JSON.parse(nrdp.utf8toa(a.body));L.log("AppBoot response is\n"+JSON.stringify(a,null," "));ia.appboot_test_response&&nrdp.gibbon.load({url:ia.appboot_test_response,async:!1,format:"json"},
function(b){ja.isObject(b.json)?(Da(b.json,a),L.warn("MODIFIED RESPONSE"),L.log(JSON.stringify(a,null," "))):L.error("Failed to load test appboot response",b)});c.appboot=a;b.transientData=c;b.removeItem(b.NO_DEVICE_ACCOUNT,"AppbootErrors");nrdp.log.deleteCriticalMessages(Oa);Ja=[];Oa=[];if(b=a.error)switch(b.actionid){case 7:K.ERROR_DESCRIPTION="toplevel: Redirect to "+b.appbootendpoint;K.ERROR_ACTIONID=b.actionid;I(b.appbootendpoint);break;case 2:K.ERROR_DESCRIPTION="toplevel: Error 2";K.ERROR_ACTIONID=
b.actionid;I();break;case 13:K.ERROR_ACTIONID=b.actionid;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 K.ERROR_ACTIONID=b.actionid,b.usertextgroup&&(K.ERROR_TEXT=b.usertextgroup.text,K.ERROR_BCP47=b.usertextgroup.bcp47),Error("AID "+b.actionid);}else{if(Ra)if(ia.appboot_fail_nas_verify&&(L.error("Synthetic failure of NAS token verification"),a.nas_token_response=
{success:!1,reason:"Synthetic failure from command line"}),(b=a.nas_token_response)&&ja.isObject(b)&&b.success)L.info("NAS token verified");else throw L.error("NAS token was not verified, response was",b),c=nrdp.nova&&nrdp.nova.wiiu&&nrdp.nova.wiiu.nasVerifyFailed,ja.isFunction(c)&&c(),new f("Response was: "+JSON.stringify(b));b=a.tls_cipher_suites;ja.isString(b)&&nrdp.hasOwnProperty("cipherList")&&(L.info("Setting TLS cipher list",b),nrdp.cipherList=b);return ka.attempt(function(){var b=a.servertime_seconds,
c=Math.floor(nrdp.now()/1E3),e=Math.floor(Date.now()/1E3);ja.isNumber(b)&&(L.info("AppBoot server time "+b),L.info("nrdp.now            "+c+" : "+(c-b)),L.info("Date.now            "+e+" : "+(e-b)),nrdp.setServerTime(b))}).then(function(){var b=a.responseparams.loglevel,c=a.responseparams.testdriveripaddr,e=a.responseparams.instrumentationparams,g=a.responseparams.retrycontrol;ja.isNumber(b)?nrdp.log.level=b:ja.isString(b)&&(nrdp.log.level=nrdp.log.levels[b]);c&&nrdp.setTestDriverIpAddress(c);e&&
nrdp.instrumentation.setParams(e.enabled,e.events);ja.isNumber(g)&&(Ua=g)}).then(function(){var b,c=a.ssltruststore;c&&((b=c.error)?L.error('AppBoot server returned an error for "ssltruststore" : '+JSON.stringify(b)):(L.info("Updating app trust store"),nrdp.setTrustStore(c.data)))}).then(function(){K.ERROR_STAGE++;var b;b=a.msltruststore;if(!b)throw Error('response is missing "msltruststore"');if(b=b.error)throw L.error('AppBoot server returned an error for "msltruststore" : '+JSON.stringify(b)),
Error(JSON.stringify(b));L.info("Updating MSL trust store")}).then(function(){var b=a.prmopvault;if(b)return J(b).then(function(){var a=nrdp.storage;L.log("Saving operator vault");a.setItem(a.NO_DEVICE_ACCOUNT,"AppbootOperatorVault",b)})}).then(function(){K.ERROR_STAGE++;var b,c;c=a.ui;if(!c)throw Error('"ui" element is missing from AppBoot response');if(b=c.error){if(2==b){K.ERROR_DESCRIPTION="ui: Error 2";I();return}throw Error('"ui" response includes an error : '+JSON.stringify(b));}b=e(c);c.splash&&
(nrdp.storage.setItem("s","appsplash",c.splash),delete c.splash);nrdp.storage.setItem("s","appbootui",c);R&&b.url==R.url?(L.trace("Remembered ui is the same, using SD data"),R.response?(L.trace("SD is already complete, setting location now"),Ma(R)):(L.trace("SD still in progress, deferring setting location"),R.setLocation=!0)):(L.trace('Unusable SD data, loading UI from "'+b.url+'"'),Ma(b))})}}).fail(function(a){var c,e=!1,r;r=a.cause?" (caused by "+a.cause.toString()+")":"";L.error("App boot failed:"+
r,a);K.ERROR_DESCRIPTION=r;if(a instanceof Bb)K.ERROR_CATEGORY="Network",K.ERROR_DESCRIPTION=a.mesg,K.ERROR_URL=a.url,K.ERROR_CODE=a.errorCode,K.ERROR_GROUP=a.errorGroup,K.NATIVE_ERROR_CODE=a.nativeerrorCode,K.ERROR_FRAME_URL=a.finalUrl,K.SERVER_IP=a.serverIp,K.ERROR_STATUS_CODE=a.httpCode,(a.errorCode===nrdp.network.ERRORCODE.TIMEOUTERROR||"TIMED_OUT_ERROR"===a.mesg)&&0<P?L.warn("Second timeout - will not retry"):(c=b(),/^http:/.test(c)?(L.warn("Retrying using SSL"),e=!0,c=c.replace(/^http:/,"https:")):
/^https:/.test(c)&&(L.warn("Retrying without SSL"),e=!0,c=c.replace(/^https:/,"http:")));else if(a instanceof sa)e=!0;else if(a instanceof Ia)P||(e=!0);else if(a instanceof qa&&a.error)switch(K.MSL_RESPONSE_CODE=a.error.responseCode,K.MSL_INTERNAL_CODE=a.error.internalCode,K.MSL_MESSAGE=a.error.message,a.error.responseCode){case nb.TRANSIENT_FAILURE:e=!0}else{if(a instanceof f)return;a instanceof z&&(e=!0)}e?I(c):aa()}).done()}var ka=I("nf-promise"),ja=I("nf-underscore"),Da=I("nf-mixin"),Ka=I("nf-console"),
O=I("nf-gibbon-mslclient"),N=I("./config-loader"),Ia=O.TimeoutError,qa=O.MslException,sa=O.MslEncodingException,Bb=O.MslIoException,nb=O.MslConstants$ResponseCode,Na,P=0,R,Y=0,fa=!1,Ua,L,ia=I("nf-config");ia.declare({appboot_key:["appboot_key",""],appboot_extra_params:["appboot_extra_params",""],appboot_milestone_timeout:["appboot_milestone_timeout",2E4],appboot_milestone_url:["appboot_milestone_url","http://ichnaea.netflix.com/log"],appboot_ui_delay:["appboot_ui_delay",0],appboot_no_reuse:["appboot_no_reuse",
!1],appboot_no_speculative_ui:["appboot_no_speculative_ui",!1],appboot_max_retries:["appboot_max_retries",5],appboot_fail_nas_verify:["appboot_fail_nas_verify",!1],appboot_test_response:["appboot_test_response",""],appboot_install_opvault:["appboot_install_opvault",!0]});f.prototype=Error();f.prototype.constructor=f;z.prototype=Error();z.prototype.constructor=z;"object"==typeof application&&application&&application.isErrorPage?(fa=!0,E()):l()})()},{"./config-loader":3,"nf-config":5,"nf-console":6,
"nf-gibbon-mslclient":10,"nf-mixin":11,"nf-promise":12,"nf-underscore":13}],2:[function(I,Y,fa){Y.exports={debug:["debug",function(){return!(!nrdp.debug&&!nrdp.log.haveTracing)}],tturl:["tturl",""],useLicenseCache:[["uselc","useLicenseCache"],!0],lc_use_std:["lc_use_std",!1],ldl_expiration_ms:[["ldl_expiration_ms","licenseCacheExpirationMs"],6E5],ldl_purge_percent:["ldl_purge_percent",25],check_instr:["check_instr",!1],nologcheck:["nologcheck",!1],hblog:["hblog",!1],usehc:[["usehc","useHeaderCache"],
!1],usehcd:[["usehcd","useHeaderCacheData"],!1],logblob_post_url:["logblob_post_url",""],npticket_interval:["npticket_interval",144E5],nopbr:["nopbr",!1],log64:["log64",!1],nccp_post_url:["nccp_post_url",""],license_offset:["license_offset",0],swex:["swex",!1],awex:["awex",!1],noss:["noss",!1],trace_msl_requests:["trace_msl_requests",!1],trace_msl_service_tokens:["trace_msl_service_tokens",!1],trace_msl_store:["trace_msl_store",!1],mslFallbackTimer:["mslFallbackTimer",!0],noverify:["noverify",!1],
unauth:["unauth",!1],compress:["compress",""],mslClear:["mslClear",!1],nccp_version:["nccp_version","3.1"],nccp_url:["nccp_url",""],apiHost:["apiHost",""],mslBackupTokens:["mslBackupTokens",!1]}},{}],3:[function(I,Y,fa){function V(a){var e;a&&b.isObject(a)&&(e=a.streamingLabels)&&b.isObject(e)&&(delete a.streamingLabels,ka={},ka._master_=a,b.each(e,function(e,l){var f="'"+l+"'",O=e;try{b.isString(O)&&(O=JSON.parse(O))}catch(z){u.warn("Failed to parse config labeled",f,":",z.toString());return}O&&
b.isObject(O)?(b.each(a,function(a,b){O.hasOwnProperty(b)||(O[b]=a)}),u.trace("Found config labeled",f),ka[l]=O):u.warn("Labeled config",f,"is not an object")}))}function f(){function a(e){return e&&b.isObject(e)?Object.keys(e).sort().reduce(function(a,b){a[b]=e[b];return a},{}):e}function l(b){var f=b.name;b=b.data;var O="streaming"===f,z=b&&b.configRestored,N=0;E.isDebug()&&u.dump('NRDP "'+f+'" config changed',a(b));O&&(V(b),N+=e.set(b,!0,u),N+=e.override({haveStreamingConfig:!0},!1,u),wa(z?"(persisted)":
"(provided)"));N&&e.dump(u,!1);!z&&e.persistConfig&&(z=nrdp.registration.currentDeviceAccount)&&(u.trace("Saving config for device account",z),O=nrdp.storage.getItem(z,"_config_")||{},O[f]=b,nrdp.storage.setItem(z,"_config_",O))}if(nrdp.registration){nrdp.registration.addEventListener("getConfigList",function(a){a=a.dak;var l=nrdp.storage.getItem(a,"_config_"),f;u.dump("Saved config for device account",a,"is",l);l?b.isObject(l)?e.persistConfig?b.each(l,function(a,e){a&&e&&b.isObject(a)&&b.isString(e)?
(u.trace('Restoring saved config "'+e+'"'),a.configRestored=!0,nrdp.setConfigData(e,a)):(u.log("Skipping bad entry in saved config"),f||(f="has a bad entry"))}):f="persistConfig is false":f="it is not an object":u.trace("No saved config");f&&(u.warn("Deleting saved config :",f),nrdp.storage.removeItem(a,"_config_"))});var f=nrdp.device.SDKVersion&&nrdp.device.SDKVersion.components&&nrdp.device.SDKVersion.components.nrdapp;if("string"==typeof f&&(0===f.indexOf("2014.1")||2014>parseInt(f.substr(0,4),
10))){u.warn("NRDAPP version is",f,': overriding nrdp.setConfigData because there is no "configChanged" event');var z=nrdp.setConfigData.bind(nrdp);nrdp.setConfigData=function(a,b){z(a,b);l({name:a,data:b})}}else nrdp.addEventListener("configChanged",l)}}function z(){}var E=I("nf-console"),u=new E("CONFIG"),b=I("nf-underscore");fa=I("nf-promise");var e=I("nf-config"),a=I("./command-line-options");e.declare({haveStreamingConfig:["haveStreamingConfig",!1],persistConfig:["persistConfig",!0],configRestored:["configRestored",
!1]});var wa,l=(new fa(function(a){wa=a})).then(function(a){u.warn("Streaming config arrived",a);return e}),ka,ja="_master_",Da;z.prototype.initialize=function(){var b;if(Da)u.trace("Config loader already initialized"),b=e;else if(nrdp.isReady){Da=!0;e.declare(a);if(b=nrdp.options.js_opts)u.trace('Setting command-line overrides using : "'+b+'"'),e.override(b,!0,u);f();e.dump(u,!1);b=e}else u.fatal("Cannot initialize config when NRDP is not ready"),b=void 0;return b};z.prototype.setConfigLabel=function(a){var b,
l;a=a||"_master_";l="'"+a+"'";if(a==ja)return u.trace("Already on config",l),!0;if(ka){if(b=ka[a])return u.trace("Switching to config labeled",l),ja=a,e.reset(),b.configRestored=!0,nrdp.setConfigData("streaming",b),!0;u.warn("No config labeled",l)}else u.trace("No labeled configs")};z.afterStreamingConfigArrives=function(a){return b.isFunction(a)?l.then(a).done():l};Y.exports=z},{"./command-line-options":2,"nf-config":5,"nf-console":6,"nf-promise":12,"nf-underscore":13}],4:[function(I,Y,fa){function V(){b=
!1;e.length?u=e.concat(u):a=-1;u.length&&f()}function f(){if(!b){var f=setTimeout(V);b=!0;for(var l=u.length;l;){e=u;for(u=[];++a<l;)e&&e[a].run();a=-1;l=u.length}e=null;b=!1;clearTimeout(f)}}function z(a,b){this.fun=a;this.array=b}function E(){}I=Y.exports={};var u=[],b=!1,e,a=-1;I.nextTick=function(a){var e=Array(arguments.length-1);if(1<arguments.length)for(var E=1;E<arguments.length;E++)e[E-1]=arguments[E];u.push(new z(a,e));1!==u.length||b||setTimeout(f,0)};z.prototype.run=function(){this.fun.apply(null,
this.array)};I.title="browser";I.browser=!0;I.env={};I.argv=[];I.version="";I.versions={};I.on=E;I.addListener=E;I.once=E;I.off=E;I.removeListener=E;I.removeAllListeners=E;I.emit=E;I.binding=function(a){throw Error("process.binding is not supported");};I.cwd=function(){return"/"};I.chdir=function(a){throw Error("process.chdir is not supported");};I.umask=function(){return 0}},{}],5:[function(I,Y,fa){function V(a){return a.split(",").reduce(function(a,b){var e=b.split("="),l=e[0],e=e.slice(1).join("=");
l&&l.length&&(a[l]=e||!0);return a},{})}function f(a){return a&&"object"===typeof a?JSON.stringify(a):"string"===typeof a?'"'+a+'"':""+a}function z(a,b,u){if("string"===typeof a)return z.call(this,V(a),b,u);var E=0;Object.keys(a).forEach(function(z){var I=ka[z],V=a[z],wa;if(I){if(wa=ja[z]||Ka[typeof e[I]])try{V=wa(V)}catch(P){u&&u.error("Failed to convert value '"+V+"' for config '"+z+"' : "+P.toString());return}wa=l[I];this[I]=V;l[I]!==wa&&(u&&u.trace("Config changed for '"+z+"' from "+f(wa)+" ("+
typeof wa+") to "+f(V)+" ("+typeof V+")"),++E)}else b?(I=(I=Da[z])?I.filter(function(a){return a[0]!==this},this):[],I.push([this,V]),Da[z]=I):u&&u.error("Attempt to change undeclared config option '"+z+"'")},this);E&&l.emit("changed");return E}function E(){return Object.keys(ka).reduce(function(a,b){var e=ka[b],l=a[e];l?(l.push(b),a[e]=l.sort(function(a,b){return b.length-a.length})):a[e]=[b];return a},{})}function u(a,b){return a.hasOwnProperty(b)?f(a[b]):void 0}function b(a,b){return"undefined"===
typeof a?b:a}fa=I("nf-mixin");I=I("nf-events").EventEmitter;var e={},a=Object.create(e),wa=Object.create(a),l=Object.create(wa),ka={},ja={},Da={};l.declare=function(a){Object.keys(a).forEach(function(b){var l=a[b],f=l[0],u=l[1],E=l[2];if(e.hasOwnProperty(b))throw Error("The local configuraion key '"+b+"' is already in use");"string"===typeof f&&(f=[f]);f.forEach(function(a){var l;if(ka.hasOwnProperty(a))throw Error("The configuration value '"+a+"' has been declared more than once");e.hasOwnProperty(b)||
("function"===typeof u&&(u=u()),e[b]=u);ka[a]=b;"function"===typeof E&&(ja[a]=E);if(l=Da[a])l.forEach(function(b){var e=b[0],l={};l[a]=b[1];z.call(e,l,!1)}),delete Da[a]})});return l};var Ka={object:function(a){return"object"==typeof a?a:JSON.parse(""+a)},"boolean":function(a){return"boolean"==typeof a?a:!("0"===""+a||"false"===(""+a).toLowerCase())},number:function(a){if("number"==typeof a)return a;a=parseFloat(""+a);if(isNaN(a))throw Error("parseFloat returned NaN");return a}};l.set=z.bind(a);l.override=
z.bind(wa);l.dump=function(z,I){function V(){Ka&&z&&z.log("===========================================")}var Y=Object.keys(Da).sort(),ja={},fa=E(),Ka;I=b(I,!0);Object.keys(ka).sort().forEach(function(E){E=ka[E];var P,R,Y;!ja[E]&&(ja[E]=!0,R=u(a,E),Y=u(wa,E),I||"undefined"!==typeof R||"undefined"!==typeof Y)&&(P=fa[E].join(","),P+=" = "+f(l[E])+" ("+typeof l[E]+") [",P+=b(Y,"<unset>")+",",P+=b(R,"<unset>")+",",P+=u(e,E)+"]",Ka||(Ka=!0,z&&z.log("Current config values"),V()),z&&z.log(P))});(I||Y.length)&&
z&&z.log("<undeclared> :",Y);V()};l.persistent=function(){var b=E();return Object.getOwnPropertyNames(a).reduce(function(e,l){e[b[l][0]]=a[l];return e},{})};l.reset=function(){Object.keys(a).forEach(function(b){delete a[b]})};l._listeners={};fa(I,l);Y.exports=Object.freeze(l)},{"nf-events":9,"nf-mixin":11}],6:[function(I,Y,fa){function V(a,b){var e=[];return JSON.stringify(a,function(a,b){if("object"===typeof b&&null!==b){if(-1!==e.indexOf(b))return"<cycle>";e.push(b)}return b},b?" ":void 0)}function f(a,
b,e){var f=b.length,z=a.length?""+a.join(" ")+" ":"",u=e?"":z,E;for(a=0;a<f;++a)if(E=b[a],a&&u.length&&(u+=" "),"object"===typeof E)if(null===E)u+="null";else if(E instanceof Error)u+=E.toString()+(E.stack?"\n"+E.stack:"")+"\n";else try{u=e?u+("\n"+JSON.stringify(E,null,"  ")):u+JSON.stringify(E)}catch(I){u=e?u+("\n"+V(E,!0)):u+V(E)}else u+=E;e&&(b=u.split("\n"),u="",b.forEach(function(a){u+=z+a+"\n"}));return u}function z(b,l,f,z){this._traceArea=b||"CONSOLE";this._logger=z||a||e;this._prefix=[];
"function"===typeof this._logger.createArea?(this._groups=l=l?l+"|nrdjs":"nrdjs",this._logger.createArea(this._traceArea,l)):this._prefix.push("("+b+")");Array.isArray(f)?this._prefix=f:f&&"string"===typeof f&&this._prefix.push(f)}var E,u=!1,b=!0;I=function(){};var e={info:I,warn:I,error:I,trace:I},a;"undefined"!==typeof nrdp&&nrdp.log&&(a={trace:nrdp.log.trace.bind(nrdp.log),log:nrdp.log.debug.bind(nrdp.log),info:nrdp.log.info.bind(nrdp.log),warn:nrdp.log.warn.bind(nrdp.log),error:nrdp.log.error.bind(nrdp.log),
fatal:nrdp.log.fatal.bind(nrdp.log),createArea:nrdp.log.createArea?nrdp.log.createArea.bind(nrdp.log):null},E=function(){!u&&nrdp.isReady&&(u=!0,b=nrdp.debug||nrdp.log.haveTracing,E=null)});z.setDebug=function(a){b=!!a;E=null};z.isDebug=function(){E&&E();return b};z.prototype.info=function(){this._logger.info(f(this._prefix,arguments),this._traceArea)};z.prototype.error=function(){this._logger.error(f(this._prefix,arguments),this._traceArea)};z.prototype.warn=function(){this._logger.warn(f(this._prefix,
arguments),this._traceArea)};z.prototype.trace=function(){E&&E();b&&this._logger.trace(f(this._prefix,arguments),this._traceArea)};z.prototype.log=function(){var a=this._logger;a.log&&(E&&E(),b&&a.log(f(this._prefix,arguments),this._traceArea))};z.prototype.debug=z.prototype.log;z.prototype.fatal=function(){var a=this._logger;a.fatal&&a.fatal(f(this._prefix,arguments),this._traceArea)};z.prototype.dump=function(){E&&E();b&&this._logger.trace(f(this._prefix,arguments,!0),this._traceArea)};z.prototype.createSubConsole=
function(a){return new z(this._traceArea,this._groups,this._prefix.concat(a),this._logger)};Y.exports=z},{}],7:[function(I,Y,fa){function V(f,E){var u;if(void 0===E||"function"!==typeof E||"string"!==typeof f)throw new TypeError("EventEmitter: addEventListener requires a string and a function as arguments");if(void 0===this._listeners)return this._listeners={},this._listeners[f]=[E],!0;u=this._listeners[f];return void 0===u?(this._listeners[f]=[E],!0):0>u.indexOf(E)?(u.push(E),!0):!1}function f(f,
E){var u=this._listeners?this._listeners[f]:void 0;if(!u)return!1;u.forEach(function(b){b(E)});return!0}Y.exports={addEventListener:V,on:V,removeEventListener:function(f,E){var u,b;if(void 0===E||"function"!==typeof E||"string"!==typeof f)throw new TypeError("EventEmitter: removeEventListener requires a string and a function as arguments");if(void 0===this._listeners)return!1;b=this._listeners[f];if(void 0===b)return!1;u=b.indexOf(E);if(0>u)return!1;if(1===b.length)return delete this._listeners[f],
!0;b.splice(u,1);return!0},callEventListeners:f,emit:f,removeAllListeners:function(f){this._listeners&&(void 0===f?delete this._listeners:delete this._listeners[f]);return this}}},{}],8:[function(I,Y,fa){function V(f,E,u,b){f.trace(":",u,":",b);E(b)}function f(f){this.listeners=[];this.console=f}f.prototype.constructor=f;f.prototype.addEventListener=function(f,E,u,b){u=b?u.bind(b):u;b=!1;f&&(this.console&&(u=V.bind(null,this.console,u,E)),b=f.addEventListener(E,u),this.listeners.push([f,E,u]));return b};
f.prototype.on=f.prototype.addEventListener;f.prototype.clear=function(){var f=this.listeners.length;this.listeners.forEach(function(f){f[0].removeEventListener(f[1],f[2])});this.listeners=[];this.console&&this.console.trace("removed",f,"listener(s)")};Y.exports=f},{}],9:[function(I,Y,fa){Y.exports={EventEmitter:I("./event_emitter.js"),EventListenerGroup:I("./event_listener_group.js")}},{"./event_emitter.js":7,"./event_listener_group.js":8}],10:[function(I,Y,fa){var V;function f(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 z(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 E(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,g=0;g<a.length;++g){var f=a[g];if(d.equals&&"function"===typeof d.equals&&d.equals(f)||d==f){e=!0;break}}if(!e)return!1}return!0}function u(a,b){return E(a,b)&&(a.length==b.length||E(b,a))}function b(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(g){try{a.error(g)}catch(f){}}}function e(a,
c,d){if("object"!==typeof a||"function"!==typeof a.timeout)throw new TypeError("callback must be an object with function properties 'result', 'timeout', and 'error'.");b(a,c,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 wa(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}}var l=nrdp.btoa,ka=nrdp.atob,ja=nrdp.utf8toa,Da=nrdp.atoutf8,Ka=I("nf-promise"),O;(function(){function a(b){if(!b)throw new d;}function b(h,m){function n(a){a.hash&&!a.params&&(a.params={hash:a.hash.name})}if(102==h)return{process:function(a,b,h){k.exportKey(b.key,b.format,h)}};if(106==h)return{process:function(a,b,h){"raw"==b.format?k.aesUnwrap(b.buffer,b.algorithm,b.key,b.usages,h):k.unwrapJwe(b.buffer,b.key,b.algorithm,
b.extractable,b.usages,h)}};if(105==h)return{process:function(a,b,h){k.wrapJwe(b.wrappingKey,b.key,b.algorithm,k.A128GCM,h)}};if(101==h)return{process:function(a,b,h){k.importKey(b.buffer,b.format,b.algorithm,b.extractable,b.usages,h)}};if(500==h)return{process:function(a,b,h){k.getKeyByName(b.name,h)}};if(600==h)return{process:function(a,b,h){k.getKeyInfo(b.handle,h)}};switch(m.toUpperCase()){case "AES-CBC":return{process:function(a,b,h){switch(a){case 2:a=b.algorithm.params?b.algorithm.params.iv:
b.algorithm.iv;k.aesEncrypt(b.key,a,b.buffer,h);break;case 3:a=b.algorithm.params?b.algorithm.params.iv:b.algorithm.iv;k.aesDecrypt(b.key,a,b.buffer,h);break;case 103:k.symKeyGen(b.algorithm,b.extractable,b.usages,h);break;default:throw new d;}}};case "SHA-1":case "SHA-224":case "SHA-256":case "SHA-384":case "SHA-512":return{process:function(a,b,h){switch(a){case 1:k.digest(b.buffer,b.algorithm,h);break;default:throw new d;}}};case "RSASSA-PKCS1-V1_5":return{process:function(a,b,h){switch(a){case 4:n(b.algorithm);
k.rsaSign(b.key,b.buffer,b.algorithm,h);break;case 5:n(b.algorithm);k.rsaVerify(b.key,b.buffer,b.algorithm,b.signature,h);break;case 103:k.rsaKeyGen(b.algorithm,b.extractable,b.usages,h);break;default:throw new d;}}};case "RSA-OAEP":case "RSAES-PKCS1-V1_5":return{process:function(a,b,h){switch(a){case 2:k.rsaEncrypt(b.key,b.buffer,h);break;case 3:k.rsaDecrypt(b.key,b.buffer,h);break;case 103:k.rsaKeyGen(b.algorithm,b.extractable,b.usages,h);break;default:throw new d;}}};case "HMAC":return{process:function(a,
b,h){switch(a){case 4:n(b.algorithm);k.hmac(b.key,b.buffer,b.algorithm,h);break;case 5:n(b.algorithm);k.hmacVerify(b.key,b.buffer,b.algorithm,b.signature,h);break;case 103:k.symKeyGen(b.algorithm,b.extractable,b.usages,h);break;default:throw new d;}}};case "DH":return{process:function(a,b,h){switch(a){case 103:k.dhKeyGen(b.algorithm,b.extractable,b.usages,h);break;case 104:k.dhDerive(b.key,b.algorithm.params["public"],b.derivedAlgorithm,b.extractable,b.usages,h);break;default:throw new d;}}};case "NFLX-DH":return{process:function(b,
h,m){switch(b){case 103:k.dhKeyGen(h.algorithm,h.extractable,h.usages,m);break;case 104:a(k.nflxDhDerive);k.nflxDhDerive(h.key,h.algorithm.params["public"],Fa(h.algorithm.params.kd),function(a){function b(a,h){var k;a&&"object"===typeof a&&(k=a.algorithm,!k||"object"===typeof k&&!k.name)&&(t.warn("Patching algorithm for",a),a.algorithm=h,t.warn("  Key is now          ",a));return a}b(a.encryptionKey,{name:"AES-CBC"});b(a.hmacKey,{name:"HMAC",params:{hash:"SHA-256"}});b(a.wrappingKey,{name:"AES-KW"});
m(a)});break;default:throw new d;}}};case "AES-KW":return{process:function(a,b,h){switch(a){case 103:k.symKeyGen(b.algorithm,b.extractable,b.usages,h);break;default:throw new d;}}};case "NFLX-CDM-WIDEVINE":case "NFLX-CDM-JWELE":return{process:function(b,h,m){switch(b){case 103:k.symKeyGen(h.algorithm,h.extractable,h.usages,m);break;case 104:a(k.cdmDerive);k.cdmDerive(h.key,h.algorithm.params.cdmProvisionResponseData,h.algorithm.params.keKeyId,h.algorithm.params.khKeyId,m);break;default:throw new d;
}}};case "ECC":return{process:function(b,h,m){switch(b){case 4:a(k.eccSign);n(h.algorithm);k.eccSign(h.key,h.buffer,h.algorithm,m);break;default:throw new d;}}};case "NAGRA":return{process:function(b,h,m){switch(b){case 103:a(k.cdmKeyGen);k.cdmKeyGen(h.algorithm,h.extractable,h.usages,m);break;case 104:a(k.cdmDerive);k.cdmDerive(h.key,h.algorithm.params.cdmResponseData,h.algorithm.params.keKeyId,h.algorithm.params.khKeyId,m);break;case 4:a(k.cdmSign);n(h.algorithm);k.cdmSign(h.algorithm,h.buffer,
m);break;default:throw new d;}}};case "CMAC":return{process:function(b,h,m){switch(b){case 4:a(k.cmac);n(h.algorithm);k.cmac(h.key,h.algorithm,h.buffer,m);break;case 5:a(k.cmacVerify);n(h.algorithm);k.cmacVerify(h.key,h.algorithm,h.buffer,h.signature,m);break;default:throw new d;}}}}}function c(a){this.name="InvalidAlgorithmError";this.message=a||"Invalid algorithm"}function d(a){this.name="NotSupportedError";this.message=a||"Not supported"}function e(a){this.name="NotImplementedError";this.message=
a||"Not implemented yet"}function g(a,h){var k,m,n;if("string"==typeof h)return g(a,{name:h});if(h&&"object"==typeof h){k=h.name;if("string"!=typeof k)throw new c("Algorithm has bad or missing name");m=b(a,k);if(!m)throw t.error("Invalid WebCrypto algorithm",k),new c('Invalid algorithm "'+h.name+'"');n=h.params;if(void 0!==n&&(null===n||"object"!=typeof n))throw new c('Invalid algorithm parameters for "'+h.name+'", expecting undefined or an object');return{algorithm:{name:k,params:n},process:m.process}}throw new c("Invalid algorithm : "+
JSON.stringify(h));}function f(a){var b=y[a];if(void 0===b)throw new SyntaxError('Invalid key format "'+a+'"');return b}function l(a){return Array.isArray(a)?a.map(function(a){var b=F[a];if(void 0===b)throw new SyntaxError('Invalid key usage "'+a+'"');return b}):[]}function Fa(a){if(a&&"object"==typeof a&&1<=a.handle)return a.handle;throw new SyntaxError("Invalid key");}function ta(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 La(a,b,h,k){a._listeners=[];a._result=null;a._operation=b;a._args=h;a._info=k;switch(b){case 1:a._name="DIGEST";break;case 2:a._name="ENCRYPT";break;case 3:a._name="DECRYPT";break;case 4:a._name="SIGN";break;case 5:a._name="VERIFY";break;case 101:a._name="IMPORT_KEY";break;case 102:a._name="EXPORT_KEY";break;case 103:a._name="GENERATE_KEY";break;case 104:a._name="DERIVE_KEY";break;case 105:a._name="WRAP_KEY";break;case 106:a._name="UNWRAP_KEY";break;case 500:a._name="GET_KEY";break;case 600:a._name=
"KEY_INFO"}}function D(a,b,h){La(this,a,b,h)}function m(a,b,h){La(this,a,b,h)}function h(a){function b(a,h){var k=h;"object"==typeof h&&h&&h.byteLength?(k="["+h.byteLength+" bytes]",ta&&(k+="("+nrdp.btoa(h)+")")):"string"==typeof h&&"data"==a&&(k="["+h.length+" chars]",ta&&(k+="("+h+")"));return k}function h(b,k){var m,n=a._listeners.slice(0),q=n.length,p;for(m=0;m<q;++m)p=n[m],p.type==b&&p.callback(k)}function m(a){var b={handle:a.handle,extractable:a.extractable,algorithm:a.algorithm,name:a.name};
switch(a.type){case k.SECRET:b.type="secret";break;case k.PUBLIC:b.type="public";break;case k.PRIVATE:b.type="private"}b.keyUsage=a.usage.map(function(a){switch(a){case k.ENCRYPT:return"encrypt";case k.DECRYPT:return"decrypt";case k.SIGN:return"sign";case k.VERIFY:return"verify";case k.DERIVE:return"derive";case k.WRAP:return"wrap";case k.UNWRAP:return"unwrap"}});b.keyUsages=b.keyUsage;(a=b.algorithm)&&"object"===typeof a&&"HMAC"===a.name&&!a.params&&(t.warn("Changing HMAC algorithm for",b),a.params=
{hash:"SHA-256"},t.warn("  Key is now",b));return b}function D(a){switch(y){case 1:case 2:case 3:case 4:case 102:case 105:return a.data instanceof ArrayBuffer?new Uint8Array(a.data):q(a.data,!0);case 5:return a.verified?!0:!1;case 101:case 106:case 103:case 104:return a.key?m(a.key):a.encryptionKey&&a.hmacKey?{encryptionKey:m(a.encryptionKey),hmacKey:m(a.hmacKey),wrappingKey:a.wrappingKey?m(a.wrappingKey):void 0}:{publicKey:m(a.publickey),privateKey:m(a.privatekey)};case 500:case 600:return a.key?
m(a.key):null;default:throw new e;}}function c(a){t.error("FAILED "+d+"\n"+a);g.error=a;h("error",g)}var d=a._name,y=a._operation,F=a._info,La=a._args,g={target:a},Pa=nrdp.mono(),ta=U.webcryptoVerbose,W=ta||n.isDebug();p&&(p=!1,k.setBinary&&k.setBinary(!0));W&&t.trace("STARTING "+d+": "+JSON.stringify(La,b));a._result=null;try{F.process(y,La,function(k){try{t.trace("FINISHED "+d+" IN "+(nrdp.mono()-Pa)+" ms: ");W&&t.trace(JSON.stringify(k,b));if(!k.success)throw Error("WebCrypto operation "+d+" failed");
a._result=D(k);W&&t.trace("RESULT: "+JSON.stringify(a._result,b));h("complete",g)}catch(m){c(m)}})}catch(oa){setTimeout(function(){c(oa)},0)}return a}var k=nrdp.webcrypto,q=nrdp.atob,n=I("nf-console"),t=new n("CRYPTO"),U=I("nf-config"),p=!0,y={raw:k.RAW,pkcs8:k.PKCS8,spki:k.SPKI,jwk:k.JWK},F={encrypt:k.ENCRYPT,decrypt:k.DECRYPT,sign:k.SIGN,verify:k.VERIFY,derive:k.DERIVE,deriveKey:k.DERIVE,wrap:k.WRAP,unwrap:k.UNWRAP};U.declare({webcryptoVerbose:["webcryptoVerbose",!1]});c.prototype=Error();c.prototype.constructor=
c;d.prototype=Error();d.prototype.constructor=d;e.prototype=Error();e.prototype.constructor=e;D.prototype.constructor=D;D.prototype.addEventListener=function(a,b){this._listeners.push({type:a,callback:b})};D.prototype.removeEventListener=function(a,b){this._listeners=this._listeners.filter(function(h){return!(h.type==a&&h.callback==b)})};Object.defineProperties(D.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)}}});m.prototype=new D;m.prototype.constructor=m;m.prototype.process=function(a){throw new e("process not supported on CryptoOperation");};m.prototype.finish=function(){throw new e("finish not supported on CryptoOperation");};m.prototype.abort=function(){throw new e("abort not supported on CryptoOperation");};Object.defineProperties(m.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)}}});O={getRandomValues:function(a){nrdp.random(a);return a},getKeyByName:function(a){var k=b(500);return h(new D(500,{name:a},k))},getKeyInfo:function(a){var k=b(600);return h(new D(600,{handle:a},k))},digest:function(a,b){var k=g(1,a),n={algorithm:a,buffer:ta(b)};
return h(new m(1,n,k))},encrypt:function(a,b,k){var n=g(2,a);a={algorithm:a,key:Fa(b),buffer:ta(k)};return h(new m(2,a,n))},decrypt:function(a,b,k){var n=g(3,a);a={algorithm:a,key:Fa(b),buffer:ta(k)};return h(new m(3,a,n))},sign:function(a,b,k){var n=g(4,a);a={algorithm:a,key:Fa(b),buffer:ta(k)};return h(new m(4,a,n))},verify:function(a,b,k,n){var q=g(5,a);a={algorithm:a,key:Fa(b),signature:ta(k),buffer:ta(n)};return h(new m(5,a,q))},importKey:function(a,b,k,m,n){var q=g(101,k);a={format:f(a),buffer:ta(b),
algorithm:k,extractable:m?!0:!1,usages:l(n)};return h(new D(101,a,q))},exportKey:function(a,k){var m=b(102),n={format:f(a),key:Fa(k)};return h(new D(102,n,m))},generateKey:function(a,b,k){var m=g(103,a);a={algorithm:a,extractable:b?!0:!1,usages:l(k)};return h(new D(103,a,m))},deriveKey:function(a,b,k,m,n){var q=g(104,a);a={algorithm:a,key:Fa(b),derivedAlgorithm:k,extractable:m,usages:l(n)};return h(new D(104,a,q))},wrapKey:function(a,b,k){var m=g(105,k);a={algorithm:k,key:Fa(a),wrappingKey:Fa(b)};
return h(new D(105,a,m))},unwrapKey:function(a,k,m,n,q,p){var t=b(106);a={algorithm:k,buffer:ta(a),key:Fa(m),extractable:n?!0:!1,usages:l(q),format:p};return h(new D(106,a,t))}};O.subtle=O})();var N=function(a){return ka(a,!0)},Ia=O.subtle,qa=function(a,b){if(!b||"utf-8"===b)return ja(a);throw Error("unsupported encoding");},sa=function(a,b){if(!b||"utf-8"===b)return Da(a);throw Error("unsupported encoding");},Bb=function(a){return ja(a)},nb=function(a){return nrdp.compress(a,"gzip",!0)},Na=function(a){return nrdp.uncompress(a,
"gzip",!0)},P,R,zb,Ta,Ua,L,ia,Vb,aa,Ma,mb,Qa,jb,c;(function(){P="utf-8";R=9007199254740992;zb=12;var a=Ta={GZIP:"GZIP",LZW:"LZW"};Object.freeze(Ta);Ua=function(b){for(var c=[a.GZIP,a.LZW],d=0;d<c.length&&0<b.length;++d)for(var e=c[d],g=0;g<b.length;++g)if(b[g]==e)return e;return null};var b=L={AES:"AES"};Object.freeze(L);ia=function(a){var c=a;"string"===typeof a&&(c=a.toLowerCase());"object"===typeof a&&"string"===typeof a.name&&(c=a.name.toLowerCase());return da.AES_CBC.name.toLowerCase()==c?b.AES:
b[a]};Vb=function(a){if(b.AES==a)return da.AES_CBC};var d=aa={AES_CBC_PKCS5Padding:"AES/CBC/PKCS5Padding",AESWrap:"AESWrap",RSA_ECB_PKCS1Padding:"RSA/ECB/PKCS1Padding"};Object.freeze(aa);Ma=function(a){return d.AES_CBC_PKCS5Padding==a?d.AES_CBC_PKCS5Padding:d.RSA_ECB_PKCS1Padding==a?d.RSA_ECB_PKCS1Padding:d[a]};var e=mb={HmacSHA256:"HmacSHA256",SHA256withRSA:"SHA256withRSA",AESCmac:"AESCmac"};Object.freeze(mb);Qa=function(a){var b=a;"string"===typeof a&&(b=a.toLowerCase());"object"===typeof a&&"string"===
typeof a.name&&(b=a.name.toLowerCase());var c=void 0;"object"===typeof a.hash&&(c=a.hash.name.toLowerCase());return da.HMAC_SHA256.name.toLowerCase()==b&&da.HMAC_SHA256.hash.name.toLowerCase()==c?e.HmacSHA256:da.RSASSA_SHA256.name.toLowerCase()==b&&da.RSASSA_SHA256.hash.name.toLowerCase()==c?e.SHA256withRSA:da.AES_CMAC.name.toLowerCase()==b?e.AESCmac:e[a]};jb=function(a){if(e.HmacSHA256==a)return da.HMAC_SHA256;if(e.SHA256withRSA==a)return da.SHA256withRSA;if(e.AESCmac==a)return da.AES_CMAC};c={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(c)})();var J={isObjectLiteral:function(a){return null!==a&&"object"===typeof a&&a.constructor===Object},extendDeep:function(){var a=arguments[0],b=1,c=arguments.length,d=!1,e,g,f,l;"boolean"===typeof a&&(d=a,a=arguments[1],b=2);for(;b<c;b++)if(null!=(e=arguments[b]))for(g in e)d&&g in a||(l=e[g],a!==l&&void 0!==l&&(f=a[g],a[g]=null!==f&&null!==
l&&"object"===typeof f&&"object"===typeof l?J.extendDeep(d,{},f,l):l));return a}};(function(){function a(b,c){return function(){var a=b.base,D;b.base=c;D=b.apply(this,arguments);b.base=a;return D}}function b(c,d,e){var D,m,h,k;e=e||l;k=!!e.extendAll;for(D in d)m=d.__lookupGetter__(D),h=d.__lookupSetter__(D),m||h?(m&&c.__defineGetter__(D,m),h&&c.__defineSetter__(D,h)):(m=d[D],h=c[D],"function"===typeof m&&"function"===typeof h&&m!==h?(m.base!==Function.prototype.base&&(m=a(m,h)),m.base=h):(k||e[D])&&
J.isObjectLiteral(m)&&J.isObjectLiteral(h)&&(m=J.extendDeep({},h,m)),c[D]=m)}function c(){var a=Array.prototype.slice,b=a.call(arguments,1);return this.extend({init:function D(){var m=a.call(arguments,0);D.base.apply(this,b.concat(m))}})}function d(a,c){var e=new this(f);b(e,a,c);return g(e)}function e(a,c){b(this.prototype,a,c);return this}function g(a){var b=function(){var a=this.init;a&&arguments[0]!==f&&a.apply(this,arguments)};a&&(b.prototype=a);b.prototype.constructor=b;b.extend=d;b.bind=c;
b.mixin=e;return b}var f={},l={actions:!0};Function.prototype.base=function(){};J.Class={create:g,mixin:b,extend:function(a,b){var c=g();c.prototype=new a;return c.extend(b)}};J.mixin=function(){J.log&&J.log.warn("util.mixin is deprecated.  Please change your code to use util.Class.mixin()");b.apply(null,arguments)}})();(function(){function a(b,c){return function(){var a=b.base,m;b.base=c;m=b.apply(this,arguments);b.base=a;return m}}function b(c,d,D){var m,h,k,q;D=D||l;q=!!D.extendAll;for(m in d)h=
d.__lookupGetter__(m),k=d.__lookupSetter__(m),h||k?(h&&c.__defineGetter__(m,h),k&&c.__defineSetter__(m,k)):(h=d[m],k=c[m],"function"===typeof h&&"function"===typeof k&&h!==k?(h.base!==r&&(h=a(h,k)),h.base=k):(q||D[m])&&J.isObjectLiteral(h)&&J.isObjectLiteral(k)&&(h=J.extendDeep({},k,h)),c[m]=h)}function c(){var a=Array.prototype.slice,b=a.call(arguments,1);return this.extend({init:function m(){var h=a.call(arguments,0);m.base.apply(this,b.concat(h))}})}function d(a,c){var D=new this(f);b(D,a,c);return g(D)}
function e(a,c){b(this.prototype,a,c);return this}function g(a){var b=function(){var a=this.init;a&&arguments[0]!==f&&a.apply(this,arguments)};a&&(b.prototype=a);b.prototype.constructor=b;b.extend=d;b.bind=c;b.mixin=e;return b}var f={},l={actions:!0},r=function(){};Function.prototype.base=r;J.Class={create:g,mixin:b,extend:function(a,b){var c=g();c.prototype=new a;return c.extend(b)}};J.mixin=function(){J.log&&J.log.warn("util.mixin is deprecated.  Please change your code to use util.Class.mixin()");
b.apply(null,arguments)}})();var K;(function(){function a(b){return b==R?1:b+1}function b(c){if(0===Object.keys(c._waiters).length)return 0;for(var d=a(c._nextWaiter);!c._waiters[d];)d=a(d);return d}K=J.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(a){if(this._waiters[a]){var c=this._waiters[a];delete this._waiters[a];a==this._nextWaiter&&(this._nextWaiter=b(this));c.call(this,void 0)}},cancelAll:function(){for(;0!==this._nextWaiter;)this.cancel(this._nextWaiter)},poll:function(c,d){var g=this,f=a(this._lastWaiter);this._lastWaiter=f;e(d,function(){if(0<this._queue.length){var a=this._queue.shift();setTimeout(function(){d.result(a)},0)}else{var e;-1!=c&&(e=setTimeout(function(){delete g._waiters[f];f==g._nextWaiter&&(g._nextWaiter=
b(g));d.timeout()},c));this._waiters[f]=function(a){clearTimeout(e);setTimeout(function(){d.result(a)},0)};this._nextWaiter||(this._nextWaiter=f)}},g);return f},add:function(a){if(this._nextWaiter){var c=this._waiters[this._nextWaiter];delete this._waiters[this._nextWaiter];this._nextWaiter=b(this);c.call(this,a)}else this._queue.push(a)}})})();var Ja,Oa;(function(){var a=0-R,b;"undefined"!==typeof window&&(b=window.msCrypto||window.crypto);Oa=function(a){b=a};Ja=J.Class.create({nextBoolean:function(){var a=
new Uint8Array(1);b.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;var c=new Uint8Array(4);b.getRandomValues(c);return Math.floor(((c[3]&127)<<24|c[2]<<16|c[1]<<8|c[0])/2147483648*(a-0+1)+0)}a=new Uint8Array(4);b.getRandomValues(a);c=(a[3]&127)<<24|a[2]<<16|a[1]<<8|a[0];return a[3]&128?-c:c},nextLong:function(){for(var c=a;c==a;){c=
new Uint8Array(7);b.getRandomValues(c);var d=16777216*((c[6]&31)<<24|c[5]<<16|c[4]<<8|c[3])+(c[2]<<16|c[1]<<8|c[0]),c=c[6]&128?-d-1:d}return c},nextBytes:function(a){for(var c=0;;){var d=Math.min(65536,a.length-c);if(0==d)break;var e=new Uint8Array(d);b.getRandomValues(e);a.set(e,c);c+=d}}})})();var Ra;(function(){function a(b){return b==R?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}Ra=J.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 g=this,f=a(this._lastNumber);this._lastNumber=f;e(d,function(){if(!this._writer&&0===Object.keys(this._waitingWriters).length)return this._readers[f]=!0,f;var a;-1!=c&&(a=setTimeout(function(){delete g._waitingReaders[f];f==g._nextReader&&(g._nextReader=b(g));d.timeout()},c));this._waitingReaders[f]=function(b){clearTimeout(a);b?setTimeout(function(){d.result(void 0)},0):(g._readers[f]=!0,setTimeout(function(){d.result(f)},
0))};this._nextReader||(this._nextReader=f)},g);return f},writeLock:function(b,d){var g=this,f=a(this._lastNumber);this._lastNumber=f;e(d,function(){if(0===Object.keys(this._readers).length&&0===Object.keys(this._waitingReaders).length&&!this._writer)return this._writer=f;var a;-1!=b&&(a=setTimeout(function(){delete g._waitingWriters[f];f==g._nextWriter&&(g._nextWriter=c(g));d.timeout()},b));this._waitingWriters[f]=function(b){clearTimeout(a);b?setTimeout(function(){d.result(void 0)},0):(g._writer=
f,setTimeout(function(){d.result(f)},0))};this._nextWriter||(this._nextWriter=f)},g);return f},unlock:function(b){if(b==this._writer)this._writer=null;else{if(!this._readers[b])throw new x("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}}})})();J.Class.mixin(a,{JSON_PARSE_ERROR:new a(0,c.FAIL,"Error parsing JSON."),JSON_ENCODE_ERROR:new a(1,c.FAIL,"Error encoding JSON."),ENVELOPE_HASH_MISMATCH:new a(2,c.FAIL,"Computed hash does not match envelope hash."),INVALID_PUBLIC_KEY:new a(3,c.FAIL,"Invalid public key provided."),INVALID_PRIVATE_KEY:new a(4,c.FAIL,"Invalid private key provided."),PLAINTEXT_ILLEGAL_BLOCK_SIZE:new a(5,
c.FAIL,"Plaintext is not a multiple of the block size."),PLAINTEXT_BAD_PADDING:new a(6,c.FAIL,"Plaintext contains incorrect padding."),CIPHERTEXT_ILLEGAL_BLOCK_SIZE:new a(7,c.FAIL,"Ciphertext is not a multiple of the block size."),CIPHERTEXT_BAD_PADDING:new a(8,c.FAIL,"Ciphertext contains incorrect padding."),ENCRYPT_NOT_SUPPORTED:new a(9,c.FAIL,"Encryption not supported."),DECRYPT_NOT_SUPPORTED:new a(10,c.FAIL,"Decryption not supported."),ENVELOPE_KEY_ID_MISMATCH:new a(11,c.FAIL,"Encryption envelope key ID does not match crypto context key ID."),
CIPHERTEXT_ENVELOPE_PARSE_ERROR:new a(12,c.FAIL,"Error parsing ciphertext envelope."),CIPHERTEXT_ENVELOPE_ENCODE_ERROR:new a(13,c.FAIL,"Error encoding ciphertext envelope."),SIGN_NOT_SUPPORTED:new a(14,c.FAIL,"Sign not supported."),VERIFY_NOT_SUPPORTED:new a(15,c.FAIL,"Verify not suppoprted."),SIGNATURE_ERROR:new a(16,c.FAIL,"Signature not initialized or unable to process data/signature."),HMAC_ERROR:new a(17,c.FAIL,"Error computing HMAC."),ENCRYPT_ERROR:new a(18,c.FAIL,"Error encrypting plaintext."),
DECRYPT_ERROR:new a(19,c.FAIL,"Error decrypting ciphertext."),INSUFFICIENT_CIPHERTEXT:new a(20,c.FAIL,"Insufficient ciphertext for decryption."),SESSION_KEY_CREATION_FAILURE:new a(21,c.FAIL,"Error when creating session keys."),INVALID_SYMMETRIC_KEY:new a(24,c.FAIL,"Invalid symmetric key provided."),INVALID_ENCRYPTION_KEY:new a(25,c.FAIL,"Invalid encryption key."),INVALID_HMAC_KEY:new a(26,c.FAIL,"Invalid HMAC key."),WRAP_NOT_SUPPORTED:new a(27,c.FAIL,"Wrap not supported."),UNWRAP_NOT_SUPPORTED:new a(28,
c.FAIL,"Unwrap not supported."),UNIDENTIFIED_JWK_TYPE:new a(29,c.FAIL,"Unidentified JSON web key type."),UNIDENTIFIED_JWK_USAGE:new a(30,c.FAIL,"Unidentified JSON web key usage."),UNIDENTIFIED_JWK_ALGORITHM:new a(31,c.FAIL,"Unidentified JSON web key algorithm."),WRAP_ERROR:new a(32,c.FAIL,"Error wrapping plaintext."),UNWRAP_ERROR:new a(33,c.FAIL,"Error unwrapping ciphertext."),INVALID_JWK:new a(34,c.FAIL,"Invalid JSON web key."),INVALID_JWK_KEYDATA:new a(35,c.FAIL,"Invalid JSON web key keydata."),
UNSUPPORTED_JWK_ALGORITHM:new a(36,c.FAIL,"Unsupported JSON web key algorithm."),WRAP_KEY_CREATION_FAILURE:new a(37,c.FAIL,"Error when creating wrapping key."),INVALID_WRAP_CIPHERTEXT:new a(38,c.FAIL,"Invalid wrap ciphertext."),UNSUPPORTED_JWE_ALGORITHM:new a(39,c.FAIL,"Unsupported JSON web encryption algorithm."),JWE_ENCODE_ERROR:new a(40,c.FAIL,"Error encoding JSON web encryption header."),JWE_PARSE_ERROR:new a(41,c.FAIL,"Error parsing JSON web encryption header."),INVALID_ALGORITHM_PARAMS:new a(42,
c.FAIL,"Invalid algorithm parameters."),JWE_ALGORITHM_MISMATCH:new a(43,c.FAIL,"JSON web encryption header algorithms mismatch."),KEY_IMPORT_ERROR:new a(44,c.FAIL,"Error importing key."),KEY_EXPORT_ERROR:new a(45,c.FAIL,"Error exporting key."),DIGEST_ERROR:new a(46,c.FAIL,"Error in digest."),UNSUPPORTED_KEY:new a(47,c.FAIL,"Unsupported key type or algorithm."),UNSUPPORTED_JWE_SERIALIZATION:new a(48,c.FAIL,"Unsupported JSON web encryption serialization."),INVALID_WRAPPING_KEY:new a(51,c.FAIL,"Invalid wrapping key."),
UNIDENTIFIED_CIPHERTEXT_ENVELOPE:new a(52,c.FAIL,"Unidentified ciphertext envelope version."),UNIDENTIFIED_SIGNATURE_ENVELOPE:new a(53,c.FAIL,"Unidentified signature envelope version."),UNSUPPORTED_CIPHERTEXT_ENVELOPE:new a(54,c.FAIL,"Unsupported ciphertext envelope version."),UNSUPPORTED_SIGNATURE_ENVELOPE:new a(55,c.FAIL,"Unsupported signature envelope version."),UNIDENTIFIED_CIPHERSPEC:new a(56,c.FAIL,"Unidentified cipher specification."),UNIDENTIFIED_ALGORITHM:new a(57,c.FAIL,"Unidentified algorithm."),
SIGNATURE_ENVELOPE_PARSE_ERROR:new a(58,c.FAIL,"Error parsing signature envelope."),SIGNATURE_ENVELOPE_ENCODE_ERROR:new a(59,c.FAIL,"Error encoding signature envelope."),INVALID_SIGNATURE:new a(60,c.FAIL,"Invalid signature."),DERIVEKEY_ERROR:new a(61,c.FAIL,"Error deriving key."),UNIDENTIFIED_JWK_KEYOP:new a(62,c.FAIL,"Unidentified JSON web key key operation."),GENERATEKEY_ERROR:new a(63,c.FAIL,"Error generating key."),INVALID_IV:new a(64,c.FAIL,"Invalid initialization vector."),INVALID_CIPHERTEXT:new a(65,
c.FAIL,"Invalid ciphertext."),MASTERTOKEN_UNTRUSTED:new a(1E3,c.ENTITY_REAUTH,"Master token is not trusted."),MASTERTOKEN_KEY_CREATION_ERROR:new a(1001,c.ENTITY_REAUTH,"Unable to construct symmetric keys from master token."),MASTERTOKEN_EXPIRES_BEFORE_RENEWAL:new a(1002,c.ENTITY_REAUTH,"Master token expiration timestamp is before the renewal window opens."),MASTERTOKEN_SESSIONDATA_MISSING:new a(1003,c.ENTITY_REAUTH,"No master token session data found."),MASTERTOKEN_SEQUENCE_NUMBER_OUT_OF_RANGE:new a(1004,
c.ENTITY_REAUTH,"Master token sequence number is out of range."),MASTERTOKEN_SERIAL_NUMBER_OUT_OF_RANGE:new a(1005,c.ENTITY_REAUTH,"Master token serial number is out of range."),MASTERTOKEN_TOKENDATA_INVALID:new a(1006,c.ENTITY_REAUTH,"Invalid master token data."),MASTERTOKEN_SIGNATURE_INVALID:new a(1007,c.ENTITY_REAUTH,"Invalid master token signature."),MASTERTOKEN_SESSIONDATA_INVALID:new a(1008,c.ENTITY_REAUTH,"Invalid master token session data."),MASTERTOKEN_SEQUENCE_NUMBER_OUT_OF_SYNC:new a(1009,
c.ENTITY_REAUTH,"Master token sequence number does not have the expected value."),MASTERTOKEN_TOKENDATA_MISSING:new a(1010,c.ENTITY_REAUTH,"No master token data found."),MASTERTOKEN_TOKENDATA_PARSE_ERROR:new a(1011,c.ENTITY_REAUTH,"Error parsing master token data."),MASTERTOKEN_SESSIONDATA_PARSE_ERROR:new a(1012,c.ENTITY_REAUTH,"Error parsing master token session data."),MASTERTOKEN_IDENTITY_REVOKED:new a(1013,c.ENTITY_REAUTH,"Master token entity identity is revoked."),MASTERTOKEN_REJECTED_BY_APP:new a(1014,
c.ENTITY_REAUTH,"Master token is rejected by the application."),USERIDTOKEN_MASTERTOKEN_MISMATCH:new a(2E3,c.USER_REAUTH,"User ID token master token serial number does not match master token serial number."),USERIDTOKEN_NOT_DECRYPTED:new a(2001,c.USER_REAUTH,"User ID token is not decrypted or verified."),USERIDTOKEN_MASTERTOKEN_NULL:new a(2002,c.USER_REAUTH,"User ID token requires a master token."),USERIDTOKEN_EXPIRES_BEFORE_RENEWAL:new a(2003,c.USER_REAUTH,"User ID token expiration timestamp is before the renewal window opens."),
USERIDTOKEN_USERDATA_MISSING:new a(2004,c.USER_REAUTH,"No user ID token user data found."),USERIDTOKEN_MASTERTOKEN_NOT_FOUND:new a(2005,c.USER_REAUTH,"User ID token is bound to an unknown master token."),USERIDTOKEN_MASTERTOKEN_SERIAL_NUMBER_OUT_OF_RANGE:new a(2006,c.USER_REAUTH,"User ID token master token serial number is out of range."),USERIDTOKEN_SERIAL_NUMBER_OUT_OF_RANGE:new a(2007,c.USER_REAUTH,"User ID token serial number is out of range."),USERIDTOKEN_TOKENDATA_INVALID:new a(2008,c.USER_REAUTH,
"Invalid user ID token data."),USERIDTOKEN_SIGNATURE_INVALID:new a(2009,c.USER_REAUTH,"Invalid user ID token signature."),USERIDTOKEN_USERDATA_INVALID:new a(2010,c.USER_REAUTH,"Invalid user ID token user data."),USERIDTOKEN_IDENTITY_INVALID:new a(2011,c.USER_REAUTH,"Invalid user ID token user identity."),RESERVED_2012:new a(2012,c.USER_REAUTH,"The entity is not associated with the user."),USERIDTOKEN_IDENTITY_NOT_FOUND:new a(2013,c.USER_REAUTH,"The user identity was not found."),USERIDTOKEN_PASSWORD_VERSION_CHANGED:new a(2014,
c.USER_REAUTH,"The user identity must be reauthenticated because the password version changed."),USERIDTOKEN_USERAUTH_DATA_MISMATCH:new a(2015,c.USER_REAUTH,"The user ID token and user authentication data user identities do not match."),USERIDTOKEN_TOKENDATA_MISSING:new a(2016,c.USER_REAUTH,"No user ID token data found."),USERIDTOKEN_TOKENDATA_PARSE_ERROR:new a(2017,c.USER_REAUTH,"Error parsing user ID token data."),USERIDTOKEN_USERDATA_PARSE_ERROR:new a(2018,c.USER_REAUTH,"Error parsing user ID token user data."),
USERIDTOKEN_REVOKED:new a(2019,c.USER_REAUTH,"User ID token is revoked."),USERIDTOKEN_REJECTED_BY_APP:new a(2020,c.USERDATA_REAUTH,"User ID token is rejected by the application."),SERVICETOKEN_MASTERTOKEN_MISMATCH:new a(3E3,c.FAIL,"Service token master token serial number does not match master token serial number."),SERVICETOKEN_USERIDTOKEN_MISMATCH:new a(3001,c.FAIL,"Service token user ID token serial number does not match user ID token serial number."),SERVICETOKEN_SERVICEDATA_INVALID:new a(3002,
c.FAIL,"Service token data invalid."),SERVICETOKEN_MASTERTOKEN_NOT_FOUND:new a(3003,c.FAIL,"Service token is bound to an unknown master token."),SERVICETOKEN_USERIDTOKEN_NOT_FOUND:new a(3004,c.FAIL,"Service token is bound to an unknown user ID token."),SERVICETOKEN_MASTERTOKEN_SERIAL_NUMBER_OUT_OF_RANGE:new a(3005,c.FAIL,"Service token master token serial number is out of range."),SERVICETOKEN_USERIDTOKEN_SERIAL_NUMBER_OUT_OF_RANGE:new a(3006,c.FAIL,"Service token user ID token serial number is out of range."),
SERVICETOKEN_TOKENDATA_INVALID:new a(3007,c.FAIL,"Invalid service token data."),SERVICETOKEN_SIGNATURE_INVALID:new a(3008,c.FAIL,"Invalid service token signature."),SERVICETOKEN_TOKENDATA_MISSING:new a(3009,c.FAIL,"No service token data found."),UNIDENTIFIED_ENTITYAUTH_SCHEME:new a(4E3,c.FAIL,"Unable to identify entity authentication scheme."),ENTITYAUTH_FACTORY_NOT_FOUND:new a(4001,c.FAIL,"No factory registered for entity authentication scheme."),X509CERT_PARSE_ERROR:new a(4002,c.ENTITYDATA_REAUTH,
"Error parsing X.509 certificate data."),X509CERT_ENCODE_ERROR:new a(4003,c.ENTITYDATA_REAUTH,"Error encoding X.509 certificate data."),X509CERT_VERIFICATION_FAILED:new a(4004,c.ENTITYDATA_REAUTH,"X.509 certificate verification failed."),ENTITY_NOT_FOUND:new a(4005,c.FAIL,"Entity not recognized."),INCORRECT_ENTITYAUTH_DATA:new a(4006,c.FAIL,"Entity used incorrect entity authentication data type."),RSA_PUBLICKEY_NOT_FOUND:new a(4007,c.ENTITYDATA_REAUTH,"RSA public key not found."),UNSUPPORTED_ENTITYAUTH_DATA:new a(4023,
c.FAIL,"Unsupported entity authentication data."),ENTITY_REVOKED:new a(4025,c.FAIL,"Entity is revoked."),ENTITY_REJECTED_BY_APP:new a(4026,c.ENTITYDATA_REAUTH,"Entity is rejected by the application."),X509CERT_EXPIRED:new a(4028,c.ENTITYDATA_REAUTH,"X.509 certificate is expired."),X509CERT_NOT_YET_VALID:new a(4029,c.ENTITYDATA_REAUTH,"X.509 certificate is not yet valid."),X509CERT_INVALID:new a(4030,c.ENTITYDATA_REAUTH,"X.509 certificate is invalid."),RSA_PRIVATEKEY_NOT_FOUND:new a(4031,c.ENTITYDATA_REAUTH,
"RSA private key not found."),ENTITYAUTH_MASTERTOKEN_NOT_DECRYPTED:new a(4032,c.FAIL,"Entity authentication data master token is not decrypted or verified."),ENTITYAUTH_SIGNATURE_INVALID:new a(4033,c.ENTITYDATA_REAUTH,"Invalid entity authentication data siganture."),ENTITYAUTH_CIPHERTEXT_INVALID:new a(4034,c.ENTITYDATA_REAUTH,"Invalid entity authentication data ciphertext."),ENTITYAUTH_VERIFICATION_FAILED:new a(4035,c.ENTITYDATA_REAUTH,"Entity authentication data signature verification failed."),
ENTITYAUTH_MASTERTOKEN_INVALID:new a(4036,c.FAIL,"Invalid entity authentication data master token."),UNIDENTIFIED_USERAUTH_SCHEME:new a(5003,c.FAIL,"Unable to identify user authentication scheme."),USERAUTH_FACTORY_NOT_FOUND:new a(5004,c.FAIL,"No factory registered for user authentication scheme."),EMAILPASSWORD_BLANK:new a(5005,c.USERDATA_REAUTH,"Email or password is blank."),EMAILPASSWORD_INCORRECT:new a(5007,c.USERDATA_REAUTH,"Email or password is incorrect."),UNSUPPORTED_USERAUTH_DATA:new a(5008,
c.FAIL,"Unsupported user authentication data."),USERAUTH_USERIDTOKEN_INVALID:new a(5011,c.USERDATA_REAUTH,"User authentication data user ID token is invalid."),UNIDENTIFIED_USERAUTH_MECHANISM:new a(5013,c.FAIL,"Unable to identify user authentication mechanism."),UNSUPPORTED_USERAUTH_MECHANISM:new a(5014,c.FAIL,"Unsupported user authentication mechanism."),USERAUTH_MASTERTOKEN_MISSING:new a(5016,c.USERDATA_REAUTH,"User authentication required master token is missing."),USERAUTH_USERIDTOKEN_NOT_DECRYPTED:new a(5021,
c.USERDATA_REAUTH,"User authentication data user ID token is not decrypted or verified."),USERAUTH_MASTERTOKEN_INVALID:new a(5024,c.USERDATA_REAUTH,"User authentication data master token is invalid."),USERAUTH_MASTERTOKEN_NOT_DECRYPTED:new a(5025,c.USERDATA_REAUTH,"User authentication data master token is not decrypted or verified."),USERAUTH_USERIDTOKEN_MISSING:new a(5030,c.USERDATA_REAUTH,"User authentication required user ID token is missing."),USERAUTH_ENTITY_MISMATCH:new a(5032,c.USERDATA_REAUTH,
"User authentication data does not match entity identity."),USERAUTH_ENTITY_INCORRECT_DATA:new a(5033,c.FAIL,"Entity used incorrect user authentication data type."),USER_REJECTED_BY_APP:new a(5037,c.USERDATA_REAUTH,"User is rejected by the application."),USERIDTOKEN_IDENTITY_NOT_ASSOCIATED_WITH_ENTITY:new a(5040,c.USER_REAUTH,"The entity is not associated with the user."),USERAUTH_ENTITYUSER_INCORRECT_DATA:new a(5041,c.USERDATA_REAUTH,"Entity and user combination used incorrect user authentication data type."),
UNSUPPORTED_COMPRESSION:new a(6E3,c.FAIL,"Unsupported compression algorithm."),COMPRESSION_ERROR:new a(6001,c.FAIL,"Error compressing data."),UNCOMPRESSION_ERROR:new a(6002,c.FAIL,"Error uncompressing data."),MESSAGE_ENTITY_NOT_FOUND:new a(6003,c.FAIL,"Message header entity authentication data or master token not found."),PAYLOAD_MESSAGE_ID_MISMATCH:new a(6004,c.FAIL,"Payload chunk message ID does not match header message ID ."),PAYLOAD_SEQUENCE_NUMBER_MISMATCH:new a(6005,c.FAIL,"Payload chunk sequence number does not match expected sequence number."),
PAYLOAD_VERIFICATION_FAILED:new a(6006,c.FAIL,"Payload chunk payload signature verification failed."),MESSAGE_DATA_MISSING:new a(6007,c.FAIL,"No message data found."),MESSAGE_FORMAT_ERROR:new a(6008,c.FAIL,"Malformed message data."),MESSAGE_VERIFICATION_FAILED:new a(6009,c.FAIL,"Message header/error data signature verification failed."),HEADER_DATA_MISSING:new a(6010,c.FAIL,"No header data found."),PAYLOAD_DATA_MISSING:new a(6011,c.FAIL,"No payload data found in non-EOM payload chunk."),PAYLOAD_DATA_CORRUPT:new a(6012,
c.FAIL,"Corrupt payload data found in non-EOM payload chunk."),UNIDENTIFIED_COMPRESSION:new a(6013,c.FAIL,"Unidentified compression algorithm."),MESSAGE_EXPIRED:new a(6014,c.EXPIRED,"Message expired and not renewable. Rejected."),MESSAGE_ID_OUT_OF_RANGE:new a(6015,c.FAIL,"Message ID is out of range."),INTERNAL_CODE_NEGATIVE:new a(6016,c.FAIL,"Error header internal code is negative."),UNEXPECTED_RESPONSE_MESSAGE_ID:new a(6017,c.FAIL,"Unexpected response message ID. Possible replay."),RESPONSE_REQUIRES_ENCRYPTION:new a(6018,
c.KEYX_REQUIRED,"Message response requires encryption."),PAYLOAD_SEQUENCE_NUMBER_OUT_OF_RANGE:new a(6019,c.FAIL,"Payload chunk sequence number is out of range."),PAYLOAD_MESSAGE_ID_OUT_OF_RANGE:new a(6020,c.FAIL,"Payload chunk message ID is out of range."),MESSAGE_REPLAYED:new a(6021,c.REPLAYED,"Non-replayable message replayed."),INCOMPLETE_NONREPLAYABLE_MESSAGE:new a(6022,c.FAIL,"Non-replayable message sent without a master token."),HEADER_SIGNATURE_INVALID:new a(6023,c.FAIL,"Invalid Header signature."),
HEADER_DATA_INVALID:new a(6024,c.FAIL,"Invalid header data."),PAYLOAD_INVALID:new a(6025,c.FAIL,"Invalid payload."),PAYLOAD_SIGNATURE_INVALID:new a(6026,c.FAIL,"Invalid payload signature."),RESPONSE_REQUIRES_MASTERTOKEN:new a(6027,c.KEYX_REQUIRED,"Message response requires a master token."),RESPONSE_REQUIRES_USERIDTOKEN:new a(6028,c.USER_REAUTH,"Message response requires a user ID token."),REQUEST_REQUIRES_USERAUTHDATA:new a(6029,c.FAIL,"User-associated message requires user authentication data."),
UNEXPECTED_MESSAGE_SENDER:new a(6030,c.FAIL,"Message sender is equal to the local entity or not the master token entity."),NONREPLAYABLE_MESSAGE_REQUIRES_MASTERTOKEN:new a(6031,c.FAIL,"Non-replayable message requires a master token."),NONREPLAYABLE_ID_OUT_OF_RANGE:new a(6032,c.FAIL,"Non-replayable message non-replayable ID is out of range."),MESSAGE_SERVICETOKEN_MISMATCH:new a(6033,c.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,c.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,c.KEYX_REQUIRED,"Message response requires integrity protection."),HANDSHAKE_DATA_MISSING:new a(6036,c.FAIL,"Handshake message is not renewable or does not contain key request data."),MESSAGE_RECIPIENT_MISMATCH:new a(6037,c.FAIL,"Message recipient does not match local identity."),
MESSAGE_ENTITYDATABASED_VERIFICATION_FAILED:new a(6038,c.ENTITYDATA_REAUTH,"Message header entity-based signature verification failed."),MESSAGE_MASTERTOKENBASED_VERIFICATION_FAILED:new a(6039,c.ENTITY_REAUTH,"Message header master token-based signature verification failed."),MESSAGE_REPLAYED_UNRECOVERABLE:new a(6040,c.ENTITY_REAUTH,"Non-replayable message replayed with a sequence number that is too far out of sync to recover."),UNIDENTIFIED_KEYX_SCHEME:new a(7E3,c.FAIL,"Unable to identify key exchange scheme."),
KEYX_FACTORY_NOT_FOUND:new a(7001,c.FAIL,"No factory registered for key exchange scheme."),KEYX_REQUEST_NOT_FOUND:new a(7002,c.FAIL,"No key request found matching header key response data."),UNIDENTIFIED_KEYX_KEY_ID:new a(7003,c.FAIL,"Unable to identify key exchange key ID."),UNSUPPORTED_KEYX_KEY_ID:new a(7004,c.FAIL,"Unsupported key exchange key ID."),UNIDENTIFIED_KEYX_MECHANISM:new a(7005,c.FAIL,"Unable to identify key exchange mechanism."),UNSUPPORTED_KEYX_MECHANISM:new a(7006,c.FAIL,"Unsupported key exchange mechanism."),
KEYX_RESPONSE_REQUEST_MISMATCH:new a(7007,c.FAIL,"Key exchange response does not match request."),KEYX_PRIVATE_KEY_MISSING:new a(7008,c.FAIL,"Key exchange private key missing."),UNKNOWN_KEYX_PARAMETERS_ID:new a(7009,c.FAIL,"Key exchange parameters ID unknown or invalid."),KEYX_MASTER_TOKEN_MISSING:new a(7010,c.FAIL,"Master token required for key exchange is missing."),KEYX_INVALID_PUBLIC_KEY:new a(7011,c.FAIL,"Key exchange public key is invalid."),KEYX_PUBLIC_KEY_MISSING:new a(7012,c.FAIL,"Key exchange public key missing."),
KEYX_WRAPPING_KEY_MISSING:new a(7013,c.FAIL,"Key exchange wrapping key missing."),KEYX_WRAPPING_KEY_ID_MISSING:new a(7014,c.FAIL,"Key exchange wrapping key ID missing."),KEYX_INVALID_WRAPPING_KEY:new a(7015,c.FAIL,"Key exchange wrapping key is invalid."),KEYX_INCORRECT_DATA:new a(7016,c.FAIL,"Entity used incorrect key exchange data type."),KEYX_INCORRECT_MECHANISM:new a(7017,c.FAIL,"Entity used incorrect key exchange mecahnism."),KEYX_DERIVATION_KEY_MISSING:new a(7018,c.FAIL,"Key exchange derivation key missing."),
KEYX_INVALID_ENCRYPTION_KEY:new a(7019,c.FAIL,"Key exchange encryption key is invalid."),KEYX_INVALID_HMAC_KEY:new a(7020,c.FAIL,"Key exchange HMAC key is invalid."),KEYX_INVALID_WRAPDATA:new a(7021,c.FAIL,"Key exchange wrap data is invalid."),UNSUPPORTED_KEYX_SCHEME:new a(7022,c.FAIL,"Unsupported key exchange scheme."),INTERNAL_EXCEPTION:new a(9E3,c.TRANSIENT_FAILURE,"Internal exception."),MSL_COMMS_FAILURE:new a(9001,c.FAIL,"Error communicating with MSL entity."),NONE:new a(9999,c.FAIL,"Special unit test error.")});
Object.freeze(a);var r;(function(){r=J.Class.create(Error());r.mixin({init:function(a,b,c){function d(){if(g)return g;if(this.cause&&this.cause instanceof r)return this.cause.messageId}Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor);var e=a.message;b&&(e+=" ["+b+"]");var g,f=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>R)throw new RangeError("Message ID "+a+" is outside the valid range.");d()||(g=a)},configurable:!0},stack:{get:function(){var a=this.toString();f&&(a+="\n"+f);c&&c.stack&&(a+="\nCaused by "+c.stack);
return a},configurable:!0}})},setEntity:function(a){!a||this.masterToken||this.entityAuthenticationData||(a instanceof Ca?this.masterToken=a:a instanceof Va&&(this.entityAuthenticationData=a));return this},setUser:function(a){!a||this.userIdToken||this.userAuthenticationData||(a instanceof Cb?this.userIdToken=a:a instanceof ab&&(this.userAuthenticationData=a));return this},setMessageId:function(a){this.messageId=a;return this},toString:function(){return this.name+": "+this.message}})})();var v=r.extend({init:function fe(a,
b,c){fe.base.call(this,a,b,c);Object.defineProperties(this,{name:{value:"MslCryptoException",writable:!1,configurable:!0}})}}),d=r.extend({init:function ge(a,b,c){ge.base.call(this,a,b,c);Object.defineProperties(this,{name:{value:"MslEncodingException",writable:!1,configurable:!0}})}}),g=r.extend({init:function he(a,b,c){he.base.call(this,a,b,c);Object.defineProperties(this,{name:{value:"MslEntityAuthException",writable:!1,configurable:!0}})}}),C;(function(){C=J.Class.create(Error());C.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 G;(function(){G=J.Class.create(Error());G.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 x;(function(){x=J.Class.create(Error());x.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 X=r.extend({init:function ie(a,b,c){ie.base.call(this,a,b,c);Object.defineProperties(this,{name:{value:"MslKeyExchangeException",writable:!1,configurable:!0}})}}),Ha=r.extend({init:function je(a,b){je.base.call(this,a);Object.defineProperties(this,{masterToken:{value:b,writable:!1,configurable:!1},name:{value:"MslMasterTokenException",writable:!1,configurable:!0}})}}),ea=r.extend({init:function ke(a,b,c){ke.base.call(this,a,b,c);Object.defineProperties(this,{name:{value:"MslMessageException",
writable:!1,configurable:!0}})}}),Z=r.extend({init:function le(a,b,c){le.base.call(this,a,b,c);Object.defineProperties(this,{name:{value:"MslUserAuthException",writable:!1,configurable:!0}})}}),Ba;(function(){Ba=J.Class.create(Error());Ba.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,Ab,Ib,Nc;(function(){function a(b){return"undefined"===typeof b?!1:b}function b(a){if(a&&a.length){if(D===d.V2014_02||D===d.V2014_02_SAFARI)a=a.map(function(a){return"wrap"==a?"wrapKey":"unwrap"==a?"unwrapKey":a});return a}return D===d.V2014_02||D===d.V2014_02_SAFARI?"encrypt decrypt sign verify deriveKey wrapKey unwrapKey".split(" "):
"encrypt decrypt sign verify deriveKey wrap unwrap".split(" ")}function c(a){return a.then?a:new Ka(function(b,m){a.oncomplete=function(a){b(a.target.result)};a.onerror=function(a){m(a)}})}var d=Ab={LEGACY:1,V2014_01:2,V2014_02:3,V2014_02_SAFARI:4,LATEST:3};Object.freeze(Ab);var D=d.LATEST;Ib=function(a){D=a};var m;"undefined"!==typeof window&&(window.msCrypto?(m=window.msCrypto.subtle,Ib(Ab.LEGACY)):window.crypto&&(window.crypto.webkitSubtle?(m=window.crypto.webkitSubtle,Ib(Ab.V2014_02_SAFARI)):
window.crypto.subtle&&(m=window.crypto.subtle)));Nc=function(a){m=a};ma={encrypt:function(a,b,q){switch(D){case d.LEGACY:case d.V2014_01:case d.V2014_02:case d.V2014_02_SAFARI:return a=m.encrypt(a,b,q),c(a);default:throw Error("Unsupported Web Crypto version "+D+".");}},decrypt:function(a,b,q){switch(D){case d.LEGACY:case d.V2014_01:case d.V2014_02:case d.V2014_02_SAFARI:return a=m.decrypt(a,b,q),c(a);default:throw Error("Unsupported Web Crypto version "+D+".");}},sign:function(a,b,q){switch(D){case d.LEGACY:case d.V2014_01:case d.V2014_02:case d.V2014_02_SAFARI:return a=
m.sign(a,b,q),c(a);default:throw Error("Unsupported Web Crypto version "+D+".");}},verify:function(a,b,q,n){switch(D){case d.LEGACY:case d.V2014_01:case d.V2014_02:case d.V2014_02_SAFARI:return a=m.verify(a,b,q,n),c(a);default:throw Error("Unsupported Web Crypto version "+D+".");}},digest:function(a,b){switch(D){case d.LEGACY:case d.V2014_01:case d.V2014_02:case d.V2014_02_SAFARI:var q=m.digest(a,b);return c(q);default:throw Error("Unsupported Web Crypto version "+D+".");}},generateKey:function(h,
k,q){k=a(k);q=b(q);switch(D){case d.LEGACY:case d.V2014_01:case d.V2014_02:case d.V2014_02_SAFARI:return h=m.generateKey(h,k,q),c(h);default:throw Error("Unsupported Web Crypto version "+D+".");}},deriveKey:function(h,k,q,n,t){n=a(n);t=b(t);switch(D){case d.LEGACY:case d.V2014_01:case d.V2014_02:case d.V2014_02_SAFARI:return h=m.deriveKey(h,k,q,n,t),c(h);default:throw Error("Unsupported Web Crypto version "+D+".");}},importKey:function(h,k,q,n,t){var e=a(n),p=b(t);switch(D){case d.LEGACY:case d.V2014_01:case d.V2014_02:return h=
m.importKey(h,k,q,e,p),c(h);case d.V2014_02_SAFARI:if("spki"==h||"pkcs8"==h)return Ka.resolve().then(function(){var a=ASN1.webCryptoAlgorithmToJwkAlg(q),b=ASN1.webCryptoUsageToJwkKeyOps(p),a=ASN1.rsaDerToJwk(k,a,b,e);if(!a)throw Error("Could not make valid JWK from DER input");a=JSON.stringify(a);return m.importKey("jwk",Da(a),q,e,p)});h=m.importKey(h,k,q,e,p);return c(h);default:throw Error("Unsupported Web Crypto version "+D+".");}},exportKey:function(a,b){switch(D){case d.LEGACY:case d.V2014_01:case d.V2014_02:var q=
m.exportKey(a,b);return c(q);case d.V2014_02_SAFARI:if("spki"==a||"pkcs8"==a)return q=m.exportKey("jwk",b),c(q).then(function(a){a=JSON.parse(Bb(new Uint8Array(a)));a=ASN1.jwkToRsaDer(a);if(!a)throw Error("Could not make valid DER from JWK input");return a.getDer().buffer});q=m.exportKey(a,b);return c(q);default:throw Error("Unsupported Web Crypto version "+D+".");}},wrapKey:function(a,b,q,n){switch(D){case d.LEGACY:a=m.wrapKey(b,q,n);break;case d.V2014_01:case d.V2014_02:case d.V2014_02_SAFARI:a=
m.wrapKey(a,b,q,n);break;default:throw Error("Unsupported Web Crypto version "+D+".");}return c(a)},unwrapKey:function(h,k,q,n,t,e,p){switch(D){case d.LEGACY:h=m.unwrapKey(k,t,q);break;case d.V2014_01:case d.V2014_02:case d.V2014_02_SAFARI:e=a(e);p=b(p);h=m.unwrapKey(h,k,q,n,t,e,p);break;default:throw Error("Unsupported Web Crypto version "+D+".");}return c(h)}}})();var ob=["encrypt","decrypt"],Db=["wrap","unwrap"],Oc=["wrap"],pb=["sign","verify"],me=["deriveKey"],da={A128KW:{name:"AES-KW"},AES_CBC:{name:"AES-CBC"},
DIFFIE_HELLMAN:{name:"DH"},HMAC_SHA256:{name:"HMAC",hash:{name:"SHA-256"}},RSA_OAEP:{name:"RSA-OAEP",hash:{name:"SHA-1"}},RSAES:{name:"RSAES-PKCS1-v1_5"},RSASSA:{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}},AES_CMAC:{name:"AES-CMAC"},RSASSA_SHA256:{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},RSASSA_SHA1:{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}},AUTHENTICATED_DH:{name:"NFLX-DH"},SHA_256:{name:"SHA-256"},SHA_384:{name:"SHA-384"}},hc,Ea,bb;(function(){hc=J.Class.create({init:function(c,d,e){function g(a){b(d,
function(){var b=a?l(a):void 0;Object.defineProperties(D,{algorithm:{value:c.algorithm,writable:!1,configurable:!1},rawKey:{value:c,writable:!1,configurable:!1},keyData:{value:a,writable:!1,configurable:!1},keyDataB64:{value:b,writable:!1,configurable:!1}});return this},D)}var D=this;b(d,function(){if(!c||"object"!=typeof c)throw new v(a.INVALID_SYMMETRIC_KEY);!e&&c.extractable?ma.exportKey("raw",c).then(function(a){g(new Uint8Array(a))},function(b){d.error(new v(a.KEY_EXPORT_ERROR,"raw"))}):g(e)},
D)},size:function(){return this.keyData.length},toByteArray:function(){return this.keyData},toBase64:function(){return this.keyDataB64}});Ea=function(a,b){new hc(a,b)};bb=function(c,d,e,g){b(g,function(){try{c="string"==typeof c?N(c):c}catch(b){throw new v(a.INVALID_SYMMETRIC_KEY,"keydata "+c,b);}ma.importKey("raw",c,d,!0,e).then(function(a){new hc(a,g,c)},function(b){g.error(new v(a.INVALID_SYMMETRIC_KEY))})})}})();var Wb,qb,ic;(function(){Wb=J.Class.create({init:function(c,d,e){function g(a){b(d,
function(){Object.defineProperties(D,{rawKey:{value:c,writable:!1,configurable:!1},encoded:{value:a,writable:!1,configurable:!1}});return this},D)}var D=this;b(d,function(){if(!c||"object"!=typeof c||"public"!=c.type)throw new TypeError("Only original public crypto keys are supported.");!e&&c.extractable?ma.exportKey("spki",c).then(function(a){g(new Uint8Array(a))},function(b){d.error(new v(a.KEY_EXPORT_ERROR,"spki"))}):g(e)})},getEncoded:function(){return this.encoded}});qb=function(a,b){new Wb(a,
b)};ic=function(c,d,e,g){b(g,function(){try{c="string"==typeof c?N(c):c}catch(b){throw new v(a.INVALID_PUBLIC_KEY,"spki "+c,b);}ma.importKey("spki",c,d,!0,e).then(function(a){new Wb(a,g,c)},function(b){g.error(new v(a.INVALID_PUBLIC_KEY))})})}})();var jc,Eb;(function(){jc=J.Class.create({init:function(c,d,e){function g(a){b(d,function(){Object.defineProperties(D,{rawKey:{value:c,writable:!1,configurable:!1},encoded:{value:a,writable:!1,configurable:!1}});return this},D)}var D=this;b(d,function(){if(!c||
"object"!=typeof c||"private"!=c.type)throw new TypeError("Only original private crypto keys are supported.");!e&&c.extractable?ma.exportKey("pkcs8",c).then(function(a){g(new Uint8Array(a))},function(b){d.error(new v(a.KEY_EXPORT_ERROR,"pkcs8"))}):g(e)})},getEncoded:function(){return this.encoded}});Eb=function(a,b){new jc(a,b)}})();var cb,Kb,kc,lc;(function(){var c=lc={V1:1,V2:2};cb=J.Class.create({init:function(a,b,d){var D;switch(a){case c.V1:D=d;break;case c.V2:D={};D.version=a;D.algorithm=b;
D.signature=l(d);D=sa(JSON.stringify(D),P);break;default:throw new x("Signature envelope version "+a+" encoding unsupported.");}Object.defineProperties(this,{version:{value:a,writable:!1,enumerable:!1,configurable:!1},algorithm:{value:b,writable:!1,configurable:!1},signature:{value:d,writable:!1,configurable:!1},bytes:{value:D,writable:!1,configurable:!1}})}});Kb=function(){var a,d,e,D;2==arguments.length?(a=c.V1,d=arguments[0],e=null,D=arguments[1]):3==arguments.length&&(a=c.V2,e=arguments[0],d=
arguments[1],D=arguments[2]);b(D,function(){return new cb(a,e,d)})};kc=function(e,g,f){b(f,function(){if(g)switch(g){case c.V1:return new cb(c.V1,null,e);case c.V2:try{var b=qa(e,P),m=JSON.parse(b),h=parseInt(m.version),k=m.algorithm,q=m.signature;if(!h||"number"!==typeof h||h!=h||"string"!==typeof k||"string"!==typeof q)throw new d(a.JSON_PARSE_ERROR,"signature envelope "+l(e));if(c.V2!=h)throw new v(a.UNSUPPORTED_SIGNATURE_ENVELOPE,"signature envelope "+l(e));var n=Qa(k);if(!n)throw new v(a.UNIDENTIFIED_ALGORITHM,
"signature envelope "+l(e));var t=N(q);if(!t)throw new v(a.INVALID_SIGNATURE,"signature envelope "+l(e));return new cb(c.V2,n,t)}catch(U){if(U instanceof SyntaxError)throw new d(a.JSON_PARSE_ERROR,"signature envelope "+l(e),U);throw U;}default:throw new v(a.UNSUPPORTED_SIGNATURE_ENVELOPE,"signature envelope "+l(e));}try{b=qa(e,P),m=JSON.parse(b)}catch(p){m=null}if(m&&m.version){if(b=m.version,"number"!==typeof b||b!==b)b=c.V1}else b=c.V1;switch(b){case c.V1:return new cb(b,null,e);case c.V2:n=m.algorithm;
q=m.signature;if("string"!==typeof n||"string"!==typeof q)return new cb(c.V1,null,e);n=Qa(n);if(!n)return new cb(c.V1,null,e);try{t=N(q)}catch(y){return new cb(c.V1,null,e)}return new cb(b,n,t);default:throw new v(a.UNSUPPORTED_SIGNATURE_ENVELOPE,"signature envelope "+e);}})}})();var mc,nc,oc,pc;(function(){var c=pc={V1:1,V2:2};mc=J.Class.create({init:function(a,d,e,D){b(D,function(){var b=c.V1,h=a,k=null,q;for(q in aa)if(aa[q]==a){b=c.V2;h=null;k=a;break}Object.defineProperties(this,{version:{value:b,
writable:!1,enumerable:!1,configurable:!1},keyId:{value:h,writable:!1,configurable:!1},cipherSpec:{value:k,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 c.V1:a.keyid=this.keyId;this.iv&&(a.iv=l(this.iv));a.ciphertext=l(this.ciphertext);a.sha256="AA==";break;case c.V2:a.version=this.version;a.cipherspec=this.cipherSpec;this.iv&&(a.iv=l(this.iv));a.ciphertext=
l(this.ciphertext);break;default:throw new x("Ciphertext envelope version "+this.version+" encoding unsupported.");}return a}});nc=function(a,b,c,d){new mc(a,b,c,d)};oc=function(e,g,f){b(f,function(){var b=e.keyid,m=e.cipherspec,h=e.iv,k=e.ciphertext,q=e.sha256;if(!g)if((g=e.version)&&"number"===typeof g&&g===g){var n=!1,t;for(t in c)if(c[t]==g){n=!0;break}if(!n)throw new v(a.UNIDENTIFIED_CIPHERTEXT_ENVELOPE,"ciphertext envelope "+JSON.stringify(e));}else g=c.V1;switch(g){case c.V1:if("string"!==
typeof b||h&&"string"!==typeof h||"string"!==typeof k||"string"!==typeof q)throw new d(a.JSON_PARSE_ERROR,"ciphertext envelope "+JSON.stringify(e));break;case c.V2:t=e.version;if(t!=c.V2)throw new v(a.UNIDENTIFIED_CIPHERTEXT_ENVELOPE,"ciphertext envelope "+JSON.stringify(e));if("string"!==typeof m||h&&"string"!==typeof h||"string"!==typeof k)throw new d(a.JSON_PARSE_ERROR,"ciphertext envelope "+JSON.stringify(e));m=Ma(m);if(!m)throw new v(a.UNIDENTIFIED_CIPHERSPEC,"ciphertext envelope "+JSON.stringify(e));
b=m;break;default:throw new v(a.UNSUPPORTED_CIPHERTEXT_ENVELOPE,"ciphertext envelope "+JSON.stringify(e));}try{h&&(h=N(h)),k=N(k)}catch(U){throw new v(a.CIPHERTEXT_ENVELOPE_PARSE_ERROR,"encryption envelope "+JSON.stringify(e),U);}new mc(b,h,k,f)})}})();var db=J.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){}}),Lb=db.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 c=Yb={ENCRYPT_DECRYPT_OAEP:1,ENCRYPT_DECRYPT_PKCS1:2,WRAP_UNWRAP_OAEP:3,WRAP_UNWRAP_PKCS1:4,SIGN_VERIFY:5};Xb=db.extend({init:function ta(a,b,m,h,k){ta.base.call(this);m&&(m=m.rawKey);h&&(h=h.rawKey);Object.defineProperties(this,{id:{value:b,writable:!1,enumerable:!1,configurable:!1},privateKey:{value:m,writable:!1,enumerable:!1,
configurable:!1},publicKey:{value:h,writable:!1,enumerable:!1,configurable:!1},transform:{value:k==c.ENCRYPT_DECRYPT_PKCS1?da.RSAES:k==c.ENCRYPT_DECRYPT_OAEP?da.RSA_OAEP:"nullOp",writable:!1,enumerable:!1,configurable:!1},wrapTransform:{value:k==c.WRAP_UNWRAP_PKCS1?da.RSAES:k==c.WRAP_UNWRAP_OAEP?da.RSA_OAEP:"nullOp",writable:!1,enumerable:!1,configurable:!1},algo:{value:k==c.SIGN_VERIFY?da.RSASSA_SHA256:"nullOp",writable:!1,enumerable:!1,configurable:!1}})},encrypt:function(c,d){var e=this;b(d,function(){if("nullOp"==
this.transform)return c;if(!this.publicKey)throw new v(a.ENCRYPT_NOT_SUPPORTED,"no public key");if(0==c.length)return c;ma.encrypt(e.transform,e.publicKey,c).then(function(b){nc(e.id,null,new Uint8Array(b),{result:function(b){try{var k=JSON.stringify(b);d.result(sa(k,P))}catch(c){d.error(new v(a.ENCRYPT_ERROR,null,c))}},error:function(b){b instanceof r||(b=new v(a.ENCRYPT_ERROR,null,b));d.error(b)}})},function(b){d.error(new v(a.ENCRYPT_ERROR))})},this)},decrypt:function(c,e){var D=this;b(e,function(){if("nullOp"==
this.transform)return c;if(!this.privateKey)throw new v(a.DECRYPT_NOT_SUPPORTED,"no private key");if(0==c.length)return c;var b;try{var h=qa(c,P);b=JSON.parse(h)}catch(k){if(k instanceof SyntaxError)throw new v(a.CIPHERTEXT_ENVELOPE_PARSE_ERROR,null,k);throw new v(a.DECRYPT_ERROR,null,k);}oc(b,pc.V1,{result:function(b){try{if(b.keyId!=D.id)throw new v(a.ENVELOPE_KEY_ID_MISMATCH);ma.decrypt(D.transform,D.privateKey,b.ciphertext).then(function(a){e.result(new Uint8Array(a))},function(b){e.error(new v(a.DECRYPT_ERROR))})}catch(h){h instanceof
r?e.error(h):e.error(new v(a.DECRYPT_ERROR,null,h))}},error:function(b){b instanceof d&&(b=new v(a.CIPHERTEXT_ENVELOPE_ENCODE_ERROR,null,b));b instanceof r||(b=new v(a.DECRYPT_ERROR,null,b));e.error(b)}})},this)},wrap:function(c,d){b(d,function(){if("nullOp"==this.wrapTransform||!this.publicKey)throw new v(a.WRAP_NOT_SUPPORTED,"no public key");ma.wrapKey("jwk",c.rawKey,this.publicKey,this.wrapTransform).then(function(a){d.result(new Uint8Array(a))},function(b){d.error(new v(a.WRAP_ERROR))})},this)},
unwrap:function(c,d,e,m){function h(h){b(m,function(){switch(h.type){case "secret":Ea(h,m);break;case "public":qb(h,m);break;case "private":Eb(h,m);break;default:throw new v(a.UNSUPPORTED_KEY,"type: "+h.type);}})}b(m,function(){if("nullOp"==this.wrapTransform||!this.privateKey)throw new v(a.UNWRAP_NOT_SUPPORTED,"no private key");ma.unwrapKey("jwk",c,this.privateKey,this.wrapTransform,d,!1,e).then(h,function(b){m.error(new v(a.UNWRAP_ERROR))})},this)},sign:function(c,d){b(d,function(){if("nullOp"==
this.algo)return new Uint8Array(0);if(!this.privateKey)throw new v(a.SIGN_NOT_SUPPORTED,"no private key");ma.sign(this.algo,this.privateKey,c).then(function(a){Kb(new Uint8Array(a),{result:function(a){d.result(a.bytes)},error:d.error})},function(b){d.error(new v(a.SIGNATURE_ERROR))})},this)},verify:function(c,d,e){var m=this;b(e,function(){if("nullOp"==this.algo)return!0;if(!this.publicKey)throw new v(a.VERIFY_NOT_SUPPORTED,"no public key");kc(d,lc.V1,{result:function(h){b(e,function(){var b=e.result;
ma.verify(this.algo,this.publicKey,h.signature,c).then(b,function(b){e.error(new v(a.SIGNATURE_ERROR))})},m)},error:e.error})},this)}})})();var Mb;(function(){Mb=db.extend({init:function Fa(a,b,c,d,h){Fa.base.call(this);c=c&&c.rawKey;d=d&&d.rawKey;h=h&&h.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},signatureKey:{value:d,writable:!1,
enumerable:!1,configurable:!1},wrapKey:{value:h,writable:!1,enumerable:!1,configurable:!1}})},encrypt:function(c,d){var e=this;b(d,function(){if(!this.encryptionKey)throw new v(a.ENCRYPT_NOT_SUPPORTED,"no encryption/decryption key");if(0==c.length)return c;var b=new Uint8Array(16);this.ctx.getRandom().nextBytes(b);ma.encrypt({name:da.AES_CBC.name,iv:b},e.encryptionKey,c).then(function(c){nc(e.id,b,new Uint8Array(c),{result:function(b){try{var k=JSON.stringify(b);d.result(sa(k,P))}catch(c){d.error(new v(a.ENCRYPT_ERROR,
null,c))}},error:function(b){b instanceof r||(b=new v(a.ENCRYPT_ERROR,null,b));d.error(b)}})},function(b){d.error(new v(a.ENCRYPT_ERROR))})},this)},decrypt:function(c,e){var g=this;b(e,function(){if(!this.encryptionKey)throw new v(a.DECRYPT_NOT_SUPPORTED,"no encryption/decryption key");if(0==c.length)return c;var b;try{var m=qa(c,P);b=JSON.parse(m)}catch(h){if(h instanceof SyntaxError)throw new v(a.CIPHERTEXT_ENVELOPE_PARSE_ERROR,null,h);throw new v(a.DECRYPT_ERROR,null,h);}oc(b,pc.V1,{result:function(b){try{if(b.keyId!=
g.id)throw new v(a.ENVELOPE_KEY_ID_MISMATCH);ma.decrypt({name:da.AES_CBC.name,iv:b.iv},g.encryptionKey,b.ciphertext).then(function(a){e.result(new Uint8Array(a))},function(){e.error(new v(a.DECRYPT_ERROR))})}catch(h){h instanceof r?e.error(h):e.error(new v(a.DECRYPT_ERROR,null,h))}},error:function(b){b instanceof d&&(b=new v(a.CIPHERTEXT_ENVELOPE_ENCODE_ERROR,null,b));b instanceof r||(b=new v(a.DECRYPT_ERROR,null,b));e.error(b)}})},this)},wrap:function(c,d){b(d,function(){if(!this.wrapKey)throw new v(a.WRAP_NOT_SUPPORTED,
"no wrap/unwrap key");ma.wrapKey("raw",c.rawKey,this.wrapKey,this.wrapKey.algorithm).then(function(a){d.result(new Uint8Array(a))},function(b){d.error(new v(a.WRAP_ERROR))})},this)},unwrap:function(c,d,e,D){function m(h){b(D,function(){switch(h.type){case "secret":Ea(h,D);break;case "public":qb(h,D);break;case "private":Eb(h,D);break;default:throw new v(a.UNSUPPORTED_KEY,"type: "+h.type);}})}b(D,function(){if(!this.wrapKey)throw new v(a.UNWRAP_NOT_SUPPORTED,"no wrap/unwrap key");ma.unwrapKey("raw",
c,this.wrapKey,this.wrapKey.algorithm,d,!1,e).then(function(a){m(a)},function(b){D.error(new v(a.UNWRAP_ERROR))})},this)},sign:function(c,d){var e=this;b(d,function(){if(!this.signatureKey)throw new v(a.SIGN_NOT_SUPPORTED,"no signature key.");ma.sign(this.signatureKey.algorithm,this.signatureKey,c).then(function(a){b(d,function(){Kb(new Uint8Array(a),{result:function(a){d.result(a.bytes)},error:d.error})},e)},function(){d.error(new v(a.HMAC_ERROR))})},this)},verify:function(c,d,e){var D=this;b(e,
function(){if(!this.signatureKey)throw new v(a.VERIFY_NOT_SUPPORTED,"no signature key.");kc(d,lc.V1,{result:function(d){b(e,function(){var b=e.result;ma.verify(this.signatureKey.algorithm,this.signatureKey,d.signature,c).then(b,function(b){e.error(new v(a.HMAC_ERROR))})},D)},error:e.error})},this)}})})();var ua=Mb.extend({init:function Fa(b,c,d,m,h){if(d||m||h)Fa.base.call(this,b,d+"_"+c.sequenceNumber,m,h,null);else{if(!c.isDecrypted())throw new Ha(a.MASTERTOKEN_UNTRUSTED,c);Fa.base.call(this,b,
c.identity+"_"+c.sequenceNumber,c.encryptionKey,c.signatureKey,null)}}}),ne=db.extend({encrypt:function(a,b){b.result(a)},decrypt:function(a,b){b.result(a)},wrap:function(a,b){b.error(new x("Wrap is unsupported by the MSL token crypto context."))},unwrap:function(a,b,c,d){d.error(new x("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)}}),eb,fb;(function(){var c=fb={RSA_OAEP:da.RSA_OAEP.name,A128KW:da.A128KW.name};
V="A128GCM";eb=J.Class.create({init:function(a,b,d,m,h){switch(b){case c.RSA_OAEP:b=da.RSA_OAEP;h=h&&(h.rawKey||h);m=m&&(m.rawKey||m);break;case c.A128KW:b=da.A128KW;h=m=m&&(m.rawKey||m);break;default:throw new x("Unsupported algorithm: "+b);}Object.defineProperties(this,{_ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},_transform:{value:b,writable:!1,enumerable:!1,configurable:!1},_enc:{value:d,writable:!1,enumerable:!1,configurable:!1},_wrapKey:{value:h,writable:!1,enumerable:!1,configurable:!1},
_unwrapKey:{value:m,writable:!1,enumerable:!1,configurable:!1}})},encrypt:function(b,c){c.error(new v(a.ENCRYPT_NOT_SUPPORTED))},decrypt:function(b,c){c.error(new v(a.DECRYPT_NOT_SUPPORTED))},wrap:function(c,d){b(d,function(){ma.wrapKey("jwe+jwk",c.rawKey,this._wrapKey,this._transform).then(function(a){d.result(new Uint8Array(a))},function(b){d.error(new v(a.WRAP_ERROR))})},this)},unwrap:function(c,d,e,m){function h(h){b(m,function(){switch(h.type){case "secret":Ea(h,m);break;case "public":qb(h,m);
break;case "private":Eb(h,m);break;default:throw new v(a.UNSUPPORTED_KEY,"type: "+h.type);}})}b(m,function(){ma.unwrapKey("jwe+jwk",c,this._unwrapKey,this._transform,d,!1,e).then(function(a){h(a)},function(){m.error(new v(a.UNWRAP_ERROR))})},this)},sign:function(b,c){c.error(new v(a.SIGN_NOT_SUPPORTED))},verify:function(b,c,d){d.error(new v(a.VERIFY_NOT_SUPPORTED))}})})();var Pc;(function(){Pc=db.extend({init:function ta(a,b){ta.base.call(this);Object.defineProperties(this,{privateKey:{value:b,writable:!1,
enumerable:!1,configurable:!1}})},encrypt:function(a,c){b(c,function(){return a},this)},decrypt:function(c,d){b(d,function(){throw new v(a.WRAP_NOT_SUPPORTED,"ECC does not decrypt");},this)},wrap:function(c,d){b(d,function(){throw new v(a.WRAP_NOT_SUPPORTED,"ECC does not wrap");},this)},unwrap:function(c,d,e,m){b(m,function(){throw new v(a.UNWRAP_NOT_SUPPORTED,"ECC does not unwrap");},this)},sign:function(c,d){b(d,function(){ma.sign({name:"ECC",hash:"SHA-256"},this.privateKey,c).then(function(a){Kb(new Uint8Array(a),
{result:function(a){d.result(a.bytes)},error:d.error})},function(b){d.error(new v(a.SIGNATURE_ERROR))})},this)},verify:function(c,d,e){b(e,function(){throw new v(a.VERIFY_NOT_SUPPORTED,"ECC does not verify");},this)}})})();var la,Qc;(function(){var a={};la=function(b,c,d){Object.defineProperties(this,{name:{value:b,writable:!1,configurable:!1},encrypts:{value:c,writable:!1,configurable:!1},protectsIntegrity:{value:d,writable:!1,configurable:!1}});a[b]=this};J.Class.mixin(la,{PSK:new la("PSK",!0,!0),
PSK_PROFILE:new la("PSK_PROFILE",!0,!0),X509:new la("X509",!1,!0),RSA:new la("RSA",!1,!0),NONE:new la("NONE",!1,!1),NONE_SUFFIXED:new la("NONE_SUFFIXED",!1,!1),MT_PROTECTED:new la("MT_PROTECTED",!1,!1)});Object.freeze(la);Qc=function(b){return a[b]?a[b]:null}})();var Va,Rc;(function(){Va=J.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 Va?
this.scheme==a.scheme:!1},toJSON:function(){var a={};a.scheme=this.scheme.name;a.authdata=this.getAuthData();return a}});Rc=function(c,e,f){b(f,function(){var b=e.scheme,m=e.authdata;if("string"!==typeof b||"object"!==typeof m)throw new d(a.JSON_PARSE_ERROR,"entityauthdata "+JSON.stringify(e));var h=c.getEntityAuthenticationScheme(b);if(!h)throw new g(a.UNIDENTIFIED_ENTITYAUTH_SCHEME,b);b=c.getEntityAuthenticationFactory(h);if(!b)throw new g(a.ENTITYAUTH_FACTORY_NOT_FOUND,h.name);b.createData(c,m,
f)})}})();var Wa,Sc;(function(){Wa=Va.extend({init:function ta(a){ta.base.call(this,la.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 La(a){return this===a?!0:a instanceof Wa?La.base.call(this,a)&&this.identity==a.identity:!1}});Sc=function(b){var c=b.identity;if("string"!==typeof c)throw new d(a.JSON_PARSE_ERROR,"psk authdata"+JSON.stringify(b));return new Wa(c)}})();
var Tc,Uc;(function(){Tc=J.Class.create({init:function(a,b,c){Object.defineProperties(this,{encryptionKey:{value:a,writable:!1,configurable:!1},hmacKey:{value:b,writable:!1,configurable:!1},wrappingKey:{value:c,writable:!1,configurable:!1}})}});Uc=J.Class.create({getKeys:function(a){}})})();var Zb,Vc;(function(){Zb=Va.extend({init:function ta(a,b){ta.base.call(this,la.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 La(a){return this===a?!0:a instanceof Zb?La.base.call(this,a)&&this.identity==a.identity&&this.publicKeyId==a.publicKeyId:!1}});Vc=function(b){var c=b.identity,m=b.pubkeyid;if("string"!==typeof c||"string"!==typeof m)throw new d(a.JSON_PARSE_ERROR,"RSA authdata"+JSON.stringify(b));return new Zb(c,m)}})();var rb,Wc;(function(){rb=Va.extend({init:function ta(a){ta.base.call(this,
la.NONE);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 La(a){return this===a?!0:a instanceof rb?La.base.call(this,a)&&this.identity==a.identity:!1}});Wc=function(b){var c=b.identity;if("string"!==typeof c)throw new d(a.JSON_PARSE_ERROR,"Unauthenticated authdata"+JSON.stringify(b));return new rb(c)}})();var sb=J.Class.create({init:function(a){Object.defineProperties(this,
{scheme:{value:a,writable:!1,configurable:!1}})},createData:function(a,b,c){},getCryptoContext:function(a,b){}}),Xc;Xc=sb.extend({init:function ta(a,b){ta.base.call(this,la.PSK);Object.defineProperties(this,{store:{value:a,writable:!1,enumerable:!1,configurable:!1},authutils:{value:b,writable:!1,enumerable:!1,configurable:!1}})},createData:function(a,c,d){b(d,function(){return Sc(c)})},getCryptoContext:function(b,c){if(!(c instanceof Wa))throw new x("Incorrect authentication data type "+JSON.stringify(c)+
".");var d=c.getIdentity();if(this.authutils.isEntityRevoked(d))throw(new g(a.ENTITY_REVOKED,"psk "+d)).setEntity(c);if(!this.authutils.isSchemePermitted(d,this.scheme))throw(new g(a.INCORRECT_ENTITYAUTH_DATA,"Authentication scheme for entity "+d+" not supported:"+this.scheme)).setEntity(c);var m=this.store.getKeys(d);if(!m)throw(new g(a.ENTITY_NOT_FOUND,"psk "+d)).setEntity(c);return new Mb(b,d,m.encryptionKey,m.hmacKey,m.wrappingKey)}});var oe=J.Class.create({init:function(){Object.defineProperties(this,
{publicKeys:{value:{},writable:!0,enumerable:!1,configurable:!1},privateKeys:{value:{},writable:!0,enumerable:!1,configurable:!1}})},getIdentities:function(){for(var a=Object.keys(this.publicKeys).concat(Object.keys(this.privateKeys)),b=0;b<a.length;++b)for(var c=0;c<a.length;++b)a[b]==a[c]&&a.splice(c--,1);return a},addPublicKey:function(a,b){if(!(b instanceof Wb))throw new x("Incorrect key data type "+b+".");this.publicKeys[a]=b},removePublicKey:function(a){delete this.publicKeys[a]},getPublicKey:function(a){return this.publicKeys[a]},
addPrivateKey:function(a,b){if(!(b instanceof jc))throw new x("Incorrect key data type "+b+".");this.privateKeys[a]=b},removePrivateKey:function(a){delete this.privateKeys[a]},getPrivateKey:function(a){return this.privateKeys[a]},clear:function(){this.publicKeys={};this.privateKeys={}}}),Yc=sb.extend({init:function La(a,b){La.base.call(this,la.RSA);Object.defineProperties(this,{keyPairId:{value:a,writable:!1,enumerable:!1,configurable:!1},store:{value:b,writable:!1,enumerable:!1,configurable:!1}})},
createData:function(a,c,d){b(d,function(){return Vc(c)})},getCryptoContext:function(b,c){if(!(c instanceof Zb))throw new x("Incorrect authentication data type "+c+".");var d=c.identity,h=c.publicKeyId,k=this.store.getPublicKey(h),q=this.store.getPrivateKey(h);if(h==this.keyPairId&&!q)throw(new g(a.RSA_PRIVATEKEY_NOT_FOUND,h)).setEntity(c);if(h!=this.keyPairId&&!k)throw(new g(a.RSA_PUBLICKEY_NOT_FOUND,h)).setEntity(c);return new Xb(b,d,q,k,Yb.SIGN_VERIFY)}}),Zc=sb.extend({init:function D(){D.base.call(this,
la.NONE)},createData:function(a,c,h){b(h,function(){return Wc(c)})},getCryptoContext:function(a,b){if(!(b instanceof rb))throw new x("Incorrect authentication data type "+JSON.stringify(b)+".");return new Lb}}),$b;(function(){$b=Va.extend({init:function m(a,b,c){m.base.call(this,la.X509);b&&(a=b.getSubjectString());Object.defineProperties(this,{identity:{value:a,writable:!1,configurable:!1},x509cert:{value:b,writable:!1,configurable:!1},x509chain:{value:c,writable:!1,configurable:!1}})},getIdentity:function(){return this.identity},
getAuthData:function(){var a={};if(this.x509cert){var b=CryptoJS.enc.Hex.parse(this.x509cert.hex),b=CryptoJS.enc.Base64.stringify(b);a.x509certificate=b}else this.x509chain&&(a.x509chain=this.x509chain);a.identity=this.identity;return a},equals:function h(a){return this===a?!0:a instanceof $b?h.base.call(this,a)&&this.identity===a.identity&&this.x509cert===a.x509cert&&this.x509chain===a.x509chain:!1}})})();var $c=J.Class.create({abort:function(){},close:function(a,b){},mark:function(){},reset:function(){},
markSupported:function(){},read:function(a,b,c){}}),qc=J.Class.create({abort:function(){},close:function(a,b){},write:function(a,b,c,k,d){},flush:function(a,b){}}),pe=J.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 G("Stream has not been marked.");this._currentPosition=this._mark},markSupported:function(){return!0},read:function(a,b,c){e(c,function(){if(this._closed)throw new G("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)}}),qe=J.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,c,k,d){e(d,function(){if(this._closed)throw new G("Stream is 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 k=a.subarray(b,c);this._buffered.push(k);return k.length},this)},flush:function(a,b){for(;0<this._buffered.length;){var c=this._buffered.shift();if(this._result){var k=new Uint8Array(this._result.length+c.length);k.set(this._result);k.set(c,this._result.length);this._result=k}else this._result=new Uint8Array(c)}b.result(!0)},size:function(){this.flush(1,
{result:function(){}});return this._result.length},toByteArray:function(){this.flush(1,{result:function(){}});return this._result}}),ad=function(a,b,c){(function(a,b,d){a.read(-1,b,{result:function(a){a&&a.length?d(null,a):d(null,null)},timeout:function(){c.timeout()},error:function(a){d(a,null)}})})(a,b,function(b,d){var n;if(b)c.error(b);else if(d){void 0!==a.getJSON&&"function"===typeof a.getJSON&&(n=a.getJSON());if(void 0===n){n=new ClarinetParser(qa(d,"utf-8"));var m=[],e;for(e=n.nextValue();void 0!==
e;)m.push(e),e=n.nextValue();n=m}c.result(n)}else c.result(null)})},bd,re=J.Class.create({getResponse:function(a,b,c){}});(function(){var a=qc.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 qe,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 K,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){var c=this;this._responseQueue.poll(-1,{result:function(d){b(a,function(){d&&this._responseQueue.add(d);return d},c)},timeout:function(){b(a,function(){this._response={isTimeout:!0};this._responseQueue.add(this._response);this.abort();a.timeout()},c)},error:function(d){b(a,
function(){this._response={isError:!0};this._responseQueue.add(this._response);throw d;},c)}})},abort:function(){this._abortToken&&this._abortToken.abort();this._aborted=!0},close:function(a,b){var c=this;e(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,m){e(m,function(){if(this._response)throw new G("HttpOutputStream already closed.");this._buffer.write(a,b,c,d,m)},this)},flush:function(a,b){e(b,function(){if(this._response)return!0;this._buffer.flush(a,b)},this)}}),c=$c.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){e(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()},getJSON:function(){return this._json},read:function(a,b,c){function d(n){e(c,function(){if(!n)return new Uint8Array(0);this._out.getResponse({result:function(d){e(c,function(){var n;if(d.isTimeout)this._timedout=!0,c.timeout();else{if(d.isError)throw this._exception=d.error||new G("Unknown HTTP exception."),this._exception;if(!d.response)throw this._exception=new G("Missing HTTP response."),this._exception;
void 0!==d.response.json?(this._json=d.response.json,n=new Uint8Array([0])):n=d.response.content||Da(d.response.body);this._buffer=new pe(n);this._buffer.read(a,b,c)}},m)},timeout:function(){c.timeout()},error:function(a){c.error(a)}})},m)}var m=this;e(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)}})}},
m)}});bd=J.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 b=new a(this._httpLocation,this._timeout);return{input:new c(b),output:b}}})})();var xa,cd;(function(){var a={};xa=function(b){Object.defineProperties(this,{name:{value:b,writable:!1,configurable:!1}});a[b]=this};J.Class.mixin(xa,
{ASYMMETRIC_WRAPPED:new xa("ASYMMETRIC_WRAPPED"),DIFFIE_HELLMAN:new xa("DIFFIE_HELLMAN"),JWE_LADDER:new xa("JWE_LADDER"),JWK_LADDER:new xa("JWK_LADDER"),SYMMETRIC_WRAPPED:new xa("SYMMETRIC_WRAPPED")});Object.freeze(xa);cd=function(b){return a[b]?a[b]:null}})();var Xa,dd;(function(){Xa=J.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.name;a.keydata=
this.getKeydata();return a},equals:function(a){return this===a?!0:a instanceof Xa?this.keyExchangeScheme==a.keyExchangeScheme:!1},uniqueKey:function(){return this.keyExchangeScheme}});dd=function(c,m,h){b(h,function(){var b=m.scheme,e=m.keydata;if("string"!==typeof b||"object"!==typeof e)throw new d(a.JSON_PARSE_ERROR,"keyrequestdata "+JSON.stringify(m));var n=c.getKeyExchangeScheme(b);if(!n)throw new X(a.UNIDENTIFIED_KEYX_SCHEME,b);b=c.getKeyExchangeFactory(n);if(!b)throw new X(a.KEYX_FACTORY_NOT_FOUND,
n.name);b.createRequestData(c,e,h)})}})();var Ya,ed;(function(){Ya=J.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.name;a.keydata=this.getKeydata();return a},equals:function(a){return this===a?!0:a instanceof Ya?this.masterToken.equals(a.masterToken)&&this.keyExchangeScheme==
a.keyExchangeScheme:!1},uniqueKey:function(){return this.masterToken.uniqueKey()+":"+this.keyExchangeScheme}});ed=function(c,m,h){b(h,function(){var k=m.mastertoken,e=m.scheme,n=m.keydata;if("string"!==typeof e||"object"!==typeof k||"object"!==typeof n)throw new d(a.JSON_PARSE_ERROR,"keyresponsedata "+JSON.stringify(m));var t=c.getKeyExchangeScheme(e);if(!t)throw new X(a.UNIDENTIFIED_KEYX_SCHEME,e);kb(c,k,{result:function(d){b(h,function(){var b=c.getKeyExchangeFactory(t);if(!b)throw new X(a.KEYX_FACTORY_NOT_FOUND,
t.name);return b.createResponseData(c,d,n)})},error:function(a){h.error(a)}})})}})();var za;(function(){var c=J.Class.create({init:function(a,b){Object.defineProperties(this,{keyResponseData:{value:a,writable:!1,configurable:!1},cryptoContext:{value:b,writable:!1,configurable:!1}})}});za=J.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,n){},generateSessionKeys:function(c,h){b(h,function(){var b=new Uint8Array(16),d=new Uint8Array(32);c.getRandom().nextBytes(b);c.getRandom().nextBytes(d);bb(b,da.AES_CBC,ob,{result:function(b){bb(d,da.HMAC_SHA256,pb,{result:function(a){h.result({encryptionKey:b,hmacKey:a})},error:function(b){h.error(new v(a.SESSION_KEY_CREATION_FAILURE,null,b))}})},error:function(b){h.error(new v(a.SESSION_KEY_CREATION_FAILURE,null,b))}})})},importSessionKeys:function(a,
b,c){bb(a,da.AES_CBC,ob,{result:function(a){bb(b,da.HMAC_SHA256,pb,{result:function(b){c.result({encryptionKey:a,hmacKey:b})},error:function(a){c.error(a)}})},error:function(a){c.error(a)}})}});za.KeyExchangeData=c})();var Nb,fd,rc,gd;(function(){function c(b,h,d,k,e){switch(d){case m.JWE_RSA:case m.JWEJS_RSA:return new eb(b,fb.RSA_OAEP,V,k,e);case m.JWK_RSA:return new Xb(b,h,k,e,Yb.WRAP_UNWRAP_OAEP);case m.JWK_RSAES:return new Xb(b,h,k,e,Yb.WRAP_UNWRAP_PKCS1);default:throw new v(a.UNSUPPORTED_KEYX_MECHANISM,
d);}}var m=fd={RSA:"RSA",ECC:"ECC",JWE_RSA:"JWE_RSA",JWEJS_RSA:"JWEJS_RSA",JWK_RSA:"JWK_RSA",JWK_RSAES:"JWK_RSAES"},h=rc=Xa.extend({init:function t(a,b,c,h){t.base.call(this,xa.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:h,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.keypairid=this.keyPairId;a.mechanism=this.mechanism;
a.publickey=l(this.publicKey.getEncoded());return a},equals:function U(a){if(a===this)return!0;if(!(a instanceof rc))return!1;var b=this.privateKey===a.privateKey||this.privateKey&&a.privateKey&&f(this.privateKey.getEncoded(),a.privateKey.getEncoded());return U.base.call(this,a)&&this.keyPairId==a.keyPairId&&this.mechanism==a.mechanism&&f(this.publicKey.getEncoded(),a.publicKey.getEncoded())&&b},uniqueKey:function p(){var a=this.publicKey.getEncoded(),b=this.privateKey&&this.privateKey.getEncoded(),
a=p.base.call(this)+":"+this.keyPairId+":"+this.mechanism+":"+z(a);b&&(a+=":"+z(b));return a}}),k=function(c,k){b(k,function(){var b=c.keypairid,e=c.mechanism,q=c.publickey;if(!b||"string"!==typeof b||!e||!q||"string"!==typeof q)throw new d(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(c));if(!m[e])throw new X(a.UNIDENTIFIED_KEYX_MECHANISM,e);try{var g=N(q);switch(e){case m.JWE_RSA:case m.JWEJS_RSA:case m.JWK_RSA:ic(g,da.RSA_OAEP,Oc,{result:function(a){k.result(new h(b,e,a,null))},error:function(a){k.error(a)}});
break;case m.JWK_RSAES:ic(g,da.RSAES,Oc,{result:function(a){k.result(new h(b,e,a,null))},error:function(a){k.error(a)}});break;default:throw new v(a.UNSUPPORTED_KEYX_MECHANISM,e);}}catch(B){if(!(B instanceof r))throw new v(a.INVALID_PUBLIC_KEY,"keydata "+JSON.stringify(c),B);throw B;}})},e=gd=Ya.extend({init:function y(a,b,c,h){y.base.call(this,a,xa.ASYMMETRIC_WRAPPED);Object.defineProperties(this,{keyPairId:{value:b,writable:!1,configurable:!1},encryptionKey:{value:c,writable:!1,configurable:!1},
hmacKey:{value:h,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.keypairid=this.keyPairId;a.encryptionkey=l(this.encryptionKey);a.hmackey=l(this.hmacKey);return a},equals:function F(a){return this===a?!0:a instanceof gd?F.base.call(this,a)&&this.keyPairId==a.keyPairId&&f(this.encryptionKey,a.encryptionKey)&&f(this.hmacKey,a.hmacKey):!1},uniqueKey:function na(){return na.base.call(this)+":"+this.keyPairId+":"+z(this.encryptionKey)+":"+z(this.hmacKey)}});Nb=za.extend({init:function S(){S.base.call(this,
xa.ASYMMETRIC_WRAPPED)},createRequestData:function(a,b,c){k(b,c)},createResponseData:function(b,c,h){b=h.keypairid;var k=h.encryptionkey,m=h.hmackey;if(!b||"string"!==typeof b||!k||"string"!==typeof k||!m||"string"!==typeof m)throw new d(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(h));var A;try{A=N(k)}catch(g){throw new v(a.INVALID_ENCRYPTION_KEY,"keydata "+JSON.stringify(h),g);}var f;try{f=N(m)}catch(l){throw new v(a.INVALID_HMAC_KEY,"keydata "+JSON.stringify(h),l);}return new e(c,b,A,f)},generateResponse:function(a,
d,k,m){function M(h,e){b(m,function(){var q=c(a,d.keyPairId,d.mechanism,null,d.publicKey);q.wrap(h,{result:function(a){b(m,function(){q.wrap(e,{result:function(b){A(h,a,e,b)},error:function(a){b(m,function(){a instanceof r&&k instanceof Ca&&a.setEntity(k);throw a;},g)}})},g)},error:function(a){b(m,function(){a instanceof r&&k instanceof Ca&&a.setEntity(k);throw a;},g)}})},g)}function A(c,h,M,A){b(m,function(){var f=a.getTokenFactory();k instanceof Ca?f.renewMasterToken(a,k,c,M,{result:function(c){b(m,
function(){var b=new ua(a,c),k=new e(c,d.keyPairId,h,A);return new za.KeyExchangeData(k,b,m)},g)},error:function(a){b(m,function(){a instanceof r&&a.setEntity(k);throw a;},g)}}):f.createMasterToken(a,k,c,M,{result:function(c){b(m,function(){var b=new ua(a,c),k=new e(c,d.keyPairId,h,A);return new za.KeyExchangeData(k,b,m)},g)},error:m.error})},g)}var g=this;b(m,function(){if(!(d instanceof h))throw new x("Key request data "+JSON.stringify(d)+" was not created by this factory.");this.generateSessionKeys(a,
{result:function(a){M(a.encryptionKey,a.hmacKey)},error:function(a){b(m,function(){a instanceof r&&k instanceof Ca&&a.setEntity(k);throw a;},g)}})},g)},getCryptoContext:function(d,k,m,g,M){var A=this;b(M,function(){if(!(k instanceof h))throw new x("Key request data "+JSON.stringify(k)+" was not created by this factory.");if(!(m instanceof e))throw new x("Key response data "+JSON.stringify(m)+" was not created by this factory.");var ba=k.keyPairId,f=m.keyPairId;if(ba!=f)throw(new X(a.KEYX_RESPONSE_REQUEST_MISMATCH,
"request "+ba+"; response "+f)).setEntity(g);f=k.privateKey;if(!f)throw(new X(a.KEYX_PRIVATE_KEY_MISSING,"request Asymmetric private key")).setEntity(g);var l=c(d,ba,k.mechanism,f,null);l.unwrap(m.encryptionKey,da.AES_CBC,ob,{result:function(a){l.unwrap(m.hmacKey,da.HMAC_SHA256,pb,{result:function(c){d.getEntityAuthenticationData(null,{result:function(h){b(M,function(){var b=h.getIdentity();return new ua(d,m.masterToken,b,a,c)},A)},error:function(a){b(M,function(){a instanceof r&&a.setEntity(g);throw a;
},A)}})},error:function(a){b(M,function(){a instanceof r&&a.setEntity(g);throw a;},A)}})},error:function(a){b(M,function(){a instanceof r&&a.setEntity(g);throw a;},A)}})},A)}})})();var hd,sc,id,jd,kd,tc;(function(){var c=sc="entityauthdata",m=id="mastertoken",h=jd="headerdata",k=kd="errordata",e=tc="signature";hd=function(n,t,g,p){function y(c,m,e){b(p,function(){var q=t[h];if(void 0!=q&&null!=q){if("string"!==typeof q)throw new d(a.JSON_PARSE_ERROR,"header/errormsg "+JSON.stringify(t));c?kb(n,c,
{result:function(c){uc(n,q,e,c,m,g,{result:function(h){b(p,function(){if(!h.isDecrypted())throw(new v(a.MESSAGE_MASTERTOKENBASED_VERIFICATION_FAILED)).setEntity(c);return h})},error:p.error})},error:p.error}):uc(n,q,e,null,m,g,{result:function(c){b(p,function(){if(!c.isDecrypted())throw(new v(a.MESSAGE_ENTITYDATABASED_VERIFICATION_FAILED)).setEntity(e);return c})},error:p.error})}else{var B=t[k];if(void 0!=B&&null!=B){if("string"!==typeof B)throw new d(a.JSON_PARSE_ERROR,"header/errormsg "+JSON.stringify(t));
ld(n,B,e,m,p)}else throw new d(a.JSON_PARSE_ERROR,JSON.stringify(t));}})}b(p,function(){var b=t[c],h=t[m],k=t[e];if(b&&"object"!==typeof b||h&&"object"!==typeof h||"string"!==typeof k)throw new d(a.JSON_PARSE_ERROR,"header/errormsg "+JSON.stringify(t));var g;try{g=N(k)}catch(B){throw new ea(a.HEADER_SIGNATURE_INVALID,"header/errormsg "+JSON.stringify(t),B);}b?Rc(n,b,{result:function(a){y(h,g,a)},error:p.error}):y(h,g,null)})}})();var tb,md,ld;(function(){function e(a,b,c){this.errordata=a;this.signature=
b;this.timestampSeconds=c}tb=J.Class.create({init:function(c,h,d,e,n,t,g,p,y,F){var na=this;b(F,function(){0>t&&(t=-1);if(0>e||e>R)throw new x("Message ID "+e+" is out of range.");if(!h)throw new ea(a.MESSAGE_ENTITY_NOT_FOUND);if(y)return S=y.timestampSeconds,Object.defineProperties(this,{entityAuthenticationData:{value:h,writable:!1,configurable:!1},recipient:{value:d,writable:!1,configurable:!1},timestampSeconds:{value:S,writable:!1,enumerable:!1,configurable:!1},messageId:{value:e,writable:!1,
configurable:!1},errorCode:{value:n,writable:!1,configurable:!1},internalCode:{value:t,writable:!1,configurable:!1},errorMessage:{value:g,writable:!1,configurable:!1},userMessage:{value:p,writable:!1,configurable:!1},errordata:{value:y.errordata,writable:!1,enumerable:!1,configurable:!1},signature:{value:y.signature,writable:!1,enumerable:!1,configurable:!1}}),this;var S=c.getTime()/1E3,ha={};d&&(ha.recipient=d);ha.timestamp=S;ha.messageid=e;ha.errorcode=n;0<t&&(ha.internalcode=t);g&&(ha.errormsg=
g);p&&(ha.usermsg=p);var B;try{B=c.getEntityAuthenticationFactory(h.scheme).getCryptoContext(c,h)}catch(T){throw T instanceof r&&(T.setEntity(h),T.setMessageId(e)),T;}ha=sa(JSON.stringify(ha),P);B.encrypt(ha,{result:function(a){b(F,function(){B.sign(a,{result:function(c){b(F,function(){Object.defineProperties(this,{entityAuthenticationData:{value:h,writable:!1,configurable:!1},recipient:{value:d,writable:!1,configurable:!1},timestampSeconds:{value:S,writable:!1,enumerable:!1,configurable:!1},messageId:{value:e,
writable:!1,configurable:!1},errorCode:{value:n,writable:!1,configurable:!1},internalCode:{value:t,writable:!1,configurable:!1},errorMessage:{value:g,writable:!1,configurable:!1},userMessage:{value:p,writable:!1,configurable:!1},errordata:{value:a,writable:!1,enumerable:!1,configurable:!1},signature:{value:c,writable:!1,enumerable:!1,configurable:!1}});return this},na)},error:function(a){b(F,function(){a instanceof r&&(a.setEntity(h),a.setMessageId(e));throw a;},na)}})},na)},error:function(a){b(F,
function(){a instanceof r&&(a.setEntity(h),a.setMessageId(e));throw a;},na)}})},na)},get timestamp(){return new Date(1E3*this.timestampSeconds)},toJSON:function(){var a={};a[sc]=this.entityAuthenticationData;a[kd]=l(this.errordata);a[tc]=l(this.signature);return a}});md=function(a,b,c,d,e,t,g,p,y){new tb(a,b,c,d,e,t,g,p,null,y)};ld=function(m,h,k,q,n){b(n,function(){if(!k)throw new ea(a.MESSAGE_ENTITY_NOT_FOUND);var t;try{var U=k.scheme,p=m.getEntityAuthenticationFactory(U);if(!p)throw new g(a.ENTITYAUTH_FACTORY_NOT_FOUND,
U);t=p.getCryptoContext(m,k)}catch(y){throw y instanceof r&&y.setEntity(k),y;}try{h=N(h)}catch(F){throw(new ea(a.HEADER_DATA_INVALID,h,F)).setEntity(k);}if(!h||0==h.length)throw(new ea(a.HEADER_DATA_MISSING,h)).setEntity(k);t.verify(h,q,{result:function(p){b(n,function(){if(!p)throw(new v(a.MESSAGE_VERIFICATION_FAILED)).setEntity(k);t.decrypt(h,{result:function(p){b(n,function(){var b=qa(p,P),t;try{t=JSON.parse(b)}catch(g){if(g instanceof SyntaxError)throw(new d(a.JSON_PARSE_ERROR,"errordata "+b,
g)).setEntity(k);throw g;}var M=void 0!==t.recipient?t.recipient:null,A=void 0!==t.timestamp?t.timestamp:null,y=parseInt(t.messageid),F=parseInt(t.errorcode),U=parseInt(t.internalcode),na=t.errormsg,f=t.usermsg;if(M&&"string"!==typeof M||A&&"number"!==typeof A||!y||y!=y||!F||F!=F||t.internalcode&&U!=U||na&&"string"!==typeof na||f&&"string"!==typeof f)throw(new d(a.JSON_PARSE_ERROR,"errordata "+b)).setEntity(k);if(0>y||y>R)throw(new ea(a.MESSAGE_ID_OUT_OF_RANGE,"errordata "+b)).setEntity(k);t=!1;for(var l in c)if(c[l]==
F){t=!0;break}t||(F=c.FAIL);if(U){if(0>U)throw(new ea(a.INTERNAL_CODE_NEGATIVE,"errordata "+b)).setEntity(k).setMessageId(y);}else U=-1;b=new e(h,q,A);new tb(m,k,M,y,F,U,na,f,b,n)})},error:function(a){b(n,function(){a instanceof r&&a.setEntity(k);throw a;})}})})},error:function(a){b(n,function(){a instanceof r&&a.setEntity(k);throw a;})}})})}})();var se=J.Class.create({getUserMessage:function(a,b){}}),Ob,nd,vc;(function(){function b(a,c){var d={},e=[],n;for(n=0;n<a.length;++n)d[a[n]]=!0;for(n=0;n<
c.length;++n)d[c[n]]&&e.push(c[n]);return e}vc=function(a,c){if(!a||!c)return null;var d=b(a.compressionAlgorithms,c.compressionAlgorithms),e=b(a.languages,c.languages);return new Ob(d,e)};Ob=J.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 Ob?u(this.compressionAlgorithms,a.compressionAlgorithms)&&u(this.languages,a.languages):!1},uniqueKey:function(){return this.compressionAlgorithms.join(":")+"|"+this.languages.join(":")}});nd=function(b){var c=b.compressionalgos,k=b.languages;if(c&&!(c instanceof Array)||k&&!(k instanceof Array))throw new d(a.JSON_PARSE_ERROR,"capabilities "+JSON.stringify(b));b=[];for(var e=0;c&&e<c.length;++e){var n=c[e];Ta[n]&&b.push(n)}return new Ob(b,
k)}})();var ub,od,uc,pd,qd;(function(){function c(a,b,d,h,k,e,n,m){this.user=a;this.sender=b;this.timestampSeconds=d;this.messageCryptoContext=h;this.headerdata=k;this.plaintext=e;this.signature=n;this.verified=m}function e(a,b,c,d,h,k,n,m,q,t,p,g,y,W,oa,w,F,U,f,ca,l,r,D,ra,gb){return{cryptoContext:{value:b,writable:!1,configurable:!1},user:{value:c,writable:!1,configurable:!1},entityAuthenticationData:{value:d,writable:!1,configurable:!1},masterToken:{value:h,writable:!1,configurable:!1},sender:{value:k,
writable:!1,configurable:!1},recipient:{value:n,writable:!1,configurable:!1},timestampSeconds:{value:m,writable:!1,enumerable:!1,configurable:!1},messageId:{value:q,writable:!1,configurable:!1},nonReplayableId:{value:U,writable:!1,configurable:!1},keyRequestData:{value:t,writable:!1,configurable:!1},keyResponseData:{value:p,writable:!1,configurable:!1},userAuthenticationData:{value:g,writable:!1,configurable:!1},userIdToken:{value:y,writable:!1,configurable:!1},serviceTokens:{value:W,writable:!1,
configurable:!1},peerMasterToken:{value:oa,writable:!1,configurable:!1},peerUserIdToken:{value:w,writable:!1,configurable:!1},peerServiceTokens:{value:F,writable:!1,configurable:!1},messageCapabilities:{value:l,writable:!1,configurable:!1},renewable:{value:f,writable:!1,enumerable:!1,configurable:!1},handshake:{value:ca,writable:!1,enumerable:!1,configurable:!1},headerdata:{value:r,writable:!1,enumerable:!1,configurable:!1},plaintext:{value:D,writable:!1,enumerable:!1,configurable:!1},signature:{value:ra,
writable:!1,enumerable:!1,configurable:!1},verified:{value:gb,writable:!1,enumerable:!1,configurable:!1}}}function h(b,c,d){if(d){if(c=b.getMslStore().getCryptoContext(d))return c;if(!d.isVerified()||!d.isDecrypted())throw new Ha(a.MASTERTOKEN_UNTRUSTED,d);return new ua(b,d)}d=c.scheme;var h=b.getEntityAuthenticationFactory(d);if(!h)throw new g(a.ENTITYAUTH_FACTORY_NOT_FOUND,d.name);return h.getCryptoContext(b,c)}function k(a,c,d){b(d,function(){if(c)ed(a,c,d);else return null})}function q(a,c,d,
h){b(h,function(){if(c)lb(a,c,d,h);else return null})}function n(a,c,d,h){b(h,function(){if(d)rd(a,c,d,h);else return null})}function t(c,h,k,e,n,m,q){function t(h,q,g){if(q>=h.length){var y=[],W;for(W in p)y.push(p[W]);g.result(y)}else{y=h[q];if("object"!==typeof y)throw new d(a.JSON_PARSE_ERROR,"headerdata "+m);ac(c,y,k,e,n,{result:function(a){b(g,function(){p[a.uniqueKey()]=a;t(h,q+1,g)})},error:function(a){g.error(a)}})}}var p={};b(q,function(){if(h){if(!(h instanceof Array))throw new d(a.JSON_PARSE_ERROR,
"headerdata "+m);t(h,0,q)}else return[]})}function U(c,h,k,e,n,m){function q(c,h,k){b(k,function(){var b=h.peermastertoken;if(b&&"object"!==typeof b)throw new d(a.JSON_PARSE_ERROR,"headerdata "+n);if(!b)return null;kb(c,b,k)})}function p(c,h,k,e){b(e,function(){var b=h.peeruseridtoken;if(b&&"object"!==typeof b)throw new d(a.JSON_PARSE_ERROR,"headerdata "+n);if(!b)return null;lb(c,b,k,e)})}b(m,function(){if(!c.isPeerToPeer())return{peerMasterToken:null,peerUserIdToken:null,peerServiceTokens:[]};q(c,
h,{result:function(a){b(m,function(){var d=k?k.masterToken:a;p(c,h,d,{result:function(k){b(m,function(){t(c,h.peerservicetokens,d,k,e,n,{result:function(c){b(m,function(){return{peerMasterToken:a,peerUserIdToken:k,peerServiceTokens:c}})},error:function(a){b(m,function(){a instanceof r&&(a.setEntity(d),a.setUser(k));throw a;})}})})},error:function(a){b(m,function(){a instanceof r&&a.setEntity(d);throw a;})}})})},error:m.error})})}function p(c,h,k,e){function n(a,d){b(e,function(){if(d>=a.length)return m;
dd(c,a[d],{result:function(c){b(e,function(){m.push(c);n(a,d+1)})},error:function(a){e.error(a)}})})}var m=[];b(e,function(){var b=h.keyrequestdata;if(!b)return m;if(!(b instanceof Array))throw new d(a.JSON_PARSE_ERROR,"headerdata "+k);n(b,0)})}var y=pd=J.Class.create({init:function(a,b,c,d,h,k,e,n,m,q,t){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:d,
writable:!1,configurable:!1},handshake:{value:h,writable:!1,configurable:!1},capabilities:{value:k,writable:!1,configurable:!1},keyRequestData:{value:e,writable:!1,configurable:!1},keyResponseData:{value:n,writable:!1,configurable:!1},userAuthData:{value:m,writable:!1,configurable:!1},userIdToken:{value:q,writable:!1,configurable:!1},serviceTokens:{value:t,writable:!1,configurable:!1}})}}),F=qd=J.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}})}});ub=J.Class.create({init:function(a,c,d,k,n,q,t){function p(y){b(t,function(){c=d?null:c;var p=k.nonReplayableId,F=k.renewable,U=k.handshake,W=k.capabilities,oa=k.recipient,w=k.messageId,ya=k.keyRequestData?k.keyRequestData:[],Sa=k.keyResponseData,f=k.userAuthData,ca=k.userIdToken,ba=k.serviceTokens?k.serviceTokens:[],l,D,ra;a.isPeerToPeer()?(l=n.peerMasterToken,D=n.peerUserIdToken,
ra=n.peerServiceTokens?n.peerServiceTokens:[]):(D=l=null,ra=[]);if(0>w||w>R)throw new x("Message ID "+w+" is out of range.");if(!c&&!d)throw new x("Message entity authentication data or master token must be provided.");var gb,Za;Sa?a.isPeerToPeer()?(gb=d,Za=Sa.masterToken):(gb=Sa.masterToken,Za=l):(gb=d,Za=l);if(ca&&(!gb||!ca.isBoundTo(gb)))throw new x("User ID token must be bound to a master token.");if(D&&(!Za||!D.isBoundTo(Za)))throw new x("Peer user ID token must be bound to a peer master token.");
ba.forEach(function(a){if(a.isMasterTokenBound()&&(!gb||!a.isBoundTo(gb)))throw new x("Master token bound service tokens must be bound to the provided master token.");if(a.isUserIdTokenBound()&&(!ca||!a.isBoundTo(ca)))throw new x("User ID token bound service tokens must be bound to the provided user ID token.");},this);ra.forEach(function(a){if(a.isMasterTokenBound()&&(!Za||!a.isBoundTo(Za)))throw new x("Master token bound peer service tokens must be bound to the provided peer master token.");if(a.isUserIdTokenBound()&&
(!D||!a.isBoundTo(D)))throw new x("User ID token bound peer service tokens must be bound to the provided peer user ID token.");},this);if(q){var wc=q.user,C=q.timestampSeconds,u=q.messageCryptoContext,va=q.headerdata,z=q.plaintext,va=e(a,u,wc,c,d,y,oa,C,w,ya,Sa,f,ca,ba,l,D,ra,p,F,U,W,va,z,q.signature,q.verified);Object.defineProperties(this,va);return this}var wc=ca?ca.user:null,C=a.getTime()/1E3,va={};y&&(va.sender=y);oa&&(va.recipient=oa);va.timestamp=C;va.messageid=w;va.nonreplayable="number"===
typeof p;"number"===typeof p&&(va.nonreplayableid=p);va.renewable=F;va.handshake=U;W&&(va.capabilities=W);0<ya.length&&(va.keyrequestdata=ya);Sa&&(va.keyresponsedata=Sa);f&&(va.userauthdata=f);ca&&(va.useridtoken=ca);0<ba.length&&(va.servicetokens=ba);l&&(va.peermastertoken=l);D&&(va.peeruseridtoken=D);0<ra.length&&(va.peerservicetokens=ra);var u;try{u=h(a,c,d)}catch(v){throw v instanceof r&&(v.setEntity(d),v.setEntity(c),v.setUser(ca),v.setUser(f),v.setMessageId(w)),v;}var z=sa(JSON.stringify(va),
P);u.encrypt(z,{result:function(h){b(t,function(){u.sign(h,{result:function(k){b(t,function(){var b=e(a,u,wc,c,d,y,oa,C,w,ya,Sa,f,ca,ba,l,D,ra,p,F,U,W,h,z,k,!0);Object.defineProperties(this,b);return this},g)},error:function(a){b(t,function(){a instanceof r&&(a.setEntity(d),a.setEntity(c),a.setUser(ca),a.setUser(f),a.setMessageId(w));throw a;},g)}})},g)},error:function(a){b(t,function(){a instanceof r&&(a.setEntity(d),a.setEntity(c),a.setUser(ca),a.setUser(f),a.setMessageId(w));throw a;},g)}})},g)}
var g=this;b(t,function(){q?p(q.sender):d?a.getEntityAuthenticationData(null,{result:function(a){a=a.getIdentity();p(a)},error:t.error}):p(null)},g)},get timestamp(){return new Date(1E3*this.timestampSeconds)},isDecrypted:function(){return this.plaintext?!0:!1},isVerified:function(){return this.verified},isEncrypting:function(){return this.masterToken||this.entityAuthenticationData.scheme.encrypts},isRenewable:function(){return this.renewable},isHandshake:function(){return this.handshake},toJSON:function(){var a=
{};this.masterToken?a[id]=this.masterToken:a[sc]=this.entityAuthenticationData;a[jd]=l(this.headerdata);a[tc]=l(this.signature);return a}});od=function(a,b,c,d,h,k){new ub(a,b,c,d,h,null,k)};uc=function(e,m,g,B,f,M,A){function ba(h,m,f,T,ba,W){b(A,function(){if(f){var oa;try{oa=JSON.parse(W)}catch(w){if(w instanceof SyntaxError)throw(new d(a.JSON_PARSE_ERROR,"headerdata "+W,w)).setEntity(B).setEntity(g);throw w;}var ya=parseInt(oa.messageid);if(!ya||ya!=ya)throw(new d(a.JSON_PARSE_ERROR,"headerdata "+
W)).setEntity(B).setEntity(g);if(0>ya||ya>R)throw(new ea(a.MESSAGE_ID_OUT_OF_RANGE,"headerdata "+W)).setEntity(B).setEntity(g);var Sa=B?oa.sender:null;if(B&&(!Sa||"string"!==typeof Sa))throw(new d(a.JSON_PARSE_ERROR,"headerdata "+W)).setEntity(B).setEntity(g).setMessageId(ya);var l="undefined"!==oa.recipient?oa.recipient:null;if(l&&"string"!==typeof l)throw(new d(a.JSON_PARSE_ERROR,"headerdata "+W)).setEntity(B).setEntity(g).setMessageId(ya);var ca="undefined"!==oa.timestamp?oa.timestamp:null;if(ca&&
"number"!==typeof ca)throw(new d(a.JSON_PARSE_ERROR,"headerdata "+W)).setEntity(B).setEntity(g).setMessageId(ya);var S=oa.keyresponsedata;if(S&&"object"!==typeof S)throw(new d(a.JSON_PARSE_ERROR,"headerdata "+W)).setEntity(B).setEntity(g).setMessageId(ya);var x=A;A={result:function(a){x.result(a)},error:function(a){a instanceof r&&(a.setEntity(B),a.setEntity(g),a.setMessageId(ya));x.error(a)}};k(e,S,{result:function(k){b(A,function(){var w=!e.isPeerToPeer()&&k?k.masterToken:B,ra=oa.useridtoken;if(ra&&
"object"!==typeof ra)throw new d(a.JSON_PARSE_ERROR,"headerdata "+W);q(e,ra,w,{result:function(q){b(A,function(){var ra=oa.userauthdata;if(ra&&"object"!==typeof ra)throw new d(a.JSON_PARSE_ERROR,"headerdata "+W);n(e,w,ra,{result:function(n){b(A,function(){var ra;if(n){var S=n.scheme,Jb=e.getUserAuthenticationFactory(S);if(!Jb)throw(new Z(a.USERAUTH_FACTORY_NOT_FOUND,S)).setUser(q).setUser(n);S=B?B.identity:g.getIdentity();ra=Jb.authenticate(e,S,n,q)}else ra=q?q.user:null;t(e,oa.servicetokens,w,q,
M,W,{result:function(w){b(A,function(){var t=void 0!==oa.nonreplayableid?parseInt(oa.nonreplayableid):null,S=oa.renewable,Jb=void 0!==oa.handshake?oa.handshake:!1;if(t!=t||"boolean"!==typeof S||"boolean"!==typeof Jb)throw new d(a.JSON_PARSE_ERROR,"headerdata "+W);if(0>t||t>R)throw new ea(a.NONREPLAYABLE_ID_OUT_OF_RANGE,"headerdata "+W);var Za=null,x=oa.capabilities;if(x){if("object"!==typeof x)throw new d(a.JSON_PARSE_ERROR,"headerdata "+W);Za=nd(x)}p(e,oa,W,{result:function(a){U(e,oa,k,M,W,{result:function(d){b(A,
function(){var b=d.peerMasterToken,p=d.peerUserIdToken,W=d.peerServiceTokens,M=new y(l,ya,t,S,Jb,Za,a,k,n,q,w),b=new F(b,p,W),p=new c(ra,Sa,ca,h,m,f,T,ba);new ub(e,g,B,M,b,p,A)})},error:A.error})},error:function(a){b(A,function(){a instanceof r&&(a.setUser(q),a.setUser(n));throw a;})}})})},error:function(a){b(A,function(){a instanceof r&&(a.setEntity(w),a.setUser(q),a.setUser(n));throw a;})}})})},error:A.error})})},error:A.error})})},error:A.error})}else{var S=new y(null,1,null,!1,!1,null,[],null,
null,null,[]),te=new F(null,null,[]),ra=new c(null,null,null,h,m,f,T,ba,!1);new ub(e,g,B,S,te,ra,A)}})}b(A,function(){g=B?null:g;if(!g&&!B)throw new ea(a.MESSAGE_ENTITY_NOT_FOUND);var c=m;try{m=N(c)}catch(d){throw new ea(a.HEADER_DATA_INVALID,c,d);}if(!m||0==m.length)throw new ea(a.HEADER_DATA_MISSING,c);var k;try{k=h(e,g,B)}catch(n){throw n instanceof r&&(n.setEntity(B),n.setEntity(g)),n;}k.verify(m,f,{result:function(a){b(A,function(){a?k.decrypt(m,{result:function(c){b(A,function(){var b=qa(c,
P);ba(k,m,c,f,a,b)})},error:A.error}):ba(k,null,null,f,a,null)})},error:A.error})})}})();var yc,sd,td;(function(){function c(a,b){this.payload=a;this.signature=b}yc=J.Class.create({init:function(a,c,d,e,n,t,g,p){var y=this;b(p,function(){if(0>a||a>R)throw new x("Sequence number "+a+" is outside the valid range.");if(0>c||c>R)throw new x("Message ID "+c+" is outside the valid range.");if(g)return Object.defineProperties(this,{sequenceNumber:{value:a,writable:!1,configurable:!1},messageId:{value:c,
writable:!1,configurable:!1},compressionAlgo:{value:e,writable:!1,configurable:!1},data:{value:n,writable:!1,configurable:!1},endofmsg:{value:d,writable:!1,enumerable:!1,configurable:!1},payload:{value:g.payload,writable:!1,enumerable:!1,configurable:!1},signature:{value:g.signature,writable:!1,enumerable:!1,configurable:!1}}),this;var F;e?(F=zc(e,n),F||(e=null,F=n)):(e=null,F=n);var f={};f.sequencenumber=a;f.messageid=c;d&&(f.endofmsg=d);e&&(f.compressionalgo=e);f.data=l(F);F=sa(JSON.stringify(f),
P);t.encrypt(F,{result:function(g){b(p,function(){t.sign(g,{result:function(t){b(p,function(){Object.defineProperties(this,{sequenceNumber:{value:a,writable:!1,configurable:!1},messageId:{value:c,writable:!1,configurable:!1},compressionAlgo:{value:e,writable:!1,configurable:!1},data:{value:n,writable:!1,configurable:!1},endofmsg:{value:d,writable:!1,enumerable:!1,configurable:!1},payload:{value:g,writable:!1,enumerable:!1,configurable:!1},signature:{value:t,writable:!1,enumerable:!1,configurable:!1}});
return this},y)},error:function(a){p.error(a)}})},y)},error:function(a){p.error(a)}})},y)},isEndOfMessage:function(){return this.endofmsg},toJSON:function(){var a={};a.payload=l(this.payload);a.signature=l(this.signature);return a}});sd=function(a,b,c,d,e,t,g){new yc(a,b,c,d,e,t,null,g)};td=function(e,h,k){b(k,function(){var q=e.payload,n=e.signature;if(!q||"string"!==typeof q||"string"!==typeof n)throw new d(a.JSON_PARSE_ERROR,"payload chunk "+JSON.stringify(e));var t,g;try{t=N(q)}catch(p){throw new ea(a.PAYLOAD_INVALID,
"payload chunk "+JSON.stringify(e),p);}try{g=N(n)}catch(y){throw new ea(a.PAYLOAD_SIGNATURE_INVALID,"payload chunk "+JSON.stringify(e),y);}h.verify(t,g,{result:function(e){b(k,function(){if(!e)throw new v(a.PAYLOAD_VERIFICATION_FAILED);h.decrypt(t,{result:function(e){b(k,function(){var b=qa(e,P),n;try{n=JSON.parse(b)}catch(m){if(m instanceof SyntaxError)throw new d(a.JSON_PARSE_ERROR,"payload chunk payload "+b,m);throw m;}var q=parseInt(n.sequencenumber),p=parseInt(n.messageid),y=n.endofmsg,F=n.compressionalgo;
n=n.data;if(!q||q!=q||!p||p!=p||y&&"boolean"!==typeof y||F&&"string"!==typeof F||"string"!==typeof n)throw new d(a.JSON_PARSE_ERROR,"payload chunk payload "+b);if(0>q||q>R)throw new r(a.PAYLOAD_SEQUENCE_NUMBER_OUT_OF_RANGE,"payload chunk payload "+b);if(0>p||p>R)throw new r(a.PAYLOAD_MESSAGE_ID_OUT_OF_RANGE,"payload chunk payload "+b);y||(y=!1);if(F&&!Ta[F])throw new ea(a.UNIDENTIFIED_COMPRESSION,F);var f;try{f=N(n)}catch(l){throw new ea(a.PAYLOAD_DATA_CORRUPT,n,l);}if(f&&0!=f.length)b=F?bc(F,f):
f;else{if(0<n.length)throw new ea(a.PAYLOAD_DATA_CORRUPT,n);if(y)b=new Uint8Array(0);else throw new ea(a.PAYLOAD_DATA_MISSING,n);}f=new c(t,g);new yc(q,p,y,F,b,h,f,k)})},error:function(a){k.error(a)}})})},error:function(a){k.error(a)}})})}})();var cc,vb,Fb,wb,ud,vd;(function(){function c(d,h,k,e,m){function q(){b(m,function(){f>=h.length&&(f=0,++g);if(g>=l.length){if(B)throw B;throw new X(a.KEYX_FACTORY_NOT_FOUND,JSON.stringify(h));}var c=l[g],k=h[f];c.scheme!=k.keyExchangeScheme?(++f,q()):c.generateResponse(d,
k,T,{result:function(a){m.result(a)},error:function(a){b(m,function(){if(!(a instanceof r))throw a;B=a;++f;q()})}})})}var g=0,f=0,l=d.getKeyExchangeFactories(),B,T=k?k:e;q()}function d(a,h,k,e,m){b(m,function(){var d=h.keyRequestData;if(h.isRenewable()&&0<d.length)e?e.isRenewable(null)||e.isExpired(null)?c(a,d,e,null,m):a.getTokenFactory().isNewestMasterToken(a,e,{result:function(h){b(m,function(){if(h)return null;c(a,d,e,null,m)})},error:m.error}):c(a,d,null,k.getIdentity(),m);else return null})}
function h(c,d,h,k){b(k,function(){var b=d.userIdToken,e=d.userAuthenticationData,m=d.messageId;if(b&&b.isVerified()){if(b.isRenewable(null)&&d.isRenewable()||b.isExpired(null)||!b.isBoundTo(h)){e=c.getTokenFactory();e.renewUserIdToken(c,b,h,k);return}}else if(d.isRenewable()&&h&&e){b=d.user;if(!b){var b=e.scheme,q=c.getUserAuthenticationFactory(b);if(!q)throw(new Z(a.USERAUTH_FACTORY_NOT_FOUND,b)).setEntity(h).setUser(e).setMessageId(m);b=q.authenticate(c,h.identity,e,null)}e=c.getTokenFactory();
e.createUserIdToken(c,b,h,k);return}return b})}var k=new Uint8Array(0),e=vb=function(a){if(0>a||a>R)throw new x("Message ID "+a+" is outside the valid range.");return a==R?0:a+1};Fb=function(a){if(0>a||a>R)throw new x("Message ID "+a+" is outside the valid range.");return 0==a?R:a-1};wb=function(a,c,d,h,k,e){b(e,function(){if(void 0==k||null==k){var m=a.getRandom();do k=m.nextLong();while(0>k||k>R)}else if(0>k||k>R)throw new x("Message ID "+k+" is outside the valid range.");a.getEntityAuthenticationData(null,
{result:function(m){b(e,function(){var b=a.getMessageCapabilities();return new cc(a,h,k,b,m,c,d,null,null,null,null,null)})},error:function(a){e.error(a)}})})};ud=function(a,c,k){b(k,function(){function g(a){b(k,function(){a instanceof r&&(a.setEntity(y),a.setEntity(f),a.setUser(l),a.setUser(S),a.setMessageId(B));throw a;})}var y=c.masterToken,f=c.entityAuthenticationData,l=c.userIdToken,S=c.userAuthenticationData,D=y?y.identity:f.getIdentity(),B=c.messageId,T=e(B);d(a,c,f,y,{result:function(d){b(k,
function(){var e=d?d.keyResponseData.masterToken:e=y;a.getEntityAuthenticationData(null,{result:function(m){b(k,function(){h(a,c,e,{result:function(h){b(k,function(){l=h;var b=vc(c.messageCapabilities,a.getMessageCapabilities()),k=c.keyResponseData,e=c.serviceTokens;return a.isPeerToPeer()?new cc(a,D,T,b,m,k?k.masterToken:c.peerMasterToken,c.peerUserIdToken,c.peerServiceTokens,y,l,e,d):new cc(a,D,T,b,m,k?k.masterToken:y,l,e,null,null,null,d)})},error:g})})},error:g})})},error:g})})};vd=function(a,
c,d,h,k,m){b(m,function(){a.getEntityAuthenticationData(null,{result:function(g){b(m,function(){var b;if(void 0!=d&&null!=d)b=e(d);else{var f=a.getRandom();do b=f.nextLong();while(0>b||b>R)}md(a,g,c,b,h.responseCode,h.internalCode,h.message,k,m)})},error:function(a){m.error(a)}})})};cc=J.Class.create({init:function(a,b,c,d,h,k,e,m,q,g,f,M){if(!a.isPeerToPeer()&&(q||g))throw new x("Cannot set peer master token or peer user ID token when not in peer-to-peer mode.");var A;A=M&&!a.isPeerToPeer()?M.keyResponseData.masterToken:
k;var l={};a.getMslStore().getServiceTokens(A,e).forEach(function(a){l[a.name]=a},this);m&&m.forEach(function(a){l[a.name]=a},this);var D,r,gc={};a.isPeerToPeer()&&(D=q,r=g,m=M?M.keyResponseData.masterToken:q,a.getMslStore().getServiceTokens(m,g).forEach(function(a){gc[a.name]=a},this),f&&f.forEach(function(a){gc[a.name]=a},this));Object.defineProperties(this,{_ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},_entityAuthData:{value:h,writable:!1,enumerable:!1,configurable:!1},_masterToken:{value:k,
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:M,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:l,writable:!1,enumerable:!1,configurable:!1},_peerMasterToken:{value:D,writable:!0,enumerable:!1,configurable:!1},_peerUserIdToken:{value:r,writable:!0,enumerable:!1,configurable:!1},_peerServiceTokens:{value:gc,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||this._entityAuthData.scheme.encrypts},willEncryptPayloads:function(){return this._masterToken||!this._ctx.isPeerToPeer()&&this._keyExchangeData||this._entityAuthData.scheme.encrypts},willIntegrityProtectHeader:function(){return this._masterToken||this._entityAuthData.scheme.protectsIntegrity},
willIntegrityProtectPayloads:function(){return this._masterToken||!this._ctx.isPeerToPeer()&&this._keyExchangeData||this._entityAuthData.scheme.protectsIntegrity},getHeader:function(c){b(c,function(){var b=this._keyExchangeData?this._keyExchangeData.keyResponseData:null,d=[],h;for(h in this._serviceTokens)d.push(this._serviceTokens[h]);var k=[],e;for(e in this._keyRequestData)k.push(this._keyRequestData[e]);if(this._nonReplayable){if(!this._masterToken)throw new ea(a.NONREPLAYABLE_MESSAGE_REQUIRES_MASTERTOKEN);
e=this._ctx.getMslStore().getNonReplayableId(this._masterToken)}else e=null;b=new pd(this._recipient,this._messageId,e,this._renewable,this._handshake,this._capabilities,k,b,this._userAuthData,this._userIdToken,d);d=[];for(h in this._peerServiceTokens)d.push(this._peerServiceTokens[h]);h=new qd(this._peerMasterToken,this._peerUserIdToken,d);od(this._ctx,this._entityAuthData,this._masterToken,b,h,c)},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 x("User ID token must be bound to master token.");if(this._keyExchangeData&&!this._ctx.isPeerToPeer())throw new x("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 r)throw new x("Invalid master token and user ID token combination despite checking above.",d);throw d;}var h=[],k;for(k in this._serviceTokens)h.push(this._serviceTokens[k]);h.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,c){var d=this;b(c,function(){if(!this._ctx.isPeerToPeer()&&null!=this._userIdToken||this._ctx.isPeerToPeer()&&null!=this._peerUserIdToken)throw new x("User ID token or peer user ID token already exists for the remote user.");var h;h=this._keyExchangeData?this._keyExchangeData.keyResponseData.masterToken:this._ctx.isPeerToPeer()?this._peerMasterToken:this._masterToken;if(!h)throw new x("User ID token or peer user ID token cannot be created because no corresponding master token exists.");
this._ctx.getTokenFactory().createUserIdToken(this._ctx,a,h,{result:function(a){b(c,function(){this._ctx.isPeerToPeer()?this._peerUserIdToken=a:(this._userIdToken=a,this._userAuthData=null);return!0},d)},error:function(a){c.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 ea(a.SERVICETOKEN_MASTERTOKEN_MISMATCH,"st "+JSON.stringify(b)+"; mt "+JSON.stringify(c))).setEntity(c);if(b.isUserIdTokenBound()&&!b.isBoundTo(this._userIdToken))throw(new ea(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,c){var d=this;b(c,function(){var h=this._serviceTokens[a];if(!h)return this;var e=h.isMasterTokenBound()?this._masterToken:null,h=h.isUserIdTokenBound()?this._userIdToken:null;hb(this._ctx,a,k,e,h,!1,null,new Lb,{result:function(a){b(c,function(){return this.addServiceToken(a)},d)},error:function(a){a instanceof r&&(a=new x("Failed to create and add empty service token to message.",
a));c.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 x("Cannot set peer master token or peer user ID token when not in peer-to-peer mode.");if(c&&!b)throw new x("Peer master token cannot be null when setting peer user ID token.");if(c&&
!c.isBoundTo(b))throw(new ea(a.USERIDTOKEN_MASTERTOKEN_MISMATCH,"uit "+c+"; mt "+b)).setEntity(b).setUser(c);var d;try{d=this._ctx.getMslStore().getServiceTokens(b,c)}catch(h){if(h instanceof r)throw new x("Invalid peer master token and user ID token combination despite proper check.",h);throw h;}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 x("Cannot set peer service tokens when not in peer-to-peer mode.");if(b.isMasterTokenBound()&&!b.isBoundTo(this._peerMasterToken))throw(new ea(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 ea(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,
c){var d=this;b(c,function(){var h=this._peerServiceTokens[a];if(!h)return this;var e=h.isMasterTokenBound()?this._peerMasterToken:null,h=h.isUserIdTokenBound()?this._peerUserIdToken:null;hb(this._ctx,a,k,e,h,!1,null,new Lb,{result:function(a){b(c,function(){return this.addPeerServiceToken(a)},d)},error:function(a){a instanceof r&&(a=new x("Failed to create and add empty peer service token to message.",a));c.error(a)}})},d)},getPeerServiceTokens:function(){var a=[],b;for(b in this._peerServiceTokens)a.push(this._peerServiceTokens[b]);
return a}})})();var wd;(function(){function a(b,c){return c[b]?c[b]:c[""]}function c(a){var b=a.builder.getKeyExchangeData();return b&&!a.ctx.isPeerToPeer()?b.keyResponseData.masterToken:a.builder.getMasterToken()}wd=J.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 c(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
ea)return!1;throw b;}},addPeerServiceToken:function(a){try{return this.builder.addPeerServiceToken(a),!0}catch(b){if(b instanceof ea)return!1;throw b;}},addUnboundPrimaryServiceToken:function(c,d,e,m,g){var f=this;b(g,function(){var p=a(c,this.cryptoContexts);if(!p)return!1;hb(this.ctx,c,d,null,null,e,m,p,{result:function(a){b(g,function(){try{this.builder.addServiceToken(a)}catch(b){if(b instanceof ea)throw new x("Service token bound to incorrect authentication tokens despite being unbound.",b);
throw b;}return!0},f)},error:function(a){g.error(a)}})},f)},addUnboundPeerServiceToken:function(c,d,e,m,g){var f=this;b(g,function(){var p=a(c,this.cryptoContexts);if(!p)return!1;hb(this.ctx,c,d,null,null,e,m,p,{result:function(a){b(g,function(){try{this.builder.addPeerServiceToken(a)}catch(b){if(b instanceof ea)throw new x("Service token bound to incorrect authentication tokens despite being unbound.",b);throw b;}return!0},f)},error:function(a){g.error(a)}})},f)},addMasterBoundPrimaryServiceToken:function(d,
k,e,g,t){var f=this;b(t,function(){var p=c(this);if(!p)return!1;var y=a(d,this.cryptoContexts);if(!y)return!1;hb(this.ctx,d,k,p,null,e,g,y,{result:function(a){b(t,function(){try{this.builder.addServiceToken(a)}catch(b){if(b instanceof ea)throw new x("Service token bound to incorrect authentication tokens despite setting correct master token.",b);throw b;}return!0},f)},error:function(a){t.error(a)}})},f)},addMasterBoundPeerServiceToken:function(c,d,e,m,g){var f=this;b(g,function(){var p=this.builder.getPeerMasterToken();
if(!p)return!1;var y=a(c,this.cryptoContexts);if(!y)return!1;hb(this.ctx,c,d,p,null,e,m,y,{result:function(a){b(g,function(){try{this.builder.addPeerServiceToken(a)}catch(b){if(b instanceof ea)throw new x("Service token bound to incorrect authentication tokens despite setting correct master token.",b);throw b;}return!0},f)},error:function(a){g.error(a)}})},f)},addUserBoundPrimaryServiceToken:function(d,k,e,g,t){var f=this;b(t,function(){var p=c(this);if(!p)return!1;var y=this.builder.getUserIdToken();
if(!y)return!1;var l=a(d,this.cryptoContexts);if(!l)return!1;hb(this.ctx,d,k,p,y,e,g,l,{result:function(a){b(t,function(){try{this.builder.addServiceToken(a)}catch(b){if(b instanceof ea)throw new x("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){t.error(a)}})},f)},addUserBoundPeerServiceToken:function(c,d,e,m,g){var f=this;b(g,function(){var p=this.builder.getPeerMasterToken();if(!p)return!1;
var y=this.builder.getPeerUserIdToken();if(!y)return!1;var l=a(c,this.cryptoContexts);if(!l)return!1;hb(this.ctx,c,d,p,y,e,m,l,{result:function(a){b(g,function(){try{this.builder.addPeerServiceToken(a)}catch(b){if(b instanceof ea)throw new x("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){g.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,c){b(c,function(){for(var b=this.builder.getServiceTokens(),d=0;d<b.length;++d)if(b[d].name==a){this.builder.deleteServiceToken(a,{result:function(){c.result(!0)},error:function(a){c.error(a)}});return}return!1},
this)},deletePeerServiceToken:function(a,c){b(c,function(){for(var b=this.builder.getPeerServiceTokens(),d=0;d<b.length;++d)if(b[d].name==a){this.builder.deletePeerServiceToken(a,{result:function(){c.result(!0)},error:function(a){c.error(a)}});return}return!1},this)}})})();var xd,yd;(function(){function c(d,h,k,e){b(e,function(){function c(){b(e,function(){if(S>=k.length){if(D)throw D;throw new X(a.KEYX_RESPONSE_REQUEST_MISMATCH,JSON.stringify(k));}var h=k[S];y!=h.keyExchangeScheme?(++S,c()):l.getCryptoContext(d,
h,f,g,{result:e.result,error:function(a){b(e,function(){if(!(a instanceof r))throw a;D=a;++S;c()})}})})}var g=h.masterToken,f=h.keyResponseData;if(!f)return null;var p=f.masterToken;if(p.isDecrypted())return new ua(d,p);var y=f.keyExchangeScheme,l=d.getKeyExchangeFactory(y);if(!l)throw new X(a.KEYX_FACTORY_NOT_FOUND,y);var D,S=0;c()})}xd=$c.extend({init:function(b,h,k,g,n,f,l){var p=this;e(l,function(){function e(){p._ready=!0;p._readyQueue.add(!0)}function l(a,b){try{var c=b.masterToken;a.getTokenFactory().isMasterTokenRevoked(a,
c,{result:function(d){d?(p._errored=(new Ha(d,c)).setUser(b.userIdToken).setUser(b.userAuthenticationData).setMessageId(b.messageId),e()):U(a,b)},error:function(a){a instanceof r&&(a.setEntity(b.masterToken),a.setUser(b.userIdToken),a.setUser(b.userAuthenticationData),a.setMessageId(b.messageId));p._errored=a;e()}})}catch(d){d instanceof r&&(d.setEntity(b.masterToken),d.setUser(b.userIdToken),d.setUser(b.userAuthenticationData),d.setMessageId(b.messageId)),p._errored=d,e()}}function U(a,b){try{var c=
b.masterToken,d=b.userIdToken;d?a.getTokenFactory().isUserIdTokenRevoked(a,c,d,{result:function(h){h?(p._errored=(new MslUserIdTokenException(h,d)).setEntity(c).setUser(d).setMessageId(b.messageId),e()):S(a,b)},error:function(a){a instanceof r&&(a.setEntity(b.masterToken),a.setUser(b.userIdToken),a.setUser(b.userAuthenticationData),a.setMessageId(b.messageId));p._errored=a;e()}}):S(a,b)}catch(h){h instanceof r&&(h.setEntity(b.masterToken),h.setUser(b.userIdToken),h.setUser(b.userAuthenticationData),
h.setMessageId(b.messageId)),p._errored=h,e()}}function S(b,c){try{var d=c.masterToken;d.isExpired(null)?c.isRenewable()&&0!=c.keyRequestData.length?b.getTokenFactory().isMasterTokenRenewable(b,d,{result:function(a){a?(p._errored=(new ea(a,"Master token is expired and not renewable.")).setEntity(d).setUser(c.userIdToken).setUser(c.userAuthenticationData).setMessageId(c.messageId),e()):ha(b,c)},error:function(a){a instanceof r&&(a.setEntity(c.masterToken),a.setUser(c.userIdToken),a.setUser(c.userAuthenticationData),
a.setMessageId(c.messageId));p._errored=a;e()}}):(p._errored=(new ea(a.MESSAGE_EXPIRED,JSON.stringify(c))).setEntity(d).setUser(c.userIdToken).setUser(c.userAuthenticationData).setMessageId(c.messageId),e()):ha(b,c)}catch(h){h instanceof r&&(h.setEntity(c.masterToken),h.setUser(c.userIdToken),h.setUser(c.userAuthenticationData),h.setMessageId(c.messageId)),p._errored=h,e()}}function ha(b,c){try{var d=c.masterToken,h=c.nonReplayableId;"number"===typeof h?d?b.getTokenFactory().acceptNonReplayableId(b,
d,h,{result:function(a){a&&(p._errored=(new ea(a,JSON.stringify(c))).setEntity(d).setUser(c.userIdToken).setUser(c.userAuthenticationData).setMessageId(c.messageId));e()},error:function(a){a instanceof r&&(a.setEntity(d),a.setUser(c.userIdToken),a.setUser(c.userAuthenticationData),a.setMessageId(c.messageId));p._errored=a;e()}}):(p._errored=(new ea(a.INCOMPLETE_NONREPLAYABLE_MESSAGE,JSON.stringify(c))).setEntity(c.entityAuthenticationData).setUser(c.userIdToken).setUser(c.userAuthenticationData).setMessageId(c.messageId),
e()):e()}catch(k){k instanceof r&&(k.setEntity(c.masterToken),k.setEntity(c.entityAuthenticationData),k.setUser(c.userIdToken),k.setUser(c.userAuthenticationData),k.setMessageId(c.messageId)),p._errored=k,e()}}var B={_source:{value:h,writable:!1,enumerable:!1,configurable:!1},_parser:{value:void 0,writable:!0,enumerable:!1,configurable:!1},_charset:{value:k,writable:!1,enumerable:!1,configurable:!1},_remainingData:{value:"",writable:!0,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 K,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,B);ad(p._source,f,{result:function(h){p._json=h;p._jsonIndex=0;null===p._json?(p._errored=new d(a.MESSAGE_DATA_MISSING),e()):hd(b,p._json[p._jsonIndex++],n,{result:function(d){p._header=d;if(p._header instanceof tb)p._keyxCryptoContext=null,p._cryptoContext=null,e();else{var h=p._header;c(b,h,g,{result:function(c){try{p._keyxCryptoContext=
c;b.isPeerToPeer()||!p._keyxCryptoContext?p._cryptoContext=h.cryptoContext:p._cryptoContext=p._keyxCryptoContext;try{if(h.isHandshake()&&(!h.isRenewable()||0==h.keyRequestData.length))throw new ea(a.HANDSHAKE_DATA_MISSING,JSON.stringify(h));try{var d=h.masterToken;d&&(b.isPeerToPeer()||d.isVerified())?l(b,h):ha(b,h)}catch(k){k instanceof r&&(k.setEntity(h.masterToken),k.setUser(h.userIdToken),k.setUser(h.userAuthenticationData),k.setMessageId(h.messageId)),p._errored=k,e()}}catch(g){g instanceof r&&
(g.setEntity(h.masterToken),g.setEntity(h.entityAuthenticationData),g.setUser(h.userIdToken),g.setUser(h.userAuthenticationData),g.setMessageId(h.messageId)),p._errored=g,e()}}catch(q){q instanceof r&&(q.setEntity(h.masterToken),q.setEntity(h.entityAuthenticationData),q.setUser(h.userIdToken),q.setUser(h.userAuthenticationData),q.setMessageId(h.messageId)),p._errored=q,e()}},error:function(a){a instanceof r&&(a.setEntity(h.masterToken),a.setEntity(h.entityAuthenticationData),a.setUser(h.userIdToken),
a.setUser(h.userAuthenticationData),a.setMessageId(h.messageId));p._errored=a;e()}})}},error:function(a){p._errored=a;e()}})},timeout:function(){p._timedout=!0;e()},error:function(a){p._errored=a;e()}});return this},p)},nextJsonObject:function(b,c){var k=this;e(c,function(){function g(a){e(a,function(){var c;if(this._jsonIndex<this._json.length)return c=this._json[this._jsonIndex++];ad(this._source,b,{result:function(b){b&&b.length&&0<b.length?(b.forEach(function(a){this._json.push(a)}),g(a)):(this._eom=
!0,a.result(null))},timeout:a.timeout,error:a.error})},k)}if(!this.getMessageHeader())throw new x("Read attempted with error message.");if(this._eom)return null;g({result:function(b){e(c,function(){if(!b)return null;if("object"!==typeof b)throw new d(a.MESSAGE_FORMAT_ERROR);return b},k)},timeout:c.timeout,error:c.error})},k)},nextData:function(b,c){var k=this;e(c,function(){var g=this.getMessageHeader();if(!g)throw new x("Read attempted with error message.");if(-1!=this._payloadIndex&&this._payloadIndex<
this._payloads.length)return this._payloads[this._payloadIndex++];if(this._eom)return null;this.nextJsonObject(b,{result:function(b){e(c,function(){if(!b)return null;td(b,this._cryptoContext,{result:function(b){e(c,function(){var c=g.masterToken,d=g.entityAuthenticationData,h=g.userIdToken,k=g.getUserAuthenticationData;if(b.messageId!=g.messageId)throw(new ea(a.PAYLOAD_MESSAGE_ID_MISMATCH,"payload mid "+b.messageId+" header mid "+g.messageId)).setEntity(c).setEntity(d).setUser(h).setUser(k);if(b.sequenceNumber!=
this._payloadSequenceNumber)throw(new ea(a.PAYLOAD_SEQUENCE_NUMBER_MISMATCH,"payload seqno "+b.sequenceNumber+" expected seqno "+this._payloadSequenceNumber)).setEntity(c).setEntity(d).setUser(h).setUser(k);++this._payloadSequenceNumber;null==this._handshake&&(this._handshake=g.isRenewable()&&0<g.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},k)},error:function(b){b instanceof SyntaxError&&
(b=new d(a.JSON_PARSE_ERROR,"payloadchunk",b));c.error(b)}})},k)},timeout:c.timeout,error:c.error})},k)},isReady:function(a){function c(){e(a,function(){if(this._aborted)return!1;if(this._timedout)a.timeout();else{if(this._errored)throw this._errored;return!0}},d)}var d=this;e(a,function(){this._ready?c():this._readyQueue.poll(-1,{result:function(b){e(a,function(){if(void 0===b)return!1;c()},d)},timeout:function(){b(a,function(){throw new x("Timeout while waiting for MessageInputStream.isReady() despite no timeout being specified.");
})},error:function(b){a.error(b)}})},d)},isHandshake:function(a,b){var c=this;e(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){e(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){e(b,function(){a instanceof r&&(this._readException=new G("Error reading the payload chunk.",
a));throw a;},c)}});else return this._handshake},c)},getMessageHeader:function(){return this._header instanceof ub?this._header:null},getErrorHeader:function(){return this._header instanceof tb?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;e(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(){e(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){e(c,function(){if(void 0===a)return new Uint8Array(0);if(a)return null;g()},f)},timeout:c.timeout,error:function(a){e(c,function(){this._readException=null;throw new G("Error reading the payload chunk.",a);},f)}})}},f)}function g(){e(c,function(){function d(c){e(c,function(){if(g&&n>=g.length)return g.subarray(0,n);var k=-1;if(this._currentPayload){var l=
this._currentPayload.length-this._payloadOffset;if(!g){var B=l;if(-1!=this._payloadIndex)for(var T=this._payloadIndex;T<this._payloads.length;++T)B+=this._payloads[T].length;0<B&&(g=new Uint8Array(B))}l=Math.min(l,g?g.length-n:0);0<l&&(k=this._currentPayload.subarray(this._payloadOffset,this._payloadOffset+l),g.set(k,q),k=l,q+=l,this._payloadOffset+=l)}-1!=k?(n+=k,d(c)):this.nextData(b,{result:function(b){e(c,function(){if(this._aborted)return g?g.subarray(0,n):new Uint8Array(0);this._currentPayload=
b;this._payloadOffset=0;if(this._currentPayload)d(c);else return 0==n&&0!=a?null:g?g.subarray(0,n):new Uint8Array(0)},f)},timeout:function(){c.timeout(g?g.subarray(0,n):new Uint8Array(0))},error:function(a){e(c,function(){a instanceof r&&(a=new G("Error reading the payload chunk.",a));if(0<n)return f._readException=a,g.subarray(0,n);throw a;},f)}})},f)}var g=-1!=a?new Uint8Array(a):void 0,q=0,n=0;d(c)},f)}var f=this;e(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)}})},f)},reset:function(){this._payloadIndex=0;0<this._payloads.length?(this._currentPayload=this._payloads[this._payloadIndex++],this._payloadOffset=this._markOffset):this._currentPayload=null}});yd=function(a,b,c,d,e,g,f){new xd(a,b,c,d,e,g,f)}})();var zd,Ac;(function(){zd=qc.extend({init:function(a,b,c,d,g,n,f){var l=this;e(f,function(){function e(){l._ready=
!0;l._readyQueue.add(!0)}var f=vc(a.getMessageCapabilities(),d.messageCapabilities),t=null;f&&(t=Ua(f.compressionAlgorithms));f={_destination:{value:b,writable:!1,enumerable:!1,configurable:!1},_charset:{value:c,writable:!1,enumerable:!1,configurable:!1},_capabilities:{value:f,writable:!1,enumerable:!1,configurable:!1},_header:{value:d,writable:!1,enumerable:!1,configurable:!1},_compressionAlgo:{value:t,writable:!0,enumerable:!1,configurable:!1},_cryptoContext:{value:g,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 K,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,f);var r=sa(JSON.stringify(d),c);b.write(r,0,r.length,n,{result:function(a){try{l._aborted?e():a<r.length?(l._timedout=!0,e()):b.flush(n,{result:function(a){l._aborted||(l._timedout=!a);e()},timeout:function(){l._timedout=!0;e()},error:function(a){l._errored=a;e()}})}catch(c){l._errored=
c,e()}},timeout:function(){l._timedout=!0;e()},error:function(a){l._errored=a;e()}});return this},l)},setCompressionAlgorithm:function(a,b,c){function d(){g.flush(b,{result:function(b){e(c,function(){if(!b)throw new G("flush() aborted");this._compressionAlgo=a;return!0},g)},timeout:function(){c.timeout()},error:function(a){c.error(a)}})}var g=this;e(c,function(){if(!this.getMessageHeader())throw new x("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()},g)},getMessageHeader:function(){return this._header instanceof ub?this._header:null},getErrorMessage:function(){return this._header instanceof tb?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;e(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){e(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(){e(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 h=0;this._currentPayload&&this._currentPayload.forEach(function(a){h+=a.length});for(var g=new Uint8Array(h),f=0,p=0;this._currentPayload&&p<this._currentPayload.length;++p){var l=this._currentPayload[p];g.set(l,f);f+=l.length}sd(this._payloadSequenceNumber,c.messageId,this._closed,this._compressionAlgo,g,this._cryptoContext,{result:function(c){e(b,function(){this._caching&&
this._payloads.push(c);var h=sa(JSON.stringify(c),this._charset);this._destination.write(h,0,h.length,a,{result:function(h){e(b,function(){if(this._aborted)return!1;h<c.length?b.timeout():this._destination.flush(a,{result:function(a){e(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 r&&(a=new G("Error encoding payload chunk [sequence number "+
d._payloadSequenceNumber+"].",a));b.error(a)}})},d)},timeout:function(a){b.timeout()},error:function(a){a instanceof r&&(a=new G("Error encoding payload chunk [sequence number "+d._payloadSequenceNumber+"].",a));b.error(a)}})},d)},error:function(a){a instanceof r&&(a=new G("Error encoding payload chunk [sequence number "+d._payloadSequenceNumber+"].",a));b.error(a)}})}},d)}var d=this;e(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,g){e(g,function(){if(this._aborted)return!1;if(this._timedout)g.timeout();else{if(this._errored)throw this._errored;if(this._closed)throw new G("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 x("Cannot write payload data for an error message.");
if(d.isHandshake())throw new x("Cannot write payload data for a handshake message.");d=a.subarray(b,b+c);this._currentPayload.push(d);return d.length}},this)}});Ac=function(a,b,c,d,e,g,f){new zd(a,b,c,d,e,g,f)}})();Object.freeze({USERDATA_REAUTH:c.USERDATA_REAUTH,SSOTOKEN_REJECTED:c.SSOTOKEN_REJECTED});var Pb=J.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(){}}),Fe=J.Class.create({sentHeader:function(a){},receivedHeader:function(a){}});J.Class.create({getInputStream:function(a){},getOutputStream:function(a){}});var Ad;(function(){function d(a){return function(){a.abort()}}function g(a,b){Object.defineProperties(this,{masterToken:{value:a,writable:!1,configurable:!1},
ticket:{value:b,writable:!1,configurable:!1}})}function h(a,b){Object.defineProperties(this,{builder:{value:a,writable:!1,configurable:!1},msgCtx:{value:b,writable:!1,configurable:!1}})}function k(a,b){Object.defineProperties(this,{request:{value:a,writable:!1,configurable:!1},handshake:{value:b,writable:!1,configurable:!1}})}function q(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 n(a){for(;a;){if(a instanceof Ba)return!0;a=a instanceof r?a.cause:void 0}return!1}function f(a){var b=a.masterToken;return b?b.identity:a.entityAuthenticationData.getIdentity()}function l(a,b,c,d,h,k,g,m,n,q){vd(b,d,h,k,g,{result:function(d){c&&c.sentHeader(d);Ac(b,m,P,d,null,null,n,{result:function(b){a.setAbort(function(){b.abort()});b.close(n,{result:function(a){e(q,function(){if(!a)throw new Ba("sendError aborted.");return a})},timeout:function(){q.timeout()},
error:function(a){q.error(a)}})},timeout:function(){},error:function(a){q.error(a)}})},error:function(a){q.error(a)}})}var p=function(a,b){Object.defineProperties(this,{input:{value:a,writable:!1,configurable:!1},output:{value:b,writable:!1,configurable:!1}});return this},y=J.Class.create({init:function(){Object.defineProperties(this,{_offset:{value:0,writable:!0,enumerable:!1,configurable:!1}})},update:function(a,b){var c=a.getTime()/1E3;this._offset=b.getTime()/1E3-c},getTime:function(a){a=a.getTime()/
1E3+this._offset;return new Date(1E3*a)}});qc.extend({close:function(a,b){b.result(!0)},write:function(a,c,d,h,e){b(e,function(){return Math.min(a.length-c,d)})},flush:function(a,b){b.result(!0)}});var F=se.extend({getUserMessage:function(a,b){return null}}),na=Pb.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()}}),S=na.extend({init:function Pa(a,b){Pa.base.call(this,b);Object.defineProperties(this,{_payloads:{value:a,writable:!1,enumerable:!1,configurable:!1}})},write:function ga(a,b,c){function d(k){if(k==h._payloads.length)c.result(!0);else{var g=h._payloads[k];a.setCompressionAlgorithm(g.compressionAlgo,b,{result:function(m){a.write(g.data,
0,g.data.length,b,{result:function(m){e(c,function(){g.isEndOfMessage()?a.close(b,{result:function(a){a?d(k+1):c.result(a)},timeout:c.timeout,error:c.error}):a.flush(b,{result:function(a){a?d(k+1):c.result(a)},timeout:c.timeout,error:c.error})},h)},timeout:c.timeout,error:c.error})},timeout:c.timeout,error:c.error})}}var h=this;this._payloads&&0!=this._payloads.length?d(0):ga.base.call(this,a,b,c)}}),ha=na.extend({init:function W(a){W.base.call(this,a)},isEncrypted:function(){return!1},isIntegrityProtected:function(){return!1},
isNonReplayable:function(){return!1},write:function(a,b,c){c.result(!0)}}),B={},T,M,A,ba,u=J.Class.create({init:function(a){a||(a=new F);Object.defineProperties(this,{_messageRegistry:{value:a,writable:!1,enumerable:!1,configurable:!1},_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},_remoteClocks:{value:[],writable:!1,enumerable:!1,configurable:!1}})},
setFilterFactory:function(a){this._filterFactory=a},getNewestMasterToken:function(a,b,c,d){var h=this;e(d,function(){var k=b.getMslStore(),q=k.getMasterToken();if(!q)return null;var n=q.uniqueKey(),f=this._masterTokenLocks[n];f||(f=new Ra,this._masterTokenLocks[n]=f);var p=f.readLock(c,{result:function(p){e(d,function(){if(void 0===p)throw new Ba("getNewestMasterToken aborted.");var l=k.getMasterToken();if(q.equals(l))return new g(q,p);f.unlock(p);f.writeLock(c,{result:function(k){e(d,function(){if(void 0===
k)throw new Ba("getNewestMasterToken aborted.");delete this._masterTokenLocks[n];f.unlock(k);return this.getNewestMasterToken(a,b,c,d)},h)},timeout:function(){d.timeout()},error:function(a){d.error(a)}})},h)},timeout:function(){d.timeout()},error:function(a){d.error(a)}});a.setAbort(function(){p&&(f.cancel(p),p=void 0)})},h)},deleteMasterToken:function(a,b){if(b){var c=this;setTimeout(function(){var d=b.uniqueKey(),h=c._masterTokenLocks[d];h||(h=new Ra,c._masterTokenLocks[d]=h);h.writeLock(-1,{result:function(e){a.getMslStore().removeCryptoContext(b);
delete c._masterTokenLocks[d];h.unlock(e)},timeout:function(){throw new x("Unexpected timeout received.");},error:function(a){throw a;}})},0)}},releaseMasterToken:function(a){if(a&&a.masterToken){var b=a.masterToken.uniqueKey();(b=this._masterTokenLocks[b])&&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 h=a.getMslStore();if(d=d.keyResponseData)h.setCryptoContext(d.masterToken,c.getKeyExchangeCryptoContext()),this.deleteMasterToken(a,b.masterToken)}},storeServiceTokens:function(a,b,c,d){a=a.getMslStore();for(var h=[],e=0;e<d.length;++e){var k=d[e];if(!k.isBoundTo(b)||!b.isVerified()){var g=k.data;g&&0==g.length?a.removeServiceTokens(k.name,k.isMasterTokenBound()?b:null,k.isUserIdTokenBound()?c:null):h.push(k)}}0<h.length&&a.addServiceTokens(h)},buildRequest:function(a,
c,d,h,e){var k=this;this.getNewestMasterToken(a,c,h,{result:function(a){b(e,function(){var h=a&&a.masterToken,g;if(h){g=d.getUserId();var m=c.getMslStore();g=(g=g?m.getUserIdToken(g):null)&&g.isBoundTo(h)?g:null}else g=null;m=d.getRecipient();wb(c,h,g,m,null,{result:function(c){b(e,function(){c.setNonReplayable(d.isNonReplayable());return{builder:c,tokenTicket:a}})},error:function(c){b(e,function(){this.releaseMasterToken(a);c instanceof r&&(c=new x("User ID token not bound to master token despite internal check.",
c));throw c;},k)}})},k)},timeout:function(){e.timeout()},error:function(a){e.error(a)}})},buildResponse:function(a,b,c,d,h,k){var g=this;ud(b,d,{result:function(m){e(k,function(){m.setNonReplayable(c.isNonReplayable());if(!b.isPeerToPeer()&&!d.keyResponseData)return{builder:m,tokenTicket:null};this.getNewestMasterToken(a,b,h,{result:function(a){e(k,function(){var d=a&&a.masterToken,h;if(d){h=c.getUserId();var e=b.getMslStore();h=(h=h?e.getUserIdToken(h):null)&&h.isBoundTo(d)?h:null}else h=null;m.setAuthTokens(d,
h);return{builder:m,tokenTicket:a}},g)},timeout:function(){k.timeout()},error:function(a){k.error(a)}})},g)},error:function(a){k.error(a)}})},buildErrorResponse:function(a,b,d,k,g,m,q){function f(a,c){e(q,function(){var k=vb(g.messageId),m=new S(c,d),n=m.getRecipient();wb(b,null,null,n,k,{result:function(c){e(q,function(){b.isPeerToPeer()&&c.setPeerAuthTokens(a.peerMasterToken,a.peerUserIdToken);c.setNonReplayable(m.isNonReplayable());return{errorResult:new h(c,m),tokenTicket:null}},p)},error:function(a){q.error(a)}})},
p)}function n(c,k){p.getNewestMasterToken(a,b,m,{result:function(a){e(q,function(){var m=a&&a.masterToken,n=vb(g.messageId),f=new S(k,d),W=f.getRecipient();wb(b,m,null,W,n,{result:function(d){e(q,function(){b.isPeerToPeer()&&d.setPeerAuthTokens(c.peerMasterToken,c.peerUserIdToken);d.setNonReplayable(f.isNonReplayable());return{errorResult:new h(d,f),tokenTicket:a}},p)},error:function(a){q.error(a)}})},p)},timeout:function(){q.timeout()},error:function(a){q.error(a)}})}var p=this;e(q,function(){var l=
k.request.getMessageHeader(),t=k.request.getPayloads(),B=g.errorCode;switch(B){case c.ENTITYDATA_REAUTH:case c.ENTITY_REAUTH:b.getEntityAuthenticationData(B,{result:function(a){e(q,function(){if(!a)return null;f(l,t)},p)},error:function(a){q.error(a)}});break;case c.USERDATA_REAUTH:case c.SSOTOKEN_REJECTED:d.getUserAuthData(B,!1,!0,{result:function(a){e(q,function(){if(!a)return null;n(l,t)},p)},error:function(a){q.error(a)}});break;case c.USER_REAUTH:n(l,t);break;case c.KEYX_REQUIRED:var B=vb(g.messageId),
A=new S(t,d),y=A.getRecipient();wb(b,null,null,y,B,{result:function(a){e(q,function(){b.isPeerToPeer()&&a.setPeerAuthTokens(l.peerMasterToken,l.peerUserIdToken);a.setRenewable(!0);a.setNonReplayable(A.isNonReplayable());return{errorResult:new h(a,A),tokenTicket:null}},p)},error:function(a){q.error(a)}});break;case c.EXPIRED:this.getNewestMasterToken(a,b,m,{result:function(a){e(q,function(){var c=a&&a.masterToken,k;if(c){k=d.getUserId();var m=b.getMslStore();k=(k=k?m.getUserIdToken(k):null)&&k.isBoundTo(c)?
k:null}else k=null;var m=vb(g.messageId),n=new S(t,d),f=n.getRecipient();wb(b,c,k,f,m,{result:function(d){e(q,function(){b.isPeerToPeer()&&d.setPeerAuthTokens(l.peerMasterToken,l.peerUserIdToken);var k=l.masterToken;k&&!k.equals(c)||d.setRenewable(!0);d.setNonReplayable(n.isNonReplayable());return{errorResult:new h(d,n),tokenTicket:a}},p)},error:function(a){q.error(a)}},p)},p)},timeout:function(){q.timeout()},error:function(a){q.error(a)}});break;case c.REPLAYED:this.getNewestMasterToken(a,b,m,{result:function(a){e(q,
function(){var c=a&&a.masterToken,k;if(c){k=d.getUserId();var m=b.getMslStore();k=(k=k?m.getUserIdToken(k):null)&&k.isBoundTo(c)?k:null}else k=null;var m=vb(g.messageId),n=new S(t,d),f=n.getRecipient();wb(b,c,k,f,m,{result:function(c){e(q,function(){b.isPeerToPeer()&&c.setPeerAuthTokens(l.peerMasterToken,l.peerUserIdToken);c.setNonReplayable(n.isNonReplayable());return{errorResult:new h(c,n),tokenTicket:a}},p)},error:function(a){q.error(a)}})},p)},timeout:function(){q.timeout()},error:function(a){q.error(a)}});
break;default:return null}},p)},cleanupContext:function(a,b,d){switch(d.errorCode){case c.ENTITY_REAUTH:this.deleteMasterToken(a,b.masterToken);break;case c.USER_REAUTH:d=b.userIdToken,b.masterToken&&d&&a.getMslStore().removeUserIdToken(d)}},getRemoteTime:function(a){for(var b,c=0;c<this._remoteClocks.length;++c){var d=this._remoteClocks[c];if(d.ctx===a){b=d.clock;break}}return b?b.getTime(a):null},send:function(a,b,c,d,h,g,m,q){function n(a,d,k){e(q,function(){var g=h.getPeerUserIdToken();!b.isPeerToPeer()&&
!d||b.isPeerToPeer()&&!g?(g=c.getUser())?h.setUser(g,{result:function(b){e(q,function(){d=h.getUserIdToken();f(a,d,k)},t)},error:function(a){q.error(a)}}):f(a,d,k):f(a,d,k)},t)}function f(a,d,k){e(q,function(){var g=!(!(k||c.isEncrypted()&&!h.willEncryptPayloads()||c.isIntegrityProtected()&&!h.willIntegrityProtectPayloads())&&(!c.isNonReplayable()||h.isNonReplayable()&&a));h.setHandshake(g);var m=[];if(h.isRenewable()){var n=this.getRemoteTime(b);if(!a||a.isRenewable(n)||c.isNonReplayable()){c.getKeyRequestData({result:function(b){e(q,
function(){for(var c=0;c<b.length;++c){var k=b[c];m.push(k);h.addKeyRequestData(k)}p(a,d,g,m)},t)},error:function(a){q.error(a)}});return}}p(a,d,g,m)},t)}function p(k,n,f,B){e(q,function(){var p=new wd(b,c,h);c.updateServiceTokens(p,f,{result:function(p){h.getHeader({result:function(p){e(q,function(){var B=c.getDebugContext();B&&B.sentHeader(p);B=h.getKeyExchangeData();this.updateOutgoingCryptoContexts(b,p,B);this.storeServiceTokens(b,B?B.keyResponseData.masterToken:k,n,p.serviceTokens);B=!b.isPeerToPeer()&&
B?B.cryptoContext:p.cryptoContext;if(a.isAborted())throw new Ba("send aborted.");var A=null!=this._filterFactory?this._filterFactory.getOutputStream(d):d;Ac(b,A,P,p,B,m,{result:function(b){e(q,function(){a.setAbort(function(){b.abort()});b.closeDestination(g);l(b,f)},t)},timeout:function(){q.timeout()},error:function(a){q.error(a)}})},t)},timeout:function(){q.timeout()},error:function(a){q.error(a)}})},error:function(a){q.error(a)}})},t)}function l(b,d){d?e(q,function(){return new k(b,d)},t):c.write(b,
m,{result:function(c){e(q,function(){if(a.isAborted())throw new Ba("MessageOutputStream write aborted.");return new k(b,d)},t)},timeout:function(){q.timeout()},error:function(a){q.error(a)}})}var t=this;e(q,function(){var a=h.getMasterToken(),b=h.getUserIdToken(),d=!1;if(c.getUserId()){var k=!b;c.getUserAuthData(null,h.isRenewable(),k,{result:function(c){e(q,function(){c&&(h.willEncryptHeader()&&h.willIntegrityProtectHeader()?h.setUserAuthenticationData(c):d=!0);n(a,b,d)},t)},error:function(a){q.error(a)}})}else n(a,
b,d)},t)},receive:function(b,d,h,k,g,m,q){var n=this;e(q,function(){if(b.isAborted())throw new Ba("receive aborted.");var f=[];g&&(f=g.keyRequestData.filter(function(){return!0}));var p=h.getCryptoContexts(),l=this._filterFactory?this._filterFactory.getInputStream(k):k;yd(d,l,P,f,p,m,{result:function(k){b.setAbort(function(){k.abort()});k.isReady({result:function(b){e(q,function(){if(!b)throw new Ba("MessageInputStream aborted.");var m=k.getMessageHeader(),f=k.getErrorHeader(),p=h.getDebugContext();
p&&p.receivedHeader(m?m:f);var l,W,t;m?(p=m.masterToken,l=m.entityAuthenticationData,W=m.userIdToken,t=m.userAuthenticationData):(p=null,l=f.entityAuthenticationData,t=W=null);if(g){var B=f?f.errorCode:null;if(m||B!=c.FAIL&&B!=c.TRANSIENT_FAILURE&&B!=c.ENTITY_REAUTH&&B!=c.ENTITYDATA_REAUTH){var B=m?m.messageId:f.messageId,A=vb(g.messageId);if(B!=A)throw(new ea(a.UNEXPECTED_RESPONSE_MESSAGE_ID,"expected "+A+"; received "+B)).setEntity(p).setEntity(l).setUser(W).setUser(t);}}d.getEntityAuthenticationData(null,
{result:function(b){e(q,function(){var c=b.getIdentity(),e;try{if(m){var q=m.entityAuthenticationData,n=m.masterToken;e=n?m.sender:q.getIdentity();if(n&&n.isDecrypted()&&n.identity!=e||c==e)throw new ea(a.UNEXPECTED_MESSAGE_SENDER,e);var p=m.recipient;if(p&&p!=c)throw new ea(a.MESSAGE_RECIPIENT_MISMATCH,p);g&&this.updateIncomingCryptoContexts(d,g,k);var l=m.keyResponseData,B,A,ya;d.isPeerToPeer()?(B=l?l.masterToken:m.peerMasterToken,A=m.peerUserIdToken,ya=m.peerServiceTokens):(B=l?l.masterToken:m.masterToken,
A=m.userIdToken,ya=m.serviceTokens);var ra=h.getUserId();ra&&A&&!A.isVerified()&&d.getMslStore().addUserIdToken(ra,A);this.storeServiceTokens(d,B,A,ya)}else if(e=f.entityAuthenticationData.getIdentity(),c==e)throw new ea(a.UNEXPECTED_MESSAGE_SENDER,e);var T=m?m.timestamp:f.timestamp;if(T){for(var M,c=0;c<this._remoteClocks.length;++c){var F=this._remoteClocks[c];if(F.ctx===d){M=F.clock;break}}M||(M=new y,this._remoteClocks.push({ctx:d,clock:M}));M.update(d,T)}}catch(ba){throw ba instanceof r&&(ba.setEntity(n),
ba.setEntity(q),ba.setUser(W),ba.setUser(t)),ba;}return k},n)},error:q.error})},n)},timeout:function(){q.timeout()},error:function(a){q.error(a)}})},timeout:function(){q.timeout()},error:function(a){q.error(a)}})},n)},sendReceive:function(a,b,c,d,h,k,g,m,n,f){function p(k,B,t){e(f,function(){var p=k.builder,A=k.tokenTicket;p.setRenewable(t);this.send(a,b,c,h,p,m,n,{result:function(h){e(f,function(){var k=h.request.getMessageHeader(),p=k.keyRequestData;g||h.handshake||!p.isEmpty()||k.isRenewable()&&
k.masterToken&&k.userAuthenticationData?this.receive(a,b,c,d,k,n,{result:function(a){e(f,function(){var c=a.getErrorHeader();c&&this.cleanupContext(b,k,c);t&&this.releaseRenewalLock(b,B,a);this.releaseMasterToken(A);a.closeSource(m);return new q(a,h)},l)},timeout:function(){e(f,function(){t&&this.releaseRenewalLock(b,B,null);this.releaseMasterToken(A);f.timeout()},l)},error:function(a){e(f,function(){t&&this.releaseRenewalLock(b,B,null);this.releaseMasterToken(A);f.error(a)},l)}}):e(f,function(){t&&
this.releaseRenewalLock(b,B,null);this.releaseMasterToken(A);return new q(null,h)},l)},l)},timeout:function(){e(f,function(){t&&this.releaseRenewalLock(b,B,null);this.releaseMasterToken(A);f.timeout()},l)},error:function(a){e(f,function(){t&&this.releaseRenewalLock(b,B,null);this.releaseMasterToken(A);f.error(a)},l)}})},l)}var l=this;e(f,function(){var d=new K;this.acquireRenewalLock(a,b,c,d,k,n,{result:function(a){p(k,d,a)},timeout:function(){e(f,function(){this.releaseMasterToken(k.ticket);f.timeout()},
l)},error:function(a){e(f,function(){this.releaseMasterToken(k.ticket);if(a instanceof Ba)return null;f.error(a)},l)}})},l)},acquireRenewalLock:function(a,b,c,d,h,k,g){function m(c,f,p,w,l){e(g,function(){if(a.isAborted())throw new Ba("acquireRenewalLock aborted.");for(var t=null,A=0;A<this._renewingContexts.length;++A){var y=this._renewingContexts[A];if(y.ctx===b){t=y.queue;break}}if(!t)return this._renewingContexts.push({ctx:b,queue:d}),!0;var T=t.poll(k,{result:function(d){e(g,function(){if(void 0===
d)throw new Ba("acquireRenewalLock aborted.");t.add(d);if(d===B)m(c,f,p,w,l);else{var A=c;c&&c.equals(d)?q(A,c,f,p,w,l):(this.releaseMasterToken(l),this.getNewestMasterToken(a,b,k,{result:function(a){e(g,function(){(c=(h.tokenTicket=a)&&a.masterToken)?q(A,c,f,p,w,a):m(c,f,p,w,a)},n)},timeout:g.timeout,error:g.error}))}},n)},timeout:g.timeout,error:g.error});a.setAbort(function(){T&&(t.cancel(T),T=void 0)})},n)}function q(a,d,h,k,p,l){e(g,function(){if(k&&!h||h&&!h.isBoundTo(d)){var e=b.getMslStore().getUserIdToken(k);
h=e&&e.isBoundTo(d)?e:null}p.setAuthTokens(d,h);e=this.getRemoteTime(b);d.isExpired(e)?m(d,h,k,p,l):p.isRenewable()&&d.equals(a)?m(d,h,k,p,l):c.isRequestingTokens()&&!h?m(d,h,k,p,l):f(d,h)},n)}function f(h,k){e(g,function(){if(a.isAborted())throw new Ba("acquireRenewalLock aborted.");var e=this.getRemoteTime(b);if(!h||h.isRenewable(e)||!k&&c.getUserId()||k&&k.isRenewable(e)){for(var e=null,g=0;g<this._renewingContexts.length;++g){var m=this._renewingContexts[g];if(m.ctx===b){e=m.queue;break}}if(!e)return this._renewingContexts.push({ctx:b,
queue:d}),!0}return!1},n)}var n=this;e(g,function(){var a=h.builder,d=h.tokenTicket,k=a.getMasterToken(),e=a.getUserIdToken(),g=c.getUserId(),q=this.getRemoteTime(b);c.isEncrypted()&&!a.willEncryptPayloads()||c.isIntegrityProtected()&&!a.willIntegrityProtectPayloads()||a.isRenewable()||!k&&c.isNonReplayable()||k&&k.isExpired(q)||!(e||!g||a.willEncryptHeader()&&a.willIntegrityProtectHeader())||c.isRequestingTokens()&&(!k||g&&!e)?m(k,e,g,a,d):f(k,e)},n)},releaseRenewalLock:function(a,b,c){for(var d,
h,k=0;k<this._renewingContexts.length;++k){var e=this._renewingContexts[k];if(e.ctx===a){d=k;h=e.queue;break}}if(h!==b)throw new x("Attempt to release renewal lock that is not owned by this queue.");c?(c=c.getMessageHeader())?(h=c.keyResponseData)?b.add(h.masterToken):(a=a.isPeerToPeer()?c.peerMasterToken:c.masterToken)?b.add(a):b.add(B):b.add(B):b.add(B);this._renewingContexts.splice(d,1)}});Ad=J.Class.create({init:function(){var a={_impl:{value:new u,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,h,k,e){if(this._shutdown)throw new r("MslControl is shutdown.");var g=new T(this._impl,a,b,c,h,k);setTimeout(function(){g.call(e)},0);return d(g)},respond:function(a,b,c,h,k,e,g){if(this._shutdown)throw new r("MslControl is shutdown.");var m=new M(this._impl,a,b,c,h,k,e);setTimeout(function(){m.call(g)},
0);return d(m)},error:function(a,b,c,h,k,e,g){if(this._shutdown)throw new r("MslControl is shutdown.");var m=new A(this._impl,a,b,c,h,k,e);setTimeout(function(){m.call(g)},0);return d(m)},request:function(a,b){if(this._shutdown)throw new r("MslControl is shutdown.");var c,h,k,e,g;if(5==arguments.length){if(c=arguments[2],k=h=null,e=arguments[3],g=arguments[4],a.isPeerToPeer()){g.error(new x("This method cannot be used in peer-to-peer mode."));return}}else if(6==arguments.length&&(c=null,h=arguments[2],
k=arguments[3],e=arguments[4],g=arguments[5],!a.isPeerToPeer())){g.error(new x("This method cannot be used in trusted network mode."));return}var m=new ba(this._impl,a,b,c,h,k,null,0,e);setTimeout(function(){m.call(g)},0);return d(m)}});T=J.Class.create({init:function(a,b,c,d,h,k){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:h,writable:!1,enumerable:!1,configurable:!1},_timeout:{value:k,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(h){e(b,function(){var c=
h.getMessageHeader();if(!c)return h;this.setAbort(function(){h.abort()});h.isHandshake(this._timeout,{result:function(a){e(b,function(){if(void 0===a)return null;if(!a)return h;d(h)},k)},timeout:b.timeout,error:function(d){e(b,function(){if(n(d))return null;var g=h.getIdentity(),m=c.messageId,q=a.INTERNAL_EXCEPTION,f=new x("Error peeking into the message payloads.");l(this,this._ctx,this._msgCtx.getDebugContext(),g,m,q,null,this._output,this._timeout,{result:function(a){b.error(f)},timeout:function(){b.timeout()},
error:function(a){e(b,function(){if(n(a))return null;throw new C("Error peeking into the message payloads.",a,d);},k)}})},k)}})},k)}function d(c){e(b,function(){c.close();this._ctrl.buildResponse(this,this._ctx,this._msgCtx,c.getMessageHeader(),this._timeout,{result:function(a){e(b,function(){var d=a.builder,k=a.tokenTicket,g=new ha(this._msgCtx);if(this._ctx.isPeerToPeer()){var m=new ba(this._ctrl,this._ctx,g,null,this._input,this._output,a,1,this._timeout);this.setAbort(function(){m.abort()});m.call({result:function(a){e(b,
function(){return a?a.input:null})},timeout:b.timeout,error:b.error})}else h(c,d,g,k)},k)},timeout:b.timeout,error:function(d){e(b,function(){if(n(d))return null;var h=c.getIdentity(),g,m,q,f;d instanceof r?(g=d.messageId,m=d.error,q=c.getMessageHeader().messageCapabilities,q=this._ctrl.messageRegistry.getUserMessage(m,q?q.languages:null),f=d):(g=c.messageHeader.messageId,m=a.INTERNAL_EXCEPTION,q=null,f=new x("Error creating an automatic handshake response.",d));l(this,this._ctx,this._msgCtx.getDebugContext(),
h,g,m,q,this._output,this._timeout,{result:function(a){b.error(f)},timeout:function(){b.timeout()},error:function(a){e(b,function(){if(n(a))return null;throw new C("Error creating an automatic handshake response.",a,d);},k)}})},k)}})},k)}function h(c,d,g,m){e(b,function(){d.setRenewable(!1);this._ctrl.send(this._ctx,g,this._output,d,!1,this._timeout,{result:function(a){e(b,function(){this._ctx.isPeerToPeer()&&this._ctrl.releaseMasterToken(m);return null},k)},timeout:function(){e(b,function(){this._ctx.isPeerToPeer()&&
this._ctrl.releaseMasterToken(m);b.timeout()},k)},error:function(d){e(b,function(){this._ctx.isPeerToPeer()&&this._ctrl.releaseMasterToken(m);if(n(d))return null;var h=c.getIdentity(),g,q,f,p;d instanceof r?(g=d.messageId,q=d.error,f=c.getMessageHeader().messageCapabilities,f=this._ctrl.messageRegistry.getUserMessage(q,f?f.languages:null),p=d):d instanceof G?(g=c.getMessageHeader().messageId,q=a.MSL_COMMS_FAILURE,f=null,p=d):(g=c.getMessageHeader().messageId,q=a.INTERNAL_EXCEPTION,f=null,p=new x("Error sending an automatic handshake response.",
d));l(this,this._ctx,this._msgCtx.getDebugContext(),h,g,q,f,this._output,this._timeout,{result:function(a){b.error(p)},timeout:function(){b.timeout()},error:function(a){e(b,function(){if(n(a))return null;throw new C("Error sending an automatic handshake response.",a,d);},k)}})},k)}})},k)}var k=this;e(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){e(b,function(){if(n(c))return null;
var d,h,g,m,q;c instanceof r?(d=c.masterToken,h=c.entityAuthenticationData,d=d?d.identity:h?h.getIdentity():null,h=c.messageId,g=c.error,m=this._ctrl.messageRegistry.getUserMessage(g,null),q=c):(h=d=null,g=a.INTERNAL_EXCEPTION,m=null,q=new x("Error receiving the message header.",c));l(this,this._ctx,this._msgCtx.getDebugContext(),d,h,g,m,this._output,this._timeout,{result:function(a){b.error(q)},timeout:function(){b.timeout()},error:function(a){e(b,function(){if(n(a))return null;throw new C("Error receiving the message header.",
a,c);},k)}})},k)}})},k)}});M=J.Class.create({init:function(a,b,c,d,h,k,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:h,writable:!1,enumerable:!1,configurable:!1},_request:{value:k,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 h=this;e(d,function(){try{var k=b.builder,g=b.tokenTicket;if(c+1>zb)return this._ctrl.releaseMasterToken(g),null;var m;if(m=this._msgCtx.isIntegrityProtected()&&
!k.willIntegrityProtectHeader()?a.RESPONSE_REQUIRES_INTEGRITY_PROTECTION:this._msgCtx.isEncrypted()&&!k.willEncryptPayloads()?a.RESPONSE_REQUIRES_ENCRYPTION:null){var q=f(this._request),B=Fb(k.getMessageId());l(this,this._ctx,this._msgCtx.getDebugContext(),q,B,m,null,this._output,this._timeout,{result:function(a){d.result(null)},timeout:d.timeout,error:function(a){e(d,function(){if(n(a))return null;throw new C("Response requires encryption or integrity protection but cannot be protected: "+m,a,null);
},h)}});this._ctrl.releaseMasterToken(g)}else!this._msgCtx.getUser()||k.getMasterToken()||k.getKeyExchangeData()?(k.setRenewable(!1),this._ctrl.send(this._ctx,this._msgCtx,this._output,k,!1,this._timeout,{result:function(a){e(d,function(){this._ctrl.releaseMasterToken(g);return new p(this._request,a.request)},h)},timeout:function(){e(d,function(){this._ctrl.releaseMasterToken(g);d.timeout()},h)},error:function(a){e(d,function(){this._ctrl.releaseMasterToken(g);d.error(a)},h)}})):(q=f(this._request),
B=Fb(k.getMessageId()),l(this,this._ctx,this._msgCtx.getDebugContext(),q,B,a.RESPONSE_REQUIRES_MASTERTOKEN,null,this._output,this._timeout,{result:function(a){d.result(null)},timeout:d.timeout,error:function(a){e(d,function(){if(n(a))return null;throw new C("Response wishes to attach a user ID token but there is no master token.",a,null);},h)}}),this._ctrl.releaseMasterToken(g))}catch(A){throw this._ctrl.releaseMasterToken(g),A;}},h)},peerToPeerExecute:function(b,c,d,h){function k(a){e(h,function(){a.response.close(this._timeout,
{result:function(b){e(h,function(){if(!b)return null;g(a)},m)},timeout:function(){g(a)},error:function(b){e(h,function(){if(n(b))return null;g(a)},m)}})},m)}function g(a){e(h,function(){var c=a.response.getErrorHeader();this._ctrl.buildErrorResponse(this,this._ctx,b,a,c,{result:function(a){e(h,function(){if(!a)return null;var b=a.errorResult;this.peerToPeerExecute(b.msgCtx,{builder:b.builder,tokenTicket:a.tokenTicket},d,h)},m)}})},m)}var m=this;e(h,function(){var g=c.builder,q=c.tokenTicket;if(d+
2>zb)return this._ctrl.releaseMasterToken(q),null;null!=b.getUser()&&null==g.getPeerMasterToken()&&null==g.getKeyExchangeData()?(this._ctrl.releaseMasterToken(q),q=f(this._request),g=Fb(g.getMessageId()),l(this,this._ctx,b.getDebugContext(),q,g,a.RESPONSE_REQUIRES_MASTERTOKEN,null,this._output,this._timeout,{result:function(a){h.result(null)},timeout:h.timeout,error:function(a){e(h,function(){if(n(a))return null;throw new C("Response wishes to attach a user ID token but there is no master token.",
a,null);},m)}})):this._ctrl.sendReceive(this._ctx,b,this._input,this._output,c,!1,!1,this._timeout,{result:function(a){e(h,function(){function c(){q.close(m._timeout,{result:function(a){e(h,function(){if(!a)return null;g()},m)},timeout:function(){g()},error:function(a){e(h,function(){if(n(a))return null;g()},m)}})}function g(){e(h,function(){var a=new S(null,b);this._ctrl.buildResponse(this,this._ctx,a,f,this._timeout,{result:function(b){e(h,function(){this.peerToPeerExecute(a,b,d,h)},m)},timeout:h.timeout,
error:h.error})},m)}var q=a.response;d+=2;if(!q)return new p(this._request,a.request);var f=q.getMessageHeader();if(f)if(a.handshake)c();else return new p(a.response,a.request);else k(a)},m)},timeout:h.timeout,error:h.error})},m)},call:function(b){var c=this;e(b,function(){var d=this._request.getMessageHeader();this._ctrl.buildResponse(this,this._ctx,this._msgCtx,d,this._timeout,{result:function(h){e(b,function(){var k=h.builder;this._ctx.isPeerToPeer()?this.peerToPeerExecute(this._msgCtx,h,3,{result:function(a){e(b,
function(){a&&a.output.stopCaching();return a},c)},timeout:b.timeout,error:function(d){e(b,function(){if(n(d))return null;var h=f(this._request),g=Fb(k.getMessageId()),m,q,p;d instanceof r?(m=d.error,q=this._request.messageCapabilities,q=this._ctrl.messageRegistry.getUserMessage(m,q?q.languages:null),p=d):d instanceof G?(m=a.MSL_COMMS_FAILURE,q=null,p=d):(m=a.INTERNAL_EXCEPTION,q=null,p=new x("Error sending the response.",d));l(this,this._ctx,this._msgCtx.getDebugContext(),h,g,m,q,this._output,this._timeout,
{result:function(a){b.error(p)},timeout:function(){b.timeout()},error:function(a){e(b,function(){if(n(a))return!1;throw new C("Error sending the response.",a,null);},c)}})},c)}}):this.trustedNetworkExecute(h,3,{result:function(a){e(b,function(){a&&a.output.stopCaching();return a},c)},timeout:b.timeout,error:function(h){e(b,function(){if(n(h))return null;var g=f(this._request),m=Fb(k.getMessageId()),q,p,B;h instanceof r?(q=h.error,p=d.messageCapabilities,p=this._ctrl.messageRegistry.getUserMessage(q,
p?p.languages:null),B=h):h instanceof G?(q=a.MSL_COMMS_FAILURE,p=null,B=h):(q=a.INTERNAL_EXCEPTION,p=null,B=new x("Error sending the response.",h));l(this,this._ctx,this._msgCtx.getDebugContext(),g,m,q,p,this._output,this._timeout,{result:function(a){b.error(B)},timeout:function(){b.timeout()},error:function(a){e(b,function(){if(n(a))return null;throw new C("Error sending the response.",a,null);},c)}})},c)}})},c)},timeout:b.timeout,error:function(h){e(b,function(){if(n(h))return null;var k=f(this._request),
g,m,q,p;h instanceof r?(g=h.messageId,m=h.error,q=d.messageCapabilities,q=this._ctrl.messageRegistry.getUserMessage(m,q?q.languages:null),p=h):(g=null,m=a.INTERNAL_EXCEPTION,q=null,p=new x("Error building the response.",h));l(this,this._ctx,this._msgCtx.getDebugContext(),k,g,m,q,this._output,this._timeout,{result:function(a){b.error(p)},timeout:b.timeout,error:function(a){e(b,function(){if(n(a))return null;throw new C("Error building the response.",a,h);},c)}})},c)}})},c)}});A=J.Class.create({init:function(a,
b,c,d,h,k,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:h,writable:!1,enumerable:!1,configurable:!1},_request:{value:k,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;e(b,function(){var d;if("ENTITY_REJECTED"==this._appError)d=this._request.masterToken?a.MASTERTOKEN_REJECTED_BY_APP:a.ENTITY_REJECTED_BY_APP;else if("USER_REJECTED"==this._appError)d=this._request.userIdToken?a.USERIDTOKEN_REJECTED_BY_APP:
a.USER_REJECTED_BY_APP;else throw new x("Unhandled application error "+this._appError+".");var h=this._request.messageCapabilities,h=this._ctrl.messageRegistry.getUserMessage(d,h?h.languages:null);l(this,this._ctx,this._msgCtx.getDebugContext(),this._request.messageId,d,h,this._output,this._timeout,{result:function(a){b.result(a)},timeout:b.timeout,error:function(a){e(b,function(){if(n(a))return!1;a instanceof r&&b.error(a);throw new x("Error building the error response.",a);},c)}})},c)}});var v=
{result:function(){},timeout:function(){},error:function(){}};ba=J.Class.create({init:function(a,b,c,d,h,k,e,g,m){var q;e?(q=e.builder,e=e.tokenTicket):e=q=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:h,writable:!0,enumerable:!1,configurable:!1},_output:{value:k,
writable:!0,enumerable:!1,configurable:!1},_openedStreams:{value:!1,writable:!0,enumerable:!1,configurable:!1},_builder:{value:q,writable:!0,enumerable:!1,configurable:!1},_tokenTicket:{value:e,writable:!0,enumerable:!1,configurable:!1},_timeout:{value:m,writable:!1,enumerable:!1,configurable:!1},_msgCount:{value:g,writable:!1,enumerable:!1,configurable:!1},_maxMessagesHit:{value:!1,writable:!0,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,h){function k(a,b){a.request.close(l._timeout,{result:function(a){b.call(l,a)},timeout:function(){b.call(l,!0)},error:function(a){n(a)&&b.call(l,!1);b.call(l,!0)}})}function g(a,b){k(a,function(c){c?a.response.close(l._timeout,{result:function(a){b.call(l,a)},timeout:function(){b.call(l,
!0)},error:function(a){n(a)&&b.call(l,!1);b.call(l,!0)}}):b.call(l,!1)})}function m(a){e(h,function(){g(a,function(b){b?q(a):h.result(null)})},l)}function q(b){function k(a,b){e(h,function(){return this._maxMessagesHit||b&&!b.input?new p(a.response,null):b},l)}e(h,function(){var g=b.response,m=g.getErrorHeader();this._ctrl.buildErrorResponse(this,this._ctx,a,b,m,c,{result:function(a){e(h,function(){if(!a)return new p(g,null);var c=a.errorResult,m=a.tokenTicket,q={builder:c.builder,tokenTicket:m},
c=c.msgCtx;if(this._ctx.isPeerToPeer())this.execute(c,q,this._timeout,d,{result:function(a){e(h,function(){this._ctrl.releaseMasterToken(m);k(b,a)},l)},timeout:function(){e(h,function(){this._ctrl.releaseMasterToken(m);h.timeout()},l)},error:function(a){e(h,function(){this._ctrl.releaseMasterToken(m);h.error(a)},l)}});else{var f=new ba(this._ctrl,this._ctx,c,this._remoteEntity,null,null,q,d,this._timeout);this.setAbort(function(){f.abort()});f.call({result:function(a){e(h,function(){this._maxMessagesHit=
f._maxMessagesHit;k(b,a)},l)},timeout:h.timeout,error:h.error})}},l)},timeout:function(){h.timeout()},error:function(a){h.error(a)}})},l)}function f(b){e(h,function(){var m=b.request,q=b.response,f=q.getMessageHeader();if(this._ctx.isPeerToPeer())if(b.handshake)g(b,function(b){e(h,function(){if(!b)return null;var k=new S(null,a);this._ctrl.buildResponse(this,this._ctx,a,f,c,{result:function(a){this.execute(k,a,this._timeout,d,h)},timeout:h.timeout,error:h.error})},l)});else if(0<f.keyRequestData.length||
f.isRenewable()&&f.masterToken&&f.userAuthenticationData){var n=new ha(a);this._ctrl.buildResponse(this,this._ctx,n,f,c,{result:function(a){e(h,function(){var c=a.builder,m=a.tokenTicket;q.isHandshake(this._timeout,{result:function(a){e(h,function(){a?g(b,function(a){e(h,function(){if(!a)return this._ctrl.releaseMasterToken(m),null;l.execute(n,c,this._timeout,d,{result:function(a){e(h,function(){this._ctrl.releaseMasterToken(m);return a},l)},timeout:function(){e(h,function(){this._ctrl.releaseMasterToken(m);
h.timeout()},l)},error:function(a){e(h,function(){this._ctrl.releaseMasterToken(m);h.error(a)},l)}})},l)}):k(b,function(a){e(h,function(){if(!a)return this._ctrl.releaseMasterToken(m),null;c.setRenewable(!1);this._ctrl.send(this,this._ctx,n,this._output,c,this._timeout,{result:function(a){e(h,function(){this._ctrl.releaseMasterToken(m);return new p(q,a.request)},l)},timeout:h.timeout,error:h.error})},l)})},l)},timeout:function(){e(h,function(){this._ctrl.releaseMasterToken(m);h.timeout()},l)},error:function(a){e(h,
function(){this._ctrl.releaseMasterToken(m);h.error(a)},l)}})},l)},timeout:h.timeout,error:h.error})}else return new p(q,m);else{if(!b.handshake)return new p(q,m);g(b,function(b){e(h,function(){if(!b)return null;var k=new S(null,a);this._ctrl.buildResponse(this,this._ctx,a,f,c,{result:function(a){e(h,function(){var b=new ba(this._ctrl,this._ctx,k,this._remoteEntity,null,null,a,d,this._timeout);this.setAbort(function(){b.abort()});b.call(h)},l)},timeout:h.timeout,error:h.error})},l)})}},l)}var l=this;
e(h,function(){if(d+2>zb)return this._ctrl.releaseMasterToken(b.tokenTicket),this._maxMessagesHit=!0,null;this._ctrl.sendReceive(this,this._ctx,a,this._input,this._output,b,!0,this._openedStreams,c,{result:function(a){e(h,function(){if(!a)return null;var b=a.response;d+=2;b.getMessageHeader()?f(a):m(a)},l)},timeout:function(){h.timeout()},error:function(a){h.error(a)}})},l)},call:function(a){function b(d,h,k){e(a,function(){this.execute(this._msgCtx,{builder:d,tokenTicket:h},k,this._msgCount,{result:function(b){e(a,
function(){b&&b.output&&b.output.stopCaching();return b},c)},timeout:function(){e(a,function(){this._openedStreams&&(this._output.close(k,v),this._input.close(k,v));a.timeout()},c)},error:function(b){e(a,function(){this._openedStreams&&(this._output.close(k,v),this._input.close(k,v));if(n(b))return null;a.error(b)},c)}})},c)}var c=this;e(a,function(){var d=this._timeout;if(!this._input||!this._output)try{this._remoteEntity.setTimeout(this._timeout);var h=Date.now(),k=this._remoteEntity.openConnection();
this._output=k.output;this._input=k.input;-1!=d&&(d=this._timeout-(Date.now()-h));this._openedStreams=!0}catch(g){this._builder&&this._ctrl.releaseMasterToken(this._tokenTicket);this._output&&this._output.close(this._timeout,v);this._input&&this._input.close(this._timeout,v);if(n(g))return null;throw g;}this._builder?b(this._builder,this._tokenTicket,d):this._ctrl.buildRequest(this,this._ctx,this._msgCtx,this._timeout,{result:function(h){e(a,function(){b(h.builder,h.tokenTicket,d)},c)},timeout:function(){e(a,
function(){this._openedStreams&&(this._output.close(this._timeout,v),this._input.close(this._timeout,v));a.timeout()},c)},error:function(b){e(a,function(){this._openedStreams&&(this._output.close(this._timeout,v),this._input.close(this._timeout,v));if(n(b))return null;a.error(b)},c)}})},c)}})})();Pb.extend({isEncrypted:function(){return!0},isIntegrityProtected:function(){return!0},isNonReplayable:function(){return!0}});Pb.extend({isEncrypted:function(){return!1},isIntegrityProtected:function(){return!0},
isNonReplayable:function(){return!1}});Pb.extend({isEncrypted:function(){return!0},isIntegrityProtected:function(){return!0},isNonReplayable:function(){return!1}});J.Class.create({isNewestMasterToken:function(a,b,c){},isMasterTokenRevoked:function(a,b,c){},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 Ca,kb;(function(){function c(a,b,d,e){this.sessiondata=a;this.tokendata=b;this.signature=d;this.verified=e}Ca=J.Class.create({init:function(c,d,k,e,g,f,r,p,y,F,D){var S=this;b(D,function(){if(k.getTime()<d.getTime())throw new x("Cannot construct a master token that expires before its renewal window opens.");if(0>e||e>R)throw new x("Sequence number "+e+" is outside the valid range.");if(0>g||g>R)throw new x("Serial number "+g+" is outside the valid range.");
var ha=Math.floor(d.getTime()/1E3),B=Math.floor(k.getTime()/1E3),T;if(F)T=F.sessiondata;else{var M=l(p.toByteArray()),A=ia(p.algorithm),ba=l(y.toByteArray()),u=Qa(y.algorithm);if(!A||!u)throw new v(a.UNIDENTIFIED_ALGORITHM,"encryption algorithm: "+p.algorithm+"; signature algorithm: "+y.algorithm);var C={};f&&(C.issuerdata=f);C.identity=r;C.encryptionkey=M;C.encryptionalgorithm=A;C.hmackey=ba;C.signaturekey=ba;C.signaturealgorithm=u;T=sa(JSON.stringify(C),P)}if(F)return Object.defineProperties(this,
{ctx:{value:c,writable:!1,enumerable:!1,configurable:!1},renewalWindowSeconds:{value:ha,writable:!1,enumerable:!1,configurable:!1},expirationSeconds:{value:B,writable:!1,enumerable:!1,configurable:!1},sequenceNumber:{value:e,writable:!1,configurable:!1},serialNumber:{value:g,writable:!1,configurable:!1},issuerData:{value:f,writable:!1,configurable:!1},identity:{value:r,writable:!1,configurable:!1},encryptionKey:{value:p,writable:!1,configurable:!1},signatureKey:{value:y,writable:!1,configurable:!1},
sessiondata:{value:T,writable:!1,enumerable:!1,configurable:!1},verified:{value:F.verified,writable:!1,enumerable:!1,configurable:!1},tokendata:{value:F.tokendata,writable:!1,enumerable:!1,configurable:!1},signature:{value:F.signature,writable:!1,enumerable:!1,configurable:!1}}),this;var z=c.getMslCryptoContext();z.encrypt(T,{result:function(a){b(D,function(){var d={};d.renewalwindow=ha;d.expiration=B;d.sequencenumber=e;d.serialnumber=g;d.sessiondata=l(a);var h=sa(JSON.stringify(d),P);z.sign(h,{result:function(a){b(D,
function(){Object.defineProperties(this,{ctx:{value:c,writable:!1,enumerable:!1,configurable:!1},renewalWindowSeconds:{value:ha,writable:!1,enumerable:!1,configurable:!1},expirationSeconds:{value:B,writable:!1,enumerable:!1,configurable:!1},sequenceNumber:{value:e,writable:!1,enumerable:!1,configurable:!1},serialNumber:{value:g,writable:!1,enumerable:!1,configurable:!1},issuerData:{value:f,writable:!1,configurable:!1},identity:{value:r,writable:!1,configurable:!1},encryptionKey:{value:p,writable:!1,
configurable:!1},signatureKey:{value:y,writable:!1,configurable:!1},sessiondata:{value:T,writable:!1,enumerable:!1,configurable:!1},verified:{value:!0,writable:!1,enumerable:!1,configurable:!1},tokendata:{value:h,writable:!1,enumerable:!1,configurable:!1},signature:{value:a,writable:!1,enumerable:!1,configurable:!1}});return this},S)},error:function(a){D.error(a)}})},S)},error:function(a){D.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 a?this.renewalWindow.getTime()<=a.getTime():this.isVerified()?this.renewalWindow.getTime()<=this.ctx.getTime():!0},isExpired:function(a){return a?this.expiration.getTime()<=a.getTime():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-R+127;return a.sequenceNumber>=b}b=a.sequenceNumber-R+127;return this.sequenceNumber<b},toJSON:function(){var a={};a.tokendata=l(this.tokendata);a.signature=l(this.signature);return a},equals:function(a){return this===a?!0:a instanceof Ca?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()}});kb=function(e,h,k){b(k,function(){var g=e.getMslCryptoContext(),f=h.tokendata,l=h.signature;if("string"!==typeof f||"string"!==typeof l)throw new d(a.JSON_PARSE_ERROR,"mastertoken "+JSON.stringify(h));var U,p;try{U=N(f)}catch(y){throw new r(a.MASTERTOKEN_TOKENDATA_INVALID,"mastertoken "+JSON.stringify(h),y);}if(!U||0==U.length)throw new d(a.MASTERTOKEN_TOKENDATA_MISSING,"mastertoken "+JSON.stringify(h));try{p=N(l)}catch(F){throw new r(a.MASTERTOKEN_SIGNATURE_INVALID,
"mastertoken "+JSON.stringify(h),F);}g.verify(U,p,{result:function(h){b(k,function(){var f,n,l,t,y,A=qa(U,P);try{var F=JSON.parse(A);f=parseInt(F.renewalwindow);n=parseInt(F.expiration);l=parseInt(F.sequencenumber);t=parseInt(F.serialnumber);y=F.sessiondata}catch(x){if(x instanceof SyntaxError)throw new d(a.MASTERTOKEN_TOKENDATA_PARSE_ERROR,"mastertokendata "+A,x);throw x;}if(!f||f!=f||!n||n!=n||"number"!==typeof l||l!=l||"number"!==typeof t||t!=t||"string"!==typeof y)throw new d(a.MASTERTOKEN_TOKENDATA_PARSE_ERROR,
"mastertokendata "+A);if(n<f)throw new r(a.MASTERTOKEN_EXPIRES_BEFORE_RENEWAL,"mastertokendata "+A);if(0>l||l>R)throw new r(a.MASTERTOKEN_SEQUENCE_NUMBER_OUT_OF_RANGE,"mastertokendata "+A);if(0>t||t>R)throw new r(a.MASTERTOKEN_SERIAL_NUMBER_OUT_OF_RANGE,"mastertokendata "+A);var C=new Date(1E3*f),u=new Date(1E3*n),Pa;try{Pa=N(y)}catch(ga){throw new r(a.MASTERTOKEN_SESSIONDATA_INVALID,y,ga);}if(!Pa||0==Pa.length)throw new r(a.MASTERTOKEN_SESSIONDATA_MISSING,y);h?g.decrypt(Pa,{result:function(g){b(k,
function(){var q,f,n,A,y,M,F=qa(g,P);try{var ba=JSON.parse(F);q=ba.issuerdata;f=ba.identity;n=ba.encryptionkey;y=ba.encryptionalgorithm;A=ba.signaturekey;"string"!==typeof A&&(A=ba.hmackey);M=ba.signaturealgorithm}catch(r){if(r instanceof SyntaxError)throw new d(a.MASTERTOKEN_SESSIONDATA_PARSE_ERROR,"sessiondata "+F,r);throw r;}if(q&&"object"!==typeof q||!f||"string"!==typeof n||y&&"string"!==typeof y||"string"!==typeof A||M&&"string"!==typeof M)throw new d(a.MASTERTOKEN_SESSIONDATA_PARSE_ERROR,"sessiondata "+
F);y||(y=L.AES);M||(M=mb.HmacSHA256);var F=Vb(y),x=jb(M);if(!F||!x)throw new v(a.UNIDENTIFIED_ALGORITHM,"encryption algorithm: "+y+"; signature algorithm: "+M);bb(n,F,ob,{result:function(d){bb(A,x,pb,{result:function(a){b(k,function(){var b=new c(g,U,p,h);new Ca(e,C,u,l,t,q,f,d,a,b,k)})},error:function(b){k.error(new v(a.MASTERTOKEN_KEY_CREATION_ERROR,b))}})},error:function(b){k.error(new v(a.MASTERTOKEN_KEY_CREATION_ERROR,b))}})})},error:function(a){k.error(a)}}):(f=new c(null,U,p,h),new Ca(e,C,
u,l,t,null,null,null,null,f,k))})},error:function(a){k.error(a)}})})}})();var Cb,lb;(function(){function c(a,b,d){this.tokendata=a;this.signature=b;this.verified=d}Cb=J.Class.create({init:function(a,c,d,e,g,f,U,p,y){var F=this;b(y,function(){if(d.getTime()<c.getTime())throw new x("Cannot construct a user ID token that expires before its renewal window opens.");if(!e)throw new x("Cannot construct a user ID token without a master token.");if(0>g||g>R)throw new x("Serial number "+g+" is outside the valid range.");
var D=Math.floor(c.getTime()/1E3),S=Math.floor(d.getTime()/1E3),ha=e.serialNumber;if(p){var B=p.tokendata,T=p.signature,M=p.verified,ha=e.serialNumber;Object.defineProperties(this,{ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},renewalWindowSeconds:{value:D,writable:!1,enumerable:!1,configurable:!1},expirationSeconds:{value:S,writable:!1,enumerable:!1,configurable:!1},mtSerialNumber:{value:ha,writable:!1,configurable:!1},serialNumber:{value:g,writable:!1,configurable:!1},issuerData:{value:f,
writable:!1,configurable:!1},user:{value:U,writable:!1,configurable:!1},verified:{value:M,writable:!1,enumerable:!1,configurable:!1},tokendata:{value:B,writable:!1,enumerable:!1,configurable:!1},signature:{value:T,writable:!1,enumerable:!1,configurable:!1}});return this}B={};f&&(B.issuerdata=f);B.identity=U.getEncoded();var B=sa(JSON.stringify(B),P),A=a.getMslCryptoContext();A.encrypt(B,{result:function(c){b(y,function(){var d={};d.renewalwindow=D;d.expiration=S;d.mtserialnumber=ha;d.serialnumber=
g;d.userdata=l(c);var h=sa(JSON.stringify(d),P);A.sign(h,{result:function(c){b(y,function(){Object.defineProperties(this,{ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},renewalWindowSeconds:{value:D,writable:!1,enumerable:!1,configurable:!1},expirationSeconds:{value:S,writable:!1,enumerable:!1,configurable:!1},mtSerialNumber:{value:e.serialNumber,writable:!1,configurable:!1},serialNumber:{value:g,writable:!1,configurable:!1},issuerData:{value:f,writable:!1,configurable:!1},user:{value:U,
writable:!1,configurable:!1},verified:{value:!0,writable:!1,enumerable:!1,configurable:!1},tokendata:{value:h,writable:!1,enumerable:!1,configurable:!1},signature:{value:c,writable:!1,enumerable:!1,configurable:!1}});return this},F)},error:function(a){b(y,function(){a instanceof r&&a.setEntity(e);throw a;},F)}})},F)},error:function(a){b(y,function(){a instanceof r&&a.setEntity(e);throw a;},F)}})},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(a){return a?this.renewalWindow.getTime()<=a.getTime():this.isVerified()?this.renewalWindow.getTime()<=this.ctx.getTime():!0},isExpired:function(a){return a?this.expiration.getTime()<=a.getTime():this.isVerified()?this.expiration.getTime()<=this.ctx.getTime():!1},isBoundTo:function(a){return a&&a.serialNumber==this.mtSerialNumber},toJSON:function(){var a={};a.tokendata=
l(this.tokendata);a.signature=l(this.signature);return a},equals:function(a){return this===a?!0:a instanceof Cb?this.serialNumber==a.serialNumber&&this.mtSerialNumber==a.mtSerialNumber:!1},uniqueKey:function(){return this.serialNumber+":"+this.mtSerialNumber}});lb=function(e,h,k,g){b(g,function(){var f=e.getMslCryptoContext(),l=h.tokendata,U=h.signature;if("string"!==typeof l||"string"!==typeof U)throw(new d(a.JSON_PARSE_ERROR,"useridtoken "+JSON.stringify(h))).setEntity(k);var p,y;try{p=N(l)}catch(F){throw(new r(a.USERIDTOKEN_TOKENDATA_INVALID,
"useridtoken "+JSON.stringify(h),F)).setEntity(k);}if(!p||0==p.length)throw(new d(a.USERIDTOKEN_TOKENDATA_MISSING,"useridtoken "+JSON.stringify(h))).setEntity(k);try{y=N(U)}catch(C){throw(new r(a.USERIDTOKEN_TOKENDATA_INVALID,"useridtoken "+JSON.stringify(h),C)).setEntity(k);}f.verify(p,y,{result:function(h){b(g,function(){var l,B,t,M,A,F=qa(p,P);try{var U=JSON.parse(F);l=parseInt(U.renewalwindow);B=parseInt(U.expiration);t=parseInt(U.mtserialnumber);M=parseInt(U.serialnumber);A=U.userdata}catch(C){if(C instanceof
SyntaxError)throw(new d(a.USERIDTOKEN_TOKENDATA_PARSE_ERROR,"usertokendata "+F,C)).setEntity(k);throw C;}if(!l||l!=l||!B||B!=B||"number"!==typeof t||t!=t||"number"!==typeof M||M!=M||"string"!==typeof A)throw(new d(a.USERIDTOKEN_TOKENDATA_PARSE_ERROR,"usertokendata "+F)).setEntity(k);if(B<l)throw(new r(a.USERIDTOKEN_EXPIRES_BEFORE_RENEWAL,"mastertokendata "+F)).setEntity(k);if(0>t||t>R)throw(new r(a.USERIDTOKEN_MASTERTOKEN_SERIAL_NUMBER_OUT_OF_RANGE,"usertokendata "+F)).setEntity(k);if(0>M||M>R)throw(new r(a.USERIDTOKEN_SERIAL_NUMBER_OUT_OF_RANGE,
"usertokendata "+F)).setEntity(k);var u=new Date(1E3*l),v=new Date(1E3*B);if(!k||t!=k.serialNumber)throw(new r(a.USERIDTOKEN_MASTERTOKEN_MISMATCH,"uit mtserialnumber "+t+"; mt "+JSON.stringify(k))).setEntity(k);var ga;try{ga=N(A)}catch(W){throw(new r(a.USERIDTOKEN_USERDATA_INVALID,A,W)).setEntity(k);}if(!ga||0==ga.length)throw(new r(a.USERIDTOKEN_USERDATA_MISSING,A)).setEntity(k);h?f.decrypt(ga,{result:function(f){b(g,function(){var n,l,t=qa(f,P);try{var B=JSON.parse(t);n=B.issuerdata;l=B.identity}catch(A){if(A instanceof
SyntaxError)throw(new d(a.USERIDTOKEN_USERDATA_PARSE_ERROR,"userdata "+t)).setEntity(k);throw A;}if(n&&"object"!==typeof n||"string"!==typeof l)throw(new d(a.USERIDTOKEN_USERDATA_PARSE_ERROR,"userdata "+t)).setEntity(k);if(!l||0==l.length)throw(new r(a.USERIDTOKEN_IDENTITY_INVALID,"userdata "+t)).setEntity(k);e.getTokenFactory().createUser(e,l,{result:function(a){b(g,function(){if(!a)throw new x("TokenFactory.createUser() returned null in violation of the interface contract.");var b=new c(p,y,h);
new Cb(e,u,v,k,M,n,a,b,g)})},error:function(a){b(g,function(){a instanceof r&&a.setEntity(k);throw a;})}})})},error:function(a){b(g,function(){a instanceof r&&a.setEntity(k);throw a;})}}):(l=new c(p,y,h),new Cb(e,u,v,k,M,null,null,l,g))})},error:function(a){b(g,function(){a instanceof r&&a.setEntity(k);throw a;})}})})}})();var xb,hb,ac;(function(){function c(b,k){var e=b.tokendata;if("string"!==typeof e)throw new d(a.JSON_PARSE_ERROR,"servicetoken "+JSON.stringify(b));var g;try{g=N(e)}catch(m){throw new r(a.SERVICETOKEN_TOKENDATA_INVALID,
"servicetoken "+JSON.stringify(b),m);}if(!g||0==g.length)throw new d(a.SERVICETOKEN_TOKENDATA_MISSING,"servicetoken "+JSON.stringify(b));var f;try{f=JSON.parse(qa(g,P)).name}catch(p){if(p instanceof SyntaxError)throw new d(a.JSON_PARSE_ERROR,"servicetoken "+JSON.stringify(b),p);throw p;}if(!f)throw new d(a.JSON_PARSE_ERROR,"servicetoken "+JSON.stringify(b));return k[f]?k[f]:k[""]}function e(a,b,c){this.tokendata=a;this.signature=b;this.verified=c}xb=J.Class.create({init:function(a,c,d,e,g,m,f,y,F,
C){var D=this;b(C,function(){if(e&&g&&!g.isBoundTo(e))throw new x("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,B=g?g.serialNumber:-1;if(F)return A=F.tokendata,Object.defineProperties(this,{ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},name:{value:c,writable:!1,configurable:!1},mtSerialNumber:{value:u,writable:!1,configurable:!1},uitSerialNumber:{value:B,writable:!1,configurable:!1},
data:{value:d,writable:!1,configurable:!1},encrypted:{value:m,writable:!1,enumerable:!1,configurable:!1},compressionAlgo:{value:f,writable:!1,configurable:!1},verified:{value:F.verified,writable:!1,enumerable:!1,configurable:!1},tokendata:{value:A,writable:!1,enumerable:!1,configurable:!1},signature:{value:F.signature,writable:!1,enumerable:!1,configurable:!1}}),this;var T;f?(T=zc(f,d),T.length<d.length||(f=null,T=d)):(f=null,T=d);var M={};M.name=c;-1!=u&&(M.mtserialnumber=u);-1!=B&&(M.uitserialnumber=
B);M.encrypted=m;f&&(M.compressionalgo=f);if(m&&0<T.length)y.encrypt(T,{result:function(A){b(C,function(){M.servicedata=l(A);var F=sa(JSON.stringify(M),P);y.sign(F,{result:function(e){b(C,function(){Object.defineProperties(this,{ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},name:{value:c,writable:!1,configurable:!1},mtSerialNumber:{value:u,writable:!1,configurable:!1},uitSerialNumber:{value:B,writable:!1,configurable:!1},data:{value:d,writable:!1,configurable:!1},encrypted:{value:m,writable:!1,
enumerable:!1,configurable:!1},compressionAlgo:{value:f,writable:!1,configurable:!1},verified:{value:!0,writable:!1,enumerable:!1,configurable:!1},tokendata:{value:F,writable:!1,enumerable:!1,configurable:!1},signature:{value:e,writable:!1,enumerable:!1,configurable:!1}});return this},D)},error:function(a){b(C,function(){a instanceof r&&(a.setEntity(e),a.setUser(g));throw a;})}})},D)},error:function(a){b(C,function(){a instanceof r&&(a.setEntity(e),a.setUser(g));throw a;})}});else{M.servicedata=l(T);
var A=sa(JSON.stringify(M),P);y.sign(A,{result:function(e){b(C,function(){Object.defineProperties(this,{ctx:{value:a,writable:!1,enumerable:!1,configurable:!1},name:{value:c,writable:!1,configurable:!1},mtSerialNumber:{value:u,writable:!1,configurable:!1},uitSerialNumber:{value:B,writable:!1,configurable:!1},data:{value:d,writable:!1,configurable:!1},encrypted:{value:m,writable:!1,enumerable:!1,configurable:!1},compressionAlgo:{value:f,writable:!1,configurable:!1},verified:{value:!0,writable:!1,enumerable:!1,
configurable:!1},tokendata:{value:A,writable:!1,enumerable:!1,configurable:!1},signature:{value:e,writable:!1,enumerable:!1,configurable:!1}});return this},D)},error:function(a){b(C,function(){a instanceof r&&(a.setEntity(e),a.setUser(g));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 Ca?a.serialNumber==this.mtSerialNumber:a instanceof Cb?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=l(this.tokendata);a.signature=l(this.signature);return a},equals:function(a){return this===a?!0:a instanceof xb?this.name==a.name&&this.mtSerialNumber==a.mtSerialNumber&&this.uitSerialNumber==
a.uitSerialNumber:!1},uniqueKey:function(){return this.name+":"+this.mtSerialNumber+":"+this.uitSerialNumber}});hb=function(a,b,c,d,e,g,m,f,l){new xb(a,b,c,d,e,g,m,f,null,l)};ac=function(h,k,g,f,l,x){b(x,function(){!l||l instanceof db||(l=c(k,l));var p=k.tokendata,y=k.signature;if("string"!==typeof p||"string"!==typeof y)throw(new d(a.JSON_PARSE_ERROR,"servicetoken "+JSON.stringify(k))).setEntity(g).setEntity(f);var F,C;try{F=N(p)}catch(u){throw(new r(a.SERVICETOKEN_TOKENDATA_INVALID,"servicetoken "+
JSON.stringify(k),u)).setEntity(g).setEntity(f);}if(!F||0==F.length)throw(new d(a.SERVICETOKEN_TOKENDATA_MISSING,"servicetoken "+JSON.stringify(k))).setEntity(g).setEntity(f);try{C=N(y)}catch(ha){throw(new r(a.SERVICETOKEN_SIGNATURE_INVALID,"servicetoken "+JSON.stringify(k),ha)).setEntity(g).setEntity(f);}var B,T,M,A,ba,v,z=qa(F,P);try{var G=JSON.parse(z);B=G.name;T=G.mtserialnumber?parseInt(G.mtserialnumber):-1;M=G.uitserialnumber?parseInt(G.uitserialnumber):-1;A=G.encrypted;ba=G.compressionalgo;
v=G.servicedata}catch(Pa){if(Pa instanceof SyntaxError)throw(new d(a.JSON_PARSE_ERROR,"servicetokendata "+z,Pa)).setEntity(g).setEntity(f);throw Pa;}if(!B||"number"!==typeof T||T!=T||"number"!==typeof M||M!=M||"boolean"!==typeof A||ba&&"string"!==typeof ba||"string"!==typeof v)throw(new d(a.JSON_PARSE_ERROR,"servicetokendata "+z)).setEntity(g).setEntity(f);if(G.mtserialnumber&&0>T||T>R)throw(new r(a.SERVICETOKEN_MASTERTOKEN_SERIAL_NUMBER_OUT_OF_RANGE,"servicetokendata "+z)).setEntity(g).setEntity(f);
if(G.uitserialnumber&&0>M||M>R)throw(new r(a.SERVICETOKEN_USERIDTOKEN_SERIAL_NUMBER_OUT_OF_RANGE,"servicetokendata "+z)).setEntity(g).setEntity(f);if(-1!=T&&(!g||T!=g.serialNumber))throw(new r(a.SERVICETOKEN_MASTERTOKEN_MISMATCH,"st mtserialnumber "+T+"; mt "+g)).setEntity(g).setEntity(f);if(-1!=M&&(!f||M!=f.serialNumber))throw(new r(a.SERVICETOKEN_USERIDTOKEN_MISMATCH,"st uitserialnumber "+M+"; uit "+f)).setEntity(g).setEntity(f);A=!0===A;var ga;if(ba){if(!Ta[ba])throw new r(a.UNIDENTIFIED_COMPRESSION,
ba);ga=ba}else ga=null;l?l.verify(F,C,{result:function(c){b(x,function(){if(c){var d;try{d=N(v)}catch(k){throw(new r(a.SERVICETOKEN_SERVICEDATA_INVALID,"servicetokendata "+z,k)).setEntity(g).setEntity(f);}if(!d||0!=v.length&&0==d.length)throw(new r(a.SERVICETOKEN_SERVICEDATA_INVALID,"servicetokendata "+z)).setEntity(g).setEntity(f);if(A&&0<d.length)l.decrypt(d,{result:function(a){b(x,function(){var b=ga?bc(ga,a):a,d=new e(F,C,c);new xb(h,B,b,-1!=T?g:null,-1!=M?f:null,A,ga,l,d,x)})},error:function(a){b(x,
function(){a instanceof r&&(a.setEntity(g),a.setUser(f));throw a;})}});else{d=ga?bc(ga,d):d;var p=new e(F,C,c);new xb(h,B,d,-1!=T?g:null,-1!=M?f:null,A,ga,l,p,x)}}else d=""==v?new Uint8Array(0):null,p=new e(F,C,c),new xb(h,B,d,-1!=T?g:null,-1!=M?f:null,A,ga,l,p,x)})},error:function(a){b(x,function(){a instanceof r&&(a.setEntity(g),a.setUser(f));throw a;})}}):(p=""==v?new Uint8Array(0):null,y=new e(F,C,!1),new xb(h,B,p,-1!=T?g:null,-1!=M?f:null,A,ga,l,y,x))})}})();var ib,Bd;(function(){var a={};ib=
function(b){Object.defineProperties(this,{name:{value:b,writable:!1,configurable:!1}});a[b]=this};J.Class.mixin(ib,{EMAIL_PASSWORD:new ib("EMAIL_PASSWORD"),USER_ID_TOKEN:new ib("USER_ID_TOKEN")});Object.freeze(ib);Bd=function(b){return a[b]?a[b]:null}})();var ab,rd;(function(){ab=J.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 ab?this.scheme==a.scheme:!1},toJSON:function(){var a=
{};a.scheme=this.scheme.name;a.authdata=this.getAuthData();return a}});rd=function(c,e,h,k){b(k,function(){var b=h.scheme,g=h.authdata;if("string"!==typeof b||"object"!==typeof g)throw new d(a.JSON_PARSE_ERROR,"userauthdata "+JSON.stringify(h));var f=c.getUserAuthenticationScheme(b);if(!f)throw new Z(a.UNIDENTIFIED_USERAUTH_SCHEME,b);b=c.getUserAuthenticationFactory(f);if(!b)throw new Z(a.USERAUTH_FACTORY_NOT_FOUND,f.name);b.createData(c,e,g,k)})}})();var Qb=J.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){}}),Rb,Cd;(function(){Rb=ab.extend({init:function m(a,b){m.base.call(this,ib.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 h(a){return this===a?!0:a instanceof Rb?h.base.call(this,this,a)&&this.email==
a.email&&this.password==a.password:!1}});Cd=function(b){var c=b.email,e=b.password;if("string"!==typeof c||"string"!==typeof e)throw new d(a.JSON_PARSE_ERROR,"email/password authdata "+JSON.stringify(b));return new Rb(c,e)}})();Qb.extend({init:function m(a,b){m.base.call(this,ib.EMAIL_PASSWORD);Object.defineProperties(this,{_store:{value:a,writable:!1,enumerable:!1,configurable:!1},_authutils:{value:b,writable:!1,enumerable:!1,configurable:!1}})},createData:function(a,c,d,e){b(e,function(){return Cd(d)})},
authenticate:function(b,c,d,e){if(!(d instanceof Rb))throw new x("Incorrect authentication data type "+d+".");if(!this._authutils.isSchemePermitted(c,this.scheme))throw(new Z(a.USERAUTH_ENTITY_INCORRECT_DATA,"Authentication scheme "+this.scheme+" not permitted for entity "+c+".")).setUser(d);b=d.email;var g=d.password;if(!b||0==b.trim().length||!g||0==g.trim().length)throw(new Z(a.EMAILPASSWORD_BLANK)).setUser(d);b=this._store.isUser(b,g);if(null==b)throw(new Z(a.EMAILPASSWORD_INCORRECT)).setUser(d);
if(!this._authutils.isSchemePermitted(c,b,this.scheme))throw(new Z(a.USERAUTH_ENTITYUSER_INCORRECT_DATA,"Authentication scheme "+this.scheme+" not permitted for entity "+c+".")).setUser(d);if(e&&(c=e.user,!b.equals(c)))throw(new Z(a.USERIDTOKEN_USERAUTH_DATA_MISMATCH,"uad user "+b+"; uit user "+c)).setUser(d);return b}});var Bc;(function(){Bc=ab.extend({init:function h(a,b){h.base.call(this,ib.USER_ID_TOKEN);if(!b.isBoundTo(a))throw new x("User ID token must be bound to master token.");Object.defineProperties(this,
{masterToken:{value:a,writable:!1,configurable:!1},userIdToken:{value:b,writable:!1,configurable:!1}})},getAuthData:function(){var a={};a.mastertoken=JSON.parse(JSON.stringify(this.masterToken));a.useridtoken=JSON.parse(JSON.stringify(this.userIdToken));return a},equals:function k(a){return this===a?!0:a instanceof Bc?k.base.call(this,this,a)&&this.masterToken.equals(a.masterToken)&&this.userIdToken.equals(a.userIdToken):!1}})})();var Je=J.Class.create({isEntityRevoked:function(a){},isSchemePermitted:function(a){}});
Object.freeze({ENTITY_REAUTH:c.ENTITY_REAUTH,ENTITYDATA_REAUTH:c.ENTITYDATA_REAUTH});var Ke=J.Class.create({getTime:function(){},getRandom:function(){},isPeerToPeer:function(){},getMessageCapabilities:function(){},getEntityAuthenticationData:function(a,b){},getMslCryptoContext:function(){},getEntityAuthenticationScheme:function(a){},getEntityAuthenticationFactory:function(a){},getUserAuthenticationScheme:function(a){},getUserAuthenticationFactory:function(a){},getTokenFactory:function(){},getKeyExchangeScheme:function(a){},
getKeyExchangeFactory:function(a){},getKeyExchangeFactories:function(){},getMslStore:function(){}}),Le=J.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(){}}),Dd;(function(){Dd=Le.extend({init:function h(){h.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>R)throw new x("Non-replayable ID "+b+" is outside the valid range.");b=b==R?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 r)throw new x("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 r(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 r)throw new x("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 r)throw new x("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.isMasterTokenBound()){var c=!1,d;for(d in this.masterTokens)if(b.isBoundTo(this.masterTokens[d])){c=!0;break}if(!c)throw new r(a.SERVICETOKEN_MASTERTOKEN_NOT_FOUND,
"st mtserialnumber "+b.mtSerialNumber);}if(b.isUserIdTokenBound()){var c=!1,h;for(h in this.userIdTokens)if(b.isBoundTo(this.userIdTokens[h])){c=!0;break}if(!c)throw new r(a.SERVICETOKEN_USERIDTOKEN_NOT_FOUND,"st uitserialnumber "+b.uitSerialNumber);}},this);b.forEach(function(a){if(a.isUnbound())this.unboundServiceTokens[a.uniqueKey()]=a;else{if(a.isMasterTokenBound()){var b=this.mtServiceTokens[a.mtSerialNumber];b||(b={});b[a.uniqueKey()]=a;this.mtServiceTokens[a.mtSerialNumber]=b}a.isUserIdTokenBound()&&
((b=this.uitServiceTokens[a.uitSerialNumber])||(b={}),b[a.uniqueKey()]=a,this.uitServiceTokens[a.uitSerialNumber]=b)}},this)},getServiceTokens:function(b,c){if(c){if(!b)throw new r(a.USERIDTOKEN_MASTERTOKEN_NULL);if(!c.isBoundTo(b))throw new r(a.USERIDTOKEN_MASTERTOKEN_MISMATCH,"uit mtserialnumber "+c.mtSerialNumber+"; mt "+b.serialNumber);}var d={},e;for(e in this.unboundServiceTokens){var g=this.unboundServiceTokens[e];d[g.uniqueKey()]=g}if(b&&(g=this.mtServiceTokens[b.serialNumber]))for(e in g){var f=
g[e];f.isUserIdTokenBound()||(d[e]=f)}if(c&&(g=this.uitServiceTokens[c.serialNumber]))for(e in g)f=g[e],f.isBoundTo(b)&&(d[e]=f);g=[];for(e in d)g.push(d[e]);return g},removeServiceTokens:function(b,c,d){if(d&&c&&!d.isBoundTo(c))throw new r(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 g=
this.mtServiceTokens[e],f=Object.keys(g);f.forEach(function(a){g[a].name==b&&delete g[a]},this);this.mtServiceTokens[e]=g}for(var l in this.uitServiceTokens)g=this.uitServiceTokens[l],e=Object.keys(g),e.forEach(function(a){g[a].name==b&&delete g[a]},this),this.uitServiceTokens[l]=g}if(c&&!d){if(g=this.mtServiceTokens[c.serialNumber])f=Object.keys(g),f.forEach(function(a){var c=g[a];b&&c.name!=b||delete g[a]},this),this.mtServiceTokens[c.serialNumber]=g;for(l in this.uitServiceTokens){var y=this.uitServiceTokens[l];
e=Object.keys(y);e.forEach(function(a){var d=y[a];b&&d.name!=b||d.isBoundTo(c)&&delete y[a]},this);this.uitServiceTokens[l]=y}}d&&(g=this.uitServiceTokens[d.serialNumber])&&(e=Object.keys(g),e.forEach(function(a){var d=g[a];b&&d.name!=b||c&&!d.isBoundTo(c)||delete g[a]},this),this.uitServiceTokens[d.serialNumber]=g)},clearServiceTokens:function(){[this.unboundServiceTokens,this.mtServiceTokens,this.uitServiceTokens].forEach(function(a){for(var b in a)delete a[b]},this)}})})();var zc,bc;(function(){var b=
Ta;zc=function(c,d){switch(c){case b.LZW:return nrdp.compress(d,"lzw",!0);case b.GZIP:if("function"===typeof nb)return nb(d);default:throw new r(a.UNSUPPORTED_COMPRESSION,c);}};bc=function(c,d,e){switch(c){case b.LZW:return nrdp.uncompress(d,"lzw",!0);case b.GZIP:if("function"===typeof Na)return Na(d);default:throw new r(a.UNSUPPORTED_COMPRESSION,c.name());}}})();var H;(function(){H=function(b,c,d){a.call(this,2E5+b,c,d)}})();J.Class.mixin(H,{ASN1_PARSE_ERROR:new H(22,c.FAIL,"Error parsing ASN.1."),
ASN1_ENCODE_ERROR:new H(23,c.FAIL,"Error encoding ASN.1."),XML_PARSE_ERROR:new H(49,c.FAIL,"Error parsing XML."),XML_ENCODE_ERROR:new H(50,c.FAIL,"Error encoding XML."),MASTERTOKEN_SEQUENCE_NUMBER_OUT_OF_SYNC:new H(1009,c.ENTITY_REAUTH,"Master token sequence number does not have the expected value."),MASTERTOKEN_IDENTITY_REVOKED:new H(1013,c.ENTITY_REAUTH,"Master token entity identity is revoked."),USERIDTOKEN_IDENTITY_NOT_FOUND:new H(2013,c.USER_REAUTH,"The user identity was not found."),USERIDTOKEN_PASSWORD_VERSION_CHANGED:new H(2014,
c.USER_REAUTH,"The user identity must be reauthenticated because the password version changed."),USERIDTOKEN_INCORRECT_MSLUSER:new H(2015,c.FAIL,"The user ID token MSL user type is incorrect."),USERIDTOKEN_INVALID_MSLUSER:new H(2016,c.USER_REAUTH,"The user ID token MSL user is invalid."),ENTITY_NOT_FOUND:new H(4005,c.FAIL,"Entity not recognized."),INCORRECT_ENTITYAUTH_DATA:new H(4006,c.FAIL,"Entity used incorrect entity authentication data type."),NPTICKET_GRACE_PERIOD_EXCEEDED:new H(4008,c.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,c.ENTITYDATA_REAUTH,"NP-Ticket service ID is missing."),NPTICKET_SERVICE_ID_DISALLOWED:new H(4010,c.ENTITYDATA_REAUTH,"NP-Ticket service ID is not allowed."),NPTICKET_NOT_YET_VALID:new H(4011,c.ENTITYDATA_REAUTH,"NP-Ticket issuance date is in the future."),NPTICKET_EXPIRED:new H(4012,c.ENTITYDATA_REAUTH,"NP-Ticket has expired."),NPTICKET_PRIVATE_KEY_NOT_FOUND:new H(4013,
c.ENTITYDATA_REAUTH,"No private key found for NP-Ticket GUID."),NPTICKET_COOKIE_VERIFICATION_FAILED:new H(4014,c.ENTITYDATA_REAUTH,"NP-Ticket cookie signature verification failed."),NPTICKET_INCORRECT_COOKIE_VERSION:new H(4015,c.ENTITYDATA_REAUTH,"Incorrect NP-Ticket cookie version."),NPTICKET_BROKEN:new H(4016,c.ENTITYDATA_REAUTH,"NP-Ticket broken."),NPTICKET_VERIFICATION_FAILED:new H(4017,c.ENTITYDATA_REAUTH,"NP-Ticket signature verification failed."),NPTICKET_ERROR:new H(4018,c.ENTITYDATA_REAUTH,
"Unknown NP-Ticket TCM error."),NPTICKET_CIPHER_INFO_NOT_FOUND:new H(4019,c.ENTITYDATA_REAUTH,"No cipher information found for NP-Ticket."),NPTICKET_INVALID_CIPHER_INFO:new H(4020,c.ENTITYDATA_REAUTH,"Cipher information for NP-Ticket is invalid."),NPTICKET_UNSUPPORTED_VERSION:new H(4021,c.ENTITYDATA_REAUTH,"Unsupported NP-Ticket version."),NPTICKET_INCORRECT_KEY_LENGTH:new H(4022,c.ENTITYDATA_REAUTH,"Incorrect NP-Ticket public key length."),CRYPTEX_RSA_KEY_SET_NOT_FOUND:new H(4024,c.FAIL,"Cryptex RSA key set not found."),
ENTITY_REVOKED:new H(4025,c.FAIL,"Entity is revoked."),NPTICKET_COOKIE_PARSE_ERROR:new H(4027,c.ENTITYDATA_REAUTH,"Error parsing NP-Ticket cookie."),ANYCAST_CHALLENGE_PARSE_ERROR:new H(4028,c.ENTITYDATA_REAUTH,"Error parsing Anycast challenge."),ANYCAST_CHALLENGE_REJECTED:new H(4029,c.ENTITYDATA_REAUTH,"Anycast challenge is not acceptable."),FORCE_LOGIN:new H(5E3,c.USERDATA_REAUTH,"User must login again."),NETFLIXID_COOKIES_EXPIRED:new H(5001,c.USERDATA_REAUTH,"Netflix ID cookie identity has expired."),
NETFLIXID_COOKIES_BLANK:new H(5002,c.USERDATA_REAUTH,"Netflix ID or Secure Netflix ID cookie is blank."),AUTHMGR_COMMS_FAILURE:new H(5006,c.TRANSIENT_FAILURE,"Error communicating with authentication manager."),EMAILPASSWORD_INCORRECT:new H(5007,c.USERDATA_REAUTH,"Email or password is incorrect."),SSOTOKEN_BLANK:new H(5009,c.SSOTOKEN_REJECTED,"SSO token is blank."),SSOTOKEN_NOT_ASSOCIATED:new H(5010,c.USERDATA_REAUTH,"SSO token is not associated with a Netflix user."),PROFILEGUID_BLANK:new H(5012,
c.USERDATA_REAUTH,"Profile GUID is blank."),SSOTOKEN_INVALID:new H(5015,c.SSOTOKEN_REJECTED,"SSO token invalid."),ACCTMGR_COMMS_FAILURE:new H(5017,c.TRANSIENT_FAILURE,"Error communicating with the account manager."),SSO_ASSOCIATION_FAILURE:new H(5018,c.TRANSIENT_FAILURE,"SSO user association failed."),SSO_DISASSOCIATION_FAILURE:new H(5019,c.TRANSIENT_FAILURE,"SSO user disassociation failed."),MDX_USERAUTH_VERIFICATION_FAILED:new H(5020,c.USERDATA_REAUTH,"MDX user authentication data verification failed."),
MDX_USERAUTH_ACTION_INVALID:new H(5022,c.USERDATA_REAUTH,"MDX user authentication data action is invalid."),CTICKET_DECRYPT_ERROR:new H(5023,c.USERDATA_REAUTH,"CTicket decryption failed."),CTICKET_CRYPTOCONTEXT_ERROR:new H(5026,c.USERDATA_REAUTH,"Error creating CTicket crypto context."),MDX_PIN_BLANK:new H(5027,c.USERDATA_REAUTH,"MDX controller or target PIN is blank."),MDX_PIN_MISMATCH:new H(5028,c.USERDATA_REAUTH,"MDX controller and target PIN mismatch."),MDX_USER_UNKNOWN:new H(5029,c.USERDATA_REAUTH,
"MDX controller user ID token or CTicket is not decrypted or verified."),MDX_CONTROLLERDATA_INVALID:new H(5031,c.USERDATA_REAUTH,"MDX controller authentication data is invalid."),USERAUTH_ENTITY_MISMATCH:new H(5032,c.USERDATA_REAUTH,"User authentication data does not match entity identity."),USERAUTH_INCORRECT_DATA:new H(5033,c.FAIL,"Entity used incorrect user authentication data type."),SSO_ASSOCIATION_WITH_NONMEMBER:new H(5034,c.USERDATA_REAUTH,"SSO user association failed because the customer is not a member."),
SSO_ASSOCIATION_WITH_FORMERMEMBER:new H(5035,c.USERDATA_REAUTH,"SSO user association failed because the customer is a former member."),SSO_ASSOCIATION_CONFLICT:new H(5036,c.USERDATA_REAUTH,"SSO user association failed because the token identifies a different member."),PROFILE_SWITCH_DISALLOWED:new H(5038,c.TRANSIENT_FAILURE,"Unable to switch user profile."),MEMBERSHIPCLIENT_COMMS_FAILURE:new H(5039,c.TRANSIENT_FAILURE,"Error communicating with the membership manager."),USERIDTOKEN_IDENTITY_NOT_ASSOCIATED_WITH_ENTITY:new H(5040,
c.USERDATA_REAUTH,"The entity is not associated with the user."),INCORRECT_MSLUSER:new H(5041,c.FAIL,"The MSL user type is incorrect."),NONREPLAYABLE_ID_OUT_OF_RANGE:new H(6032,c.FAIL,"Non-replayable message non-replayable ID is out of range."),KEYX_INVALID_GUID:new H(7E3,c.FAIL,"Invalid key exchange GUID."),KEYX_COMMS_FAILURE:new H(7001,c.TRANSIENT_FAILURE,"Error communicating with key exchange service"),KEYX_IDENTITY_FAILURE:new H(7002,c.FAIL,"Identity in challenge doesn't match device identity"),
CRYPTEX_ENCRYPTION_ERROR:new H(8E3,c.FAIL,"Error encrypting data with cryptex."),CRYPTEX_DECRYPTION_ERROR:new H(8001,c.FAIL,"Error decrypting data with cryptex."),CRYPTEX_MAC_ERROR:new H(8002,c.FAIL,"Error computing MAC with cryptex."),CRYPTEX_VERIFY_ERROR:new H(8003,c.FAIL,"Error verifying MAC or signature with cryptex."),CRYPTEX_CONTEXT_CREATION_FAILURE:new H(8004,c.FAIL,"Error creating cryptex cipher or MAC context."),DATAMODEL_DEVICE_ACCESS_ERROR:new H(8005,c.TRANSIENT_FAILURE,"Error accessing data model device."),
DATAMODEL_DEVICETYPE_NOT_FOUND:new H(8006,c.FAIL,"Data model device type not found."),CRYPTEX_KEYSET_UNSUPPORTED:new H(8007,c.FAIL,"Cryptex key set not supported."),CRYPTEX_PRIVILEGE_EXCEPTION:new H(8008,c.FAIL,"Insufficient privileges for cryptex operation."),CRYPTEX_WRAP_ERROR:new H(8009,c.FAIL,"Error wrapping data with cryptex."),CRYPTEX_UNWRAP_ERROR:new H(8010,c.FAIL,"Error unwrapping data with cryptex."),CRYPTEX_COMMS_FAILURE:new H(8011,c.TRANSIENT_FAILURE,"Error comunicating with cryptex."),
CRYPTEX_SIGN_ERROR:new H(8012,c.FAIL,"Error computing signature with cryptex."),CRYPTEX_FINGERPRINT_ERROR:new H(8013,c.FAIL,"Error computing key fingerprint with cryptex.")});Object.freeze(H);var Ed;(function(){Ed=db.extend({init:function h(a,b,c){h.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 v(a.WRAP_NOT_SUPPORTED))},unwrap:function(b,c,d){d.error(new v(a.UNWRAP_NOT_SUPPORTED))},sign:function(c,d){b(d,function(){if(!this.privateKey)throw new v(a.SIGN_NOT_SUPPORTED,"no private key");var b=Ia.sign(da.RSASSA_SHA1,this.privateKey,c);b.oncomplete=function(){d.result(b.result)};b.onerror=function(){d.error(new v(a.SIGNATURE_ERROR))}},this)},verify:function(a,b,c){c.result(a)}})})();var Fd;(function(){Fd=db.extend({init:function h(a){h.base.call(this);Object.defineProperties(this,
{signatureKey:{value:a,writable:!1,enumerable:!1,configurable:!1}})},encrypt:function(a,b){b.result(a)},decrypt:function(b,c){c.result(new v(a.DECRYPT_NOT_SUPPORTED))},wrap:function(b,c){c.error(new v(a.WRAP_NOT_SUPPORTED))},unwrap:function(b,c){c.error(new v(a.UNWRAP_NOT_SUPPORTED))},sign:function(c,d){b(d,function(){ma.sign(this.signatureKey.algorithm,this.signatureKey,c).then(function(a){Kb(new Uint8Array(a),{result:function(a){d.result(a.bytes)},error:d.error})},function(b){d.error(new v(a.SIGNATURE_ERROR))})},
this)},verify:function(b,c){callback.error(new v(a.VERIFY_NOT_SUPPORTED))}})})();var dc;(function(){dc=Va.extend({init:function h(a){h.base.call(this,pa.ANYCAST);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 k(a){return this===a?!0:a instanceof dc?k.base.call(this,a)&&this.identity===a.identity:!1}})})();var $a,Gd;(function(){$a=Va.extend({init:function h(a){h.base.call(this,
pa.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 k(a){return this===a?!0:a instanceof $a?k.base.call(this,a)&&this.identity==a.identity:!1}});Gd=function(b){var c=b.identity;if(!c)throw new d(a.JSON_PARSE_ERROR,"mgk authdata"+JSON.stringify(b));return new $a(c)}})();var Me=sb.extend({init:function h(a){h.base.call(this,pa.MGK);Object.defineProperties(this,
{localIdentity:{value:a,writable:!1,enumerable:!1,configurable:!1}})},createData:function(a,b){return Gd(b)},getCryptoContext:function(b,c){if(!(c instanceof $a))throw new x("Incorrect authentication data type "+JSON.stringify(c)+".");if(c.identity!=this.localIdentity)throw(new g(a.ENTITY_NOT_FOUND,"mgk "+c.identity)).setEntity(c);return new Lb}}),Gb,Hd;(function(){Gb=Va.extend({init:function k(a,b){k.base.call(this,pa.NPTICKET);var c=b.algorithm.npTicketExpiration,d=b.algorithm.npTicket,e=b.algorithm.npTicketIssue,
g=b.algorithm.npTicketFake;if(c<e)throw new x("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:g,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 q(a){return this===a?!0:a instanceof Gb?q.base.call(this,a)&&f(this.npticket,a.npticket):!1},getIdentity:function(){return this.identity},getPrivateKey:function(){return this.privateKey}});Hd=function(){throw new g(a.UNSUPPORTED_ENTITY_AUTH,
"npticket");}})();var Ne=sb.extend({init:function k(a){k.base.call(this,pa.NPTICKET)},createData:function(a,b){return Hd(b)},getCryptoContext:function(b,c){if(!(c instanceof Gb))throw new x("Incorrect authentication data type "+c+".");var d=c.getIdentity(),e=c.getPrivateKey();if(!d)throw(new g(a.ENTITY_NOT_FOUND,"npticket "+d)).setEntity(c);if(!e)throw(new g(a.NPTICKET_PRIVATE_KEY_NOT_FOUND,"npticket "+d)).setEntity(c);return new Ed(b,d,e)}}),pa;(function(){pa=function(a,b,c){la.call(this,a,b,c)};
J.Class.mixin(pa,{MGK:new pa("MGK",!0,!0),MGK_PROFILE:new pa("MGK_PROFILE",!0,!0),NPTICKET:new pa("NPTICKET",!1,!0),ECC:new pa("ECC",!1,!0),ANYCAST:new pa("ANYCAST",!1,!0)});Object.freeze(pa)})();var Id,Cc,Jd,Kd,Ld;(function(){function c(a,d,e){b(e,function(){Ea(a,{result:function(a){Ea(d,{result:function(b){e.result({encryptionKey:a,cmacKey:b})},error:e.error})},error:e.error})})}var e=Cc=Xa.extend({init:function U(a,b,c){U.base.call(this,Aa.ANYCAST);a={baseKey:{value:a,writable:!1,configurable:!1},
slotId:{value:b,writable:!1,configurable:!1},keyRequest:{value:l(c),writable:!1,configurable:!1}};Object.defineProperties(this,a)},getKeydata:function(){var a={};a.slotid=this.slotId;a.keyrequest=this.keyRequest;return a},equals:function p(a){return a===this?!0:a instanceof Cc?p.base.call(this,a)&&this.slotId==a.slotId&&this.keyRequest==a.keyRequest:!1},uniqueKey:function y(){return y.base.call(this)+":"+this.slotId+":"+this.keyRequest}});Jd=function(b){var c=b.slotid,g=b.keyrequest;if("string"!==
typeof c||"string"!==typeof g)throw new d(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(b));if(!isUuid)throw new X(H.KEYX_INVALID_GUID,"keydata "+JSON.stringify(b));return new e(c,g)};var g=Kd=Ya.extend({init:function F(a,b,c,d){F.base.call(this,a,Aa.ANYCAST);Object.defineProperties(this,{keyResponse:{value:b,writable:!1,configurable:!1},encryptionKeyId:{value:c,writable:!1,configurable:!1},cmacKeyId:{value:d,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.encryptionkeyid=this.encryptionKeyId;
a.cmackeyid=this.cmacKeyId;a.keyresponse=this.keyResponse;return a},equals:function na(a){return this===a?!0:a instanceof Kd?na.base.call(this,a)&&this.keyResponse==a.keyResponse&&this.encryptionKeyId==a.encryptionKeyId&&this.cmacKeyId==a.cmacKeyId:!1},uniqueKey:function S(){return S.base.call(this)+":"+keyResponse+":"+encryptionKeyId+":"+cmacKeyId}});Ld=function(b,c){var e=c.keyresponse,k=c.encryptionkeyid,f=c.cmackeyid;if("string"!==typeof e||"string"!==typeof k||"string"!==typeof f)throw new d(a.JSON_PARSE_ERROR,
"keydata "+JSON.stringify(c));return new g(b,e,k,f)};Id=za.extend({init:function ha(){ha.base.call(this,Aa.ANYCAST)},createRequestData:function(a,c,d){b(d,function(){return Jd(c)})},createResponseData:function(a,b,c){return Ld(b,c)},generateResponse:function(b,c,d,e){e.error(new X(a.UNSUPPORTED_KEYX_SCHEME))},getCryptoContext:function(d,f,l,M,A){function ba(e,g,f){b(A,function(){var l=g.baseKey;ma.deriveKey({name:l.algorithm.name,params:{cdmResponseData:f.keyResponse,keKeyId:""+g.slotId+";"+f.encryptionKeyId,
khKeyId:""+g.slotId+";"+f.cmacKeyId}},l).then(function(a){c(a.encryptionKey,a.hmacKey,{result:function(a){b(A,function(){var b=f.masterToken,c=e.getIdentity();return new ua(d,b,c,a.encryptionKey,a.cmacKey)},C)},error:function(a){b(A,function(){a instanceof r&&a.setEntity(e);throw a;})}})},function(b){A.error((new v(a.DERIVEKEY_ERROR,"",b)).setEntity(e))})},C)}var C=this;b(A,function(){if(!(f instanceof e))throw new x("Key request data "+JSON.stringify(f)+" was not created by this factory.");if(!(l instanceof
g))throw new x("Key response data "+JSON.stringify(l)+" was not created by this factory.");d.getEntityAuthenticationData(null,{result:function(a){b(A,function(){ba(a,f,l)},C)},error:A.error})},C)}})})();var Md,Dc,Ec,Nd,Od;(function(){function c(a){for(var b=0,d=0;d<a.length&&0==a[d];++d)++b;if(1==b)return a;d=new Uint8Array(a.length-b+1);d[0]=0;d.set(a.subarray(b),1);return d}function e(a,c,d,g){b(g,function(){Ea(a,{result:function(a){Ea(c,{result:function(b){Ea(d,{result:function(c){g.result({encryptionKey:a,
hmacKey:b,wrappingKey:c})},error:g.error})},error:g.error})},error:g.error})})}var g=Dc={PSK:"PSK",MGK:"MGK",WRAP:"WRAP"};Od=J.Class.create({addDerivationKey:function(a,b){},getDerivationKey:function(a){},removeDerivationKey:function(a){}});var t=Ec=Xa.extend({init:function y(a,b,c,d,e){y.base.call(this,Aa.AUTHENTICATED_DH);switch(a){case g.WRAP:if(!e)throw new x("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=l(c(this.publicKey));a.parametersid=this.parametersId;this.wrapdata&&(a.wrapdata=l(this.wrapdata));return a},equals:function F(a){if(a===this)return!0;if(!(a instanceof Ec))return!1;var b=
this.privateKey===a.privateKey||this.privateKey&&a.privateKey&&f(this.privateKey.getEncoded(),a.privateKey.getEncoded());return F.base.call(this,a)&&this.mechanism==a.mechanism&&this.parametersId==a.parametersId&&f(this.publicKey,a.publicKey)&&f(this.wrapdata,a.wrapdata)&&b},uniqueKey:function na(){var a=na.base.call(this)+":"+this.mechanism+":"+this.parametersId+":"+z(this.publicKey);this.wrapdata&&(a+=":"+z(this.wrapdata));return a}}),C=Nd=Ya.extend({init:function S(a,b,c,d){S.base.call(this,a,
Aa.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=l(this.wrapdata);var b=c(this.publicKey);a.publickey=l(b);return a},equals:function ha(a){return this===a?!0:a instanceof Nd?ha.base.call(this,a)&&this.parametersId==a.parametersId&&f(this.publicKey,a.publicKey)&&f(this.wrapdata,
a.wrapdata):!1},uniqueKey:function B(){return B.base.call(this)+":"+this.parametersId+":"+z(this.publicKey)+":"+z(this.wrapdata)}});Md=za.extend({init:function T(a,b){T.base.call(this,Aa.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,c,d){b(d,function(){return RequestData$parse(c)})},createResponseData:function(b,e,g){b=g.wrapdata;var f=g.parametersid,
l=g.publickey;if("string"!==typeof b||"string"!==typeof f||"string"!==typeof l)throw new d(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(g));var q;try{q=N(b)}catch(n){throw new X(a.KEYX_WRAPPING_KEY_MISSING,"keydata "+g.toString(),n);}if(!q||0==q.length)throw new X(a.KEYX_WRAPPING_KEY_MISSING,"keydata "+g.toString());var t;try{var r=N(l);t=c(r)}catch(x){throw new X(a.KEYX_INVALID_PUBLIC_KEY,"keydata "+JSON.stringify(g),x);}if(!t||0==t.length)throw new X(a.KEYX_INVALID_PUBLIC_KEY,"keydata "+JSON.stringify(g));
return new C(e,f,t,q)},generateResponse:function(c,d,k,f){function u(c,d,k){b(f,function(){var b=request.mechanism,c=request.wrapdata,A=request.publicKey;switch(b){case g.PSK:case g.MGK:c=this.repository.getDerivationKey();if(!c)throw new X(a.UNSUPPORTED_KEYX_MECHANISM,b);break;case g.WRAP:c=this.repository.getDerivationKey(c);if(!c)throw new X(a.KEYX_DERIVATION_KEY_MISSING,l(requestWrapdata));break;default:throw new X(a.UNSUPPORTED_KEYX_MECHANISM,b);}ma.deriveKey({name:da.AUTHENTICATED_DH.name,params:{"public":A,
kd:c}},k).then(function(a){e(a.encryptionKey,a.hmacKey,a.wrappingKey,{result:function(a){z(d,a)},error:f.error})},function(b){f.error(new v(a.DERIVEKEY_ERROR,"",b))})},G)}function z(a,d){b(f,function(){var e=request.parametersId;c.getMslCryptoContext().wrap(d.derivationKey,{result:function(g){g=c.getTokenFactory();k instanceof Ca?g.renewMasterToken(c,k,d.encryptionKey,d.hmacKey,{result:function(d){b(f,function(){var b=new ua(c,d),g=new C(d,e,a);return new za.KeyExchangeData(g,b)},G)},error:function(a){b(f,
function(){a instanceof r&&a.setEntity(k);throw a;},G)}}):g.createMasterToken(c,k,d.encryptionKey,d.hmacKey,{result:function(d){b(f,function(){var b=new ua(c,d),g=new C(d,e,a);return new za.KeyExchangeData(g,b)},G)},error:f.error})},error:f.error})},G)}var G=this;b(f,function(){if(!(d instanceof t))throw new x("Key request data "+JSON.stringify(d)+" was not created by this factory.");var b;if(k instanceof Ca){if(!masterToken.isVerified())throw new Ha(a.MASTERTOKEN_UNTRUSTED,masterToken);b=masterToken.identity}else b=
k;var c=this.params.getParameterSpec(d.parametersId);ma.generateKey({name:da.AUTHENTICATED_DH,prime:c.p,generator:c.g},!1,me).then(function(a){u(b,a.publicKey,a.privateKey)},function(b){f.error(new v(a.GENERATEKEY_ERROR,"Error generating Diffie-Hellman key pair.",b))})},G)},getCryptoContext:function(c,d,k,f,u){function z(d,g,k,f){b(u,function(){ma.deriveKey({name:da.AUTHENTICATED_DH.name,params:{"public":k.publicKey,kd:f.rawKey}},g.privateKey).then(function(a){e(a.encryptionKey,a.hmacKey,a.wrappingKey,
{result:function(a){b(u,function(){this.repository.addDerivationKey(k.wrapdata,a.derivationKey);g.wrapdata&&this.repository.removeDerivationKey(g.wrapdata);var b=k.masterToken,e=d.getIdentity();return new ua(c,b,e,a.encryptionKey,a.hmacKey)},G)},error:function(a){b(u,function(){a instanceof r&&a.setEntity(d);throw a;})}})},function(b){u.error((new v(a.DERIVEKEY_ERROR,"",b)).setEntity(d))})},G)}var G=this;b(u,function(){if(!(d instanceof t))throw new x("Key request data "+JSON.stringify(d)+" was not created by this factory.");
if(!(k instanceof C))throw new x("Key response data "+JSON.stringify(k)+" was not created by this factory.");var e=d.parametersId,q=k.parametersId;if(e!=q)throw(new X(a.KEYX_RESPONSE_REQUEST_MISMATCH,"request "+e+"; response "+q)).setEntity(f);var r=d.mechanism,v=d.wrapdata;c.getEntityAuthenticationData(null,{result:function(c){b(u,function(){var b;switch(r){case g.WRAP:b=this.repository.getDerivationKey(v);if(!b)throw new X(a.KEYX_DERIVATION_KEY_MISSING,l(v));break;case g.PSK:case g.MGK:b=this.repository.getDerivationKey();
if(!b)throw new X(a.UNSUPPORTED_KEYX_MECHANISM,r);break;default:throw new x("Key request data mechanism "+r+" is not supported but it should be.");}z(c,d,k,b)},G)},error:u.error})},G)}})})();var Pd,Fc,Gc,Qd,Rd;(function(){function c(d,g,k,f,l){b(l,function(){switch(g){case e.PSK:var c=new Wa(f),n=d.getEntityAuthenticationFactory(la.PSK);if(!n)throw new X(a.UNSUPPORTED_KEYX_MECHANISM,g);c=n.getCryptoContext(d,c);return new eb(d,fb.A128KW,V,n._kw);case e.MGK:c=new $a(f);n=d.getEntityAuthenticationFactory(pa.MGK);
if(!n)throw new X(a.UNSUPPORTED_KEYX_MECHANISM,g);c=n.getCryptoContext(d,c);return new eb(d,fb.A128KW,V,n._kw);case e.WRAP:c=d.getMslCryptoContext();c.unwrap(k,da.A128KW,Db,{result:function(a){b(l,function(){return new eb(d,fb.A128KW,V,a)})},error:l.error});break;default:throw new X(a.UNSUPPORTED_KEYX_MECHANISM,g);}})}var e=Fc={PSK:"PSK",MGK:"MGK",WRAP:"WRAP"},g=Gc=Xa.extend({init:function p(a,b){p.base.call(this,xa.JWE_LADDER);switch(a){case e.WRAP:if(!b)throw new x("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=l(this.wrapdata));return a},equals:function y(a){return a===this?!0:a instanceof Gc?y.base.call(this,a)&&this.mechanism==a.mechanism&&f(this.wrapdata,a.wrapdata):!1},uniqueKey:function F(){var a=F.base.call(this)+":"+this.mechanism;this.wrapdata&&(a+=":"+z(this.wrapdata));
return a}}),t=Qd=Ya.extend({init:function na(a,b,c,d,e){na.base.call(this,a,xa.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=l(this.wrapKey);a.wrapdata=l(this.wrapdata);a.encryptionkey=l(this.encryptionKey);a.hmackey=l(this.hmacKey);return a},equals:function S(a){return this===
a?!0:a instanceof Qd?S.base.call(this,a)&&f(this.wrapKey,a.wrapKey)&&f(this.wrapdata,a.wrapdata)&&f(this.encryptionKey,a.encryptionKey)&&f(this.hmacKey,a.hmacKey):!1},uniqueKey:function ha(){return ha.base.call(this)+":"+z(this.wrapKey)+":"+z(this.wrapdata)+":"+z(this.encryptionKey)+":"+z(this.hmacKey)}});Rd=J.Class.create({addCryptoContext:function(a,b){},getCryptoContext:function(a){},removeCryptoContext:function(a){}});Pd=za.extend({init:function B(a){B.base.call(this,xa.JWE_LADDER);Object.defineProperties(this,
{repository:{value:a,writable:!1,enumerable:!1,configurable:!1}})},createRequestData:function(c,k,f){b(f,function(){var b=k.mechanism,c=k.wrapdata;if(!b||b==e.WRAP&&(!c||"string"!==typeof c))throw new d(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(k));if(!e[b])throw new X(a.UNIDENTIFIED_KEYX_MECHANISM,b);var f;switch(b){case e.WRAP:try{f=N(c)}catch(l){throw new X(a.KEYX_WRAPPING_KEY_MISSING,"keydata "+k.toString());}if(null==f||0==f.length)throw new X(a.KEYX_WRAPPING_KEY_MISSING,"keydata "+k.toString());
break;default:f=null}return new g(b,f)})},createResponseData:function(b,c,e){b=e.wrapkey;var g=e.wrapdata,k=e.encryptionkey,f=e.hmackey;if(!(b&&"string"===typeof b&&g&&"string"===typeof g&&k&&"string"===typeof k&&f)||"string"!==typeof f)throw new d(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(e));var l,q,n,r;try{l=N(b),q=N(g)}catch(x){throw new v(a.INVALID_SYMMETRIC_KEY,"keydata "+JSON.stringify(e),x);}try{n=N(k)}catch(C){throw new v(a.INVALID_ENCRYPTION_KEY,"keydata "+JSON.stringify(e),C);}try{r=
N(f)}catch(w){throw new v(a.INVALID_HMAC_KEY,"keydata "+JSON.stringify(e),w);}return new t(c,l,q,n,r)},generateResponse:function(d,e,f,l){function q(a,c,e){G.generateSessionKeys(d,{result:function(d){b(l,function(){C(a,c,e,d.encryptionKey,d.hmacKey)},G)},error:function(a){b(l,function(){a instanceof r&&a.setEntity(ga);throw a;})}})}function C(a,g,f,q,n){b(l,function(){c(d,e.mechanism,e.wrapdata,a,{result:function(a){a.wrap(g,{result:function(a){u(g,f,q,n,a)},error:function(a){b(l,function(){a instanceof
r&&a.setEntity(ga);throw a;})}})},error:function(a){b(l,function(){a instanceof r&&a.setEntity(ga);throw a;})}})},G)}function u(a,c,e,g,k){b(l,function(){var f=new eb(d,fb.A128KW,V,a);f.wrap(e,{result:function(a){f.wrap(g,{result:function(b){z(c,k,e,a,g,b)},error:function(a){b(l,function(){a instanceof r&&a.setEntity(ga);throw a;})}})},error:function(a){b(l,function(){a instanceof r&&a.setEntity(ga);throw a;})}})},G)}function z(a,c,e,g,k,q){b(l,function(){var n=d.getTokenFactory();ga?n.renewMasterToken(d,
ga,e,k,{result:function(e){b(l,function(){var b=new ua(d,e),k=new t(e,c,a,g,q);return new za.KeyExchangeData(k,b,l)},G)},error:function(a){b(l,function(){a instanceof r&&a.setEntity(ga);throw a;})}}):n.createMasterToken(d,f,e,k,{result:function(e){b(l,function(){var b=new ua(d,e),k=new t(e,c,a,g,q);return new za.KeyExchangeData(k,b,l)},G)},error:l.error})},G)}var G=this,ga;b(l,function(){if(!(e instanceof g))throw new x("Key request data "+JSON.stringify(e)+" was not created by this factory.");var c=
f;if(f instanceof Ca){if(!f.isVerified())throw new Ha(a.MASTERTOKEN_UNTRUSTED,f);ga=f;c=f.identity}var k=new Uint8Array(16);d.getRandom().nextBytes(k);bb(k,da.A128KW,Db,{result:function(a){b(l,function(){d.getMslCryptoContext().wrap(a,{result:function(b){q(c,a,b)},error:function(a){b(l,function(){a instanceof r&&a.setEntity(ga);throw a;},G)}})},G)},error:function(c){b(l,function(){throw(new v(a.WRAP_KEY_CREATION_FAILURE,null,c)).setEntity(ga);},G)}})},G)},getCryptoContext:function(c,d,k,f,C){function u(a,
d,e,g,k){b(C,function(){var f=new eb(c,fb.A128KW,V,k);f.unwrap(d.encryptionKey,da.AES_CBC,ob,{result:function(k){f.unwrap(d.hmacKey,da.HMAC_SHA256,pb,{result:function(a){b(C,function(){this.repository.addCryptoContext(d.wrapdata,f);this.repository.removeCryptoContext(e);return new ua(c,d.masterToken,g,k,a)},G)},error:function(c){b(C,function(){c instanceof r&&c.setEntity(a);throw c;})}})},error:function(c){b(C,function(){c instanceof r&&c.setEntity(a);throw c;})}})},G)}var G=this;b(C,function(){if(!(d instanceof
g))throw new x("Key request data "+JSON.stringify(d)+" was not created by this factory.");if(!(k instanceof t))throw new x("Key response data "+JSON.stringify(k)+" was not created by this factory.");var f=d.mechanism,A=d.wrapdata;c.getEntityAuthenticationData(null,{result:function(d){b(C,function(){var g=d.getIdentity(),n;switch(f){case e.PSK:n=new Wa(g);var w=c.getEntityAuthenticationFactory(la.PSK);if(!w)throw(new X(a.UNSUPPORTED_KEYX_MECHANISM,f)).setEntity(d);w.getCryptoContext(c,n);n=new eb(c,
fb.A128KW,V,w._kw);break;case e.MGK:n=new $a(g);w=c.getEntityAuthenticationFactory(pa.MGK);if(!w)throw(new X(a.UNSUPPORTED_KEYX_MECHANISM,f)).setEntity(d);w.getCryptoContext(c,n);n=new eb(c,fb.A128KW,V,w._kw);break;case e.WRAP:n=this.repository.getCryptoContext(A);if(!n)throw(new X(a.KEYX_WRAPPING_KEY_MISSING,l(A))).setEntity(d);break;default:throw(new X(a.UNSUPPORTED_KEYX_MECHANISM,f)).setEntity(d);}n.unwrap(k.wrapKey,da.A128KW,Db,{result:function(a){u(d,k,A,g,a)},error:function(a){b(C,function(){a instanceof
r&&a.setEntity(d);throw a;})}})},G)},error:C.error})},G)}})})();var Sd,Td;(function(){function c(d,g,k,f,l){b(l,function(){switch(g){case e.PSK:var c=new Wa(f),n=d.getEntityAuthenticationFactory(la.PSK);if(!n)throw new X(a.UNSUPPORTED_KEYX_MECHANISM,g);c=n.getCryptoContext(d,c);return new C(void 0);case e.MGK:c=new $a(f);n=d.getEntityAuthenticationFactory(pa.MGK);if(!n)throw new X(a.UNSUPPORTED_KEYX_MECHANISM,g);c=n.getCryptoContext(d,c);return new C(void 0);case e.WRAP:c=d.getMslCryptoContext();
c.unwrap(k,da.A128KW,Db,{result:function(a){b(l,function(){return new C(a)})},error:l.error});break;default:throw new X(a.UNSUPPORTED_KEYX_MECHANISM,g);}})}var e={PSK:"PSK",MGK:"MGK",WRAP:"WRAP"},g=Sd=Xa.extend({init:function y(a,b){y.base.call(this,xa.JWK_LADDER);switch(a){case e.WRAP:if(!b)throw new x("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=l(this.wrapdata));return a},equals:function F(a){return a===this?!0:a instanceof Sd?F.base.call(this,a)&&this.mechanism==a.mechanism&&f(this.wrapdata,a.wrapdata):!1},uniqueKey:function na(){var a=na.base.call(this)+":"+this.mechanism;this.wrapdata&&(a+=":"+z(this.wrapdata));return a}}),t=Td=Ya.extend({init:function S(a,b,c,d,e){S.base.call(this,a,xa.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=l(this.wrapKey);a.wrapdata=l(this.wrapdata);a.encryptionkey=l(this.encryptionKey);a.hmackey=l(this.hmacKey);return a},equals:function ha(a){return this===a?!0:a instanceof Td?ha.base.call(this,a)&&f(this.wrapKey,a.wrapKey)&&f(this.wrapdata,a.wrapdata)&&f(this.encryptionKey,
a.encryptionKey)&&f(this.hmacKey,a.hmacKey):!1},uniqueKey:function B(){return B.base.call(this)+":"+z(this.wrapKey)+":"+z(this.wrapdata)+":"+z(this.encryptionKey)+":"+z(this.hmacKey)}}),C=db.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 v(a.ENCRYPT_NOT_SUPPORTED))},decrypt:function(b,c){c.error(new v(a.DECRYPT_NOT_SUPPORTED))},wrap:function(c,d){b(d,function(){ma.wrapKey("jwk",
c.rawKey,this._wrapKey,da.A128KW).then(function(a){d.result(a)},function(b){d.error(new v(a.WRAP_ERROR))})},this)},unwrap:function(c,d,e,g){function k(c){b(g,function(){switch(c.type){case "secret":Ea(c,g);break;case "public":qb(c,g);break;case "private":Eb(c,g);break;default:throw new v(a.UNSUPPORTED_KEY,"type: "+c.type);}})}b(g,function(){ma.unwrapKey("jwk",c,this._wrapKey,da.A128KW,d,!1,e).then(function(a){k(a)},function(b){g.error(new v(a.UNWRAP_ERROR))})},this)},sign:function(b,c){c.error(new v(a.SIGN_NOT_SUPPORTED))},
verify:function(b,c,d){d.error(new v(a.VERIFY_NOT_SUPPORTED))}});za.extend({init:function T(a){T.base.call(this,xa.JWK_LADDER);Object.defineProperties(this,{repository:{value:a,writable:!1,enumerable:!1,configurable:!1}})},createRequestData:function(c,k,f){b(f,function(){var b=k.mechanism,c=k.wrapdata;if(!b||b==e.WRAP&&(!c||"string"!==typeof c))throw new d(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(k));if(!e[b])throw new X(a.UNIDENTIFIED_KEYX_MECHANISM,b);var f;switch(b){case e.WRAP:try{f=N(c)}catch(l){throw new X(a.KEYX_WRAPPING_KEY_MISSING,
"keydata "+k.toString());}if(null==f||0==f.length)throw new X(a.KEYX_WRAPPING_KEY_MISSING,"keydata "+k.toString());break;default:f=null}return new g(b,f)})},createResponseData:function(b,c,e){b=e.wrapkey;var g=e.wrapdata,k=e.encryptionkey,f=e.hmackey;if(!(b&&"string"===typeof b&&g&&"string"===typeof g&&k&&"string"===typeof k&&f)||"string"!==typeof f)throw new d(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(e));var l,n,q,r;try{l=N(b),n=N(g)}catch(C){throw new v(a.INVALID_SYMMETRIC_KEY,"keydata "+JSON.stringify(e),
C);}try{q=N(k)}catch(w){throw new v(a.INVALID_ENCRYPTION_KEY,"keydata "+JSON.stringify(e),w);}try{r=N(f)}catch(x){throw new v(a.INVALID_HMAC_KEY,"keydata "+JSON.stringify(e),x);}return new t(c,l,n,q,r)},generateResponse:function(d,e,f,l){function q(a,c,e){ga.generateSessionKeys(d,{result:function(d){b(l,function(){u(a,c,e,d.encryptionKey,d.hmacKey)},ga)},error:function(a){b(l,function(){a instanceof r&&a.setEntity(W);throw a;})}})}function u(a,g,f,n,q){b(l,function(){c(d,e.mechanism,e.wrapdata,a,
{result:function(a){a.wrap(g,{result:function(a){G(g,f,n,q,a)},error:function(a){b(l,function(){a instanceof r&&a.setEntity(W);throw a;})}})},error:function(a){b(l,function(){a instanceof r&&a.setEntity(W);throw a;})}})},ga)}function G(a,c,d,e,g){b(l,function(){var k=new C(a);k.wrap(d,{result:function(a){k.wrap(e,{result:function(b){z(c,g,d,a,e,b)},error:function(a){b(l,function(){a instanceof r&&a.setEntity(W);throw a;})}})},error:function(a){b(l,function(){a instanceof r&&a.setEntity(W);throw a;
})}})},ga)}function z(a,c,e,g,k,n){b(l,function(){var q=d.getTokenFactory();W?q.renewMasterToken(d,W,e,k,{result:function(e){b(l,function(){var b=new ua(d,e),k=new t(e,c,a,g,n);return new za.KeyExchangeData(k,b,l)},ga)},error:function(a){b(l,function(){a instanceof r&&a.setEntity(W);throw a;})}}):q.createMasterToken(d,f,e,k,{result:function(e){b(l,function(){var b=new ua(d,e),k=new t(e,c,a,g,n);return new za.KeyExchangeData(k,b,l)},ga)},error:l.error})},ga)}var ga=this,W;b(l,function(){if(!(e instanceof
g))throw new x("Key request data "+JSON.stringify(e)+" was not created by this factory.");var c=f;if(f instanceof Ca){if(!f.isVerified())throw new Ha(a.MASTERTOKEN_UNTRUSTED,f);W=f;c=f.identity}var k=new Uint8Array(16);d.getRandom().nextBytes(k);bb(k,da.A128KW,Db,{result:function(a){b(l,function(){d.getMslCryptoContext().wrap(a,{result:function(b){q(c,a,b)},error:function(a){b(l,function(){a instanceof r&&a.setEntity(W);throw a;},ga)}})},ga)},error:function(c){b(l,function(){throw(new v(a.WRAP_KEY_CREATION_FAILURE,
null,c)).setEntity(W);},ga)}})},ga)},getCryptoContext:function(c,d,k,f,u){function G(a,d,e,g,k){b(u,function(){var f=new C(k);f.unwrap(d.encryptionKey,da.AES_CBC,ob,{result:function(k){f.unwrap(d.hmacKey,da.HMAC_SHA256,pb,{result:function(a){b(u,function(){this.repository.addCryptoContext(d.wrapdata,f);this.repository.removeCryptoContext(e);return new ua(c,d.masterToken,g,k,a)},v)},error:function(c){b(u,function(){c instanceof r&&c.setEntity(a);throw c;})}})},error:function(c){b(u,function(){c instanceof
r&&c.setEntity(a);throw c;})}})},v)}var v=this;b(u,function(){if(!(d instanceof g))throw new x("Key request data "+JSON.stringify(d)+" was not created by this factory.");if(!(k instanceof t))throw new x("Key response data "+JSON.stringify(k)+" was not created by this factory.");var f=d.mechanism,z=d.wrapdata;c.getEntityAuthenticationData(null,{result:function(d){b(u,function(){var g=d.getIdentity(),n;switch(f){case e.PSK:n=new Wa(g);var t=c.getEntityAuthenticationFactory(la.PSK);if(!t)throw(new X(a.UNSUPPORTED_KEYX_MECHANISM,
f)).setEntity(d);t.getCryptoContext(c,n);n=new C(void 0);break;case e.MGK:n=new $a(g);t=c.getEntityAuthenticationFactory(pa.MGK);if(!t)throw(new X(a.UNSUPPORTED_KEYX_MECHANISM,f)).setEntity(d);t.getCryptoContext(c,n);n=new C(void 0);break;case e.WRAP:n=this.repository.getCryptoContext(z);if(!n)throw(new X(a.KEYX_WRAPPING_KEY_MISSING,l(z))).setEntity(d);break;default:throw(new X(a.UNSUPPORTED_KEYX_MECHANISM,f)).setEntity(d);}n.unwrap(k.wrapKey,da.A128KW,Db,{result:function(a){G(d,k,z,g,a)},error:function(a){b(u,
function(){a instanceof r&&a.setEntity(d);throw a;})}})},v)},error:u.error})},v)}})})();var Ud,Hc,Vd;(function(){function c(d,g,k,f,l){b(l,function(){switch(g){case e.SESSION:if(!k)throw new X(a.KEYX_MASTER_TOKEN_MISSING,g);var b=d.getMslStore().getCryptoContext(k);if(b)return b;if(!k.isDecrypted())throw new Ha(a.MASTERTOKEN_UNTRUSTED,k);return new ua(d,k);case e.PSK:var b=new Wa(f),c=d.getEntityAuthenticationFactory(la.PSK);if(!c)throw new X(a.UNSUPPORTED_KEYX_KEY_ID,g);return c.getCryptoContext(d,
b);case e.MGK:b=new $a(f);c=d.getEntityAuthenticationFactory(pa.MGK);if(!c)throw new X(a.UNSUPPORTED_KEYX_KEY_ID,g);return c.getCryptoContext(d,b);default:throw new X(a.UNSUPPORTED_KEYX_KEY_ID,g);}})}var e={PSK:"PSK",MGK:"MGK",SESSION:"SESSION"},g=Hc=Xa.extend({init:function p(a){p.base.call(this,xa.SYMMETRIC_WRAPPED);Object.defineProperties(this,{keyId:{value:a,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.keyid=this.keyId;return a},equals:function y(a){return this===a?!0:a instanceof
Hc?y.base.call(this,a)&&this.keyId==a.keyId:!1},uniqueKey:function F(){return F.base.call(this)+":"+this.keyId}}),t=Vd=Ya.extend({init:function na(a,b,c,d){na.base.call(this,a,xa.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=l(this.encryptionKey);a.hmackey=l(this.hmacKey);return a},equals:function S(a){return this===
a?!0:a instanceof Vd?S.base.call(this,a)&&this.keyId==a.keyId&&f(this.encryptionKey,a.encryptionKey)&&f(this.hmacKey,a.hmacKey):!1},uniqueKey:function ha(){return ha.base.call(this)+":"+this.keyId+":"+z(this.encryptionKey)+":"+z(this.hmacKey)}});Ud=za.extend({init:function B(){B.base.call(this,xa.SYMMETRIC_WRAPPED)},createRequestData:function(c,k,f){b(f,function(){var b=k.keyid;if(!b||"string"!==typeof b)throw new d(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(k));if(!e[b])throw new X(a.UNIDENTIFIED_KEYX_KEY_ID,
b);return new g(b)},this)},createResponseData:function(b,c,g){b=g.keyid;var k=g.encryptionkey,f=g.hmackey;if(!b||"string"!==typeof b||!k||"string"!==typeof k||!f||"string"!==typeof f)throw new d(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(g));if(!e[b])throw new X(a.UNIDENTIFIED_KEYX_KEY_ID,b);var l;try{l=N(k)}catch(n){throw new v(a.INVALID_ENCRYPTION_KEY,"keydata "+JSON.stringify(g),n);}var r;try{r=N(f)}catch(C){throw new v(a.INVALID_HMAC_KEY,"keydata "+JSON.stringify(g),C);}return new t(c,b,l,r)},
generateResponse:function(d,e,f,l){function q(g,n){b(l,function(){var q,t;if("string"!==typeof f){if(!f.isVerified())throw new Ha(a.MASTERTOKEN_UNTRUSTED,f);q=f;t=q.identity}else q=null,t=f;c(d,e.keyId,q,t,{result:function(a){a.wrap(g,{result:function(c){a.wrap(n,{result:function(a){C(g,c,n,a)},error:function(a){b(l,function(){a instanceof r&&a.setEntity(q);throw a;},u)}})},error:function(a){b(l,function(){a instanceof r&&a.setEntity(q);throw a;},u)}})},error:function(a){b(l,function(){a instanceof
r&&a.setEntity(q);throw a;},u)}})},u)}function C(a,c,g,k){b(l,function(){var n=d.getTokenFactory();f instanceof Ca?n.renewMasterToken(d,f,a,g,{result:function(a){b(l,function(){var b;try{b=new ua(d,a)}catch(g){if(g instanceof Ha)throw new x("Master token constructed by token factory is not trusted.",g);g instanceof r&&g.setEntity(f);throw g;}var l=new t(a,e.keyId,c,k);return new za.KeyExchangeData(l,b)},u)},error:function(a){b(l,function(){a instanceof r&&a.setEntity(f);throw a;},u)}}):n.createMasterToken(d,
f,a,g,{result:function(a){b(l,function(){var b;try{b=new ua(d,a)}catch(g){if(g instanceof Ha)throw new x("Master token constructed by token factory is not trusted.",g);throw g;}var f=new t(a,e.keyId,c,k);return new za.KeyExchangeData(f,b)},u)},error:l.error})},u)}var u=this;b(l,function(){if(!(e instanceof g))throw new x("Key request data "+JSON.stringify(e)+" was not created by this factory.");this.generateSessionKeys(d,{result:function(a){q(a.encryptionKey,a.hmacKey)},error:function(a){b(l,function(){a instanceof
r&&f instanceof Ca&&a.setEntity(f);throw a;},u)}})},u)},getCryptoContext:function(d,e,f,l,q){function C(a){b(q,function(){a instanceof r&&(a.setEntity(l),a.setEntity(G));throw a;},u)}var u=this,G;b(q,function(){if(!(e instanceof g))throw new x("Key request data "+JSON.stringify(e)+" was not created by this factory.");if(!(f instanceof t))throw new x("Key response data "+JSON.stringify(f)+" was not created by this factory.");var r=e.keyId,v=f.keyId;if(r!=v)throw(new X(a.KEYX_RESPONSE_REQUEST_MISMATCH,
"request "+r+"; response "+v)).setEntity(l);d.getEntityAuthenticationData(null,{result:function(a){b(q,function(){G=a;var e=G.getIdentity();c(d,v,l,e,{result:function(a){a.unwrap(f.encryptionKey,da.AES_CBC,ob,{result:function(c){a.unwrap(f.hmacKey,da.HMAC_SHA256,pb,{result:function(a){d.getEntityAuthenticationData(null,{result:function(e){b(q,function(){var b=e.getIdentity();return new ua(d,f.masterToken,b,c,a)},u)},error:C})},error:C})},error:C})},error:C})},u)},error:C})},u)}})})();var Aa;(function(){Aa=
function(a){xa.call(this,a)};J.Class.mixin(Aa,{AUTHENTICATED_DH:new Aa("AUTHENTICATED_DH"),WIDEVINE:new Aa("WIDEVINE"),ANYCAST:new Aa("ANYCAST"),CDM:new Aa("CDM")});Object.freeze(Aa)})();var Wd,Ic,Xd;(function(){function c(a,d,e){b(e,function(){Ea(a,{result:function(a){Ea(d,{result:function(b){e.result({encryptionKey:a,hmacKey:b})},error:e.error})},error:e.error})})}var e=Ic=Xa.extend({init:function U(a,b){U.base.call(this,Aa.WIDEVINE);if(!b)throw new x("Key request missing key request data.");Object.defineProperties(this,
{baseKey:{value:a,writable:!1,configurable:!1},keyRequest:{value:l(b),writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.keyrequest=this.keyRequest;return a},equals:function p(a){return a===this?!0:a instanceof Ic?p.base.call(this,a)&&this.baseKey===a.baseKey&&this.keyRequest===a.keyRequest:!1},uniqueKey:function y(){return y.base.call(this)+":"+this.baseKey+":"+this.keyRequest}}),g=Xd=Ya.extend({init:function F(a,b,c,d){F.base.call(this,a,Aa.WIDEVINE);Object.defineProperties(this,{keyResponse:{value:b,
writable:!1,configurable:!1},encryptionKeyId:{value:c,writable:!1,configurable:!1},hmacKeyId:{value:d,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.cdmkeyresponse=this.keyResponse;a.encryptionkeyid=this.encryptionKeyId;a.hmackeyid=this.hmacKeyId;return a},equals:function na(a){return this===a?!0:a instanceof Xd?na.base.call(this,a)&&this.keyResponse===a.keyResponse&&this.encryptionKeyId==a.encryptionKeyId&&this.hmacKeyId==a.hmacKeyId:!1},uniqueKey:function S(){return S.base.call(this)+
":"+this.keyResponse+":"+this.encryptionKeyId+":"+this.hmacKeyId}});Wd=za.extend({init:function ha(){ha.base.call(this,Aa.WIDEVINE)},createRequestData:function(a,b,c){throw new x("WidevineExchange::createRequestData not implemented.");},createResponseData:function(b,c,e){b=e.cdmkeyresponse;var k=e.encryptionkeyid,f=e.hmackeyid;if("string"!==typeof b||"string"!==typeof k||"string"!==typeof f)throw new d(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(e));return new g(c,b,k,f)},generateResponse:function(a,
b,c,d){throw new x("WidevineExchange::generateResponse not implemented.");},getCryptoContext:function(d,f,l,C,A){function u(e,g,f){b(A,function(){ma.deriveKey({name:"NFLX-CDM-WIDEVINE",params:{cdmProvisionResponseData:f.keyResponse,keKeyId:f.encryptionKeyId,khKeyId:f.hmacKeyId}},g.baseKey).then(function(a){c(a.encryptionKey,a.hmacKey,{result:function(a){b(A,function(){var b=f.masterToken,c=e.getIdentity();return new ua(d,b,c,a.encryptionKey,a.hmacKey)},G)},error:function(a){b(A,function(){a instanceof
r&&a.setEntity(e);throw a;})}})},function(b){A.error((new v(a.DERIVEKEY_ERROR,"",b)).setEntity(e))})},G)}var G=this;b(A,function(){if(!(f instanceof e))throw new x("Key request data "+JSON.stringify(f)+" was not created by this factory.");if(!(l instanceof g))throw new x("Key response data "+JSON.stringify(l)+" was not created by this factory.");d.getEntityAuthenticationData(null,{result:function(a){b(A,function(){u(a,f,l)},G)},error:A.error})},G)}})})();var Yd,Jc,Zd;(function(){function c(a,d,e){b(e,
function(){Ea(a,{result:function(a){Ea(d,{result:function(b){e.result({encryptionKey:a,hmacKey:b})},error:e.error})},error:e.error})})}var e=Jc=Xa.extend({init:function U(a,b,c){U.base.call(this,Aa.CDM);if(!c)throw new x("Key request missing key request data.");Object.defineProperties(this,{mechanism:{value:a,writable:!1,configurable:!1},baseKey:{value:b,writable:!1,configurable:!1},keyRequest:{value:l(c),writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.mechanism=this.mechanism;a.keyrequest=
this.keyRequest;return a},equals:function p(a){return a===this?!0:a instanceof Jc?p.base.call(this,a)&&this.baseKey===a.baseKey&&this.mechanism===a.mechanism&&this.keyRequest===a.keyRequest:!1},uniqueKey:function y(){return y.base.call(this)+":"+this.baseKey+":"+this.mechanism+":"+this.keyRequest}}),g=Zd=Ya.extend({init:function F(a,b,c,d){F.base.call(this,a,Aa.CDM);Object.defineProperties(this,{keyResponse:{value:b,writable:!1,configurable:!1},encryptionKeyId:{value:c,writable:!1,configurable:!1},
hmacKeyId:{value:d,writable:!1,configurable:!1}})},getKeydata:function(){var a={};a.cdmkeyresponse=this.keyResponse;a.encryptionkeyid=this.encryptionKeyId;a.hmackeyid=this.hmacKeyId;return a},equals:function na(a){return this===a?!0:a instanceof Zd?na.base.call(this,a)&&this.keyResponse===a.keyResponse&&this.encryptionKeyId==a.encryptionKeyId&&this.hmacKeyId==a.hmacKeyId:!1},uniqueKey:function S(){return S.base.call(this)+":"+this.keyResponse+":"+this.encryptionKeyId+":"+this.hmacKeyId}});Yd=za.extend({init:function ha(){ha.base.call(this,
Aa.CDM)},createRequestData:function(a,b,c){throw new x("CdmExchange::createRequestData not implemented.");},createResponseData:function(b,c,e){b=e.cdmkeyresponse;var k=e.encryptionkeyid,f=e.hmackeyid;if("string"!==typeof b||"string"!==typeof k||"string"!==typeof f)throw new d(a.JSON_PARSE_ERROR,"keydata "+JSON.stringify(e));return new g(c,b,k,f)},generateResponse:function(a,b,c,d){throw new x("CdmExchange::generateResponse not implemented.");},getCryptoContext:function(d,f,l,C,A){function u(e,g,f){b(A,
function(){ma.deriveKey({name:"NFLX-CDM-JWELE",params:{cdmProvisionResponseData:f.keyResponse,keKeyId:f.encryptionKeyId,khKeyId:f.hmacKeyId}},g.baseKey).then(function(a){c(a.encryptionKey,a.hmacKey,{result:function(a){b(A,function(){var b=f.masterToken,c=e.getIdentity();return new ua(d,b,c,a.encryptionKey,a.hmacKey)},G)},error:function(a){b(A,function(){a instanceof r&&a.setEntity(e);throw a;})}})},function(b){A.error((new v(a.DERIVEKEY_ERROR,"",b)).setEntity(e))})},G)}var G=this;b(A,function(){if(!(f instanceof
e))throw new x("Key request data "+JSON.stringify(f)+" was not created by this factory.");if(!(l instanceof g))throw new x("Key response data "+JSON.stringify(l)+" was not created by this factory.");d.getEntityAuthenticationData(null,{result:function(a){b(A,function(){u(a,f,l)},G)},error:A.error})},G)}})})();var Hb,$d,ec,Kc,Sb,Lc;(function(){function c(a,b){return"<"+a+">"+b+"</"+a+">"}function e(a){return a.replace(/[<>&"']/g,function(a){return u[a]})}function g(a){return encodeURIComponent(a).replace("%20",
"+").replace(/[!'()]/g,escape).replace(/\*/g,"%2A")}var t=ec={MSL:"MSL",NTBA:"NTBA",MSL_LEGACY:"MSL_LEGACY"},C=J.Class.create({getAction:function(){},getNonce:function(){},getPin:function(){},getSignature:function(){},getEncoding:function(){},equals:function(){}}),p=Kc=C.extend({init:function(c,e,g,k,f,n,q){function p(k){b(q,function(){var b;try{var n={};n.useridtoken=c;n.action=e;n.nonce=g;n.pin=l(k);b=sa(JSON.stringify(n),P)}catch(p){throw new d(a.JSON_ENCODE_ERROR,"MSL-based MDX authdata",p);}f.sign(b,
{result:function(a){t(b,a)},error:q.error})},r)}function t(a,d){b(q,function(){Object.defineProperties(this,{_userIdToken:{value:c,writable:!1,enumerable:!1,configurable:!1},_action:{value:e,writable:!1,enumerable:!1,configurable:!1},_nonce:{value:g,writable:!1,enumerable:!1,configurable:!1},_pin:{value:k,writable:!1,enumerable:!1,configurable:!1},_encoding:{value:a,writable:!1,enumerable:!1,configurable:!1},_signature:{value:d,writable:!1,enumerable:!1,configurable:!1}});return this},r)}var r=this;
b(q,function(){n?t(n.encoding,n.signature):f.encrypt(sa(k,P),{result:function(a){p(a)},error:q.error})},r)},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 p?this._action==a._action&&this._nonce==a._nonce&&this._pin==a._pin&&this._userIdToken.equals(a._userIdToken):
!1}});Kc.ACTION="userauth";var y=function(c,e,g,k,f){function n(k){b(f,function(){var l=qa(g,P),n,p,t,C;try{var y=JSON.parse(l);n=y.useridtoken;p=y.action;t=y.nonce;C=y.pin}catch(u){if(u instanceof SyntaxError)throw new d(a.JSON_PARSE_ERROR,"MDX authdata "+l,u);throw u;}if(!(n&&"object"===typeof n&&p&&"string"===typeof p&&t&&"number"===typeof t&&C)||"string"!==typeof C)throw new d(a.JSON_PARSE_ERROR,"MDX authdata "+l);lb(c,n,e,{result:function(c){b(f,function(){if(!c.isDecrypted())throw new Z(a.USERAUTH_USERIDTOKEN_NOT_DECRYPTED,
"MDX authdata "+l);q(k,c,p,t,C)})},error:function(c){b(f,function(){if(c instanceof r)throw new Z(a.USERAUTH_USERIDTOKEN_INVALID,"MDX authdata "+l,c);throw c;})}})})}function q(a,c,d,e,l){b(f,function(){var n=N(l);a.decrypt(n,{result:function(a){b(f,function(){var b=qa(a,P);new p(c,d,e,b,null,{encoding:g,signature:k},f)})},error:f.error})})}b(f,function(){var d;try{var q=c.getMslStore().getCryptoContext(e);d=q?q:new ua(c,e)}catch(p){if(p instanceof Ha)throw new Z(a.USERAUTH_MASTERTOKEN_NOT_DECRYPTED,
"MDX authdata "+l(g));throw p;}d.verify(g,k,{result:function(a){b(f,function(){if(!a)throw new v(H.MDX_USERAUTH_VERIFICATION_FAILED,"MDX authdata "+l(g));n(d)})},error:f.error})})},u={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&apos;"},G=Sb=C.extend({init:function(a,b,d,g){var f=c("action",e(a)),l=c("nonce",b.toString());d=c("pin",d);f=c("registerdata",f+l+d);f=sa(f,"utf-8");Object.defineProperties(this,{_action:{value:a,writable:!1,enumerable:!1,configurable:!1},_nonce:{value:b,writable:!1,
enumerable:!1,configurable:!1},_pin:{value:null,writable:!1,enumerable:!1,configurable:!1},_encoding:{value:f,writable:!1,enumerable:!1,configurable:!1},_signature:{value:g,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 G?this._action==a._action&&
this._nonce==a._nonce&&this._pin==a._pin:!1}});Sb.ACTION="regpairrequest";var z=Lc=C.extend({init:function(a,d,f,p,t,r){function C(f){b(r,function(){var b=l(f),t=c("action",e(a)),C=c("nonce",d.toString()),u=c("pin",b),t=c("registerdata",t+C+u),x=sa(t,"utf-8"),b="action="+g(a)+"&nonce="+g(d.toString())+"&pin="+g(b);p.sign(sa(b,"utf-8"),{result:function(a){y(x,a)},error:r.error})},u)}function y(c,e){b(r,function(){Object.defineProperties(this,{_action:{value:a,writable:!1,enumerable:!1,configurable:!1},
_nonce:{value:d,writable:!1,enumerable:!1,configurable:!1},_pin:{value:f,writable:!1,enumerable:!1,configurable:!1},_encoding:{value:c,writable:!1,enumerable:!1,configurable:!1},_signature:{value:e,writable:!1,enumerable:!1,configurable:!1}});return this},u)}var u=this;b(r,function(){t?y(t.encoding,t.signature):p.encrypt(sa(f,"utf-8"),{result:function(a){C(a)},error:r.error})},u)},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 z?this._action==a._action&&this._nonce==a._nonce&&this._pin==a._pin:!1}});Lc.ACTION=Sb.ACTION;var E=function(a,c,e,k,f){b(f,function(){var p=a.getMslStore().getCryptoContext(c),q=p?p:new ua(a,c),p=qa(e,"utf-8"),t=(new DOMParser).parseFromString(p,"application/xml"),p=t.getElementsByTagName("action"),r=t.getElementsByTagName("nonce"),t=t.getElementsByTagName("pin"),
C=p&&1==p.length&&p[0].firstChild?p[0].firstChild.nodeValue:null,y=r&&1==r.length&&r[0].firstChild?parseInt(r[0].firstChild.nodeValue):null,u=t&&1==t.length&&t[0].firstChild?t[0].firstChild.nodeValue:null;if(!C||!y||!u)throw new d(H.XML_PARSE_ERROR,"MDX authdata "+l(e));p="action="+g(C)+"&nonce="+g(y.toString())+"&pin="+g(u);q.verify(sa(p,"utf-8"),k,{result:function(a){b(f,function(){if(!a)throw new v(H.MDX_USERAUTH_VERIFICATION_FAILED,"MDX authdata "+l(e));var c=N(u);q.decrypt(c,{result:function(a){b(f,
function(){var b=qa(a,"utf-8");new z(C,y,b,null,{encoding:e,signature:k},f)})},error:f.error})})},error:f.error})})};Hb=ab.extend({init:function T(a,b,c,d,e,g){T.base.call(this,Ga.MDX);var k=null,f=null,l=null;if("string"===typeof c)a=t.MSL_LEGACY,l=c;else if(c instanceof Uint8Array)a=t.NTBA,f=c;else if(c instanceof Ca)a=t.MSL,k=c;else throw new TypeError("Controller token "+c+" is not a master token, encrypted CTicket, or MSL token construct.");var n=c=null,q=null,r=null;if(g){var C=g.controllerAuthData;
c=C.getAction();n=C.getPin();q=g.userIdToken;C instanceof p?r=C.getUserIdToken().user:q&&(r=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:n,writable:!1,configurable:!1},user:{value:r,writable:!1,configurable:!1},_masterToken:{value:k,writable:!1,enumerable:!1,configurable:!1},_encryptedCTicket:{value:f,writable:!1,enumerable:!1,configurable:!1},
_mslTokens:{value:l,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=qa(this._encryptedCTicket,"utf-8");a.cticket=b;break;case t.MSL_LEGACY:a.cticket=this._mslTokens;break;default:throw new x("Unsupported MDX mechanism.");
}a.pin=this.targetPin;a.mdxauthdata=l(this._controllerEncoding);a.signature=l(this._signature);return a},equals:function M(a){return this===a?!0:a instanceof Hb?M.base.call(this,a)&&(this._masterToken==a._masterToken||this._masterToken&&this._masterToken.equals(a._masterToken))&&(this._encryptedCTicket==a._encryptedCTicket||this._encryptedCTicket&&f(this._encryptedCTicket,a._encryptedCTicket))&&this._mslTokens==a._mslTokens&&f(this._controllerEncoding,a._controllerEncoding)&&f(this._signature,a._signature):
!1}});$d=function(c,e,g){function k(d,f,l,n){kb(c,f,{result:function(k){b(g,function(){if(!k.isDecrypted())throw new Z(a.USERAUTH_MASTERTOKEN_NOT_DECRYPTED,"MDX authdata "+e.toString());y(c,k,l,n,{result:function(a){b(g,function(){var b=a.getEncoding(),e=a.getSignature();return new Hb(c,d,k,b,e,{controllerAuthData:a,userIdToken:null})})},error:g.error})})},error:function(c){b(g,function(){if(c instanceof r)throw new Z(a.USERAUTH_MASTERTOKEN_INVALID,"MDX authdata "+JSON.stringify(e),c);throw c;})}})}
function f(c,d,e,k){b(g,function(){throw new Z(a.UNSUPPORTED_USERAUTH_MECHANISM,"NtbaControllerData$parse");})}function l(k,f,n,p){function q(g,k){b(k,function(){var f;try{f=N(g)}catch(l){throw new Z(a.USERAUTH_MASTERTOKEN_INVALID,"MDX authdata "+JSON.stringify(e),l);}if(!f||0==f.length)throw new Z(a.USERAUTH_MASTERTOKEN_MISSING,"MDX authdata "+JSON.stringify(e));try{var n=JSON.parse(qa(f,"utf-8"));kb(c,n,{result:function(c){b(k,function(){if(!c.isDecrypted())throw new Z(a.USERAUTH_MASTERTOKEN_NOT_DECRYPTED,
"MDX authdata "+e.toString());return c})},error:function(c){b(k,function(){if(c instanceof r)throw new Z(a.USERAUTH_MASTERTOKEN_INVALID,"MDX authdata "+JSON.stringify(e),c);throw c;})}})}catch(p){if(p instanceof SyntaxError)throw new d(a.JSON_PARSE_ERROR,"MDX authdata "+JSON.stringify(e),p);throw p;}})}function t(g,k,f){b(f,function(){var l;try{l=N(g)}catch(n){throw new Z(a.USERAUTH_USERIDTOKEN_INVALID,"MDX authdata "+JSON.stringify(e),n);}if(!l||0==l.length)throw new Z(a.USERAUTH_USERIDTOKEN_MISSING,
"MDX authdata "+JSON.stringify(e));try{var p=JSON.parse(qa(l,"utf-8"));lb(c,p,k,{result:function(c){b(f,function(){if(!c.isDecrypted())throw new Z(a.USERAUTH_USERIDTOKEN_NOT_DECRYPTED,"MDX authdata "+JSON.stringify(e));return c})},error:function(c){b(f,function(){if(c instanceof r)throw new Z(a.USERAUTH_USERIDTOKEN_INVALID,"MDX authdata "+JSON.stringify(e),c);throw c;})}})}catch(q){if(q instanceof SyntaxError)throw new d(a.JSON_PARSE_ERROR,"MDX authdata "+JSON.stringify(e),q);throw q;}})}b(g,function(){var d=
f.split(",");if(3!=d.length||"1"!=d[0])throw new Z(a.UNIDENTIFIED_USERAUTH_MECHANISM,"MDX authdata "+JSON.stringify(e));q(d[1],{result:function(l){t(d[2],l,{result:function(d){E(c,l,n,p,{result:function(a){b(g,function(){return new Hb(c,k,f,n,p,{controllerAuthData:a,userIdToken:d})})},error:function(c){b(g,function(){if(c instanceof Ha)throw new Z(a.USERAUTH_MASTERTOKEN_NOT_DECRYPTED,"MDX authdata "+JSON.stringify(e),c);throw c;})}})},error:g.error})},error:g.error})})}b(g,function(){var b=e.pin,
c=e.mdxauthdata,g=e.signature;if(!b||"string"!==typeof b||!c||"string"!==typeof c||!g||"string"!==typeof g)throw new d(a.JSON_PARSE_ERROR,"MDX authdata "+JSON.stringify(e));var n,p;try{n=N(c),p=N(g)}catch(q){throw new Z(H.MDX_CONTROLLERDATA_INVALID,"MDX authdata "+JSON.stringify(e),q);}if(e.mastertoken){c=e.mastertoken;if(!c||"object"!==typeof c)throw new d(a.JSON_PARSE_ERROR,"MDX authdata "+JSON.stringify(e));k(b,c,n,p)}else if(e.cticket){c=e.cticket;if(!c||"string"!==typeof c)throw new d(a.JSON_PARSE_ERROR,
"MDX authdata "+JSON.stringify(e));-1==c.indexOf(",")?f(b,c,n,p):l(b,c,n,p)}else throw new Z(a.UNIDENTIFIED_USERAUTH_MECHANISM,"MDX authdata "+JSON.stringify(e));})}})();(function(){var b=Kc.ACTION,c=Sb.ACTION,d=Lc.ACTION;Qb.extend({init:function U(){U.base.call(this,Ga.MDX)},createData:function(a,b,c,d){$d(a,c,d)},authenticate:function(e,g,f,l){if(!(f instanceof Hb))throw new x("Incorrect authentication data type "+f.getClass().getName()+".");e=f.action;switch(f.mechanism){case ec.MSL:if(b!=e)throw(new Z(H.MDX_USERAUTH_ACTION_INVALID)).setUser(f);
break;case ec.NTBA:if(c!=e)throw(new Z(H.MDX_USERAUTH_ACTION_INVALID)).setUser(f);break;case ec.MSL_LEGACY:if(d!=e)throw(new Z(H.MDX_USERAUTH_ACTION_INVALID)).setUser(f);}e=f.controllerPin;g=f.targetPin;if(!e||!g)throw(new Z(H.MDX_PIN_BLANK)).setUser(f);if(e!=g)throw(new Z(H.MDX_PIN_MISMATCH)).setUser(f);e=f.user;if(!e)throw(new Z(H.MDX_USER_UNKNOWN)).setUser(f);if(l&&(l=l.user,!e.equals(l)))throw(new Z(a.USERIDTOKEN_USERAUTH_DATA_MISMATCH,"uad user "+e+"; uit user "+l)).setUser(f);return e}})})();
var Tb,ae;(function(){Tb=ab.extend({init:function q(a,b){q.base.call(this,Ga.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 n(a){return this===a?!0:a instanceof Tb?n.base.call(this,a)&&this.netflixId==a.netflixId&&this.secureNetflixId==a.secureNetflixId:
!1}});ae=function(b){var c=b.netflixid,e=b.securenetflixid;if(!c)throw new d(a.JSON_PARSE_ERROR,"NetflixId authdata "+JSON.stringify(b));return new Tb(c,e)}})();Qb.extend({init:function q(){q.base.call(this,Ga.NETFLIXID)},createData:function(a,c,d,e){b(e,function(){return ae(d)})},authenticate:function(b,c,d,e){if(!(d instanceof Tb))throw new x("Incorrect authentication data type "+d+".");b=d.secureNetflixId;if(!d.netflixId||!b)throw(new Z(H.NETFLIXID_COOKIES_BLANK)).setUser(d);throw(new Z(a.UNSUPPORTED_USERAUTH_DATA,
this.scheme)).setUser(d);}});var Ga;(function(){Ga=function(a){ib.call(this,a)};J.Class.mixin(Ga,{NETFLIXID:new Ga("NETFLIXID"),SSO:new Ga("SSO"),SWITCH_PROFILE:new Ga("SWITCH_PROFILE"),MDX:new Ga("MDX")});Object.freeze(Ga)})();var Ub,be,Mc,ce,de;(function(){var b=Mc={MICROSOFT_SAML:"MICROSOFT_SAML",MICROSOFT_JWT:"MICROSOFT_JWT"},c=ce=J.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=de=J.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}})}});Ub=ab.extend({init:function p(a,b,d){p.base.call(this,Ga.SSO);var g=null,f=null,l=null,q=null;d instanceof c?(g=d.email,f=d.password):d instanceof e&&(l=d.netflixId,q=d.secureNetflixId);Object.defineProperties(this,{mechanism:{value:a,writable:!1,configurable:!1},token:{value:b,
writable:!1,configurable:!1},email:{value:g,writable:!1,configurable:!1},password:{value:f,writable:!1,configurable:!1},netflixId:{value:l,writable:!1,configurable:!1},secureNetflixId:{value:q,writable:!1,configurable:!1}})},getAuthData:function(){var a={};a.mechanism=this.mechanism;a.token=l(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 y(a){return this===
a?!0:a instanceof Ub?y.base.call(this,a)&&this.mechanism==a.mechanism&&f(this.token,a.token)&&this.email==a.email&&this.password==a.password&&this.netflixId==a.netflixId&&this.secureNetflixId==a.secureNetflixId:!1}});be=function(g){var f=g.mechanism,l=g.token;if(!f||!l||"string"!==typeof l)throw new d(a.JSON_PARSE_ERROR,"SSO authdata "+JSON.stringify(g));if(!b[f])throw new Z(a.UNIDENTIFIED_USERAUTH_MECHANISM,"SSO authdata "+JSON.stringify(g));var r=g.email,C=g.password,u=g.netflixid,x=g.securenetflixid;
if(r&&!C||!r&&C||u&&!x||!u&&x||r&&u)throw new d(a.JSON_PARSE_ERROR,"SSO authdata "+JSON.stringify(g));var G;try{G=N(l)}catch(v){throw new Z(H.SSOTOKEN_INVALID,"SSO authdata "+JSON.stringify(g),v);}var z;r&&C?z=new c(r,C):u&&x&&(z=new e(u,x));return new Ub(f,G,z)}})();Qb.extend({init:function n(){n.base.call(this,Ga.SSO)},createData:function(a,c,d,e){b(e,function(){return be(d)})},authenticate:function(b,c,d,e){if(!(d instanceof Ub))throw new x("Incorrect authentication data type "+d+".");b=d.token;
c=d.email;e=d.password;var g=d.netflixId,f=d.secureNetflixId;if(!b||0==b.length)throw new Z(H.SSOTOKEN_BLANK);if(!(null===c&&null===e||c&&e))throw new Z(a.EMAILPASSWORD_BLANK);if(!(null===g&&null===f||g&&f))throw(new Z(H.NETFLIXID_COOKIES_BLANK)).setUser(d);throw(new Z(a.UNSUPPORTED_USERAUTH_DATA,this.scheme)).setUser(d);}});var fc,ee;(function(){fc=ab.extend({init:function t(a,b){t.base.call(this,Ga.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 U(a){return this==a?!0:a instanceof fc?U.base.call(this,a)&&this.userIdToken.equals(a.userIdToken)&&this.profileGuid==a.profileGuid:!1}});ee=function(c,e,g,f){b(f,function(){if(!e)throw new Z(a.USERAUTH_MASTERTOKEN_MISSING);var l=g.useridtoken,r=g.profileguid;if("object"!==typeof l||"string"!==typeof r)throw new d(a.JSON_PARSE_ERROR,
"switch profile authdata "+JSON.stringify(g));lb(c,l,e,{result:function(c){b(f,function(){if(!c.isDecrypted())throw new Z(a.USERAUTH_USERIDTOKEN_NOT_DECRYPTED,"switch profile authdata "+JSON.stringify(g));return new fc(c,r)})},error:function(b){f.error(new Z(a.USERAUTH_USERIDTOKEN_INVALID,"switch profile authdata "+JSON.stringify(g),b))}})})}})();Qb.extend({init:function t(){t.base.call(this,Ga.SWITCH_PROFILE)},createData:function(a,b,c,d){ee(a,b,c,d)},authenticate:function(b,c,d,e){if(!(d instanceof
fc))throw new x("Incorrect authentication data type "+d+".");b=d.userIdToken;if(!d.profileGuid)throw(new Z(H.PROFILEGUID_BLANK)).setUser(d);if(e&&!e.equals(b))throw(new Z(a.USERAUTH_USERIDTOKEN_INVALID)).setUser(d);if(!b.user)throw(new Z(a.USERAUTH_USERIDTOKEN_NOT_DECRYPTED)).setUser(d);throw(new Z(a.UNSUPPORTED_USERAUTH_DATA,this.scheme)).setUser(d);}});wa.prototype=Error();wa.prototype.constructor=wa;var yb;(function(){function b(a,c,d){for(var e=0,g=c?c.length:0;void 0!==a&&e<g;)a=a[c[e++]];return void 0===
a?d:a}function d(a,b){var c,e,g;if(a&&b)try{c="",e=nrdp.network.ERRORGROUP,Object.keys(e).some(function(b){if(a===e[b])return c=b,!0}),g=nrdp.network.ERRORCODE,Object.keys(g).some(function(a){if(b===g[a])return c+=(c?"/":"")+a,!0})}catch(f){}return c}function e(a){return new K(function(b,c){a.oncomplete=b;a.onerror=function(a){c(a.error)}})}function g(a){var b=this;this.promise=new K(function(c,d){b.result=ca.isUndefined(a)?c:function(b){c([b,a])};b.error=d;b.timeout=function(){d(new wa)}})}function f(a,
b){var c;a&&ca.isObject(a)&&(c=a.algorithm,!c||ca.isObject(c)&&!c.name)&&(w.warn("Patching algorithm for",a),a.algorithm=b,w.warn("  Key is now          ",a));return a}function C(){return new K(function(a){var b;b=nrdp.storage.diskStoreContexts;if(!b||!ca.isObject(b))throw"Platform does not support disk store";b=b["msl-backup-tokens"];a(b)})}function u(){return C().then(function(a){if(a)return a;if(!ca.isFunction(nrdp.storage.createDiskStoreContext))throw"Platform doesn't support creating disk store contexts";
w.log("Disk store context doesn't exist, creating");a=nrdp.storage.createDiskStoreContext({context:"msl-backup-tokens",size:5120,encrypted:!1,signed:!1});if(!a)throw"Failed to create disk store context";return a})}function v(a){this.config=a;this.name="backup storage"}function z(a){if(a instanceof wa)return 1;if(a instanceof G)return 2;if(a instanceof r&&a.error)switch(a.error.responseCode){case c.TRANSIENT_FAILURE:return 2;case c.USERDATA_REAUTH:return a.error.internalCode==H.NETFLIXID_COOKIES_EXPIRED.internalCode?
12:8;case c.SSOTOKEN_REJECTED:return 10}return 1}function E(a){return a?""+a.sequenceNumber+":"+a.serialNumber+":"+a.expiration.toISOString()+":"+a.renewalWindow.toISOString():"null"}function X(a){return a?""+a.serialNumber+":"+a.mtSerialNumber+":"+a.expiration.toISOString()+":"+a.renewalWindow.toISOString():"null"}function A(){return K.attempt(function(){w.info("Generating AsymmetricWrappedExchange RSA keys");var a={name:"RSA-OAEP",params:{modulusLength:1024,publicExponent:new Uint8Array([1,0,1])}};
return e(O.generateKey(a,!0))}).then(function(a){var b=new g,c=new g;Eb(a.target.result.privateKey,b);qb(a.target.result.publicKey,c);return[b.promise,c.promise]}).spread(function(a,b){var c="RKPI"+Math.floor(nrdp.now()/1E3)+Math.floor(1E8*Math.random());return new rc(c,fd.JWE_RSA,b,a)})}function J(){return K.attempt(function(){w.info("Generating Widevine CDM key");return e(O.generateKey({name:"NFLX-CDM-WIDEVINE"},!0))}).then(function(a){var b=a.target.result;w.log("Exporting CDM key request data");
return e(O.exportKey("raw",b)).then(function(a){a=a.target.result;if(ca.isNumber(a.byteLength)&&!a.byteLength)throw Error("Key request data for Widevine key exchange has zero length");return new Ic(b,a)})})}function ea(){return K.attempt(function(){w.info("Generating Widevine CDM JWE key");return e(O.generateKey({name:"NFLX-CDM-JWELE"},!0))}).then(function(a){var b=a.target.result;w.log("Exporting CDM JWE key request data");return e(O.exportKey("raw",b)).then(function(a){return new Jc("JWELE",b,a.target.result)})})}
function L(a,b){var c;switch(b){case pa.MGK:c=$a;break;case la.PSK:c=Wa;break;default:w.error("Invalid entity authentication scheme :",b);return}return K.attempt(function(){return["DKE","DKH","DKW"].map(function(a){return e(O.getKeyByName(a))})}).all().spread(function(a,b,c){return[f(a.target.result,Ba),f(b.target.result,ma),f(c.target.result,ia)].map(function(a){var b;if(ca.isNull(a))throw Error("Failed to get device key by name");b=new g;Ea(a,b);return b.promise})}).spread(function(d,e,g){var f,
l,p;switch(b){case pa.MGK:f=Me.extend({init:function ue(a,b,c,d){ue.base.call(this,a);Object.defineProperties(this,{_ke:{value:b,writable:!1,enumerable:!1,configurable:!1},_kh:{value:c,writable:!1,enumerable:!1,configurable:!1},_kw:{value:d,writable:!1,enumerable:!1,configurable:!1},_esn:{value:a,writable:!1,enumerable:!1,configurable:!1}})},getCryptoContext:function ve(a,b){return b instanceof c&&this._esn==b.identity?new Mb(a,this._esn,this._ke,this._kh,this._kw):ve.base.call(this,a,b)}});break;
case la.PSK:l=Uc.extend({init:function(a,b,c,d){Object.defineProperties(this,{keys:{value:new Tc(b,c,d),writable:!1,enumerable:!1,configurable:!1},identity:{value:a,writable:!1,enumerable:!1,configurable:!1}})},getKeys:function(a){w.warn("identity is",a,this.identity,this.keys);return a===this.identity?this.keys:null}});p=Je.extend({isEntityRevoked:function(a){return!1},isSchemePermitted:function(a){return!0}});f=Xc.extend({init:function we(a,b,c,d){we.base.call(this,new l(a,b,c,d),new p)}});break;
default:w.error("Invalid entity authentication scheme :",b);return}w.info("Created",b.name,"entity auth factory");a._entityAuthFactories[b.name]=new f(a._deviceIdentity,d,e,g);a._entityAuthData=new c(a._deviceIdentity);return[d,e,g]})}function Z(a,b,c,d){var e;switch(c){case pa.MGK:case la.PSK:break;default:w.error("Invalid entity authentication scheme :",c);return}if(a.swex)w.info("Using symmetric wrapped exchange"),b._keyRequestDataFactory=function(){return K.attempt(function(){return new Hc(c.name)})},
b._keyExchangeFactories.push(new Ud);else if(a.awex)w.info("Using asymmetric wrapped exchange (JWE_RSA)"),b._keyExchangeFactories.push(new Nb),b._keyRequestDataFactory=A;else if(nrdp.webcrypto.nflxDhDerive){w.info("Using ADH exchange");switch(c){case pa.MGK:e=Dc.MGK;break;case la.PSK:e=Dc.PSK}b._keyExchangeFactories.push(b._makeADHExchange(d));b._keyRequestDataFactory=function(){return b._generateADHExchangeRequestData(e,d.rawKey)}}else{w.info("Using JWE ladder exchange");a=Rd.extend({init:function va(){va.base.call(this);
Object.defineProperties(this,{_contextMap:{value:{},writable:!1,enumerable:!1,configurable:!1}})},addCryptoContext:function(a,b){b&&a&&a.length&&(this._contextMap[l(a)]=b)},getCryptoContext:function(a){return a&&a.length?this._contextMap[l(a)]||null:null},removeCryptoContext:function(a){a&&a.length&&delete this._contextMap[l(a)]}});switch(c){case pa.MGK:e=Fc.MGK;break;case la.PSK:e=Fc.PSK}b._keyExchangeFactories.push(new Pd(new a));b._keyRequestDataFactory=function(){return K.attempt(function(){return new Gc(e)})}}}
function N(a){return e(O.getKeyByName("WIIU-ECC")).then(function(b){var c;b=b.target.result;if(ca.isNull(b))throw Error("Failed to find named key WIIU-ECC");w.log("Got","WIIU-ECC","key");c=b.algorithm.certificate;if(!ca.isString(c))throw Error("WIIU-ECC key missing 'certificate'");if(!c.length)throw Error("WIIU-ECC key has empty 'certificate'");a._entityAuthData=new $b(a._deviceIdentity,null,c);return b}).then(function(b){var c=la.X509,d=sb.extend({init:function xc(a){xc.base.call(this,c);Object.defineProperties(this,
{_eccKey:{value:a,writable:!1,enumerable:!1,configurable:!1}})},getCryptoContext:function(a,b){if(!(b instanceof $b))throw new x("Incorrect authentication data type "+JSON.stringify(b)+".");return new Pc(a,this._eccKey)}});a._entityAuthFactories[c.name]=new d(b)}).then(function(){w.info("Using asymmetric wrapped exchange (JWE_RSA)");a._keyExchangeFactories.push(new Nb);a._keyRequestDataFactory=A})}function V(a){return e(O.getKeyByName("NAGRA-CDM")).then(function(b){b=b.target.result;if(ca.isNull(b))throw Error("Failed to find named key NAGRA-CDM");
w.log("Got","NAGRA-CDM","key");a._entityAuthData=new dc(a._deviceIdentity);return b}).then(function(b){var c=pa.ANYCAST,d=sb.extend({init:function xc(a){xc.base.call(this,c);Object.defineProperties(this,{_cdmKey:{value:a,writable:!1,enumerable:!1,configurable:!1}})},getCryptoContext:function(a,b){if(!(b instanceof dc))throw new x("Incorrect authentication data type "+JSON.stringify(b)+".");return new Fd(this._cdmKey)}});a._entityAuthFactories[c.name]=new d(b)}).then(function(){w.info("Using Nagra/Anycast key exchange");
var b=["70af7b2b-6c34-431d-b10a-50bad4f683a4","57f13e19-ecc3-4cb4-87df-5a8760bc4e5f"];a._keyExchangeFactories.push(new Id);a._keyRequestDataFactory=function(){return K.attempt(function(){w.info("Generating Nagra/Anycast CDM key");return e(O.generateKey({name:"NAGRA"},!0,["derive"]))}).then(function(a){var c=a.target.result.publicKey,d=a.target.result.privateKey;w.log("Exporting Nagra/Anycast key request data");return e(O.exportKey("raw",c)).then(function(a){a=a.target.result;var c=b.shift();b.push(c);
return new Cc(d,c,a)})})}})}function P(l){function C(a,b,c,d,e){var g=[];c&&(g=c.slice(0));d&&(c=d.getMslStore(),d=c.getMasterToken())&&(g=g.concat(c.getServiceTokens(d,null)),e&&(e=e.getUserId())&&(e=c.getUserIdToken(e))&&(g=g.concat(c.getServiceTokens(d,e))));0===g.length?w.trace("No "+a+" service tokens for request ("+b.n+")"):g.forEach(function(c,d){c?(w.trace(a+" service token "+d+" for request ("+b.n+") : "+c.name),w.dump(c.toJSON())):w.error("st is undefined, wtf.")})}var u=!1,x=!1,H=!1,I=
1,S=nrdp.device.setRegistered||function(){},W=Dd.extend({init:function xe(a,b){xe.base.call(this);this._deviceIdentity=a;this._eventEmitter=b},_hasUserIdTokens:function(){return!!Object.keys(this.userIdTokens).length},_emit:function(a,b){this._eventEmitter&&this._eventEmitter.emit(a,b)},setCryptoContext:function ye(a,b){function c(a){return a?a.sequenceNumber+":"+a.serialNumber+":"+a.expiration.getTime():"<null>"}var d=this.getMasterToken();ye.base.call(this,a,b);this.markDirty("setCryptoContext ["+
c(d)+" TO "+c(a)+"]");this._emit("setCryptoContext",{masterToken:a,cryptoContext:b})},removeCryptoContext:function ze(a){ze.base.call(this,a);this.markDirty("removeCryptoContext");this._emit("removeCryptoContext",{masterToken:a})},clearCryptoContexts:function Ae(){Ae.base.call(this);this.markDirty("clearCryptoContexts");this._emit("clearCryptoContexts")},addUserIdToken:function Be(a,b){Be.base.call(this,a,b);this.markDirty("addUserIdToken");this._emit("addUserIdToken",{userId:a,userIdToken:b})},removeUserIdToken:function Ce(a){Ce.base.call(this,
a);this.markDirty("removeUserIdToken");this._emit("removeUserIdToken",{userIdToken:a})},clearUserIdTokens:function De(){De.base.call(this);this.markDirty("clearUserIdTokens");this._emit("clearUserIdTokens")},addServiceTokens:function Ee(a){var b={"streaming.servicetokens.movie":!0,"streaming.servicetokens.license":!0};a=a.filter(function(a){return a&&!b[a.name]});0<a.length&&(Ee.base.call(this,a),this.markDirty("addServiceTokens"),this._emit("addServiceTokens",{tokens:a}))},removeServiceTokens:function Ge(a,
b,c){Ge.base.call(this,a,b,c);this.markDirty("removeServiceTokens");this._emit("removeServiceTokens",{name:a,masterToken:b,userIdToken:c})},clearServiceTokens:function He(){He.base.call(this);this.markDirty("clearServiceTokens");this._emit("clearServiceTokens")},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||(w.log("MslStore dirty ("+
a+")"),this._dirty=!0)},getBackupTokens:function(a,b){if(!l.mslBackupTokens)return w.log("Backup tokens are disabled"),K.resolve().then(b).done();(new v(l)).load().spread(function(b,c){w.log("Loaded backup tokens",c);if(!(c&&ca.isObject(c)&&c.mt&&c.uit))throw"Loaded backup tokens don't look good";w.log("Parsing backup tokens");var d=new g;kb(a,c.mt,d);return d.promise.then(function(b){var d=new g;lb(a,c.uit,b,d);return d.promise.then(function(a){if(!b||!a)throw"Ended up with falsy tokens";w.log("Backup tokens parsed");
return{mt:b,uit:a}})})}).fail(function(a){w.warn("Failed to get backup tokens",a)}).then(b).done()},load:function(a){var b=this,c,d;return K.attempt(function(){c=nrdp.storage.getItem(nrdp.storage.NO_DEVICE_ACCOUNT,"mslstore");w.log("Attempting to load MslStore");if(c)if(d=JSON.parse(c),w.log("Loaded MslStore"),H&&w.dump(d),d.di!==b._deviceIdentity)w.warn("MslStore is for a different device: "+d.di),nrdp.storage.removeItem(nrdp.storage.NO_DEVICE_ACCOUNT,"mslstore");else return K.attempt(function(){var c=
d.mt,e;b._loading=!0;if(!c)throw Error("No master token found");e=new g;kb(a,c,e);return e.promise}).then(function(c){switch(d.cc){case "symmetric":return K.resolve([d.ek,d.hk].map(function(a){return e(O.getKeyInfo(a)).then(function(a){return a.target.result})})).all().spread(function(a,b){return[f(a,Ba),f(b,ma)].map(function(a){var b=new g;Ea(a,b);return b.promise})}).all().spread(function(d,e){var g=new ua(a,c,b._deviceIdentity,d,e);b.setCryptoContext(c,g)}).thenResolve(c);default:throw Error("Unable to load crypto context");
}}).then(function(c){var e=d.uit;if(e)return w.log("Parsing user id tokens"),K.attempt(function(){return e.map(function(b){var d=new g({id:b.id,st:b.st});lb(a,b.t,c,d);return d.promise})}).all().then(function(d){var e=[];d.forEach(function(d){var f=d[0],l=d[1].st;b.addUserIdToken(d[1].id,f);ca.isArray(l)&&l.forEach(function(b){var d=new g;ac(a,b,c,f,null,d);e.push(d.promise.fail(function(a){w.warn("Failed to parse service token from store");return null}))})});return e}).all().then(function(a){a.forEach(function(a){if(a)try{b.addServiceTokens([a]),
w.log("Added service token "+a.name)}catch(c){w.warn("Failed to add service token "+a.name)}})})}).then(function(){var a=d.npk;if(a)if("npticket"!=nrdp.webcrypto.authenticationType)w.log("Ignoring saved NP Ticket");else return w.log("Loading NP Ticket..."),e(O.getKeyInfo(a)).then(function(a){(a=a.target.result)&&b.setNpTicket(a)})}).then(function(){w.log("Finished loading MslStore");b._lastSaved||(b._lastSaved=c)}).fin(function(){delete b._dirty;delete b._loading});else w.warn("No MslStore to load")}).fail(function(a){w.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,g=[],f,p=b._lastSaved;if(this._dirty){delete this._dirty;w.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 g=b.getUserIdToken(a),f;g.isBoundTo(c)&&(f=b.getServiceTokens(c,g).map(function(a){return a.toJSON()}),d.push({id:a,t:g.toJSON(),st:f}),!e||g.expiration>
e.expiration)&&(e=g)});f.uit=d;if(a=b.getCryptoContext(c))a instanceof Mb?([a.encryptionKey,a.signatureKey].forEach(function(a){a&&g.push(a)}),f.cc="symmetric",f.ek=a.encryptionKey.handle,f.hk=a.signatureKey.handle):w.error("NrdpMslStore does not know how to persist this kind of CryptoContext");this._npTicketWCKey&&(g.push(this._npTicketWCKey),f.npk=this._npTicketWCKey.handle)}if(f){a=JSON.stringify(f);if(p&&p===a){w.log("Already saved this, skipping it");return}H&&(w.trace("This is what I will save:"),
w.dump(f));nrdp.storage.setItem(nrdp.storage.NO_DEVICE_ACCOUNT,"mslstore",a);b._lastSaved=a;w.log("Finished saving MslStore");c&&e&&(l.mslBackupTokens?(w.log("Saving backup tokens",E(c),"/",X(e)),(new v(l)).save(JSON.stringify({mt:c.toJSON(),uit:e.toJSON()}))):w.log("Not saving backup tokens"))}else nrdp.storage.removeItem(nrdp.storage.NO_DEVICE_ACCOUNT,"mslstore"),delete b._lastSaved;nrdp.webcrypto.persistKeys(g,function(a){a.success?w.log("Finished persisting MslStore keys"):w.warn("Failed to persist MslStore keys")});
S(b._hasUserIdTokens())}}}),ia=Ke.extend({init:function(a){this._client=a;this._entityAuthFactories={};this._keyRequestDataFactory=this._keyRequestData=null;this._keyExchangeFactories=[];this._mslCryptoContext=new ne;this._deviceIdentity=nrdp.device.ESN;w.warn("ESN: "+this._deviceIdentity);this._store=new W(this._deviceIdentity,a);this._random=new Ja;this._entityAuthData=new rb(this._deviceIdentity)},_generateNPTicket:function(){var a=this,b={name:"RSASSA-PKCS1-v1_5",params:{npticket:!0}};return K.attempt(function(){if(a._generatingNPTicket)throw Error("Already waiting for NP ticket generation, cannot make a new one now");
w.log("Creating NP-Ticket");a._generatingNPTicket=!0;return e(O.generateKey(b,!0)).fin(function(){delete a._generatingNPTicket}).then(function(b){var c=b.target.result.privateKey;w.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){w.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 Gb(a._deviceIdentity,b));return}}a.getMslStore().setNpTicket(c);a._entityAuthData=new Gb(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]),d=new Uint8Array([5]);w.log("Generating DH key");return e(O.generateKey({name:"NFLX-DH",params:{prime:c,generator:d}},!1,["derive"])).then(function(b){var c=b.target.result.publicKey,d=b.target.result.privateKey;w.log("Exporting DH public key");return e(O.exportKey("raw",c)).then(function(b){return new Ec(a,"1",
b.target.result,d,null)})})},_makeADHExchange:function(a){var b=Od.extend({getDerivationKey:function(b){if(!b)return a}});return new Md(new b)},prepare:function(){var a=this;w.info("Preparing MslContext...");return K.resolve(a._store.load(a)).then(function(){var b=function(){w.log("Crypto context removed, dropping key request data");this._keyRequestData=null}.bind(a);a._client.addEventListener("removeCryptoContext",b);a._client.addEventListener("clearCryptoContexts",b);a._client.addEventListener("setCryptoContext",
b)}).then(function(){var b,c;w.info("Server entity auth keys...");if(l.noverify)c=Yc.extend({getCryptoContext:function(a,b){this._cryptoContext||(this._cryptoContext=new Lb);return this._cryptoContext}}),w.warn("Added NULL RSA auth factory because we are not verifying the server"),a._entityAuthFactories[la.RSA.name]=new c;else{try{b=nrdp.storage.transientData.appboot.msltruststore.keys,c=Object.getOwnPropertyNames(b).map(function(a){return{identity:a,type:"downloaded",op:O.importKey("spki",b[a],da.RSASSA,
!1,["verify"])}})}catch(d){c=l.appboot_key?[{identity:"APPBOOT",type:"overridden",op:O.importKey("spki",l.appboot_key,da.RSASSA,!1,["verify"])}]:[{identity:"APPBOOT",type:"baked in",op:O.getKeyByName("ABKP")}]}return K.all(c.map(function(a){return new K(function(b,c){var d=a.op;w.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 K.all(a.map(function(a){var b=new g,c;
w.info("Creating MSL PublicKey for "+a.identity);c=b.result;b.result=function(b){c({identity:a.identity,key:b})};qb(a.key,b);return b.promise}))}).then(function(b){var c=new oe;b.forEach(function(a){w.info("Adding key to RSA store "+a.identity);c.addPublicKey(a.identity,a.key)});a._entityAuthFactories[la.RSA.name]=new Yc(void 0,c)}).fail(function(a){w.error("Failed to set-up server entity auth keys : "+a.toString())})}}).then(function(){var b=l.unauth?"UNKNOWN":nrdp.webcrypto.authenticationType;w.info("Device authentication type is '"+
b+"'");switch(b){case "PSK":return w.info("Device authentication using PSK"),L(a,la.PSK).spread(function(b,c,d){Z(l,a,la.PSK,d)});case "MGK":return w.info("Device authentication using MGK"),L(a,pa.MGK).spread(function(b,c,d){Z(l,a,pa.MGK,d)});case "npticket":return w.info("Device authentication using NP-Ticket"),K.attempt(function(){var b=a.getMslStore().getNpTicket(),c,d,e;if(b)if(w.info("Checking saved NP-Ticket"),e=nrdp.now(),c=1E3*b.algorithm.npTicketIssue,d=1E3*b.algorithm.npTicketExpiration,
c+l.npticket_interval<e)w.warn("NP-Ticket was issued more than 4 hours ago : issued="+c+"ms, now="+e+"ms, expiration="+d+"ms");else if(d<=e)w.warn("NP-Ticket is expired : issued="+c+"ms, now="+e+"ms, expiration="+d+"ms");else{w.info("Saved NP-Ticket seems good");a._entityAuthData=new Gb(a._deviceIdentity,b);return}else w.info("No saved NP-Ticket, making a new one");return a._generateNPTicket()}).then(function(){a._entityAuthFactories[pa.NPTICKET.name]=new Ne;a._keyExchangeFactories.push(new Nb);a._keyRequestDataFactory=
A});case "UNKNOWN":w.warn("Using unauthenticated auth factory - NOT using device keys");a._entityAuthFactories[la.NONE.name]=new Zc;a._entityAuthData=new rb(a._deviceIdentity);l.mslClear?w.warn("Configured for clear messages - NO key exchange"):(a._keyExchangeFactories.push(new Nb),a._keyRequestDataFactory=A);break;case "CDM":w.warn("Using unauthenticated auth factory - NOT using device keys");a._entityAuthFactories[la.NONE.name]=new Zc;a._entityAuthData=new rb(a._deviceIdentity);if(!nrdp.webcrypto.cdmDerive)throw Error("Platform does not support CDM key exchange");
a._keyExchangeFactories.push(new Wd);a._keyRequestDataFactory=J;break;case "CDM_JWE":w.info("Device authentication using MGK");if(!nrdp.webcrypto.cdmDerive)throw Error("Platform does not have cdmDerive");return L(a,pa.MGK).then(function(){a._keyExchangeFactories.push(new Yd);a._keyRequestDataFactory=ea});case "ecclink":w.info("Device authentication using ECC Ninentdo");if(!nrdp.webcrypto.eccSign)throw Error("Platform does not have eccSign");return N(a);case "NAGRA":w.info("Device authentication using Nagra/Anycast");
if(!nrdp.webcrypto.cdmSign)throw Error("Platform does not have cdmSign");return V(a);default:throw Error('Unrecognized authentication type "'+nrdp.webcrypto.authenticationType+'" from nrdp.webcrypto.authenticationType');}})},getTime:function(){return nrdp.now()},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);"lzw"===l.compress&&a.push(Ta.LZW);
"none"!==l.compress&&a.push(Ta.GZIP);return new Ob(a,b)},getEntityAuthenticationData:function(a,b){var c=this;K.attempt(function(){if(a&&(w.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.name]},getUserAuthenticationFactory:function(a){return null},
getTokenFactory:function(){return null},getKeyExchangeFactory:function(a){return this.getKeyExchangeFactories().filter(function(b){return b.scheme.name==a.name})[0]},getKeyExchangeFactories:function(){return this._keyExchangeFactories},getMslStore:function(){return this._store},getEntityAuthenticationScheme:function(a){return Qc(a)},getUserAuthenticationScheme:function(a){return Bd(a)},getKeyExchangeScheme:function(a){return cd(a)},getKeyRequestData:function(a){var b=this,c=b._keyRequestData;K.attempt(function(){if(c)return c;
w.info("Don't have key request data, creating one...");if(!b._keyRequestDataFactory)throw Error("Missing a key request data factory");return b._keyRequestDataFactory()}).then(function(c){if(!c)throw Error("Request data factory returned null");b._keyRequestData=c;a.result([c])}).fail(function(b){l.mslClear?(w.warn("No key exchange - configured for clear messages, not including key request data"),a.result([])):(w.error("Failed to create key request data.","This usually means that the MSL client has been reset.",
b.toString()),a.error(b))})}}),ka=Fe.extend({init:function(a){this._requestInfo=a},sentHeader:function(a){try{var b=a.masterToken,c=a.userIdToken,d,e,g,f,l="-> ["+this._requestInfo.n+"."+ ++this._requestInfo.r+"] "+this._requestInfo.url,l=l+(" mid="+a.messageId+" mt="+E(b)),l=l+(" nrp="+!!a.nonReplayable+" ren="+!!a.renewable),l=l+(" nrpid="+a.nonReplayableId),l=l+(" hshk="+!!a.handshake),l=l+(" uit="+X(c));if(d=a.userAuthenticationData)l+=" uad="+JSON.stringify(d.toJSON());if(f=a.entityAuthenticationData)l+=
" ead="+JSON.stringify(f.toJSON());(e=a.serviceTokens)&&e.length&&(l+=" st=[",e.forEach(function(a,b){b&&(l+=",");l+=a.uniqueKey()}),l+="]");(g=a.keyRequestData)&&g.length&&(l+=" krd=[",g.forEach(function(a,b){b&&(l+=",");l+=JSON.stringify(a.toJSON())}),l+="]");w.log(l)}catch(p){}},receivedHeader:function(a){try{var b,c,d,e,g="<- ["+this._requestInfo.n+"."+this._requestInfo.r+"] "+this._requestInfo.url;a instanceof tb?g+=" mid="+a.messageId+" error="+a.internalCode+" ["+a.errorCode+"] "+a.errorMessage:
a instanceof ub&&(b=a.masterToken,c=a.userIdToken,g+=" mid="+a.messageId+" mt="+E(b),g+=" nrp="+!!a.nonReplayable+" ren="+!!a.renewable,g+=" uit="+X(c),(d=a.serviceTokens)&&d.length&&(g+=" st=[",d.forEach(function(a,b){b&&(g+=",");g+=a.uniqueKey()}),g+="]"),e=a.keyResponseData)&&(b=e.masterToken,g+=" krd-mt="+E(b));w.log(g)}catch(f){}}}),fa=Pb.extend({init:function(a,b,c,d,e,g,f,l,p,r){var C=null,t=nrdp.registration;e=ca.isUndefined(e)||ca.isNull(e)?!0:!!e;g=ca.isUndefined(g)||ca.isNull(g)?!0:!!g;
f=!!f||p;r&&(w.log("Using custom tokens that were passed in to the message context"),this.tokens=r);if(c&&ca.isObject(c))C=c,w.warn("Using message-specific account",C);else if(t)if(ca.isUndefined(c)){if(r=t.activationTokens,t.registered||r&&(r.NetflixId&&r.SecureNetflixId||r.email&&r.password||r.ssoService&&r.ssoToken||r.mt&&r.uit))C={id:t.currentDeviceAccount,tokens:r}}else ca.isNull(c)||((r=t.deviceAccounts.filter(function(a){return a.accountKey==c}).reduce(function(a,b){return b.tokens},void 0))?
C={id:c,tokens:r}:w.warn("No tokens for user id '"+c+"', sending with no account"));else ca.isNull(c)||(C={id:c});Object.defineProperties(this,{_client:{value:a,writable:!1},_account:{value:C,writable:!1},_payload:{value:d,writable:!1},_encrypted:{value:e,writable:!1},_replayable:{value:g,writable:!1},_requestingTokens:{value:f,writable:!1},_serviceTokens:{value:l,writable:!1},_requestInfo:{value:b,writable:!1},_forceUserAuthData:{value:!!p,writable:!1}})},getCryptoContexts:function(){this._cryptoContexts||
(this._cryptoContexts={});return this._cryptoContexts},getRecipient:function(){},isEncrypted:function(){return l.mslClear?(w.warn("Message will NOT be encrypted"),!1):this._encrypted},isIntegrityProtected:function(){return l.mslClear?(w.warn("Message will NOT be integrity protected"),!1):!0},isNonReplayable:function(){return!this._replayable},isRequestingTokens:function(){return!!this._requestingTokens},getUserId:function(){if(this._account)return this._account.id;w.log("No account associated with this request");
return null},getUserAuthData:function(a,b,c,d){b=null;var e=this._account,g,f;e?a?w.error("Asked to reauth user auth data, need to log in again"):this._forceUserAuthData||c||!this._client.getUserIdToken(e.id,!0)?(this._forceUserAuthData&&w.log("User auth data is being forced for this message"),c&&w.log("User auth data is required for this message"),a=this.tokens||e.tokens,a)?a.ssoService&&a.ssoToken?("xboxsaml"==a.ssoService.toLowerCase()?(f=Mc.MICROSOFT_SAML,w.log("Will use XBox SAML SSO user auth data")):
"xboxjwt"==a.ssoService.toLowerCase()&&(f=Mc.MICROSOFT_JWT,w.log("Will use XBox JWT SSO user auth data")),f&&(a.email&&a.password?(w.log("Including SSO email/password user auth data for "+e.id),g=new ce(a.email,a.password)):a.NetflixId&&a.SecureNetflixId&&(w.log("Including SSO netflix id user auth data for "+e.id),g=new de(a.NetflixId,a.SecureNetflixId)),b=new Ub(f,a.ssoToken,g))):a.email&&a.password?(w.log("Including email/password user auth data for "+e.id),b=new Rb(a.email,a.password)):a.NetflixId&&
a.SecureNetflixId?(w.log("Including netflix id user auth data for "+e.id),b=new Tb(a.NetflixId,a.SecureNetflixId)):a.mdxControllerToken?(w.log("Including mdx controller auth data"),g=(new Sb("regpairrequest",a.mdxNonce,a.mdxEncryptedPinB64,a.mdxSignature)).getEncoding(),b=new Hb(void 0,a.mdxPin,a.mdxControllerToken,g,a.mdxSignature)):a.mt&&a.uit&&(w.log("Including user id token auth data for",e.id),b=new Bc(a.mt,a.uit)):w.log("User id "+e.id+" does not have email/password or netflix"):w.log("Already have a user id token for "+
e.id+" and this is not a reauth - will not send auth data"):w.log("No account associated with this request");d.result(b)},getUser:function(){return null},getKeyRequestData:function(a){this._client.getKeyRequestData(a)},updateServiceTokens:function(a,b,c){var d=!0;b||this._serviceTokens&&this._serviceTokens.forEach(function(b){b?(w.log("Adding service token to outbound message : "+b.name),d=d&&a.addPrimaryServiceToken(b)):w.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;K.attempt(function(){var c;switch(l.compress){case "none":break;default:return}c=new g;w.trace("Configuring output stream without compression");a.setCompressionAlgorithm(null,b,c);return c.promise}).then(function(){var c,e=new g;ca.isObject(d)&&d.constructor==Uint8Array||(d=Da(d));c=d.length;a.write(d,0,c,b,e);return e.promise.then(function(d){var e=new g;if(d!==c)throw new G("Message context did not write all bytes");a.close(b,e);return e.promise})}).then(function(){c.result(!0)}).fail(function(a){w.error("Exception writing : "+
a);a instanceof wa?c.timeout():c.error(a)}).done()},getDebugContext:function(){return R.isDebug()?new ka(this._requestInfo):null}}),aa=G.extend({init:function Ie(a,b){var c;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;if(c=d(this.errorGroup,this.errorCode))this.mesg+=" ["+c+"]";Ie.base.call(this,a)}}),na=re.extend({init:function(a,b,c){this._client=
a;this._url=b;this._info=c},getResponse:function(a,b,c){function d(a){z&&g.clearTimeout(z);if(v)w.warn("load callback was called again");else{v=!0;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/"+p.n);p.networkTime=nrdp.mono()-x;p.netStats=b;u&&w.dump(a);w.log("  HTTP took "+p.networkTime+" ms ("+G+","+a.size+" bytes) ["+b.dt+","+b.ct+","+b.tt+"="+b.du+
" ("+(p.networkTime-b.du)+")] for request ("+p.n+") "+f);try{switch(a.reason){case g.SUCCESS:b={};if(200===a.statusCode){b.json=a.json||null;p.simnetOverride=a.simnetOverride;c.result(b);break}throw new aa("HTTP status code "+a.statusCode,a);case g.TIMEOUTERROR:throw new aa("TIMED_OUT_ERROR",a);case g.NOTSECUREERROR:throw new aa("NOT_SECURE_ERROR",a);case g.FILEACCESSERROR:throw new aa("FILE_ACCESS_ERROR",a);case g.DATAURIERROR:throw new aa("DATA_URI_ERROR",a);case g.DNS_ERROR:throw new aa("DNS_ERROR",
a);case g.CONNECT_ERROR:throw new aa("CONNECT_ERROR",a);case g.SSLHANDSHAKEERROR:throw new aa("SSL_HANDSHAKE_ERROR",a);case g.SSLCACERTERROR:throw new aa("SSL_CA_CERT_ERROR",a);case g.SSLCACERTFILEERROR:throw new aa("SSL_CA_CERT_FILE_ERROR",a);case g.CERTSTATUSSSLERROR:throw new aa("CERT_STATUS_ERROR",a);case g.CERTSTATUSREVOKED:throw new aa("CERT_REVOKED_ERROR",a);case g.CERTSTATUSPEWREVOKED:throw new aa("CERT_PEW_REVOKED_ERROR",a);case g.SENDERROR:throw new aa("SEND_ERROR",a);case g.RECVERROR:throw new aa("RECV_ERROR",
a);case g.COMPRESSIONERROR:throw new aa("COMPRESSION_ERROR",a);case g.SECURITYERROR:throw new aa("SECURITY_ERROR",a);case g.NETWORKERROR:throw new aa("NETWORK_ERROR",a);default:throw new aa(200<a.statusCode?"HTTP_ERROR":"UNKNOWN ["+a.reason+"]",a);}}catch(l){w.error("Request ("+p.n+") to "+f+" failed : "+l.mesg+" : "+JSON.stringify(l)),e._client.emit("requestError",{exception:l,response:a}),c.error(l)}}}var e=this,g=nrdp.gibbon,f=this._url,p=this._info,r=""+Math.floor(nrdp.now()/1E3)+Math.floor(1E8*
Math.random()),C={url:f,headers:{"X-Gibbon-Cache-Control":"no-cache","X-AllowCompression":"true","X-Client-Request-Id":r},body:a.body,async:!0,secure:!0,timeout:b||void 0,connectTimeout:b/2||void 0,stallTimeout:b||void 0,format:"jsonstream"},t,x=nrdp.mono(),G=a.body.length,v,z,y;ca.isNumber(b)&&(C.headers["X-Netflix.request.expiry.timeout"]=""+b);nrdp.device.deviceModel&&(C.headers["X-DeviceModel"]=nrdp.device.deviceModel);l.noss&&(C.headers["X-Netflix.esn"]=nrdp.device.ESN);if(p.headers&&ca.isObject(p.headers))for(y in p.headers)C.headers[y]=
p.headers[y];p.mslPayload&&(C.mslPayload=p.mslPayload);p.clientRequestId=r;w.log("  Making HTTP request ("+p.n+") ["+r+"] request body is "+a.body.length+" bytes "+f);u&&w.dump(C);nrdp.instrumentation.endInterval(nrdp.instrumentation.SWITCHED,"nrdjs.prepare-msl-request/"+p.n);t=g.load(C,d);l.mslFallbackTimer&&(z=setTimeout(function(){w.error("Failing request on artifical timeout of "+(b+1E3)+" ms");g.stopLoad(t);z=null;d({reason:g.TIMEOUTERROR,size:0,url:f,finalURL:f,errorcode:nrdp.network.ERRORCODE.TIMEOUTERROR,
errorgroup:nrdp.network.ERRORGROUP.CONNECTIVITY_ERROR,nativeerrorCode:0,serverIp:"",statusCode:0})},b+1E3));return{abort:function(){w.warn("Aborting request ("+p.n+") : ID "+t);g.stopLoad(t)}}}});this._prepare=function(){u=l.trace_msl_requests;x=l.trace_msl_service_tokens;H=l.trace_msl_store;w.info("Creating MslControl...");this._mslControl=new Ad;w.info("Creating MslContext...");this._mslContext=new ia(this);return this._mslContext.prepare().thenResolve(this)};this.request=function(b,c,d,e,f,l,p,
t,u,G,v,z,A){var B=this,F=nrdp.mono(),E={url:b,n:I++,r:0,headers:A};nrdp.instrumentation.startInterval(nrdp.instrumentation.SWITCHED,"nrdjs.prepare-msl-request/"+E.n,{url:b,n:E.n});w.log("Making MSL request ("+E.n+") payload is "+(d.byteLength||d.length)+" bytes "+b);"undefined"!==typeof simnet&&(E.mslPayload=d);return K.attempt(function(){var a=new fa(B,E,c,d,f,l,p,t,u,z),r=new g,A=new bd(new na(B,b,E));G&&(w.info("Getting new message context from message context factory"),a=G(B._mslContext,a)||
a,nrdp.assert(ca.isObject(a)));x&&C("outbound",E,t,B._mslContext,a);v&&(w.info("Getting URL from URL factory"),A=v(B._mslContext,a,b,E,A)||A,nrdp.assert(ca.isObject(A)));B._mslControl.request(B._mslContext,a,A,e||-1,r);return r.promise}).then(function(a){if(!a)throw Error("No MSL channel returned");return a}).fail(function(a){w.log("<- ["+E.n+"."+E.r+"] "+E.url+" e="+a.toString());throw a;}).then(function(b){b=b.input;var c=b.getErrorHeader(),d=b.getMessageHeader();if(c)throw w.error("MSL response has error header : "+
c.internalCode+" ["+c.errorCode+"] "+c.errorMessage),new r(new a(c.internalCode,c.errorCode,c.errorMessage));c=d.serviceTokens;x&&C("inbound",E,c);d=new g;b.read(-1,e,d);return[d.promise,K.resolve(c)]}).spread(function(a,b){ca.isFunction(E.simnetOverride)&&(a=E.simnetOverride(a),delete E.simnetOverride);return{body:a||new Uint8Array,serviceTokens:b,requestInfo:E}}).fin(function(){B._mslContext.getMslStore().save("After a request");w.log("  MSL took "+(nrdp.mono()-F-(E.networkTime||0))+" ms for request ("+
E.n+") "+b);nrdp.instrumentation.endInterval(nrdp.instrumentation.SWITCHED,"nrdjs.handle-msl-response/"+E.n,{url:b,n:E.n})})};this.send=function(a,b){var d=this;K.attempt(function(){return d.request(a.url,a.userId,a.body,a.timeout,a.encrypted,a.replayable,a.requestingTokens,a.serviceTokens,a.forceUserAuthData,void 0,void 0,a.customTokens,a.headers)}).then(function(a){try{w.trace("MSL networkstats:"+JSON.stringify(a.requestInfo.netStats)),b({success:!0,body:ja(a.body),serviceTokens:a.serviceTokens,
requestInfo:a.requestInfo})}catch(c){w.error("Exception in MSL callback : "+c.toString()+"\n"+c.stack)}}).fail(function(e){var g=nrdp.registration,f=a.userId,l,p,C={mslError:e,errorActionId:z(e),errorIsTimeout:!!(ca.isString(e.mesg)&&-1<e.mesg.indexOf("TIMED_OUT_ERROR")),errorSubCode:1300};w.error("MSL request failed : "+e.toString()+(e.cause&&e.cause.toString?" (caused by "+e.cause.toString()+")":"")+" : ACTION ID "+C.errorActionId+" : "+a.url);try{l="undefined"!==typeof g?g.currentDeviceAccount:
null,p="undefined"!==typeof f&&null!==f?f:l,e instanceof r&&e.error&&e.error.responseCode===c.USERDATA_REAUTH&&null!==l&&(g.deviceAccounts.filter(function(a){return p===a.accountKey}).forEach(function(a){w.log("Clearing device account tokens for user "+p);a.tokens={}}),w.log("Dropping user id token for user "+p),d.removeUserIdToken(p)),b(C)}catch(t){w.error("Exception in MSL error callback : "+t.toString()+"\n"+t.stack)}}).done()};this.sendWithRetries=function(a,b,c,d){var e=this;d="number"===typeof d?
d:0;ca.isObject(a.headers)||(a.headers={});a.headers["X-Netflix.request.attempt"]=""+(d+1);e.send(a,function(g){"undefined"!==typeof g.mslError&&2==g.errorActionId&&d<b?(w.info("MSL request failed with retryable condition, will retry "+(b-d)+" more times : "+JSON.stringify(g)+" : "+a.url),g=1E3*Math.pow(2,d),w.info("will retry MSL request in "+g+"ms"),setTimeout(function(){e.sendWithRetries(a,b,c,d+1)},g)):(d===b&&(w.warn("MSL request failed with retryable condition, but we've already retried "+b+
" times, so we'll report it as non-retryable"),g.errorActionId=1,w.warn("responding with "+JSON.stringify(g))),c(g))})};this.getRandom=function(){return this._mslContext.getRandom()};this.getKeyRequestData=function(a){return this._mslContext.getKeyRequestData(a)};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;K.attempt(function(){var c=d.getMslStore(),e=c.getMasterToken(),c=c.getUserIdToken(a),f;if(b&&e&&c)return f=new g,ac(this._mslContext,b,e,c,null,f),f.promise}).fail(function(a){w.warn("Failed to parse service token",a)}).then(function(b){b?w.trace("Parsed service token "+
b.name+" for account "+a):w.trace("Did not parse the service token for account "+a);c(b)}).done()};this.getNpTicketCookie=function(){var a=this.getMslStore().getNpTicket();return b(a,["algorithm","npTicket"])};this.isNpTicketFake=function(){var a=this.getMslStore().getNpTicket();return b(a,["algorithm","npTicketFake"])};this.generateNpTicket=function(a,b){var c=this;K.attempt(function(){if("npticket"!=nrdp.webcrypto.authenticationType)throw Error("Not npticket authentication type");a&&(w.warn("Dropping existing NP-Ticket"),
c.getMslStore().setNpTicket(null));return c._mslContext._generateNPTicket()}).then(function(){return c.getNpTicketCookie()},function(a){w.error("Failed to make new NP-Ticket : "+a.toString())}).then(function(a){b&&b(a)}).done()};this.resetMslContext=function(){w.warn("MSL Context has been reset and it will no longer function properly");this._mslContext=new ia(this)};this.getBackupTokens=function(a){this.getMslStore().getBackupTokens(this._mslContext,a)};Ha(Y,this)}var R=I("nf-console"),w=new R("MSL"),
K=I("nf-promise"),Ha=I("nf-mixin"),Y=I("nf-events").EventEmitter,ca=I("nf-underscore");Oa(O);Nc(O.subtle);Ib(Ab.LEGACY);var Ba={name:"AES-CBC"},ma={name:"HMAC",params:{hash:"SHA-256"}},ia={name:"AES-KW"};v.prototype.load=function(){var a=this.name;w.log("Loading from",a);return C().then(function(b){if(!b)throw"Disk store context does not exist";return new K(function(c,d){b.read(nrdp.storage.NO_DEVICE_ACCOUNT,"msl-backup-tokens",-1,-1,function(b){var e;if(!b.success)return d("Disk store context 'read' failed");
b=b.value;if(!b)return d("Disk store context read returned and empty value");b=ja(b);if(!b)return d("UTF8 conversion of value returned an empty string");e=JSON.parse(b);if(!e||!ca.isObject(e))return d("Loaded data from "+a+" is falsy or not an object");c([b,e])})})})};v.prototype.delete=function(){w.log("Deleting from",this.name);return C().then(function(a){if(a)return new K(function(b,c){a.remove(nrdp.storage.NO_DEVICE_ACCOUNT,"msl-backup-tokens",function(a){if(!a.success)return c("Disk store context 'remove' failed");
b()})})})};v.prototype.save=function(a){var b=this.name;w.log("Saving to",b);return u().then(function(c){return new K(function(d,e){c.create(nrdp.storage.NO_DEVICE_ACCOUNT,"msl-backup-tokens",Da(a),function(a){if(!a.success)return e("Disk store context 'create' failed");w.log("Finished saving to",b);d()})})}).fail(function(a){w.warn("Failed to save to",b,":",a)})};yb=function(a){return K.attempt(function(){return(new P(a))._prepare()})}})();Ib(Ab.LEGACY);yb.TimeoutError=wa;yb.MslException=r;yb.MslEncodingException=
d;yb.MslIoException=G;yb.MslConstants$ResponseCode=c;Y.exports=yb},{"nf-config":5,"nf-console":6,"nf-events":9,"nf-mixin":11,"nf-promise":12,"nf-underscore":13}],11:[function(I,Y,fa){Y.exports=function(I,f){for(var z in I)I.hasOwnProperty(z)&&(f[z]=I[z]);return f}},{}],12:[function(I,Y,fa){Y.exports=function(){var V=I("q"),f=function(f){var E=V.defer(),u=E.resolve.bind(E),b=E.reject.bind(E);try{f(u,b)}catch(e){b(e)}return E.promise};f.attempt=function(f){return V.fcall(f)};f.resolve=function(f){return V(f)};
f.reject=function(f){return V.reject(f)};f.all=function(f){return V.all(f)};V.stopUnhandledRejectionTracking();return f}()},{q:14}],13:[function(I,Y,fa){var V={isNumber:function(f){return"number"===typeof f},isObject:function(f){return"object"===typeof f},isString:function(f){return"string"===typeof f},isUndefined:function(f){return"undefined"===typeof f},isBoolean:function(f){return"boolean"===typeof f},isFunction:function(f){return"function"===typeof f},isNull:function(f){return null===f},isArray:function(f){return"[object Array]"===
Object.prototype.toString.call(f)},isFinite:function(f){return isFinite(f)&&!isNaN(parseFloat(f))},has:function(f,z){return null!==f&&"undefined"!==typeof f&&Object.prototype.hasOwnProperty.call(f,z)},pairs:function(f){var z,E=[];if(!V.isObject(f))throw new TypeError("Object.pairs called on non-object");for(z in f)f.hasOwnProperty(z)&&E.push([z,f[z]]);return E}};V.each=V.forEach=function(f,z,E){if(null===f||"undefined"===typeof f)return f;if(f.length===+f.length)for(var u=0,b=f.length;u<b;u++)z.call(E,
f[u],u,f);else for(u in f)V.has(f,u)&&z.call(E,f[u],u,f);return f};Y.exports=V},{}],14:[function(I,Y,fa){(function(I){(function(f){"function"===typeof bootstrap?bootstrap("promise",f):"object"===typeof fa?Y.exports=f():"function"===typeof define&&define.amd?define(f):"undefined"!==typeof ses?ses.ok()&&(ses.makeQ=f):Q=f()})(function(){function f(a){return function(){return Vb.apply(a,arguments)}}function z(a,b){if(R&&b.stack&&"object"===typeof a&&null!==a&&a.stack&&-1===a.stack.indexOf("From previous event:")){for(var c=
[],e=b;e;e=e.source)e.stack&&c.unshift(e.stack);c.unshift(a.stack);for(var c=c.join("\nFrom previous event:\n").split("\n"),e=[],f=0;f<c.length;++f){var l=c[f],r;if(r=E(l)){var u=r[1];r=r[0]===Ua&&u>=Ta&&u<=v}else r=!1;r||(r=l,r=-1!==r.indexOf("(module.js:")||-1!==r.indexOf("(node.js:"));r||!l||e.push(l)}c=e.join("\n");a.stack=c}}function E(a){var b=/at .+ \((.+):(\d+):(?:\d+)\)$/.exec(a);if(b||(b=/at ([^ ]+):(\d+):(?:\d+)$/.exec(a)))return[b[1],Number(b[2])];if(a=/.*@(.+):(\d+)$/.exec(a))return[a[1],
Number(a[2])]}function u(){if(R)try{throw Error();}catch(a){var b=a.stack.split("\n"),b=0<b[0].indexOf("@")?b[1]:b[2];if(b=E(b))return Ua=b[0],b[1]}}function b(a){return fa(a)?a:Ka(a)?sa(a):qa(a)}function e(){function a(b){r=b;v.source=b;Ma(c,function(a,c){ia(function(){b.promiseDispatch.apply(b,c)})},void 0);f=c=void 0}var c=[],f=[],r,u=jb(e.prototype),v=jb(l.prototype);v.promiseDispatch=function(a,b,d){var e=aa(arguments);c?(c.push(e),"when"===b&&d[1]&&f.push(d[1])):ia(function(){r.promiseDispatch.apply(r,
e)})};v.valueOf=function(){if(c)return v;var a=ja(r);fa(a)&&(r=a);return a};v.inspect=function(){return r?r.inspect():{state:"pending"}};if(b.longStackSupport&&R)try{throw Error();}catch(z){v.stack=z.stack.substring(z.stack.indexOf("\n")+1)}u.promise=v;u.resolve=function(c){r||a(b(c))};u.fulfill=function(b){r||a(qa(b))};u.reject=function(b){r||a(Ia(b))};u.notify=function(a){r||Ma(f,function(b,c){ia(function(){c(a)})},void 0)};return u}function a(a){if("function"!==typeof a)throw new TypeError("resolver must be a function.");
var b=e();try{a(b.resolve,b.reject,b.notify)}catch(c){b.reject(c)}return b.promise}function Y(c){return a(function(a,e){for(var f=0,l=c.length;f<l;f++)b(c[f]).then(a,e)})}function l(a,b,c){void 0===b&&(b=function(a){return Ia(Error("Promise does not support operation: "+a))});void 0===c&&(c=function(){return{state:"unknown"}});var e=jb(l.prototype);e.promiseDispatch=function(c,f,l){var r;try{r=a[f]?a[f].apply(e,l):b.call(e,f,l)}catch(C){r=Ia(C)}c&&c(r)};if(e.inspect=c){var f=c();"rejected"===f.state&&
(e.exception=f.reason);e.valueOf=function(){var a=c();return"pending"===a.state||"rejected"===a.state?e:a.value}}return e}function ka(a,c,e,f){return b(a).then(c,e,f)}function ja(a){if(fa(a)){var b=a.inspect();if("fulfilled"===b.state)return b.value}return a}function fa(a){return a===Object(a)&&"function"===typeof a.promiseDispatch&&"function"===typeof a.inspect}function Ka(a){return a===Object(a)&&"function"===typeof a.then}function O(){Oa.length=0;Ra.length=0;r||(r=!0)}function N(a,b){r&&(Ra.push(a),
b&&"undefined"!==typeof b.stack?Oa.push(b.stack):Oa.push("(no stack) "+b))}function Ia(a){var b=l({when:function(b){if(b&&r){var c=mb(Ra,this);-1!==c&&(Ra.splice(c,1),Oa.splice(c,1))}return b?b(a):this}},function(){return this},function(){return{state:"rejected",reason:a}});N(b,a);return b}function qa(a){return l({when:function(){return a},get:function(b){return a[b]},set:function(b,c){a[b]=c},"delete":function(b){delete a[b]},post:function(b,c){return null===b||void 0===b?a.apply(void 0,c):a[b].apply(a,
c)},apply:function(b,c){return a.apply(b,c)},keys:function(){return J(a)}},void 0,function(){return{state:"fulfilled",value:a}})}function sa(a){var b=e();ia(function(){try{a.then(b.resolve,b.reject,b.notify)}catch(c){b.reject(c)}});return b.promise}function Bb(a,c,e){return b(a).spread(c,e)}function nb(a,c,e){return b(a).dispatch(c,e)}function Na(a){return ka(a,function(a){var b=0,c=e();Ma(a,function(d,e,f){var l;fa(e)&&"fulfilled"===(l=e.inspect()).state?a[f]=l.value:(++b,ka(e,function(d){a[f]=d;
0===--b&&c.resolve(a)},c.reject,function(a){c.notify({index:f,value:a})}))},void 0);0===b&&c.resolve(a);return c.promise})}function P(a){return ka(a,function(a){a=Qa(a,b);return ka(Na(Qa(a,function(a){return ka(a,L,L)})),function(){return a})})}var R=!1;try{throw Error();}catch(zb){R=!!zb.stack}var Ta=u(),Ua,L=function(){},ia=function(){function a(){for(;b.next;){b=b.next;var c=b.task;b.task=void 0;var f=b.domain;f&&(b.domain=void 0,f.enter());try{c()}catch(r){if(l)throw f&&f.exit(),setTimeout(a,
0),f&&f.enter(),r;setTimeout(function(){throw r;},0)}f&&f.exit()}e=!1}var b={task:void 0,next:null},c=b,e=!1,f=void 0,l=!1;ia=function(a){c=c.next={task:a,domain:l&&I.domain,next:null};e||(e=!0,f())};if("undefined"!==typeof I&&I.nextTick)l=!0,f=function(){I.nextTick(a)};else if("function"===typeof setImmediate)f="undefined"!==typeof window?setImmediate.bind(window,a):function(){setImmediate(a)};else if("undefined"!==typeof MessageChannel){var r=new MessageChannel;r.port1.onmessage=function(){f=u;
r.port1.onmessage=a;a()};var u=function(){r.port2.postMessage(0)},f=function(){setTimeout(a,0);u()}}else f=function(){setTimeout(a,0)};return ia}(),Vb=Function.call,aa=f(Array.prototype.slice),Ma=f(Array.prototype.reduce||function(a,b){var c=0,e=this.length;if(1===arguments.length){do{if(c in this){b=this[c++];break}if(++c>=e)throw new TypeError;}while(1)}for(;c<e;c++)c in this&&(b=a(b,this[c],c));return b}),mb=f(Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++)if(this[b]===a)return b;
return-1}),Qa=f(Array.prototype.map||function(a,b){var c=this,e=[];Ma(c,function(f,l,r){e.push(a.call(b,l,r,c))},void 0);return e}),jb=Object.create||function(a){function b(){}b.prototype=a;return new b},c=f(Object.prototype.hasOwnProperty),J=Object.keys||function(a){var b=[],e;for(e in a)c(a,e)&&b.push(e);return b},K=f(Object.prototype.toString),Ja;Ja="undefined"!==typeof ReturnValue?ReturnValue:function(a){this.value=a};b.resolve=b;b.nextTick=ia;b.longStackSupport=!1;b.defer=e;e.prototype.makeNodeResolver=
function(){var a=this;return function(b,c){b?a.reject(b):2<arguments.length?a.resolve(aa(arguments,1)):a.resolve(c)}};b.Promise=a;b.promise=a;a.race=Y;a.all=Na;a.reject=Ia;a.resolve=b;b.passByCopy=function(a){return a};l.prototype.passByCopy=function(){return this};b.join=function(a,c){return b(a).join(c)};l.prototype.join=function(a){return b([this,a]).spread(function(a,b){if(a===b)return a;throw Error("Can't join: not the same: "+a+" "+b);})};b.race=Y;l.prototype.race=function(){return this.then(b.race)};
b.makePromise=l;l.prototype.toString=function(){return"[object Promise]"};l.prototype.then=function(a,c,f){function l(b){try{return"function"===typeof a?a(b):b}catch(c){return Ia(c)}}function r(a){if("function"===typeof c){z(a,u);try{return c(a)}catch(b){return Ia(b)}}return Ia(a)}var u=this,v=e(),E=!1;ia(function(){u.promiseDispatch(function(a){E||(E=!0,v.resolve(l(a)))},"when",[function(a){E||(E=!0,v.resolve(r(a)))}])});u.promiseDispatch(void 0,"when",[void 0,function(a){var c,d=!1;try{c="function"===
typeof f?f(a):a}catch(e){if(d=!0,b.onerror)b.onerror(e);else throw e;}d||v.notify(c)}]);return v.promise};b.when=ka;l.prototype.thenResolve=function(a){return this.then(function(){return a})};b.thenResolve=function(a,c){return b(a).thenResolve(c)};l.prototype.thenReject=function(a){return this.then(function(){throw a;})};b.thenReject=function(a,c){return b(a).thenReject(c)};b.nearer=ja;b.isPromise=fa;b.isPromiseAlike=Ka;b.isPending=function(a){return fa(a)&&"pending"===a.inspect().state};l.prototype.isPending=
function(){return"pending"===this.inspect().state};b.isFulfilled=function(a){return!fa(a)||"fulfilled"===a.inspect().state};l.prototype.isFulfilled=function(){return"fulfilled"===this.inspect().state};b.isRejected=function(a){return fa(a)&&"rejected"===a.inspect().state};l.prototype.isRejected=function(){return"rejected"===this.inspect().state};var Oa=[],Ra=[],r=!0;b.resetUnhandledRejections=O;b.getUnhandledReasons=function(){return Oa.slice()};b.stopUnhandledRejectionTracking=function(){O();r=!1};
O();b.reject=Ia;b.fulfill=qa;b.master=function(a){return l({isDef:function(){}},function(b,c){return nb(a,b,c)},function(){return b(a).inspect()})};b.spread=Bb;l.prototype.spread=function(a,b){return this.all().then(function(b){return a.apply(void 0,b)},b)};b.async=function(a){return function(){function b(a,d){var g;if("undefined"===typeof StopIteration){try{g=c[a](d)}catch(l){return Ia(l)}return g.done?g.value:ka(g.value,e,f)}try{g=c[a](d)}catch(r){return"[object StopIteration]"===K(r)||r instanceof
Ja?r.value:Ia(r)}return ka(g,e,f)}var c=a.apply(this,arguments),e=b.bind(b,"next"),f=b.bind(b,"throw");return e()}};b.spawn=function(a){b.done(b.async(a)())};b["return"]=function(a){throw new Ja(a);};b.promised=function(a){return function(){return Bb([this,Na(arguments)],function(b,c){return a.apply(b,c)})}};b.dispatch=nb;l.prototype.dispatch=function(a,b){var c=this,f=e();ia(function(){c.promiseDispatch(f.resolve,a,b)});return f.promise};b.get=function(a,c){return b(a).dispatch("get",[c])};l.prototype.get=
function(a){return this.dispatch("get",[a])};b.set=function(a,c,e){return b(a).dispatch("set",[c,e])};l.prototype.set=function(a,b){return this.dispatch("set",[a,b])};b.del=b["delete"]=function(a,c){return b(a).dispatch("delete",[c])};l.prototype.del=l.prototype["delete"]=function(a){return this.dispatch("delete",[a])};b.mapply=b.post=function(a,c,e){return b(a).dispatch("post",[c,e])};l.prototype.mapply=l.prototype.post=function(a,b){return this.dispatch("post",[a,b])};b.send=b.mcall=b.invoke=function(a,
c){return b(a).dispatch("post",[c,aa(arguments,2)])};l.prototype.send=l.prototype.mcall=l.prototype.invoke=function(a){return this.dispatch("post",[a,aa(arguments,1)])};b.fapply=function(a,c){return b(a).dispatch("apply",[void 0,c])};l.prototype.fapply=function(a){return this.dispatch("apply",[void 0,a])};b["try"]=b.fcall=function(a){return b(a).dispatch("apply",[void 0,aa(arguments,1)])};l.prototype.fcall=function(){return this.dispatch("apply",[void 0,aa(arguments)])};b.fbind=function(a){var c=
b(a),e=aa(arguments,1);return function(){return c.dispatch("apply",[this,e.concat(aa(arguments))])}};l.prototype.fbind=function(){var a=this,b=aa(arguments);return function(){return a.dispatch("apply",[this,b.concat(aa(arguments))])}};b.keys=function(a){return b(a).dispatch("keys",[])};l.prototype.keys=function(){return this.dispatch("keys",[])};b.all=Na;l.prototype.all=function(){return Na(this)};b.allResolved=function(a,b,c){return function(){"undefined"!==typeof console&&"function"===typeof console.warn&&
console.warn(b+" is deprecated, use "+c+" instead.",Error("").stack);return a.apply(a,arguments)}}(P,"allResolved","allSettled");l.prototype.allResolved=function(){return P(this)};b.allSettled=function(a){return b(a).allSettled()};l.prototype.allSettled=function(){return this.then(function(a){return Na(Qa(a,function(a){function c(){return a.inspect()}a=b(a);return a.then(c,c)}))})};b.fail=b["catch"]=function(a,c){return b(a).then(void 0,c)};l.prototype.fail=l.prototype["catch"]=function(a){return this.then(void 0,
a)};b.progress=function(a,c){return b(a).then(void 0,void 0,c)};l.prototype.progress=function(a){return this.then(void 0,void 0,a)};b.fin=b["finally"]=function(a,c){return b(a)["finally"](c)};l.prototype.fin=l.prototype["finally"]=function(a){a=b(a);return this.then(function(b){return a.fcall().then(function(){return b})},function(b){return a.fcall().then(function(){throw b;})})};b.done=function(a,c,e,f){return b(a).done(c,e,f)};l.prototype.done=function(a,c,e){var f=function(a){ia(function(){z(a,
l);if(b.onerror)b.onerror(a);else throw a;})},l=a||c||e?this.then(a,c,e):this;"object"===typeof I&&I&&I.domain&&(f=I.domain.bind(f));l.then(void 0,f)};b.timeout=function(a,c,e){return b(a).timeout(c,e)};l.prototype.timeout=function(a,b){var c=e(),f=setTimeout(function(){c.reject(Error(b||"Timed out after "+a+" ms"))},a);this.then(function(a){clearTimeout(f);c.resolve(a)},function(a){clearTimeout(f);c.reject(a)},c.notify);return c.promise};b.delay=function(a,c){void 0===c&&(c=a,a=void 0);return b(a).delay(c)};
l.prototype.delay=function(a){return this.then(function(b){var c=e();setTimeout(function(){c.resolve(b)},a);return c.promise})};b.nfapply=function(a,c){return b(a).nfapply(c)};l.prototype.nfapply=function(a){var b=e();a=aa(a);a.push(b.makeNodeResolver());this.fapply(a).fail(b.reject);return b.promise};b.nfcall=function(a){var c=aa(arguments,1);return b(a).nfapply(c)};l.prototype.nfcall=function(){var a=aa(arguments),b=e();a.push(b.makeNodeResolver());this.fapply(a).fail(b.reject);return b.promise};
b.nfbind=b.denodeify=function(a){var c=aa(arguments,1);return function(){var f=c.concat(aa(arguments)),l=e();f.push(l.makeNodeResolver());b(a).fapply(f).fail(l.reject);return l.promise}};l.prototype.nfbind=l.prototype.denodeify=function(){var a=aa(arguments);a.unshift(this);return b.denodeify.apply(void 0,a)};b.nbind=function(a,c){var f=aa(arguments,2);return function(){var l=f.concat(aa(arguments)),r=e();l.push(r.makeNodeResolver());b(function(){return a.apply(c,arguments)}).fapply(l).fail(r.reject);
return r.promise}};l.prototype.nbind=function(){var a=aa(arguments,0);a.unshift(this);return b.nbind.apply(void 0,a)};b.nmapply=b.npost=function(a,c,e){return b(a).npost(c,e)};l.prototype.nmapply=l.prototype.npost=function(a,b){var c=aa(b||[]),f=e();c.push(f.makeNodeResolver());this.dispatch("post",[a,c]).fail(f.reject);return f.promise};b.nsend=b.nmcall=b.ninvoke=function(a,c){var f=aa(arguments,2),l=e();f.push(l.makeNodeResolver());b(a).dispatch("post",[c,f]).fail(l.reject);return l.promise};l.prototype.nsend=
l.prototype.nmcall=l.prototype.ninvoke=function(a){var b=aa(arguments,1),c=e();b.push(c.makeNodeResolver());this.dispatch("post",[a,b]).fail(c.reject);return c.promise};b.nodeify=function(a,c){return b(a).nodeify(c)};l.prototype.nodeify=function(a){if(a)this.then(function(b){ia(function(){a(null,b)})},function(b){ia(function(){a(b)})});else return this};var v=u();return b})}).call(this,I("_process"))},{_process:4}]},{},[1]);
