@privy-io/react-auth 1.13.0-beta.6 → 1.13.0-beta.7

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.
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{useEffect as bi,useMemo as qs,useState as me}from"react";import Bt from"axios";import Ci from"axios";var z=class extends Error{constructor(o,r){super(o);r instanceof Error&&(this.cause=r)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},ke=class extends z{constructor(o,r,i,n){super(i,n);this.type=o;this.status=r}},c=class extends z{constructor(o,r){super(o,r);this.type="client_error"}};var G=class extends z{constructor(o,r){super(o,r);this.type="connector_error"}},S=t=>{if(t instanceof z)return t;if(!Ci.isAxiosError(t))return V(t);if(!t.response)return new ke("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new ke(e||"ApiError",t.response.status,o||r,t)},V=t=>t instanceof z?t:t instanceof Error?new c(t.message,t):new c(`Internal error: ${t}`);var bo="1.13.0-beta.6";var vo="https://api.privy.io/v0",Co=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",et="4df5e2316331463a9130964bd6078dfa",xo=1e4,_e=1400,Vt=bo;var Pe="privy:token",tt="privy:refresh_token",Z="privy:active_wallet",ot="privy:wallet_type",Lo="walletconnect";var rt=class{constructor(e,o,r){this.appId=e,this.sdkVersion=Vt,this.client=o,this.defaults=r}async get(e,o){try{return await Bt.get(e,await this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(r){throw S(r)}}async post(e,o,r){try{return await Bt.post(e,o,await this.buildConfig(r))}catch(i){throw S(i)}}async delete(e,o){try{return await Bt.delete(e,await this.buildConfig(o))}catch(r){throw S(r)}}async buildConfig(e){if(e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-client"]=`react-auth:${this.sdkVersion}`,!e.headers.authorization){let o=await this.client.getAccessToken();o!==null&&(e.headers.authorization=`Bearer ${o}`)}return{...this.defaults,...e}}};import*as Ao from"jose";var Y=class{static parse(e){try{return new Y(e)}catch{return null}}constructor(e){this.value=e,this._decoded=Ao.decodeJwt(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}get issuer(){return this._decoded.iss}get audience(){return this._decoded.aud}isExpired(e=0){let o=Date.now(),r=(this.expiration-e)*1e3;return o>=r}};var ne=class{constructor(e){this.promise=null;this.fn=e}execute(e){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(e)}finally{this.promise=null}})()),this.promise}};var Ht=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,o){o!==void 0?this._cache[e]=o:this.del(e)}del(e){delete this._cache[e]}},zt=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}};function Li(){return typeof window<"u"&&window.localStorage?new zt:new Ht}var k=Li();function se(t){return new Date(t*1e3)}function Ai(t){return t.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:se(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:se(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:se(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:se(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:se(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:se(e.verified_at)};case"github_oauth":return{subject:e.subject,username:e.username,name:e.name,email:e.email,type:e.type,verifiedAt:se(e.verified_at)};default:throw new c("Unrecognized account type")}})}function Ei(t,e){return e.find(o=>o.type==="wallet"&&o.address===t)}function ae(t,e){return t.sort((o,r)=>r.verifiedAt.getTime()-o.verifiedAt.getTime()),t.find(o=>o.type===e)}function Ge(t){let e=t.linkedAccounts.map(s=>s.type==="wallet"?s.address:null),r=k.get(Z);if(!r||!e.includes(r)){k.del(Z);let s=ae(t.linkedAccounts,"wallet");s&&(r=s.address,k.put(Z,r))}let i=Ei(r,t.linkedAccounts),n=Object.assign({},t);return n.wallet=i&&{address:i.address,chainType:i.chainType,chainId:i.chainId,walletType:i.walletType},n}function Q(t){if(!t)return null;let e=Ai(t.linked_accounts),o=ae(e,"wallet"),r=ae(e,"email"),i=ae(e,"phone"),n=ae(e,"google_oauth"),s=ae(e,"twitter_oauth"),u=ae(e,"discord_oauth"),h=ae(e,"github_oauth"),m={id:t.id,createdAt:se(t.created_at),linkedAccounts:e,email:r&&{address:r==null?void 0:r.address},phone:i&&{number:i==null?void 0:i.number},wallet:o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},google:n&&{subject:n.subject,email:n.email,name:n.name},twitter:s&&{subject:s.subject,username:s.username,name:s.name},discord:u&&{subject:u.subject,username:u.username,email:u.email},github:h&&{subject:h.subject,username:h.username,name:h.name,email:h.email}};return Ge(m)}var Eo=()=>"/api/v1/sessions",ko=()=>"/api/v1/sessions/logout",_o=()=>"/api/v1/sessions/fork",Po=()=>"/api/v1/siwe/init",So=()=>"/api/v1/siwe/authenticate",To=()=>"/api/v1/siwe/link",Io=()=>"/api/v1/passwordless/init",Ro=()=>"/api/v1/passwordless/authenticate",Mo=()=>"/api/v1/passwordless/link",Wo=()=>"/api/v1/passwordless_sms/init",No=()=>"/api/v1/passwordless_sms/authenticate",Oo=()=>"/api/v1/passwordless_sms/link",Uo=()=>"/api/v1/oauth/init",Do=()=>"/api/v1/oauth/authenticate",Fo=()=>"/api/v1/oauth/link",Go=()=>"/api/v1/siwe/unlink",Vo=()=>"/api/v1/passwordless/unlink",Bo=()=>"/api/v1/passwordless_sms/unlink",Ho=()=>"/api/v1/oauth/unlink";var ki=30,it=class{constructor(){this.authenticateOnce=new ne(async e=>this._authenticate(e)),this.linkOnce=new ne(async e=>this._link(e)),this.refreshOnce=new ne(this._refresh.bind(this)),this.destroyOnce=new ne(this._destroy.bind(this)),this.forkSessionOnce=new ne(this._forkSession.bind(this))}get token(){try{let e=k.get(Pe);return typeof e=="string"?new Y(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=k.get(tt);return typeof e=="string"?e:null}catch(e){return console.error(e),this.destroyLocalState(),null}}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=Y.parse(this.token);return e!==null&&!e.isExpired(ki)}authenticate(e){return this.authenticateOnce.execute(e)}link(e){return this.linkOnce.execute(e)}refresh(){return this.refreshOnce.execute()}forkSession(){return this.forkSessionOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:o,refresh_token:r,user:i,is_new_user:n}=await e.authenticate();return this.storeToken(o),this.storeRefreshToken(r),{user:Q(i),isNewUser:n}}catch(o){throw console.warn("Error authenticating session"),V(o)}}async _link(e){try{let o=await e.link();return Q(o)}catch(o){throw console.warn("Error linking account"),V(o)}}async _refresh(){if(!this.api)throw new c("Session has no API instance");if(!this.client)throw new c("Session has no PrivyClient instance");let e=await this.client.getAccessToken({disableAutoRefresh:!0}),o=this.refreshToken;if(!e||!o)return null;try{let r=await this.api.post(Eo(),{refresh_token:o},{headers:{authorization:`Bearer ${this.token}`}});return this.storeToken(r.data.token),this.storeRefreshToken(r.data.refresh_token),Q(r.data.user)}catch(r){if(r instanceof ke&&r.status===400&&r.message==="Invalid auth token")return this.destroyLocalState(),null;throw V(r)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(ko(),{refresh_token:this.refreshToken}))}catch{console.warn("Error destroying session")}this.destroyLocalState()}async _forkSession(){if(!this.api)throw new c("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(_o(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw V(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null),k.del(Z)}storeToken(e){typeof e=="string"?k.put(Pe,e):k.del(Pe)}storeRefreshToken(e){typeof e=="string"?k.put(tt,e):k.del(tt)}};import{getAddress as Ri}from"@ethersproject/address";import jo from"@walletconnect/web3-provider";import{ErrorCode as _i}from"@ethersproject/logger";var Se=class extends G{constructor(){super("Wallet timeout");this.type="wallet_error"}},nt=t=>{if(t instanceof G)return t;if((t==null?void 0:t.code)&&(t==null?void 0:t.reason)){let e=new Te(t);return t.code===_i.ACTION_REJECTED&&(e.details=ge.E4001_USER_REJECTED_REQUEST),e}return t!=null&&t.code?new Te(t):new G("Unknown connector error",t)},jt=class extends z{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},Te=class extends jt{constructor(o){var n,s,u;let r=o;super(r.message,r.code,r.data);let i=Object.values(ge).find(h=>h.eipCode===r.code);this.details=i||ge.UNKNOWN_ERROR,r.code===-32002&&((n=r.message)!=null&&n.includes("already pending for origin")?(s=r.message)!=null&&s.includes("wallet_requestPermissions")?this.details=ge.E32002_CONNECTION_ALREADY_PENDING:this.details=ge.E32002_REQUEST_ALREADY_PENDING:(u=r.message)!=null&&u.includes("Already processing")&&r.message.includes("eth_requestAccounts")&&(this.details=ge.E32002_WALLET_LOCKED))}},Pi={ERROR_USER_EXISTS:{message:"User already exists for this address",detail:"Try another address!",retryable:!1},ERROR_TIMED_OUT:{message:"Wallet request timed out",detail:"Please try connecting again.",retryable:!0},ERROR_WALLET_CONNECTION:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0}},Si={E32002_CONNECTION_ALREADY_PENDING:{eipCode:-32002,message:"Connection request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_REQUEST_ALREADY_PENDING:{eipCode:-32002,message:"Resource request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_WALLET_LOCKED:{eipCode:-32002,message:"Wallet might be locked",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E4001_USER_REJECTED_REQUEST:{eipCode:4001,message:"Signature rejected",detail:"Please try signing again.",retryable:!0}},Ti={E4001_DEFAULT_USER_REJECTED_REQUEST:{eipCode:4001,message:"User Rejected Request",detail:"The user rejected the request.",default:!0,retryable:!0},E4100_DEFAULT_UNAUTHORIZED:{eipCode:4100,message:"Unauthorized",detail:"The requested method and/or account has not been authorized by the user.",default:!0,retryable:!1},E4200_DEFAULT_UNSUPPORTED_METHOD:{eipCode:4200,message:"Unsupported Method",detail:"The Provider does not support the requested method.",default:!0,retryable:!1},E4900_DEFAULT_DISCONNECTED:{eipCode:4900,message:"Disconnected",detail:"The Provider is disconnected from all chains.",default:!0,retryable:!0},E4901_DEFAULT_CHAIN_DISCONNECTED:{eipCode:4901,message:"Chain Disconnected",detail:"The Provider is not connected to the requested chain.",default:!0,retryable:!0},E32700_DEFAULT_PARSE_ERROR:{eipCode:-32700,message:"Parse error",detail:"Invalid JSON",default:!0,retryable:!1},E32600_DEFAULT_INVALID_REQUEST:{eipCode:-32600,message:"Invalid request",detail:"JSON is not a valid request object",default:!0,retryable:!1},E32601_DEFAULT_METHOD_NOT_FOUND:{eipCode:-32601,message:"Method not found",detail:"Method does not exist",default:!0,retryable:!1},E32602_DEFAULT_INVALID_PARAMS:{eipCode:-32602,message:"Invalid params",detail:"Invalid method parameters",default:!0,retryable:!1},E32603_DEFAULT_INTERNAL_ERROR:{eipCode:-32603,message:"Internal error",detail:"Internal JSON-RPC error",default:!0,retryable:!0},E32000_DEFAULT_INVALID_INPUT:{eipCode:-32e3,message:"Invalid input",detail:"Missing or invalid parameters",default:!0,retryable:!1},E32001_DEFAULT_RESOURCE_NOT_FOUND:{eipCode:-32001,message:"Resource not found",detail:"Requested resource not found",default:!0,retryable:!1},E32002_DEFAULT_RESOURCE_UNAVAILABLE:{eipCode:-32002,message:"Resource unavailable",detail:"Requested resource not available",default:!0,retryable:!0},E32003_DEFAULT_TRANSACTION_REJECTED:{eipCode:-32003,message:"Transaction rejected",detail:"Transaction creation failed",default:!0,retryable:!0},E32004_DEFAULT_METHOD_NOT_SUPPORTED:{eipCode:-32004,message:"Method not supported",detail:"Method is not implemented",default:!0,retryable:!1},E32005_DEFAULT_LIMIT_EXCEEDED:{eipCode:-32005,message:"Limit exceeded",detail:"Request exceeds defined limit",default:!0,retryable:!1},E32006_DEFAULT_JSON_RPC_VERSION_NOT_SUPPORTED:{eipCode:-32006,message:"JSON-RPC version not supported",detail:"Version of JSON-RPC protocol is not supported",default:!0,retryable:!1}},ge={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...Ti,...Si},st={...Pi,...ge};var Ii=12e4,$t=(t=new Se,e=Ii)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),we=class{constructor(e){this.removeListener=(e,o)=>{if(this.walletProvider)return this.walletProvider.removeListener(e,o)};this.setProvider=e=>{this.walletProvider=e,this._subscriptions.forEach(o=>{var r;(r=this.walletProvider)==null||r.on(o.eventName,o.listener)})};this.walletProvider=e,this._subscriptions=[]}on(e,o){if(this.walletProvider)return this.walletProvider.on(e,o);this._subscriptions.push({eventName:e,listener:o})}request(e){if(!this.walletProvider)throw new G(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),$t()]).catch(o=>{throw nt(o)})}},ye=class extends we{constructor(o){super(o)}},at=class extends we{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};import{Web3Provider as Mi}from"@ethersproject/providers";var zo=["metamask","coinbase_wallet","wallet_connect"];import Wi from"@coinbase/wallet-sdk";import{isMobile as Ni}from"react-device-detect";var Oi=()=>{let t=`https://mainnet.infura.io/v3/${et}`,e=1;return new Wi({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(t,e)},Zt=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let t of window.ethereum.providers)if(t.isMetaMask)return!0}return!1},lt=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let t of window.ethereum.providers)if(t.isCoinbaseWallet)return!0}return!1},Ve=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,r,i,n,s,u)=>`${r} wants you to sign in with your Ethereum account:
1
+ import{useEffect as bi,useState as me}from"react";import Bt from"axios";import Ci from"axios";var z=class extends Error{constructor(o,r){super(o);r instanceof Error&&(this.cause=r)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},ke=class extends z{constructor(o,r,i,n){super(i,n);this.type=o;this.status=r}},c=class extends z{constructor(o,r){super(o,r);this.type="client_error"}};var G=class extends z{constructor(o,r){super(o,r);this.type="connector_error"}},S=t=>{if(t instanceof z)return t;if(!Ci.isAxiosError(t))return V(t);if(!t.response)return new ke("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new ke(e||"ApiError",t.response.status,o||r,t)},V=t=>t instanceof z?t:t instanceof Error?new c(t.message,t):new c(`Internal error: ${t}`);var bo="1.13.0-beta.7";var vo="https://api.privy.io/v0",Co=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",et="4df5e2316331463a9130964bd6078dfa",xo=1e4,_e=1400,Vt=bo;var Pe="privy:token",tt="privy:refresh_token",Z="privy:active_wallet",ot="privy:wallet_type",Lo="walletconnect";var rt=class{constructor(e,o,r){this.appId=e,this.sdkVersion=Vt,this.client=o,this.defaults=r}async get(e,o){try{return await Bt.get(e,await this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(r){throw S(r)}}async post(e,o,r){try{return await Bt.post(e,o,await this.buildConfig(r))}catch(i){throw S(i)}}async delete(e,o){try{return await Bt.delete(e,await this.buildConfig(o))}catch(r){throw S(r)}}async buildConfig(e){if(e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-client"]=`react-auth:${this.sdkVersion}`,!e.headers.authorization){let o=await this.client.getAccessToken();o!==null&&(e.headers.authorization=`Bearer ${o}`)}return{...this.defaults,...e}}};import*as Ao from"jose";var Y=class{static parse(e){try{return new Y(e)}catch{return null}}constructor(e){this.value=e,this._decoded=Ao.decodeJwt(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}get issuer(){return this._decoded.iss}get audience(){return this._decoded.aud}isExpired(e=0){let o=Date.now(),r=(this.expiration-e)*1e3;return o>=r}};var ne=class{constructor(e){this.promise=null;this.fn=e}execute(e){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(e)}finally{this.promise=null}})()),this.promise}};var Ht=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,o){o!==void 0?this._cache[e]=o:this.del(e)}del(e){delete this._cache[e]}},zt=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}};function Li(){return typeof window<"u"&&window.localStorage?new zt:new Ht}var k=Li();function se(t){return new Date(t*1e3)}function Ai(t){return t.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:se(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:se(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:se(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:se(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:se(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:se(e.verified_at)};case"github_oauth":return{subject:e.subject,username:e.username,name:e.name,email:e.email,type:e.type,verifiedAt:se(e.verified_at)};default:throw new c("Unrecognized account type")}})}function Ei(t,e){return e.find(o=>o.type==="wallet"&&o.address===t)}function ae(t,e){return t.sort((o,r)=>r.verifiedAt.getTime()-o.verifiedAt.getTime()),t.find(o=>o.type===e)}function Ge(t){let e=t.linkedAccounts.map(s=>s.type==="wallet"?s.address:null),r=k.get(Z);if(!r||!e.includes(r)){k.del(Z);let s=ae(t.linkedAccounts,"wallet");s&&(r=s.address,k.put(Z,r))}let i=Ei(r,t.linkedAccounts),n=Object.assign({},t);return n.wallet=i&&{address:i.address,chainType:i.chainType,chainId:i.chainId,walletType:i.walletType},n}function Q(t){if(!t)return null;let e=Ai(t.linked_accounts),o=ae(e,"wallet"),r=ae(e,"email"),i=ae(e,"phone"),n=ae(e,"google_oauth"),s=ae(e,"twitter_oauth"),u=ae(e,"discord_oauth"),h=ae(e,"github_oauth"),m={id:t.id,createdAt:se(t.created_at),linkedAccounts:e,email:r&&{address:r==null?void 0:r.address},phone:i&&{number:i==null?void 0:i.number},wallet:o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},google:n&&{subject:n.subject,email:n.email,name:n.name},twitter:s&&{subject:s.subject,username:s.username,name:s.name},discord:u&&{subject:u.subject,username:u.username,email:u.email},github:h&&{subject:h.subject,username:h.username,name:h.name,email:h.email}};return Ge(m)}var Eo=()=>"/api/v1/sessions",ko=()=>"/api/v1/sessions/logout",_o=()=>"/api/v1/sessions/fork",Po=()=>"/api/v1/siwe/init",So=()=>"/api/v1/siwe/authenticate",To=()=>"/api/v1/siwe/link",Io=()=>"/api/v1/passwordless/init",Ro=()=>"/api/v1/passwordless/authenticate",Mo=()=>"/api/v1/passwordless/link",Wo=()=>"/api/v1/passwordless_sms/init",No=()=>"/api/v1/passwordless_sms/authenticate",Oo=()=>"/api/v1/passwordless_sms/link",Uo=()=>"/api/v1/oauth/init",Do=()=>"/api/v1/oauth/authenticate",Fo=()=>"/api/v1/oauth/link",Go=()=>"/api/v1/siwe/unlink",Vo=()=>"/api/v1/passwordless/unlink",Bo=()=>"/api/v1/passwordless_sms/unlink",Ho=()=>"/api/v1/oauth/unlink";var ki=30,it=class{constructor(){this.authenticateOnce=new ne(async e=>this._authenticate(e)),this.linkOnce=new ne(async e=>this._link(e)),this.refreshOnce=new ne(this._refresh.bind(this)),this.destroyOnce=new ne(this._destroy.bind(this)),this.forkSessionOnce=new ne(this._forkSession.bind(this))}get token(){try{let e=k.get(Pe);return typeof e=="string"?new Y(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=k.get(tt);return typeof e=="string"?e:null}catch(e){return console.error(e),this.destroyLocalState(),null}}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=Y.parse(this.token);return e!==null&&!e.isExpired(ki)}authenticate(e){return this.authenticateOnce.execute(e)}link(e){return this.linkOnce.execute(e)}refresh(){return this.refreshOnce.execute()}forkSession(){return this.forkSessionOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:o,refresh_token:r,user:i,is_new_user:n}=await e.authenticate();return this.storeToken(o),this.storeRefreshToken(r),{user:Q(i),isNewUser:n}}catch(o){throw console.warn("Error authenticating session"),V(o)}}async _link(e){try{let o=await e.link();return Q(o)}catch(o){throw console.warn("Error linking account"),V(o)}}async _refresh(){if(!this.api)throw new c("Session has no API instance");if(!this.client)throw new c("Session has no PrivyClient instance");let e=await this.client.getAccessToken({disableAutoRefresh:!0}),o=this.refreshToken;if(!e||!o)return null;try{let r=await this.api.post(Eo(),{refresh_token:o},{headers:{authorization:`Bearer ${this.token}`}});return this.storeToken(r.data.token),this.storeRefreshToken(r.data.refresh_token),Q(r.data.user)}catch(r){if(r instanceof ke&&r.status===400&&r.message==="Invalid auth token")return this.destroyLocalState(),null;throw V(r)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(ko(),{refresh_token:this.refreshToken}))}catch{console.warn("Error destroying session")}this.destroyLocalState()}async _forkSession(){if(!this.api)throw new c("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(_o(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw V(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null),k.del(Z)}storeToken(e){typeof e=="string"?k.put(Pe,e):k.del(Pe)}storeRefreshToken(e){typeof e=="string"?k.put(tt,e):k.del(tt)}};import{getAddress as Ri}from"@ethersproject/address";import jo from"@walletconnect/web3-provider";import{ErrorCode as _i}from"@ethersproject/logger";var Se=class extends G{constructor(){super("Wallet timeout");this.type="wallet_error"}},nt=t=>{if(t instanceof G)return t;if((t==null?void 0:t.code)&&(t==null?void 0:t.reason)){let e=new Te(t);return t.code===_i.ACTION_REJECTED&&(e.details=ge.E4001_USER_REJECTED_REQUEST),e}return t!=null&&t.code?new Te(t):new G("Unknown connector error",t)},jt=class extends z{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},Te=class extends jt{constructor(o){var n,s,u;let r=o;super(r.message,r.code,r.data);let i=Object.values(ge).find(h=>h.eipCode===r.code);this.details=i||ge.UNKNOWN_ERROR,r.code===-32002&&((n=r.message)!=null&&n.includes("already pending for origin")?(s=r.message)!=null&&s.includes("wallet_requestPermissions")?this.details=ge.E32002_CONNECTION_ALREADY_PENDING:this.details=ge.E32002_REQUEST_ALREADY_PENDING:(u=r.message)!=null&&u.includes("Already processing")&&r.message.includes("eth_requestAccounts")&&(this.details=ge.E32002_WALLET_LOCKED))}},Pi={ERROR_USER_EXISTS:{message:"User already exists for this address",detail:"Try another address!",retryable:!1},ERROR_TIMED_OUT:{message:"Wallet request timed out",detail:"Please try connecting again.",retryable:!0},ERROR_WALLET_CONNECTION:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0}},Si={E32002_CONNECTION_ALREADY_PENDING:{eipCode:-32002,message:"Connection request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_REQUEST_ALREADY_PENDING:{eipCode:-32002,message:"Resource request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_WALLET_LOCKED:{eipCode:-32002,message:"Wallet might be locked",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E4001_USER_REJECTED_REQUEST:{eipCode:4001,message:"Signature rejected",detail:"Please try signing again.",retryable:!0}},Ti={E4001_DEFAULT_USER_REJECTED_REQUEST:{eipCode:4001,message:"User Rejected Request",detail:"The user rejected the request.",default:!0,retryable:!0},E4100_DEFAULT_UNAUTHORIZED:{eipCode:4100,message:"Unauthorized",detail:"The requested method and/or account has not been authorized by the user.",default:!0,retryable:!1},E4200_DEFAULT_UNSUPPORTED_METHOD:{eipCode:4200,message:"Unsupported Method",detail:"The Provider does not support the requested method.",default:!0,retryable:!1},E4900_DEFAULT_DISCONNECTED:{eipCode:4900,message:"Disconnected",detail:"The Provider is disconnected from all chains.",default:!0,retryable:!0},E4901_DEFAULT_CHAIN_DISCONNECTED:{eipCode:4901,message:"Chain Disconnected",detail:"The Provider is not connected to the requested chain.",default:!0,retryable:!0},E32700_DEFAULT_PARSE_ERROR:{eipCode:-32700,message:"Parse error",detail:"Invalid JSON",default:!0,retryable:!1},E32600_DEFAULT_INVALID_REQUEST:{eipCode:-32600,message:"Invalid request",detail:"JSON is not a valid request object",default:!0,retryable:!1},E32601_DEFAULT_METHOD_NOT_FOUND:{eipCode:-32601,message:"Method not found",detail:"Method does not exist",default:!0,retryable:!1},E32602_DEFAULT_INVALID_PARAMS:{eipCode:-32602,message:"Invalid params",detail:"Invalid method parameters",default:!0,retryable:!1},E32603_DEFAULT_INTERNAL_ERROR:{eipCode:-32603,message:"Internal error",detail:"Internal JSON-RPC error",default:!0,retryable:!0},E32000_DEFAULT_INVALID_INPUT:{eipCode:-32e3,message:"Invalid input",detail:"Missing or invalid parameters",default:!0,retryable:!1},E32001_DEFAULT_RESOURCE_NOT_FOUND:{eipCode:-32001,message:"Resource not found",detail:"Requested resource not found",default:!0,retryable:!1},E32002_DEFAULT_RESOURCE_UNAVAILABLE:{eipCode:-32002,message:"Resource unavailable",detail:"Requested resource not available",default:!0,retryable:!0},E32003_DEFAULT_TRANSACTION_REJECTED:{eipCode:-32003,message:"Transaction rejected",detail:"Transaction creation failed",default:!0,retryable:!0},E32004_DEFAULT_METHOD_NOT_SUPPORTED:{eipCode:-32004,message:"Method not supported",detail:"Method is not implemented",default:!0,retryable:!1},E32005_DEFAULT_LIMIT_EXCEEDED:{eipCode:-32005,message:"Limit exceeded",detail:"Request exceeds defined limit",default:!0,retryable:!1},E32006_DEFAULT_JSON_RPC_VERSION_NOT_SUPPORTED:{eipCode:-32006,message:"JSON-RPC version not supported",detail:"Version of JSON-RPC protocol is not supported",default:!0,retryable:!1}},ge={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...Ti,...Si},st={...Pi,...ge};var Ii=12e4,$t=(t=new Se,e=Ii)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),we=class{constructor(e){this.removeListener=(e,o)=>{if(this.walletProvider)return this.walletProvider.removeListener(e,o)};this.setProvider=e=>{this.walletProvider=e,this._subscriptions.forEach(o=>{var r;(r=this.walletProvider)==null||r.on(o.eventName,o.listener)})};this.walletProvider=e,this._subscriptions=[]}on(e,o){if(this.walletProvider)return this.walletProvider.on(e,o);this._subscriptions.push({eventName:e,listener:o})}request(e){if(!this.walletProvider)throw new G(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),$t()]).catch(o=>{throw nt(o)})}},ye=class extends we{constructor(o){super(o)}},at=class extends we{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};import{Web3Provider as Mi}from"@ethersproject/providers";var zo=["metamask","coinbase_wallet","wallet_connect"];import Wi from"@coinbase/wallet-sdk";import{isMobile as Ni}from"react-device-detect";var Oi=()=>{let t=`https://mainnet.infura.io/v3/${et}`,e=1;return new Wi({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(t,e)},Zt=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let t of window.ethereum.providers)if(t.isMetaMask)return!0}return!1},lt=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let t of window.ethereum.providers)if(t.isCoinbaseWallet)return!0}return!1},Ve=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,r,i,n,s,u)=>`${r} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${u}
@@ -9,7 +9,7 @@ Chain ID: ${e}
9
9
  Nonce: ${s}
10
10
  Issued At: ${n}
11
11
  Resources:
12
- - https://privy.io`;this.ethProvider=new we,this.initialized=!1}initialize(){let e=k.get(ot);zo.includes(e)?(this.walletType=e,this.connect({showPrompt:!1}).then(()=>this.initialized=!0)):this.initialized=!0}destroy(){this.walletType=null,k.del(ot),k.del(Lo)}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.address(),r=await this.chainId();return{address:o,chainId:r,chainType:"ethereum",walletType:e}}async connect(e){var o;switch(this.walletType){case"metamask":this.ethProvider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async i=>{i.isMetaMask&&this.ethProvider.setProvider(i)});break;case"coinbase_wallet":this.ethProvider.setProvider(Oi());break;case"wallet_connect":let r=new jo({infuraId:et});this.ethProvider.setProvider(r);break;default:throw new G(`Unsupported wallet: ${this.walletType}`)}return(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(this.walletType),this.getConnectedWallet()}async isConnected(){switch(this.walletType){case"metamask":return await this.address()!==null;case"coinbase_wallet":return await this.address()!==null;case"wallet_connect":return this.ethProvider.walletProvider.connected;default:throw new G(`Unsupported wallet: ${this.walletType}`)}}async promptConnection(e){try{switch(e){case"metamask":Ni||await this.ethProvider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]}),await this.ethProvider.request({method:"eth_requestAccounts"});break;case"coinbase_wallet":await this.ethProvider.request({method:"eth_requestAccounts"});break;case"wallet_connect":let o=new jo({infuraId:et});this.ethProvider.setProvider(o),await Promise.race([o.enable(),$t()]);break;default:throw new G(`Unsupported wallet: ${this.walletType}`)}k.put(ot,e)}catch(o){throw nt(o)}}async sign(e){return new Mi(new ye(this.getEthereumProvider())).getSigner().signMessage(e)}prepareMessage(e,o,r){let i=window.location.host,n=window.location.origin,s="By signing, you are proving you own this wallet and logging in. This does not initiate a transaction or cost any fees.",u=new Date().toISOString();return this.createSiweMessage(e,o,i,n,u,r,s)}async chainId(){let e=await this.getEthereumProvider().request({method:"eth_chainId"}),o=Number(e);return String(o)}async address(){let e=await this.getEthereumProvider().request({method:"eth_accounts"});return Array.isArray(e)&&e.length>0?Ri(e[0]):null}};var Kt,Be=class{constructor(e){let o=e.apiURL||vo,r=e.timeout||xo;this.appId=e.appId,this.connector=new Ve,Kt||(Kt=new it),this.session=Kt,this.api=new rt(e.appId,this,{baseURL:o,timeout:r}),this.session.api=this.api,this.session.client=this}authenticate(){if(!this.authFlow)throw new c("No auth flow in progress.");return this.session.authenticate(this.authFlow)}link(){if(!this.authFlow)throw new c("No auth flow in progress.");return this.session.link(this.authFlow)}async logout(){await this.session.destroy(),this.connector.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post(Vo(),{address:e});return Q(o.data)}catch(o){throw V(o)}}async unlinkPhone(e){try{let o=await this.api.post(Bo(),{phoneNumber:e});return Q(o.data)}catch(o){throw V(o)}}async unlinkWallet(e){try{let o=await this.api.post(Go(),{address:e});return Q(o.data)}catch(o){throw V(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(Ho(),{provider:e,subject:o});return Q(r.data)}catch(r){throw V(r)}}async getAuthenticatedUser(){return this.session.hasRefreshCredentials()?this.session.refresh():null}async getAccessToken(e){var o;return this.session.hasActiveToken()?((o=Y.parse(this.session.token))==null?void 0:o.audience)!==this.appId?(await this.logout(),null):this.session.token:!(e!=null&&e.disableAutoRefresh)&&this.session.hasRefreshCredentials()?(await this.session.refresh(),this.session.token):null}async getAppSettings(){try{let e=await this.api.get(`/api/v1/apps/${this.appId}`);return{id:e.data.id,name:e.data.name,verificationKey:e.data.verification_key,logoUrl:e.data.logo_url||void 0,theme:e.data.theme,accentColor:e.data.accent_color||void 0,showWalletLoginFirst:e.data.show_wallet_login_first,allowlistConfig:{errorTitle:e.data.allowlist_config.error_title,errorDetail:e.data.allowlist_config.error_detail,ctaText:e.data.allowlist_config.cta_text,ctaLink:e.data.allowlist_config.cta_link},walletAuth:e.data.wallet_auth,emailAuth:e.data.email_auth,smsAuth:e.data.sms_auth,googleOAuth:e.data.google_oauth,twitterOAuth:e.data.twitter_oauth,discordOAuth:e.data.discord_oauth,githubOAuth:e.data.github_oauth,termsAndConditionsUrl:e.data.terms_and_conditions_url,privacyPolicyUrl:e.data.privacy_policy_url,createdAt:new Date(e.data.created_at*1e3),updatedAt:new Date(e.data.updated_at*1e3)}}catch(e){throw V(e)}}setActiveWallet(e,o){if(!o.linkedAccounts.map(i=>i.type==="wallet"?i.address:null).includes(e))throw new c("Cannot set an unlinked address as active.");return k.put(Z,e),Ge(o)}async forkSession(){return await this.session.forkSession()}};import{Web3Provider as Js}from"@ethersproject/providers";import{createContext as Ui,useContext as Di}from"react";var f=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var qt=Ui({ready:!1,authenticated:!1,user:null,walletConnector:null,login:f,linkEmail:f,linkPhone:f,linkWallet:f,linkGoogle:f,linkTwitter:f,linkDiscord:f,linkGithub:f,logout:f,getAccessToken:f,getEthereumProvider:f,getEthersProvider:f,getWeb3jsProvider:f,unlinkEmail:f,unlinkPhone:f,unlinkWallet:f,unlinkGoogle:f,unlinkTwitter:f,unlinkDiscord:f,unlinkGithub:f,setActiveWallet:f,forkSession:f}),W=()=>Di(qt);var He=class{constructor(e){this.connector=e,this.meta={wallet:this.connector.walletType}}async authenticate(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.connector.walletType)throw new c("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(So(),{message:e,signature:o});return{user:r.data.user,token:r.data.token,refresh_token:r.data.refresh_token,is_new_user:r.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.connector.walletType)throw new c("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api);return(await this.api.post(To(),{message:e,signature:o})).data}catch(e){throw S(e)}}async promptConnectAndSign(e){let o=await this.connector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(Po(),{address:r}),s=this.connector.prepareMessage(i,r,n.data.nonce),u=await this.connector.sign(s);return{message:s,signature:u}}getEthereumProvider(){return this.connector.getEthereumProvider()}};var ze=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new c("Email and email code must be set prior to calling authenticate.");try{let e=Ro(),o=await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new c("Email and email code must be set prior to calling authenticate.");try{let e=Mo();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw S(e)}}async sendCodeEmail(e){if(!this.api)throw new c("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new c("Email must be set when initialzing authentication.");try{let o=Io();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw S(o)}}};var je=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new c("phone number and sms code must be set prior to calling authenticate.");try{let e=No(),o=await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new c("phone number and sms code must be set prior to calling authenticate.");try{let e=Oo();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw S(e)}}async sendSmsCode(e){if(!this.api)throw new c("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new c("phone nNumber must be set when initialzing authentication.");try{let o=Wo();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw S(o)}}};var Ie=class{constructor(e,o,r){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=r}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new c("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new c("User denied confirmation during OAuth flow");try{let e=Do(),o=await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new c("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new c("User denied confirmation during OAuth flow");try{let e=Fo();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw S(e)}}async getAuthorizationUrl(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.provider)throw new c("Provider must be set when initialzing OAuth authentication.");try{let e=Uo();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw S(e)}}};import"wicg-inert";import Hs from"react-dom";import go from"styled-components";import{createContext as Gi,useContext as Vi,useEffect as Zo,useState as Ko}from"react";import{jsx as Fi}from"react/jsx-runtime";function $o(t){return Fi("link",{rel:"prefetch",href:t.src})}import{jsx as Bi,jsxs as Hi}from"react/jsx-runtime";var qo=Gi({ready:!1,app:null,options:{email:!0,sms:!1,wallet:!0,google:!1,twitter:!1,discord:!1,github:!1},currentScreen:"LANDING",lastScreen:"LANDING",navigate:f,navigateBack:f}),Jo=t=>{let e=t.appSettings,o=t.authenticated,r=t.visible,[i,n]=Ko("LANDING"),[s,u]=Ko("LANDING");Zo(()=>{o||n("LANDING")},[o]),Zo(()=>{r||(u("LANDING"),n("LANDING"))},[r]);let h={ready:!!(e!=null&&e.id),app:e,options:t.options,currentScreen:i,lastScreen:s,navigate:m=>{u(i),n(m)},navigateBack:()=>{n(s)}};return Hi(qo.Provider,{value:h,children:[e&&e.logoUrl&&Bi($o,{src:e.logoUrl}),t.children]})},g=()=>Vi(qo);import{useEffect as Dn,useState as Fn}from"react";import qe from"styled-components";import $i from"styled-components";import{jsx as Yo}from"react/jsx-runtime";var Qo=({style:t,...e})=>Yo("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:Yo("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});import{jsx as Xo}from"react/jsx-runtime";var er=({style:t,...e})=>Xo("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:Xo("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});import{createContext as zi,useContext as ji}from"react";var Jt=zi({isLinking:!1,getAuthMeta:f,getAuthFlow:f,closePrivyModal:f,initLoginWithWallet:f,loginWithWallet:f,loginWithCode:f,initLoginWithEmail:f,initLoginWithSms:f,resendEmailCode:f,resendSmsCode:f,initLoginWithOAuth:f,loginWithOAuth:f,handleLoginError:f}),_=()=>ji(Jt);import{jsx as ee,jsxs as Yi}from"react/jsx-runtime";var Zi=()=>ee("div",{}),Ki=({backFn:t})=>ee("div",{children:ee(er,{onClick:t})}),qi=t=>ee("div",{children:ee("div",{children:ee(Qo,{onClick:t.onClose})})});var A=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=_();return Yi(Ji,{children:[t?ee(Ki,{backFn:t}):ee(Zi,{}),ee(qi,{onClose:e||o})]})},Ji=$i.div`
12
+ - https://privy.io`;this.ethProvider=new we,this.initialized=!1}initialize(){let e=k.get(ot);zo.includes(e)?(this.walletType=e,this.connect({showPrompt:!1}).then(()=>this.initialized=!0)):this.initialized=!0}destroy(){this.walletType=null,k.del(ot),k.del(Lo)}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.address(),r=await this.chainId();return{address:o,chainId:r,chainType:"ethereum",walletType:e}}async connect(e){var o;switch(this.walletType){case"metamask":this.ethProvider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async i=>{i.isMetaMask&&this.ethProvider.setProvider(i)});break;case"coinbase_wallet":this.ethProvider.setProvider(Oi());break;case"wallet_connect":let r=new jo({infuraId:et});this.ethProvider.setProvider(r);break;default:throw new G(`Unsupported wallet: ${this.walletType}`)}return(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(this.walletType),this.getConnectedWallet()}async isConnected(){switch(this.walletType){case"metamask":return await this.address()!==null;case"coinbase_wallet":return await this.address()!==null;case"wallet_connect":return this.ethProvider.walletProvider.connected;default:throw new G(`Unsupported wallet: ${this.walletType}`)}}async promptConnection(e){try{switch(e){case"metamask":Ni||await this.ethProvider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]}),await this.ethProvider.request({method:"eth_requestAccounts"});break;case"coinbase_wallet":await this.ethProvider.request({method:"eth_requestAccounts"});break;case"wallet_connect":let o=new jo({infuraId:et});this.ethProvider.setProvider(o),await Promise.race([o.enable(),$t()]);break;default:throw new G(`Unsupported wallet: ${this.walletType}`)}k.put(ot,e)}catch(o){throw nt(o)}}async sign(e){return new Mi(new ye(this.getEthereumProvider())).getSigner().signMessage(e)}prepareMessage(e,o,r){let i=window.location.host,n=window.location.origin,s="By signing, you are proving you own this wallet and logging in. This does not initiate a transaction or cost any fees.",u=new Date().toISOString();return this.createSiweMessage(e,o,i,n,u,r,s)}async chainId(){let e=await this.getEthereumProvider().request({method:"eth_chainId"}),o=Number(e);return String(o)}async address(){let e=await this.getEthereumProvider().request({method:"eth_accounts"});return Array.isArray(e)&&e.length>0?Ri(e[0]):null}};var Kt,Be=class{constructor(e){let o=e.apiURL||vo,r=e.timeout||xo;this.appId=e.appId,this.connector=new Ve,Kt||(Kt=new it),this.session=Kt,this.api=new rt(e.appId,this,{baseURL:o,timeout:r}),this.session.api=this.api,this.session.client=this}authenticate(){if(!this.authFlow)throw new c("No auth flow in progress.");return this.session.authenticate(this.authFlow)}link(){if(!this.authFlow)throw new c("No auth flow in progress.");return this.session.link(this.authFlow)}async logout(){await this.session.destroy(),this.connector.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post(Vo(),{address:e});return Q(o.data)}catch(o){throw V(o)}}async unlinkPhone(e){try{let o=await this.api.post(Bo(),{phoneNumber:e});return Q(o.data)}catch(o){throw V(o)}}async unlinkWallet(e){try{let o=await this.api.post(Go(),{address:e});return Q(o.data)}catch(o){throw V(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(Ho(),{provider:e,subject:o});return Q(r.data)}catch(r){throw V(r)}}async getAuthenticatedUser(){return this.session.hasRefreshCredentials()?this.session.refresh():null}async getAccessToken(e){var o;return this.session.hasActiveToken()?((o=Y.parse(this.session.token))==null?void 0:o.audience)!==this.appId?(await this.logout(),null):this.session.token:!(e!=null&&e.disableAutoRefresh)&&this.session.hasRefreshCredentials()?(await this.session.refresh(),this.session.token):null}async getAppSettings(){try{let e=await this.api.get(`/api/v1/apps/${this.appId}`);return{id:e.data.id,name:e.data.name,verificationKey:e.data.verification_key,logoUrl:e.data.logo_url||void 0,theme:e.data.theme,accentColor:e.data.accent_color||void 0,showWalletLoginFirst:e.data.show_wallet_login_first,allowlistConfig:{errorTitle:e.data.allowlist_config.error_title,errorDetail:e.data.allowlist_config.error_detail,ctaText:e.data.allowlist_config.cta_text,ctaLink:e.data.allowlist_config.cta_link},walletAuth:e.data.wallet_auth,emailAuth:e.data.email_auth,smsAuth:e.data.sms_auth,googleOAuth:e.data.google_oauth,twitterOAuth:e.data.twitter_oauth,discordOAuth:e.data.discord_oauth,githubOAuth:e.data.github_oauth,termsAndConditionsUrl:e.data.terms_and_conditions_url,privacyPolicyUrl:e.data.privacy_policy_url,createdAt:new Date(e.data.created_at*1e3),updatedAt:new Date(e.data.updated_at*1e3)}}catch(e){throw V(e)}}setActiveWallet(e,o){if(!o.linkedAccounts.map(i=>i.type==="wallet"?i.address:null).includes(e))throw new c("Cannot set an unlinked address as active.");return k.put(Z,e),Ge(o)}async forkSession(){return await this.session.forkSession()}};import{Web3Provider as qs}from"@ethersproject/providers";import{createContext as Ui,useContext as Di}from"react";var f=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var qt=Ui({ready:!1,authenticated:!1,user:null,walletConnector:null,login:f,linkEmail:f,linkPhone:f,linkWallet:f,linkGoogle:f,linkTwitter:f,linkDiscord:f,linkGithub:f,logout:f,getAccessToken:f,getEthereumProvider:f,getEthersProvider:f,getWeb3jsProvider:f,unlinkEmail:f,unlinkPhone:f,unlinkWallet:f,unlinkGoogle:f,unlinkTwitter:f,unlinkDiscord:f,unlinkGithub:f,setActiveWallet:f,forkSession:f}),W=()=>Di(qt);var He=class{constructor(e){this.connector=e,this.meta={wallet:this.connector.walletType}}async authenticate(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.connector.walletType)throw new c("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(So(),{message:e,signature:o});return{user:r.data.user,token:r.data.token,refresh_token:r.data.refresh_token,is_new_user:r.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.connector.walletType)throw new c("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api);return(await this.api.post(To(),{message:e,signature:o})).data}catch(e){throw S(e)}}async promptConnectAndSign(e){let o=await this.connector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(Po(),{address:r}),s=this.connector.prepareMessage(i,r,n.data.nonce),u=await this.connector.sign(s);return{message:s,signature:u}}getEthereumProvider(){return this.connector.getEthereumProvider()}};var ze=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new c("Email and email code must be set prior to calling authenticate.");try{let e=Ro(),o=await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new c("Email and email code must be set prior to calling authenticate.");try{let e=Mo();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw S(e)}}async sendCodeEmail(e){if(!this.api)throw new c("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new c("Email must be set when initialzing authentication.");try{let o=Io();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw S(o)}}};var je=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new c("phone number and sms code must be set prior to calling authenticate.");try{let e=No(),o=await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new c("phone number and sms code must be set prior to calling authenticate.");try{let e=Oo();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw S(e)}}async sendSmsCode(e){if(!this.api)throw new c("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new c("phone nNumber must be set when initialzing authentication.");try{let o=Wo();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw S(o)}}};var Ie=class{constructor(e,o,r){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=r}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new c("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new c("User denied confirmation during OAuth flow");try{let e=Do(),o=await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new c("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new c("User denied confirmation during OAuth flow");try{let e=Fo();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw S(e)}}async getAuthorizationUrl(){if(!this.api)throw new c("Auth flow has no API instance");if(!this.meta.provider)throw new c("Provider must be set when initialzing OAuth authentication.");try{let e=Uo();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw S(e)}}};import"wicg-inert";import Hs from"react-dom";import go from"styled-components";import{createContext as Gi,useContext as Vi,useEffect as Zo,useState as Ko}from"react";import{jsx as Fi}from"react/jsx-runtime";function $o(t){return Fi("link",{rel:"prefetch",href:t.src})}import{jsx as Bi,jsxs as Hi}from"react/jsx-runtime";var qo=Gi({ready:!1,app:null,options:{email:!0,sms:!1,wallet:!0,google:!1,twitter:!1,discord:!1,github:!1},currentScreen:"LANDING",lastScreen:"LANDING",navigate:f,navigateBack:f}),Jo=t=>{let e=t.appSettings,o=t.authenticated,r=t.visible,[i,n]=Ko("LANDING"),[s,u]=Ko("LANDING");Zo(()=>{o||n("LANDING")},[o]),Zo(()=>{r||(u("LANDING"),n("LANDING"))},[r]);let h={ready:!!(e!=null&&e.id),app:e,options:t.options,currentScreen:i,lastScreen:s,navigate:m=>{u(i),n(m)},navigateBack:()=>{n(s)}};return Hi(qo.Provider,{value:h,children:[e&&e.logoUrl&&Bi($o,{src:e.logoUrl}),t.children]})},g=()=>Vi(qo);import{useEffect as Dn,useState as Fn}from"react";import qe from"styled-components";import $i from"styled-components";import{jsx as Yo}from"react/jsx-runtime";var Qo=({style:t,...e})=>Yo("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:Yo("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});import{jsx as Xo}from"react/jsx-runtime";var er=({style:t,...e})=>Xo("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:Xo("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});import{createContext as zi,useContext as ji}from"react";var Jt=zi({isLinking:!1,getAuthMeta:f,getAuthFlow:f,closePrivyModal:f,initLoginWithWallet:f,loginWithWallet:f,loginWithCode:f,initLoginWithEmail:f,initLoginWithSms:f,resendEmailCode:f,resendSmsCode:f,initLoginWithOAuth:f,loginWithOAuth:f,handleLoginError:f}),_=()=>ji(Jt);import{jsx as ee,jsxs as Yi}from"react/jsx-runtime";var Zi=()=>ee("div",{}),Ki=({backFn:t})=>ee("div",{children:ee(er,{onClick:t})}),qi=t=>ee("div",{children:ee("div",{children:ee(Qo,{onClick:t.onClose})})});var A=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=_();return Yi(Ji,{children:[t?ee(Ki,{backFn:t}):ee(Zi,{}),ee(qi,{onClose:e||o})]})},Ji=$i.div`
13
13
  height: 30px;
14
14
  display: flex;
15
15
  align-items: center;
@@ -861,7 +861,7 @@ Resources:
861
861
  background-color: var(--primary-color);
862
862
  color: var(--light-theme-bg-1);
863
863
  }
864
- `,Oc=co(Zr)`
864
+ `,Nc=co(Zr)`
865
865
  && {
866
866
  border: 1px solid var(--light-theme-bg-3);
867
867
  color: var(--light-theme-fg-1);
@@ -1455,4 +1455,4 @@ Resources:
1455
1455
  align-items: center;
1456
1456
  justify-content: center;
1457
1457
  height: 100%;
1458
- `;import{jsx as Ut,jsxs as oa}from"react/jsx-runtime";function Ys(t){return typeof t=="string"&&t.length===25}var Xe;function Qs(){if(!Xe){let t=k.get(Pe);return Promise.resolve(t||null)}return Xe.getAccessToken()}var Xs=t=>{if(!Ys(t.appId))throw new c("Cannot initialize the Privy provider with an invalid Privy app ID");return Xe||(Xe=new Be({appId:t.appId,apiURL:Co})),Ut(ta,{...t,client:Xe})},ea=(t,e)=>{if(e)return{email:!1,sms:!1,wallet:!1,google:!1,twitter:!1,discord:!1,github:!1,[e]:!0};let o=!!(t!=null&&t.emailAuth),r=!!(t!=null&&t.smsAuth);return o&&r&&(console.warn("Enabling both email and SMS passwordless is not currently supported. Disabling SMS."),r=!1),{email:o,sms:r,wallet:!!(t!=null&&t.walletAuth),google:!!(t!=null&&t.googleOAuth),twitter:!!(t!=null&&t.twitterOAuth),discord:!!(t!=null&&t.discordOAuth),github:!!(t!=null&&t.githubOAuth)}},ta=t=>{let e=t.client,[o,r]=me(!1),[i,n]=me(!1),[s,u]=me(!1),[h,m]=me(null),[x,I]=me(!1),[b,E]=me({accentColor:"#696ffd",theme:"System",showWalletLoginFirst:!0,allowlistConfig:{errorTitle:null,errorDetail:null,ctaText:null,ctaLink:null},walletAuth:!0,emailAuth:!0,smsAuth:!1,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,githubOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null}),[P,l]=me(null),[y,F]=me(!1),fe=ea(b,P);bi(()=>{async function d(){let a=await e.getAppSettings();E(a),e.connector.initialize(),M();let L=await e.getAuthenticatedUser();u(!!L),m(L),n(!0)}d()},[e]);let M=()=>{let d=new URLSearchParams(window.location.search),a=d.get("privy_oauth_code"),L=d.get("privy_oauth_state"),O=d.get("privy_oauth_provider");a&&L&&O&&(e.startAuthFlow(new Ie(O,a,L)),l(O),r(!0))};bi(()=>{i&&s&&h===null&&e.getAuthenticatedUser().then(m)},[i,s,h,e]);let J={ready:i,authenticated:s,user:h,walletConnector:e.connector,linkWallet:()=>{l("wallet"),F(!0),r(!0)},linkEmail:()=>{l("email"),F(!0),r(!0)},linkPhone:()=>{l("sms"),F(!0),r(!0)},linkGoogle:async()=>{await H.initLoginWithOAuth("google")},linkTwitter:async()=>{await H.initLoginWithOAuth("twitter")},linkDiscord:async()=>{await H.initLoginWithOAuth("discord")},linkGithub:async()=>{await H.initLoginWithOAuth("github")},login:()=>{if(i&&s){console.warn("Attempted to log in, but user is already logged in. Use a `link` helper instead.");return}r(!0)},logout:async()=>{await e.logout(),m(null),u(!1),l(null),F(!1),r(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>{if(!e.connector.initialized)throw new c("Connector is not loaded");return e.connector.getEthereumProvider()},getEthersProvider:()=>{if(!e.connector.initialized)throw new c("Connector is not loaded");return new Js(new ye(e.connector.getEthereumProvider()))},getWeb3jsProvider:()=>{if(!e.connector.initialized)throw new c("Connector is not loaded");return new at(e.connector.getEthereumProvider())},unlinkWallet:async d=>{let a=await e.unlinkWallet(d);return m(a),a},unlinkEmail:async d=>{let a=await e.unlinkEmail(d);return m(a),a},unlinkPhone:async d=>{let a=await e.unlinkPhone(d);return m(a),a},unlinkGoogle:async d=>{let a=await e.unlinkOAuth("google",d);return m(a),a},unlinkTwitter:async d=>{let a=await e.unlinkOAuth("twitter",d);return m(a),a},unlinkDiscord:async d=>{let a=await e.unlinkOAuth("discord",d);return m(a),a},unlinkGithub:async d=>{let a=await e.unlinkOAuth("github",d);return m(a),a},setActiveWallet:d=>{if(!h)return;let a=e.setActiveWallet(d,h);m(a)},forkSession:()=>e.forkSession()},H=qs(()=>({isLinking:y,getAuthFlow:()=>e.authFlow,getAuthMeta:()=>{var d;return(d=e.authFlow)==null?void 0:d.meta},closePrivyModal:()=>{var d;i&&s&&h&&((d=t.onSuccess)==null||d.call(t,h,x)),e.authFlow=void 0,l(null),F(!1),I(!1),r(!1)},handleLoginError:async d=>{var a;e.authFlow=void 0,l(null),F(!1),I(!1),(a=t.onError)==null||a.call(t,d)},initLoginWithWallet:d=>{if(!e.connector)throw new c("Connector not initialized");d||(d="metamask"),e.connector.walletType=d,e.startAuthFlow(new He(e.connector))},loginWithWallet:async()=>{if(!(e.authFlow instanceof He))throw new c("Must initialize SIWE flow first.");let d,a;y?(d=await e.link(),d&&(k.del(Z),d=Ge(d))):{user:d,isNewUser:a}=await e.authenticate(),m(d||h||null),I(a||!1),u(!0)},initLoginWithOAuth:async d=>{e.startAuthFlow(new Ie(d));let a=await e.authFlow.getAuthorizationUrl();a&&a.url&&window.location.assign(a.url)},loginWithOAuth:async()=>{if(!(e.authFlow instanceof Ie))throw new c("Must initialize OAuth flow before calling loginWithOAuth");let d,a;i&&s?d=await e.link():{user:d,isNewUser:a}=await e.authenticate(),m(d),I(a||!1),u(!0)},initLoginWithEmail:async d=>{let a=new ze(d);e.startAuthFlow(a),await a.sendCodeEmail()},initLoginWithSms:async d=>{let a=new je(d);e.startAuthFlow(a),await a.sendSmsCode()},resendEmailCode:async()=>{var d;await((d=e.authFlow)==null?void 0:d.sendCodeEmail())},resendSmsCode:async()=>{var d;await((d=e.authFlow)==null?void 0:d.sendSmsCode())},loginWithCode:async d=>{if(e.authFlow instanceof ze)e.authFlow.meta.emailCode=d.trim();else if(e.authFlow instanceof je)e.authFlow.meta.smsCode=d.trim();else throw new c("Must initialize a passwordless code flow first");let a,L;y?a=await e.link():{user:a,isNewUser:L}=await e.authenticate(),m(a||h||null),I(L||!1),u(!0)}}),[e]);return oa(qt.Provider,{value:J,children:[t.children,Ut(Jt.Provider,{value:H,children:Ut(Jo,{appSettings:b,options:fe,visible:o,authenticated:s,children:o&&Ut(yi,{})})})]})};export{ye as AsExternalProvider,Be as PrivyClient,Ve as PrivyConnector,Xs as PrivyProvider,we as PrivyProxyProvider,Vt as VERSION,Qs as getAccessToken,W as usePrivy};
1458
+ `;import{jsx as Ut,jsxs as ta}from"react/jsx-runtime";function Js(t){return typeof t=="string"&&t.length===25}var Xe;function Ys(){if(!Xe){let t=k.get(Pe);return Promise.resolve(t||null)}return Xe.getAccessToken()}var Qs=t=>{if(!Js(t.appId))throw new c("Cannot initialize the Privy provider with an invalid Privy app ID");return Xe||(Xe=new Be({appId:t.appId,apiURL:Co})),Ut(ea,{...t,client:Xe})},Xs=(t,e)=>{if(e)return{email:!1,sms:!1,wallet:!1,google:!1,twitter:!1,discord:!1,github:!1,[e]:!0};let o=!!(t!=null&&t.emailAuth),r=!!(t!=null&&t.smsAuth);return o&&r&&(console.warn("Enabling both email and SMS passwordless is not currently supported. Disabling SMS."),r=!1),{email:o,sms:r,wallet:!!(t!=null&&t.walletAuth),google:!!(t!=null&&t.googleOAuth),twitter:!!(t!=null&&t.twitterOAuth),discord:!!(t!=null&&t.discordOAuth),github:!!(t!=null&&t.githubOAuth)}},ea=t=>{let e=t.client,[o,r]=me(!1),[i,n]=me(!1),[s,u]=me(!1),[h,m]=me(null),[x,I]=me(!1),[b,E]=me({accentColor:"#696ffd",theme:"System",showWalletLoginFirst:!0,allowlistConfig:{errorTitle:null,errorDetail:null,ctaText:null,ctaLink:null},walletAuth:!0,emailAuth:!0,smsAuth:!1,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,githubOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null}),[P,l]=me(null),[y,F]=me(!1),fe=Xs(b,P);bi(()=>{async function d(){let a=await e.getAppSettings();E(a),e.connector.initialize(),M();let L=await e.getAuthenticatedUser();u(!!L),m(L),n(!0)}d()},[e]);let M=()=>{let d=new URLSearchParams(window.location.search),a=d.get("privy_oauth_code"),L=d.get("privy_oauth_state"),O=d.get("privy_oauth_provider");a&&L&&O&&(e.startAuthFlow(new Ie(O,a,L)),l(O),r(!0))};bi(()=>{i&&s&&h===null&&e.getAuthenticatedUser().then(m)},[i,s,h,e]);let J={ready:i,authenticated:s,user:h,walletConnector:e.connector,linkWallet:()=>{l("wallet"),F(!0),r(!0)},linkEmail:()=>{l("email"),F(!0),r(!0)},linkPhone:()=>{l("sms"),F(!0),r(!0)},linkGoogle:async()=>{await H.initLoginWithOAuth("google")},linkTwitter:async()=>{await H.initLoginWithOAuth("twitter")},linkDiscord:async()=>{await H.initLoginWithOAuth("discord")},linkGithub:async()=>{await H.initLoginWithOAuth("github")},login:()=>{if(i&&s){console.warn("Attempted to log in, but user is already logged in. Use a `link` helper instead.");return}r(!0)},logout:async()=>{await e.logout(),m(null),u(!1),l(null),F(!1),r(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>{if(!e.connector.initialized)throw new c("Connector is not loaded");return e.connector.getEthereumProvider()},getEthersProvider:()=>{if(!e.connector.initialized)throw new c("Connector is not loaded");return new qs(new ye(e.connector.getEthereumProvider()))},getWeb3jsProvider:()=>{if(!e.connector.initialized)throw new c("Connector is not loaded");return new at(e.connector.getEthereumProvider())},unlinkWallet:async d=>{let a=await e.unlinkWallet(d);return m(a),a},unlinkEmail:async d=>{let a=await e.unlinkEmail(d);return m(a),a},unlinkPhone:async d=>{let a=await e.unlinkPhone(d);return m(a),a},unlinkGoogle:async d=>{let a=await e.unlinkOAuth("google",d);return m(a),a},unlinkTwitter:async d=>{let a=await e.unlinkOAuth("twitter",d);return m(a),a},unlinkDiscord:async d=>{let a=await e.unlinkOAuth("discord",d);return m(a),a},unlinkGithub:async d=>{let a=await e.unlinkOAuth("github",d);return m(a),a},setActiveWallet:d=>{if(!h)return;let a=e.setActiveWallet(d,h);m(a)},forkSession:()=>e.forkSession()},H=(()=>({isLinking:y,getAuthFlow:()=>e.authFlow,getAuthMeta:()=>{var d;return(d=e.authFlow)==null?void 0:d.meta},closePrivyModal:()=>{var d;i&&s&&h&&((d=t.onSuccess)==null||d.call(t,h,x)),e.authFlow=void 0,l(null),F(!1),I(!1),r(!1)},handleLoginError:async d=>{var a;e.authFlow=void 0,l(null),F(!1),I(!1),(a=t.onError)==null||a.call(t,d)},initLoginWithWallet:d=>{if(!e.connector)throw new c("Connector not initialized");d||(d="metamask"),e.connector.walletType=d,e.startAuthFlow(new He(e.connector))},loginWithWallet:async()=>{if(!(e.authFlow instanceof He))throw new c("Must initialize SIWE flow first.");let d,a;y?(d=await e.link(),d&&(k.del(Z),d=Ge(d))):{user:d,isNewUser:a}=await e.authenticate(),m(d||h||null),I(a||!1),u(!0)},initLoginWithOAuth:async d=>{e.startAuthFlow(new Ie(d));let a=await e.authFlow.getAuthorizationUrl();a&&a.url&&window.location.assign(a.url)},loginWithOAuth:async()=>{if(!(e.authFlow instanceof Ie))throw new c("Must initialize OAuth flow before calling loginWithOAuth");let d,a;i&&s?d=await e.link():{user:d,isNewUser:a}=await e.authenticate(),m(d),I(a||!1),u(!0)},initLoginWithEmail:async d=>{let a=new ze(d);e.startAuthFlow(a),await a.sendCodeEmail()},initLoginWithSms:async d=>{let a=new je(d);e.startAuthFlow(a),await a.sendSmsCode()},resendEmailCode:async()=>{var d;await((d=e.authFlow)==null?void 0:d.sendCodeEmail())},resendSmsCode:async()=>{var d;await((d=e.authFlow)==null?void 0:d.sendSmsCode())},loginWithCode:async d=>{if(e.authFlow instanceof ze)e.authFlow.meta.emailCode=d.trim();else if(e.authFlow instanceof je)e.authFlow.meta.smsCode=d.trim();else throw new c("Must initialize a passwordless code flow first");let a,L;y?a=await e.link():{user:a,isNewUser:L}=await e.authenticate(),m(a||h||null),I(L||!1),u(!0)}}))();return ta(qt.Provider,{value:J,children:[t.children,Ut(Jt.Provider,{value:H,children:Ut(Jo,{appSettings:b,options:fe,visible:o,authenticated:s,children:o&&Ut(yi,{})})})]})};export{ye as AsExternalProvider,Be as PrivyClient,Ve as PrivyConnector,Qs as PrivyProvider,we as PrivyProxyProvider,Vt as VERSION,Ys as getAccessToken,W as usePrivy};
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Pi=Object.create;var pt=Object.defineProperty;var Si=Object.getOwnPropertyDescriptor;var Ti=Object.getOwnPropertyNames;var Ii=Object.getPrototypeOf,Ri=Object.prototype.hasOwnProperty;var Mi=(t,e)=>{for(var o in e)pt(t,o,{get:e[o],enumerable:!0})},Ro=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ti(e))!Ri.call(t,i)&&i!==o&&pt(t,i,{get:()=>e[i],enumerable:!(r=Si(e,i))||r.enumerable});return t};var v=(t,e,o)=>(o=t!=null?Pi(Ii(t)):{},Ro(e||!t||!t.__esModule?pt(o,"default",{value:t,enumerable:!0}):o,t)),Wi=t=>Ro(pt({},"__esModule",{value:!0}),t);var ls={};Mi(ls,{AsExternalProvider:()=>xe,PrivyClient:()=>je,PrivyConnector:()=>ze,PrivyProvider:()=>ki,PrivyProxyProvider:()=>Ce,VERSION:()=>mt,getAccessToken:()=>Ei,usePrivy:()=>O});module.exports=Wi(ls);var j=require("react");var wt=v(require("axios"));var Mo=v(require("axios")),ee=class extends Error{constructor(o,r){super(o);r instanceof Error&&(this.cause=r)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},Fe=class extends ee{constructor(o,r,i,n){super(i,n);this.type=o;this.status=r}},u=class extends ee{constructor(o,r){super(o,r);this.type="client_error"}};var K=class extends ee{constructor(o,r){super(o,r);this.type="connector_error"}},W=t=>{if(t instanceof ee)return t;if(!Mo.default.isAxiosError(t))return q(t);if(!t.response)return new Fe("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new Fe(e||"ApiError",t.response.status,o||r,t)},q=t=>t instanceof ee?t:t instanceof Error?new u(t.message,t):new u(`Internal error: ${t}`);var Wo="1.13.0-beta.6";var No="https://api.privy.io/v0",Oo=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",ht="4df5e2316331463a9130964bd6078dfa",Uo=1e4,Ge=1400,mt=Wo;var Ve="privy:token",ft="privy:refresh_token",se="privy:active_wallet",gt="privy:wallet_type",Do="walletconnect";var yt=class{constructor(e,o,r){this.appId=e,this.sdkVersion=mt,this.client=o,this.defaults=r}async get(e,o){try{return await wt.default.get(e,await this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(r){throw W(r)}}async post(e,o,r){try{return await wt.default.post(e,o,await this.buildConfig(r))}catch(i){throw W(i)}}async delete(e,o){try{return await wt.default.delete(e,await this.buildConfig(o))}catch(r){throw W(r)}}async buildConfig(e){if(e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-client"]=`react-auth:${this.sdkVersion}`,!e.headers.authorization){let o=await this.client.getAccessToken();o!==null&&(e.headers.authorization=`Bearer ${o}`)}return{...this.defaults,...e}}};var Fo=v(require("jose")),pe=class{static parse(e){try{return new pe(e)}catch{return null}}constructor(e){this.value=e,this._decoded=Fo.decodeJwt(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}get issuer(){return this._decoded.iss}get audience(){return this._decoded.aud}isExpired(e=0){let o=Date.now(),r=(this.expiration-e)*1e3;return o>=r}};var ye=class{constructor(e){this.promise=null;this.fn=e}execute(e){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(e)}finally{this.promise=null}})()),this.promise}};var Jt=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,o){o!==void 0?this._cache[e]=o:this.del(e)}del(e){delete this._cache[e]}},Yt=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}};function Oi(){return typeof window<"u"&&window.localStorage?new Yt:new Jt}var T=Oi();function be(t){return new Date(t*1e3)}function Ui(t){return t.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:be(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:be(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:be(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:be(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:be(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:be(e.verified_at)};case"github_oauth":return{subject:e.subject,username:e.username,name:e.name,email:e.email,type:e.type,verifiedAt:be(e.verified_at)};default:throw new u("Unrecognized account type")}})}function Di(t,e){return e.find(o=>o.type==="wallet"&&o.address===t)}function ve(t,e){return t.sort((o,r)=>r.verifiedAt.getTime()-o.verifiedAt.getTime()),t.find(o=>o.type===e)}function Xe(t){let e=t.linkedAccounts.map(s=>s.type==="wallet"?s.address:null),r=T.get(se);if(!r||!e.includes(r)){T.del(se);let s=ve(t.linkedAccounts,"wallet");s&&(r=s.address,T.put(se,r))}let i=Di(r,t.linkedAccounts),n=Object.assign({},t);return n.wallet=i&&{address:i.address,chainType:i.chainType,chainId:i.chainId,walletType:i.walletType},n}function he(t){if(!t)return null;let e=Ui(t.linked_accounts),o=ve(e,"wallet"),r=ve(e,"email"),i=ve(e,"phone"),n=ve(e,"google_oauth"),s=ve(e,"twitter_oauth"),p=ve(e,"discord_oauth"),m=ve(e,"github_oauth"),f={id:t.id,createdAt:be(t.created_at),linkedAccounts:e,email:r&&{address:r==null?void 0:r.address},phone:i&&{number:i==null?void 0:i.number},wallet:o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},google:n&&{subject:n.subject,email:n.email,name:n.name},twitter:s&&{subject:s.subject,username:s.username,name:s.name},discord:p&&{subject:p.subject,username:p.username,email:p.email},github:m&&{subject:m.subject,username:m.username,name:m.name,email:m.email}};return Xe(f)}var Go=()=>"/api/v1/sessions",Vo=()=>"/api/v1/sessions/logout",Bo=()=>"/api/v1/sessions/fork",Ho=()=>"/api/v1/siwe/init",zo=()=>"/api/v1/siwe/authenticate",jo=()=>"/api/v1/siwe/link",$o=()=>"/api/v1/passwordless/init",Zo=()=>"/api/v1/passwordless/authenticate",Ko=()=>"/api/v1/passwordless/link",qo=()=>"/api/v1/passwordless_sms/init",Jo=()=>"/api/v1/passwordless_sms/authenticate",Yo=()=>"/api/v1/passwordless_sms/link",Qo=()=>"/api/v1/oauth/init",Xo=()=>"/api/v1/oauth/authenticate",er=()=>"/api/v1/oauth/link",tr=()=>"/api/v1/siwe/unlink",or=()=>"/api/v1/passwordless/unlink",rr=()=>"/api/v1/passwordless_sms/unlink",ir=()=>"/api/v1/oauth/unlink";var Fi=30,bt=class{constructor(){this.authenticateOnce=new ye(async e=>this._authenticate(e)),this.linkOnce=new ye(async e=>this._link(e)),this.refreshOnce=new ye(this._refresh.bind(this)),this.destroyOnce=new ye(this._destroy.bind(this)),this.forkSessionOnce=new ye(this._forkSession.bind(this))}get token(){try{let e=T.get(Ve);return typeof e=="string"?new pe(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=T.get(ft);return typeof e=="string"?e:null}catch(e){return console.error(e),this.destroyLocalState(),null}}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=pe.parse(this.token);return e!==null&&!e.isExpired(Fi)}authenticate(e){return this.authenticateOnce.execute(e)}link(e){return this.linkOnce.execute(e)}refresh(){return this.refreshOnce.execute()}forkSession(){return this.forkSessionOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:o,refresh_token:r,user:i,is_new_user:n}=await e.authenticate();return this.storeToken(o),this.storeRefreshToken(r),{user:he(i),isNewUser:n}}catch(o){throw console.warn("Error authenticating session"),q(o)}}async _link(e){try{let o=await e.link();return he(o)}catch(o){throw console.warn("Error linking account"),q(o)}}async _refresh(){if(!this.api)throw new u("Session has no API instance");if(!this.client)throw new u("Session has no PrivyClient instance");let e=await this.client.getAccessToken({disableAutoRefresh:!0}),o=this.refreshToken;if(!e||!o)return null;try{let r=await this.api.post(Go(),{refresh_token:o},{headers:{authorization:`Bearer ${this.token}`}});return this.storeToken(r.data.token),this.storeRefreshToken(r.data.refresh_token),he(r.data.user)}catch(r){if(r instanceof Fe&&r.status===400&&r.message==="Invalid auth token")return this.destroyLocalState(),null;throw q(r)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(Vo(),{refresh_token:this.refreshToken}))}catch{console.warn("Error destroying session")}this.destroyLocalState()}async _forkSession(){if(!this.api)throw new u("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(Bo(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw q(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null),T.del(se)}storeToken(e){typeof e=="string"?T.put(Ve,e):T.del(Ve)}storeRefreshToken(e){typeof e=="string"?T.put(ft,e):T.del(ft)}};var ar=require("@ethersproject/address"),eo=v(require("@walletconnect/web3-provider"));var nr=require("@ethersproject/logger");var Be=class extends K{constructor(){super("Wallet timeout");this.type="wallet_error"}},vt=t=>{if(t instanceof K)return t;if((t==null?void 0:t.code)&&(t==null?void 0:t.reason)){let e=new He(t);return t.code===nr.ErrorCode.ACTION_REJECTED&&(e.details=Re.E4001_USER_REJECTED_REQUEST),e}return t!=null&&t.code?new He(t):new K("Unknown connector error",t)},Qt=class extends ee{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},He=class extends Qt{constructor(o){var n,s,p;let r=o;super(r.message,r.code,r.data);let i=Object.values(Re).find(m=>m.eipCode===r.code);this.details=i||Re.UNKNOWN_ERROR,r.code===-32002&&((n=r.message)!=null&&n.includes("already pending for origin")?(s=r.message)!=null&&s.includes("wallet_requestPermissions")?this.details=Re.E32002_CONNECTION_ALREADY_PENDING:this.details=Re.E32002_REQUEST_ALREADY_PENDING:(p=r.message)!=null&&p.includes("Already processing")&&r.message.includes("eth_requestAccounts")&&(this.details=Re.E32002_WALLET_LOCKED))}},Gi={ERROR_USER_EXISTS:{message:"User already exists for this address",detail:"Try another address!",retryable:!1},ERROR_TIMED_OUT:{message:"Wallet request timed out",detail:"Please try connecting again.",retryable:!0},ERROR_WALLET_CONNECTION:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0}},Vi={E32002_CONNECTION_ALREADY_PENDING:{eipCode:-32002,message:"Connection request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_REQUEST_ALREADY_PENDING:{eipCode:-32002,message:"Resource request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_WALLET_LOCKED:{eipCode:-32002,message:"Wallet might be locked",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E4001_USER_REJECTED_REQUEST:{eipCode:4001,message:"Signature rejected",detail:"Please try signing again.",retryable:!0}},Bi={E4001_DEFAULT_USER_REJECTED_REQUEST:{eipCode:4001,message:"User Rejected Request",detail:"The user rejected the request.",default:!0,retryable:!0},E4100_DEFAULT_UNAUTHORIZED:{eipCode:4100,message:"Unauthorized",detail:"The requested method and/or account has not been authorized by the user.",default:!0,retryable:!1},E4200_DEFAULT_UNSUPPORTED_METHOD:{eipCode:4200,message:"Unsupported Method",detail:"The Provider does not support the requested method.",default:!0,retryable:!1},E4900_DEFAULT_DISCONNECTED:{eipCode:4900,message:"Disconnected",detail:"The Provider is disconnected from all chains.",default:!0,retryable:!0},E4901_DEFAULT_CHAIN_DISCONNECTED:{eipCode:4901,message:"Chain Disconnected",detail:"The Provider is not connected to the requested chain.",default:!0,retryable:!0},E32700_DEFAULT_PARSE_ERROR:{eipCode:-32700,message:"Parse error",detail:"Invalid JSON",default:!0,retryable:!1},E32600_DEFAULT_INVALID_REQUEST:{eipCode:-32600,message:"Invalid request",detail:"JSON is not a valid request object",default:!0,retryable:!1},E32601_DEFAULT_METHOD_NOT_FOUND:{eipCode:-32601,message:"Method not found",detail:"Method does not exist",default:!0,retryable:!1},E32602_DEFAULT_INVALID_PARAMS:{eipCode:-32602,message:"Invalid params",detail:"Invalid method parameters",default:!0,retryable:!1},E32603_DEFAULT_INTERNAL_ERROR:{eipCode:-32603,message:"Internal error",detail:"Internal JSON-RPC error",default:!0,retryable:!0},E32000_DEFAULT_INVALID_INPUT:{eipCode:-32e3,message:"Invalid input",detail:"Missing or invalid parameters",default:!0,retryable:!1},E32001_DEFAULT_RESOURCE_NOT_FOUND:{eipCode:-32001,message:"Resource not found",detail:"Requested resource not found",default:!0,retryable:!1},E32002_DEFAULT_RESOURCE_UNAVAILABLE:{eipCode:-32002,message:"Resource unavailable",detail:"Requested resource not available",default:!0,retryable:!0},E32003_DEFAULT_TRANSACTION_REJECTED:{eipCode:-32003,message:"Transaction rejected",detail:"Transaction creation failed",default:!0,retryable:!0},E32004_DEFAULT_METHOD_NOT_SUPPORTED:{eipCode:-32004,message:"Method not supported",detail:"Method is not implemented",default:!0,retryable:!1},E32005_DEFAULT_LIMIT_EXCEEDED:{eipCode:-32005,message:"Limit exceeded",detail:"Request exceeds defined limit",default:!0,retryable:!1},E32006_DEFAULT_JSON_RPC_VERSION_NOT_SUPPORTED:{eipCode:-32006,message:"JSON-RPC version not supported",detail:"Version of JSON-RPC protocol is not supported",default:!0,retryable:!1}},Re={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...Bi,...Vi},Ct={...Gi,...Re};var Hi=12e4,Xt=(t=new Be,e=Hi)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),Ce=class{constructor(e){this.removeListener=(e,o)=>{if(this.walletProvider)return this.walletProvider.removeListener(e,o)};this.setProvider=e=>{this.walletProvider=e,this._subscriptions.forEach(o=>{var r;(r=this.walletProvider)==null||r.on(o.eventName,o.listener)})};this.walletProvider=e,this._subscriptions=[]}on(e,o){if(this.walletProvider)return this.walletProvider.on(e,o);this._subscriptions.push({eventName:e,listener:o})}request(e){if(!this.walletProvider)throw new K(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),Xt()]).catch(o=>{throw vt(o)})}},xe=class extends Ce{constructor(o){super(o)}},xt=class extends Ce{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var lr=require("@ethersproject/providers");var sr=["metamask","coinbase_wallet","wallet_connect"];var dr=v(require("@coinbase/wallet-sdk")),cr=require("react-device-detect"),zi=()=>{let t=`https://mainnet.infura.io/v3/${ht}`,e=1;return new dr.default({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(t,e)},to=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let t of window.ethereum.providers)if(t.isMetaMask)return!0}return!1},Lt=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let t of window.ethereum.providers)if(t.isCoinbaseWallet)return!0}return!1},ze=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,r,i,n,s,p)=>`${r} wants you to sign in with your Ethereum account:
1
+ "use strict";var Pi=Object.create;var pt=Object.defineProperty;var Si=Object.getOwnPropertyDescriptor;var Ti=Object.getOwnPropertyNames;var Ii=Object.getPrototypeOf,Ri=Object.prototype.hasOwnProperty;var Mi=(t,e)=>{for(var o in e)pt(t,o,{get:e[o],enumerable:!0})},Ro=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ti(e))!Ri.call(t,i)&&i!==o&&pt(t,i,{get:()=>e[i],enumerable:!(r=Si(e,i))||r.enumerable});return t};var v=(t,e,o)=>(o=t!=null?Pi(Ii(t)):{},Ro(e||!t||!t.__esModule?pt(o,"default",{value:t,enumerable:!0}):o,t)),Wi=t=>Ro(pt({},"__esModule",{value:!0}),t);var ls={};Mi(ls,{AsExternalProvider:()=>xe,PrivyClient:()=>je,PrivyConnector:()=>ze,PrivyProvider:()=>ki,PrivyProxyProvider:()=>Ce,VERSION:()=>mt,getAccessToken:()=>Ei,usePrivy:()=>O});module.exports=Wi(ls);var Q=require("react");var wt=v(require("axios"));var Mo=v(require("axios")),ee=class extends Error{constructor(o,r){super(o);r instanceof Error&&(this.cause=r)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},Fe=class extends ee{constructor(o,r,i,n){super(i,n);this.type=o;this.status=r}},u=class extends ee{constructor(o,r){super(o,r);this.type="client_error"}};var Z=class extends ee{constructor(o,r){super(o,r);this.type="connector_error"}},W=t=>{if(t instanceof ee)return t;if(!Mo.default.isAxiosError(t))return K(t);if(!t.response)return new Fe("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new Fe(e||"ApiError",t.response.status,o||r,t)},K=t=>t instanceof ee?t:t instanceof Error?new u(t.message,t):new u(`Internal error: ${t}`);var Wo="1.13.0-beta.7";var No="https://api.privy.io/v0",Oo=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",ht="4df5e2316331463a9130964bd6078dfa",Uo=1e4,Ge=1400,mt=Wo;var Ve="privy:token",ft="privy:refresh_token",se="privy:active_wallet",gt="privy:wallet_type",Do="walletconnect";var yt=class{constructor(e,o,r){this.appId=e,this.sdkVersion=mt,this.client=o,this.defaults=r}async get(e,o){try{return await wt.default.get(e,await this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(r){throw W(r)}}async post(e,o,r){try{return await wt.default.post(e,o,await this.buildConfig(r))}catch(i){throw W(i)}}async delete(e,o){try{return await wt.default.delete(e,await this.buildConfig(o))}catch(r){throw W(r)}}async buildConfig(e){if(e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-client"]=`react-auth:${this.sdkVersion}`,!e.headers.authorization){let o=await this.client.getAccessToken();o!==null&&(e.headers.authorization=`Bearer ${o}`)}return{...this.defaults,...e}}};var Fo=v(require("jose")),pe=class{static parse(e){try{return new pe(e)}catch{return null}}constructor(e){this.value=e,this._decoded=Fo.decodeJwt(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}get issuer(){return this._decoded.iss}get audience(){return this._decoded.aud}isExpired(e=0){let o=Date.now(),r=(this.expiration-e)*1e3;return o>=r}};var ye=class{constructor(e){this.promise=null;this.fn=e}execute(e){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(e)}finally{this.promise=null}})()),this.promise}};var Jt=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,o){o!==void 0?this._cache[e]=o:this.del(e)}del(e){delete this._cache[e]}},Yt=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}};function Oi(){return typeof window<"u"&&window.localStorage?new Yt:new Jt}var T=Oi();function be(t){return new Date(t*1e3)}function Ui(t){return t.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:be(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:be(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:be(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:be(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:be(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:be(e.verified_at)};case"github_oauth":return{subject:e.subject,username:e.username,name:e.name,email:e.email,type:e.type,verifiedAt:be(e.verified_at)};default:throw new u("Unrecognized account type")}})}function Di(t,e){return e.find(o=>o.type==="wallet"&&o.address===t)}function ve(t,e){return t.sort((o,r)=>r.verifiedAt.getTime()-o.verifiedAt.getTime()),t.find(o=>o.type===e)}function Xe(t){let e=t.linkedAccounts.map(s=>s.type==="wallet"?s.address:null),r=T.get(se);if(!r||!e.includes(r)){T.del(se);let s=ve(t.linkedAccounts,"wallet");s&&(r=s.address,T.put(se,r))}let i=Di(r,t.linkedAccounts),n=Object.assign({},t);return n.wallet=i&&{address:i.address,chainType:i.chainType,chainId:i.chainId,walletType:i.walletType},n}function he(t){if(!t)return null;let e=Ui(t.linked_accounts),o=ve(e,"wallet"),r=ve(e,"email"),i=ve(e,"phone"),n=ve(e,"google_oauth"),s=ve(e,"twitter_oauth"),p=ve(e,"discord_oauth"),m=ve(e,"github_oauth"),f={id:t.id,createdAt:be(t.created_at),linkedAccounts:e,email:r&&{address:r==null?void 0:r.address},phone:i&&{number:i==null?void 0:i.number},wallet:o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},google:n&&{subject:n.subject,email:n.email,name:n.name},twitter:s&&{subject:s.subject,username:s.username,name:s.name},discord:p&&{subject:p.subject,username:p.username,email:p.email},github:m&&{subject:m.subject,username:m.username,name:m.name,email:m.email}};return Xe(f)}var Go=()=>"/api/v1/sessions",Vo=()=>"/api/v1/sessions/logout",Bo=()=>"/api/v1/sessions/fork",Ho=()=>"/api/v1/siwe/init",zo=()=>"/api/v1/siwe/authenticate",jo=()=>"/api/v1/siwe/link",$o=()=>"/api/v1/passwordless/init",Zo=()=>"/api/v1/passwordless/authenticate",Ko=()=>"/api/v1/passwordless/link",qo=()=>"/api/v1/passwordless_sms/init",Jo=()=>"/api/v1/passwordless_sms/authenticate",Yo=()=>"/api/v1/passwordless_sms/link",Qo=()=>"/api/v1/oauth/init",Xo=()=>"/api/v1/oauth/authenticate",er=()=>"/api/v1/oauth/link",tr=()=>"/api/v1/siwe/unlink",or=()=>"/api/v1/passwordless/unlink",rr=()=>"/api/v1/passwordless_sms/unlink",ir=()=>"/api/v1/oauth/unlink";var Fi=30,bt=class{constructor(){this.authenticateOnce=new ye(async e=>this._authenticate(e)),this.linkOnce=new ye(async e=>this._link(e)),this.refreshOnce=new ye(this._refresh.bind(this)),this.destroyOnce=new ye(this._destroy.bind(this)),this.forkSessionOnce=new ye(this._forkSession.bind(this))}get token(){try{let e=T.get(Ve);return typeof e=="string"?new pe(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=T.get(ft);return typeof e=="string"?e:null}catch(e){return console.error(e),this.destroyLocalState(),null}}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=pe.parse(this.token);return e!==null&&!e.isExpired(Fi)}authenticate(e){return this.authenticateOnce.execute(e)}link(e){return this.linkOnce.execute(e)}refresh(){return this.refreshOnce.execute()}forkSession(){return this.forkSessionOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:o,refresh_token:r,user:i,is_new_user:n}=await e.authenticate();return this.storeToken(o),this.storeRefreshToken(r),{user:he(i),isNewUser:n}}catch(o){throw console.warn("Error authenticating session"),K(o)}}async _link(e){try{let o=await e.link();return he(o)}catch(o){throw console.warn("Error linking account"),K(o)}}async _refresh(){if(!this.api)throw new u("Session has no API instance");if(!this.client)throw new u("Session has no PrivyClient instance");let e=await this.client.getAccessToken({disableAutoRefresh:!0}),o=this.refreshToken;if(!e||!o)return null;try{let r=await this.api.post(Go(),{refresh_token:o},{headers:{authorization:`Bearer ${this.token}`}});return this.storeToken(r.data.token),this.storeRefreshToken(r.data.refresh_token),he(r.data.user)}catch(r){if(r instanceof Fe&&r.status===400&&r.message==="Invalid auth token")return this.destroyLocalState(),null;throw K(r)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(Vo(),{refresh_token:this.refreshToken}))}catch{console.warn("Error destroying session")}this.destroyLocalState()}async _forkSession(){if(!this.api)throw new u("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(Bo(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw K(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null),T.del(se)}storeToken(e){typeof e=="string"?T.put(Ve,e):T.del(Ve)}storeRefreshToken(e){typeof e=="string"?T.put(ft,e):T.del(ft)}};var ar=require("@ethersproject/address"),eo=v(require("@walletconnect/web3-provider"));var nr=require("@ethersproject/logger");var Be=class extends Z{constructor(){super("Wallet timeout");this.type="wallet_error"}},vt=t=>{if(t instanceof Z)return t;if((t==null?void 0:t.code)&&(t==null?void 0:t.reason)){let e=new He(t);return t.code===nr.ErrorCode.ACTION_REJECTED&&(e.details=Re.E4001_USER_REJECTED_REQUEST),e}return t!=null&&t.code?new He(t):new Z("Unknown connector error",t)},Qt=class extends ee{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},He=class extends Qt{constructor(o){var n,s,p;let r=o;super(r.message,r.code,r.data);let i=Object.values(Re).find(m=>m.eipCode===r.code);this.details=i||Re.UNKNOWN_ERROR,r.code===-32002&&((n=r.message)!=null&&n.includes("already pending for origin")?(s=r.message)!=null&&s.includes("wallet_requestPermissions")?this.details=Re.E32002_CONNECTION_ALREADY_PENDING:this.details=Re.E32002_REQUEST_ALREADY_PENDING:(p=r.message)!=null&&p.includes("Already processing")&&r.message.includes("eth_requestAccounts")&&(this.details=Re.E32002_WALLET_LOCKED))}},Gi={ERROR_USER_EXISTS:{message:"User already exists for this address",detail:"Try another address!",retryable:!1},ERROR_TIMED_OUT:{message:"Wallet request timed out",detail:"Please try connecting again.",retryable:!0},ERROR_WALLET_CONNECTION:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0}},Vi={E32002_CONNECTION_ALREADY_PENDING:{eipCode:-32002,message:"Connection request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_REQUEST_ALREADY_PENDING:{eipCode:-32002,message:"Resource request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_WALLET_LOCKED:{eipCode:-32002,message:"Wallet might be locked",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E4001_USER_REJECTED_REQUEST:{eipCode:4001,message:"Signature rejected",detail:"Please try signing again.",retryable:!0}},Bi={E4001_DEFAULT_USER_REJECTED_REQUEST:{eipCode:4001,message:"User Rejected Request",detail:"The user rejected the request.",default:!0,retryable:!0},E4100_DEFAULT_UNAUTHORIZED:{eipCode:4100,message:"Unauthorized",detail:"The requested method and/or account has not been authorized by the user.",default:!0,retryable:!1},E4200_DEFAULT_UNSUPPORTED_METHOD:{eipCode:4200,message:"Unsupported Method",detail:"The Provider does not support the requested method.",default:!0,retryable:!1},E4900_DEFAULT_DISCONNECTED:{eipCode:4900,message:"Disconnected",detail:"The Provider is disconnected from all chains.",default:!0,retryable:!0},E4901_DEFAULT_CHAIN_DISCONNECTED:{eipCode:4901,message:"Chain Disconnected",detail:"The Provider is not connected to the requested chain.",default:!0,retryable:!0},E32700_DEFAULT_PARSE_ERROR:{eipCode:-32700,message:"Parse error",detail:"Invalid JSON",default:!0,retryable:!1},E32600_DEFAULT_INVALID_REQUEST:{eipCode:-32600,message:"Invalid request",detail:"JSON is not a valid request object",default:!0,retryable:!1},E32601_DEFAULT_METHOD_NOT_FOUND:{eipCode:-32601,message:"Method not found",detail:"Method does not exist",default:!0,retryable:!1},E32602_DEFAULT_INVALID_PARAMS:{eipCode:-32602,message:"Invalid params",detail:"Invalid method parameters",default:!0,retryable:!1},E32603_DEFAULT_INTERNAL_ERROR:{eipCode:-32603,message:"Internal error",detail:"Internal JSON-RPC error",default:!0,retryable:!0},E32000_DEFAULT_INVALID_INPUT:{eipCode:-32e3,message:"Invalid input",detail:"Missing or invalid parameters",default:!0,retryable:!1},E32001_DEFAULT_RESOURCE_NOT_FOUND:{eipCode:-32001,message:"Resource not found",detail:"Requested resource not found",default:!0,retryable:!1},E32002_DEFAULT_RESOURCE_UNAVAILABLE:{eipCode:-32002,message:"Resource unavailable",detail:"Requested resource not available",default:!0,retryable:!0},E32003_DEFAULT_TRANSACTION_REJECTED:{eipCode:-32003,message:"Transaction rejected",detail:"Transaction creation failed",default:!0,retryable:!0},E32004_DEFAULT_METHOD_NOT_SUPPORTED:{eipCode:-32004,message:"Method not supported",detail:"Method is not implemented",default:!0,retryable:!1},E32005_DEFAULT_LIMIT_EXCEEDED:{eipCode:-32005,message:"Limit exceeded",detail:"Request exceeds defined limit",default:!0,retryable:!1},E32006_DEFAULT_JSON_RPC_VERSION_NOT_SUPPORTED:{eipCode:-32006,message:"JSON-RPC version not supported",detail:"Version of JSON-RPC protocol is not supported",default:!0,retryable:!1}},Re={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...Bi,...Vi},Ct={...Gi,...Re};var Hi=12e4,Xt=(t=new Be,e=Hi)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),Ce=class{constructor(e){this.removeListener=(e,o)=>{if(this.walletProvider)return this.walletProvider.removeListener(e,o)};this.setProvider=e=>{this.walletProvider=e,this._subscriptions.forEach(o=>{var r;(r=this.walletProvider)==null||r.on(o.eventName,o.listener)})};this.walletProvider=e,this._subscriptions=[]}on(e,o){if(this.walletProvider)return this.walletProvider.on(e,o);this._subscriptions.push({eventName:e,listener:o})}request(e){if(!this.walletProvider)throw new Z(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),Xt()]).catch(o=>{throw vt(o)})}},xe=class extends Ce{constructor(o){super(o)}},xt=class extends Ce{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var lr=require("@ethersproject/providers");var sr=["metamask","coinbase_wallet","wallet_connect"];var dr=v(require("@coinbase/wallet-sdk")),cr=require("react-device-detect"),zi=()=>{let t=`https://mainnet.infura.io/v3/${ht}`,e=1;return new dr.default({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(t,e)},to=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let t of window.ethereum.providers)if(t.isMetaMask)return!0}return!1},Lt=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let t of window.ethereum.providers)if(t.isCoinbaseWallet)return!0}return!1},ze=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,r,i,n,s,p)=>`${r} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${p}
@@ -9,7 +9,7 @@ Chain ID: ${e}
9
9
  Nonce: ${s}
10
10
  Issued At: ${n}
11
11
  Resources:
12
- - https://privy.io`;this.ethProvider=new Ce,this.initialized=!1}initialize(){let e=T.get(gt);sr.includes(e)?(this.walletType=e,this.connect({showPrompt:!1}).then(()=>this.initialized=!0)):this.initialized=!0}destroy(){this.walletType=null,T.del(gt),T.del(Do)}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.address(),r=await this.chainId();return{address:o,chainId:r,chainType:"ethereum",walletType:e}}async connect(e){var o;switch(this.walletType){case"metamask":this.ethProvider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async i=>{i.isMetaMask&&this.ethProvider.setProvider(i)});break;case"coinbase_wallet":this.ethProvider.setProvider(zi());break;case"wallet_connect":let r=new eo.default({infuraId:ht});this.ethProvider.setProvider(r);break;default:throw new K(`Unsupported wallet: ${this.walletType}`)}return(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(this.walletType),this.getConnectedWallet()}async isConnected(){switch(this.walletType){case"metamask":return await this.address()!==null;case"coinbase_wallet":return await this.address()!==null;case"wallet_connect":return this.ethProvider.walletProvider.connected;default:throw new K(`Unsupported wallet: ${this.walletType}`)}}async promptConnection(e){try{switch(e){case"metamask":cr.isMobile||await this.ethProvider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]}),await this.ethProvider.request({method:"eth_requestAccounts"});break;case"coinbase_wallet":await this.ethProvider.request({method:"eth_requestAccounts"});break;case"wallet_connect":let o=new eo.default({infuraId:ht});this.ethProvider.setProvider(o),await Promise.race([o.enable(),Xt()]);break;default:throw new K(`Unsupported wallet: ${this.walletType}`)}T.put(gt,e)}catch(o){throw vt(o)}}async sign(e){return new lr.Web3Provider(new xe(this.getEthereumProvider())).getSigner().signMessage(e)}prepareMessage(e,o,r){let i=window.location.host,n=window.location.origin,s="By signing, you are proving you own this wallet and logging in. This does not initiate a transaction or cost any fees.",p=new Date().toISOString();return this.createSiweMessage(e,o,i,n,p,r,s)}async chainId(){let e=await this.getEthereumProvider().request({method:"eth_chainId"}),o=Number(e);return String(o)}async address(){let e=await this.getEthereumProvider().request({method:"eth_accounts"});return Array.isArray(e)&&e.length>0?(0,ar.getAddress)(e[0]):null}};var oo,je=class{constructor(e){let o=e.apiURL||No,r=e.timeout||Uo;this.appId=e.appId,this.connector=new ze,oo||(oo=new bt),this.session=oo,this.api=new yt(e.appId,this,{baseURL:o,timeout:r}),this.session.api=this.api,this.session.client=this}authenticate(){if(!this.authFlow)throw new u("No auth flow in progress.");return this.session.authenticate(this.authFlow)}link(){if(!this.authFlow)throw new u("No auth flow in progress.");return this.session.link(this.authFlow)}async logout(){await this.session.destroy(),this.connector.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post(or(),{address:e});return he(o.data)}catch(o){throw q(o)}}async unlinkPhone(e){try{let o=await this.api.post(rr(),{phoneNumber:e});return he(o.data)}catch(o){throw q(o)}}async unlinkWallet(e){try{let o=await this.api.post(tr(),{address:e});return he(o.data)}catch(o){throw q(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(ir(),{provider:e,subject:o});return he(r.data)}catch(r){throw q(r)}}async getAuthenticatedUser(){return this.session.hasRefreshCredentials()?this.session.refresh():null}async getAccessToken(e){var o;return this.session.hasActiveToken()?((o=pe.parse(this.session.token))==null?void 0:o.audience)!==this.appId?(await this.logout(),null):this.session.token:!(e!=null&&e.disableAutoRefresh)&&this.session.hasRefreshCredentials()?(await this.session.refresh(),this.session.token):null}async getAppSettings(){try{let e=await this.api.get(`/api/v1/apps/${this.appId}`);return{id:e.data.id,name:e.data.name,verificationKey:e.data.verification_key,logoUrl:e.data.logo_url||void 0,theme:e.data.theme,accentColor:e.data.accent_color||void 0,showWalletLoginFirst:e.data.show_wallet_login_first,allowlistConfig:{errorTitle:e.data.allowlist_config.error_title,errorDetail:e.data.allowlist_config.error_detail,ctaText:e.data.allowlist_config.cta_text,ctaLink:e.data.allowlist_config.cta_link},walletAuth:e.data.wallet_auth,emailAuth:e.data.email_auth,smsAuth:e.data.sms_auth,googleOAuth:e.data.google_oauth,twitterOAuth:e.data.twitter_oauth,discordOAuth:e.data.discord_oauth,githubOAuth:e.data.github_oauth,termsAndConditionsUrl:e.data.terms_and_conditions_url,privacyPolicyUrl:e.data.privacy_policy_url,createdAt:new Date(e.data.created_at*1e3),updatedAt:new Date(e.data.updated_at*1e3)}}catch(e){throw q(e)}}setActiveWallet(e,o){if(!o.linkedAccounts.map(i=>i.type==="wallet"?i.address:null).includes(e))throw new u("Cannot set an unlinked address as active.");return T.put(se,e),Xe(o)}async forkSession(){return await this.session.forkSession()}};var Ai=require("@ethersproject/providers");var At=require("react");var w=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var ro=(0,At.createContext)({ready:!1,authenticated:!1,user:null,walletConnector:null,login:w,linkEmail:w,linkPhone:w,linkWallet:w,linkGoogle:w,linkTwitter:w,linkDiscord:w,linkGithub:w,logout:w,getAccessToken:w,getEthereumProvider:w,getEthersProvider:w,getWeb3jsProvider:w,unlinkEmail:w,unlinkPhone:w,unlinkWallet:w,unlinkGoogle:w,unlinkTwitter:w,unlinkDiscord:w,unlinkGithub:w,setActiveWallet:w,forkSession:w}),O=()=>(0,At.useContext)(ro);var et=class{constructor(e){this.connector=e,this.meta={wallet:this.connector.walletType}}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.connector.walletType)throw new u("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(zo(),{message:e,signature:o});return{user:r.data.user,token:r.data.token,refresh_token:r.data.refresh_token,is_new_user:r.data.is_new_user}}catch(e){throw W(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.connector.walletType)throw new u("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api);return(await this.api.post(jo(),{message:e,signature:o})).data}catch(e){throw W(e)}}async promptConnectAndSign(e){let o=await this.connector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(Ho(),{address:r}),s=this.connector.prepareMessage(i,r,n.data.nonce),p=await this.connector.sign(s);return{message:s,signature:p}}getEthereumProvider(){return this.connector.getEthereumProvider()}};var tt=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new u("Email and email code must be set prior to calling authenticate.");try{let e=Zo(),o=await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw W(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new u("Email and email code must be set prior to calling authenticate.");try{let e=Ko();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw W(e)}}async sendCodeEmail(e){if(!this.api)throw new u("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new u("Email must be set when initialzing authentication.");try{let o=$o();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw W(o)}}};var ot=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new u("phone number and sms code must be set prior to calling authenticate.");try{let e=Jo(),o=await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw W(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new u("phone number and sms code must be set prior to calling authenticate.");try{let e=Yo();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw W(e)}}async sendSmsCode(e){if(!this.api)throw new u("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new u("phone nNumber must be set when initialzing authentication.");try{let o=qo();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw W(o)}}};var $e=class{constructor(e,o,r){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=r}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new u("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new u("User denied confirmation during OAuth flow");try{let e=Xo(),o=await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw W(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new u("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new u("User denied confirmation during OAuth flow");try{let e=er();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw W(e)}}async getAuthorizationUrl(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.provider)throw new u("Provider must be set when initialzing OAuth authentication.");try{let e=Qo();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw W(e)}}};var Zd=require("wicg-inert"),Ci=v(require("react-dom")),$t=v(require("styled-components"));var ae=require("react");var pr=require("react/jsx-runtime");function ur(t){return(0,pr.jsx)("link",{rel:"prefetch",href:t.src})}var Et=require("react/jsx-runtime"),hr=(0,ae.createContext)({ready:!1,app:null,options:{email:!0,sms:!1,wallet:!0,google:!1,twitter:!1,discord:!1,github:!1},currentScreen:"LANDING",lastScreen:"LANDING",navigate:w,navigateBack:w}),mr=t=>{let e=t.appSettings,o=t.authenticated,r=t.visible,[i,n]=(0,ae.useState)("LANDING"),[s,p]=(0,ae.useState)("LANDING");(0,ae.useEffect)(()=>{o||n("LANDING")},[o]),(0,ae.useEffect)(()=>{r||(p("LANDING"),n("LANDING"))},[r]);let m={ready:!!(e!=null&&e.id),app:e,options:t.options,currentScreen:i,lastScreen:s,navigate:f=>{p(i),n(f)},navigateBack:()=>{n(s)}};return(0,Et.jsxs)(hr.Provider,{value:m,children:[e&&e.logoUrl&&(0,Et.jsx)(ur,{src:e.logoUrl}),t.children]})},y=()=>(0,ae.useContext)(hr);var Vt=require("react"),Je=v(require("styled-components"));var wr=v(require("styled-components"));var io=require("react/jsx-runtime"),fr=({style:t,...e})=>(0,io.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:(0,io.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});var no=require("react/jsx-runtime"),gr=({style:t,...e})=>(0,no.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:(0,no.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});var kt=require("react");var so=(0,kt.createContext)({isLinking:!1,getAuthMeta:w,getAuthFlow:w,closePrivyModal:w,initLoginWithWallet:w,loginWithWallet:w,loginWithCode:w,initLoginWithEmail:w,initLoginWithSms:w,resendEmailCode:w,resendSmsCode:w,initLoginWithOAuth:w,loginWithOAuth:w,handleLoginError:w}),I=()=>(0,kt.useContext)(so);var J=require("react/jsx-runtime"),ji=()=>(0,J.jsx)("div",{}),$i=({backFn:t})=>(0,J.jsx)("div",{children:(0,J.jsx)(gr,{onClick:t})}),Zi=t=>(0,J.jsx)("div",{children:(0,J.jsx)("div",{children:(0,J.jsx)(fr,{onClick:t.onClose})})});var k=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=I();return(0,J.jsxs)(Ki,{children:[t?(0,J.jsx)($i,{backFn:t}):(0,J.jsx)(ji,{}),(0,J.jsx)(Zi,{onClose:e||o})]})},Ki=wr.default.div`
12
+ - https://privy.io`;this.ethProvider=new Ce,this.initialized=!1}initialize(){let e=T.get(gt);sr.includes(e)?(this.walletType=e,this.connect({showPrompt:!1}).then(()=>this.initialized=!0)):this.initialized=!0}destroy(){this.walletType=null,T.del(gt),T.del(Do)}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.address(),r=await this.chainId();return{address:o,chainId:r,chainType:"ethereum",walletType:e}}async connect(e){var o;switch(this.walletType){case"metamask":this.ethProvider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async i=>{i.isMetaMask&&this.ethProvider.setProvider(i)});break;case"coinbase_wallet":this.ethProvider.setProvider(zi());break;case"wallet_connect":let r=new eo.default({infuraId:ht});this.ethProvider.setProvider(r);break;default:throw new Z(`Unsupported wallet: ${this.walletType}`)}return(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(this.walletType),this.getConnectedWallet()}async isConnected(){switch(this.walletType){case"metamask":return await this.address()!==null;case"coinbase_wallet":return await this.address()!==null;case"wallet_connect":return this.ethProvider.walletProvider.connected;default:throw new Z(`Unsupported wallet: ${this.walletType}`)}}async promptConnection(e){try{switch(e){case"metamask":cr.isMobile||await this.ethProvider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]}),await this.ethProvider.request({method:"eth_requestAccounts"});break;case"coinbase_wallet":await this.ethProvider.request({method:"eth_requestAccounts"});break;case"wallet_connect":let o=new eo.default({infuraId:ht});this.ethProvider.setProvider(o),await Promise.race([o.enable(),Xt()]);break;default:throw new Z(`Unsupported wallet: ${this.walletType}`)}T.put(gt,e)}catch(o){throw vt(o)}}async sign(e){return new lr.Web3Provider(new xe(this.getEthereumProvider())).getSigner().signMessage(e)}prepareMessage(e,o,r){let i=window.location.host,n=window.location.origin,s="By signing, you are proving you own this wallet and logging in. This does not initiate a transaction or cost any fees.",p=new Date().toISOString();return this.createSiweMessage(e,o,i,n,p,r,s)}async chainId(){let e=await this.getEthereumProvider().request({method:"eth_chainId"}),o=Number(e);return String(o)}async address(){let e=await this.getEthereumProvider().request({method:"eth_accounts"});return Array.isArray(e)&&e.length>0?(0,ar.getAddress)(e[0]):null}};var oo,je=class{constructor(e){let o=e.apiURL||No,r=e.timeout||Uo;this.appId=e.appId,this.connector=new ze,oo||(oo=new bt),this.session=oo,this.api=new yt(e.appId,this,{baseURL:o,timeout:r}),this.session.api=this.api,this.session.client=this}authenticate(){if(!this.authFlow)throw new u("No auth flow in progress.");return this.session.authenticate(this.authFlow)}link(){if(!this.authFlow)throw new u("No auth flow in progress.");return this.session.link(this.authFlow)}async logout(){await this.session.destroy(),this.connector.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post(or(),{address:e});return he(o.data)}catch(o){throw K(o)}}async unlinkPhone(e){try{let o=await this.api.post(rr(),{phoneNumber:e});return he(o.data)}catch(o){throw K(o)}}async unlinkWallet(e){try{let o=await this.api.post(tr(),{address:e});return he(o.data)}catch(o){throw K(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(ir(),{provider:e,subject:o});return he(r.data)}catch(r){throw K(r)}}async getAuthenticatedUser(){return this.session.hasRefreshCredentials()?this.session.refresh():null}async getAccessToken(e){var o;return this.session.hasActiveToken()?((o=pe.parse(this.session.token))==null?void 0:o.audience)!==this.appId?(await this.logout(),null):this.session.token:!(e!=null&&e.disableAutoRefresh)&&this.session.hasRefreshCredentials()?(await this.session.refresh(),this.session.token):null}async getAppSettings(){try{let e=await this.api.get(`/api/v1/apps/${this.appId}`);return{id:e.data.id,name:e.data.name,verificationKey:e.data.verification_key,logoUrl:e.data.logo_url||void 0,theme:e.data.theme,accentColor:e.data.accent_color||void 0,showWalletLoginFirst:e.data.show_wallet_login_first,allowlistConfig:{errorTitle:e.data.allowlist_config.error_title,errorDetail:e.data.allowlist_config.error_detail,ctaText:e.data.allowlist_config.cta_text,ctaLink:e.data.allowlist_config.cta_link},walletAuth:e.data.wallet_auth,emailAuth:e.data.email_auth,smsAuth:e.data.sms_auth,googleOAuth:e.data.google_oauth,twitterOAuth:e.data.twitter_oauth,discordOAuth:e.data.discord_oauth,githubOAuth:e.data.github_oauth,termsAndConditionsUrl:e.data.terms_and_conditions_url,privacyPolicyUrl:e.data.privacy_policy_url,createdAt:new Date(e.data.created_at*1e3),updatedAt:new Date(e.data.updated_at*1e3)}}catch(e){throw K(e)}}setActiveWallet(e,o){if(!o.linkedAccounts.map(i=>i.type==="wallet"?i.address:null).includes(e))throw new u("Cannot set an unlinked address as active.");return T.put(se,e),Xe(o)}async forkSession(){return await this.session.forkSession()}};var Ai=require("@ethersproject/providers");var At=require("react");var w=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var ro=(0,At.createContext)({ready:!1,authenticated:!1,user:null,walletConnector:null,login:w,linkEmail:w,linkPhone:w,linkWallet:w,linkGoogle:w,linkTwitter:w,linkDiscord:w,linkGithub:w,logout:w,getAccessToken:w,getEthereumProvider:w,getEthersProvider:w,getWeb3jsProvider:w,unlinkEmail:w,unlinkPhone:w,unlinkWallet:w,unlinkGoogle:w,unlinkTwitter:w,unlinkDiscord:w,unlinkGithub:w,setActiveWallet:w,forkSession:w}),O=()=>(0,At.useContext)(ro);var et=class{constructor(e){this.connector=e,this.meta={wallet:this.connector.walletType}}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.connector.walletType)throw new u("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(zo(),{message:e,signature:o});return{user:r.data.user,token:r.data.token,refresh_token:r.data.refresh_token,is_new_user:r.data.is_new_user}}catch(e){throw W(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.connector.walletType)throw new u("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api);return(await this.api.post(jo(),{message:e,signature:o})).data}catch(e){throw W(e)}}async promptConnectAndSign(e){let o=await this.connector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(Ho(),{address:r}),s=this.connector.prepareMessage(i,r,n.data.nonce),p=await this.connector.sign(s);return{message:s,signature:p}}getEthereumProvider(){return this.connector.getEthereumProvider()}};var tt=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new u("Email and email code must be set prior to calling authenticate.");try{let e=Zo(),o=await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw W(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new u("Email and email code must be set prior to calling authenticate.");try{let e=Ko();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw W(e)}}async sendCodeEmail(e){if(!this.api)throw new u("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new u("Email must be set when initialzing authentication.");try{let o=$o();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw W(o)}}};var ot=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new u("phone number and sms code must be set prior to calling authenticate.");try{let e=Jo(),o=await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw W(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new u("phone number and sms code must be set prior to calling authenticate.");try{let e=Yo();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw W(e)}}async sendSmsCode(e){if(!this.api)throw new u("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new u("phone nNumber must be set when initialzing authentication.");try{let o=qo();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw W(o)}}};var $e=class{constructor(e,o,r){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=r}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new u("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new u("User denied confirmation during OAuth flow");try{let e=Xo(),o=await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw W(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new u("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new u("User denied confirmation during OAuth flow");try{let e=er();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw W(e)}}async getAuthorizationUrl(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.provider)throw new u("Provider must be set when initialzing OAuth authentication.");try{let e=Qo();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw W(e)}}};var Zd=require("wicg-inert"),Ci=v(require("react-dom")),$t=v(require("styled-components"));var ae=require("react");var pr=require("react/jsx-runtime");function ur(t){return(0,pr.jsx)("link",{rel:"prefetch",href:t.src})}var Et=require("react/jsx-runtime"),hr=(0,ae.createContext)({ready:!1,app:null,options:{email:!0,sms:!1,wallet:!0,google:!1,twitter:!1,discord:!1,github:!1},currentScreen:"LANDING",lastScreen:"LANDING",navigate:w,navigateBack:w}),mr=t=>{let e=t.appSettings,o=t.authenticated,r=t.visible,[i,n]=(0,ae.useState)("LANDING"),[s,p]=(0,ae.useState)("LANDING");(0,ae.useEffect)(()=>{o||n("LANDING")},[o]),(0,ae.useEffect)(()=>{r||(p("LANDING"),n("LANDING"))},[r]);let m={ready:!!(e!=null&&e.id),app:e,options:t.options,currentScreen:i,lastScreen:s,navigate:f=>{p(i),n(f)},navigateBack:()=>{n(s)}};return(0,Et.jsxs)(hr.Provider,{value:m,children:[e&&e.logoUrl&&(0,Et.jsx)(ur,{src:e.logoUrl}),t.children]})},y=()=>(0,ae.useContext)(hr);var Vt=require("react"),Je=v(require("styled-components"));var wr=v(require("styled-components"));var io=require("react/jsx-runtime"),fr=({style:t,...e})=>(0,io.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:(0,io.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});var no=require("react/jsx-runtime"),gr=({style:t,...e})=>(0,no.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:(0,no.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});var kt=require("react");var so=(0,kt.createContext)({isLinking:!1,getAuthMeta:w,getAuthFlow:w,closePrivyModal:w,initLoginWithWallet:w,loginWithWallet:w,loginWithCode:w,initLoginWithEmail:w,initLoginWithSms:w,resendEmailCode:w,resendSmsCode:w,initLoginWithOAuth:w,loginWithOAuth:w,handleLoginError:w}),I=()=>(0,kt.useContext)(so);var q=require("react/jsx-runtime"),ji=()=>(0,q.jsx)("div",{}),$i=({backFn:t})=>(0,q.jsx)("div",{children:(0,q.jsx)(gr,{onClick:t})}),Zi=t=>(0,q.jsx)("div",{children:(0,q.jsx)("div",{children:(0,q.jsx)(fr,{onClick:t.onClose})})});var k=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=I();return(0,q.jsxs)(Ki,{children:[t?(0,q.jsx)($i,{backFn:t}):(0,q.jsx)(ji,{}),(0,q.jsx)(Zi,{onClose:e||o})]})},Ki=wr.default.div`
13
13
  height: 30px;
14
14
  display: flex;
15
15
  align-items: center;
@@ -158,7 +158,7 @@ Resources:
158
158
  @media (max-width: 440px) {
159
159
  margin-top: 4px;
160
160
  }
161
- `;var ho=v(require("styled-components"));var po=require("react/jsx-runtime"),Cr=({style:t,...e})=>(0,po.jsx)("svg",{width:"16",height:"17",viewBox:"0 0 16 17",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{height:"1.25rem",width:"1.25rem",...t},...e,children:(0,po.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.99555 0.929932C-1.12055 1.31799 -0.499722 9.15734 2.17445 8.76915C0.0807959 10.5544 -0.960455 16.6416 6.01654 16.0265C10.6356 15.9489 15.5635 12.2232 15.5635 8.1095C15.5635 2.63748 10.7516 0.929932 7.99555 0.929932ZM9.47052 7.53055C9.47052 8.49933 8.81856 9.28468 8.01433 9.28468C7.2101 9.28468 6.55814 8.49933 6.55814 7.53055C6.55814 6.56176 7.2101 5.77641 8.01433 5.77641C8.81856 5.77641 9.47052 6.56176 9.47052 7.53055ZM12.3171 9.28468C13.1213 9.28468 13.7733 8.49933 13.7733 7.53055C13.7733 6.56176 13.1213 5.77641 12.3171 5.77641C11.5129 5.77641 10.8609 6.56176 10.8609 7.53055C10.8609 8.49933 11.5129 9.28468 12.3171 9.28468Z",fill:"var(--primary-color)"})});var Y=require("react/jsx-runtime"),Yi=ho.default.div`
161
+ `;var ho=v(require("styled-components"));var po=require("react/jsx-runtime"),Cr=({style:t,...e})=>(0,po.jsx)("svg",{width:"16",height:"17",viewBox:"0 0 16 17",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{height:"1.25rem",width:"1.25rem",...t},...e,children:(0,po.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.99555 0.929932C-1.12055 1.31799 -0.499722 9.15734 2.17445 8.76915C0.0807959 10.5544 -0.960455 16.6416 6.01654 16.0265C10.6356 15.9489 15.5635 12.2232 15.5635 8.1095C15.5635 2.63748 10.7516 0.929932 7.99555 0.929932ZM9.47052 7.53055C9.47052 8.49933 8.81856 9.28468 8.01433 9.28468C7.2101 9.28468 6.55814 8.49933 6.55814 7.53055C6.55814 6.56176 7.2101 5.77641 8.01433 5.77641C8.81856 5.77641 9.47052 6.56176 9.47052 7.53055ZM12.3171 9.28468C13.1213 9.28468 13.7733 8.49933 13.7733 7.53055C13.7733 6.56176 13.1213 5.77641 12.3171 5.77641C11.5129 5.77641 10.8609 6.56176 10.8609 7.53055C10.8609 8.49933 11.5129 9.28468 12.3171 9.28468Z",fill:"var(--primary-color)"})});var J=require("react/jsx-runtime"),Yi=ho.default.div`
162
162
  margin-top: 16px;
163
163
  font-size: 12px;
164
164
  text-align: left;
@@ -167,7 +167,7 @@ Resources:
167
167
  && > a {
168
168
  color: var(--primary-color);
169
169
  }
170
- `;function xr(t){let{privacyPolicyUrl:e,termsAndConditionsUrl:o}=t.app,r=!!e,i=!!o,n=r&&i;return!r&&!i?null:(0,Y.jsxs)(Yi,{children:["By logging in I agree to the"," ",i&&(0,Y.jsx)("a",{href:o,target:"_blank",children:n?"Terms":"Terms of Service"}),n&&" & ",r&&(0,Y.jsx)("a",{href:e,target:"_blank",children:"Privacy Policy"})]})}var le=({protectedByPrivy:t})=>(0,Y.jsx)(ge,{hideOnMobile:t,children:t?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Cr,{}),(0,Y.jsx)("span",{children:(0,Y.jsx)("a",{href:"https://www.privy.io/",target:"_blank",children:"Protected by Privy"})})]}):null}),ge=ho.default.div`
170
+ `;function xr(t){let{privacyPolicyUrl:e,termsAndConditionsUrl:o}=t.app,r=!!e,i=!!o,n=r&&i;return!r&&!i?null:(0,J.jsxs)(Yi,{children:["By logging in I agree to the"," ",i&&(0,J.jsx)("a",{href:o,target:"_blank",children:n?"Terms":"Terms of Service"}),n&&" & ",r&&(0,J.jsx)("a",{href:e,target:"_blank",children:"Privacy Policy"})]})}var le=({protectedByPrivy:t})=>(0,J.jsx)(ge,{hideOnMobile:t,children:t?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Cr,{}),(0,J.jsx)("span",{children:(0,J.jsx)("a",{href:"https://www.privy.io/",target:"_blank",children:"Protected by Privy"})})]}):null}),ge=ho.default.div`
171
171
  height: 20px;
172
172
  font-size: 12px;
173
173
  display: flex;
@@ -537,7 +537,7 @@ Resources:
537
537
  width: 1rem;
538
538
  border-width: 2px;
539
539
  }
540
- `;var bo=require("react/jsx-runtime"),Rr=()=>{let{app:t}=y();return t!=null&&t.logoUrl?(0,bo.jsx)("div",{children:(0,bo.jsx)("img",{src:t.logoUrl,alt:`${t==null?void 0:t.name} logo`,style:{objectFit:"contain",width:"200px",height:"80px"}})}):null};var vo=require("react-device-detect"),h=require("react/jsx-runtime");var Wr=()=>{let{ready:t}=O(),{getAuthMeta:e,isLinking:o}=I(),{app:r,navigate:i,options:n}=y(),s=n.email,p=n.sms,m=n.wallet,f=n.google,A=n.twitter,N=n.discord,C=n.github,P=m&&(r==null?void 0:r.showWalletLoginFirst)?0:1,[M,d]=(0,Vt.useState)(P),b=e(),Z=(b==null?void 0:b.authorizationCode)&&(b==null?void 0:b.stateCode)&&(b==null?void 0:b.provider);(0,Vt.useEffect)(()=>{Z?i("AWAITING_OAUTH_SCREEN"):o&&s?i("LINK_EMAIL_SCREEN"):o&&p?i("LINK_PHONE_SCREEN"):o&&m&&i("LINK_WALLET_SCREEN")},[t]);let Ie=M==0,V=M==1,ue=()=>(0,h.jsx)(h.Fragment,{children:m&&(0,h.jsx)(gn,{active:Ie,onClick:()=>d(0)})}),x=()=>(0,h.jsx)(h.Fragment,{children:(s||p)&&(0,h.jsx)(wn,{active:V,onClick:()=>d(1),email:s,sms:p,google:f,twitter:A,discord:N,github:C})});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(k,{},"header"),(0,h.jsx)(vn,{walletOnly:!s&&!p&&!f&&!A&&!N&&!C,hasTerms:!!((r==null?void 0:r.privacyPolicyUrl)||(r==null?void 0:r.termsAndConditionsUrl)),children:(0,h.jsx)(Rr,{})}),(0,h.jsx)(Ae,{children:r!=null&&r.showWalletLoginFirst?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(ue,{}),(0,h.jsx)(x,{})]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(x,{}),(0,h.jsx)(ue,{})]})}),r&&(0,h.jsx)(xr,{app:r}),(0,h.jsx)(le,{protectedByPrivy:!0})]})};function gn(t){return(0,h.jsxs)(Or,{active:t.active,onClick:t.onClick,children:[(0,h.jsx)(Nr,{active:t.active,children:(0,h.jsx)("h4",{children:"Connect Wallet"})}),t.active&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(St,{}),(0,h.jsx)(Tt,{})]})]})}function wn(t){let e=t.google||t.discord||t.github||t.twitter&&!vo.isMobile,o=t.email?"Email":"Phone";return(0,h.jsxs)(Or,{active:t.active,onClick:t.onClick,children:[(0,h.jsx)(Nr,{active:t.active,children:(0,h.jsx)("h4",{children:e?`${o} & Social`:o})}),t.active&&t.email&&(0,h.jsx)(Dt,{}),t.active&&t.sms&&!t.email&&(0,h.jsx)(Gt,{}),t.active&&e&&(0,h.jsx)(yn,{google:t.google,twitter:t.twitter&&!vo.isMobile,discord:t.discord,github:t.github})]})}function yn(t){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(bn,{children:[(0,h.jsx)(Mr,{}),(0,h.jsx)("p",{children:" Or "}),(0,h.jsx)(Mr,{})]}),(0,h.jsx)(Ar,{showGoogle:t.google,showDiscord:t.discord,showGithub:t.github,showTwitter:t.twitter})]})}var Nr=Je.default.div`
540
+ `;var bo=require("react/jsx-runtime"),Rr=()=>{let{app:t}=y();return t!=null&&t.logoUrl?(0,bo.jsx)("div",{children:(0,bo.jsx)("img",{src:t.logoUrl,alt:`${t==null?void 0:t.name} logo`,style:{objectFit:"contain",width:"200px",height:"80px"}})}):null};var vo=require("react-device-detect"),h=require("react/jsx-runtime");var Wr=()=>{let{ready:t}=O(),{getAuthMeta:e,isLinking:o}=I(),{app:r,navigate:i,options:n}=y(),s=n.email,p=n.sms,m=n.wallet,f=n.google,A=n.twitter,N=n.discord,C=n.github,P=m&&(r==null?void 0:r.showWalletLoginFirst)?0:1,[M,d]=(0,Vt.useState)(P),b=e(),$=(b==null?void 0:b.authorizationCode)&&(b==null?void 0:b.stateCode)&&(b==null?void 0:b.provider);(0,Vt.useEffect)(()=>{$?i("AWAITING_OAUTH_SCREEN"):o&&s?i("LINK_EMAIL_SCREEN"):o&&p?i("LINK_PHONE_SCREEN"):o&&m&&i("LINK_WALLET_SCREEN")},[t]);let Ie=M==0,V=M==1,ue=()=>(0,h.jsx)(h.Fragment,{children:m&&(0,h.jsx)(gn,{active:Ie,onClick:()=>d(0)})}),x=()=>(0,h.jsx)(h.Fragment,{children:(s||p)&&(0,h.jsx)(wn,{active:V,onClick:()=>d(1),email:s,sms:p,google:f,twitter:A,discord:N,github:C})});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(k,{},"header"),(0,h.jsx)(vn,{walletOnly:!s&&!p&&!f&&!A&&!N&&!C,hasTerms:!!((r==null?void 0:r.privacyPolicyUrl)||(r==null?void 0:r.termsAndConditionsUrl)),children:(0,h.jsx)(Rr,{})}),(0,h.jsx)(Ae,{children:r!=null&&r.showWalletLoginFirst?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(ue,{}),(0,h.jsx)(x,{})]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(x,{}),(0,h.jsx)(ue,{})]})}),r&&(0,h.jsx)(xr,{app:r}),(0,h.jsx)(le,{protectedByPrivy:!0})]})};function gn(t){return(0,h.jsxs)(Or,{active:t.active,onClick:t.onClick,children:[(0,h.jsx)(Nr,{active:t.active,children:(0,h.jsx)("h4",{children:"Connect Wallet"})}),t.active&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(St,{}),(0,h.jsx)(Tt,{})]})]})}function wn(t){let e=t.google||t.discord||t.github||t.twitter&&!vo.isMobile,o=t.email?"Email":"Phone";return(0,h.jsxs)(Or,{active:t.active,onClick:t.onClick,children:[(0,h.jsx)(Nr,{active:t.active,children:(0,h.jsx)("h4",{children:e?`${o} & Social`:o})}),t.active&&t.email&&(0,h.jsx)(Dt,{}),t.active&&t.sms&&!t.email&&(0,h.jsx)(Gt,{}),t.active&&e&&(0,h.jsx)(yn,{google:t.google,twitter:t.twitter&&!vo.isMobile,discord:t.discord,github:t.github})]})}function yn(t){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(bn,{children:[(0,h.jsx)(Mr,{}),(0,h.jsx)("p",{children:" Or "}),(0,h.jsx)(Mr,{})]}),(0,h.jsx)(Ar,{showGoogle:t.google,showDiscord:t.discord,showGithub:t.github,showTwitter:t.twitter})]})}var Nr=Je.default.div`
541
541
  font-weight: ${t=>t.active?600:500};
542
542
  color: ${t=>t.active?"inherit":"var(--light-theme-fg-3)"};
543
543
  display: flex;
@@ -631,7 +631,7 @@ Resources:
631
631
  border-color: var(--light-theme-bg-3);
632
632
  border-width: 1px;
633
633
  }
634
- `;var _=require("react/jsx-runtime"),Co=6,Fr=new Array(Co).fill(""),Ln=1400;var Gr=()=>{var x,X,c;let{app:t}=y(),{closePrivyModal:e,resendEmailCode:o,resendSmsCode:r,getAuthMeta:i,loginWithCode:n}=I(),{authenticated:s,user:p}=O(),[m,f]=(0,Pe.useState)(Fr),[A,N]=(0,Pe.useState)(!1),[C,P]=(0,Pe.useState)(null),[M,d]=(0,Pe.useState)(null),b=(x=i())!=null&&x.email?0:1;(0,Pe.useEffect)(()=>{if(s&&A){let a=setTimeout(e,Ge);return()=>clearTimeout(a)}},[s,A,p]),(0,Pe.useEffect)(()=>{if(C&&M===0){let a=setTimeout(()=>{f(Fr),P(null);let E=document.querySelector("input[name=code-0]");E==null||E.focus()},Ln);return()=>clearTimeout(a)}},[C]);let Z=a=>{var Io;let E=a.currentTarget.value.replace(" ","");if(E==="")return;if(isNaN(Number(E))){P("Code should be numeric"),d(1);return}P(null),d(null);let z=Number((Io=a.currentTarget.name)==null?void 0:Io.charAt(5)),Zt=[...E||[""]].slice(0,Co-z),Kt=[...m.slice(0,z),...Zt,...m.slice(z+Zt.length)];f(Kt);let _i=Zt.length,To=Math.min(Math.max(z+_i,0),Co-1);if(!isNaN(Number(a.currentTarget.value))){let ne=document.querySelector(`input[name=code-${To}]`);ne==null||ne.focus()}if(Kt.every(ne=>ne&&!isNaN(+ne))){let ne=document.querySelector(`input[name=code-${To}]`);ne==null||ne.blur(),n(Kt.join("")).then(()=>N(!0)).catch(qt=>{(qt==null?void 0:qt.status)===422?P("Invalid or expired verification code"):P("Issue verifying code"),d(0)})}a.preventDefault()},Ie=a=>{M===1&&(P(null),d(null));let E=[...m.slice(0,a),"",...m.slice(a+1)];if(f(E),a>0){let z=document.querySelector(`input[name=code-${a-1}]`);z==null||z.focus()}},V=`Verify your ${b==0?"email":"phone"}`,ue=b==0?`Please check ${(X=i())==null?void 0:X.email} for an email from privy.io and enter your code below.`:`Please check ${(c=i())==null?void 0:c.phoneNumber} for a message from ${(t==null?void 0:t.name)||"privy.io"} and enter your code below.`;return(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(k,{},"header"),(0,_.jsxs)(An,{children:[(0,_.jsx)(Oe,{title:V,description:ue}),(0,_.jsxs)(Lr,{children:[(0,_.jsxs)(En,{children:[(0,_.jsx)(kn,{fail:!!C,success:A,children:(0,_.jsx)("span",{children:C||(A?"Success!":"")})}),(0,_.jsx)("div",{children:m.map((a,E)=>(0,_.jsx)("input",{name:`code-${E}`,type:"text",value:m[E],onChange:Z,onKeyUp:z=>{z.key==="Backspace"&&Ie(E)},inputMode:"numeric",autoFocus:E===0,pattern:"[0-9]",className:`${A?"success":""} ${C?"fail":""}`,autoComplete:"one-time-code"},E))})]}),(0,_.jsx)(_n,{children:b==0?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("span",{children:"Didn't get an email?"}),(0,_.jsx)("button",{onClick:o,children:"Resend Code"})]}):(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("span",{children:"Didn't get a message?"}),(0,_.jsx)("button",{onClick:r,children:"Resend Code"})]})})]})]}),(0,_.jsx)(le,{protectedByPrivy:!0})]})},An=st.default.div`
634
+ `;var _=require("react/jsx-runtime"),Co=6,Fr=new Array(Co).fill(""),Ln=1400;var Gr=()=>{var x,X,c;let{app:t}=y(),{closePrivyModal:e,resendEmailCode:o,resendSmsCode:r,getAuthMeta:i,loginWithCode:n}=I(),{authenticated:s,user:p}=O(),[m,f]=(0,Pe.useState)(Fr),[A,N]=(0,Pe.useState)(!1),[C,P]=(0,Pe.useState)(null),[M,d]=(0,Pe.useState)(null),b=(x=i())!=null&&x.email?0:1;(0,Pe.useEffect)(()=>{if(s&&A){let a=setTimeout(e,Ge);return()=>clearTimeout(a)}},[s,A,p]),(0,Pe.useEffect)(()=>{if(C&&M===0){let a=setTimeout(()=>{f(Fr),P(null);let E=document.querySelector("input[name=code-0]");E==null||E.focus()},Ln);return()=>clearTimeout(a)}},[C]);let $=a=>{var Io;let E=a.currentTarget.value.replace(" ","");if(E==="")return;if(isNaN(Number(E))){P("Code should be numeric"),d(1);return}P(null),d(null);let z=Number((Io=a.currentTarget.name)==null?void 0:Io.charAt(5)),Zt=[...E||[""]].slice(0,Co-z),Kt=[...m.slice(0,z),...Zt,...m.slice(z+Zt.length)];f(Kt);let _i=Zt.length,To=Math.min(Math.max(z+_i,0),Co-1);if(!isNaN(Number(a.currentTarget.value))){let ne=document.querySelector(`input[name=code-${To}]`);ne==null||ne.focus()}if(Kt.every(ne=>ne&&!isNaN(+ne))){let ne=document.querySelector(`input[name=code-${To}]`);ne==null||ne.blur(),n(Kt.join("")).then(()=>N(!0)).catch(qt=>{(qt==null?void 0:qt.status)===422?P("Invalid or expired verification code"):P("Issue verifying code"),d(0)})}a.preventDefault()},Ie=a=>{M===1&&(P(null),d(null));let E=[...m.slice(0,a),"",...m.slice(a+1)];if(f(E),a>0){let z=document.querySelector(`input[name=code-${a-1}]`);z==null||z.focus()}},V=`Verify your ${b==0?"email":"phone"}`,ue=b==0?`Please check ${(X=i())==null?void 0:X.email} for an email from privy.io and enter your code below.`:`Please check ${(c=i())==null?void 0:c.phoneNumber} for a message from ${(t==null?void 0:t.name)||"privy.io"} and enter your code below.`;return(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(k,{},"header"),(0,_.jsxs)(An,{children:[(0,_.jsx)(Oe,{title:V,description:ue}),(0,_.jsxs)(Lr,{children:[(0,_.jsxs)(En,{children:[(0,_.jsx)(kn,{fail:!!C,success:A,children:(0,_.jsx)("span",{children:C||(A?"Success!":"")})}),(0,_.jsx)("div",{children:m.map((a,E)=>(0,_.jsx)("input",{name:`code-${E}`,type:"text",value:m[E],onChange:$,onKeyUp:z=>{z.key==="Backspace"&&Ie(E)},inputMode:"numeric",autoFocus:E===0,pattern:"[0-9]",className:`${A?"success":""} ${C?"fail":""}`,autoComplete:"one-time-code"},E))})]}),(0,_.jsx)(_n,{children:b==0?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("span",{children:"Didn't get an email?"}),(0,_.jsx)("button",{onClick:o,children:"Resend Code"})]}):(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("span",{children:"Didn't get a message?"}),(0,_.jsx)("button",{onClick:r,children:"Resend Code"})]})})]})]}),(0,_.jsx)(le,{protectedByPrivy:!0})]})},An=st.default.div`
635
635
  display: flex;
636
636
  flex-direction: column;
637
637
  align-items: flex-start;
@@ -791,7 +791,7 @@ Resources:
791
791
  opacity: ${t=>t.visible?"1":"0"};
792
792
  transition: opacity 200ms;
793
793
  }
794
- `;var ii=require("react"),Q=v(require("styled-components"));var Zr=v(require("qrcode")),Kr=v(require("styled-components"));var L=require("react/jsx-runtime"),$=7,Lo=(t,e,o,r,i)=>{for(let n=e;n<e+r;n++)for(let s=o;s<o+i;s++){let p=t==null?void 0:t[s];p&&p[n]&&(p[n]=0)}return t},In=t=>{let e=Zr.default.create(t,{errorCorrectionLevel:"high"}).modules,o=Tr(Array.from(e.data),e.size);return o=Lo(o,0,0,$,$),o=Lo(o,o.length-$,0,$,$),o=Lo(o,0,o.length-$,$,$),o},Rn=({x:t,y:e,cellSize:o,bgColor:r,fgColor:i})=>(0,L.jsx)(L.Fragment,{children:[0,1,2].map(n=>(0,L.jsx)("circle",{r:o*($-n*2)/2,cx:t+o*$/2,cy:e+o*$/2,fill:n%2!==0?r:i},`finder-${t}-${e}-${n}`))}),Mn=({cellSize:t,matrixSize:e,bgColor:o,fgColor:r})=>{let i=[[0,0],[(e-$)*t,0],[0,(e-$)*t]];return(0,L.jsx)(L.Fragment,{children:i.map(([n,s])=>(0,L.jsx)(Rn,{x:n,y:s,cellSize:t,bgColor:o,fgColor:r}))})},Wn=({matrix:t,cellSize:e,color:o})=>(0,L.jsx)(L.Fragment,{children:t.map((r,i)=>r.map((n,s)=>n?(0,L.jsx)("circle",{r:e/2.5,cx:i*e+e/2,cy:s*e+e/2,fill:o},`circle-${i}-${s}`):(0,L.jsx)(L.Fragment,{})))}),$r=(t,e)=>t-t%e,Nn=({outputSize:t,cellSize:e,element:o,size:r,padding:i,bgColor:n})=>{if(!o)return(0,L.jsx)(L.Fragment,{});let s=r||40,p=i||4,m=o,f=t/2-s/2-p;return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)("rect",{x:$r(f,e),y:$r(f,e),width:s+p*2+(f%e?e+.5:.5),height:s+p*2+(f%e?e+.5:.5),fill:n}),(0,L.jsx)(m,{x:t/2-s/2,y:t/2-s/2,height:s,width:s})]})},On=t=>{var i;let e=t.outputSize,o=In(t.url),r=e/o.length;return(0,L.jsxs)("svg",{height:t.outputSize,width:t.outputSize,viewBox:`0 0 ${t.outputSize} ${t.outputSize}`,style:{height:"100%",width:"100%"},children:[(0,L.jsx)(Wn,{matrix:o,cellSize:r,color:t.fgColor}),(0,L.jsx)(Mn,{cellSize:r,matrixSize:o.length,fgColor:t.fgColor,bgColor:t.bgColor}),(0,L.jsx)(Nn,{outputSize:t.outputSize,cellSize:r,element:(i=t.logo)==null?void 0:i.element,bgColor:t.bgColor})]})},Un=Kr.default.div`
794
+ `;var ii=require("react"),Y=v(require("styled-components"));var Zr=v(require("qrcode")),Kr=v(require("styled-components"));var L=require("react/jsx-runtime"),j=7,Lo=(t,e,o,r,i)=>{for(let n=e;n<e+r;n++)for(let s=o;s<o+i;s++){let p=t==null?void 0:t[s];p&&p[n]&&(p[n]=0)}return t},In=t=>{let e=Zr.default.create(t,{errorCorrectionLevel:"high"}).modules,o=Tr(Array.from(e.data),e.size);return o=Lo(o,0,0,j,j),o=Lo(o,o.length-j,0,j,j),o=Lo(o,0,o.length-j,j,j),o},Rn=({x:t,y:e,cellSize:o,bgColor:r,fgColor:i})=>(0,L.jsx)(L.Fragment,{children:[0,1,2].map(n=>(0,L.jsx)("circle",{r:o*(j-n*2)/2,cx:t+o*j/2,cy:e+o*j/2,fill:n%2!==0?r:i},`finder-${t}-${e}-${n}`))}),Mn=({cellSize:t,matrixSize:e,bgColor:o,fgColor:r})=>{let i=[[0,0],[(e-j)*t,0],[0,(e-j)*t]];return(0,L.jsx)(L.Fragment,{children:i.map(([n,s])=>(0,L.jsx)(Rn,{x:n,y:s,cellSize:t,bgColor:o,fgColor:r}))})},Wn=({matrix:t,cellSize:e,color:o})=>(0,L.jsx)(L.Fragment,{children:t.map((r,i)=>r.map((n,s)=>n?(0,L.jsx)("circle",{r:e/2.5,cx:i*e+e/2,cy:s*e+e/2,fill:o},`circle-${i}-${s}`):(0,L.jsx)(L.Fragment,{})))}),$r=(t,e)=>t-t%e,Nn=({outputSize:t,cellSize:e,element:o,size:r,padding:i,bgColor:n})=>{if(!o)return(0,L.jsx)(L.Fragment,{});let s=r||40,p=i||4,m=o,f=t/2-s/2-p;return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)("rect",{x:$r(f,e),y:$r(f,e),width:s+p*2+(f%e?e+.5:.5),height:s+p*2+(f%e?e+.5:.5),fill:n}),(0,L.jsx)(m,{x:t/2-s/2,y:t/2-s/2,height:s,width:s})]})},On=t=>{var i;let e=t.outputSize,o=In(t.url),r=e/o.length;return(0,L.jsxs)("svg",{height:t.outputSize,width:t.outputSize,viewBox:`0 0 ${t.outputSize} ${t.outputSize}`,style:{height:"100%",width:"100%"},children:[(0,L.jsx)(Wn,{matrix:o,cellSize:r,color:t.fgColor}),(0,L.jsx)(Mn,{cellSize:r,matrixSize:o.length,fgColor:t.fgColor,bgColor:t.bgColor}),(0,L.jsx)(Nn,{outputSize:t.outputSize,cellSize:r,element:(i=t.logo)==null?void 0:i.element,bgColor:t.bgColor})]})},Un=Kr.default.div`
795
795
  display: flex;
796
796
  justify-content: center;
797
797
  align-items: center;
@@ -866,7 +866,7 @@ Resources:
866
866
  border: 1px solid var(--light-theme-bg-3);
867
867
  color: var(--light-theme-fg-1);
868
868
  }
869
- `;var l=require("react/jsx-runtime");var ko=()=>{let{navigate:t}=y(),e="https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en";return Se.isFirefox&&(e="https://addons.mozilla.org/en-US/firefox/addon/ether-metamask/"),(0,l.jsxs)(si,{children:[(0,l.jsx)(Oe,{title:"Create a Metamask wallet",description:"Follow the instructions below to get started."}),(0,l.jsx)(ai,{children:(0,l.jsx)(Me,{style:{width:"152px",height:"152px"}})}),(0,l.jsxs)(Eo,{children:[(0,l.jsx)(Ue,{children:(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{children:"Install the "}),(0,l.jsx)("a",{href:e,target:"_blank",children:"MetaMask browser extension"})]})}),(0,l.jsx)(lt,{}),(0,l.jsx)(Ue,{children:"Set up your first wallet"}),(0,l.jsx)(lt,{}),(0,l.jsx)(Ue,{children:"Store your recovery phrase in a safe place!"})]}),(0,l.jsx)(li,{onClick:()=>t("LANDING"),children:"Done! I have my wallet"})]})},_o=()=>{let{navigate:t}=y();return(0,l.jsxs)(si,{children:[(0,l.jsx)(Oe,{title:"Create a Coinbase wallet",description:"Follow the instructions below to get started."}),(0,l.jsx)(ai,{style:{marginTop:"-24px"},children:(0,l.jsx)(Jr,{size:200})}),(0,l.jsxs)(Eo,{children:[(0,l.jsx)(Ue,{children:"Scan the QR code with your camera"}),(0,l.jsx)(lt,{}),(0,l.jsx)(Ue,{children:"Set up your first wallet"}),(0,l.jsx)(lt,{}),(0,l.jsx)(Ue,{children:"Store your seed phrase in a safe place!"})]}),(0,l.jsx)(li,{onClick:()=>t("LANDING"),children:"Done! I have my wallet"})]})},ni=()=>{let[t,e]=(0,ii.useState)("WHAT_IS_A_WALLET"),{navigateBack:o}=y();return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(k,{backFn:t==="WHAT_IS_A_WALLET"?o:t==="PICK_A_NEW_WALLET"?()=>e("WHAT_IS_A_WALLET"):()=>e("PICK_A_NEW_WALLET")},"header"),(0,l.jsxs)(Fn,{children:[t==="WHAT_IS_A_WALLET"&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(zn,{children:(0,l.jsx)(Xr,{style:{width:"240px",height:"auto",borderRadius:"var(--border-radius-sm)",marginBottom:"32px"}})}),(0,l.jsxs)(Ye,{title:"Get started with a new wallet",children:[(0,l.jsx)("p",{children:"Wallets help you store, send, and receive digital assets and collectibles. They are also a new\xA0way\xA0to\xA0log\xA0in."}),(0,l.jsx)("p",{children:"Instead of creating new accounts and passwords for every app, you just connect your wallet and bring your\xA0data\xA0with\xA0you."})]}),(0,l.jsx)(Bn,{children:(0,l.jsx)(Hn,{onClick:()=>{e("PICK_A_NEW_WALLET")},children:"Create a wallet"})})]}),t==="PICK_A_NEW_WALLET"&&(0,l.jsx)(l.Fragment,{children:(0,l.jsxs)(Gn,{children:[(0,l.jsx)(Oe,{title:"Create a new wallet",description:"Select one the wallet providers below to get started on your web3 adventure."}),(0,l.jsxs)(Vn,{children:[(0,l.jsxs)(oi,{onClick:()=>{Se.isIOS?window.location.href="https://apps.apple.com/us/app/metamask-blockchain-wallet/id1438144202":Se.isAndroid?window.location.href="https://play.google.com/store/apps/details?id=io.metamask":e("CREATE_METAMASK_WALLET")},children:[(0,l.jsx)(Me,{}),(0,l.jsxs)(ri,{children:[(0,l.jsx)("h4",{children:"MetaMask"}),(0,l.jsx)("p",{children:"Get a browser-based wallet"})]}),(0,l.jsx)("div",{children:(0,l.jsx)("span",{children:"Set up"})})]}),(0,l.jsxs)(oi,{onClick:()=>{Se.isIOS?window.location.href="https://apps.apple.com/us/app/coinbase-wallet-nfts-crypto/id1278383455":Se.isAndroid?window.location.href="https://play.google.com/store/apps/details?id=org.toshi":e("CREATE_COINBASE_WALLET")},children:[(0,l.jsx)(Le,{}),(0,l.jsxs)(ri,{children:[(0,l.jsx)("h4",{children:"Coinbase Wallet"}),(0,l.jsx)("p",{children:"Get a mobile app wallet"})]}),(0,l.jsx)("div",{children:(0,l.jsx)("span",{children:"Set up"})})]})]})]})}),t==="CREATE_COINBASE_WALLET"&&(0,l.jsx)(_o,{}),t==="CREATE_METAMASK_WALLET"&&(0,l.jsx)(ko,{})]}),(0,l.jsxs)(ge,{children:[(0,l.jsx)("span",{children:"Still not sure? "}),(0,l.jsx)("a",{target:"_blank",href:"https://join.tell.ie/blog/explaining-web3-wallets",children:"Learn more"}),"."]})]})},Fn=Q.default.div`
869
+ `;var l=require("react/jsx-runtime");var ko=()=>{let{navigate:t}=y(),e="https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en";return Se.isFirefox&&(e="https://addons.mozilla.org/en-US/firefox/addon/ether-metamask/"),(0,l.jsxs)(si,{children:[(0,l.jsx)(Oe,{title:"Create a Metamask wallet",description:"Follow the instructions below to get started."}),(0,l.jsx)(ai,{children:(0,l.jsx)(Me,{style:{width:"152px",height:"152px"}})}),(0,l.jsxs)(Eo,{children:[(0,l.jsx)(Ue,{children:(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{children:"Install the "}),(0,l.jsx)("a",{href:e,target:"_blank",children:"MetaMask browser extension"})]})}),(0,l.jsx)(lt,{}),(0,l.jsx)(Ue,{children:"Set up your first wallet"}),(0,l.jsx)(lt,{}),(0,l.jsx)(Ue,{children:"Store your recovery phrase in a safe place!"})]}),(0,l.jsx)(li,{onClick:()=>t("LANDING"),children:"Done! I have my wallet"})]})},_o=()=>{let{navigate:t}=y();return(0,l.jsxs)(si,{children:[(0,l.jsx)(Oe,{title:"Create a Coinbase wallet",description:"Follow the instructions below to get started."}),(0,l.jsx)(ai,{style:{marginTop:"-24px"},children:(0,l.jsx)(Jr,{size:200})}),(0,l.jsxs)(Eo,{children:[(0,l.jsx)(Ue,{children:"Scan the QR code with your camera"}),(0,l.jsx)(lt,{}),(0,l.jsx)(Ue,{children:"Set up your first wallet"}),(0,l.jsx)(lt,{}),(0,l.jsx)(Ue,{children:"Store your seed phrase in a safe place!"})]}),(0,l.jsx)(li,{onClick:()=>t("LANDING"),children:"Done! I have my wallet"})]})},ni=()=>{let[t,e]=(0,ii.useState)("WHAT_IS_A_WALLET"),{navigateBack:o}=y();return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(k,{backFn:t==="WHAT_IS_A_WALLET"?o:t==="PICK_A_NEW_WALLET"?()=>e("WHAT_IS_A_WALLET"):()=>e("PICK_A_NEW_WALLET")},"header"),(0,l.jsxs)(Fn,{children:[t==="WHAT_IS_A_WALLET"&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(zn,{children:(0,l.jsx)(Xr,{style:{width:"240px",height:"auto",borderRadius:"var(--border-radius-sm)",marginBottom:"32px"}})}),(0,l.jsxs)(Ye,{title:"Get started with a new wallet",children:[(0,l.jsx)("p",{children:"Wallets help you store, send, and receive digital assets and collectibles. They are also a new\xA0way\xA0to\xA0log\xA0in."}),(0,l.jsx)("p",{children:"Instead of creating new accounts and passwords for every app, you just connect your wallet and bring your\xA0data\xA0with\xA0you."})]}),(0,l.jsx)(Bn,{children:(0,l.jsx)(Hn,{onClick:()=>{e("PICK_A_NEW_WALLET")},children:"Create a wallet"})})]}),t==="PICK_A_NEW_WALLET"&&(0,l.jsx)(l.Fragment,{children:(0,l.jsxs)(Gn,{children:[(0,l.jsx)(Oe,{title:"Create a new wallet",description:"Select one the wallet providers below to get started on your web3 adventure."}),(0,l.jsxs)(Vn,{children:[(0,l.jsxs)(oi,{onClick:()=>{Se.isIOS?window.location.href="https://apps.apple.com/us/app/metamask-blockchain-wallet/id1438144202":Se.isAndroid?window.location.href="https://play.google.com/store/apps/details?id=io.metamask":e("CREATE_METAMASK_WALLET")},children:[(0,l.jsx)(Me,{}),(0,l.jsxs)(ri,{children:[(0,l.jsx)("h4",{children:"MetaMask"}),(0,l.jsx)("p",{children:"Get a browser-based wallet"})]}),(0,l.jsx)("div",{children:(0,l.jsx)("span",{children:"Set up"})})]}),(0,l.jsxs)(oi,{onClick:()=>{Se.isIOS?window.location.href="https://apps.apple.com/us/app/coinbase-wallet-nfts-crypto/id1278383455":Se.isAndroid?window.location.href="https://play.google.com/store/apps/details?id=org.toshi":e("CREATE_COINBASE_WALLET")},children:[(0,l.jsx)(Le,{}),(0,l.jsxs)(ri,{children:[(0,l.jsx)("h4",{children:"Coinbase Wallet"}),(0,l.jsx)("p",{children:"Get a mobile app wallet"})]}),(0,l.jsx)("div",{children:(0,l.jsx)("span",{children:"Set up"})})]})]})]})}),t==="CREATE_COINBASE_WALLET"&&(0,l.jsx)(_o,{}),t==="CREATE_METAMASK_WALLET"&&(0,l.jsx)(ko,{})]}),(0,l.jsxs)(ge,{children:[(0,l.jsx)("span",{children:"Still not sure? "}),(0,l.jsx)("a",{target:"_blank",href:"https://join.tell.ie/blog/explaining-web3-wallets",children:"Learn more"}),"."]})]})},Fn=Y.default.div`
870
870
  display: flex;
871
871
  flex-direction: column;
872
872
  height: 100%;
@@ -876,19 +876,19 @@ Resources:
876
876
  display: none;
877
877
  }
878
878
  }
879
- `,Gn=Q.default.div`
879
+ `,Gn=Y.default.div`
880
880
  display: flex;
881
881
  flex-direction: column;
882
882
  align-items: flex-start;
883
883
  justify-content: flex-start;
884
884
  text-align: left;
885
885
  gap: 20px;
886
- `,Vn=Q.default.div`
886
+ `,Vn=Y.default.div`
887
887
  display: flex;
888
888
  flex-direction: column;
889
889
  width: 100%;
890
890
  gap: 8px;
891
- `,oi=Q.default.button`
891
+ `,oi=Y.default.button`
892
892
  display: flex;
893
893
  flex-direction: row;
894
894
  align-items: center;
@@ -945,24 +945,24 @@ Resources:
945
945
  border: 1px solid var(--border-color-2);
946
946
  }
947
947
  }
948
- `,ri=Q.default.div`
948
+ `,ri=Y.default.div`
949
949
  text-align: left;
950
950
 
951
951
  p {
952
952
  font-style: italic;
953
953
  font-size: 12px;
954
954
  }
955
- `,Bn=Q.default.div`
955
+ `,Bn=Y.default.div`
956
956
  margin-top: auto;
957
957
  display: flex;
958
958
  align-items: flex-end;
959
959
  flex-grow: 1;
960
960
  width: 100%;
961
- `,Hn=(0,Q.default)(ti)`
961
+ `,Hn=(0,Y.default)(ti)`
962
962
  && {
963
963
  margin-top: 14px;
964
964
  }
965
- `,si=Q.default.div`
965
+ `,si=Y.default.div`
966
966
  display: flex;
967
967
  flex-direction: column;
968
968
  align-items: center;
@@ -973,13 +973,13 @@ Resources:
973
973
  > :first-child > svg {
974
974
  margin-top: 20px;
975
975
  }
976
- `,ai=Q.default.div`
976
+ `,ai=Y.default.div`
977
977
  display: flex;
978
978
  flex-direction: column;
979
979
  align-items: center;
980
980
  justify-content: center;
981
981
  width: 100%;
982
- `,li=Q.default.button`
982
+ `,li=Y.default.button`
983
983
  && {
984
984
  padding: 12px 16px;
985
985
  font-weight: 500;
@@ -988,10 +988,10 @@ Resources:
988
988
  background-color: var(--primary-color-bg-1);
989
989
  border-radius: var(--border-radius-sm);
990
990
  }
991
- `,zn=Q.default.div`
991
+ `,zn=Y.default.div`
992
992
  display: flex;
993
993
  justify-content: center;
994
- `;var Te=require("react");var dt=v(require("styled-components"));var B=require("react/jsx-runtime"),Po=2,di={metamask:{name:"MetaMask",component:Me},coinbase_wallet:{name:"Coinbase Wallet",component:Le},wallet_connect:{name:"WalletConnect",component:_t}},ci=()=>{var ue;let[t,e]=(0,Te.useState)(!1),[o,r]=(0,Te.useState)(void 0),{navigate:i,navigateBack:n}=y(),{getAuthMeta:s,closePrivyModal:p,loginWithWallet:m,handleLoginError:f}=I(),[A,N]=(0,Te.useState)(0),{user:C}=O(),[P,M]=(0,Te.useState)((C==null?void 0:C.linkedAccounts.length)||0);(0,Te.useEffect)(()=>{r(void 0),m().then(()=>e(!0)).catch(x=>{x instanceof ee?console.error(x.cause):console.error(x);let X=(x==null?void 0:x.status)===401&&(x==null?void 0:x.message)==="User is not allowed to login to this app.";(x==null?void 0:x.status)===422?r(Ct.ERROR_USER_EXISTS):X?i("ALLOWLIST_REJECTION_SCREEN"):x instanceof He&&!x.details.default?r(x.details):x instanceof Be?r(Ct.ERROR_TIMED_OUT):r(Ct.ERROR_WALLET_CONNECTION),f(X)})},[A]),(0,Te.useEffect)(()=>{if(t){let x=setTimeout(p,Ge);return()=>clearTimeout(x)}},[C]);let d=((ue=s())==null?void 0:ue.wallet)||"metamask",b=di[d].name,Z=di[d].component,Ie=t?`Successfully connected with ${b}`:o?o.message:`Waiting for ${b}`,V="";if(t){let x=(C==null?void 0:C.linkedAccounts.length)||0;P===x?V="Wallet was already linked.":V="You\u2019re good to go!"}else if(A>=Po&&o)V="Unable to connect wallet";else if(o)V=o.detail;else switch(V="Don\u2019t see your wallet modal? Check your other browser windows.",d){case"wallet_connect":V="Open your mobile wallet app to continue";break;case"coinbase_wallet":Lt()||(V="Open the Coinbase app on your phone to continue.");break;default:V="Don\u2019t see your wallet modal? Check your other browser windows."}return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(k,{backFn:n}),(0,B.jsxs)(jn,{children:[(0,B.jsx)(Zn,{children:(0,B.jsxs)("div",{children:[(0,B.jsx)(Ot,{success:t,fail:!!o}),(0,B.jsx)(Z,{style:{width:"38px",height:"38px"}})]})}),(0,B.jsxs)($n,{children:[(0,B.jsx)("h3",{children:Ie}),(0,B.jsx)("p",{children:V})]}),(0,B.jsx)(Kn,{onClick:()=>{N(A+1),r(void 0)},visible:!t&&(o==null?void 0:o.retryable)&&A<Po,disabled:!t&&(!(o!=null&&o.retryable)||A>=Po),children:"Retry"})]})]})},jn=dt.default.div`
994
+ `;var Te=require("react");var dt=v(require("styled-components"));var B=require("react/jsx-runtime"),Po=2,di={metamask:{name:"MetaMask",component:Me},coinbase_wallet:{name:"Coinbase Wallet",component:Le},wallet_connect:{name:"WalletConnect",component:_t}},ci=()=>{var ue;let[t,e]=(0,Te.useState)(!1),[o,r]=(0,Te.useState)(void 0),{navigate:i,navigateBack:n}=y(),{getAuthMeta:s,closePrivyModal:p,loginWithWallet:m,handleLoginError:f}=I(),[A,N]=(0,Te.useState)(0),{user:C}=O(),[P,M]=(0,Te.useState)((C==null?void 0:C.linkedAccounts.length)||0);(0,Te.useEffect)(()=>{r(void 0),m().then(()=>e(!0)).catch(x=>{x instanceof ee?console.error(x.cause):console.error(x);let X=(x==null?void 0:x.status)===401&&(x==null?void 0:x.message)==="User is not allowed to login to this app.";(x==null?void 0:x.status)===422?r(Ct.ERROR_USER_EXISTS):X?i("ALLOWLIST_REJECTION_SCREEN"):x instanceof He&&!x.details.default?r(x.details):x instanceof Be?r(Ct.ERROR_TIMED_OUT):r(Ct.ERROR_WALLET_CONNECTION),f(X)})},[A]),(0,Te.useEffect)(()=>{if(t){let x=setTimeout(p,Ge);return()=>clearTimeout(x)}},[C]);let d=((ue=s())==null?void 0:ue.wallet)||"metamask",b=di[d].name,$=di[d].component,Ie=t?`Successfully connected with ${b}`:o?o.message:`Waiting for ${b}`,V="";if(t){let x=(C==null?void 0:C.linkedAccounts.length)||0;P===x?V="Wallet was already linked.":V="You\u2019re good to go!"}else if(A>=Po&&o)V="Unable to connect wallet";else if(o)V=o.detail;else switch(V="Don\u2019t see your wallet modal? Check your other browser windows.",d){case"wallet_connect":V="Open your mobile wallet app to continue";break;case"coinbase_wallet":Lt()||(V="Open the Coinbase app on your phone to continue.");break;default:V="Don\u2019t see your wallet modal? Check your other browser windows."}return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(k,{backFn:n}),(0,B.jsxs)(jn,{children:[(0,B.jsx)(Zn,{children:(0,B.jsxs)("div",{children:[(0,B.jsx)(Ot,{success:t,fail:!!o}),(0,B.jsx)($,{style:{width:"38px",height:"38px"}})]})}),(0,B.jsxs)($n,{children:[(0,B.jsx)("h3",{children:Ie}),(0,B.jsx)("p",{children:V})]}),(0,B.jsx)(Kn,{onClick:()=>{N(A+1),r(void 0)},visible:!t&&(o==null?void 0:o.retryable)&&A<Po,disabled:!t&&(!(o!=null&&o.retryable)||A>=Po),children:"Retry"})]})]})},jn=dt.default.div`
995
995
  display: flex;
996
996
  flex-direction: column;
997
997
  align-items: center;
@@ -1455,4 +1455,4 @@ Resources:
1455
1455
  align-items: center;
1456
1456
  justify-content: center;
1457
1457
  height: 100%;
1458
- `;var De=require("react/jsx-runtime");function ns(t){return typeof t=="string"&&t.length===25}var ut;function Ei(){if(!ut){let t=T.get(Ve);return Promise.resolve(t||null)}return ut.getAccessToken()}var ki=t=>{if(!ns(t.appId))throw new u("Cannot initialize the Privy provider with an invalid Privy app ID");return ut||(ut=new je({appId:t.appId,apiURL:Oo})),(0,De.jsx)(as,{...t,client:ut})},ss=(t,e)=>{if(e)return{email:!1,sms:!1,wallet:!1,google:!1,twitter:!1,discord:!1,github:!1,[e]:!0};let o=!!(t!=null&&t.emailAuth),r=!!(t!=null&&t.smsAuth);return o&&r&&(console.warn("Enabling both email and SMS passwordless is not currently supported. Disabling SMS."),r=!1),{email:o,sms:r,wallet:!!(t!=null&&t.walletAuth),google:!!(t!=null&&t.googleOAuth),twitter:!!(t!=null&&t.twitterOAuth),discord:!!(t!=null&&t.discordOAuth),github:!!(t!=null&&t.githubOAuth)}},as=t=>{let e=t.client,[o,r]=(0,j.useState)(!1),[i,n]=(0,j.useState)(!1),[s,p]=(0,j.useState)(!1),[m,f]=(0,j.useState)(null),[A,N]=(0,j.useState)(!1),[C,P]=(0,j.useState)({accentColor:"#696ffd",theme:"System",showWalletLoginFirst:!0,allowlistConfig:{errorTitle:null,errorDetail:null,ctaText:null,ctaLink:null},walletAuth:!0,emailAuth:!0,smsAuth:!1,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,githubOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null}),[M,d]=(0,j.useState)(null),[b,Z]=(0,j.useState)(!1),Ie=ss(C,M);(0,j.useEffect)(()=>{async function c(){let a=await e.getAppSettings();P(a),e.connector.initialize(),V();let E=await e.getAuthenticatedUser();p(!!E),f(E),n(!0)}c()},[e]);let V=()=>{let c=new URLSearchParams(window.location.search),a=c.get("privy_oauth_code"),E=c.get("privy_oauth_state"),z=c.get("privy_oauth_provider");a&&E&&z&&(e.startAuthFlow(new $e(z,a,E)),d(z),r(!0))};(0,j.useEffect)(()=>{i&&s&&m===null&&e.getAuthenticatedUser().then(f)},[i,s,m,e]);let ue={ready:i,authenticated:s,user:m,walletConnector:e.connector,linkWallet:()=>{d("wallet"),Z(!0),r(!0)},linkEmail:()=>{d("email"),Z(!0),r(!0)},linkPhone:()=>{d("sms"),Z(!0),r(!0)},linkGoogle:async()=>{await X.initLoginWithOAuth("google")},linkTwitter:async()=>{await X.initLoginWithOAuth("twitter")},linkDiscord:async()=>{await X.initLoginWithOAuth("discord")},linkGithub:async()=>{await X.initLoginWithOAuth("github")},login:()=>{if(i&&s){console.warn("Attempted to log in, but user is already logged in. Use a `link` helper instead.");return}r(!0)},logout:async()=>{await e.logout(),f(null),p(!1),d(null),Z(!1),r(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>{if(!e.connector.initialized)throw new u("Connector is not loaded");return e.connector.getEthereumProvider()},getEthersProvider:()=>{if(!e.connector.initialized)throw new u("Connector is not loaded");return new Ai.Web3Provider(new xe(e.connector.getEthereumProvider()))},getWeb3jsProvider:()=>{if(!e.connector.initialized)throw new u("Connector is not loaded");return new xt(e.connector.getEthereumProvider())},unlinkWallet:async c=>{let a=await e.unlinkWallet(c);return f(a),a},unlinkEmail:async c=>{let a=await e.unlinkEmail(c);return f(a),a},unlinkPhone:async c=>{let a=await e.unlinkPhone(c);return f(a),a},unlinkGoogle:async c=>{let a=await e.unlinkOAuth("google",c);return f(a),a},unlinkTwitter:async c=>{let a=await e.unlinkOAuth("twitter",c);return f(a),a},unlinkDiscord:async c=>{let a=await e.unlinkOAuth("discord",c);return f(a),a},unlinkGithub:async c=>{let a=await e.unlinkOAuth("github",c);return f(a),a},setActiveWallet:c=>{if(!m)return;let a=e.setActiveWallet(c,m);f(a)},forkSession:()=>e.forkSession()},X=(0,j.useMemo)(()=>({isLinking:b,getAuthFlow:()=>e.authFlow,getAuthMeta:()=>{var c;return(c=e.authFlow)==null?void 0:c.meta},closePrivyModal:()=>{var c;i&&s&&m&&((c=t.onSuccess)==null||c.call(t,m,A)),e.authFlow=void 0,d(null),Z(!1),N(!1),r(!1)},handleLoginError:async c=>{var a;e.authFlow=void 0,d(null),Z(!1),N(!1),(a=t.onError)==null||a.call(t,c)},initLoginWithWallet:c=>{if(!e.connector)throw new u("Connector not initialized");c||(c="metamask"),e.connector.walletType=c,e.startAuthFlow(new et(e.connector))},loginWithWallet:async()=>{if(!(e.authFlow instanceof et))throw new u("Must initialize SIWE flow first.");let c,a;b?(c=await e.link(),c&&(T.del(se),c=Xe(c))):{user:c,isNewUser:a}=await e.authenticate(),f(c||m||null),N(a||!1),p(!0)},initLoginWithOAuth:async c=>{e.startAuthFlow(new $e(c));let a=await e.authFlow.getAuthorizationUrl();a&&a.url&&window.location.assign(a.url)},loginWithOAuth:async()=>{if(!(e.authFlow instanceof $e))throw new u("Must initialize OAuth flow before calling loginWithOAuth");let c,a;i&&s?c=await e.link():{user:c,isNewUser:a}=await e.authenticate(),f(c),N(a||!1),p(!0)},initLoginWithEmail:async c=>{let a=new tt(c);e.startAuthFlow(a),await a.sendCodeEmail()},initLoginWithSms:async c=>{let a=new ot(c);e.startAuthFlow(a),await a.sendSmsCode()},resendEmailCode:async()=>{var c;await((c=e.authFlow)==null?void 0:c.sendCodeEmail())},resendSmsCode:async()=>{var c;await((c=e.authFlow)==null?void 0:c.sendSmsCode())},loginWithCode:async c=>{if(e.authFlow instanceof tt)e.authFlow.meta.emailCode=c.trim();else if(e.authFlow instanceof ot)e.authFlow.meta.smsCode=c.trim();else throw new u("Must initialize a passwordless code flow first");let a,E;b?a=await e.link():{user:a,isNewUser:E}=await e.authenticate(),f(a||m||null),N(E||!1),p(!0)}}),[e]);return(0,De.jsxs)(ro.Provider,{value:ue,children:[t.children,(0,De.jsx)(so.Provider,{value:X,children:(0,De.jsx)(mr,{appSettings:C,options:Ie,visible:o,authenticated:s,children:o&&(0,De.jsx)(Li,{})})})]})};0&&(module.exports={AsExternalProvider,PrivyClient,PrivyConnector,PrivyProvider,PrivyProxyProvider,VERSION,getAccessToken,usePrivy});
1458
+ `;var De=require("react/jsx-runtime");function ns(t){return typeof t=="string"&&t.length===25}var ut;function Ei(){if(!ut){let t=T.get(Ve);return Promise.resolve(t||null)}return ut.getAccessToken()}var ki=t=>{if(!ns(t.appId))throw new u("Cannot initialize the Privy provider with an invalid Privy app ID");return ut||(ut=new je({appId:t.appId,apiURL:Oo})),(0,De.jsx)(as,{...t,client:ut})},ss=(t,e)=>{if(e)return{email:!1,sms:!1,wallet:!1,google:!1,twitter:!1,discord:!1,github:!1,[e]:!0};let o=!!(t!=null&&t.emailAuth),r=!!(t!=null&&t.smsAuth);return o&&r&&(console.warn("Enabling both email and SMS passwordless is not currently supported. Disabling SMS."),r=!1),{email:o,sms:r,wallet:!!(t!=null&&t.walletAuth),google:!!(t!=null&&t.googleOAuth),twitter:!!(t!=null&&t.twitterOAuth),discord:!!(t!=null&&t.discordOAuth),github:!!(t!=null&&t.githubOAuth)}},as=t=>{let e=t.client,[o,r]=(0,Q.useState)(!1),[i,n]=(0,Q.useState)(!1),[s,p]=(0,Q.useState)(!1),[m,f]=(0,Q.useState)(null),[A,N]=(0,Q.useState)(!1),[C,P]=(0,Q.useState)({accentColor:"#696ffd",theme:"System",showWalletLoginFirst:!0,allowlistConfig:{errorTitle:null,errorDetail:null,ctaText:null,ctaLink:null},walletAuth:!0,emailAuth:!0,smsAuth:!1,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,githubOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null}),[M,d]=(0,Q.useState)(null),[b,$]=(0,Q.useState)(!1),Ie=ss(C,M);(0,Q.useEffect)(()=>{async function c(){let a=await e.getAppSettings();P(a),e.connector.initialize(),V();let E=await e.getAuthenticatedUser();p(!!E),f(E),n(!0)}c()},[e]);let V=()=>{let c=new URLSearchParams(window.location.search),a=c.get("privy_oauth_code"),E=c.get("privy_oauth_state"),z=c.get("privy_oauth_provider");a&&E&&z&&(e.startAuthFlow(new $e(z,a,E)),d(z),r(!0))};(0,Q.useEffect)(()=>{i&&s&&m===null&&e.getAuthenticatedUser().then(f)},[i,s,m,e]);let ue={ready:i,authenticated:s,user:m,walletConnector:e.connector,linkWallet:()=>{d("wallet"),$(!0),r(!0)},linkEmail:()=>{d("email"),$(!0),r(!0)},linkPhone:()=>{d("sms"),$(!0),r(!0)},linkGoogle:async()=>{await X.initLoginWithOAuth("google")},linkTwitter:async()=>{await X.initLoginWithOAuth("twitter")},linkDiscord:async()=>{await X.initLoginWithOAuth("discord")},linkGithub:async()=>{await X.initLoginWithOAuth("github")},login:()=>{if(i&&s){console.warn("Attempted to log in, but user is already logged in. Use a `link` helper instead.");return}r(!0)},logout:async()=>{await e.logout(),f(null),p(!1),d(null),$(!1),r(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>{if(!e.connector.initialized)throw new u("Connector is not loaded");return e.connector.getEthereumProvider()},getEthersProvider:()=>{if(!e.connector.initialized)throw new u("Connector is not loaded");return new Ai.Web3Provider(new xe(e.connector.getEthereumProvider()))},getWeb3jsProvider:()=>{if(!e.connector.initialized)throw new u("Connector is not loaded");return new xt(e.connector.getEthereumProvider())},unlinkWallet:async c=>{let a=await e.unlinkWallet(c);return f(a),a},unlinkEmail:async c=>{let a=await e.unlinkEmail(c);return f(a),a},unlinkPhone:async c=>{let a=await e.unlinkPhone(c);return f(a),a},unlinkGoogle:async c=>{let a=await e.unlinkOAuth("google",c);return f(a),a},unlinkTwitter:async c=>{let a=await e.unlinkOAuth("twitter",c);return f(a),a},unlinkDiscord:async c=>{let a=await e.unlinkOAuth("discord",c);return f(a),a},unlinkGithub:async c=>{let a=await e.unlinkOAuth("github",c);return f(a),a},setActiveWallet:c=>{if(!m)return;let a=e.setActiveWallet(c,m);f(a)},forkSession:()=>e.forkSession()},X=(()=>({isLinking:b,getAuthFlow:()=>e.authFlow,getAuthMeta:()=>{var c;return(c=e.authFlow)==null?void 0:c.meta},closePrivyModal:()=>{var c;i&&s&&m&&((c=t.onSuccess)==null||c.call(t,m,A)),e.authFlow=void 0,d(null),$(!1),N(!1),r(!1)},handleLoginError:async c=>{var a;e.authFlow=void 0,d(null),$(!1),N(!1),(a=t.onError)==null||a.call(t,c)},initLoginWithWallet:c=>{if(!e.connector)throw new u("Connector not initialized");c||(c="metamask"),e.connector.walletType=c,e.startAuthFlow(new et(e.connector))},loginWithWallet:async()=>{if(!(e.authFlow instanceof et))throw new u("Must initialize SIWE flow first.");let c,a;b?(c=await e.link(),c&&(T.del(se),c=Xe(c))):{user:c,isNewUser:a}=await e.authenticate(),f(c||m||null),N(a||!1),p(!0)},initLoginWithOAuth:async c=>{e.startAuthFlow(new $e(c));let a=await e.authFlow.getAuthorizationUrl();a&&a.url&&window.location.assign(a.url)},loginWithOAuth:async()=>{if(!(e.authFlow instanceof $e))throw new u("Must initialize OAuth flow before calling loginWithOAuth");let c,a;i&&s?c=await e.link():{user:c,isNewUser:a}=await e.authenticate(),f(c),N(a||!1),p(!0)},initLoginWithEmail:async c=>{let a=new tt(c);e.startAuthFlow(a),await a.sendCodeEmail()},initLoginWithSms:async c=>{let a=new ot(c);e.startAuthFlow(a),await a.sendSmsCode()},resendEmailCode:async()=>{var c;await((c=e.authFlow)==null?void 0:c.sendCodeEmail())},resendSmsCode:async()=>{var c;await((c=e.authFlow)==null?void 0:c.sendSmsCode())},loginWithCode:async c=>{if(e.authFlow instanceof tt)e.authFlow.meta.emailCode=c.trim();else if(e.authFlow instanceof ot)e.authFlow.meta.smsCode=c.trim();else throw new u("Must initialize a passwordless code flow first");let a,E;b?a=await e.link():{user:a,isNewUser:E}=await e.authenticate(),f(a||m||null),N(E||!1),p(!0)}}))();return(0,De.jsxs)(ro.Provider,{value:ue,children:[t.children,(0,De.jsx)(so.Provider,{value:X,children:(0,De.jsx)(mr,{appSettings:C,options:Ie,visible:o,authenticated:s,children:o&&(0,De.jsx)(Li,{})})})]})};0&&(module.exports={AsExternalProvider,PrivyClient,PrivyConnector,PrivyProvider,PrivyProxyProvider,VERSION,getAccessToken,usePrivy});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privy-io/react-auth",
3
- "version": "1.13.0-beta.6",
3
+ "version": "1.13.0-beta.7",
4
4
  "description": "React client for the Privy Auth API",
5
5
  "keywords": [
6
6
  "authentication",