1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6123],{36123:(e,t,s)=>{s.d(t,{ReownAuthentication:()=>d});var r=s(55257),o=s(96853),n=s(48083),i=s(7022),a=s(38521),c=s(81805),h=s(194);class u{constructor(e){this.getNonce=e.getNonce}async createMessage(e){let t={accountAddress:e.accountAddress,chainId:e.chainId,version:"1",domain:"undefined"==typeof document?"Unknown Domain":document.location.host,uri:"undefined"==typeof document?"Unknown URI":document.location.href,resources:this.resources,nonce:await this.getNonce(e),issuedAt:this.stringifyDate(new Date),statement:void 0,expirationTime:void 0,notBefore:void 0};return Object.assign(t,{toString:()=>this.stringify(t)})}stringify(e){let t=this.getNetworkName(e.chainId);return[`${e.domain} wants you to sign in with your ${t} account:`,e.accountAddress,e.statement?` 2${e.statement} 3`:"",`URI: ${e.uri}`,`Version: ${e.version}`,`Chain ID: ${e.chainId}`,`Nonce: ${e.nonce}`,e.issuedAt&&`Issued At: ${e.issuedAt}`,e.expirationTime&&`Expiration Time: ${e.expirationTime}`,e.notBefore&&`Not Before: ${e.notBefore}`,e.requestId&&`Request ID: ${e.requestId}`,e.resources?.length&&e.resources.reduce((e,t)=>`${e} 4- ${t}`,"Resources:")].filter(e=>"string"==typeof e).join("\n").trim()}getNetworkName(e){let t=a.W.getAllRequestedCaipNetworks();return h.L.getNetworkNameByCaipNetworkId(t,e)}stringifyDate(e){return e.toISOString()}}class d{constructor(e={}){this.otpUuid=null,this.listeners={sessionChanged:[]},this.localAuthStorageKey=e.localAuthStorageKey||r.Ws.SIWX_AUTH_TOKEN,this.localNonceStorageKey=e.localNonceStorageKey||r.Ws.SIWX_NONCE_TOKEN,this.required=e.required??!0,this.messenger=new u({getNonce:this.getNonce.bind(this)})}async createMessage(e){return this.messenger.createMessage(e)}async addSession(e){let t=await this.request({method:"POST",key:"authenticate",body:{data:e.data,message:e.message,signature:e.signature,clientId:this.getClientId(),walletInfo:this.getWalletInfo()},headers:["nonce","otp"]});this.setStorageToken(t.token,this.localAuthStorageKey),this.emit("sessionChanged",e),this.setAppKitAccountUser(function(e){let t=e.split(".");if(3!==t.length)throw Error("Invalid token");let s=t[1];if("string"!=typeof s)throw Error("Invalid token");let r=s.replace(/-/gu,"+").replace(/_/gu,"/");return JSON.parse(atob(r.padEnd(r.length+(4-r.length%4)%4,"=")))}(t.token)),this.otpUuid=null}async getSessions(e,t){try{if(!this.getStorageToken(this.localAuthStorageKey))return[];let s=await this.request({method:"GET",key:"me",query:{},headers:["auth"]});if(!s)return[];let r=s.address.toLowerCase()===t.toLowerCase(),o=s.caip2Network===e;if(!r||!o)return[];let n={data:{accountAddress:s.address,chainId:s.caip2Network},message:"",signature:""};return this.emit("sessionChanged",n),this.setAppKitAccountUser(s),[n]}catch{return[]}}async revokeSession(e,t){return Promise.resolve(this.clearStorageTokens())}async setSessions(e){if(0===e.length)this.clearStorageTokens();else{let t=e.find(e=>e.data.chainId===(0,c.kg)()?.caipNetworkId)||e[0];await this.addSession(t)}}getRequired(){return this.required}async getSessionAccount(){if(!this.getStorageToken(this.localAuthStorageKey))throw Error("Not authenticated");return this.request({method:"GET",key:"me",body:void 0,query:{includeAppKitAccount:!0},headers:["auth"]})}async setSessionAccountMetadata(e=null){if(!this.getStorageToken(this.localAuthStorageKey))throw Error("Not authenticated");return this.request({method:"PUT",key:"account-metadata",body:{metadata:e},headers:["auth"]})}on(e,t){return this.listeners[e].push(t),()=>{this.listeners[e]=this.listeners[e].filter(e=>e!==t)}}removeAllListeners(){Object.keys(this.listeners).forEach(e=>{this.listeners[e]=[]})}async requestEmailOtp({email:e,account:t}){let s=await this.request({method:"POST",key:"otp",body:{email:e,account:t}});return this.otpUuid=s.uuid,this.messenger.resources=[`email:${e}`],s}confirmEmailOtp({code:e}){return this.request({method:"PUT",key:"otp",body:{code:e},headers:["otp"]})}async request({method:e,key:t,query:s,body:r,headers:n}){let{projectId:i,st:a,sv:c}=this.getSDKProperties(),h=new URL(`${o.o.W3M_API_URL}/auth/v1/${String(t)}`);h.searchParams.set("projectId",i),h.searchParams.set("st",a),h.searchParams.set("sv",c),s&&Object.entries(s).forEac
4h(([e,t])=>h.searchParams.set(e,String(t)));let u=await fetch(h,{method:e,body:r?JSON.stringify(r):void 0,headers:Array.isArray(n)?n.reduce((e,t)=>{switch(t){case"nonce":e["x-nonce-jwt"]=`Bearer ${this.getStorageToken(this.localNonceStorageKey)}`;break;case"auth":e.Authorization=`Bearer ${this.getStorageToken(this.localAuthStorageKey)}`;break;case"otp":this.otpUuid&&(e["x-otp"]=this.otpUuid)}return e},{}):void 0});if(!u.ok)throw Error(await u.text());return u.headers.get("content-type")?.includes("application/json")?u.json():null}getStorageToken(e){return r.Ud.getItem(e)}setStorageToken(e,t){r.Ud.setItem(t,e)}clearStorageTokens(){this.otpUuid=null,r.Ud.removeItem(this.localAuthStorageKey),r.Ud.removeItem(this.localNonceStorageKey),this.emit("sessionChanged",void 0)}async getNonce(){let{nonce:e,token:t}=await this.request({method:"GET",key:"nonce"});return this.setStorageToken(t,this.localNonceStorageKey),e}getClientId(){return i.T.state.clientId}getWalletInfo(){let e=a.W.getAccountData()?.connectedWalletInfo;if(!e)return;if("social"in e&&"identifier"in e)return{type:"social",social:e.social,identifier:e.identifier};let{name:t,icon:s}=e,r="unknown";switch(e.type){case"EXTERNAL":case"INJECTED":case"ANNOUNCED":r="extension";break;case"WALLET_CONNECT":r="walletconnect";break;default:r="unknown"}return{type:r,name:t,icon:s}}getSDKProperties(){return n.N._getSdkProperties()}emit(e,t){this.listeners[e].forEach(e=>e(t))}setAppKitAccountUser(e){let{email:t}=e;
4t&&Object.values(o.o.CHAIN).forEach(e=>{a.W.setAccountProp("user",{email:t},e)})}}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.