@cloudbase/js-sdk 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("cloudbase_oauth",[],e):"object"==typeof exports?exports.cloudbase_oauth=e():t.cloudbase_oauth=e()}("undefined"!=typeof window?window:this,(()=>(()=>{"use strict";var t={118:function(t,e,r){var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(e,r);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,i)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),i=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),i(r(342),e)},342:(t,e,r)=>{r.r(e),r.d(e,{AUTH_API_PREFIX:()=>h,Auth:()=>vt,CloudbaseOAuth:()=>_t,authModels:()=>n});var n={};r.r(n);var i,o,s,a,u,c,h="/auth";function l(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,(t=>{var e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)}))}!function(t){t.AUTH_SIGN_UP_URL="/v1/signup",t.AUTH_TOKEN_URL="/v1/token",t.AUTH_REVOKE_URL="/v1/revoke",t.WEDA_USER_URL="/v1/plugin/weda/userinfo",t.AUTH_RESET_PASSWORD="/v1/reset",t.AUTH_GET_DEVICE_CODE="/v1/device/code",t.CHECK_USERNAME="/v1/checkUsername",t.CHECK_IF_USER_EXIST="/v1/checkIfUserExist",t.GET_PROVIDER_TYPE="/v1/mgr/provider/providerSubType",t.AUTH_SIGN_IN_URL="/v1/signin",t.AUTH_SIGN_IN_ANONYMOUSLY_URL="/v1/signin/anonymously",t.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v1/signin/with/provider",t.AUTH_SIGN_IN_WITH_WECHAT_URL="/v1/signin/wechat/noauth",t.AUTH_SIGN_IN_CUSTOM="/v1/signin/custom",t.PROVIDER_TOKEN_URL="/v1/provider/token",t.PROVIDER_URI_URL="/v1/provider/uri",t.USER_ME_URL="/v1/user/me",t.AUTH_SIGNOUT_URL="/v1/user/signout",t.USER_QUERY_URL="/v1/user/query",t.USER_PRIFILE_URL="/v1/user/profile",t.USER_BASIC_EDIT_URL="/v1/user/basic/edit",t.USER_TRANS_BY_PROVIDER_URL="/v1/user/trans/by/provider",t.PROVIDER_LIST="/v1/user/provider",t.PROVIDER_BIND_URL="/v1/user/provider/bind",t.PROVIDER_UNBIND_URL="/v1/user/provider",t.CHECK_PWD_URL="/v1/user/sudo",t.SUDO_URL="/v1/user/sudo",t.BIND_CONTACT_URL="/v1/user/contact",t.AUTH_SET_PASSWORD="/v1/user/password",t.AUTHORIZE_DEVICE_URL="/v1/user/device/authorize",t.AUTHORIZE_URL="/v1/user/authorize",t.AUTHORIZE_INFO_URL="/v1/user/authorize/info",t.AUTHORIZED_DEVICES_DELETE_URL="/v1/user/authorized/devices/",t.AUTH_REVOKE_ALL_URL="/v1/user/revoke/all",t.GET_USER_BEHAVIOR_LOG="/v1/user/security/history",t.VERIFICATION_URL="/v1/verification",t.VERIFY_URL="/v1/verification/verify",t.CAPTCHA_DATA_URL="/v1/captcha/data",t.VERIFY_CAPTCHA_DATA_URL="/v1/captcha/data/verify",t.GET_CAPTCHA_URL="/v1/captcha/init",t.GET_MINIPROGRAM_QRCODE="/v1/qrcode/generate",t.GET_MINIPROGRAM_QRCODE_STATUS="/v1/qrcode/get/status"}(i||(i={})),function(t){t.AUTH_SIGN_IN_URL="/v2/signin/username",t.AUTH_TOKEN_URL="/v2/token",t.USER_ME_URL="/v2/user/me",t.VERIFY_URL="/v2/signin/verificationcode",t.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v2/signin/with/provider",t.AUTH_PUBLIC_KEY="/v2/signin/publichkey",t.AUTH_RESET_PASSWORD="/v2/signin/password/update"}(o||(o={})),function(t){t.REGISTER="REGISTER",t.SIGN_IN="SIGN_IN",t.PASSWORD_RESET="PASSWORD_RESET",t.EMAIL_ADDRESS_CHANGE="EMAIL_ADDRESS_CHANGE",t.PHONE_NUMBER_CHANGE="PHONE_NUMBER_CHANGE"}(s||(s={})),(c=a||(a={})).UNREACHABLE="unreachable",c.LOCAL="local",c.CANCELLED="cancelled",c.UNKNOWN="unknown",c.UNAUTHENTICATED="unauthenticated",c.RESOURCE_EXHAUSTED="resource_exhausted",c.FAILED_PRECONDITION="failed_precondition",c.INVALID_ARGUMENT="invalid_argument",c.DEADLINE_EXCEEDED="deadline_exceeded",c.NOT_FOUND="not_found",c.ALREADY_EXISTS="already_exists",c.PERMISSION_DENIED="permission_denied",c.ABORTED="aborted",c.OUT_OF_RANGE="out_of_range",c.UNIMPLEMENTED="unimplemented",c.INTERNAL="internal",c.UNAVAILABLE="unavailable",c.DATA_LOSS="data_loss",c.INVALID_PASSWORD="invalid_password",c.PASSWORD_NOT_SET="password_not_set",c.INVALID_STATUS="invalid_status",c.USER_PENDING="user_pending",c.USER_BLOCKED="user_blocked",c.INVALID_VERIFICATION_CODE="invalid_verification_code",c.TWO_FACTOR_REQUIRED="two_factor_required",c.INVALID_TWO_FACTOR="invalid_two_factor",c.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",c.UNDER_REVIEW="under_review",c.INVALID_REQUEST="invalid_request",c.UNAUTHORIZED_CLIENT="unauthorized_client",c.ACCESS_DENIED="access_denied",c.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",c.INVALID_SCOPE="invalid_scope",c.INVALID_GRANT="invalid_grant",c.SERVER_ERROR="server_error",c.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",c.INTERACTION_REQUIRED="interaction_required",c.LOGIN_REQUIRED="login_required",c.ACCOUNT_SELECTION_REQUIRED="account_selection_required",c.CONSENT_REQUIRED="consent_required",c.INVALID_REQUEST_URI="invalid_request_uri",c.INVALID_REQUEST_OBJECT="invalid_request_object",c.REQUEST_NOT_SUPPORTED="request_not_supported",c.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",c.REGISTRATION_NOT_SUPPORTED="registration_not_supported",c.CAPTCHA_REQUIRED="captcha_required",c.CAPTCHA_INVALID="captcha_invalid",function(t){t.CLIENT_ID="client_id",t.CLIENT_SECRET="client_secret",t.RESPONSE_TYPE="response_type",t.SCOPE="scope",t.STATE="state",t.REDIRECT_URI="redirect_uri",t.ERROR="error",t.ERROR_DESCRIPTION="error_description",t.ERROR_URI="error_uri",t.GRANT_TYPE="grant_type",t.CODE="code",t.ACCESS_TOKEN="access_token",t.TOKEN_TYPE="token_type",t.EXPIRES_IN="expires_in",t.USERNAME="username",t.PASSWORD="password",t.REFRESH_TOKEN="refresh_token"}(u||(u={}));var d=r(655);function f(t,e,r,n,i,o,s){try{var a=t[o](s),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,i)}function p(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){f(o,n,i,s,a,"next",t)}function a(t){f(o,n,i,s,a,"throw",t)}s(void 0)}))}}var v=new Map;class g{constructor(t){this.clientId=(null==t?void 0:t.clientId)||"",v=v||new Map}run(t,e){var r=this;return p((function*(){t="".concat(r.clientId,"_").concat(t);var n=v.get(t);return n||(n=new Promise(((n,i)=>{p((function*(){try{yield r.runIdlePromise();var o=e();n(yield o)}catch(t){i(t)}finally{v.delete(t)}}))()})),v.set(t,n)),n}))()}runIdlePromise(){return Promise.resolve()}}var y="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",m="@cloudbase/js-sdk";function _(){return m}var b,T="INVALID_OPERATION",E="OPERATION_FAIL";!function(t){t.local="local",t.none="none",t.session="session"}(b||(b={}));function S(t,e){console.warn("[".concat(_(),"][").concat(t,"]:").concat(e))}var w,I,O=(w=function(t,e){return w=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},w(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}w(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),R=function(){return R=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},R.apply(this,arguments)},C=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},A=function(t,e){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};!function(t){function e(e){var r=t.call(this)||this,n=e.timeout,i=e.timeoutMsg,o=e.restrictedMethods;return r.timeout=n||0,r.timeoutMsg=i||"请求超时",r.restrictedMethods=o||["get","post","upload","download"],r}O(e,t),e.prototype.get=function(t){return this.request(R(R({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(R(R({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(R(R({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t.data,r=t.file,n=t.name,i=t.method,o=t.headers,s=void 0===o?{}:o,a={post:"post",put:"put"}[null==i?void 0:i.toLowerCase()]||"put",u=new FormData;return"post"===a?(Object.keys(e).forEach((function(t){u.append(t,e[t])})),u.append("key",n),u.append("file",r),this.request(R(R({},t),{data:u,method:a}),this.restrictedMethods.includes("upload"))):this.request(R(R({},t),{method:"put",headers:s,body:r}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return C(this,void 0,void 0,(function(){var e,r,n,i;return A(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.get(R(R({},t),{headers:{},responseType:"blob"}))];case 1:return e=o.sent().data,r=window.URL.createObjectURL(new Blob([e])),n=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(i=document.createElement("a")).href=r,i.setAttribute("download",n),i.style.display="none",document.body.appendChild(i),i.click(),window.URL.revokeObjectURL(r),document.body.removeChild(i),[3,3];case 2:return o.sent(),[3,3];case 3:return[2,new Promise((function(e){e({statusCode:200,tempFilePath:t.url})}))]}}))}))},e.prototype.fetch=function(t){var e;return C(this,void 0,void 0,(function(){var r,n,i,o,s,a,u,c,h,l,d,f=this;return A(this,(function(p){switch(p.label){case 0:return r=new AbortController,n=t.url,i=t.enableAbort,o=void 0!==i&&i,s=t.stream,a=void 0!==s&&s,u=t.signal,c=t.timeout,h=null!=c?c:this.timeout,u&&(u.aborted&&r.abort(),u.addEventListener("abort",(function(){return r.abort()}))),l=null,o&&h&&(l=setTimeout((function(){console.warn(f.timeoutMsg),r.abort(new Error(f.timeoutMsg))}),h)),[4,fetch(n,R(R({},t),{signal:r.signal})).then((function(t){return C(f,void 0,void 0,(function(){var e,r,n;return A(this,(function(i){switch(i.label){case 0:return clearTimeout(l),t.ok?(e=t,[3,3]):[3,1];case 1:return n=(r=Promise).reject,[4,t.json()];case 2:e=n.apply(r,[i.sent()]),i.label=3;case 3:return[2,e]}}))}))})).catch((function(t){return clearTimeout(l),Promise.reject(t)}))];case 1:return d=p.sent(),[2,{data:a?d.body:(null===(e=d.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?d.json():d.text(),statusCode:d.status,header:d.headers}]}}))}))},e.prototype.request=function(t,e){var r=this;void 0===e&&(e=!1);var n=String(t.method).toLowerCase()||"get";return new Promise((function(i){var o,s,a,u=t.url,c=t.headers,h=void 0===c?{}:c,l=t.data,d=t.responseType,f=t.withCredentials,p=t.body,v=t.onUploadProgress,g=function(t,e,r){void 0===r&&(r={});var n=/\?/.test(e),i="";return Object.keys(r).forEach((function(t){""===i?!n&&(e+="?"):i+="&",i+="".concat(t,"=").concat(encodeURIComponent(r[t]))})),/^http(s)?:\/\//.test(e+=i)?e:"".concat(t).concat(e)}("https:",u,"get"===n?l:{}),y=new XMLHttpRequest;y.open(n,g),d&&(y.responseType=d),Object.keys(h).forEach((function(t){y.setRequestHeader(t,h[t])})),v&&y.upload.addEventListener("progress",v),y.onreadystatechange=function(){var t={};if(4===y.readyState){var e=y.getAllResponseHeaders().trim().split(/[\r\n]+/),r={};e.forEach((function(t){var e=t.split(": "),n=e.shift().toLowerCase(),i=e.join(": ");r[n]=i})),t.header=r,t.statusCode=y.status;try{t.data="blob"===d?y.response:JSON.parse(y.responseText)}catch(e){t.data="blob"===d?y.response:y.responseText}clearTimeout(o),i(t)}},e&&r.timeout&&(o=setTimeout((function(){console.warn(r.timeoutMsg),y.abort()}),r.timeout)),a=l,s="[object FormData]"===Object.prototype.toString.call(a)?l:"application/x-www-form-urlencoded"===h["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach((function(r){e.push("".concat(r,"=").concat(encodeURIComponent(t[r])))})),e.join("&")}(l):p||(l?JSON.stringify(l):void 0),f&&(y.withCredentials=!0),y.send(s)}))}}((function(){})),function(t){t.WEB="web",t.WX_MP="wx_mp"}(I||(I={}));var P=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),U=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},D=function(t,e){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},N=function(t){function e(e){var r=t.call(this)||this;return r.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),r}return P(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}((function(){}));!function(){function t(t){this.keys={};var e=t.persistence,r=t.platformInfo,n=void 0===r?{}:r,i=t.keys,o=void 0===i?{}:i;this.platformInfo=n,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:(S("INVALID_PARAMS","localStorage is not supported on current platform"),new N(e.root));case"none":return new N(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=o)}Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,r){if("async"!==this.mode){if(this.storage)try{var n={version:r||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(n))}catch(t){throw new Error(JSON.stringify({code:E,msg:"[".concat(_(),"][").concat(E,"]setStore failed"),info:t}))}}else S(T,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,r){return U(this,void 0,void 0,(function(){var n;return D(this,(function(i){switch(i.label){case 0:if(!this.storage)return[2];i.label=1;case 1:return i.trys.push([1,3,,4]),n={version:r||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(n))];case 2:return i.sent(),[3,4];case 3:return i.sent(),[2];case 4:return[2]}}))}))},t.prototype.getStore=function(t,e){var r;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0})||void 0===r?void 0:r.tcb_token))return{IS_MP_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var n=this.storage.getItem(t);return n&&n.indexOf(e)>=0?JSON.parse(n).content:""}S(T,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var r;return U(this,void 0,void 0,(function(){var n;return D(this,(function(i){switch(i.label){case 0:try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0})||void 0===r?void 0:r.tcb_token))return[2,{IS_MP_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(n=i.sent())&&n.indexOf(e)>=0?[2,JSON.parse(n).content]:[2,""]}}))}))},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):S(T,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return U(this,void 0,void 0,(function(){return D(this,(function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}}))}))}}();var L=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),x=function(t,e){this.data=e||null,this.name=t},k=function(t){function e(e,r){var n=t.call(this,"error",{error:e,data:r})||this;return n.error=e,n}return L(e,t),e}(x),q=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,r){r[t]=r[t]||[],r[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,r){if(null==r?void 0:r[t]){var n=r[t].indexOf(e);-1!==n&&r[t].splice(n,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof k)return console.error(t.error),this;var r="string"==typeof t?new x(t,e||{}):t,n=r.name;if(this.listens(n)){r.target=this;for(var i=0,o=this.listeners[n]?function(t,e,r){if(r||2===arguments.length)for(var n,i=0,o=e.length;i<o;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}([],this.listeners[n],!0):[];i<o.length;i++)o[i].call(this,r)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();new q;var B=new q;function j(t){this.message=t}function M(t){this.message=t}function H(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function V(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?H(Object(r),!0).forEach((function(e){G(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):H(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function G(t,e,r){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function F(t,e,r,n,i,o,s){try{var a=t[o](s),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,i)}function K(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){F(o,n,i,s,a,"next",t)}function a(t){F(o,n,i,s,a,"throw",t)}s(void 0)}))}}"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox"),j.prototype=new Error,j.prototype.name="InvalidCharacterError","undefined"!=typeof window&&window.atob&&window.atob.bind(window),M.prototype=new Error,M.prototype.name="InvalidTokenError";var W="x-request-id",Y="x-device-id",z="device_id",Z=function(){var t=K((function*(t,e){var r=null,n=null;try{var i=Object.assign({},e);i.method||(i.method="GET"),i.body&&"string"!=typeof i.body&&(i.body=JSON.stringify(i.body));var o=yield fetch(t,i),s=yield o.json();null!=s&&s.error?(n=s).error_uri=new URL(t).pathname:r=s}catch(e){n={error:a.UNREACHABLE,error_description:e.message,error_uri:new URL(t).pathname}}if(n)throw n;return r}));return function(e,r){return t.apply(this,arguments)}}(),Q=new class{constructor(t){this._env=(null==t?void 0:t.env)||""}getItem(t){var e=this;return K((function*(){return window.localStorage.getItem("".concat(t).concat(e._env))}))()}removeItem(t){var e=this;return K((function*(){window.localStorage.removeItem("".concat(t).concat(e._env))}))()}setItem(t,e){var r=this;return K((function*(){window.localStorage.setItem("".concat(t).concat(r._env),e)}))()}getItemSync(t){return window.localStorage.getItem("".concat(t).concat(this._env))}removeItemSync(t){window.localStorage.removeItem("".concat(t).concat(this._env))}setItemSync(t,e){window.localStorage.setItem("".concat(t).concat(this._env),e)}};function J(t){var e=!0;return null!=t&&t.expires_at&&null!=t&&t.access_token&&(e=t.expires_at<new Date),e}class X{constructor(t){this.credentials=null,this.singlePromise=null,this.tokenSectionName=t.tokenSectionName,this.storage=t.storage,this.clientId=t.clientId,this.singlePromise=new g({clientId:this.clientId}),this.credentials=t.credentials||null,this.credentials&&this.setCredentials(this.credentials)}getStorageCredentialsSync(){var t=null,e=this.storage.getItemSync(this.tokenSectionName);if(null!=e)try{var r;null!==(r=t=JSON.parse(e))&&void 0!==r&&r.expires_at&&(t.expires_at=new Date(t.expires_at))}catch(e){this.storage.removeItem(this.tokenSectionName),t=null}return t}setCredentials(t){var e=this;return K((function*(){if(null!=t&&t.expires_in){if(null!=t&&t.expires_at||(t.expires_at=new Date(Date.now()+1e3*(t.expires_in-30))),e.storage){var r=JSON.stringify(t);yield e.storage.setItem(e.tokenSectionName,r)}e.credentials=t}else e.storage&&(yield e.storage.removeItem(e.tokenSectionName)),e.credentials=null}))()}getCredentials(){var t=this;return K((function*(){return t.singlePromise.run("getCredentials",K((function*(){return J(t.credentials)&&(t.credentials=yield t.getStorageCredentials()),t.credentials})))}))()}getStorageCredentials(){var t=this;return K((function*(){return t.singlePromise.run("_getStorageCredentials",K((function*(){var e=null,r=yield t.storage.getItem(t.tokenSectionName);if(null!=r)try{var n;null!==(n=e=JSON.parse(r))&&void 0!==n&&n.expires_at&&(e.expires_at=new Date(e.expires_at))}catch(r){yield t.storage.removeItem(t.tokenSectionName),e=null}return e})))}))()}}class ${constructor(t){this.singlePromise=null,t.clientSecret||(t.clientSecret=""),!t.clientId&&t.env&&(t.clientId=t.env),this.apiOrigin=t.apiOrigin,this.apiPath=t.apiPath||h,this.clientId=t.clientId,this.i18n=t.i18n,this.publishable_key=t.publishable_key,this.singlePromise=new g({clientId:this.clientId}),this.retry=this.formatRetry(t.retry,$.defaultRetry),t.baseRequest?this.baseRequest=t.baseRequest:this.baseRequest=Z,this.tokenInURL=t.tokenInURL,this.headers=t.headers,this.storage=t.storage||Q,this.localCredentials=new X({tokenSectionName:"credentials_".concat(t.clientId),storage:this.storage,clientId:t.clientId,credentials:this.publishable_key?{access_token:this.publishable_key,token_type:"Bearer",scope:"publishable_key",expires_at:new Date(+new Date+ +new Date),expires_in:+new Date+ +new Date}:null}),this.clientSecret=t.clientSecret,t.clientId&&(this.basicAuth="Basic ".concat(function(t){for(var e,r,n,i,o="",s=0,a=(t=String(t)).length%3;s<t.length;){if((r=t.charCodeAt(s++))>255||(n=t.charCodeAt(s++))>255||(i=t.charCodeAt(s++))>255)throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");o+=y.charAt((e=r<<16|n<<8|i)>>18&63)+y.charAt(e>>12&63)+y.charAt(e>>6&63)+y.charAt(63&e)}return a?o.slice(0,a-3)+"===".substring(a):o}("".concat(t.clientId,":").concat(this.clientSecret)))),this.wxCloud=t.wxCloud;try{(function(){if("undefined"==typeof wx)return!1;if("undefined"==typeof Page)return!1;if(!wx.getSystemInfoSync)return!1;if(!wx.getStorageSync)return!1;if(!wx.setStorageSync)return!1;if(!wx.connectSocket)return!1;if(!wx.request)return!1;try{if(!wx.getSystemInfoSync())return!1;if("qq"===wx.getSystemInfoSync().AppPlatform)return!1}catch(t){return!1}return!0})()&&void 0===this.wxCloud&&t.env&&(wx.cloud.init({env:t.env}),this.wxCloud=wx.cloud)}catch(t){}this.refreshTokenFunc=t.refreshTokenFunc||this.defaultRefreshTokenFunc,this.anonymousSignInFunc=t.anonymousSignInFunc,this.onCredentialsError=t.onCredentialsError,B.on("lang_change",(t=>{var e;this.i18n=(null===(e=t.data)||void 0===e?void 0:e.i18n)||this.i18n}))}setCredentials(t){return this.localCredentials.setCredentials(t)}getAccessToken(){var t=this;return K((function*(){var e=yield t.getCredentials();if(null!=e&&e.access_token)return Promise.resolve(e.access_token);var r={error:a.UNAUTHENTICATED};return Promise.reject(r)}))()}request(t,e){var r=this;return K((function*(){var n,i,o,s;e||(e={});var u=r.formatRetry(e.retry,r.retry);if(e.headers=V(V({},e.headers),{},{[null===(n=r.i18n)||void 0===n?void 0:n.LANG_HEADER_KEY]:null===(i=r.i18n)||void 0===i?void 0:i.lang}),r.headers&&(e.headers=V(V({},r.headers),e.headers)),e.headers[W]||(e.headers[W]=l()),!e.headers[Y]){var c=yield r.getDeviceId();e.headers[Y]=c}if(null!==(o=e)&&void 0!==o&&o.withBasicAuth&&r.basicAuth&&(e.headers.Authorization=r.basicAuth),null!==(s=e)&&void 0!==s&&s.withCredentials){var h=yield r.getCredentials();h&&(r.tokenInURL?(t.indexOf("?")<0&&(t+="?"),t+="access_token=".concat(h.access_token)):e.headers.Authorization="".concat(h.token_type," ").concat(h.access_token))}else r.clientId&&t.indexOf("client_id")<0&&(t+=t.indexOf("?")<0?"?":"&",t+="client_id=".concat(r.clientId));t.startsWith("/")&&(t="".concat(r.apiOrigin).concat(r.apiPath).concat(t));for(var d=null,f=u+1,p=0;p<f;p++){try{d=e.useWxCloud?yield r.wxCloudCallFunction(t,e):yield r.baseRequest(t,e);break}catch(t){if(e.withCredentials&&t&&t.error===a.UNAUTHENTICATED)return yield r.setCredentials(null),Promise.reject(t);if(p===u||!t||"unreachable"!==t.error)return Promise.reject(t)}yield r.sleep($.retryInterval)}return d}))()}wxCloudCallFunction(t,e){var r=this;return K((function*(){var n=null,i=null;try{var o,s="";try{s=yield wx.getRendererUserAgent()}catch(t){}var{result:u}=yield r.wxCloud.callFunction({name:"httpOverCallFunction",data:{url:t,method:e.method,headers:V({origin:"https://servicewechat.com","User-Agent":s},e.headers),body:e.body}});null!=u&&null!==(o=u.body)&&void 0!==o&&o.error_code?(i=null==u?void 0:u.body).error_uri=(0,d.y)(t):n=null==u?void 0:u.body}catch(e){i={error:a.UNREACHABLE,error_description:e.message,error_uri:(0,d.y)(t)}}if(i)throw i;return n}))()}getCredentials(){var t=this;return K((function*(){var e=yield t.localCredentials.getCredentials();if(!e){var r,n="credentials not found";return null===(r=t.onCredentialsError)||void 0===r||r.call(t,{msg:n}),t.unAuthenticatedError(n)}if(J(e))if(e.refresh_token)try{e=yield t.refreshToken(e)}catch(r){var i;if("anonymous"!==e.scope)return null===(i=t.onCredentialsError)||void 0===i||i.call(t,{msg:r.error_description}),Promise.reject(r);e=yield t.anonymousLogin(e)}else{if("anonymous"!==e.scope){var o,s="no refresh token found in credentials";return null===(o=t.onCredentialsError)||void 0===o||o.call(t,{msg:s}),t.unAuthenticatedError(s)}e=yield t.anonymousLogin(e)}return e}))()}getCredentialsSync(){return this.localCredentials.getStorageCredentialsSync()}getCredentialsAsync(){return this.getCredentials()}getScope(){var t=this;return K((function*(){var e=yield t.localCredentials.getCredentials();if(!e){var r,n="credentials not found";return null===(r=t.onCredentialsError)||void 0===r||r.call(t,{msg:n}),t.unAuthenticatedError(n)}return e.scope}))()}getGroups(){var t=this;return K((function*(){var e=yield t.localCredentials.getCredentials();if(!e){var r,n="credentials not found";return null===(r=t.onCredentialsError)||void 0===r||r.call(t,{msg:n}),t.unAuthenticatedError(n)}return e.groups}))()}refreshToken(t){var e=this;return K((function*(){return e.singlePromise.run("_refreshToken",K((function*(){if(!t||!t.refresh_token){var r,n="no refresh token found in credentials";return null===(r=e.onCredentialsError)||void 0===r||r.call(e,{msg:n}),e.unAuthenticatedError(n)}try{var i=yield e.refreshTokenFunc(t.refresh_token,t);return yield e.localCredentials.setCredentials(i),i}catch(t){var o;if(t.error===a.INVALID_GRANT){var s;yield e.localCredentials.setCredentials(null);var u=t.error_description;return null===(s=e.onCredentialsError)||void 0===s||s.call(e,{msg:u}),e.unAuthenticatedError(u)}return null===(o=e.onCredentialsError)||void 0===o||o.call(e,{msg:t.error_description}),Promise.reject(t)}})))}))()}anonymousLogin(t){var e=this;return K((function*(){return e.singlePromise.run("_anonymousLogin",K((function*(){if(e.anonymousSignInFunc){var r=yield e.anonymousSignInFunc(t);t=r||(yield e.localCredentials.getCredentials())}else t=yield e.anonymousSignIn(t);return t})))}))()}checkRetry(t){var e=null;if(("number"!=typeof t||t<$.minRetry||t>$.maxRetry)&&(e={error:a.UNREACHABLE,error_description:"wrong options param: retry"}),e)throw e;return t}formatRetry(t,e){return void 0===t?e:this.checkRetry(t)}sleep(t){return K((function*(){return new Promise((e=>{setTimeout((()=>{e()}),t)}))}))()}anonymousSignIn(t){var e=this;return K((function*(){return e.singlePromise.run("_anonymous",K((function*(){if(!t||"anonymous"!==t.scope)return e.unAuthenticatedError("no anonymous in credentials");try{var r=yield e.request(i.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",withBasicAuth:!0,body:{}});return yield e.localCredentials.setCredentials(r),r}catch(t){return t.error===a.INVALID_GRANT?(yield e.localCredentials.setCredentials(null),e.unAuthenticatedError(t.error_description)):Promise.reject(t)}})))}))()}defaultRefreshTokenFunc(t,e){var r=this;return K((function*(){if(void 0===t||""===t){var n,s="refresh token not found";return null===(n=r.onCredentialsError)||void 0===n||n.call(r,{msg:s}),r.unAuthenticatedError(s)}var a=i.AUTH_TOKEN_URL;return"v2"===(null==e?void 0:e.version)&&(a=o.AUTH_TOKEN_URL),V(V({},yield r.request(a,{method:"POST",body:{client_id:r.clientId,client_secret:r.clientSecret,grant_type:"refresh_token",refresh_token:t}})),{},{version:(null==e?void 0:e.version)||"v1"})}))()}getDeviceId(){var t=this;return K((function*(){if(t.deviceID)return t.deviceID;var e=yield t.storage.getItem(z);return"string"==typeof e&&e.length>=16&&e.length<=48||(e=l(),yield t.storage.setItem(z,e)),t.deviceID=e,e}))()}unAuthenticatedError(t){var e={error:a.UNAUTHENTICATED,error_description:t};return Promise.reject(e)}}function tt(){if("undefined"==typeof globalThis)return!1;var{wx:t}=globalThis;if(void 0===t)return!1;if(void 0===globalThis.Page)return!1;if(!t.getSystemInfoSync)return!1;if(!t.getStorageSync)return!1;if(!t.setStorageSync)return!1;if(!t.connectSocket)return!1;if(!t.request)return!1;try{if(!t.getSystemInfoSync())return!1;if("qq"===t.getSystemInfoSync().AppPlatform)return!1}catch(t){return!1}return!0}$.defaultRetry=2,$.minRetry=0,$.maxRetry=5,$.retryInterval=1e3;var et=!1;function rt(){et=et||void 0!==typeof window&&"miniprogram"===window.__wxjs_environment}try{tt()||(et=et||!!navigator.userAgent.match(/miniprogram/i)||"miniprogram"===window.__wxjs_environment,window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?rt():"undefined"!=typeof document&&document.addEventListener("WeixinJSBridgeReady",rt,!1))}catch(j){}function nt(){return et}const it=class{constructor(t){if(this.params={},"string"==typeof t)this.parse(t);else if(t&&"object"==typeof t)for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&this.append(e,t[e])}parse(t){t.split("&").forEach((t=>{var[e,r]=t.split("=").map(decodeURIComponent);this.append(e,r)}))}append(t,e){this.params[t]?this.params[t]=this.params[t].concat([e]):this.params[t]=[e]}get(t){return this.params[t]?this.params[t][0]:null}getAll(t){return this.params[t]||[]}delete(t){delete this.params[t]}has(t){return Object.prototype.hasOwnProperty.call(this.params,t)}set(t,e){this.params[t]=[e]}toString(){var t=this,e=[],r=function(r){Object.prototype.hasOwnProperty.call(t.params,r)&&t.params[r].forEach((t=>{e.push("".concat(encodeURIComponent(r),"=").concat(encodeURIComponent(t)))}))};for(var n in this.params)r(n);return e.join("&")}};function ot(t,e,r,n,i,o,s){try{var a=t[o](s),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,i)}function st(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){ot(o,n,i,s,a,"next",t)}function a(t){ot(o,n,i,s,a,"throw",t)}s(void 0)}))}}class at{constructor(t){t.openURIWithCallback||(t.openURIWithCallback=this.getDefaultOpenURIWithCallback()),t.storage||(t.storage=Q),this.config=t,this.tokenSectionName="captcha_".concat(t.clientId)}isMatch(){var t,e;return(null===(t=this.config)||void 0===t||null===(t=t.adapter)||void 0===t||null===(e=t.isMatch)||void 0===e?void 0:e.call(t))||tt()}request(t,e){var r=this;return st((function*(){e||(e={}),e.method||(e.method="GET");var n,i="".concat(e.method,":").concat(t),o=t;e.withCaptcha&&(o=yield r.appendCaptchaTokenToURL(t,i,!1));try{n=yield r.config.request(o,e)}catch(n){return n.error===a.CAPTCHA_REQUIRED||n.error===a.CAPTCHA_INVALID?(t=yield r.appendCaptchaTokenToURL(t,i,n.error===a.CAPTCHA_INVALID),r.config.request(t,e)):Promise.reject(n)}return n}))()}getDefaultOpenURIWithCallback(){if(!this.isMatch()&&!nt()&&(window.location.search.indexOf("__captcha")>0&&(document.body.style.display="none"),null===document.getElementById("captcha_panel_wrap"))){var t=document.createElement("div");t.style.cssText="background-color: rgba(0, 0, 0, 0.7);position: fixed;left: 0px;right: 0px;top: 0px;bottom: 0px;padding: 9vw 0 0 0;display: none;z-index:100;",t.setAttribute("id","captcha_panel_wrap"),setTimeout((()=>{document.body.appendChild(t)}),0)}return this.defaultOpenURIWithCallback}defaultOpenURIWithCallback(t,e){return st((function*(){var{width:r="355px",height:n="355px"}=e||{};if(t.match(/^(data:.*)$/))return Promise.reject({error:a.UNIMPLEMENTED,error_description:"need to impl captcha data"});var i=document.getElementById("captcha_panel_wrap"),o=document.createElement("iframe");return i.innerHTML="",o.setAttribute("src",t),o.setAttribute("id","review-panel-iframe"),o.style.cssText="min-width:".concat(r,";display:block;height:").concat(n,";margin:0 auto;background-color: rgb(255, 255, 255);border: none;"),i.appendChild(o),i.style.display="block",new Promise(((t,e)=>{o.onload=function(){try{var r=window.location,n=o.contentWindow.location;if(n.host+n.pathname===r.host+r.pathname){i.style.display="none";var s=new it(n.search),a=s.get("captcha_token");return a?t({captcha_token:a,expires_in:Number(s.get("expires_in"))}):e({error:s.get("error"),error_description:s.get("error_description")})}i.style.display="block"}catch(t){i.style.display="block"}}}))}))()}getCaptchaToken(t,e){var r=this;return st((function*(){if(!t){var n=yield r.findCaptchaToken();if(n)return n}var o;if(r.isMatch()||nt()){var s=yield r.config.request(i.CAPTCHA_DATA_URL,{method:"POST",body:{state:e,redirect_uri:""},withCredentials:!1});o={url:"".concat(s.data,"?state=").concat(encodeURIComponent(e),"&token=").concat(encodeURIComponent(s.token))}}else{var a="".concat(window.location.origin+window.location.pathname,"?__captcha=on");if((o=yield r.config.request(i.GET_CAPTCHA_URL,{method:"POST",body:{client_id:r.config.clientId,redirect_uri:a,state:e},withCredentials:!1})).captcha_token){var u={captcha_token:o.captcha_token,expires_in:o.expires_in};return r.saveCaptchaToken(u),o.captcha_token}}var c=yield r.config.openURIWithCallback(o.url);return r.saveCaptchaToken(c),c.captcha_token}))()}appendCaptchaTokenToURL(t,e,r){var n=this;return st((function*(){var i=yield n.getCaptchaToken(r,e);return t.indexOf("?")>0?t+="&captcha_token=".concat(i):t+="?captcha_token=".concat(i),t}))()}saveCaptchaToken(t){var e=this;return st((function*(){t.expires_at=new Date(Date.now()+1e3*(t.expires_in-10));var r=JSON.stringify(t);yield e.config.storage.setItem(e.tokenSectionName,r)}))()}findCaptchaToken(){var t=this;return st((function*(){var e=yield t.config.storage.getItem(t.tokenSectionName);if(null!=e)try{var r=JSON.parse(e);return null!=r&&r.expires_at&&(r.expires_at=new Date(r.expires_at)),r.expires_at<new Date?null:r.captcha_token}catch(e){return yield t.config.storage.removeItem(t.tokenSectionName),null}return null}))()}}var ut=["provider_redirect_uri","other_params"];function ct(t,e,r,n,i,o,s){try{var a=t[o](s),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,i)}function ht(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){ct(o,n,i,s,a,"next",t)}function a(t){ct(o,n,i,s,a,"throw",t)}s(void 0)}))}}function lt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function dt(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?lt(Object(r),!0).forEach((function(e){ft(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):lt(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function ft(t,e,r){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function pt(t,e){try{var n;if(((null==e||null===(n=e.root)||void 0===n?void 0:n.globalThis)||globalThis).IS_MP_BUILD)return}catch(e){if(t)return(()=>{try{return r(171)}catch(t){return}})()}}class vt{static parseParamsToSearch(t){return Object.keys(t).forEach((e=>{t[e]||delete t[e]})),new it(t).toString()}constructor(t){var{request:e}=t,r=t.credentialsClient;if(!r){var n={apiOrigin:t.apiOrigin,apiPath:t.apiPath,clientId:t.clientId,storage:t.storage,env:t.env,baseRequest:t.baseRequest,anonymousSignInFunc:t.anonymousSignInFunc,wxCloud:t.wxCloud,onCredentialsError:t.onCredentialsError,headers:t.headers||{},i18n:t.i18n,publishable_key:t.publishable_key};r=new $(n)}if(!e){var i=r.request.bind(r),o=new at(dt({clientId:t.clientId,request:i,storage:t.storage,adapter:t.adapter},t.captchaOptions));e=o.request.bind(o)}this.config={env:t.env,apiOrigin:t.apiOrigin,apiPath:t.apiPath,clientId:t.clientId,request:e,credentialsClient:r,storage:t.storage||Q,adapter:t.adapter}}getParamsByVersion(t,e){var r,n=(0,d.I)(t),s=(null===(r={v2:o}[null==n?void 0:n.version])||void 0===r?void 0:r[e])||i[e];return n&&delete n.version,{params:n,url:s}}signIn(t){var e=this;return ht((function*(){var r=t.version||"v1",n=e.getParamsByVersion(t,"AUTH_SIGN_IN_URL");n.params.query&&delete n.params.query;var i=yield e.getEncryptParams(n.params),o=yield e.config.request(n.url,{method:"POST",body:i});return yield e.config.credentialsClient.setCredentials(dt(dt({},o),{},{version:r})),Promise.resolve(o)}))()}signInAnonymously(){var t=arguments,e=this;return ht((function*(){var r=t.length>0&&void 0!==t[0]?t[0]:{},n=t.length>1&&void 0!==t[1]&&t[1],o=yield e.config.request(i.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:r,useWxCloud:n});return yield e.config.credentialsClient.setCredentials(o),Promise.resolve(o)}))()}signUp(t){var e=this;return ht((function*(){var r=yield e.config.request(i.AUTH_SIGN_UP_URL,{method:"POST",body:t});return yield e.config.credentialsClient.setCredentials(r),Promise.resolve(r)}))()}signOut(t){var e=this;return ht((function*(){var r={};if(t){try{r=yield e.config.request(i.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:t})}catch(t){t.error!==a.UNAUTHENTICATED&&console.log("sign_out_error",t)}return yield e.config.credentialsClient.setCredentials(),r}var n=yield e.config.credentialsClient.getAccessToken(),o=yield e.config.request(i.AUTH_REVOKE_URL,{method:"POST",body:{token:n}});return yield e.config.credentialsClient.setCredentials(),Promise.resolve(o)}))()}revokeAllDevices(){var t=this;return ht((function*(){yield t.config.request(i.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})}))()}revokeDevice(t){var e=this;return ht((function*(){yield e.config.request(i.AUTHORIZED_DEVICES_DELETE_URL+t.device_id,{method:"DELETE",withCredentials:!0})}))()}getVerification(t,e){var r=this;return ht((function*(){var n=!1;return("CUR_USER"===t.target||(yield r.hasLoginState()))&&(n=!0),r.config.request(i.VERIFICATION_URL,{method:"POST",body:t,withCaptcha:(null==e?void 0:e.withCaptcha)||!1,withCredentials:n})}))()}verify(t){var e=this;return ht((function*(){var r=e.getParamsByVersion(t,"VERIFY_URL"),n=yield e.config.request(r.url,{method:"POST",body:r.params});return"v2"===(null==t?void 0:t.version)&&(yield e.config.credentialsClient.setCredentials(dt(dt({},n),{},{version:"v2"}))),n}))()}genProviderRedirectUri(t){var e=this;return ht((function*(){var{provider_redirect_uri:r,other_params:n={}}=t,o=function(t,e){if(null==t)return{};var r,n,i=function(t,e){if(null==t)return{};var r={};for(var n in t)if({}.hasOwnProperty.call(t,n)){if(e.includes(n))continue;r[n]=t[n]}return r}(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(n=0;n<o.length;n++)r=o[n],e.includes(r)||{}.propertyIsEnumerable.call(t,r)&&(i[r]=t[r])}return i}(t,ut);r&&!o.redirect_uri&&(o.redirect_uri=r);var s="".concat(i.PROVIDER_URI_URL,"?").concat(vt.parseParamsToSearch(o));return Object.keys(n).forEach((t=>{var e=n[t];("sign_out_uri"!==t||(null==e?void 0:e.length)>0)&&(s+="&other_params[".concat(t,"]=").concat(encodeURIComponent(e)))})),e.config.request(s,{method:"GET"})}))()}grantProviderToken(t){var e=arguments,r=this;return ht((function*(){var n=e.length>1&&void 0!==e[1]&&e[1];return r.config.request(i.PROVIDER_TOKEN_URL,{method:"POST",body:t,useWxCloud:n})}))()}patchProviderToken(t){var e=this;return ht((function*(){return e.config.request(i.PROVIDER_TOKEN_URL,{method:"PATCH",body:t})}))()}signInWithProvider(t){var e=arguments,r=this;return ht((function*(){var n=e.length>1&&void 0!==e[1]&&e[1],i=r.getParamsByVersion(t,"AUTH_SIGN_IN_WITH_PROVIDER_URL"),o=yield r.config.request(i.url,{method:"POST",body:i.params,useWxCloud:n});return yield r.config.credentialsClient.setCredentials(dt(dt({},o),{},{version:(null==t?void 0:t.version)||"v1"})),Promise.resolve(o)}))()}signInCustom(t){var e=this;return ht((function*(){var r=yield e.config.request(i.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:t});return yield e.config.credentialsClient.setCredentials(r),Promise.resolve(r)}))()}signInWithWechat(){var t=arguments,e=this;return ht((function*(){var r=t.length>0&&void 0!==t[0]?t[0]:{},n=yield e.config.request(i.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:r});return yield e.config.credentialsClient.setCredentials(n),Promise.resolve(n)}))()}bindWithProvider(t){var e=this;return ht((function*(){return e.config.request(i.PROVIDER_BIND_URL,{method:"POST",body:t,withCredentials:!0})}))()}getUserProfile(t){var e=this;return ht((function*(){return e.getUserInfo(t)}))()}getUserInfo(){var t=arguments,e=this;return ht((function*(){var r,n=t.length>0&&void 0!==t[0]?t[0]:{},i=e.getParamsByVersion(n,"USER_ME_URL");if(null!==(r=i.params)&&void 0!==r&&r.query){var o=new it(i.params.query);i.url+="?".concat(o.toString())}var s=yield e.config.request(i.url,{method:"GET",withCredentials:!0});return s.sub&&(s.uid=s.sub),s}))()}getWedaUserInfo(){var t=this;return ht((function*(){return yield t.config.request(i.WEDA_USER_URL,{method:"GET",withCredentials:!0})}))()}deleteMe(t){var e=this;return ht((function*(){var r=e.getParamsByVersion(t,"USER_ME_URL"),n="".concat(r.url,"?").concat(vt.parseParamsToSearch(r.params));return e.config.request(n,{method:"DELETE",withCredentials:!0})}))()}hasLoginState(){var t=this;return ht((function*(){try{return yield t.config.credentialsClient.getAccessToken(),!0}catch(t){return!1}}))()}hasLoginStateSync(){return this.config.credentialsClient.getCredentialsSync()}getLoginState(){var t=this;return ht((function*(){return t.config.credentialsClient.getCredentialsAsync()}))()}transByProvider(t){var e=this;return ht((function*(){return e.config.request(i.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:t,withCredentials:!0})}))()}grantToken(t){var e=this;return ht((function*(){var r=e.getParamsByVersion(t,"AUTH_TOKEN_URL");return e.config.request(r.url,{method:"POST",body:r.params})}))()}getProviders(){var t=this;return ht((function*(){return t.config.request(i.PROVIDER_LIST,{method:"GET",withCredentials:!0})}))()}unbindProvider(t){var e=this;return ht((function*(){return e.config.request("".concat(i.PROVIDER_UNBIND_URL,"/").concat(t.provider_id),{method:"DELETE",withCredentials:!0})}))()}checkPassword(t){var e=this;return ht((function*(){return e.config.request("".concat(i.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:t})}))()}editContact(t){var e=this;return ht((function*(){return e.config.request("".concat(i.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:t})}))()}setPassword(t){var e=this;return ht((function*(){return e.config.request("".concat(i.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:t})}))()}updatePasswordByOld(t){var e=this;return ht((function*(){var r=yield e.sudo({password:t.old_password});return e.setPassword({sudo_token:r.sudo_token,new_password:t.new_password})}))()}sudo(t){var e=this;return ht((function*(){return e.config.request("".concat(i.SUDO_URL),{method:"POST",withCredentials:!0,body:t})}))()}sendVerificationCodeToCurrentUser(t){var e=this;return ht((function*(){return t.target="CUR_USER",e.config.request(i.VERIFICATION_URL,{method:"POST",body:t,withCredentials:!0,withCaptcha:!0})}))()}changeBoundProvider(t){var e=this;return ht((function*(){return e.config.request("".concat(i.PROVIDER_LIST,"/").concat(t.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:t.trans_token},withCredentials:!0})}))()}setUserProfile(t){var e=this;return ht((function*(){return e.config.request(i.USER_PRIFILE_URL,{method:"PATCH",body:t,withCredentials:!0})}))()}updateUserBasicInfo(t){var e=this;return ht((function*(){return e.config.request(i.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:t})}))()}queryUserProfile(t){var e=this;return ht((function*(){var r=new it(t);return e.config.request("".concat(i.USER_QUERY_URL,"?").concat(r.toString()),{method:"GET",withCredentials:!0})}))()}setCustomSignFunc(t){this.getCustomSignTicketFn=t}signInWithCustomTicket(){var t=this;return ht((function*(){var e=t.getCustomSignTicketFn;if(!e)return Promise.reject({error:"failed_precondition",error_description:"please use setCustomSignFunc to set custom sign function"});var r=yield e();return t.signInCustom({provider_id:"custom",ticket:r})}))()}resetPassword(t){var e=this;return ht((function*(){return e.config.request(i.AUTH_RESET_PASSWORD,{method:"POST",body:t})}))()}authorize(t){var e=this;return ht((function*(){return e.config.request(i.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:t})}))()}authorizeDevice(t){var e=this;return ht((function*(){return e.config.request(i.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:t})}))()}deviceAuthorize(t){var e=this;return ht((function*(){return e.config.request(i.AUTH_GET_DEVICE_CODE,{method:"POST",body:t,withCredentials:!0})}))()}authorizeInfo(t){var e=this;return ht((function*(){var r="".concat(i.AUTHORIZE_INFO_URL,"?").concat(vt.parseParamsToSearch(t)),n=!0,o=!1;return(yield e.hasLoginState())&&(o=!0,n=!1),e.config.request(r,{method:"GET",withBasicAuth:n,withCredentials:o})}))()}checkUsername(t){var e=this;return ht((function*(){return e.config.request(i.CHECK_USERNAME,{method:"GET",body:t,withCredentials:!0})}))()}checkIfUserExist(t){var e=this;return ht((function*(){var r=new it(t);return e.config.request("".concat(i.CHECK_IF_USER_EXIST,"?").concat(r.toString()),{method:"GET"})}))()}loginScope(){var t=this;return ht((function*(){return t.config.credentialsClient.getScope()}))()}loginGroups(){var t=this;return ht((function*(){return t.config.credentialsClient.getGroups()}))()}refreshTokenForce(t){var e=this;return ht((function*(){var r=yield e.config.credentialsClient.getCredentials();return yield e.config.credentialsClient.refreshToken(dt(dt({},r),{},{version:(null==t?void 0:t.version)||"v1"}))}))()}getCredentials(){var t=this;return ht((function*(){return t.config.credentialsClient.getCredentials()}))()}getPublicKey(){var t=this;return ht((function*(){return t.config.request(o.AUTH_PUBLIC_KEY,{method:"POST",body:{}})}))()}getEncryptParams(t){var e=this;return ht((function*(){var{isEncrypt:r}=t;delete t.isEncrypt;var n=(0,d.I)(t),i=pt(r,e.config.adapter);if(!i)return t;var o="",s="";try{var a=yield e.getPublicKey();if(o=a.public_key,s=a.public_key_thumbprint,!o||!s)throw a}catch(t){throw t}return{params:i.getEncryptInfo({publicKey:o,payload:n}),public_key_thumbprint:s}}))()}getProviderSubType(){var t=this;return ht((function*(){return t.config.request(i.GET_PROVIDER_TYPE,{method:"POST",body:{provider_id:"weda"}})}))()}verifyCaptchaData(t){var e=this;return ht((function*(){var{token:r,key:n}=t;return e.config.request(i.VERIFY_CAPTCHA_DATA_URL,{method:"POST",body:{token:r,key:n},withCredentials:!1})}))()}createCaptchaData(t){var e=this;return ht((function*(){var{state:r,redirect_uri:n}=t;return e.config.request(i.CAPTCHA_DATA_URL,{method:"POST",body:{state:r,redirect_uri:n},withCredentials:!1})}))()}getMiniProgramCode(t){var e=this;return ht((function*(){return e.config.request(i.GET_MINIPROGRAM_QRCODE,{method:"POST",body:t})}))()}getMiniProgramQrCodeStatus(t){var e=this;return ht((function*(){return e.config.request(i.GET_MINIPROGRAM_QRCODE_STATUS,{method:"POST",body:t})}))()}getUserBehaviorLog(t){var e=this;return ht((function*(){var r="".concat(i.GET_USER_BEHAVIOR_LOG,"?").concat({LOGIN:"query[action]=USER_LOGIN",MODIFY:"ne_query[action]=USER_LOGIN"}[t.type],"&limit=").concat(t.limit).concat(t.page_token?"&page_token=".concat(t.page_token):"");return e.config.request(r,{method:"GET",withCredentials:!0})}))()}modifyPassword(t){var e=this;return ht((function*(){var r="",n="",o=pt(!0,e.config.adapter);if(!o)throw new Error("do not support encrypt, a encrypt util required.");try{var s=yield e.getPublicKey();if(r=s.public_key,n=s.public_key_thumbprint,!r||!n)throw s}catch(t){throw t}var a=t.password?o.getEncryptInfo({publicKey:r,payload:t.password}):"",u=o.getEncryptInfo({publicKey:r,payload:t.new_password});return e.config.request(i.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:{user_id:t.user_id,encrypt_password:a,encrypt_new_password:u,public_key_thumbprint:n}})}))()}modifyPasswordWithoutLogin(t){var e=this;return ht((function*(){var r="",n="",i=pt(!0,e.config.adapter);if(!i)throw new Error("do not support encrypt, a encrypt util required.");try{var s=yield e.getPublicKey();if(r=s.public_key,n=s.public_key_thumbprint,!r||!n)throw s}catch(t){throw t}var a=t.password?i.getEncryptInfo({publicKey:r,payload:t.password}):"",u=i.getEncryptInfo({publicKey:r,payload:t.new_password});return e.config.request(o.AUTH_RESET_PASSWORD,{method:"POST",body:{username:t.username,password:a,new_password:u,public_key_thumbprint:n}})}))()}}function gt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function yt(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?gt(Object(r),!0).forEach((function(e){mt(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):gt(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function mt(t,e,r){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}class _t{constructor(t){var{apiOrigin:e,apiPath:r=h,clientId:n,env:i,storage:o,request:s,baseRequest:a,anonymousSignInFunc:u,wxCloud:c,adapter:l,onCredentialsError:d,headers:f,i18n:p,publishable_key:v}=t;this.oauth2client=new $({apiOrigin:e,apiPath:r,clientId:n,env:i,storage:o,baseRequest:a||s,anonymousSignInFunc:u,wxCloud:c,onCredentialsError:d,headers:f||{},i18n:p,publishable_key:v}),this.authApi=new vt(yt(yt({credentialsClient:this.oauth2client},t),{},{request:s?this.oauth2client.request.bind(this.oauth2client):void 0,adapter:l}))}}},171:(t,e,r)=>{var n;if(r.r(e),r.d(e,{getEncryptInfo:()=>j}),!globalThis.IS_MP_BUILD){var i="undefined"!=typeof globalThis?globalThis.navigator:window.globalThis,o="0123456789abcdefghijklmnopqrstuvwxyz";function M(t){return o.charAt(t)}function H(t,e){return t&e}function V(t,e){return t|e}function G(t,e){return t^e}function F(t,e){return t&~e}function K(t){if(0==t)return-1;var e=0;return 65535&t||(t>>=16,e+=16),255&t||(t>>=8,e+=8),15&t||(t>>=4,e+=4),3&t||(t>>=2,e+=2),1&t||++e,e}function W(t){for(var e=0;0!=t;)t&=t-1,++e;return e}var s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function Y(t){var e,r,n="";for(e=0;e+3<=t.length;e+=3)r=parseInt(t.substring(e,e+3),16),n+=s.charAt(r>>6)+s.charAt(63&r);for(e+1==t.length?(r=parseInt(t.substring(e,e+1),16),n+=s.charAt(r<<2)):e+2==t.length&&(r=parseInt(t.substring(e,e+2),16),n+=s.charAt(r>>2)+s.charAt((3&r)<<4));(3&n.length)>0;)n+="=";return n}function z(t){var e,r="",n=0,i=0;for(e=0;e<t.length&&"="!=t.charAt(e);++e){var o=s.indexOf(t.charAt(e));o<0||(0==n?(r+=M(o>>2),i=3&o,n=1):1==n?(r+=M(i<<2|o>>4),i=15&o,n=2):2==n?(r+=M(i),r+=M(o>>2),i=3&o,n=3):(r+=M(i<<2|o>>4),r+=M(15&o),n=0))}return 1==n&&(r+=M(i<<2)),r}var a,u,c={decode:function(t){var e;if(void 0===a){var r="0123456789ABCDEF";for(a={},e=0;e<16;++e)a[r.charAt(e)]=e;for(r=r.toLowerCase(),e=10;e<16;++e)a[r.charAt(e)]=e;for(e=0;e<8;++e)a[" \f\n\r\t \u2028\u2029".charAt(e)]=-1}var n=[],i=0,o=0;for(e=0;e<t.length;++e){var s=t.charAt(e);if("="==s)break;if(-1!=(s=a[s])){if(void 0===s)throw new Error("Illegal character at offset "+e);i|=s,++o>=2?(n[n.length]=i,i=0,o=0):i<<=4}}if(o)throw new Error("Hex encoding incomplete: 4 bits missing");return n}},h={decode:function(t){var e;if(void 0===u){for(u=Object.create(null),e=0;e<64;++e)u["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)]=e;for(e=0;e<9;++e)u["= \f\n\r\t \u2028\u2029".charAt(e)]=-1}var r=[],n=0,i=0;for(e=0;e<t.length;++e){var o=t.charAt(e);if("="==o)break;if(-1!=(o=u[o])){if(void 0===o)throw new Error("Illegal character at offset "+e);n|=o,++i>=4?(r[r.length]=n>>16,r[r.length]=n>>8&255,r[r.length]=255&n,n=0,i=0):n<<=6}}switch(i){case 1:throw new Error("Base64 encoding incomplete: at least 2 bits missing");case 2:r[r.length]=n>>10;break;case 3:r[r.length]=n>>16,r[r.length]=n>>8&255}return r},re:/-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,unarmor:function(t){var e=h.re.exec(t);if(e)if(e[1])t=e[1];else{if(!e[2])throw new Error("RegExp out of sync");t=e[2]}return h.decode(t)}},l=1e13;class Z{constructor(t){this.buf=[+t||0]}mulAdd(t,e){var r,n,i=this.buf,o=i.length;for(r=0;r<o;++r)(n=i[r]*t+e)<l?e=0:n-=(e=0|n/l)*l,i[r]=n;e>0&&(i[r]=e)}sub(t){var e,r,n=this.buf,i=n.length;for(e=0;e<i;++e)(r=n[e]-t)<0?(r+=l,t=1):t=0,n[e]=r;for(;0===n[n.length-1];)n.pop()}toString(t){if(10!=(t||10))throw new Error("only base 10 is supported");for(var e=this.buf,r=e[e.length-1].toString(),n=e.length-2;n>=0;--n)r+=(l+e[n]).toString().substring(1);return r}valueOf(){for(var t=this.buf,e=0,r=t.length-1;r>=0;--r)e=e*l+t[r];return e}simplify(){var t=this.buf;return 1==t.length?t[0]:this}}var d,f=/^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/,p=/^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;function Q(t,e){return t.length>e&&(t=t.substring(0,e)+"…"),t}class J{constructor(t,e){this.hexDigits="0123456789ABCDEF",t instanceof J?(this.enc=t.enc,this.pos=t.pos):(this.enc=t,this.pos=e)}get(t){if(void 0===t&&(t=this.pos++),t>=this.enc.length)throw new Error("Requesting byte offset "+t+" on a stream of length "+this.enc.length);return"string"==typeof this.enc?this.enc.charCodeAt(t):this.enc[t]}hexByte(t){return this.hexDigits.charAt(t>>4&15)+this.hexDigits.charAt(15&t)}hexDump(t,e,r){for(var n="",i=t;i<e;++i)if(n+=this.hexByte(this.get(i)),!0!==r)switch(15&i){case 7:n+=" ";break;case 15:n+="\n";break;default:n+=" "}return n}isASCII(t,e){for(var r=t;r<e;++r){var n=this.get(r);if(n<32||n>176)return!1}return!0}parseStringISO(t,e){for(var r="",n=t;n<e;++n)r+=String.fromCharCode(this.get(n));return r}parseStringUTF(t,e){for(var r="",n=t;n<e;){var i=this.get(n++);r+=i<128?String.fromCharCode(i):i>191&&i<224?String.fromCharCode((31&i)<<6|63&this.get(n++)):String.fromCharCode((15&i)<<12|(63&this.get(n++))<<6|63&this.get(n++))}return r}parseStringBMP(t,e){for(var r,n,i="",o=t;o<e;)r=this.get(o++),n=this.get(o++),i+=String.fromCharCode(r<<8|n);return i}parseTime(t,e,r){var n=this.parseStringISO(t,e),i=(r?f:p).exec(n);return i?(r&&(i[1]=+i[1],i[1]+=+i[1]<70?2e3:1900),n=i[1]+"-"+i[2]+"-"+i[3]+" "+i[4],i[5]&&(n+=":"+i[5],i[6]&&(n+=":"+i[6],i[7]&&(n+="."+i[7]))),i[8]&&(n+=" UTC","Z"!=i[8]&&(n+=i[8],i[9]&&(n+=":"+i[9]))),n):"Unrecognized time: "+n}parseInteger(t,e){for(var r,n=this.get(t),i=n>127,o=i?255:0,s="";n==o&&++t<e;)n=this.get(t);if(0==(r=e-t))return i?-1:0;if(r>4){for(s=n,r<<=3;!(128&(+s^o));)s=+s<<1,--r;s="("+r+" bit)\n"}i&&(n-=256);for(var a=new Z(n),u=t+1;u<e;++u)a.mulAdd(256,this.get(u));return s+a.toString()}parseBitString(t,e,r){for(var n=this.get(t),i="("+((e-t-1<<3)-n)+" bit)\n",o="",s=t+1;s<e;++s){for(var a=this.get(s),u=s==e-1?n:0,c=7;c>=u;--c)o+=a>>c&1?"1":"0";if(o.length>r)return i+Q(o,r)}return i+o}parseOctetString(t,e,r){if(this.isASCII(t,e))return Q(this.parseStringISO(t,e),r);var n=e-t,i="("+n+" byte)\n";n>(r/=2)&&(e=t+r);for(var o=t;o<e;++o)i+=this.hexByte(this.get(o));return n>r&&(i+="…"),i}parseOID(t,e,r){for(var n="",i=new Z,o=0,s=t;s<e;++s){var a=this.get(s);if(i.mulAdd(128,127&a),o+=7,!(128&a)){if(""===n)if((i=i.simplify())instanceof Z)i.sub(80),n="2."+i.toString();else{var u=i<80?i<40?0:1:2;n=u+"."+(i-40*u)}else n+="."+i.toString();if(n.length>r)return Q(n,r);i=new Z,o=0}}return o>0&&(n+=".incomplete"),n}}class X{constructor(t,e,r,n,i){if(!(n instanceof $))throw new Error("Invalid tag value.");this.stream=t,this.header=e,this.length=r,this.tag=n,this.sub=i}typeName(){switch(this.tag.tagClass){case 0:switch(this.tag.tagNumber){case 0:return"EOC";case 1:return"BOOLEAN";case 2:return"INTEGER";case 3:return"BIT_STRING";case 4:return"OCTET_STRING";case 5:return"NULL";case 6:return"OBJECT_IDENTIFIER";case 7:return"ObjectDescriptor";case 8:return"EXTERNAL";case 9:return"REAL";case 10:return"ENUMERATED";case 11:return"EMBEDDED_PDV";case 12:return"UTF8String";case 16:return"SEQUENCE";case 17:return"SET";case 18:return"NumericString";case 19:return"PrintableString";case 20:return"TeletexString";case 21:return"VideotexString";case 22:return"IA5String";case 23:return"UTCTime";case 24:return"GeneralizedTime";case 25:return"GraphicString";case 26:return"VisibleString";case 27:return"GeneralString";case 28:return"UniversalString";case 30:return"BMPString"}return"Universal_"+this.tag.tagNumber.toString();case 1:return"Application_"+this.tag.tagNumber.toString();case 2:return"["+this.tag.tagNumber.toString()+"]";case 3:return"Private_"+this.tag.tagNumber.toString()}}content(t){if(void 0===this.tag)return null;void 0===t&&(t=1/0);var e=this.posContent(),r=Math.abs(this.length);if(!this.tag.isUniversal())return null!==this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(e,e+r,t);switch(this.tag.tagNumber){case 1:return 0===this.stream.get(e)?"false":"true";case 2:return this.stream.parseInteger(e,e+r);case 3:return this.sub?"("+this.sub.length+" elem)":this.stream.parseBitString(e,e+r,t);case 4:return this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(e,e+r,t);case 6:return this.stream.parseOID(e,e+r,t);case 16:case 17:return null!==this.sub?"("+this.sub.length+" elem)":"(no elem)";case 12:return Q(this.stream.parseStringUTF(e,e+r),t);case 18:case 19:case 20:case 21:case 22:case 26:return Q(this.stream.parseStringISO(e,e+r),t);case 30:return Q(this.stream.parseStringBMP(e,e+r),t);case 23:case 24:return this.stream.parseTime(e,e+r,23==this.tag.tagNumber)}return null}toString(){return this.typeName()+"@"+this.stream.pos+"[header:"+this.header+",length:"+this.length+",sub:"+(null===this.sub?"null":this.sub.length)+"]"}toPrettyString(t){void 0===t&&(t="");var e=t+this.typeName()+" @"+this.stream.pos;if(this.length>=0&&(e+="+"),e+=this.length,this.tag.tagConstructed?e+=" (constructed)":!this.tag.isUniversal()||3!=this.tag.tagNumber&&4!=this.tag.tagNumber||null===this.sub||(e+=" (encapsulates)"),e+="\n",null!==this.sub){t+=" ";for(var r=0,n=this.sub.length;r<n;++r)e+=this.sub[r].toPrettyString(t)}return e}posStart(){return this.stream.pos}posContent(){return this.stream.pos+this.header}posEnd(){return this.stream.pos+this.header+Math.abs(this.length)}toHexString(){return this.stream.hexDump(this.posStart(),this.posEnd(),!0)}static decodeLength(t){var e=t.get(),r=127&e;if(r==e)return r;if(r>6)throw new Error("Length over 48 bits not supported at position "+(t.pos-1));if(0===r)return null;e=0;for(var n=0;n<r;++n)e=256*e+t.get();return e}getHexStringValue(){var t=this.toHexString(),e=2*this.header,r=2*this.length;return t.substr(e,r)}static decode(t){var e;e=t instanceof J?t:new J(t,0);var r=new J(e),n=new $(e),i=X.decodeLength(e),o=e.pos,s=o-r.pos,a=null,u=function(){var t=[];if(null!==i){for(var r=o+i;e.pos<r;)t[t.length]=X.decode(e);if(e.pos!=r)throw new Error("Content size is not correct for container starting at offset "+o)}else try{for(;;){var n=X.decode(e);if(n.tag.isEOC())break;t[t.length]=n}i=o-e.pos}catch(t){throw new Error("Exception while decoding undefined length content: "+t)}return t};if(n.tagConstructed)a=u();else if(n.isUniversal()&&(3==n.tagNumber||4==n.tagNumber))try{if(3==n.tagNumber&&0!=e.get())throw new Error("BIT STRINGs with unused bits cannot encapsulate.");a=u();for(var c=0;c<a.length;++c)if(a[c].tag.isEOC())throw new Error("EOC is not supposed to be actual content.")}catch(t){a=null}if(null===a){if(null===i)throw new Error("We can't skip over an invalid tag with undefined length at offset "+o);e.pos=o+Math.abs(i)}return new X(r,s,i,n,a)}}class ${constructor(t){var e=t.get();if(this.tagClass=e>>6,this.tagConstructed=!!(32&e),this.tagNumber=31&e,31==this.tagNumber){var r=new Z;do{e=t.get(),r.mulAdd(128,127&e)}while(128&e);this.tagNumber=r.simplify()}}isUniversal(){return 0===this.tagClass}isEOC(){return 0===this.tagClass&&0===this.tagNumber}}var v=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],g=(1<<26)/v[v.length-1];class tt{constructor(t,e,r){null!=t&&("number"==typeof t?this.fromNumber(t,e,r):null==e&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,e))}toString(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var r,n=(1<<e)-1,i=!1,o="",s=this.t,a=this.DB-s*this.DB%e;if(s-- >0)for(a<this.DB&&(r=this[s]>>a)>0&&(i=!0,o=M(r));s>=0;)a<e?(r=(this[s]&(1<<a)-1)<<e-a,r|=this[--s]>>(a+=this.DB-e)):(r=this[s]>>(a-=e)&n,a<=0&&(a+=this.DB,--s)),r>0&&(i=!0),i&&(o+=M(r));return i?o:"0"}negate(){var t=et();return tt.ZERO.subTo(this,t),t}abs(){return this.s<0?this.negate():this}compareTo(t){var e=this.s-t.s;if(0!=e)return e;var r=this.t;if(0!=(e=r-t.t))return this.s<0?-e:e;for(;--r>=0;)if(0!=(e=this[r]-t[r]))return e;return 0}bitLength(){return this.t<=0?0:this.DB*(this.t-1)+ut(this[this.t-1]^this.s&this.DM)}mod(t){var e=et();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(tt.ZERO)>0&&t.subTo(e,e),e}modPowInt(t,e){var r;return r=t<256||e.isEven()?new m(e):new _(e),this.exp(t,r)}clone(){var t=et();return this.copyTo(t),t}intValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}byteValue(){return 0==this.t?this.s:this[0]<<24>>24}shortValue(){return 0==this.t?this.s:this[0]<<16>>16}signum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}toByteArray(){var t=this.t,e=[];e[0]=this.s;var r,n=this.DB-t*this.DB%8,i=0;if(t-- >0)for(n<this.DB&&(r=this[t]>>n)!=(this.s&this.DM)>>n&&(e[i++]=r|this.s<<this.DB-n);t>=0;)n<8?(r=(this[t]&(1<<n)-1)<<8-n,r|=this[--t]>>(n+=this.DB-8)):(r=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),128&r&&(r|=-256),0==i&&(128&this.s)!=(128&r)&&++i,(i>0||r!=this.s)&&(e[i++]=r);return e}equals(t){return 0==this.compareTo(t)}min(t){return this.compareTo(t)<0?this:t}max(t){return this.compareTo(t)>0?this:t}and(t){var e=et();return this.bitwiseTo(t,H,e),e}or(t){var e=et();return this.bitwiseTo(t,V,e),e}xor(t){var e=et();return this.bitwiseTo(t,G,e),e}andNot(t){var e=et();return this.bitwiseTo(t,F,e),e}not(){for(var t=et(),e=0;e<this.t;++e)t[e]=this.DM&~this[e];return t.t=this.t,t.s=~this.s,t}shiftLeft(t){var e=et();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e}shiftRight(t){var e=et();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e}getLowestSetBit(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+K(this[t]);return this.s<0?this.t*this.DB:-1}bitCount(){for(var t=0,e=this.s&this.DM,r=0;r<this.t;++r)t+=W(this[r]^e);return t}testBit(t){var e=Math.floor(t/this.DB);return e>=this.t?0!=this.s:!!(this[e]&1<<t%this.DB)}setBit(t){return this.changeBit(t,V)}clearBit(t){return this.changeBit(t,F)}flipBit(t){return this.changeBit(t,G)}add(t){var e=et();return this.addTo(t,e),e}subtract(t){var e=et();return this.subTo(t,e),e}multiply(t){var e=et();return this.multiplyTo(t,e),e}divide(t){var e=et();return this.divRemTo(t,e,null),e}remainder(t){var e=et();return this.divRemTo(t,null,e),e}divideAndRemainder(t){var e=et(),r=et();return this.divRemTo(t,e,r),[e,r]}modPow(t,e){var r,n,i=t.bitLength(),o=at(1);if(i<=0)return o;r=i<18?1:i<48?3:i<144?4:i<768?5:6,n=i<8?new m(e):e.isEven()?new b(e):new _(e);var s=[],a=3,u=r-1,c=(1<<r)-1;if(s[1]=n.convert(this),r>1){var h=et();for(n.sqrTo(s[1],h);a<=c;)s[a]=et(),n.mulTo(h,s[a-2],s[a]),a+=2}var l,d,f=t.t-1,p=!0,v=et();for(i=ut(t[f])-1;f>=0;){for(i>=u?l=t[f]>>i-u&c:(l=(t[f]&(1<<i+1)-1)<<u-i,f>0&&(l|=t[f-1]>>this.DB+i-u)),a=r;!(1&l);)l>>=1,--a;if((i-=a)<0&&(i+=this.DB,--f),p)s[l].copyTo(o),p=!1;else{for(;a>1;)n.sqrTo(o,v),n.sqrTo(v,o),a-=2;a>0?n.sqrTo(o,v):(d=o,o=v,v=d),n.mulTo(v,s[l],o)}for(;f>=0&&!(t[f]&1<<i);)n.sqrTo(o,v),d=o,o=v,v=d,--i<0&&(i=this.DB-1,--f)}return n.revert(o)}modInverse(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return tt.ZERO;for(var r=t.clone(),n=this.clone(),i=at(1),o=at(0),s=at(0),a=at(1);0!=r.signum();){for(;r.isEven();)r.rShiftTo(1,r),e?(i.isEven()&&o.isEven()||(i.addTo(this,i),o.subTo(t,o)),i.rShiftTo(1,i)):o.isEven()||o.subTo(t,o),o.rShiftTo(1,o);for(;n.isEven();)n.rShiftTo(1,n),e?(s.isEven()&&a.isEven()||(s.addTo(this,s),a.subTo(t,a)),s.rShiftTo(1,s)):a.isEven()||a.subTo(t,a),a.rShiftTo(1,a);r.compareTo(n)>=0?(r.subTo(n,r),e&&i.subTo(s,i),o.subTo(a,o)):(n.subTo(r,n),e&&s.subTo(i,s),a.subTo(o,a))}return 0!=n.compareTo(tt.ONE)?tt.ZERO:a.compareTo(t)>=0?a.subtract(t):a.signum()<0?(a.addTo(t,a),a.signum()<0?a.add(t):a):a}pow(t){return this.exp(t,new y)}gcd(t){var e=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(e.compareTo(r)<0){var n=e;e=r,r=n}var i=e.getLowestSetBit(),o=r.getLowestSetBit();if(o<0)return e;for(i<o&&(o=i),o>0&&(e.rShiftTo(o,e),r.rShiftTo(o,r));e.signum()>0;)(i=e.getLowestSetBit())>0&&e.rShiftTo(i,e),(i=r.getLowestSetBit())>0&&r.rShiftTo(i,r),e.compareTo(r)>=0?(e.subTo(r,e),e.rShiftTo(1,e)):(r.subTo(e,r),r.rShiftTo(1,r));return o>0&&r.lShiftTo(o,r),r}isProbablePrime(t){var e,r=this.abs();if(1==r.t&&r[0]<=v[v.length-1]){for(e=0;e<v.length;++e)if(r[0]==v[e])return!0;return!1}if(r.isEven())return!1;for(e=1;e<v.length;){for(var n=v[e],i=e+1;i<v.length&&n<g;)n*=v[i++];for(n=r.modInt(n);e<i;)if(n%v[e++]==0)return!1}return r.millerRabin(t)}copyTo(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s}fromInt(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0}fromString(t,e){var r;if(16==e)r=4;else if(8==e)r=3;else if(256==e)r=8;else if(2==e)r=1;else if(32==e)r=5;else{if(4!=e)return void this.fromRadix(t,e);r=2}this.t=0,this.s=0;for(var n=t.length,i=!1,o=0;--n>=0;){var s=8==r?255&+t[n]:st(t,n);s<0?"-"==t.charAt(n)&&(i=!0):(i=!1,0==o?this[this.t++]=s:o+r>this.DB?(this[this.t-1]|=(s&(1<<this.DB-o)-1)<<o,this[this.t++]=s>>this.DB-o):this[this.t-1]|=s<<o,(o+=r)>=this.DB&&(o-=this.DB))}8==r&&128&+t[0]&&(this.s=-1,o>0&&(this[this.t-1]|=(1<<this.DB-o)-1<<o)),this.clamp(),i&&tt.ZERO.subTo(this,this)}clamp(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t}dlShiftTo(t,e){var r;for(r=this.t-1;r>=0;--r)e[r+t]=this[r];for(r=t-1;r>=0;--r)e[r]=0;e.t=this.t+t,e.s=this.s}drShiftTo(t,e){for(var r=t;r<this.t;++r)e[r-t]=this[r];e.t=Math.max(this.t-t,0),e.s=this.s}lShiftTo(t,e){for(var r=t%this.DB,n=this.DB-r,i=(1<<n)-1,o=Math.floor(t/this.DB),s=this.s<<r&this.DM,a=this.t-1;a>=0;--a)e[a+o+1]=this[a]>>n|s,s=(this[a]&i)<<r;for(a=o-1;a>=0;--a)e[a]=0;e[o]=s,e.t=this.t+o+1,e.s=this.s,e.clamp()}rShiftTo(t,e){e.s=this.s;var r=Math.floor(t/this.DB);if(r>=this.t)e.t=0;else{var n=t%this.DB,i=this.DB-n,o=(1<<n)-1;e[0]=this[r]>>n;for(var s=r+1;s<this.t;++s)e[s-r-1]|=(this[s]&o)<<i,e[s-r]=this[s]>>n;n>0&&(e[this.t-r-1]|=(this.s&o)<<i),e.t=this.t-r,e.clamp()}}subTo(t,e){for(var r=0,n=0,i=Math.min(t.t,this.t);r<i;)n+=this[r]-t[r],e[r++]=n&this.DM,n>>=this.DB;if(t.t<this.t){for(n-=t.s;r<this.t;)n+=this[r],e[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<t.t;)n-=t[r],e[r++]=n&this.DM,n>>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[r++]=this.DV+n:n>0&&(e[r++]=n),e.t=r,e.clamp()}multiplyTo(t,e){var r=this.abs(),n=t.abs(),i=r.t;for(e.t=i+n.t;--i>=0;)e[i]=0;for(i=0;i<n.t;++i)e[i+r.t]=r.am(0,n[i],e,i,0,r.t);e.s=0,e.clamp(),this.s!=t.s&&tt.ZERO.subTo(e,e)}squareTo(t){for(var e=this.abs(),r=t.t=2*e.t;--r>=0;)t[r]=0;for(r=0;r<e.t-1;++r){var n=e.am(r,e[r],t,2*r,0,1);(t[r+e.t]+=e.am(r+1,2*e[r],t,2*r+1,n,e.t-r-1))>=e.DV&&(t[r+e.t]-=e.DV,t[r+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(r,e[r],t,2*r,0,1)),t.s=0,t.clamp()}divRemTo(t,e,r){var n=t.abs();if(!(n.t<=0)){var i=this.abs();if(i.t<n.t)return null!=e&&e.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=et());var o=et(),s=this.s,a=t.s,u=this.DB-ut(n[n.t-1]);u>0?(n.lShiftTo(u,o),i.lShiftTo(u,r)):(n.copyTo(o),i.copyTo(r));var c=o.t,h=o[c-1];if(0!=h){var l=h*(1<<this.F1)+(c>1?o[c-2]>>this.F2:0),d=this.FV/l,f=(1<<this.F1)/l,p=1<<this.F2,v=r.t,g=v-c,y=null==e?et():e;for(o.dlShiftTo(g,y),r.compareTo(y)>=0&&(r[r.t++]=1,r.subTo(y,r)),tt.ONE.dlShiftTo(c,y),y.subTo(o,o);o.t<c;)o[o.t++]=0;for(;--g>=0;){var m=r[--v]==h?this.DM:Math.floor(r[v]*d+(r[v-1]+p)*f);if((r[v]+=o.am(0,m,r,g,0,c))<m)for(o.dlShiftTo(g,y),r.subTo(y,r);r[v]<--m;)r.subTo(y,r)}null!=e&&(r.drShiftTo(c,e),s!=a&&tt.ZERO.subTo(e,e)),r.t=c,r.clamp(),u>0&&r.rShiftTo(u,r),s<0&&tt.ZERO.subTo(r,r)}}}invDigit(){if(this.t<1)return 0;var t=this[0];if(!(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e}isEven(){return 0==(this.t>0?1&this[0]:this.s)}exp(t,e){if(t>4294967295||t<1)return tt.ONE;var r=et(),n=et(),i=e.convert(this),o=ut(t)-1;for(i.copyTo(r);--o>=0;)if(e.sqrTo(r,n),(t&1<<o)>0)e.mulTo(n,i,r);else{var s=r;r=n,n=s}return e.revert(r)}chunkSize(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}toRadix(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),r=Math.pow(t,e),n=at(r),i=et(),o=et(),s="";for(this.divRemTo(n,i,o);i.signum()>0;)s=(r+o.intValue()).toString(t).substr(1)+s,i.divRemTo(n,i,o);return o.intValue().toString(t)+s}fromRadix(t,e){this.fromInt(0),null==e&&(e=10);for(var r=this.chunkSize(e),n=Math.pow(e,r),i=!1,o=0,s=0,a=0;a<t.length;++a){var u=st(t,a);u<0?"-"==t.charAt(a)&&0==this.signum()&&(i=!0):(s=e*s+u,++o>=r&&(this.dMultiply(n),this.dAddOffset(s,0),o=0,s=0))}o>0&&(this.dMultiply(Math.pow(e,o)),this.dAddOffset(s,0)),i&&tt.ZERO.subTo(this,this)}fromNumber(t,e,r){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,r),this.testBit(t-1)||this.bitwiseTo(tt.ONE.shiftLeft(t-1),V,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(tt.ONE.shiftLeft(t-1),this);else{var n=[],i=7&t;n.length=1+(t>>3),e.nextBytes(n),i>0?n[0]&=(1<<i)-1:n[0]=0,this.fromString(n,256)}}bitwiseTo(t,e,r){var n,i,o=Math.min(t.t,this.t);for(n=0;n<o;++n)r[n]=e(this[n],t[n]);if(t.t<this.t){for(i=t.s&this.DM,n=o;n<this.t;++n)r[n]=e(this[n],i);r.t=this.t}else{for(i=this.s&this.DM,n=o;n<t.t;++n)r[n]=e(i,t[n]);r.t=t.t}r.s=e(this.s,t.s),r.clamp()}changeBit(t,e){var r=tt.ONE.shiftLeft(t);return this.bitwiseTo(r,e,r),r}addTo(t,e){for(var r=0,n=0,i=Math.min(t.t,this.t);r<i;)n+=this[r]+t[r],e[r++]=n&this.DM,n>>=this.DB;if(t.t<this.t){for(n+=t.s;r<this.t;)n+=this[r],e[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<t.t;)n+=t[r],e[r++]=n&this.DM,n>>=this.DB;n+=t.s}e.s=n<0?-1:0,n>0?e[r++]=n:n<-1&&(e[r++]=this.DV+n),e.t=r,e.clamp()}dMultiply(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}dAddOffset(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}}multiplyLowerTo(t,e,r){var n=Math.min(this.t+t.t,e);for(r.s=0,r.t=n;n>0;)r[--n]=0;for(var i=r.t-this.t;n<i;++n)r[n+this.t]=this.am(0,t[n],r,n,0,this.t);for(i=Math.min(t.t,e);n<i;++n)this.am(0,t[n],r,n,0,e-n);r.clamp()}multiplyUpperTo(t,e,r){--e;var n=r.t=this.t+t.t-e;for(r.s=0;--n>=0;)r[n]=0;for(n=Math.max(e-this.t,0);n<t.t;++n)r[this.t+n-e]=this.am(e-n,t[n],r,0,0,this.t+n-e);r.clamp(),r.drShiftTo(1,r)}modInt(t){if(t<=0)return 0;var e=this.DV%t,r=this.s<0?t-1:0;if(this.t>0)if(0==e)r=this[0]%t;else for(var n=this.t-1;n>=0;--n)r=(e*r+this[n])%t;return r}millerRabin(t){var e=this.subtract(tt.ONE),r=e.getLowestSetBit();if(r<=0)return!1;var n=e.shiftRight(r);(t=t+1>>1)>v.length&&(t=v.length);for(var i=et(),o=0;o<t;++o){i.fromInt(v[Math.floor(Math.random()*v.length)]);var s=i.modPow(n,this);if(0!=s.compareTo(tt.ONE)&&0!=s.compareTo(e)){for(var a=1;a++<r&&0!=s.compareTo(e);)if(0==(s=s.modPowInt(2,this)).compareTo(tt.ONE))return!1;if(0!=s.compareTo(e))return!1}}return!0}square(){var t=et();return this.squareTo(t),t}gcda(t,e){var r=this.s<0?this.negate():this.clone(),n=t.s<0?t.negate():t.clone();if(r.compareTo(n)<0){var i=r;r=n,n=i}var o=r.getLowestSetBit(),s=n.getLowestSetBit();if(s<0)e(r);else{o<s&&(s=o),s>0&&(r.rShiftTo(s,r),n.rShiftTo(s,n));var a=()=>{(o=r.getLowestSetBit())>0&&r.rShiftTo(o,r),(o=n.getLowestSetBit())>0&&n.rShiftTo(o,n),r.compareTo(n)>=0?(r.subTo(n,r),r.rShiftTo(1,r)):(n.subTo(r,n),n.rShiftTo(1,n)),r.signum()>0?setTimeout(a,0):(s>0&&n.lShiftTo(s,n),setTimeout((function(){e(n)}),0))};setTimeout(a,10)}}fromNumberAsync(t,e,r,n){if("number"==typeof e)if(t<2)this.fromInt(1);else{this.fromNumber(t,r),this.testBit(t-1)||this.bitwiseTo(tt.ONE.shiftLeft(t-1),V,this),this.isEven()&&this.dAddOffset(1,0);var i=this,o=function(){i.dAddOffset(2,0),i.bitLength()>t&&i.subTo(tt.ONE.shiftLeft(t-1),i),i.isProbablePrime(e)?setTimeout((function(){n()}),0):setTimeout(o,0)};setTimeout(o,0)}else{var s=[],a=7&t;s.length=1+(t>>3),e.nextBytes(s),a>0?s[0]&=(1<<a)-1:s[0]=0,this.fromString(s,256)}}}var y=function(){function t(){}return t.prototype.convert=function(t){return t},t.prototype.revert=function(t){return t},t.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r)},t.prototype.sqrTo=function(t,e){t.squareTo(e)},t}(),m=function(){function t(t){this.m=t}return t.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},t.prototype.revert=function(t){return t},t.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},t.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r),this.reduce(r)},t.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},t}(),_=function(){function t(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}return t.prototype.convert=function(t){var e=et();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(tt.ZERO)>0&&this.m.subTo(e,e),e},t.prototype.revert=function(t){var e=et();return t.copyTo(e),this.reduce(e),e},t.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var r=32767&t[e],n=r*this.mpl+((r*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[r=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[r]>=t.DV;)t[r]-=t.DV,t[++r]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},t.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r),this.reduce(r)},t.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},t}(),b=function(){function t(t){this.m=t,this.r2=et(),this.q3=et(),tt.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t)}return t.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=et();return t.copyTo(e),this.reduce(e),e},t.prototype.revert=function(t){return t},t.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},t.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r),this.reduce(r)},t.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},t}();function et(){return new tt(null)}function rt(t,e){return new tt(t,e)}function nt(t,e,r,n,i,o){for(;--o>=0;){var s=e*this[t++]+r[n]+i;i=Math.floor(s/67108864),r[n++]=67108863&s}return i}function it(t,e,r,n,i,o){for(var s=32767&e,a=e>>15;--o>=0;){var u=32767&this[t],c=this[t++]>>15,h=a*u+c*s;i=((u=s*u+((32767&h)<<15)+r[n]+(1073741823&i))>>>30)+(h>>>15)+a*c+(i>>>30),r[n++]=1073741823&u}return i}function ot(t,e,r,n,i,o){for(var s=16383&e,a=e>>14;--o>=0;){var u=16383&this[t],c=this[t++]>>14,h=a*u+c*s;i=((u=s*u+((16383&h)<<14)+r[n]+i)>>28)+(h>>14)+a*c,r[n++]=268435455&u}return i}void 0!==i&&"Microsoft Internet Explorer"==(null==i?void 0:i.appName)?(tt.prototype.am=it,d=30):"Netscape"!=(null==i?void 0:i.appName)?(tt.prototype.am=nt,d=26):(tt.prototype.am=ot,d=28),tt.prototype.DB=d,tt.prototype.DM=(1<<d)-1,tt.prototype.DV=1<<d,tt.prototype.FV=Math.pow(2,52),tt.prototype.F1=52-d,tt.prototype.F2=2*d-52;var T,E,S=[];for(T="0".charCodeAt(0),E=0;E<=9;++E)S[T++]=E;for(T="a".charCodeAt(0),E=10;E<36;++E)S[T++]=E;for(T="A".charCodeAt(0),E=10;E<36;++E)S[T++]=E;function st(t,e){var r=S[t.charCodeAt(e)];return null==r?-1:r}function at(t){var e=et();return e.fromInt(t),e}function ut(t){var e,r=1;return 0!=(e=t>>>16)&&(t=e,r+=16),0!=(e=t>>8)&&(t=e,r+=8),0!=(e=t>>4)&&(t=e,r+=4),0!=(e=t>>2)&&(t=e,r+=2),0!=(e=t>>1)&&(t=e,r+=1),r}tt.ZERO=at(0),tt.ONE=at(1);class ct{constructor(){this.i=0,this.j=0,this.S=[]}init(t){var e,r,n;for(e=0;e<256;++e)this.S[e]=e;for(r=0,e=0;e<256;++e)r=r+this.S[e]+t[e%t.length]&255,n=this.S[e],this.S[e]=this.S[r],this.S[r]=n;this.i=0,this.j=0}next(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]}}var w,I,O=null;if(null==O){var R,C,A,P;O=[],I=0;var U=void 0;if(null!==(R=window)&&void 0!==R&&R.crypto&&null!==(C=window)&&void 0!==C&&C.crypto.getRandomValues){var D,N=new Uint32Array(256);for(null===(D=window)||void 0===D||D.crypto.getRandomValues(N),U=0;U<N.length;++U)O[I++]=255&N[U]}var L,x=function(t){var e,r,n;if(this.count=this.count||0,this.count>=256||I>=256){if(null!==(e=window)&&void 0!==e&&e.removeEventListener)null===(n=window)||void 0===n||n.removeEventListener("mousemove",x,!1);else if(null!==(r=window)&&void 0!==r&&r.detachEvent){var i;null===(i=window)||void 0===i||i.detachEvent("onmousemove",x)}}else try{var o=t.x+t.y;O[I++]=255&o,this.count+=1}catch(t){}};if(null!==(A=window)&&void 0!==A&&A.addEventListener)null===(L=window)||void 0===L||L.addEventListener("mousemove",x,!1);else if(null!==(P=window)&&void 0!==P&&P.attachEvent){var k;null===(k=window)||void 0===k||k.attachEvent("onmousemove",x)}}function ht(){if(null==w){for(w=new ct;I<256;){var t=Math.floor(65536*Math.random());O[I++]=255&t}for(w.init(O),I=0;I<O.length;++I)O[I]=0;I=0}return w.next()}class lt{constructor(){}nextBytes(t){for(var e=0;e<t.length;++e)t[e]=ht()}}function dt(t,e){if(e<t.length+11)return console.error("Message too long for RSA"),null;for(var r=[],n=t.length-1;n>=0&&e>0;){var i=t.charCodeAt(n--);i<128?r[--e]=i:i>127&&i<2048?(r[--e]=63&i|128,r[--e]=i>>6|192):(r[--e]=63&i|128,r[--e]=i>>6&63|128,r[--e]=i>>12|224)}r[--e]=0;for(var o=new lt,s=[];e>2;){for(s[0]=0;0==s[0];)o.nextBytes(s);r[--e]=s[0]}return r[--e]=2,r[--e]=0,new tt(r)}class ft{constructor(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}doPublic(t){return t.modPowInt(this.e,this.n)}doPrivate(t){if(null==this.p||null==this.q)return t.modPow(this.d,this.n);for(var e=t.mod(this.p).modPow(this.dmp1,this.p),r=t.mod(this.q).modPow(this.dmq1,this.q);e.compareTo(r)<0;)e=e.add(this.p);return e.subtract(r).multiply(this.coeff).mod(this.p).multiply(this.q).add(r)}setPublic(t,e){null!=t&&null!=e&&t.length>0&&e.length>0?(this.n=rt(t,16),this.e=parseInt(e,16)):console.error("Invalid RSA public key")}encrypt(t){var e=dt(t,this.n.bitLength()+7>>3);if(null==e)return null;var r=this.doPublic(e);if(null==r)return null;var n=r.toString(16);return 1&n.length?"0"+n:n}encryptLong(t){var e=this,r=(this.n.bitLength()+7>>3)-11;try{var n="";return t.length>r?(t.match(/.{1,117}/g).forEach((function(t){var r=e.encrypt(t);n+=r})),Y(n)):Y(this.encrypt(t))}catch(t){return!1}}decryptLong(t){var e=this,r=this.n.bitLength()+7>>3;t=z(t);try{if(t.length>r){var n="";return t.match(/.{1,256}/g).forEach((function(t){var r=e.decrypt(t);n+=r})),n}return this.decrypt(t)}catch(t){return!1}}setPrivate(t,e,r){null!=t&&null!=e&&t.length>0&&e.length>0?(this.n=rt(t,16),this.e=parseInt(e,16),this.d=rt(r,16)):console.error("Invalid RSA private key")}setPrivateEx(t,e,r,n,i,o,s,a){null!=t&&null!=e&&t.length>0&&e.length>0?(this.n=rt(t,16),this.e=parseInt(e,16),this.d=rt(r,16),this.p=rt(n,16),this.q=rt(i,16),this.dmp1=rt(o,16),this.dmq1=rt(s,16),this.coeff=rt(a,16)):console.error("Invalid RSA private key")}generate(t,e){var r=new lt,n=t>>1;this.e=parseInt(e,16);for(var i=new tt(e,16);;){for(;this.p=new tt(t-n,1,r),0!=this.p.subtract(tt.ONE).gcd(i).compareTo(tt.ONE)||!this.p.isProbablePrime(10););for(;this.q=new tt(n,1,r),0!=this.q.subtract(tt.ONE).gcd(i).compareTo(tt.ONE)||!this.q.isProbablePrime(10););if(this.p.compareTo(this.q)<=0){var o=this.p;this.p=this.q,this.q=o}var s=this.p.subtract(tt.ONE),a=this.q.subtract(tt.ONE),u=s.multiply(a);if(0==u.gcd(i).compareTo(tt.ONE)){this.n=this.p.multiply(this.q),this.d=i.modInverse(u),this.dmp1=this.d.mod(s),this.dmq1=this.d.mod(a),this.coeff=this.q.modInverse(this.p);break}}}decrypt(t){var e=rt(t,16),r=this.doPrivate(e);return null==r?null:pt(r,this.n.bitLength()+7>>3)}generateAsync(t,e,r){var n=new lt,i=t>>1;this.e=parseInt(e,16);var o=new tt(e,16),s=this,a=()=>{var e=()=>{if(s.p.compareTo(s.q)<=0){var t=s.p;s.p=s.q,s.q=t}var e=s.p.subtract(tt.ONE),n=s.q.subtract(tt.ONE),i=e.multiply(n);0==i.gcd(o).compareTo(tt.ONE)?(s.n=s.p.multiply(s.q),s.d=o.modInverse(i),s.dmp1=s.d.mod(e),s.dmq1=s.d.mod(n),s.coeff=s.q.modInverse(s.p),setTimeout((function(){r()}),0)):setTimeout(a,0)},u=()=>{s.q=et(),s.q.fromNumberAsync(i,1,n,(function(){s.q.subtract(tt.ONE).gcda(o,(function(t){0==t.compareTo(tt.ONE)&&s.q.isProbablePrime(10)?setTimeout(e,0):setTimeout(u,0)}))}))},c=()=>{s.p=et(),s.p.fromNumberAsync(t-i,1,n,(function(){s.p.subtract(tt.ONE).gcda(o,(function(t){0==t.compareTo(tt.ONE)&&s.p.isProbablePrime(10)?setTimeout(u,0):setTimeout(c,0)}))}))};setTimeout(c,0)};setTimeout(a,0)}}function pt(t,e){for(var r=t.toByteArray(),n=0;n<r.length&&0==r[n];)++n;if(r.length-n!=e-1||2!=r[n])return null;for(++n;0!=r[n];)if(++n>=r.length)return null;for(var i="";++n<r.length;){var o=255&r[n];o<128?i+=String.fromCharCode(o):o>191&&o<224?(i+=String.fromCharCode((31&o)<<6|63&r[n+1]),++n):(i+=String.fromCharCode((15&o)<<12|(63&r[n+1])<<6|63&r[n+2]),n+=2)}return i}class vt extends ft{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";super(),t&&("string"==typeof t?this.parseKey(t):(this.hasPrivateKeyProperty(t)||this.hasPublicKeyProperty(t))&&this.parsePropertiesFrom(t))}parseKey(t){try{var e=0,r=0,n=/^\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\s*)+$/.test(t)?c.decode(t):h.unarmor(t),i=X.decode(n);if(3===i.sub.length&&(i=i.sub[2].sub[0]),9===i.sub.length){e=i.sub[1].getHexStringValue(),this.n=rt(e,16),r=i.sub[2].getHexStringValue(),this.e=parseInt(r,16);var o=i.sub[3].getHexStringValue();this.d=rt(o,16);var s=i.sub[4].getHexStringValue();this.p=rt(s,16);var a=i.sub[5].getHexStringValue();this.q=rt(a,16);var u=i.sub[6].getHexStringValue();this.dmp1=rt(u,16);var l=i.sub[7].getHexStringValue();this.dmq1=rt(l,16);var d=i.sub[8].getHexStringValue();this.coeff=rt(d,16)}else{if(2!==i.sub.length)return!1;var f=i.sub[1].sub[0];e=f.sub[0].getHexStringValue(),this.n=rt(e,16),r=f.sub[1].getHexStringValue(),this.e=parseInt(r,16)}return!0}catch(t){return!1}}hasPublicKeyProperty(t){return(t=t||{}).hasOwnProperty("n")&&t.hasOwnProperty("e")}hasPrivateKeyProperty(t){return(t=t||{}).hasOwnProperty("n")&&t.hasOwnProperty("e")&&t.hasOwnProperty("d")&&t.hasOwnProperty("p")&&t.hasOwnProperty("q")&&t.hasOwnProperty("dmp1")&&t.hasOwnProperty("dmq1")&&t.hasOwnProperty("coeff")}parsePropertiesFrom(t){this.n=t.n,this.e=t.e,t.hasOwnProperty("d")&&(this.d=t.d,this.p=t.p,this.q=t.q,this.dmp1=t.dmp1,this.dmq1=t.dmq1,this.coeff=t.coeff)}}(n=function(t){t=t||{},this.default_key_size=parseInt(t.default_key_size,10)||1024,this.default_public_exponent=t.default_public_exponent||"010001",this.log=t.log||!1,this.key=null}).prototype.setKey=function(t){this.log&&this.key&&console.warn("A key was already set, overriding existing."),this.key=new vt(t)},n.prototype.setPrivateKey=function(t){this.setKey(t)},n.prototype.setPublicKey=function(t){this.setKey(t)},n.prototype.decrypt=function(t){try{return this.getKey().decrypt(z(t))}catch(t){return!1}},n.prototype.encrypt=function(t){try{return Y(this.getKey().encrypt(t))}catch(t){return!1}},n.prototype.encryptLong=function(t){try{for(var e=this.getKey().encryptLong(t)||"",r=this.getKey().decryptLong(e)||"",n=0,i=/null$/g;i.test(r)&&(n++,e=this.getKey().encryptLong(t)||"",r=this.getKey().decryptLong(e)||"",!(n>10)););return e}catch(t){return!1}},n.prototype.getKey=function(t){if(!this.key){if(this.key=new vt,t&&"[object Function]"==={}.toString.call(t))return void this.key.generateAsync(this.default_key_size,this.default_public_exponent,t);this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},n.version="3.1.4"}const q=n;var B=r(655),j=function(){var{publicKey:t="",payload:e={}}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!t)return"";try{var r=(0,B.I)(e),n=new q;return n.setPublicKey(t),n.encryptLong("object"==typeof r?JSON.stringify(r):r)}catch(t){console.error("encrypt error:",t)}return""}},655:(t,e,r)=>{r.d(e,{I:()=>n,y:()=>i});var n=t=>{var e=e=>{for(var r in t)t.hasOwnProperty(r)&&(e[r]=n(t[r]));return e},r=null==t?"NullOrUndefined":Object.prototype.toString.call(t).slice(8,-1);if(["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(r))return t.slice();switch(r){case"Object":return e(Object.create(Object.getPrototypeOf(t)));case"Array":return e([]);case"Date":return new Date(t.valueOf());case"RegExp":return new RegExp(t.source,(t.global?"g":"")+(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.sticky?"y":"")+(t.unicode?"u":""));default:return t}},i=t=>{var e=t.match(/^(?:http(s)?:\/\/[^\/]+)?(\/[^\?#]*)/);return e&&e[2]||""}}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}return r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r(118)})()));
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("cloudbase_oauth",[],e):"object"==typeof exports?exports.cloudbase_oauth=e():t.cloudbase_oauth=e()}("undefined"!=typeof window?window:this,(()=>(()=>{"use strict";var t={118:function(t,e,r){var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(e,r);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,i)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),i=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),i(r(875),e)},875:(t,e,r)=>{r.r(e),r.d(e,{AUTH_API_PREFIX:()=>u,AUTH_STATE_CHANGED_TYPE:()=>d,Auth:()=>jt,AuthError:()=>At,CloudbaseOAuth:()=>Vt,EVENTS:()=>f,LOGIN_STATE_CHANGED_TYPE:()=>h,OAUTH_TYPE:()=>p,authModels:()=>n,weAppJwtDecodeAll:()=>I});var n={};r.r(n);var i,o,s,a,c,u="/auth";!function(t){t.AUTH_SIGN_UP_URL="/v1/signup",t.AUTH_TOKEN_URL="/v1/token",t.AUTH_REVOKE_URL="/v1/revoke",t.WEDA_USER_URL="/v1/plugin/weda/userinfo",t.AUTH_RESET_PASSWORD="/v1/reset",t.AUTH_GET_DEVICE_CODE="/v1/device/code",t.CHECK_USERNAME="/v1/checkUsername",t.CHECK_IF_USER_EXIST="/v1/checkIfUserExist",t.GET_PROVIDER_TYPE="/v1/mgr/provider/providerSubType",t.AUTH_SIGN_IN_URL="/v1/signin",t.AUTH_SIGN_IN_ANONYMOUSLY_URL="/v1/signin/anonymously",t.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v1/signin/with/provider",t.AUTH_SIGN_IN_WITH_WECHAT_URL="/v1/signin/wechat/noauth",t.AUTH_SIGN_IN_CUSTOM="/v1/signin/custom",t.PROVIDER_TOKEN_URL="/v1/provider/token",t.PROVIDER_URI_URL="/v1/provider/uri",t.USER_ME_URL="/v1/user/me",t.AUTH_SIGNOUT_URL="/v1/user/signout",t.USER_QUERY_URL="/v1/user/query",t.USER_PRIFILE_URL="/v1/user/profile",t.USER_BASIC_EDIT_URL="/v1/user/basic/edit",t.USER_TRANS_BY_PROVIDER_URL="/v1/user/trans/by/provider",t.PROVIDER_LIST="/v1/user/provider",t.PROVIDER_BIND_URL="/v1/user/provider/bind",t.PROVIDER_UNBIND_URL="/v1/user/provider",t.CHECK_PWD_URL="/v1/user/sudo",t.SUDO_URL="/v1/user/sudo",t.BIND_CONTACT_URL="/v1/user/contact",t.AUTH_SET_PASSWORD="/v1/user/password",t.AUTHORIZE_DEVICE_URL="/v1/user/device/authorize",t.AUTHORIZE_URL="/v1/user/authorize",t.AUTHORIZE_INFO_URL="/v1/user/authorize/info",t.AUTHORIZED_DEVICES_DELETE_URL="/v1/user/authorized/devices/",t.AUTH_REVOKE_ALL_URL="/v1/user/revoke/all",t.GET_USER_BEHAVIOR_LOG="/v1/user/security/history",t.VERIFICATION_URL="/v1/verification",t.VERIFY_URL="/v1/verification/verify",t.CAPTCHA_DATA_URL="/v1/captcha/data",t.VERIFY_CAPTCHA_DATA_URL="/v1/captcha/data/verify",t.GET_CAPTCHA_URL="/v1/captcha/init",t.GET_MINIPROGRAM_QRCODE="/v1/qrcode/generate",t.GET_MINIPROGRAM_QRCODE_STATUS="/v1/qrcode/get/status"}(i||(i={})),function(t){t.AUTH_SIGN_IN_URL="/v2/signin/username",t.AUTH_TOKEN_URL="/v2/token",t.USER_ME_URL="/v2/user/me",t.VERIFY_URL="/v2/signin/verificationcode",t.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v2/signin/with/provider",t.AUTH_PUBLIC_KEY="/v2/signin/publichkey",t.AUTH_RESET_PASSWORD="/v2/signin/password/update"}(o||(o={})),function(t){t.REGISTER="REGISTER",t.SIGN_IN="SIGN_IN",t.PASSWORD_RESET="PASSWORD_RESET",t.EMAIL_ADDRESS_CHANGE="EMAIL_ADDRESS_CHANGE",t.PHONE_NUMBER_CHANGE="PHONE_NUMBER_CHANGE"}(s||(s={})),(c=a||(a={})).UNREACHABLE="unreachable",c.LOCAL="local",c.CANCELLED="cancelled",c.UNKNOWN="unknown",c.UNAUTHENTICATED="unauthenticated",c.RESOURCE_EXHAUSTED="resource_exhausted",c.FAILED_PRECONDITION="failed_precondition",c.INVALID_ARGUMENT="invalid_argument",c.DEADLINE_EXCEEDED="deadline_exceeded",c.NOT_FOUND="not_found",c.ALREADY_EXISTS="already_exists",c.PERMISSION_DENIED="permission_denied",c.ABORTED="aborted",c.OUT_OF_RANGE="out_of_range",c.UNIMPLEMENTED="unimplemented",c.INTERNAL="internal",c.UNAVAILABLE="unavailable",c.DATA_LOSS="data_loss",c.INVALID_PASSWORD="invalid_password",c.PASSWORD_NOT_SET="password_not_set",c.INVALID_STATUS="invalid_status",c.USER_PENDING="user_pending",c.USER_BLOCKED="user_blocked",c.INVALID_VERIFICATION_CODE="invalid_verification_code",c.TWO_FACTOR_REQUIRED="two_factor_required",c.INVALID_TWO_FACTOR="invalid_two_factor",c.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",c.UNDER_REVIEW="under_review",c.INVALID_REQUEST="invalid_request",c.UNAUTHORIZED_CLIENT="unauthorized_client",c.ACCESS_DENIED="access_denied",c.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",c.INVALID_SCOPE="invalid_scope",c.INVALID_GRANT="invalid_grant",c.SERVER_ERROR="server_error",c.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",c.INTERACTION_REQUIRED="interaction_required",c.LOGIN_REQUIRED="login_required",c.ACCOUNT_SELECTION_REQUIRED="account_selection_required",c.CONSENT_REQUIRED="consent_required",c.INVALID_REQUEST_URI="invalid_request_uri",c.INVALID_REQUEST_OBJECT="invalid_request_object",c.REQUEST_NOT_SUPPORTED="request_not_supported",c.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",c.REGISTRATION_NOT_SUPPORTED="registration_not_supported",c.CAPTCHA_REQUIRED="captcha_required",c.CAPTCHA_INVALID="captcha_invalid";var l,h={SIGN_OUT:"sign_out",SIGN_IN:"sign_in",CREDENTIALS_ERROR:"credentials_error"},d={SIGNED_OUT:"SIGNED_OUT",SIGNED_IN:"SIGNED_IN",INITIAL_SESSION:"INITIAL_SESSION",PASSWORD_RECOVERY:"PASSWORD_RECOVERY",TOKEN_REFRESHED:"TOKEN_REFRESHED",USER_UPDATED:"USER_UPDATED",BIND_IDENTITY:"BIND_IDENTITY"},f={LOGIN_STATE_CHANGED:"loginStateChanged",AUTH_STATE_CHANGED:"authStateChanged"},p={SIGN_IN:"sign_in",BIND_IDENTITY:"bind_identity"};function v(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,(t=>{var e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)}))}!function(t){t.CLIENT_ID="client_id",t.CLIENT_SECRET="client_secret",t.RESPONSE_TYPE="response_type",t.SCOPE="scope",t.STATE="state",t.REDIRECT_URI="redirect_uri",t.ERROR="error",t.ERROR_DESCRIPTION="error_description",t.ERROR_URI="error_uri",t.GRANT_TYPE="grant_type",t.CODE="code",t.ACCESS_TOKEN="access_token",t.TOKEN_TYPE="token_type",t.EXPIRES_IN="expires_in",t.USERNAME="username",t.PASSWORD="password",t.REFRESH_TOKEN="refresh_token"}(l||(l={}));var g=r(655);function y(t,e,r,n,i,o,s){try{var a=t[o](s),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,i)}function m(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){y(o,n,i,s,a,"next",t)}function a(t){y(o,n,i,s,a,"throw",t)}s(void 0)}))}}var _=new Map;class b{constructor(t){this.clientId=(null==t?void 0:t.clientId)||"",_=_||new Map}run(t,e){var r=this;return m((function*(){t="".concat(r.clientId,"_").concat(t);var n=_.get(t);return n||(n=new Promise(((n,i)=>{m((function*(){try{yield r.runIdlePromise();var o=e();n(yield o)}catch(t){i(t)}finally{_.delete(t)}}))()})),_.set(t,n)),n}))()}runIdlePromise(){return Promise.resolve()}}var E="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",T=/^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/,S=function(t){if(t=String(t).replace(/[\t\n\f\r ]+/g,""),!T.test(t))throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");var e;t+="==".slice(2-(3&t.length));for(var r,n,i="",o=0;o<t.length;)e=E.indexOf(t.charAt(o++))<<18|E.indexOf(t.charAt(o++))<<12|(r=E.indexOf(t.charAt(o++)))<<6|(n=E.indexOf(t.charAt(o++))),i+=64===r?String.fromCharCode(e>>16&255):64===n?String.fromCharCode(e>>16&255,e>>8&255):String.fromCharCode(e>>16&255,e>>8&255,255&e);return i};function I(t){if("string"!=typeof t)throw new Error("Invalid token specified");try{var e=t.split(".").map(((t,e)=>2===e?t:JSON.parse(function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("Illegal base64url string!")}try{return function(t){return decodeURIComponent(S(t).replace(/(.)/g,(t=>{var e=t.charCodeAt(0).toString(16).toUpperCase();return e.length<2&&(e="0".concat(e)),"%".concat(e)})))}(e)}catch(t){return S(e)}}(t))));return{claims:e[1],header:e[0],signature:e[2]}}catch(t){throw new Error("Invalid token specified: ".concat(t)?t.message:0)}}function w(){if("undefined"==typeof globalThis)return!1;var{wx:t}=globalThis;if(void 0===t)return!1;if(void 0===globalThis.Page)return!1;if(!t.getDeviceInfo)return!1;if(!t.getStorageSync)return!1;if(!t.setStorageSync)return!1;if(!t.connectSocket)return!1;if(!t.request)return!1;try{if(!t.getDeviceInfo())return!1;if("qq"===t.getDeviceInfo().platform)return!1}catch(t){return!1}return!0}var O=!1;function C(){O=O||void 0!==typeof window&&"miniprogram"===window.__wxjs_environment}try{w()||(O=O||!!navigator.userAgent.match(/miniprogram/i)||"miniprogram"===window.__wxjs_environment,window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?C():"undefined"!=typeof document&&document.addEventListener("WeixinJSBridgeReady",C,!1))}catch(Z){}var R="@cloudbase/js-sdk";function A(){return R}var P,N="INVALID_OPERATION",D="OPERATION_FAIL";!function(t){t.local="local",t.none="none",t.session="session"}(P||(P={}));function U(t,e){console.warn("[".concat(A(),"][").concat(t,"]:").concat(e))}var x,L,k=(x=function(t,e){return x=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},x(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}x(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),q=function(){return q=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},q.apply(this,arguments)},j=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))},B=function(t,e){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};!function(t){function e(e){var r=t.call(this)||this,n=e.timeout,i=e.timeoutMsg,o=e.restrictedMethods;return r.timeout=n||0,r.timeoutMsg=i||"请求超时",r.restrictedMethods=o||["get","post","upload","download"],r}k(e,t),e.prototype.get=function(t){return this.request(q(q({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(q(q({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(q(q({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t.data,r=t.file,n=t.name,i=t.method,o=t.headers,s=void 0===o?{}:o,a={post:"post",put:"put"}[null==i?void 0:i.toLowerCase()]||"put",c=new FormData;return"post"===a?(Object.keys(e).forEach((function(t){c.append(t,e[t])})),c.append("key",n),c.append("file",r),this.request(q(q({},t),{data:c,method:a}),this.restrictedMethods.includes("upload"))):this.request(q(q({},t),{method:"put",headers:s,body:r}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return j(this,void 0,void 0,(function(){var e,r,n,i;return B(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.get(q(q({},t),{headers:{},responseType:"blob"}))];case 1:return e=o.sent().data,r=window.URL.createObjectURL(new Blob([e])),n=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(i=document.createElement("a")).href=r,i.setAttribute("download",n),i.style.display="none",document.body.appendChild(i),i.click(),window.URL.revokeObjectURL(r),document.body.removeChild(i),[3,3];case 2:return o.sent(),[3,3];case 3:return[2,new Promise((function(e){e({statusCode:200,tempFilePath:t.url})}))]}}))}))},e.prototype.fetch=function(t){var e;return j(this,void 0,void 0,(function(){var r,n,i,o,s,a,c,u,l,h,d,f,p,v=this;return B(this,(function(g){switch(g.label){case 0:return r=new AbortController,n=t.url,i=t.enableAbort,o=void 0!==i&&i,s=t.stream,a=void 0!==s&&s,c=t.signal,u=t.timeout,l=t.shouldThrowOnError,h=void 0===l||l,d=null!=u?u:this.timeout,c&&(c.aborted&&r.abort(),c.addEventListener("abort",(function(){return r.abort()}))),f=null,o&&d&&(f=setTimeout((function(){console.warn(v.timeoutMsg),r.abort(new Error(v.timeoutMsg))}),d)),[4,fetch(n,q(q({},t),{signal:r.signal})).then((function(t){return j(v,void 0,void 0,(function(){var e,r,n;return B(this,(function(i){switch(i.label){case 0:return clearTimeout(f),h?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return n=(r=Promise).reject,[4,t.json()];case 2:e=n.apply(r,[i.sent()]),i.label=3;case 3:return[2,e];case 4:return[2,t]}}))}))})).catch((function(t){if(clearTimeout(f),h)return Promise.reject(t)}))];case 1:return p=g.sent(),[2,{data:a?p.body:(null===(e=p.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?p.json():p.text(),statusCode:p.status,header:p.headers}]}}))}))},e.prototype.request=function(t,e){var r=this;void 0===e&&(e=!1);var n=String(t.method).toLowerCase()||"get";return new Promise((function(i){var o,s,a,c=t.url,u=t.headers,l=void 0===u?{}:u,h=t.data,d=t.responseType,f=t.withCredentials,p=t.body,v=t.onUploadProgress,g=function(t,e,r){void 0===r&&(r={});var n=/\?/.test(e),i="";return Object.keys(r).forEach((function(t){""===i?!n&&(e+="?"):i+="&",i+="".concat(t,"=").concat(encodeURIComponent(r[t]))})),/^http(s)?:\/\//.test(e+=i)?e:"".concat(t).concat(e)}("https:",c,"get"===n?h:{}),y=new XMLHttpRequest;y.open(n,g),d&&(y.responseType=d),Object.keys(l).forEach((function(t){y.setRequestHeader(t,l[t])})),v&&y.upload.addEventListener("progress",v),y.onreadystatechange=function(){var t={};if(4===y.readyState){var e=y.getAllResponseHeaders().trim().split(/[\r\n]+/),r={};e.forEach((function(t){var e=t.split(": "),n=e.shift().toLowerCase(),i=e.join(": ");r[n]=i})),t.header=r,t.statusCode=y.status;try{t.data="blob"===d?y.response:JSON.parse(y.responseText)}catch(e){t.data="blob"===d?y.response:y.responseText}clearTimeout(o),i(t)}},e&&r.timeout&&(o=setTimeout((function(){console.warn(r.timeoutMsg),y.abort()}),r.timeout)),a=h,s="[object FormData]"===Object.prototype.toString.call(a)?h:"application/x-www-form-urlencoded"===l["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach((function(r){e.push("".concat(r,"=").concat(encodeURIComponent(t[r])))})),e.join("&")}(h):p||(h?JSON.stringify(h):void 0),f&&(y.withCredentials=!0),y.send(s)}))}}((function(){})),function(t){t.WEB="web",t.WX_MP="wx_mp"}(L||(L={}));var M=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),H=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))},V=function(t,e){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},G=function(t){function e(e){var r=t.call(this)||this;return r.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),r}return M(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}((function(){}));!function(){function t(t){this.keys={};var e=t.persistence,r=t.platformInfo,n=void 0===r?{}:r,i=t.keys,o=void 0===i?{}:i;this.platformInfo=n,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:(U("INVALID_PARAMS","localStorage is not supported on current platform"),new G(e.root));case"none":return new G(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=o)}Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,r){if("async"!==this.mode){if(this.storage)try{var n={version:r||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(n))}catch(t){throw new Error(JSON.stringify({code:D,msg:"[".concat(A(),"][").concat(D,"]setStore failed"),info:t}))}}else U(N,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,r){return H(this,void 0,void 0,(function(){var n;return V(this,(function(i){switch(i.label){case 0:if(!this.storage)return[2];i.label=1;case 1:return i.trys.push([1,3,,4]),n={version:r||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(n))];case 2:return i.sent(),[3,4];case 3:return i.sent(),[2];case 4:return[2]}}))}))},t.prototype.getStore=function(t,e){var r;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0})||void 0===r?void 0:r.tcb_token))return{IS_MP_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var n=this.storage.getItem(t);return n&&n.indexOf(e)>=0?JSON.parse(n).content:""}U(N,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var r;return H(this,void 0,void 0,(function(){var n;return V(this,(function(i){switch(i.label){case 0:try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0})||void 0===r?void 0:r.tcb_token))return[2,{IS_MP_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(n=i.sent())&&n.indexOf(e)>=0?[2,JSON.parse(n).content]:[2,""]}}))}))},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):U(N,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return H(this,void 0,void 0,(function(){return V(this,(function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}}))}))}}();var F=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),K=function(t,e){this.data=e||null,this.name=t},W=function(t){function e(e,r){var n=t.call(this,"error",{error:e,data:r})||this;return n.error=e,n}return F(e,t),e}(K),z=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,r){r[t]=r[t]||[],r[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,r){if(null==r?void 0:r[t]){var n=r[t].indexOf(e);-1!==n&&r[t].splice(n,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof W)return console.error(t.error),this;var r="string"==typeof t?new K(t,e||{}):t,n=r.name;if(this.listens(n)){r.target=this;for(var i=0,o=this.listeners[n]?function(t,e,r){if(r||2===arguments.length)for(var n,i=0,o=e.length;i<o;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}([],this.listeners[n],!0):[];i<o.length;i++)o[i].call(this,r)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();new z;var Y=new z;function Z(t){this.message=t}function Q(t){this.message=t}function J(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function X(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?J(Object(r),!0).forEach((function(e){$(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):J(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function $(t,e,r){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function tt(t,e,r,n,i,o,s){try{var a=t[o](s),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,i)}function et(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){tt(o,n,i,s,a,"next",t)}function a(t){tt(o,n,i,s,a,"throw",t)}s(void 0)}))}}"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox"),Z.prototype=new Error,Z.prototype.name="InvalidCharacterError","undefined"!=typeof window&&window.atob&&window.atob.bind(window),Q.prototype=new Error,Q.prototype.name="InvalidTokenError";var rt="x-request-id",nt="x-device-id",it="device_id",ot=function(){var t=et((function*(t,e){var r=null,n=null;try{var i=Object.assign({},e);i.method||(i.method="GET"),i.body&&"string"!=typeof i.body&&(i.body=JSON.stringify(i.body));var o=yield fetch(t,i),s=yield o.json();null!=s&&s.error?(n=s).error_uri=new URL(t).pathname:r=s}catch(e){n={error:a.UNREACHABLE,error_description:e.message,error_uri:new URL(t).pathname}}if(n)throw n;return r}));return function(e,r){return t.apply(this,arguments)}}(),st=new class{constructor(t){this._env=(null==t?void 0:t.env)||""}getItem(t){var e=this;return et((function*(){return window.localStorage.getItem("".concat(t).concat(e._env))}))()}removeItem(t){var e=this;return et((function*(){window.localStorage.removeItem("".concat(t).concat(e._env))}))()}setItem(t,e){var r=this;return et((function*(){window.localStorage.setItem("".concat(t).concat(r._env),e)}))()}getItemSync(t){return window.localStorage.getItem("".concat(t).concat(this._env))}removeItemSync(t){window.localStorage.removeItem("".concat(t).concat(this._env))}setItemSync(t,e){window.localStorage.setItem("".concat(t).concat(this._env),e)}};function at(t){var e=!0;return null!=t&&t.expires_at&&null!=t&&t.access_token&&(e=t.expires_at<new Date),e}class ct{constructor(t){this.credentials=null,this.accessKeyCredentials=null,this.singlePromise=null,this.tokenSectionName=t.tokenSectionName,this.storage=t.storage,this.clientId=t.clientId,this.singlePromise=new b({clientId:this.clientId}),this.credentials=t.credentials||null}getStorageCredentialsSync(){var t=null,e=this.storage.getItemSync(this.tokenSectionName);if(null!=e)try{var r;null!==(r=t=JSON.parse(e))&&void 0!==r&&r.expires_at&&(t.expires_at=new Date(t.expires_at))}catch(e){this.storage.removeItem(this.tokenSectionName),t=null}return t}setCredentials(t){var e=this;return et((function*(){if(null!=t&&t.expires_in){if(null!=t&&t.expires_at||(t.expires_at=new Date(Date.now()+1e3*(t.expires_in-30))),e.storage){var r=JSON.stringify(t);yield e.storage.setItem(e.tokenSectionName,r)}e.credentials=t}else e.storage&&(yield e.storage.removeItem(e.tokenSectionName)),e.credentials=null}))()}setAccessKeyCredentials(t){this.accessKeyCredentials=t}getCredentials(){var t=this;return et((function*(){return t.singlePromise.run("getCredentials",et((function*(){if(at(t.credentials)){var{credentials:e,isAccessKeyCredentials:r}=yield t.getStorageCredentials();if(r)return e;t.credentials=e}return t.credentials})))}))()}getStorageCredentials(){var t=this;return et((function*(){return t.singlePromise.run("_getStorageCredentials",et((function*(){var e=null,r=!1,n=yield t.storage.getItem(t.tokenSectionName);if(n)try{var i;null!==(i=e=JSON.parse(n))&&void 0!==i&&i.expires_at&&(e.expires_at=new Date(e.expires_at))}catch(r){yield t.storage.removeItem(t.tokenSectionName),e=null}else e=t.accessKeyCredentials||null,r=!0;return{credentials:e,isAccessKeyCredentials:r}})))}))()}}class ut{constructor(t){var e;this.initializePromise=null,this.lockAcquired=!1,this.pendingInLock=[],this.singlePromise=null,t.clientSecret||(t.clientSecret=""),!t.clientId&&t.env&&(t.clientId=t.env),this.apiOrigin=t.apiOrigin,this.apiPath=t.apiPath||u,this.clientId=t.clientId,this.i18n=t.i18n,this.eventBus=t.eventBus,this.singlePromise=new b({clientId:this.clientId}),this.retry=this.formatRetry(t.retry,ut.defaultRetry),t.baseRequest?this.baseRequest=t.baseRequest:this.baseRequest=ot,this.tokenInURL=t.tokenInURL,this.headers=t.headers,this.storage=t.storage||st,this.localCredentials=new ct({tokenSectionName:"credentials_".concat(t.clientId),storage:this.storage,clientId:t.clientId}),this.clientSecret=t.clientSecret,t.clientId&&(this.basicAuth="Basic ".concat(function(t){for(var e,r,n,i,o="",s=0,a=(t=String(t)).length%3;s<t.length;){if((r=t.charCodeAt(s++))>255||(n=t.charCodeAt(s++))>255||(i=t.charCodeAt(s++))>255)throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");o+=E.charAt((e=r<<16|n<<8|i)>>18&63)+E.charAt(e>>12&63)+E.charAt(e>>6&63)+E.charAt(63&e)}return a?o.slice(0,a-3)+"===".substring(a):o}("".concat(t.clientId,":").concat(this.clientSecret)))),this.wxCloud=t.wxCloud;try{w()&&(this.useWxCloud=t.useWxCloud,void 0===this.wxCloud&&t.env&&(wx.cloud.init({env:t.env}),this.wxCloud=wx.cloud))}catch(t){}this.refreshTokenFunc=t.refreshTokenFunc||this.defaultRefreshTokenFunc,this.anonymousSignInFunc=t.anonymousSignInFunc,this.onCredentialsError=t.onCredentialsError,this.getInitialSession=t.getInitialSession,this.onInitialSessionObtained=t.onInitialSessionObtained,this.logDebugMessages=null!==(e=t.debug)&&void 0!==e&&e,Y.on("lang_change",(t=>{var e;this.i18n=(null===(e=t.data)||void 0===e?void 0:e.i18n)||this.i18n}))}setGetInitialSession(t){this.getInitialSession=t}setOnInitialSessionObtained(t){this.onInitialSessionObtained=t}initialize(t){var e=this;return et((function*(){return e.initializePromise?yield e.initializePromise:void 0!==t?(e.initializePromise=t,yield e.initializePromise):(e.initializePromise=et((function*(){return yield e._acquireLock(-1,et((function*(){return yield e._initialize()})))}))(),yield e.initializePromise)}))()}setCredentials(t){var e=this;return et((function*(){return yield e.initializePromise,e._acquireLock(-1,et((function*(){return e.localCredentials.setCredentials(t)})))}))()}setAccessKeyCredentials(t){return this.localCredentials.setAccessKeyCredentials(t)}getAccessToken(){var t=this;return et((function*(){yield t.initializePromise;var e=yield t.getCredentials();if(null!=e&&e.access_token)return Promise.resolve(e.access_token);var r={error:a.UNAUTHENTICATED};return Promise.reject(r)}))()}request(t,e){var r=this;return et((function*(){var n,i,o,s;e||(e={});var c=r.formatRetry(e.retry,r.retry);if(e.headers=X(X({},e.headers),{},{[null===(n=r.i18n)||void 0===n?void 0:n.LANG_HEADER_KEY]:null===(i=r.i18n)||void 0===i?void 0:i.lang}),r.headers&&(e.headers=X(X({},r.headers),e.headers)),e.headers[rt]||(e.headers[rt]=v()),!e.headers[nt]){var u=yield r.getDeviceId();e.headers[nt]=u}if(null!==(o=e)&&void 0!==o&&o.withBasicAuth&&r.basicAuth&&(e.headers.Authorization=r.basicAuth),null!==(s=e)&&void 0!==s&&s.withCredentials){var l=e.getCredentials?yield e.getCredentials():yield r.getCredentials();l&&(r.tokenInURL?(t.indexOf("?")<0&&(t+="?"),t+="access_token=".concat(l.access_token)):e.headers.Authorization="".concat(l.token_type," ").concat(l.access_token))}else r.clientId&&t.indexOf("client_id")<0&&(t+=t.indexOf("?")<0?"?":"&",t+="client_id=".concat(r.clientId));t.startsWith("/")&&(t="".concat(r.apiOrigin).concat(r.apiPath).concat(t));for(var h=null,d=c+1,f=0;f<d;f++){try{var p;if(null!==(p=h=e.useWxCloud||r.useWxCloud?yield r.wxCloudCallFunction(t,e):yield r.baseRequest(t,e))&&void 0!==p&&p.code)throw{error:h.code,error_description:h.message,error_uri:new URL(t).pathname};break}catch(t){if(e.withCredentials&&t&&t.error===a.UNAUTHENTICATED)return yield r.setCredentials(null),Promise.reject(t);if(f===c||!t||"unreachable"!==t.error)return Promise.reject(t)}yield r.sleep(ut.retryInterval)}return h}))()}wxCloudCallFunction(t,e){var r=this;return et((function*(){var n=null,i=null;try{var o,s="";try{s=yield wx.getRendererUserAgent()}catch(t){}var{result:c}=yield r.wxCloud.callFunction({name:"httpOverCallFunction",data:{url:t,method:e.method,headers:X({origin:"https://servicewechat.com","User-Agent":s},e.headers),body:e.body}});null!=c&&null!==(o=c.body)&&void 0!==o&&o.error_code?(i=null==c?void 0:c.body).error_uri=(0,g.y)(t):n=null==c?void 0:c.body}catch(e){i={error:a.UNREACHABLE,error_description:e.message,error_uri:(0,g.y)(t)}}if(i)throw i;return n}))()}getCredentials(){var t=this;return et((function*(){return yield t.initializePromise,t._acquireLock(-1,et((function*(){return t._getCredentials()})))}))()}getCredentialsSync(){return this.localCredentials.getStorageCredentialsSync()}getCredentialsAsync(){return this.getCredentials()}getScope(){var t=this;return et((function*(){var e=yield t.localCredentials.getCredentials();if(!e){var r,n="credentials not found";return null===(r=t.onCredentialsError)||void 0===r||r.call(t,{msg:n}),t.unAuthenticatedError(n)}return e.scope}))()}getGroups(){var t=this;return et((function*(){var e=yield t.localCredentials.getCredentials();if(!e){var r,n="credentials not found";return null===(r=t.onCredentialsError)||void 0===r||r.call(t,{msg:n}),t.unAuthenticatedError(n)}return e.groups}))()}refreshToken(t,e){var r=this;return et((function*(){return yield r.initializePromise,r._acquireLock(-1,et((function*(){return r._refreshToken(t,e)})))}))()}_refreshToken(t,e){var r=this;return et((function*(){return r.singlePromise.run("_refreshToken",et((function*(){if(!t||!t.refresh_token){var n,i="no refresh token found in credentials";return null===(n=r.onCredentialsError)||void 0===n||n.call(r,{msg:i}),r.unAuthenticatedError(i)}try{var o,s=yield r.refreshTokenFunc(t.refresh_token,t);return yield r.localCredentials.setCredentials(s),null===(o=r.eventBus)||void 0===o||o.fire(f.AUTH_STATE_CHANGED,{event:d.TOKEN_REFRESHED}),s}catch(t){var c;if(null!=e&&e.throwError)throw t;if(t.error===a.INVALID_GRANT){var u;yield r.localCredentials.setCredentials(null);var l=t.error_description;return null===(u=r.onCredentialsError)||void 0===u||u.call(r,{msg:l}),r.unAuthenticatedError(l)}return null===(c=r.onCredentialsError)||void 0===c||c.call(r,{msg:t.error_description}),Promise.reject(t)}})))}))()}anonymousLogin(t){var e=this;return et((function*(){return e.singlePromise.run("_anonymousLogin",et((function*(){if(e.anonymousSignInFunc){var r=yield e.anonymousSignInFunc(t);t=r||(yield e.localCredentials.getCredentials())}else t=yield e.anonymousSignIn(t);return t})))}))()}checkRetry(t){var e=null;if(("number"!=typeof t||t<ut.minRetry||t>ut.maxRetry)&&(e={error:a.UNREACHABLE,error_description:"wrong options param: retry"}),e)throw e;return t}formatRetry(t,e){return void 0===t?e:this.checkRetry(t)}sleep(t){return et((function*(){return new Promise((e=>{setTimeout((()=>{e()}),t)}))}))()}anonymousSignIn(t){var e=this;return et((function*(){return e.singlePromise.run("_anonymous",et((function*(){if(!t||"anonymous"!==t.scope)return e.unAuthenticatedError("no anonymous in credentials");try{var r=yield e.request(i.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",withBasicAuth:!0,body:{}});return yield e.localCredentials.setCredentials(r),r}catch(t){return t.error===a.INVALID_GRANT?(yield e.localCredentials.setCredentials(null),e.unAuthenticatedError(t.error_description)):Promise.reject(t)}})))}))()}defaultRefreshTokenFunc(t,e){var r=this;return et((function*(){if(void 0===t||""===t){var n,s="refresh token not found";return null===(n=r.onCredentialsError)||void 0===n||n.call(r,{msg:s}),r.unAuthenticatedError(s)}var a=i.AUTH_TOKEN_URL;return"v2"===(null==e?void 0:e.version)&&(a=o.AUTH_TOKEN_URL),X(X({},yield r.request(a,{method:"POST",body:{client_id:r.clientId,client_secret:r.clientSecret,grant_type:"refresh_token",refresh_token:t}})),{},{version:(null==e?void 0:e.version)||"v1"})}))()}getDeviceId(){var t=this;return et((function*(){if(t.deviceID)return t.deviceID;var e=yield t.storage.getItem(it);return"string"==typeof e&&e.length>=16&&e.length<=48||(e=v(),yield t.storage.setItem(it,e)),t.deviceID=e,e}))()}unAuthenticatedError(t){var e={error:a.UNAUTHENTICATED,error_description:t};return Promise.reject(e)}_debug(){if(this.logDebugMessages){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];console.log("[OAuth2Client]",...e)}}_initialize(){var t=this;return et((function*(){try{if(!t.getInitialSession)return t._debug("#_initialize()","no getInitialSession callback set, skipping"),{error:null};t._debug("#_initialize()","calling getInitialSession callback");try{var{data:e,error:r}=yield t.getInitialSession();if(null!=e&&e.session&&(t._debug("#_initialize()","session obtained from getInitialSession",e.session),yield t.localCredentials.setCredentials(null==e?void 0:e.session)),t.onInitialSessionObtained){t._debug("#_initialize()","calling onInitialSessionObtained callback");try{yield t.onInitialSessionObtained(e,r)}catch(e){t._debug("#_initialize()","error in onInitialSessionObtained",e)}}return r?(t._debug("#_initialize()","error from getInitialSession",r),{error:r}):{error:null}}catch(e){return t._debug("#_initialize()","exception during getInitialSession",e),{error:e instanceof Error?e:new Error(String(e))}}}catch(r){return t._debug("#_initialize()","unexpected error",r),{error:r instanceof Error?r:new Error(String(r))}}finally{t._debug("#_initialize()","end")}}))()}_acquireLock(t,e){var r=this;return et((function*(){r._debug("#_acquireLock","begin",t);try{if(r.lockAcquired){var n=r.pendingInLock.length?r.pendingInLock[r.pendingInLock.length-1]:Promise.resolve(),i=et((function*(){return yield n,yield e()}))();return r.pendingInLock.push(et((function*(){try{yield i}catch(t){}}))()),i}r._debug("#_acquireLock","acquiring lock for client",r.clientId);try{r.lockAcquired=!0;var o=e();for(r.pendingInLock.push(et((function*(){try{yield o}catch(t){}}))()),yield o;r.pendingInLock.length;){var s=[...r.pendingInLock];yield Promise.all(s),r.pendingInLock.splice(0,s.length)}return yield o}finally{r._debug("#_acquireLock","releasing lock for client",r.clientId),r.lockAcquired=!1}}finally{r._debug("#_acquireLock","end")}}))()}_getCredentials(){var t=this;return et((function*(){var e=yield t.localCredentials.getCredentials();if(!e){var r,n="credentials not found";return null===(r=t.onCredentialsError)||void 0===r||r.call(t,{msg:n}),t.unAuthenticatedError(n)}if(at(e))if(e.refresh_token)try{e=yield t._refreshToken(e)}catch(r){var i;if("anonymous"!==e.scope)return null===(i=t.onCredentialsError)||void 0===i||i.call(t,{msg:r.error_description}),Promise.reject(r);e=yield t.anonymousLogin(e)}else{if("anonymous"!==e.scope){var o,s="no refresh token found in credentials";return null===(o=t.onCredentialsError)||void 0===o||o.call(t,{msg:s}),t.unAuthenticatedError(s)}e=yield t.anonymousLogin(e)}return e}))()}}ut.defaultRetry=2,ut.minRetry=0,ut.maxRetry=5,ut.retryInterval=1e3;var lt=r(689),ht=r(616);function dt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function ft(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?dt(Object(r),!0).forEach((function(e){pt(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):dt(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function pt(t,e,r){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function vt(t,e,r,n,i,o,s){try{var a=t[o](s),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,i)}function gt(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){vt(o,n,i,s,a,"next",t)}function a(t){vt(o,n,i,s,a,"throw",t)}s(void 0)}))}}var yt=(t,e)=>{var r;return function(){for(var n=arguments.length,i=new Array(n),o=0;o<n;o++)i[o]=arguments[o];clearTimeout(r),r=setTimeout((()=>t.apply(null,i)),e)}},mt=new lt.CloudbaseEventEmitter,_t="resolveCaptchaData",bt="padding:10px 8px;background:#007bff;color:#fff;border:none;border-radius:4px;cursor:pointer;flex:1;white-space:nowrap;margin-left:10px",Et="width:100%;padding:10px;background:#007bff;color:#fff;border:none;border-radius:4px;cursor:pointer",Tt="background:#6c757d;cursor:not-allowed",St=t=>{var{oauthInstance:e,captchaState:r}=t,n="captcha-image",i=function(){var t=gt((function*(){try{var t=yield e.createCaptchaData({state:r.state});r=ft(ft({},r),{},{captchaData:t.data,token:t.token}),document.getElementById(n).src=t.data}catch(t){console.error("刷新图形验证码失败",t)}}));return function(){return t.apply(this,arguments)}}(),o=(t,e,r)=>{var n=document.createElement(t);return e&&(n.style.cssText=e),r&&(n.textContent=r),n},s=o("div","position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:999"),a=o("div","position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:320px;padding:20px;background:#fff;border-radius:8px;box-shadow:0 0 10px rgba(0,0,0,0.2);z-index:1000");a.appendChild(o("p","margin-bottom:15px","请输入你看到的字符:"));var c=o("div","display:flex;align-items:center;justify-content:space-between;margin-bottom:15px"),u=o("img","width:100%;height:auto;border:1px solid #eee");u.id=n,u.src=r.captchaData,c.appendChild(u);var l=o("button",bt,"刷新");l.onclick=yt(gt((function*(){l.textContent="加载中...",l.disabled=!0,l.style.cssText="".concat(bt,";").concat(Tt);try{yield i()}finally{l.textContent="刷新",l.disabled=!1,l.style.cssText=bt}})),500),c.appendChild(l),a.appendChild(c);var h=o("input","width:100%;padding:14px 16px;margin-bottom:15px;box-sizing:border-box;border:2px solid #e8ecf4;border-radius:10px;font-size:15px");h.type="text",h.placeholder="输入字符",h.maxLength=4,a.appendChild(h);var d=o("div","color:#dc3545;font-size:12px;margin-bottom:10px;display:none;padding:8px;background:#f8d7da;border:1px solid #f5c6cb;border-radius:4px");a.appendChild(d);var f=t=>{d.textContent=t,d.style.display="block"},p=o("button",Et,"确定");p.onclick=yt(gt((function*(){var t=h.value.trim();if(t){d.style.display="none",p.textContent="验证中...",p.disabled=!0,p.style.cssText="".concat(Et,";").concat(Tt);try{var n=yield e.verifyCaptchaData({token:r.token,key:t});mt.fire(_t,n),console.log("图形验证码校验成功"),document.body.removeChild(s),document.body.removeChild(a)}catch(t){console.error("图形验证码校验失败",t);var o=t.error_description||"图形验证码校验失败";f(o),h.value="",h.focus(),yield i()}finally{p.textContent="确定",p.disabled=!1,p.style.cssText=Et}}else f("请输入字符")})),500),a.appendChild(p),document.body.appendChild(s),document.body.appendChild(a)},It=function(){var t=gt((function*(t,e){var{captchaData:r,state:n,token:i}=(0,ht.parseCaptcha)(t);return St({oauthInstance:e,captchaState:{captchaData:r,state:n,token:i}}),new Promise((t=>{console.log("等待图形验证码校验结果..."),mt.on(_t,(e=>{t(null==e?void 0:e.data)}))}))}));return function(e,r){return t.apply(this,arguments)}}();function wt(t,e,r,n,i,o,s){try{var a=t[o](s),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,i)}function Ot(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){wt(o,n,i,s,a,"next",t)}function a(t){wt(o,n,i,s,a,"throw",t)}s(void 0)}))}}class Ct{constructor(t){t.openURIWithCallback||(t.openURIWithCallback=this.getDefaultOpenURIWithCallback()),t.storage||(t.storage=st),this.config=t,this.tokenSectionName="captcha_".concat(t.clientId||t.env)}isMatch(){var t,e;return(null===(t=this.config)||void 0===t||null===(t=t.adapter)||void 0===t||null===(e=t.isMatch)||void 0===e?void 0:e.call(t))||w()}request(t,e){var r=this;return Ot((function*(){e||(e={}),e.method||(e.method="GET");var n,i="".concat(e.method,":").concat(t),o=t;e.withCaptcha&&(o=yield r.appendCaptchaTokenToURL(t,i,!1));try{n=yield r.config.request(o,e)}catch(n){return n.error===a.CAPTCHA_REQUIRED||n.error===a.CAPTCHA_INVALID?(t=yield r.appendCaptchaTokenToURL(t,i,n.error===a.CAPTCHA_INVALID),r.config.request(t,e)):Promise.reject(n)}return n}))()}getDefaultOpenURIWithCallback(){return t=>It(t,this.config.oauthInstance)}getCaptchaToken(t,e){var r=this;return Ot((function*(){if(!t){var n=yield r.findCaptchaToken();if(n)return n}var o=yield r.config.request(i.CAPTCHA_DATA_URL,{method:"POST",body:{state:e,redirect_uri:""},withCredentials:!1}),s="".concat(o.data,"?state=").concat(encodeURIComponent(e),"&token=").concat(encodeURIComponent(o.token)),a=yield r.config.openURIWithCallback(s);return r.saveCaptchaToken(a),a.captcha_token}))()}appendCaptchaTokenToURL(t,e,r){var n=this;return Ot((function*(){var i=yield n.getCaptchaToken(r,e);return t.indexOf("?")>0?t+="&captcha_token=".concat(i):t+="?captcha_token=".concat(i),t}))()}saveCaptchaToken(t){var e=this;return Ot((function*(){t.expires_at=new Date(Date.now()+1e3*(t.expires_in-10));var r=JSON.stringify(t);yield e.config.storage.setItem(e.tokenSectionName,r)}))()}findCaptchaToken(){var t=this;return Ot((function*(){var e=yield t.config.storage.getItem(t.tokenSectionName);if(null!=e)try{var r=JSON.parse(e);return null!=r&&r.expires_at&&(r.expires_at=new Date(r.expires_at)),r.expires_at<new Date?null:r.captcha_token}catch(e){return yield t.config.storage.removeItem(t.tokenSectionName),null}return null}))()}}const Rt=class{constructor(t){if(this.params={},"string"==typeof t)this.parse(t);else if(t&&"object"==typeof t)for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&this.append(e,t[e])}parse(t){t.split("&").forEach((t=>{var[e,r]=t.split("=").map(decodeURIComponent);this.append(e,r)}))}append(t,e){this.params[t]?this.params[t]=this.params[t].concat([e]):this.params[t]=[e]}get(t){return this.params[t]?this.params[t][0]:null}getAll(t){return this.params[t]||[]}delete(t){delete this.params[t]}has(t){return Object.prototype.hasOwnProperty.call(this.params,t)}set(t,e){this.params[t]=[e]}toString(){var t=this,e=[],r=function(r){Object.prototype.hasOwnProperty.call(t.params,r)&&t.params[r].forEach((t=>{e.push("".concat(encodeURIComponent(r),"=").concat(encodeURIComponent(t)))}))};for(var n in this.params)r(n);return e.join("&")}};class At extends Error{constructor(t){super(t.error_description||t.message),this.__isAuthError=!0,this.name="AuthError",this.status=t.error,this.code=t.error_code}}var Pt=["provider_redirect_uri","other_params"];function Nt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function Dt(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?Nt(Object(r),!0).forEach((function(e){Ut(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):Nt(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function Ut(t,e,r){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function xt(t,e,r,n,i,o,s){try{var a=t[o](s),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,i)}function Lt(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){xt(o,n,i,s,a,"next",t)}function a(t){xt(o,n,i,s,a,"throw",t)}s(void 0)}))}}function kt(t,e){return qt.apply(this,arguments)}function qt(){return qt=Lt((function*(t,e){var n=function(){var t=Lt((function*(){try{return r(171)}catch(t){try{return yield Promise.resolve().then(r.bind(r,171))}catch(t){return}}}));return function(){return t.apply(this,arguments)}}();try{var i;if(((null==e||null===(i=e.root)||void 0===i?void 0:i.globalThis)||globalThis).IS_MP_BUILD)return}catch(e){if(t)return n()}})),qt.apply(this,arguments)}class jt{static parseParamsToSearch(t){return Object.keys(t).forEach((e=>{t[e]||delete t[e]})),new Rt(t).toString()}constructor(t){var{request:e}=t,r=t.credentialsClient;if(!r){var n={apiOrigin:t.apiOrigin,apiPath:t.apiPath,clientId:t.clientId,storage:t.storage,env:t.env,baseRequest:t.baseRequest,anonymousSignInFunc:t.anonymousSignInFunc,wxCloud:t.wxCloud,onCredentialsError:t.onCredentialsError,headers:t.headers||{},i18n:t.i18n,debug:t.debug};r=new ut(n)}if(!e){var i=r.request.bind(r),o=new Ct(Dt({env:t.env,clientId:t.clientId,request:i,storage:t.storage,adapter:t.adapter,oauthInstance:this},t.captchaOptions));e=o.request.bind(o)}this.config={env:t.env,apiOrigin:t.apiOrigin,apiPath:t.apiPath,clientId:t.clientId,request:e,credentialsClient:r,storage:t.storage||st,adapter:t.adapter}}getParamsByVersion(t,e){var r,n=(0,g.I)(t),s=(null===(r={v2:o}[null==n?void 0:n.version])||void 0===r?void 0:r[e])||i[e];return n&&delete n.version,{params:n,url:s}}signIn(t){var e=this;return Lt((function*(){var r=t.version||"v1",n=e.getParamsByVersion(t,"AUTH_SIGN_IN_URL");n.params.query&&delete n.params.query;var i=yield e.getEncryptParams(n.params),o=yield e.config.request(n.url,{method:"POST",body:i});return yield e.config.credentialsClient.setCredentials(Dt(Dt({},o),{},{version:r})),Promise.resolve(o)}))()}signInAnonymously(){var t=arguments,e=this;return Lt((function*(){var r=t.length>0&&void 0!==t[0]?t[0]:{},n=t.length>1&&void 0!==t[1]&&t[1],o=yield e.config.request(i.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:r,useWxCloud:n});return yield e.config.credentialsClient.setCredentials(o),Promise.resolve(o)}))()}signUp(t){var e=this;return Lt((function*(){var r=yield e.config.request(i.AUTH_SIGN_UP_URL,{method:"POST",body:t});return yield e.config.credentialsClient.setCredentials(r),Promise.resolve(r)}))()}signOut(t){var e=this;return Lt((function*(){var r={};if(t){try{r=yield e.config.request(i.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:t})}catch(t){t.error!==a.UNAUTHENTICATED&&console.log("sign_out_error",t)}return yield e.config.credentialsClient.setCredentials(),r}var n=yield e.config.credentialsClient.getAccessToken(),o=yield e.config.request(i.AUTH_REVOKE_URL,{method:"POST",body:{token:n}});return yield e.config.credentialsClient.setCredentials(),Promise.resolve(o)}))()}revokeAllDevices(){var t=this;return Lt((function*(){yield t.config.request(i.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})}))()}revokeDevice(t){var e=this;return Lt((function*(){yield e.config.request(i.AUTHORIZED_DEVICES_DELETE_URL+t.device_id,{method:"DELETE",withCredentials:!0})}))()}getVerification(t,e){var r=this;return Lt((function*(){var n=!1;("CUR_USER"===t.target||(yield r.hasLoginState()))&&(n=!0);var o=(0,g.I)(t);return o.phone_number&&!/^\+\d{1,3}\s+\d+/.test(o.phone_number)&&(o.phone_number="+86 ".concat(o.phone_number)),r.config.request(i.VERIFICATION_URL,{method:"POST",body:o,withCaptcha:(null==e?void 0:e.withCaptcha)||!1,withCredentials:n})}))()}verify(t){var e=this;return Lt((function*(){var r=e.getParamsByVersion(t,"VERIFY_URL"),n=yield e.config.request(r.url,{method:"POST",body:r.params});return"v2"===(null==t?void 0:t.version)&&(yield e.config.credentialsClient.setCredentials(Dt(Dt({},n),{},{version:"v2"}))),n}))()}genProviderRedirectUri(t){var e=this;return Lt((function*(){var{provider_redirect_uri:r,other_params:n={}}=t,o=function(t,e){if(null==t)return{};var r,n,i=function(t,e){if(null==t)return{};var r={};for(var n in t)if({}.hasOwnProperty.call(t,n)){if(e.includes(n))continue;r[n]=t[n]}return r}(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(n=0;n<o.length;n++)r=o[n],e.includes(r)||{}.propertyIsEnumerable.call(t,r)&&(i[r]=t[r])}return i}(t,Pt);r&&!o.redirect_uri&&(o.redirect_uri=r);var s="".concat(i.PROVIDER_URI_URL,"?").concat(jt.parseParamsToSearch(o));return Object.keys(n).forEach((t=>{var e=n[t];("sign_out_uri"!==t||(null==e?void 0:e.length)>0)&&(s+="&other_params[".concat(t,"]=").concat(encodeURIComponent(e)))})),e.config.request(s,{method:"GET"})}))()}grantProviderToken(t){var e=arguments,r=this;return Lt((function*(){var n=e.length>1&&void 0!==e[1]&&e[1];return r.config.request(i.PROVIDER_TOKEN_URL,{method:"POST",body:t,useWxCloud:n})}))()}patchProviderToken(t){var e=this;return Lt((function*(){return e.config.request(i.PROVIDER_TOKEN_URL,{method:"PATCH",body:t})}))()}signInWithProvider(t){var e=arguments,r=this;return Lt((function*(){var n=e.length>1&&void 0!==e[1]&&e[1],i=r.getParamsByVersion(t,"AUTH_SIGN_IN_WITH_PROVIDER_URL"),o=yield r.config.request(i.url,{method:"POST",body:i.params,useWxCloud:n});return yield r.config.credentialsClient.setCredentials(Dt(Dt({},o),{},{version:(null==t?void 0:t.version)||"v1"})),Promise.resolve(o)}))()}toBindIdentity(t){var e=this;return Lt((function*(){var r,n,i,o=t.credentials||(yield e.config.credentialsClient.localCredentials.getCredentials());try{yield e.bindWithProvider({provider_token:t.provider_token},o),r={data:{type:p.BIND_IDENTITY,provider:t.provider},error:null}}catch(t){r={data:{type:p.BIND_IDENTITY},error:new At(t)}}return t.fireEvent&&(null===(n=e.config.eventBus)||void 0===n||null===(i=n.fire)||void 0===i||i.call(n,f.AUTH_STATE_CHANGED,{event:d.BIND_IDENTITY,info:r})),r}))()}getInitialSession(){var t=this;return Lt((function*(){var e={};try{var r,n,i,o,s;if("undefined"==typeof window||"undefined"==typeof document)return{data:null,error:null};var a=new URLSearchParams(null===(r=location)||void 0===r?void 0:r.search),c=a.get("code"),u=a.get("state");if(!c||!u)return{data:null,error:null};var l=null;try{l=JSON.parse(sessionStorage.getItem(u)||"null")}catch(t){}e={type:null===(n=l)||void 0===n?void 0:n.type};var h=a.get("error"),d=a.get("error_description");if(h||d)return{data:e,error:new At({message:d||h||"Unknown error from OAuth provider"})};var f=(null===(i=l)||void 0===i?void 0:i.provider)||a.get("provider");if(!f)return{data:e,error:new At({message:"Provider is required for OAuth verification"})};var v,g,y=location.origin+location.pathname,{provider_token:m}=yield t.grantProviderToken({provider_id:f,provider_redirect_uri:y,provider_code:c}),_=null;if(l.type===p.BIND_IDENTITY)v=yield t.config.credentialsClient.localCredentials.getCredentials(),g=yield t.toBindIdentity({provider:f,provider_token:m,credentials:v});else if(l.type===p.SIGN_IN){g=t.getParamsByVersion({provider:f},"AUTH_SIGN_IN_WITH_PROVIDER_URL"),v=yield t.config.request(g.url,{method:"POST",body:{provider_token:m}});try{_=yield t.getUserInfo({credentials:v})}catch(t){console.error("get user info error",t)}g={data:Dt(Dt({},e),{},{session:v,user:_}),error:null}}a.delete("code"),a.delete("state"),a.delete("provider"),t.restoreUrlState(void 0===(null===(o=l)||void 0===o?void 0:o.search)?"?".concat(a.toString()):l.search,(null===(s=l)||void 0===s?void 0:s.hash)||location.hash);try{sessionStorage.removeItem(u)}catch(t){}return g}catch(t){return{data:e,error:new At(t)}}}))()}signInCustom(t){var e=this;return Lt((function*(){var r=yield e.config.request(i.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:t});return yield e.config.credentialsClient.setCredentials(r),Promise.resolve(r)}))()}signInWithWechat(){var t=arguments,e=this;return Lt((function*(){var r=t.length>0&&void 0!==t[0]?t[0]:{},n=yield e.config.request(i.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:r});return yield e.config.credentialsClient.setCredentials(n),Promise.resolve(n)}))()}bindWithProvider(t,e){var r=this;return Lt((function*(){return r.config.request(i.PROVIDER_BIND_URL,{method:"POST",body:t,withCredentials:!0,getCredentials:e?()=>e:void 0})}))()}getUserProfile(t){var e=this;return Lt((function*(){return e.getUserInfo(t)}))()}getUserInfo(){var t=arguments,e=this;return Lt((function*(){var r,n=t.length>0&&void 0!==t[0]?t[0]:{},i=e.getParamsByVersion(n,"USER_ME_URL");if(null!==(r=i.params)&&void 0!==r&&r.query){var o=new Rt(i.params.query);i.url+="?".concat(o.toString())}var s=yield e.config.request(i.url,{method:"GET",withCredentials:!0,getCredentials:n.credentials?()=>n.credentials:void 0});return s.sub&&(s.uid=s.sub),s}))()}getWedaUserInfo(){var t=this;return Lt((function*(){return yield t.config.request(i.WEDA_USER_URL,{method:"GET",withCredentials:!0})}))()}deleteMe(t){var e=this;return Lt((function*(){var r=e.getParamsByVersion(t,"USER_ME_URL"),n="".concat(r.url,"?").concat(jt.parseParamsToSearch(r.params));return e.config.request(n,{method:"DELETE",withCredentials:!0})}))()}hasLoginState(){var t=this;return Lt((function*(){try{return yield t.config.credentialsClient.getAccessToken(),!0}catch(t){return!1}}))()}hasLoginStateSync(){return this.config.credentialsClient.getCredentialsSync()}getLoginState(){var t=this;return Lt((function*(){return t.config.credentialsClient.getCredentialsAsync()}))()}transByProvider(t){var e=this;return Lt((function*(){return e.config.request(i.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:t,withCredentials:!0})}))()}grantToken(t){var e=this;return Lt((function*(){var r=e.getParamsByVersion(t,"AUTH_TOKEN_URL");return e.config.request(r.url,{method:"POST",body:r.params})}))()}getProviders(){var t=this;return Lt((function*(){return t.config.request(i.PROVIDER_LIST,{method:"GET",withCredentials:!0})}))()}unbindProvider(t){var e=this;return Lt((function*(){return e.config.request("".concat(i.PROVIDER_UNBIND_URL,"/").concat(t.provider_id),{method:"DELETE",withCredentials:!0})}))()}checkPassword(t){var e=this;return Lt((function*(){return e.config.request("".concat(i.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:t})}))()}editContact(t){var e=this;return Lt((function*(){return e.config.request("".concat(i.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:t})}))()}setPassword(t){var e=this;return Lt((function*(){return e.config.request("".concat(i.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:t})}))()}updatePasswordByOld(t){var e=this;return Lt((function*(){var r=yield e.sudo({password:t.old_password});return e.setPassword({sudo_token:r.sudo_token,new_password:t.new_password})}))()}sudo(t){var e=this;return Lt((function*(){return e.config.request("".concat(i.SUDO_URL),{method:"POST",withCredentials:!0,body:t})}))()}sendVerificationCodeToCurrentUser(t){var e=this;return Lt((function*(){return t.target="CUR_USER",e.config.request(i.VERIFICATION_URL,{method:"POST",body:t,withCredentials:!0,withCaptcha:!0})}))()}changeBoundProvider(t){var e=this;return Lt((function*(){return e.config.request("".concat(i.PROVIDER_LIST,"/").concat(t.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:t.trans_token},withCredentials:!0})}))()}setUserProfile(t){var e=this;return Lt((function*(){return e.config.request(i.USER_PRIFILE_URL,{method:"PATCH",body:t,withCredentials:!0})}))()}updateUserBasicInfo(t){var e=this;return Lt((function*(){return e.config.request(i.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:t})}))()}queryUserProfile(t){var e=this;return Lt((function*(){var r=new Rt(t);return e.config.request("".concat(i.USER_QUERY_URL,"?").concat(r.toString()),{method:"GET",withCredentials:!0})}))()}setCustomSignFunc(t){this.getCustomSignTicketFn=t}signInWithCustomTicket(){var t=this;return Lt((function*(){var e=t.getCustomSignTicketFn;if(!e)return Promise.reject({error:"failed_precondition",error_description:"please use setCustomSignFunc to set custom sign function"});var r=yield e();return t.signInCustom({provider_id:"custom",ticket:r})}))()}resetPassword(t){var e=this;return Lt((function*(){return e.config.request(i.AUTH_RESET_PASSWORD,{method:"POST",body:t})}))()}authorize(t){var e=this;return Lt((function*(){return e.config.request(i.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:t})}))()}authorizeDevice(t){var e=this;return Lt((function*(){return e.config.request(i.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:t})}))()}deviceAuthorize(t){var e=this;return Lt((function*(){return e.config.request(i.AUTH_GET_DEVICE_CODE,{method:"POST",body:t,withCredentials:!0})}))()}authorizeInfo(t){var e=this;return Lt((function*(){var r="".concat(i.AUTHORIZE_INFO_URL,"?").concat(jt.parseParamsToSearch(t)),n=!0,o=!1;return(yield e.hasLoginState())&&(o=!0,n=!1),e.config.request(r,{method:"GET",withBasicAuth:n,withCredentials:o})}))()}checkUsername(t){var e=this;return Lt((function*(){return e.config.request(i.CHECK_USERNAME,{method:"GET",body:t,withCredentials:!0})}))()}checkIfUserExist(t){var e=this;return Lt((function*(){var r=new Rt(t);return e.config.request("".concat(i.CHECK_IF_USER_EXIST,"?").concat(r.toString()),{method:"GET"})}))()}loginScope(){var t=this;return Lt((function*(){return t.config.credentialsClient.getScope()}))()}loginGroups(){var t=this;return Lt((function*(){return t.config.credentialsClient.getGroups()}))()}refreshTokenForce(t){var e=this;return Lt((function*(){var r=yield e.config.credentialsClient.getCredentials();return yield e.config.credentialsClient.refreshToken(Dt(Dt({},r),{},{version:(null==t?void 0:t.version)||"v1"}))}))()}getCredentials(){var t=this;return Lt((function*(){return t.config.credentialsClient.getCredentials()}))()}getPublicKey(){var t=this;return Lt((function*(){return t.config.request(o.AUTH_PUBLIC_KEY,{method:"POST",body:{}})}))()}getEncryptParams(t){var e=this;return Lt((function*(){var{isEncrypt:r}=t;delete t.isEncrypt;var n=(0,g.I)(t),i=yield kt(r,e.config.adapter);if(!i)return t;var o="",s="";try{var a=yield e.getPublicKey();if(o=a.public_key,s=a.public_key_thumbprint,!o||!s)throw a}catch(t){throw t}return{params:i.getEncryptInfo({publicKey:o,payload:n}),public_key_thumbprint:s}}))()}getProviderSubType(){var t=this;return Lt((function*(){return t.config.request(i.GET_PROVIDER_TYPE,{method:"POST",body:{provider_id:"weda"}})}))()}verifyCaptchaData(t){var e=this;return Lt((function*(){var{token:r,key:n}=t;return e.config.request(i.VERIFY_CAPTCHA_DATA_URL,{method:"POST",body:{token:r,key:n},withCredentials:!1})}))()}createCaptchaData(t){var e=this;return Lt((function*(){var{state:r,redirect_uri:n}=t;return e.config.request(i.CAPTCHA_DATA_URL,{method:"POST",body:{state:r,redirect_uri:n},withCredentials:!1})}))()}getMiniProgramCode(t){var e=this;return Lt((function*(){return e.config.request(i.GET_MINIPROGRAM_QRCODE,{method:"POST",body:t})}))()}getMiniProgramQrCodeStatus(t){var e=this;return Lt((function*(){return e.config.request(i.GET_MINIPROGRAM_QRCODE_STATUS,{method:"POST",body:t})}))()}getUserBehaviorLog(t){var e=this;return Lt((function*(){var r="".concat(i.GET_USER_BEHAVIOR_LOG,"?").concat({LOGIN:"query[action]=USER_LOGIN",MODIFY:"ne_query[action]=USER_LOGIN"}[t.type],"&limit=").concat(t.limit).concat(t.page_token?"&page_token=".concat(t.page_token):"");return e.config.request(r,{method:"GET",withCredentials:!0})}))()}modifyPassword(t){var e=this;return Lt((function*(){var r="",n="",o=yield kt(!0,e.config.adapter);if(!o)throw new Error("do not support encrypt, a encrypt util required.");try{var s=yield e.getPublicKey();if(r=s.public_key,n=s.public_key_thumbprint,!r||!n)throw s}catch(t){throw t}var a=t.password?o.getEncryptInfo({publicKey:r,payload:t.password}):"",c=o.getEncryptInfo({publicKey:r,payload:t.new_password});return e.config.request(i.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:{user_id:t.user_id,encrypt_password:a,encrypt_new_password:c,public_key_thumbprint:n}})}))()}modifyPasswordWithoutLogin(t){var e=this;return Lt((function*(){var r="",n="",i=yield kt(!0,e.config.adapter);if(!i)throw new Error("do not support encrypt, a encrypt util required.");try{var s=yield e.getPublicKey();if(r=s.public_key,n=s.public_key_thumbprint,!r||!n)throw s}catch(t){throw t}var a=t.password?i.getEncryptInfo({publicKey:r,payload:t.password}):"",c=i.getEncryptInfo({publicKey:r,payload:t.new_password});return e.config.request(o.AUTH_RESET_PASSWORD,{method:"POST",body:{username:t.username,password:a,new_password:c,public_key_thumbprint:n}})}))()}restoreUrlState(t,e){if(void 0!==t)try{var r=new URL(window.location.href);r.search=t,r.hash=e||"",window.history.replaceState(null,"",r.toString())}catch(t){}}}function Bt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function Mt(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?Bt(Object(r),!0).forEach((function(e){Ht(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):Bt(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function Ht(t,e,r){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}class Vt{constructor(t){var{apiOrigin:e,apiPath:r=u,clientId:n,env:i,storage:o,request:s,baseRequest:a,anonymousSignInFunc:c,wxCloud:l,adapter:h,onCredentialsError:d,headers:f,i18n:p,useWxCloud:v,eventBus:g,detectSessionInUrl:y,debug:m}=t;this.detectSessionInUrl=null!=y&&y,this.oauth2client=new ut({apiOrigin:e,apiPath:r,clientId:n,env:i,storage:o,baseRequest:a||s,anonymousSignInFunc:c,wxCloud:l,onCredentialsError:d,headers:f||{},i18n:p,useWxCloud:v,eventBus:g,debug:m}),this.authApi=new jt(Mt(Mt({credentialsClient:this.oauth2client},t),{},{request:s?this.oauth2client.request.bind(this.oauth2client):void 0,adapter:h})),y&&this.oauth2client.setGetInitialSession(this.authApi.getInitialSession.bind(this.authApi))}initializeSession(t){this.detectSessionInUrl?(this.oauth2client.setOnInitialSessionObtained(t),this.oauth2client.initialize()):this.oauth2client.initialize(Promise.resolve({error:null}))}}},171:(t,e,r)=>{var n;if(r.r(e),r.d(e,{getEncryptInfo:()=>B}),!globalThis.IS_MP_BUILD){var i="undefined"!=typeof globalThis?globalThis.navigator:window.globalThis,o="0123456789abcdefghijklmnopqrstuvwxyz";function M(t){return o.charAt(t)}function H(t,e){return t&e}function V(t,e){return t|e}function G(t,e){return t^e}function F(t,e){return t&~e}function K(t){if(0==t)return-1;var e=0;return 65535&t||(t>>=16,e+=16),255&t||(t>>=8,e+=8),15&t||(t>>=4,e+=4),3&t||(t>>=2,e+=2),1&t||++e,e}function W(t){for(var e=0;0!=t;)t&=t-1,++e;return e}var s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function z(t){var e,r,n="";for(e=0;e+3<=t.length;e+=3)r=parseInt(t.substring(e,e+3),16),n+=s.charAt(r>>6)+s.charAt(63&r);for(e+1==t.length?(r=parseInt(t.substring(e,e+1),16),n+=s.charAt(r<<2)):e+2==t.length&&(r=parseInt(t.substring(e,e+2),16),n+=s.charAt(r>>2)+s.charAt((3&r)<<4));(3&n.length)>0;)n+="=";return n}function Y(t){var e,r="",n=0,i=0;for(e=0;e<t.length&&"="!=t.charAt(e);++e){var o=s.indexOf(t.charAt(e));o<0||(0==n?(r+=M(o>>2),i=3&o,n=1):1==n?(r+=M(i<<2|o>>4),i=15&o,n=2):2==n?(r+=M(i),r+=M(o>>2),i=3&o,n=3):(r+=M(i<<2|o>>4),r+=M(15&o),n=0))}return 1==n&&(r+=M(i<<2)),r}var a,c,u={decode:function(t){var e;if(void 0===a){var r="0123456789ABCDEF";for(a={},e=0;e<16;++e)a[r.charAt(e)]=e;for(r=r.toLowerCase(),e=10;e<16;++e)a[r.charAt(e)]=e;for(e=0;e<8;++e)a[" \f\n\r\t \u2028\u2029".charAt(e)]=-1}var n=[],i=0,o=0;for(e=0;e<t.length;++e){var s=t.charAt(e);if("="==s)break;if(-1!=(s=a[s])){if(void 0===s)throw new Error("Illegal character at offset "+e);i|=s,++o>=2?(n[n.length]=i,i=0,o=0):i<<=4}}if(o)throw new Error("Hex encoding incomplete: 4 bits missing");return n}},l={decode:function(t){var e;if(void 0===c){for(c=Object.create(null),e=0;e<64;++e)c["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)]=e;for(e=0;e<9;++e)c["= \f\n\r\t \u2028\u2029".charAt(e)]=-1}var r=[],n=0,i=0;for(e=0;e<t.length;++e){var o=t.charAt(e);if("="==o)break;if(-1!=(o=c[o])){if(void 0===o)throw new Error("Illegal character at offset "+e);n|=o,++i>=4?(r[r.length]=n>>16,r[r.length]=n>>8&255,r[r.length]=255&n,n=0,i=0):n<<=6}}switch(i){case 1:throw new Error("Base64 encoding incomplete: at least 2 bits missing");case 2:r[r.length]=n>>10;break;case 3:r[r.length]=n>>16,r[r.length]=n>>8&255}return r},re:/-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,unarmor:function(t){var e=l.re.exec(t);if(e)if(e[1])t=e[1];else{if(!e[2])throw new Error("RegExp out of sync");t=e[2]}return l.decode(t)}},h=1e13;class Z{constructor(t){this.buf=[+t||0]}mulAdd(t,e){var r,n,i=this.buf,o=i.length;for(r=0;r<o;++r)(n=i[r]*t+e)<h?e=0:n-=(e=0|n/h)*h,i[r]=n;e>0&&(i[r]=e)}sub(t){var e,r,n=this.buf,i=n.length;for(e=0;e<i;++e)(r=n[e]-t)<0?(r+=h,t=1):t=0,n[e]=r;for(;0===n[n.length-1];)n.pop()}toString(t){if(10!=(t||10))throw new Error("only base 10 is supported");for(var e=this.buf,r=e[e.length-1].toString(),n=e.length-2;n>=0;--n)r+=(h+e[n]).toString().substring(1);return r}valueOf(){for(var t=this.buf,e=0,r=t.length-1;r>=0;--r)e=e*h+t[r];return e}simplify(){var t=this.buf;return 1==t.length?t[0]:this}}var d,f=/^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/,p=/^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;function Q(t,e){return t.length>e&&(t=t.substring(0,e)+"…"),t}class J{constructor(t,e){this.hexDigits="0123456789ABCDEF",t instanceof J?(this.enc=t.enc,this.pos=t.pos):(this.enc=t,this.pos=e)}get(t){if(void 0===t&&(t=this.pos++),t>=this.enc.length)throw new Error("Requesting byte offset "+t+" on a stream of length "+this.enc.length);return"string"==typeof this.enc?this.enc.charCodeAt(t):this.enc[t]}hexByte(t){return this.hexDigits.charAt(t>>4&15)+this.hexDigits.charAt(15&t)}hexDump(t,e,r){for(var n="",i=t;i<e;++i)if(n+=this.hexByte(this.get(i)),!0!==r)switch(15&i){case 7:n+=" ";break;case 15:n+="\n";break;default:n+=" "}return n}isASCII(t,e){for(var r=t;r<e;++r){var n=this.get(r);if(n<32||n>176)return!1}return!0}parseStringISO(t,e){for(var r="",n=t;n<e;++n)r+=String.fromCharCode(this.get(n));return r}parseStringUTF(t,e){for(var r="",n=t;n<e;){var i=this.get(n++);r+=i<128?String.fromCharCode(i):i>191&&i<224?String.fromCharCode((31&i)<<6|63&this.get(n++)):String.fromCharCode((15&i)<<12|(63&this.get(n++))<<6|63&this.get(n++))}return r}parseStringBMP(t,e){for(var r,n,i="",o=t;o<e;)r=this.get(o++),n=this.get(o++),i+=String.fromCharCode(r<<8|n);return i}parseTime(t,e,r){var n=this.parseStringISO(t,e),i=(r?f:p).exec(n);return i?(r&&(i[1]=+i[1],i[1]+=+i[1]<70?2e3:1900),n=i[1]+"-"+i[2]+"-"+i[3]+" "+i[4],i[5]&&(n+=":"+i[5],i[6]&&(n+=":"+i[6],i[7]&&(n+="."+i[7]))),i[8]&&(n+=" UTC","Z"!=i[8]&&(n+=i[8],i[9]&&(n+=":"+i[9]))),n):"Unrecognized time: "+n}parseInteger(t,e){for(var r,n=this.get(t),i=n>127,o=i?255:0,s="";n==o&&++t<e;)n=this.get(t);if(0==(r=e-t))return i?-1:0;if(r>4){for(s=n,r<<=3;!(128&(+s^o));)s=+s<<1,--r;s="("+r+" bit)\n"}i&&(n-=256);for(var a=new Z(n),c=t+1;c<e;++c)a.mulAdd(256,this.get(c));return s+a.toString()}parseBitString(t,e,r){for(var n=this.get(t),i="("+((e-t-1<<3)-n)+" bit)\n",o="",s=t+1;s<e;++s){for(var a=this.get(s),c=s==e-1?n:0,u=7;u>=c;--u)o+=a>>u&1?"1":"0";if(o.length>r)return i+Q(o,r)}return i+o}parseOctetString(t,e,r){if(this.isASCII(t,e))return Q(this.parseStringISO(t,e),r);var n=e-t,i="("+n+" byte)\n";n>(r/=2)&&(e=t+r);for(var o=t;o<e;++o)i+=this.hexByte(this.get(o));return n>r&&(i+="…"),i}parseOID(t,e,r){for(var n="",i=new Z,o=0,s=t;s<e;++s){var a=this.get(s);if(i.mulAdd(128,127&a),o+=7,!(128&a)){if(""===n)if((i=i.simplify())instanceof Z)i.sub(80),n="2."+i.toString();else{var c=i<80?i<40?0:1:2;n=c+"."+(i-40*c)}else n+="."+i.toString();if(n.length>r)return Q(n,r);i=new Z,o=0}}return o>0&&(n+=".incomplete"),n}}class X{constructor(t,e,r,n,i){if(!(n instanceof $))throw new Error("Invalid tag value.");this.stream=t,this.header=e,this.length=r,this.tag=n,this.sub=i}typeName(){switch(this.tag.tagClass){case 0:switch(this.tag.tagNumber){case 0:return"EOC";case 1:return"BOOLEAN";case 2:return"INTEGER";case 3:return"BIT_STRING";case 4:return"OCTET_STRING";case 5:return"NULL";case 6:return"OBJECT_IDENTIFIER";case 7:return"ObjectDescriptor";case 8:return"EXTERNAL";case 9:return"REAL";case 10:return"ENUMERATED";case 11:return"EMBEDDED_PDV";case 12:return"UTF8String";case 16:return"SEQUENCE";case 17:return"SET";case 18:return"NumericString";case 19:return"PrintableString";case 20:return"TeletexString";case 21:return"VideotexString";case 22:return"IA5String";case 23:return"UTCTime";case 24:return"GeneralizedTime";case 25:return"GraphicString";case 26:return"VisibleString";case 27:return"GeneralString";case 28:return"UniversalString";case 30:return"BMPString"}return"Universal_"+this.tag.tagNumber.toString();case 1:return"Application_"+this.tag.tagNumber.toString();case 2:return"["+this.tag.tagNumber.toString()+"]";case 3:return"Private_"+this.tag.tagNumber.toString()}}content(t){if(void 0===this.tag)return null;void 0===t&&(t=1/0);var e=this.posContent(),r=Math.abs(this.length);if(!this.tag.isUniversal())return null!==this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(e,e+r,t);switch(this.tag.tagNumber){case 1:return 0===this.stream.get(e)?"false":"true";case 2:return this.stream.parseInteger(e,e+r);case 3:return this.sub?"("+this.sub.length+" elem)":this.stream.parseBitString(e,e+r,t);case 4:return this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(e,e+r,t);case 6:return this.stream.parseOID(e,e+r,t);case 16:case 17:return null!==this.sub?"("+this.sub.length+" elem)":"(no elem)";case 12:return Q(this.stream.parseStringUTF(e,e+r),t);case 18:case 19:case 20:case 21:case 22:case 26:return Q(this.stream.parseStringISO(e,e+r),t);case 30:return Q(this.stream.parseStringBMP(e,e+r),t);case 23:case 24:return this.stream.parseTime(e,e+r,23==this.tag.tagNumber)}return null}toString(){return this.typeName()+"@"+this.stream.pos+"[header:"+this.header+",length:"+this.length+",sub:"+(null===this.sub?"null":this.sub.length)+"]"}toPrettyString(t){void 0===t&&(t="");var e=t+this.typeName()+" @"+this.stream.pos;if(this.length>=0&&(e+="+"),e+=this.length,this.tag.tagConstructed?e+=" (constructed)":!this.tag.isUniversal()||3!=this.tag.tagNumber&&4!=this.tag.tagNumber||null===this.sub||(e+=" (encapsulates)"),e+="\n",null!==this.sub){t+=" ";for(var r=0,n=this.sub.length;r<n;++r)e+=this.sub[r].toPrettyString(t)}return e}posStart(){return this.stream.pos}posContent(){return this.stream.pos+this.header}posEnd(){return this.stream.pos+this.header+Math.abs(this.length)}toHexString(){return this.stream.hexDump(this.posStart(),this.posEnd(),!0)}static decodeLength(t){var e=t.get(),r=127&e;if(r==e)return r;if(r>6)throw new Error("Length over 48 bits not supported at position "+(t.pos-1));if(0===r)return null;e=0;for(var n=0;n<r;++n)e=256*e+t.get();return e}getHexStringValue(){var t=this.toHexString(),e=2*this.header,r=2*this.length;return t.substr(e,r)}static decode(t){var e;e=t instanceof J?t:new J(t,0);var r=new J(e),n=new $(e),i=X.decodeLength(e),o=e.pos,s=o-r.pos,a=null,c=function(){var t=[];if(null!==i){for(var r=o+i;e.pos<r;)t[t.length]=X.decode(e);if(e.pos!=r)throw new Error("Content size is not correct for container starting at offset "+o)}else try{for(;;){var n=X.decode(e);if(n.tag.isEOC())break;t[t.length]=n}i=o-e.pos}catch(t){throw new Error("Exception while decoding undefined length content: "+t)}return t};if(n.tagConstructed)a=c();else if(n.isUniversal()&&(3==n.tagNumber||4==n.tagNumber))try{if(3==n.tagNumber&&0!=e.get())throw new Error("BIT STRINGs with unused bits cannot encapsulate.");a=c();for(var u=0;u<a.length;++u)if(a[u].tag.isEOC())throw new Error("EOC is not supposed to be actual content.")}catch(t){a=null}if(null===a){if(null===i)throw new Error("We can't skip over an invalid tag with undefined length at offset "+o);e.pos=o+Math.abs(i)}return new X(r,s,i,n,a)}}class ${constructor(t){var e=t.get();if(this.tagClass=e>>6,this.tagConstructed=!!(32&e),this.tagNumber=31&e,31==this.tagNumber){var r=new Z;do{e=t.get(),r.mulAdd(128,127&e)}while(128&e);this.tagNumber=r.simplify()}}isUniversal(){return 0===this.tagClass}isEOC(){return 0===this.tagClass&&0===this.tagNumber}}var v=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],g=(1<<26)/v[v.length-1];class tt{constructor(t,e,r){null!=t&&("number"==typeof t?this.fromNumber(t,e,r):null==e&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,e))}toString(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var r,n=(1<<e)-1,i=!1,o="",s=this.t,a=this.DB-s*this.DB%e;if(s-- >0)for(a<this.DB&&(r=this[s]>>a)>0&&(i=!0,o=M(r));s>=0;)a<e?(r=(this[s]&(1<<a)-1)<<e-a,r|=this[--s]>>(a+=this.DB-e)):(r=this[s]>>(a-=e)&n,a<=0&&(a+=this.DB,--s)),r>0&&(i=!0),i&&(o+=M(r));return i?o:"0"}negate(){var t=et();return tt.ZERO.subTo(this,t),t}abs(){return this.s<0?this.negate():this}compareTo(t){var e=this.s-t.s;if(0!=e)return e;var r=this.t;if(0!=(e=r-t.t))return this.s<0?-e:e;for(;--r>=0;)if(0!=(e=this[r]-t[r]))return e;return 0}bitLength(){return this.t<=0?0:this.DB*(this.t-1)+ct(this[this.t-1]^this.s&this.DM)}mod(t){var e=et();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(tt.ZERO)>0&&t.subTo(e,e),e}modPowInt(t,e){var r;return r=t<256||e.isEven()?new m(e):new _(e),this.exp(t,r)}clone(){var t=et();return this.copyTo(t),t}intValue(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}byteValue(){return 0==this.t?this.s:this[0]<<24>>24}shortValue(){return 0==this.t?this.s:this[0]<<16>>16}signum(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1}toByteArray(){var t=this.t,e=[];e[0]=this.s;var r,n=this.DB-t*this.DB%8,i=0;if(t-- >0)for(n<this.DB&&(r=this[t]>>n)!=(this.s&this.DM)>>n&&(e[i++]=r|this.s<<this.DB-n);t>=0;)n<8?(r=(this[t]&(1<<n)-1)<<8-n,r|=this[--t]>>(n+=this.DB-8)):(r=this[t]>>(n-=8)&255,n<=0&&(n+=this.DB,--t)),128&r&&(r|=-256),0==i&&(128&this.s)!=(128&r)&&++i,(i>0||r!=this.s)&&(e[i++]=r);return e}equals(t){return 0==this.compareTo(t)}min(t){return this.compareTo(t)<0?this:t}max(t){return this.compareTo(t)>0?this:t}and(t){var e=et();return this.bitwiseTo(t,H,e),e}or(t){var e=et();return this.bitwiseTo(t,V,e),e}xor(t){var e=et();return this.bitwiseTo(t,G,e),e}andNot(t){var e=et();return this.bitwiseTo(t,F,e),e}not(){for(var t=et(),e=0;e<this.t;++e)t[e]=this.DM&~this[e];return t.t=this.t,t.s=~this.s,t}shiftLeft(t){var e=et();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e}shiftRight(t){var e=et();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e}getLowestSetBit(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+K(this[t]);return this.s<0?this.t*this.DB:-1}bitCount(){for(var t=0,e=this.s&this.DM,r=0;r<this.t;++r)t+=W(this[r]^e);return t}testBit(t){var e=Math.floor(t/this.DB);return e>=this.t?0!=this.s:!!(this[e]&1<<t%this.DB)}setBit(t){return this.changeBit(t,V)}clearBit(t){return this.changeBit(t,F)}flipBit(t){return this.changeBit(t,G)}add(t){var e=et();return this.addTo(t,e),e}subtract(t){var e=et();return this.subTo(t,e),e}multiply(t){var e=et();return this.multiplyTo(t,e),e}divide(t){var e=et();return this.divRemTo(t,e,null),e}remainder(t){var e=et();return this.divRemTo(t,null,e),e}divideAndRemainder(t){var e=et(),r=et();return this.divRemTo(t,e,r),[e,r]}modPow(t,e){var r,n,i=t.bitLength(),o=at(1);if(i<=0)return o;r=i<18?1:i<48?3:i<144?4:i<768?5:6,n=i<8?new m(e):e.isEven()?new b(e):new _(e);var s=[],a=3,c=r-1,u=(1<<r)-1;if(s[1]=n.convert(this),r>1){var l=et();for(n.sqrTo(s[1],l);a<=u;)s[a]=et(),n.mulTo(l,s[a-2],s[a]),a+=2}var h,d,f=t.t-1,p=!0,v=et();for(i=ct(t[f])-1;f>=0;){for(i>=c?h=t[f]>>i-c&u:(h=(t[f]&(1<<i+1)-1)<<c-i,f>0&&(h|=t[f-1]>>this.DB+i-c)),a=r;!(1&h);)h>>=1,--a;if((i-=a)<0&&(i+=this.DB,--f),p)s[h].copyTo(o),p=!1;else{for(;a>1;)n.sqrTo(o,v),n.sqrTo(v,o),a-=2;a>0?n.sqrTo(o,v):(d=o,o=v,v=d),n.mulTo(v,s[h],o)}for(;f>=0&&!(t[f]&1<<i);)n.sqrTo(o,v),d=o,o=v,v=d,--i<0&&(i=this.DB-1,--f)}return n.revert(o)}modInverse(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return tt.ZERO;for(var r=t.clone(),n=this.clone(),i=at(1),o=at(0),s=at(0),a=at(1);0!=r.signum();){for(;r.isEven();)r.rShiftTo(1,r),e?(i.isEven()&&o.isEven()||(i.addTo(this,i),o.subTo(t,o)),i.rShiftTo(1,i)):o.isEven()||o.subTo(t,o),o.rShiftTo(1,o);for(;n.isEven();)n.rShiftTo(1,n),e?(s.isEven()&&a.isEven()||(s.addTo(this,s),a.subTo(t,a)),s.rShiftTo(1,s)):a.isEven()||a.subTo(t,a),a.rShiftTo(1,a);r.compareTo(n)>=0?(r.subTo(n,r),e&&i.subTo(s,i),o.subTo(a,o)):(n.subTo(r,n),e&&s.subTo(i,s),a.subTo(o,a))}return 0!=n.compareTo(tt.ONE)?tt.ZERO:a.compareTo(t)>=0?a.subtract(t):a.signum()<0?(a.addTo(t,a),a.signum()<0?a.add(t):a):a}pow(t){return this.exp(t,new y)}gcd(t){var e=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(e.compareTo(r)<0){var n=e;e=r,r=n}var i=e.getLowestSetBit(),o=r.getLowestSetBit();if(o<0)return e;for(i<o&&(o=i),o>0&&(e.rShiftTo(o,e),r.rShiftTo(o,r));e.signum()>0;)(i=e.getLowestSetBit())>0&&e.rShiftTo(i,e),(i=r.getLowestSetBit())>0&&r.rShiftTo(i,r),e.compareTo(r)>=0?(e.subTo(r,e),e.rShiftTo(1,e)):(r.subTo(e,r),r.rShiftTo(1,r));return o>0&&r.lShiftTo(o,r),r}isProbablePrime(t){var e,r=this.abs();if(1==r.t&&r[0]<=v[v.length-1]){for(e=0;e<v.length;++e)if(r[0]==v[e])return!0;return!1}if(r.isEven())return!1;for(e=1;e<v.length;){for(var n=v[e],i=e+1;i<v.length&&n<g;)n*=v[i++];for(n=r.modInt(n);e<i;)if(n%v[e++]==0)return!1}return r.millerRabin(t)}copyTo(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s}fromInt(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0}fromString(t,e){var r;if(16==e)r=4;else if(8==e)r=3;else if(256==e)r=8;else if(2==e)r=1;else if(32==e)r=5;else{if(4!=e)return void this.fromRadix(t,e);r=2}this.t=0,this.s=0;for(var n=t.length,i=!1,o=0;--n>=0;){var s=8==r?255&+t[n]:st(t,n);s<0?"-"==t.charAt(n)&&(i=!0):(i=!1,0==o?this[this.t++]=s:o+r>this.DB?(this[this.t-1]|=(s&(1<<this.DB-o)-1)<<o,this[this.t++]=s>>this.DB-o):this[this.t-1]|=s<<o,(o+=r)>=this.DB&&(o-=this.DB))}8==r&&128&+t[0]&&(this.s=-1,o>0&&(this[this.t-1]|=(1<<this.DB-o)-1<<o)),this.clamp(),i&&tt.ZERO.subTo(this,this)}clamp(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t}dlShiftTo(t,e){var r;for(r=this.t-1;r>=0;--r)e[r+t]=this[r];for(r=t-1;r>=0;--r)e[r]=0;e.t=this.t+t,e.s=this.s}drShiftTo(t,e){for(var r=t;r<this.t;++r)e[r-t]=this[r];e.t=Math.max(this.t-t,0),e.s=this.s}lShiftTo(t,e){for(var r=t%this.DB,n=this.DB-r,i=(1<<n)-1,o=Math.floor(t/this.DB),s=this.s<<r&this.DM,a=this.t-1;a>=0;--a)e[a+o+1]=this[a]>>n|s,s=(this[a]&i)<<r;for(a=o-1;a>=0;--a)e[a]=0;e[o]=s,e.t=this.t+o+1,e.s=this.s,e.clamp()}rShiftTo(t,e){e.s=this.s;var r=Math.floor(t/this.DB);if(r>=this.t)e.t=0;else{var n=t%this.DB,i=this.DB-n,o=(1<<n)-1;e[0]=this[r]>>n;for(var s=r+1;s<this.t;++s)e[s-r-1]|=(this[s]&o)<<i,e[s-r]=this[s]>>n;n>0&&(e[this.t-r-1]|=(this.s&o)<<i),e.t=this.t-r,e.clamp()}}subTo(t,e){for(var r=0,n=0,i=Math.min(t.t,this.t);r<i;)n+=this[r]-t[r],e[r++]=n&this.DM,n>>=this.DB;if(t.t<this.t){for(n-=t.s;r<this.t;)n+=this[r],e[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<t.t;)n-=t[r],e[r++]=n&this.DM,n>>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e[r++]=this.DV+n:n>0&&(e[r++]=n),e.t=r,e.clamp()}multiplyTo(t,e){var r=this.abs(),n=t.abs(),i=r.t;for(e.t=i+n.t;--i>=0;)e[i]=0;for(i=0;i<n.t;++i)e[i+r.t]=r.am(0,n[i],e,i,0,r.t);e.s=0,e.clamp(),this.s!=t.s&&tt.ZERO.subTo(e,e)}squareTo(t){for(var e=this.abs(),r=t.t=2*e.t;--r>=0;)t[r]=0;for(r=0;r<e.t-1;++r){var n=e.am(r,e[r],t,2*r,0,1);(t[r+e.t]+=e.am(r+1,2*e[r],t,2*r+1,n,e.t-r-1))>=e.DV&&(t[r+e.t]-=e.DV,t[r+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(r,e[r],t,2*r,0,1)),t.s=0,t.clamp()}divRemTo(t,e,r){var n=t.abs();if(!(n.t<=0)){var i=this.abs();if(i.t<n.t)return null!=e&&e.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=et());var o=et(),s=this.s,a=t.s,c=this.DB-ct(n[n.t-1]);c>0?(n.lShiftTo(c,o),i.lShiftTo(c,r)):(n.copyTo(o),i.copyTo(r));var u=o.t,l=o[u-1];if(0!=l){var h=l*(1<<this.F1)+(u>1?o[u-2]>>this.F2:0),d=this.FV/h,f=(1<<this.F1)/h,p=1<<this.F2,v=r.t,g=v-u,y=null==e?et():e;for(o.dlShiftTo(g,y),r.compareTo(y)>=0&&(r[r.t++]=1,r.subTo(y,r)),tt.ONE.dlShiftTo(u,y),y.subTo(o,o);o.t<u;)o[o.t++]=0;for(;--g>=0;){var m=r[--v]==l?this.DM:Math.floor(r[v]*d+(r[v-1]+p)*f);if((r[v]+=o.am(0,m,r,g,0,u))<m)for(o.dlShiftTo(g,y),r.subTo(y,r);r[v]<--m;)r.subTo(y,r)}null!=e&&(r.drShiftTo(u,e),s!=a&&tt.ZERO.subTo(e,e)),r.t=u,r.clamp(),c>0&&r.rShiftTo(c,r),s<0&&tt.ZERO.subTo(r,r)}}}invDigit(){if(this.t<1)return 0;var t=this[0];if(!(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e}isEven(){return 0==(this.t>0?1&this[0]:this.s)}exp(t,e){if(t>4294967295||t<1)return tt.ONE;var r=et(),n=et(),i=e.convert(this),o=ct(t)-1;for(i.copyTo(r);--o>=0;)if(e.sqrTo(r,n),(t&1<<o)>0)e.mulTo(n,i,r);else{var s=r;r=n,n=s}return e.revert(r)}chunkSize(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}toRadix(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var e=this.chunkSize(t),r=Math.pow(t,e),n=at(r),i=et(),o=et(),s="";for(this.divRemTo(n,i,o);i.signum()>0;)s=(r+o.intValue()).toString(t).substr(1)+s,i.divRemTo(n,i,o);return o.intValue().toString(t)+s}fromRadix(t,e){this.fromInt(0),null==e&&(e=10);for(var r=this.chunkSize(e),n=Math.pow(e,r),i=!1,o=0,s=0,a=0;a<t.length;++a){var c=st(t,a);c<0?"-"==t.charAt(a)&&0==this.signum()&&(i=!0):(s=e*s+c,++o>=r&&(this.dMultiply(n),this.dAddOffset(s,0),o=0,s=0))}o>0&&(this.dMultiply(Math.pow(e,o)),this.dAddOffset(s,0)),i&&tt.ZERO.subTo(this,this)}fromNumber(t,e,r){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,r),this.testBit(t-1)||this.bitwiseTo(tt.ONE.shiftLeft(t-1),V,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(tt.ONE.shiftLeft(t-1),this);else{var n=[],i=7&t;n.length=1+(t>>3),e.nextBytes(n),i>0?n[0]&=(1<<i)-1:n[0]=0,this.fromString(n,256)}}bitwiseTo(t,e,r){var n,i,o=Math.min(t.t,this.t);for(n=0;n<o;++n)r[n]=e(this[n],t[n]);if(t.t<this.t){for(i=t.s&this.DM,n=o;n<this.t;++n)r[n]=e(this[n],i);r.t=this.t}else{for(i=this.s&this.DM,n=o;n<t.t;++n)r[n]=e(i,t[n]);r.t=t.t}r.s=e(this.s,t.s),r.clamp()}changeBit(t,e){var r=tt.ONE.shiftLeft(t);return this.bitwiseTo(r,e,r),r}addTo(t,e){for(var r=0,n=0,i=Math.min(t.t,this.t);r<i;)n+=this[r]+t[r],e[r++]=n&this.DM,n>>=this.DB;if(t.t<this.t){for(n+=t.s;r<this.t;)n+=this[r],e[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<t.t;)n+=t[r],e[r++]=n&this.DM,n>>=this.DB;n+=t.s}e.s=n<0?-1:0,n>0?e[r++]=n:n<-1&&(e[r++]=this.DV+n),e.t=r,e.clamp()}dMultiply(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}dAddOffset(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}}multiplyLowerTo(t,e,r){var n=Math.min(this.t+t.t,e);for(r.s=0,r.t=n;n>0;)r[--n]=0;for(var i=r.t-this.t;n<i;++n)r[n+this.t]=this.am(0,t[n],r,n,0,this.t);for(i=Math.min(t.t,e);n<i;++n)this.am(0,t[n],r,n,0,e-n);r.clamp()}multiplyUpperTo(t,e,r){--e;var n=r.t=this.t+t.t-e;for(r.s=0;--n>=0;)r[n]=0;for(n=Math.max(e-this.t,0);n<t.t;++n)r[this.t+n-e]=this.am(e-n,t[n],r,0,0,this.t+n-e);r.clamp(),r.drShiftTo(1,r)}modInt(t){if(t<=0)return 0;var e=this.DV%t,r=this.s<0?t-1:0;if(this.t>0)if(0==e)r=this[0]%t;else for(var n=this.t-1;n>=0;--n)r=(e*r+this[n])%t;return r}millerRabin(t){var e=this.subtract(tt.ONE),r=e.getLowestSetBit();if(r<=0)return!1;var n=e.shiftRight(r);(t=t+1>>1)>v.length&&(t=v.length);for(var i=et(),o=0;o<t;++o){i.fromInt(v[Math.floor(Math.random()*v.length)]);var s=i.modPow(n,this);if(0!=s.compareTo(tt.ONE)&&0!=s.compareTo(e)){for(var a=1;a++<r&&0!=s.compareTo(e);)if(0==(s=s.modPowInt(2,this)).compareTo(tt.ONE))return!1;if(0!=s.compareTo(e))return!1}}return!0}square(){var t=et();return this.squareTo(t),t}gcda(t,e){var r=this.s<0?this.negate():this.clone(),n=t.s<0?t.negate():t.clone();if(r.compareTo(n)<0){var i=r;r=n,n=i}var o=r.getLowestSetBit(),s=n.getLowestSetBit();if(s<0)e(r);else{o<s&&(s=o),s>0&&(r.rShiftTo(s,r),n.rShiftTo(s,n));var a=()=>{(o=r.getLowestSetBit())>0&&r.rShiftTo(o,r),(o=n.getLowestSetBit())>0&&n.rShiftTo(o,n),r.compareTo(n)>=0?(r.subTo(n,r),r.rShiftTo(1,r)):(n.subTo(r,n),n.rShiftTo(1,n)),r.signum()>0?setTimeout(a,0):(s>0&&n.lShiftTo(s,n),setTimeout((function(){e(n)}),0))};setTimeout(a,10)}}fromNumberAsync(t,e,r,n){if("number"==typeof e)if(t<2)this.fromInt(1);else{this.fromNumber(t,r),this.testBit(t-1)||this.bitwiseTo(tt.ONE.shiftLeft(t-1),V,this),this.isEven()&&this.dAddOffset(1,0);var i=this,o=function(){i.dAddOffset(2,0),i.bitLength()>t&&i.subTo(tt.ONE.shiftLeft(t-1),i),i.isProbablePrime(e)?setTimeout((function(){n()}),0):setTimeout(o,0)};setTimeout(o,0)}else{var s=[],a=7&t;s.length=1+(t>>3),e.nextBytes(s),a>0?s[0]&=(1<<a)-1:s[0]=0,this.fromString(s,256)}}}var y=function(){function t(){}return t.prototype.convert=function(t){return t},t.prototype.revert=function(t){return t},t.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r)},t.prototype.sqrTo=function(t,e){t.squareTo(e)},t}(),m=function(){function t(t){this.m=t}return t.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},t.prototype.revert=function(t){return t},t.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},t.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r),this.reduce(r)},t.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},t}(),_=function(){function t(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}return t.prototype.convert=function(t){var e=et();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(tt.ZERO)>0&&this.m.subTo(e,e),e},t.prototype.revert=function(t){var e=et();return t.copyTo(e),this.reduce(e),e},t.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var r=32767&t[e],n=r*this.mpl+((r*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[r=e+this.m.t]+=this.m.am(0,n,t,e,0,this.m.t);t[r]>=t.DV;)t[r]-=t.DV,t[++r]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},t.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r),this.reduce(r)},t.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},t}(),b=function(){function t(t){this.m=t,this.r2=et(),this.q3=et(),tt.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t)}return t.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=et();return t.copyTo(e),this.reduce(e),e},t.prototype.revert=function(t){return t},t.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},t.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r),this.reduce(r)},t.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},t}();function et(){return new tt(null)}function rt(t,e){return new tt(t,e)}function nt(t,e,r,n,i,o){for(;--o>=0;){var s=e*this[t++]+r[n]+i;i=Math.floor(s/67108864),r[n++]=67108863&s}return i}function it(t,e,r,n,i,o){for(var s=32767&e,a=e>>15;--o>=0;){var c=32767&this[t],u=this[t++]>>15,l=a*c+u*s;i=((c=s*c+((32767&l)<<15)+r[n]+(1073741823&i))>>>30)+(l>>>15)+a*u+(i>>>30),r[n++]=1073741823&c}return i}function ot(t,e,r,n,i,o){for(var s=16383&e,a=e>>14;--o>=0;){var c=16383&this[t],u=this[t++]>>14,l=a*c+u*s;i=((c=s*c+((16383&l)<<14)+r[n]+i)>>28)+(l>>14)+a*u,r[n++]=268435455&c}return i}void 0!==i&&"Microsoft Internet Explorer"==(null==i?void 0:i.appName)?(tt.prototype.am=it,d=30):"Netscape"!=(null==i?void 0:i.appName)?(tt.prototype.am=nt,d=26):(tt.prototype.am=ot,d=28),tt.prototype.DB=d,tt.prototype.DM=(1<<d)-1,tt.prototype.DV=1<<d,tt.prototype.FV=Math.pow(2,52),tt.prototype.F1=52-d,tt.prototype.F2=2*d-52;var E,T,S=[];for(E="0".charCodeAt(0),T=0;T<=9;++T)S[E++]=T;for(E="a".charCodeAt(0),T=10;T<36;++T)S[E++]=T;for(E="A".charCodeAt(0),T=10;T<36;++T)S[E++]=T;function st(t,e){var r=S[t.charCodeAt(e)];return null==r?-1:r}function at(t){var e=et();return e.fromInt(t),e}function ct(t){var e,r=1;return 0!=(e=t>>>16)&&(t=e,r+=16),0!=(e=t>>8)&&(t=e,r+=8),0!=(e=t>>4)&&(t=e,r+=4),0!=(e=t>>2)&&(t=e,r+=2),0!=(e=t>>1)&&(t=e,r+=1),r}tt.ZERO=at(0),tt.ONE=at(1);class ut{constructor(){this.i=0,this.j=0,this.S=[]}init(t){var e,r,n;for(e=0;e<256;++e)this.S[e]=e;for(r=0,e=0;e<256;++e)r=r+this.S[e]+t[e%t.length]&255,n=this.S[e],this.S[e]=this.S[r],this.S[r]=n;this.i=0,this.j=0}next(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]}}var I,w,O=null;if(null==O){O=[],w=0;var C,R,A=void 0;if("undefined"!=typeof window&&null!==(C=window)&&void 0!==C&&C.crypto&&null!==(R=window)&&void 0!==R&&R.crypto.getRandomValues){var P,N=new Uint32Array(256);for(null===(P=window)||void 0===P||P.crypto.getRandomValues(N),A=0;A<N.length;++A)O[w++]=255&N[A]}var D,U,x,L=function(t){var e,r,n;if(this.count=this.count||0,this.count>=256||w>=256){if("undefined"!=typeof window)if(null!==(e=window)&&void 0!==e&&e.removeEventListener)null===(n=window)||void 0===n||n.removeEventListener("mousemove",L,!1);else if(null!==(r=window)&&void 0!==r&&r.detachEvent){var i;null===(i=window)||void 0===i||i.detachEvent("onmousemove",L)}}else try{var o=t.x+t.y;O[w++]=255&o,this.count+=1}catch(t){}};if("undefined"!=typeof window)if(null!==(D=window)&&void 0!==D&&D.addEventListener)null===(x=window)||void 0===x||x.addEventListener("mousemove",L,!1);else if(null!==(U=window)&&void 0!==U&&U.attachEvent){var k;null===(k=window)||void 0===k||k.attachEvent("onmousemove",L)}}function lt(){if(null==I){for(I=new ut;w<256;){var t=Math.floor(65536*Math.random());O[w++]=255&t}for(I.init(O),w=0;w<O.length;++w)O[w]=0;w=0}return I.next()}class ht{constructor(){}nextBytes(t){for(var e=0;e<t.length;++e)t[e]=lt()}}function dt(t,e){if(e<t.length+11)return console.error("Message too long for RSA"),null;for(var r=[],n=t.length-1;n>=0&&e>0;){var i=t.charCodeAt(n--);i<128?r[--e]=i:i>127&&i<2048?(r[--e]=63&i|128,r[--e]=i>>6|192):(r[--e]=63&i|128,r[--e]=i>>6&63|128,r[--e]=i>>12|224)}r[--e]=0;for(var o=new ht,s=[];e>2;){for(s[0]=0;0==s[0];)o.nextBytes(s);r[--e]=s[0]}return r[--e]=2,r[--e]=0,new tt(r)}class ft{constructor(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}doPublic(t){return t.modPowInt(this.e,this.n)}doPrivate(t){if(null==this.p||null==this.q)return t.modPow(this.d,this.n);for(var e=t.mod(this.p).modPow(this.dmp1,this.p),r=t.mod(this.q).modPow(this.dmq1,this.q);e.compareTo(r)<0;)e=e.add(this.p);return e.subtract(r).multiply(this.coeff).mod(this.p).multiply(this.q).add(r)}setPublic(t,e){null!=t&&null!=e&&t.length>0&&e.length>0?(this.n=rt(t,16),this.e=parseInt(e,16)):console.error("Invalid RSA public key")}encrypt(t){var e=dt(t,this.n.bitLength()+7>>3);if(null==e)return null;var r=this.doPublic(e);if(null==r)return null;var n=r.toString(16);return 1&n.length?"0"+n:n}encryptLong(t){var e=this,r=(this.n.bitLength()+7>>3)-11;try{var n="";return t.length>r?(t.match(/.{1,117}/g).forEach((function(t){var r=e.encrypt(t);n+=r})),z(n)):z(this.encrypt(t))}catch(t){return!1}}decryptLong(t){var e=this,r=this.n.bitLength()+7>>3;t=Y(t);try{if(t.length>r){var n="";return t.match(/.{1,256}/g).forEach((function(t){var r=e.decrypt(t);n+=r})),n}return this.decrypt(t)}catch(t){return!1}}setPrivate(t,e,r){null!=t&&null!=e&&t.length>0&&e.length>0?(this.n=rt(t,16),this.e=parseInt(e,16),this.d=rt(r,16)):console.error("Invalid RSA private key")}setPrivateEx(t,e,r,n,i,o,s,a){null!=t&&null!=e&&t.length>0&&e.length>0?(this.n=rt(t,16),this.e=parseInt(e,16),this.d=rt(r,16),this.p=rt(n,16),this.q=rt(i,16),this.dmp1=rt(o,16),this.dmq1=rt(s,16),this.coeff=rt(a,16)):console.error("Invalid RSA private key")}generate(t,e){var r=new ht,n=t>>1;this.e=parseInt(e,16);for(var i=new tt(e,16);;){for(;this.p=new tt(t-n,1,r),0!=this.p.subtract(tt.ONE).gcd(i).compareTo(tt.ONE)||!this.p.isProbablePrime(10););for(;this.q=new tt(n,1,r),0!=this.q.subtract(tt.ONE).gcd(i).compareTo(tt.ONE)||!this.q.isProbablePrime(10););if(this.p.compareTo(this.q)<=0){var o=this.p;this.p=this.q,this.q=o}var s=this.p.subtract(tt.ONE),a=this.q.subtract(tt.ONE),c=s.multiply(a);if(0==c.gcd(i).compareTo(tt.ONE)){this.n=this.p.multiply(this.q),this.d=i.modInverse(c),this.dmp1=this.d.mod(s),this.dmq1=this.d.mod(a),this.coeff=this.q.modInverse(this.p);break}}}decrypt(t){var e=rt(t,16),r=this.doPrivate(e);return null==r?null:pt(r,this.n.bitLength()+7>>3)}generateAsync(t,e,r){var n=new ht,i=t>>1;this.e=parseInt(e,16);var o=new tt(e,16),s=this,a=()=>{var e=()=>{if(s.p.compareTo(s.q)<=0){var t=s.p;s.p=s.q,s.q=t}var e=s.p.subtract(tt.ONE),n=s.q.subtract(tt.ONE),i=e.multiply(n);0==i.gcd(o).compareTo(tt.ONE)?(s.n=s.p.multiply(s.q),s.d=o.modInverse(i),s.dmp1=s.d.mod(e),s.dmq1=s.d.mod(n),s.coeff=s.q.modInverse(s.p),setTimeout((function(){r()}),0)):setTimeout(a,0)},c=()=>{s.q=et(),s.q.fromNumberAsync(i,1,n,(function(){s.q.subtract(tt.ONE).gcda(o,(function(t){0==t.compareTo(tt.ONE)&&s.q.isProbablePrime(10)?setTimeout(e,0):setTimeout(c,0)}))}))},u=()=>{s.p=et(),s.p.fromNumberAsync(t-i,1,n,(function(){s.p.subtract(tt.ONE).gcda(o,(function(t){0==t.compareTo(tt.ONE)&&s.p.isProbablePrime(10)?setTimeout(c,0):setTimeout(u,0)}))}))};setTimeout(u,0)};setTimeout(a,0)}}function pt(t,e){for(var r=t.toByteArray(),n=0;n<r.length&&0==r[n];)++n;if(r.length-n!=e-1||2!=r[n])return null;for(++n;0!=r[n];)if(++n>=r.length)return null;for(var i="";++n<r.length;){var o=255&r[n];o<128?i+=String.fromCharCode(o):o>191&&o<224?(i+=String.fromCharCode((31&o)<<6|63&r[n+1]),++n):(i+=String.fromCharCode((15&o)<<12|(63&r[n+1])<<6|63&r[n+2]),n+=2)}return i}class vt extends ft{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";super(),t&&("string"==typeof t?this.parseKey(t):(this.hasPrivateKeyProperty(t)||this.hasPublicKeyProperty(t))&&this.parsePropertiesFrom(t))}parseKey(t){try{var e=0,r=0,n=/^\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\s*)+$/.test(t)?u.decode(t):l.unarmor(t),i=X.decode(n);if(3===i.sub.length&&(i=i.sub[2].sub[0]),9===i.sub.length){e=i.sub[1].getHexStringValue(),this.n=rt(e,16),r=i.sub[2].getHexStringValue(),this.e=parseInt(r,16);var o=i.sub[3].getHexStringValue();this.d=rt(o,16);var s=i.sub[4].getHexStringValue();this.p=rt(s,16);var a=i.sub[5].getHexStringValue();this.q=rt(a,16);var c=i.sub[6].getHexStringValue();this.dmp1=rt(c,16);var h=i.sub[7].getHexStringValue();this.dmq1=rt(h,16);var d=i.sub[8].getHexStringValue();this.coeff=rt(d,16)}else{if(2!==i.sub.length)return!1;var f=i.sub[1].sub[0];e=f.sub[0].getHexStringValue(),this.n=rt(e,16),r=f.sub[1].getHexStringValue(),this.e=parseInt(r,16)}return!0}catch(t){return!1}}hasPublicKeyProperty(t){return(t=t||{}).hasOwnProperty("n")&&t.hasOwnProperty("e")}hasPrivateKeyProperty(t){return(t=t||{}).hasOwnProperty("n")&&t.hasOwnProperty("e")&&t.hasOwnProperty("d")&&t.hasOwnProperty("p")&&t.hasOwnProperty("q")&&t.hasOwnProperty("dmp1")&&t.hasOwnProperty("dmq1")&&t.hasOwnProperty("coeff")}parsePropertiesFrom(t){this.n=t.n,this.e=t.e,t.hasOwnProperty("d")&&(this.d=t.d,this.p=t.p,this.q=t.q,this.dmp1=t.dmp1,this.dmq1=t.dmq1,this.coeff=t.coeff)}}(n=function(t){t=t||{},this.default_key_size=parseInt(t.default_key_size,10)||1024,this.default_public_exponent=t.default_public_exponent||"010001",this.log=t.log||!1,this.key=null}).prototype.setKey=function(t){this.log&&this.key&&console.warn("A key was already set, overriding existing."),this.key=new vt(t)},n.prototype.setPrivateKey=function(t){this.setKey(t)},n.prototype.setPublicKey=function(t){this.setKey(t)},n.prototype.decrypt=function(t){try{return this.getKey().decrypt(Y(t))}catch(t){return!1}},n.prototype.encrypt=function(t){try{return z(this.getKey().encrypt(t))}catch(t){return!1}},n.prototype.encryptLong=function(t){try{for(var e=this.getKey().encryptLong(t)||"",r=this.getKey().decryptLong(e)||"",n=0,i=/null$/g;i.test(r)&&(n++,e=this.getKey().encryptLong(t)||"",r=this.getKey().decryptLong(e)||"",!(n>10)););return e}catch(t){return!1}},n.prototype.getKey=function(t){if(!this.key){if(this.key=new vt,t&&"[object Function]"==={}.toString.call(t))return void this.key.generateAsync(this.default_key_size,this.default_public_exponent,t);this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},n.version="3.1.4"}const q=n;var j=r(655),B=function(){var{publicKey:t="",payload:e={}}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!t)return"";try{var r=(0,j.I)(e),n=new q;return n.setPublicKey(t),n.encryptLong("object"==typeof r?JSON.stringify(r):r)}catch(t){console.error("encrypt error:",t)}return""}},655:(t,e,r)=>{r.d(e,{I:()=>n,y:()=>i});var n=t=>{var e=e=>{for(var r in t)t.hasOwnProperty(r)&&(e[r]=n(t[r]));return e},r=null==t?"NullOrUndefined":Object.prototype.toString.call(t).slice(8,-1);if(["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(r))return t.slice();switch(r){case"Object":return e(Object.create(Object.getPrototypeOf(t)));case"Array":return e([]);case"Date":return new Date(t.valueOf());case"RegExp":return new RegExp(t.source,(t.global?"g":"")+(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.sticky?"y":"")+(t.unicode?"u":""));default:return t}},i=t=>{var e=t.match(/^(?:http(s)?:\/\/[^\/]+)?(\/[^\?#]*)/);return e&&e[2]||""}},946:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.COMMUNITY_SITE_URL=e.IS_DEBUG_MODE=e.getProtocol=e.setProtocol=e.getSdkName=e.setSdkName=void 0;var r="@cloudbase/js-sdk";e.setSdkName=function(t){r=t},e.getSdkName=function(){return r};var n="https:";e.setProtocol=function(t){n=t},e.getProtocol=function(){return n},e.IS_DEBUG_MODE=!1,e.COMMUNITY_SITE_URL="https://support.qq.com/products/148793"},205:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ERRORS=void 0,e.ERRORS={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"}},794:function(t,e,r){var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(e,r);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,i)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),i=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),e.OATUH_LOGINTYPE=void 0,i(r(946),e),i(r(205),e),e.OATUH_LOGINTYPE="constants"},689:function(t,e,r){var n,i=this&&this.__extends||(n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},n(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),o=this&&this.__spreadArray||function(t,e,r){if(r||2===arguments.length)for(var n,i=0,o=e.length;i<o;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))};Object.defineProperty(e,"__esModule",{value:!0}),e.removeEventListener=e.activateEvent=e.addEventListener=e.CloudbaseEventEmitter=e.IErrorEvent=e.CloudbaseEvent=void 0;var s=r(616),a=function(t,e){this.data=e||null,this.name=t};e.CloudbaseEvent=a;var c=function(t){function e(e,r){var n=t.call(this,"error",{error:e,data:r})||this;return n.error=e,n}return i(e,t),e}(a);e.IErrorEvent=c;var u=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,r){r[t]=r[t]||[],r[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,r){if(null==r?void 0:r[t]){var n=r[t].indexOf(e);-1!==n&&r[t].splice(n,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if((0,s.isInstanceOf)(t,c))return console.error(t.error),this;var r=(0,s.isString)(t)?new a(t,e||{}):t,n=r.name;if(this.listens(n)){r.target=this;for(var i=0,u=this.listeners[n]?o([],this.listeners[n],!0):[];i<u.length;i++)u[i].call(this,r)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();e.CloudbaseEventEmitter=u;var l=new u;e.addEventListener=function(t,e){l.on(t,e)},e.activateEvent=function(t,e){void 0===e&&(e={}),l.fire(t,e)},e.removeEventListener=function(t,e){l.off(t,e)}},616:function(t,e,r){var n=this&&this.__rest||function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r};Object.defineProperty(e,"__esModule",{value:!0}),e.parseCaptcha=e.parseQueryString=e.transformPhone=e.sleep=e.printGroupLog=e.throwError=e.printInfo=e.printError=e.printWarn=e.execCallback=e.createPromiseCallback=e.removeParam=e.getHash=e.getQuery=e.toQueryString=e.formatUrl=e.generateRequestId=e.genSeqId=e.isFormData=e.isInstanceOf=e.isNull=e.isPalinObject=e.isUndefined=e.isString=e.isArray=void 0;var i=r(794);e.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)},e.isString=function(t){return"string"==typeof t},e.isUndefined=function(t){return void 0===t},e.isPalinObject=function(t){return"[object Object]"===Object.prototype.toString.call(t)},e.isNull=function(t){return"[object Null]"===Object.prototype.toString.call(t)},e.isInstanceOf=function(t,e){return t instanceof e},e.isFormData=function(t){return"[object FormData]"===Object.prototype.toString.call(t)},e.genSeqId=function(){return Math.random().toString(16).slice(2)},e.generateRequestId=function(){var t=(new Date).getTime(),e=(null===Date||void 0===Date?void 0:Date.now)&&1e3*Date.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(r){var n=16*Math.random();return t>0?(n=(t+n)%16|0,t=Math.floor(t/16)):(n=(e+n)%16|0,e=Math.floor(e/16)),("x"===r?n:7&n|8).toString(16)}))},e.formatUrl=function(t,e,r){void 0===r&&(r={});var n=/\?/.test(e),i="";return Object.keys(r).forEach((function(t){""===i?!n&&(e+="?"):i+="&",i+="".concat(t,"=").concat(encodeURIComponent(r[t]))})),/^http(s)?:\/\//.test(e+=i)?e:"".concat(t).concat(e)},e.toQueryString=function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach((function(r){e.push("".concat(r,"=").concat(encodeURIComponent(t[r])))})),e.join("&")},e.getQuery=function(t,e){if("undefined"==typeof window)return!1;var r=e||decodeURIComponent(window.location.search),n=new RegExp("(^|&)".concat(t,"=([^&]*)(&|$)")),i=r.substr(r.indexOf("?")+1).match(n);return null!=i?i[2]:""},e.getHash=function(t){if("undefined"==typeof window)return"";var e=window.location.hash.match(new RegExp("[#?&/]".concat(t,"=([^&#]*)")));return e?e[1]:""},e.removeParam=function(t,e){var r=e.split("?")[0],n=[],i=-1!==e.indexOf("?")?e.split("?")[1]:"";if(""!==i){for(var o=(n=i.split("&")).length-1;o>=0;o-=1)n[o].split("=")[0]===t&&n.splice(o,1);r="".concat(r,"?").concat(n.join("&"))}return r},e.createPromiseCallback=function(){var t={};if(!Promise){(t=function(){}).promise={};var e=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(t.promise,"then",{get:e}),Object.defineProperty(t.promise,"catch",{get:e}),t}var r=new Promise((function(e,r){t=function(t,n){return t?r(t):e(n)}}));return t.promise=r,t},e.execCallback=function(t,e,r){if(void 0===r&&(r=null),t&&"function"==typeof t)return t(e,r);if(e)throw e;return r},e.printWarn=function(t,e){console.warn("[".concat((0,i.getSdkName)(),"][").concat(t,"]:").concat(e))},e.printError=function(t,e){console.error({code:t,msg:"[".concat((0,i.getSdkName)(),"][").concat(t,"]:").concat(e)})},e.printInfo=function(t,e){console.log("[".concat((0,i.getSdkName)(),"][").concat(t,"]:").concat(e))},e.throwError=function(t,e){throw new Error(JSON.stringify({code:t,msg:"[".concat((0,i.getSdkName)(),"][").concat(t,"]:").concat(e)}))},e.printGroupLog=function(t){var e,r=t.title,n=t.subtitle,i=void 0===n?"":n,o=t.content,s=void 0===o?[]:o,a=t.printTrace,c=void 0!==a&&a,u=t.collapsed;void 0!==u&&u?(console.groupCollapsed||console.error)(r,i):(console.group||console.error)(r,i);for(var l=0,h=s;l<h.length;l++){var d=h[l],f=d.type,p=d.body;switch(f){case"info":console.log(p);break;case"warn":console.warn(p);break;case"error":console.error(p)}}c&&(console.trace||console.log)("stack trace:"),null===(e=console.groupEnd)||void 0===e||e.call(console)},e.sleep=function(t){return void 0===t&&(t=0),new Promise((function(e){return setTimeout(e,t)}))},e.transformPhone=function(t){return"+86".concat(t)},e.parseQueryString=function(t){t=t.replace(/^\?/,"");var e={};return t.split("&").forEach((function(t){var r=t.split("="),n=r[0],i=r[1];n=decodeURIComponent(n),i=decodeURIComponent(i),n&&(e[n]?Array.isArray(e[n])?e[n].push(i):e[n]=[e[n],i]:e[n]=i)})),e},e.parseCaptcha=function(t){var r={},i=t.match(/^(data:.*?)(\?[^#\s]*)?$/);if(i){t=i[1];var o=i[2];o&&(r=(0,e.parseQueryString)(o))}var s=r.token,a=n(r,["token"]);return/^data:/.test(t)&&!s?{error:"invalid_argument",error_description:"invalid captcha data: ".concat(t)}:s?{state:a.state,token:s,captchaData:t}:{error:"unimplemented",error_description:"need to impl captcha data"}}}},e={};function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}return r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r(118)})()));