@privy-io/react-auth 1.13.0-beta.9 → 1.13.0

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 Li,useState as fe}from"react";import jt from"axios";import Ei 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}]`:""}`}},_e=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 O=class extends z{constructor(o,r){super(o,r);this.type="connector_error"}},S=t=>{if(t instanceof z)return t;if(!Ei.isAxiosError(t))return V(t);if(!t.response)return new _e("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new _e(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 Lo="1.13.0-beta.9";var Ao="https://api.privy.io/v0",Eo=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",Ve="4df5e2316331463a9130964bd6078dfa",ko=1e4,Pe=1400,zt=Lo;var Se="privy:token",rt="privy:refresh_token",it="privy:connectors",_o="walletconnect";var nt=class{constructor(e,o,r){this.appId=e,this.sdkVersion=zt,this.client=o,this.defaults=r}async get(e,o){try{return await jt.get(e,await this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(r){throw S(r)}}async post(e,o,r){try{return await jt.post(e,o,await this.buildConfig(r))}catch(i){throw S(i)}}async delete(e,o){try{return await jt.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 Po from"jose";var Y=class{static parse(e){try{return new Y(e)}catch{return null}}constructor(e){this.value=e,this._decoded=Po.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 Zt=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]}},$t=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 _i(){return typeof window<"u"&&window.localStorage?new $t:new Zt}var U=_i();import{ErrorCode as Pi}from"@ethersproject/logger";var Te=class extends O{constructor(){super("Wallet timeout");this.type="wallet_error"}},se=t=>{if(t instanceof O)return t;if((t==null?void 0:t.code)&&(t==null?void 0:t.reason)){let e=new We(t);return t.code===Pi.ACTION_REJECTED&&(e.details=we.E4001_USER_REJECTED_REQUEST),e}return t!=null&&t.code?new We(t):new O("Unknown connector error",t)},qt=class extends z{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},We=class extends qt{constructor(o){var n,s,p;let r=o;super(r.message,r.code,r.data);let i=Object.values(we).find(m=>m.eipCode===r.code);this.details=i||we.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=we.E32002_CONNECTION_ALREADY_PENDING:this.details=we.E32002_REQUEST_ALREADY_PENDING:(p=r.message)!=null&&p.includes("Already processing")&&r.message.includes("eth_requestAccounts")&&(this.details=we.E32002_WALLET_LOCKED))}},Si={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}},Ti={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}},Wi={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}},we={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...Wi,...Ti},st={...Si,...we};var Ii=12e4,Kt=(t=new Te,e=Ii)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),q=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 O(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),Kt()]).catch(o=>{throw se(o)})}},ye=class extends q{constructor(o){super(o)}},at=class extends q{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};import{getAddress as Ni}from"@ethersproject/address";import{getAddress as Ri}from"@ethersproject/address";import{Web3Provider as Mi}from"@ethersproject/providers";var ae=class{constructor(e,o,r){this.createSiweMessage=(e,o,r,i,n,s,p)=>`${r} wants you to sign in with your Ethereum account:
1
+ import{useEffect as Li,useState as fe}from"react";import jt from"axios";import Ei 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}]`:""}`}},_e=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 O=class extends z{constructor(o,r){super(o,r);this.type="connector_error"}},S=t=>{if(t instanceof z)return t;if(!Ei.isAxiosError(t))return V(t);if(!t.response)return new _e("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new _e(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 Lo="1.13.0";var Ao="https://api.privy.io/v0",Eo=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",Ve="4df5e2316331463a9130964bd6078dfa",ko=1e4,Pe=1400,zt=Lo;var Se="privy:token",rt="privy:refresh_token",it="privy:connectors",_o="walletconnect";var nt=class{constructor(e,o,r){this.appId=e,this.sdkVersion=zt,this.client=o,this.defaults=r}async get(e,o){try{return await jt.get(e,await this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(r){throw S(r)}}async post(e,o,r){try{return await jt.post(e,o,await this.buildConfig(r))}catch(i){throw S(i)}}async delete(e,o){try{return await jt.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 Po from"jose";var Y=class{static parse(e){try{return new Y(e)}catch{return null}}constructor(e){this.value=e,this._decoded=Po.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 Zt=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]}},$t=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 _i(){return typeof window<"u"&&window.localStorage?new $t:new Zt}var U=_i();import{ErrorCode as Pi}from"@ethersproject/logger";var Te=class extends O{constructor(){super("Wallet timeout");this.type="wallet_error"}},se=t=>{if(t instanceof O)return t;if((t==null?void 0:t.code)&&(t==null?void 0:t.reason)){let e=new We(t);return t.code===Pi.ACTION_REJECTED&&(e.details=we.E4001_USER_REJECTED_REQUEST),e}return t!=null&&t.code?new We(t):new O("Unknown connector error",t)},qt=class extends z{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},We=class extends qt{constructor(o){var n,s,p;let r=o;super(r.message,r.code,r.data);let i=Object.values(we).find(m=>m.eipCode===r.code);this.details=i||we.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=we.E32002_CONNECTION_ALREADY_PENDING:this.details=we.E32002_REQUEST_ALREADY_PENDING:(p=r.message)!=null&&p.includes("Already processing")&&r.message.includes("eth_requestAccounts")&&(this.details=we.E32002_WALLET_LOCKED))}},Si={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}},Ti={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}},Wi={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}},we={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...Wi,...Ti},st={...Si,...we};var Ii=12e4,Kt=(t=new Te,e=Ii)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),q=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 O(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),Kt()]).catch(o=>{throw se(o)})}},ye=class extends q{constructor(o){super(o)}},at=class extends q{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};import{getAddress as Ni}from"@ethersproject/address";import{getAddress as Ri}from"@ethersproject/address";import{Web3Provider as Mi}from"@ethersproject/providers";var ae=class{constructor(e,o,r){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.provider=o,this.walletType=e,this.address=r,this.chain=null,this.connected=!1}async fetchAddress(){if(!this.address){let e=await this.provider.request({method:"eth_accounts"});Array.isArray(e)&&e.length>0&&(this.address=Ri(e[0]))}return this.address}async fetchChainId(){if(!this.chain){let e=await this.provider.request({method:"eth_chainId"}),o=Number(e);this.chain=String(o)}return this.chain}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.fetchAddress(),r=await this.fetchChainId();return{address:o,chainId:r,chainType:"ethereum",walletType:e}}async sign(e){return new Mi(new ye(this.provider)).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)}};import{isMobile as Oi}from"react-device-detect";var lt=class extends ae{constructor(e,o){super("metamask",e,o)}async connect(e){var o;return this.provider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async r=>{r.isMetaMask&&this.provider.setProvider(r)}),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return await this.fetchAddress()!==null}async promptConnection(){try{let e="";Oi||await this.provider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]});let o=await this.provider.request({method:"eth_requestAccounts"});if(o.length>0&&(e=Ni(o[0])),!e||e==="")throw new O("Unable to retrieve address");this.connected=!0,this.address=e}catch(e){throw se(e)}}};import{getAddress as Ui}from"@ethersproject/address";import Fi from"@coinbase/wallet-sdk";var Di=()=>{let t=`https://mainnet.infura.io/v3/${Ve}`,e=1;return new Fi({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(t,e)},dt=class extends ae{constructor(e,o){super("coinbase_wallet",e,o)}async connect(e){return this.provider.setProvider(Di()),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return await this.fetchAddress()!==null}async promptConnection(){try{let e="",o=await this.provider.request({method:"eth_requestAccounts"});if(o.length>0&&(e=Ui(o[0])),!e||e==="")throw new O("Unable to retrieve address");this.connected=!0}catch(e){throw se(e)}}};import So from"@walletconnect/web3-provider";var ct=class extends ae{constructor(e,o){super("wallet_connect",e,o)}async connect(e){let o=new So({infuraId:Ve});return this.provider.setProvider(o),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return this.provider.walletProvider.connected}async promptConnection(){try{let e="",o=new So({infuraId:Ve});this.provider.setProvider(o);let r=await Promise.race([o.enable(),Kt()]);if(r.length>0&&(e=r[0]),!e||e==="")throw new O("Unable to retrieve address");this.connected=!0}catch(e){throw se(e)}}};var Jt=()=>{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},pt=()=>{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},To=()=>{var e;let t=U.get(it);return t?(e=t.find(o=>o.active))==null?void 0:e.address:null},Yt=(t,e)=>{switch(t){case"metamask":return new lt(new q,e);case"coinbase_wallet":return new dt(new q,e);case"wallet_connect":return new ct(new q,e)}},Be=class{constructor(){this.getEthereumProvider=()=>{var e;return((e=this.activeWalletConnector)==null?void 0:e.provider)||new q};this.walletConnectors=[],this.initialized=!1}initialize(){this.initialized||(this.load(),this.activeWalletConnector&&this.activeWalletConnector.connect({showPrompt:!1}).then(()=>this.initialized=!0),this.initialized=!0)}initializeLinkedWallets(e){e.linkedAccounts.forEach(()=>{})}load(){(U.get(it)||[]).forEach(o=>{let r=Yt(o.walletType,o.address);this.addWalletConnector(r),o.active&&this.setActiveWallet(o.address)})}save(){let e=this.walletConnectors.map(o=>{var r;return{address:o.address,walletType:o.walletType,active:o.address===((r=this.activeWalletConnector)==null?void 0:r.address)}});U.put(it,e)}destroy(){this.walletConnectors=[],this.initialized=!1,this.activeWalletConnector=void 0,U.del(_o)}addWalletConnector(e){this.walletConnectors.find(r=>r.address===e.address&&r.walletType===e.walletType)||this.walletConnectors.push(e)}removeWallet(e){var r;if(this.walletConnectors=this.walletConnectors.filter(i=>i.address!==e),e===((r=this.activeWalletConnector)==null?void 0:r.address))if(this.walletConnectors.length>0){let i=this.walletConnectors[this.walletConnectors.length-1];this.setActiveWallet(i.address)}else this.activeWalletConnector=void 0;this.save()}async activeWalletSign(e){return this.activeWalletConnector?await this.activeWalletConnector.connect({showPrompt:!1})?this.activeWalletConnector.sign(e):null:(console.error("Cannot sign, no wallet is active. Is a wallet connected?"),null)}setActiveWallet(e){let o=this.walletConnectors.find(r=>r.address===e);return o?(this.activeWalletConnector=o,this.save(),!0):!1}};function le(t){return new Date(t*1e3)}function Gi(t){return t.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:le(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:le(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:le(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:le(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:le(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:le(e.verified_at)};case"github_oauth":return{subject:e.subject,username:e.username,name:e.name,email:e.email,type:e.type,verifiedAt:le(e.verified_at)};default:throw new c("Unrecognized account type")}})}function Ce(t,e){return t.sort((o,r)=>r.verifiedAt.getTime()-o.verifiedAt.getTime()),t.find(o=>o.type===e)}function He(t){let e=To();if(!e)return t.wallet&&console.warn("[Privy] User has linked wallets but no active wallet"),t;let o=t.linkedAccounts.find(i=>i.type==="wallet"&&i.address===e),r=Object.assign({},t);return r.wallet=o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},r}function Q(t){if(!t)return null;let e=Gi(t.linked_accounts),o=Ce(e,"wallet"),r=Ce(e,"email"),i=Ce(e,"phone"),n=Ce(e,"google_oauth"),s=Ce(e,"twitter_oauth"),p=Ce(e,"discord_oauth"),m=Ce(e,"github_oauth"),u={id:t.id,createdAt:le(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 He(u)}var Wo=()=>"/api/v1/sessions",Io=()=>"/api/v1/sessions/logout",Ro=()=>"/api/v1/sessions/fork",Mo=()=>"/api/v1/siwe/init",No=()=>"/api/v1/siwe/authenticate",Oo=()=>"/api/v1/siwe/link",Uo=()=>"/api/v1/passwordless/init",Fo=()=>"/api/v1/passwordless/authenticate",Do=()=>"/api/v1/passwordless/link",Go=()=>"/api/v1/passwordless_sms/init",Vo=()=>"/api/v1/passwordless_sms/authenticate",Bo=()=>"/api/v1/passwordless_sms/link",Ho=()=>"/api/v1/oauth/init",zo=()=>"/api/v1/oauth/authenticate",jo=()=>"/api/v1/oauth/link",Zo=()=>"/api/v1/siwe/unlink",$o=()=>"/api/v1/passwordless/unlink",qo=()=>"/api/v1/passwordless_sms/unlink",Ko=()=>"/api/v1/oauth/unlink";var Vi=30,ut=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=U.get(Se);return typeof e=="string"?new Y(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=U.get(rt);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(Vi)}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(Wo(),{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 _e&&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(Io(),{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(Ro(),{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)}storeToken(e){typeof e=="string"?U.put(Se,e):U.del(Se)}storeRefreshToken(e){typeof e=="string"?U.put(rt,e):U.del(rt)}};var Qt,ze=class{constructor(e){let o=e.apiURL||Ao,r=e.timeout||ko;this.appId=e.appId,this.connectors=new Be,Qt||(Qt=new ut),this.session=Qt,this.api=new nt(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.connectors.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post($o(),{address:e});return Q(o.data)}catch(o){throw V(o)}}async unlinkPhone(e){try{let o=await this.api.post(qo(),{phoneNumber:e});return Q(o.data)}catch(o){throw V(o)}}async unlinkWallet(e){try{let o=await this.api.post(Zo(),{address:e});return Q(o.data)}catch(o){throw V(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(Ko(),{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(n=>n.type==="wallet"?n.address:null).includes(e))throw new c("Cannot set an unlinked address as active.");if(!this.connectors.setActiveWallet(e))throw new c("Error setting the active wallet.");return He(o)}async forkSession(){return await this.session.forkSession()}};import{Web3Provider as ea}from"@ethersproject/providers";import{createContext as Bi,useContext as Hi}from"react";var f=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var Xt=Bi({ready:!1,authenticated:!1,user:null,walletConnectors: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}),R=()=>Hi(Xt);var je=class{constructor(e,o){this.meta={walletType:o},this.connectors=e,this.walletConnector=Yt(o,null)}async authenticate(){if(!this.api)throw new c("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(No(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),{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");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Oo(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),r.data}catch(e){throw S(e)}}async promptConnectAndSign(e){let o=await this.walletConnector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(Mo(),{address:r}),s=this.walletConnector.prepareMessage(i,r,n.data.nonce),p=await this.walletConnector.sign(s);return{message:s,signature:p}}};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=Fo(),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=Do();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=Uo();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw S(o)}}};var $e=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=Vo(),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=Bo();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=Go();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=zo(),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=jo();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=Ho();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 qs from"react-dom";import vo from"styled-components";import{createContext as ji,useContext as Zi,useEffect as Yo,useState as Qo}from"react";import{jsx as zi}from"react/jsx-runtime";function Jo(t){return zi("link",{rel:"prefetch",href:t.src})}import{jsx as $i,jsxs as qi}from"react/jsx-runtime";var Xo=ji({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}),er=t=>{let e=t.appSettings,o=t.authenticated,r=t.visible,[i,n]=Qo("LANDING"),[s,p]=Qo("LANDING");Yo(()=>{o||n("LANDING")},[o]),Yo(()=>{r||(p("LANDING"),n("LANDING"))},[r]);let m={ready:!!(e!=null&&e.id),app:e,options:t.options,currentScreen:i,lastScreen:s,navigate:u=>{p(i),n(u)},navigateBack:()=>{n(s)}};return qi(Xo.Provider,{value:m,children:[e&&e.logoUrl&&$i(Jo,{src:e.logoUrl}),t.children]})},g=()=>Zi(Xo);import{useEffect as Hn,useState as zn}from"react";import Ye from"styled-components";import Yi from"styled-components";import{jsx as tr}from"react/jsx-runtime";var or=({style:t,...e})=>tr("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:tr("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});import{jsx as rr}from"react/jsx-runtime";var ir=({style:t,...e})=>rr("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:rr("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});import{createContext as Ki,useContext as Ji}from"react";var eo=Ki({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}),_=()=>Ji(eo);import{jsx as ee,jsxs as on}from"react/jsx-runtime";var Qi=()=>ee("div",{}),Xi=({backFn:t})=>ee("div",{children:ee(ir,{onClick:t})}),en=t=>ee("div",{children:ee("div",{children:ee(or,{onClick:t.onClose})})});var L=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=_();return on(tn,{children:[t?ee(Xi,{backFn:t}):ee(Qi,{}),ee(en,{onClose:e||o})]})},tn=Yi.div`
12
+ - https://privy.io`;this.provider=o,this.walletType=e,this.address=r,this.chain=null,this.connected=!1}async fetchAddress(){if(!this.address){let e=await this.provider.request({method:"eth_accounts"});Array.isArray(e)&&e.length>0&&(this.address=Ri(e[0]))}return this.address}async fetchChainId(){if(!this.chain){let e=await this.provider.request({method:"eth_chainId"}),o=Number(e);this.chain=String(o)}return this.chain}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.fetchAddress(),r=await this.fetchChainId();return{address:o,chainId:r,chainType:"ethereum",walletType:e}}async sign(e){return new Mi(new ye(this.provider)).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)}};import{isMobile as Oi}from"react-device-detect";var lt=class extends ae{constructor(e,o){super("metamask",e,o)}async connect(e){var o;return this.provider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async r=>{r.isMetaMask&&this.provider.setProvider(r)}),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return await this.fetchAddress()!==null}async promptConnection(){try{let e="";Oi||await this.provider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]});let o=await this.provider.request({method:"eth_requestAccounts"});if(o.length>0&&(e=Ni(o[0])),!e||e==="")throw new O("Unable to retrieve address");this.connected=!0,this.address=e}catch(e){throw se(e)}}};import{getAddress as Ui}from"@ethersproject/address";import Fi from"@coinbase/wallet-sdk";var Di=()=>{let t=`https://mainnet.infura.io/v3/${Ve}`,e=1;return new Fi({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(t,e)},dt=class extends ae{constructor(e,o){super("coinbase_wallet",e,o)}async connect(e){return this.provider.setProvider(Di()),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return await this.fetchAddress()!==null}async promptConnection(){try{let e="",o=await this.provider.request({method:"eth_requestAccounts"});if(o.length>0&&(e=Ui(o[0])),!e||e==="")throw new O("Unable to retrieve address");this.connected=!0}catch(e){throw se(e)}}};import So from"@walletconnect/web3-provider";var ct=class extends ae{constructor(e,o){super("wallet_connect",e,o)}async connect(e){let o=new So({infuraId:Ve});return this.provider.setProvider(o),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return this.provider.walletProvider.connected}async promptConnection(){try{let e="",o=new So({infuraId:Ve});this.provider.setProvider(o);let r=await Promise.race([o.enable(),Kt()]);if(r.length>0&&(e=r[0]),!e||e==="")throw new O("Unable to retrieve address");this.connected=!0}catch(e){throw se(e)}}};var Jt=()=>{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},pt=()=>{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},To=()=>{var e;let t=U.get(it);return t?(e=t.find(o=>o.active))==null?void 0:e.address:null},Yt=(t,e)=>{switch(t){case"metamask":return new lt(new q,e);case"coinbase_wallet":return new dt(new q,e);case"wallet_connect":return new ct(new q,e)}},Be=class{constructor(){this.getEthereumProvider=()=>{var e;return((e=this.activeWalletConnector)==null?void 0:e.provider)||new q};this.walletConnectors=[],this.initialized=!1}initialize(){this.initialized||(this.load(),this.activeWalletConnector&&this.activeWalletConnector.connect({showPrompt:!1}).then(()=>this.initialized=!0),this.initialized=!0)}initializeLinkedWallets(e){e.linkedAccounts.forEach(()=>{})}load(){(U.get(it)||[]).forEach(o=>{let r=Yt(o.walletType,o.address);this.addWalletConnector(r),o.active&&this.setActiveWallet(o.address)})}save(){let e=this.walletConnectors.map(o=>{var r;return{address:o.address,walletType:o.walletType,active:o.address===((r=this.activeWalletConnector)==null?void 0:r.address)}});U.put(it,e)}destroy(){this.walletConnectors=[],this.initialized=!1,this.activeWalletConnector=void 0,U.del(_o)}addWalletConnector(e){this.walletConnectors.find(r=>r.address===e.address&&r.walletType===e.walletType)||this.walletConnectors.push(e)}removeWallet(e){var r;if(this.walletConnectors=this.walletConnectors.filter(i=>i.address!==e),e===((r=this.activeWalletConnector)==null?void 0:r.address))if(this.walletConnectors.length>0){let i=this.walletConnectors[this.walletConnectors.length-1];this.setActiveWallet(i.address)}else this.activeWalletConnector=void 0;this.save()}async activeWalletSign(e){return this.activeWalletConnector?await this.activeWalletConnector.connect({showPrompt:!1})?this.activeWalletConnector.sign(e):null:(console.error("Cannot sign, no wallet is active. Is a wallet connected?"),null)}setActiveWallet(e){let o=this.walletConnectors.find(r=>r.address===e);return o?(this.activeWalletConnector=o,this.save(),!0):!1}};function le(t){return new Date(t*1e3)}function Gi(t){return t.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:le(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:le(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:le(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:le(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:le(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:le(e.verified_at)};case"github_oauth":return{subject:e.subject,username:e.username,name:e.name,email:e.email,type:e.type,verifiedAt:le(e.verified_at)};default:throw new c("Unrecognized account type")}})}function Ce(t,e){return t.sort((o,r)=>r.verifiedAt.getTime()-o.verifiedAt.getTime()),t.find(o=>o.type===e)}function He(t){let e=To();if(!e)return t.wallet&&console.warn("[Privy] User has linked wallets but no active wallet"),t;let o=t.linkedAccounts.find(i=>i.type==="wallet"&&i.address===e),r=Object.assign({},t);return r.wallet=o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},r}function Q(t){if(!t)return null;let e=Gi(t.linked_accounts),o=Ce(e,"wallet"),r=Ce(e,"email"),i=Ce(e,"phone"),n=Ce(e,"google_oauth"),s=Ce(e,"twitter_oauth"),p=Ce(e,"discord_oauth"),m=Ce(e,"github_oauth"),u={id:t.id,createdAt:le(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 He(u)}var Wo=()=>"/api/v1/sessions",Io=()=>"/api/v1/sessions/logout",Ro=()=>"/api/v1/sessions/fork",Mo=()=>"/api/v1/siwe/init",No=()=>"/api/v1/siwe/authenticate",Oo=()=>"/api/v1/siwe/link",Uo=()=>"/api/v1/passwordless/init",Fo=()=>"/api/v1/passwordless/authenticate",Do=()=>"/api/v1/passwordless/link",Go=()=>"/api/v1/passwordless_sms/init",Vo=()=>"/api/v1/passwordless_sms/authenticate",Bo=()=>"/api/v1/passwordless_sms/link",Ho=()=>"/api/v1/oauth/init",zo=()=>"/api/v1/oauth/authenticate",jo=()=>"/api/v1/oauth/link",Zo=()=>"/api/v1/siwe/unlink",$o=()=>"/api/v1/passwordless/unlink",qo=()=>"/api/v1/passwordless_sms/unlink",Ko=()=>"/api/v1/oauth/unlink";var Vi=30,ut=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=U.get(Se);return typeof e=="string"?new Y(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=U.get(rt);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(Vi)}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(Wo(),{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 _e&&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(Io(),{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(Ro(),{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)}storeToken(e){typeof e=="string"?U.put(Se,e):U.del(Se)}storeRefreshToken(e){typeof e=="string"?U.put(rt,e):U.del(rt)}};var Qt,ze=class{constructor(e){let o=e.apiURL||Ao,r=e.timeout||ko;this.appId=e.appId,this.connectors=new Be,Qt||(Qt=new ut),this.session=Qt,this.api=new nt(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.connectors.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post($o(),{address:e});return Q(o.data)}catch(o){throw V(o)}}async unlinkPhone(e){try{let o=await this.api.post(qo(),{phoneNumber:e});return Q(o.data)}catch(o){throw V(o)}}async unlinkWallet(e){try{let o=await this.api.post(Zo(),{address:e});return Q(o.data)}catch(o){throw V(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(Ko(),{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,errorCtaText:e.data.allowlist_config.cta_text,errorCtaLink: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(n=>n.type==="wallet"?n.address:null).includes(e))throw new c("Cannot set an unlinked address as active.");if(!this.connectors.setActiveWallet(e))throw new c("Error setting the active wallet.");return He(o)}async forkSession(){return await this.session.forkSession()}};import{Web3Provider as ea}from"@ethersproject/providers";import{createContext as Bi,useContext as Hi}from"react";var f=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var Xt=Bi({ready:!1,authenticated:!1,user:null,walletConnectors: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}),R=()=>Hi(Xt);var je=class{constructor(e,o){this.meta={walletType:o},this.connectors=e,this.walletConnector=Yt(o,null)}async authenticate(){if(!this.api)throw new c("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(No(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),{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");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Oo(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),r.data}catch(e){throw S(e)}}async promptConnectAndSign(e){let o=await this.walletConnector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(Mo(),{address:r}),s=this.walletConnector.prepareMessage(i,r,n.data.nonce),p=await this.walletConnector.sign(s);return{message:s,signature:p}}};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=Fo(),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=Do();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=Uo();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw S(o)}}};var $e=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=Vo(),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=Bo();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=Go();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=zo(),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=jo();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=Ho();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 qs from"react-dom";import vo from"styled-components";import{createContext as ji,useContext as Zi,useEffect as Yo,useState as Qo}from"react";import{jsx as zi}from"react/jsx-runtime";function Jo(t){return zi("link",{rel:"prefetch",href:t.src})}import{jsx as $i,jsxs as qi}from"react/jsx-runtime";var Xo=ji({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}),er=t=>{let e=t.appSettings,o=t.authenticated,r=t.visible,[i,n]=Qo("LANDING"),[s,p]=Qo("LANDING");Yo(()=>{o||n("LANDING")},[o]),Yo(()=>{r||(p("LANDING"),n("LANDING"))},[r]);let m={ready:!!(e!=null&&e.id),app:e,options:t.options,currentScreen:i,lastScreen:s,navigate:u=>{p(i),n(u)},navigateBack:()=>{n(s)}};return qi(Xo.Provider,{value:m,children:[e&&e.logoUrl&&$i(Jo,{src:e.logoUrl}),t.children]})},g=()=>Zi(Xo);import{useEffect as Hn,useState as zn}from"react";import Ye from"styled-components";import Yi from"styled-components";import{jsx as tr}from"react/jsx-runtime";var or=({style:t,...e})=>tr("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:tr("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});import{jsx as rr}from"react/jsx-runtime";var ir=({style:t,...e})=>rr("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:rr("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});import{createContext as Ki,useContext as Ji}from"react";var eo=Ki({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}),_=()=>Ji(eo);import{jsx as ee,jsxs as on}from"react/jsx-runtime";var Qi=()=>ee("div",{}),Xi=({backFn:t})=>ee("div",{children:ee(ir,{onClick:t})}),en=t=>ee("div",{children:ee("div",{children:ee(or,{onClick:t.onClose})})});var L=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=_();return on(tn,{children:[t?ee(Xi,{backFn:t}):ee(Qi,{}),ee(en,{onClose:e||o})]})},tn=Yi.div`
13
13
  height: 30px;
14
14
  display: flex;
15
15
  align-items: center;
@@ -744,7 +744,7 @@ Resources:
744
744
  border-color: var(--primary-color);
745
745
  border-bottom-color: var(--primary-color);
746
746
  }
747
- `;import{jsx as Gr}from"react/jsx-runtime";var Vr=({style:t,...e})=>Gr("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:Gr("path",{"fill-rule":"evenodd",d:"M12 1.5a5.25 5.25 0 00-5.25 5.25v3a3 3 0 00-3 3v6.75a3 3 0 003 3h10.5a3 3 0 003-3v-6.75a3 3 0 00-3-3v-3c0-2.9-2.35-5.25-5.25-5.25zm3.75 8.25v-3a3.75 3.75 0 10-7.5 0v3h7.5z","clip-rule":"evenodd"})});import{Fragment as co,jsx as J,jsxs as Wt}from"react/jsx-runtime";var Hr=()=>{let{navigate:t,app:e}=g(),o=(e==null?void 0:e.allowlistConfig.errorTitle)||"You don't have access to this app",r=(e==null?void 0:e.allowlistConfig.errorDetail)||"Try with a different account?";return Wt(co,{children:[J(L,{}),Wt(is,{children:[J(ss,{children:Wt("div",{children:[J(Dr,{}),J(Vr,{style:{width:"38px",height:"38px",strokeWidth:"1",stroke:"var(--primary-color)",fill:"var(--primary-color)"}})]})}),Wt(ns,{children:[typeof o=="string"?J("h3",{children:o}):J(co,{children:o}),typeof r=="string"?J("p",{children:r}):J(co,{children:r})]}),e!=null&&e.allowlistConfig.ctaLink?J(Br,{onClick:()=>{typeof window<"u"&&(e==null?void 0:e.allowlistConfig.ctaLink)&&(window.location.href=e.allowlistConfig.ctaLink)},visible:!0,disabled:!1,children:e.allowlistConfig.ctaText}):J(Br,{onClick:()=>{t("LANDING")},visible:!0,disabled:!1,children:"Okay"})]})]})},is=It.div`
747
+ `;import{jsx as Gr}from"react/jsx-runtime";var Vr=({style:t,...e})=>Gr("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:Gr("path",{"fill-rule":"evenodd",d:"M12 1.5a5.25 5.25 0 00-5.25 5.25v3a3 3 0 00-3 3v6.75a3 3 0 003 3h10.5a3 3 0 003-3v-6.75a3 3 0 00-3-3v-3c0-2.9-2.35-5.25-5.25-5.25zm3.75 8.25v-3a3.75 3.75 0 10-7.5 0v3h7.5z","clip-rule":"evenodd"})});import{Fragment as co,jsx as J,jsxs as Wt}from"react/jsx-runtime";var Hr=()=>{let{navigate:t,app:e}=g(),o=(e==null?void 0:e.allowlistConfig.errorTitle)||"You don't have access to this app",r=(e==null?void 0:e.allowlistConfig.errorDetail)||"Have you been invited?",i=(e==null?void 0:e.allowlistConfig.errorCtaText)||"Try another account";return Wt(co,{children:[J(L,{}),Wt(is,{children:[J(ss,{children:Wt("div",{children:[J(Dr,{}),J(Vr,{style:{width:"38px",height:"38px",strokeWidth:"1",stroke:"var(--primary-color)",fill:"var(--primary-color)"}})]})}),Wt(ns,{children:[typeof o=="string"?J("h3",{children:o}):J(co,{children:o}),typeof r=="string"?J("p",{children:r}):J(co,{children:r})]}),e!=null&&e.allowlistConfig.errorCtaLink?J(Br,{as:"a",href:e.allowlistConfig.errorCtaLink,visible:!0,children:i}):J(Br,{onClick:()=>{t("LANDING")},visible:!0,children:i})]})]})},is=It.div`
748
748
  display: flex;
749
749
  flex-direction: column;
750
750
  align-items: center;
@@ -788,8 +788,12 @@ Resources:
788
788
  background-color: var(--primary-color-bg-1);
789
789
  border-radius: var(--border-radius-sm);
790
790
  min-width: 144px;
791
- opacity: ${t=>t.visible?"1":"0"};
792
- transition: opacity 200ms;
791
+ opacity: ${t=>t.visible?"0.95":"0"};
792
+ transition: opacity 200ms, background-color 200ms;
793
+
794
+ :hover {
795
+ background-color: var(--primary-color-bg-2);
796
+ }
793
797
  }
794
798
  `;import{useState as vs}from"react";import j from"styled-components";import as from"qrcode";import ls from"styled-components";import{Fragment as Fe,jsx as M,jsxs as Zr}from"react/jsx-runtime";var G=7,po=(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},ds=t=>{let e=as.create(t,{errorCorrectionLevel:"high"}).modules,o=Lr(Array.from(e.data),e.size);return o=po(o,0,0,G,G),o=po(o,o.length-G,0,G,G),o=po(o,0,o.length-G,G,G),o},cs=({x:t,y:e,cellSize:o,bgColor:r,fgColor:i})=>M(Fe,{children:[0,1,2].map(n=>M("circle",{r:o*(G-n*2)/2,cx:t+o*G/2,cy:e+o*G/2,fill:n%2!==0?r:i},`finder-${t}-${e}-${n}`))}),ps=({cellSize:t,matrixSize:e,bgColor:o,fgColor:r})=>{let i=[[0,0],[(e-G)*t,0],[0,(e-G)*t]];return M(Fe,{children:i.map(([n,s])=>M(cs,{x:n,y:s,cellSize:t,bgColor:o,fgColor:r}))})},us=({matrix:t,cellSize:e,color:o})=>M(Fe,{children:t.map((r,i)=>r.map((n,s)=>n?M("circle",{r:e/2.5,cx:i*e+e/2,cy:s*e+e/2,fill:o},`circle-${i}-${s}`):M(Fe,{})))}),zr=(t,e)=>t-t%e,hs=({outputSize:t,cellSize:e,element:o,size:r,padding:i,bgColor:n})=>{if(!o)return M(Fe,{});let s=r||40,p=i||4,m=o,u=t/2-s/2-p;return Zr(Fe,{children:[M("rect",{x:zr(u,e),y:zr(u,e),width:s+p*2+(u%e?e+.5:.5),height:s+p*2+(u%e?e+.5:.5),fill:n}),M(m,{x:t/2-s/2,y:t/2-s/2,height:s,width:s})]})},ms=t=>{var i;let e=t.outputSize,o=ds(t.url),r=e/o.length;return Zr("svg",{height:t.outputSize,width:t.outputSize,viewBox:`0 0 ${t.outputSize} ${t.outputSize}`,style:{height:"100%",width:"100%"},children:[M(us,{matrix:o,cellSize:r,color:t.fgColor}),M(ps,{cellSize:r,matrixSize:o.length,fgColor:t.fgColor,bgColor:t.bgColor}),M(hs,{outputSize:t.outputSize,cellSize:r,element:(i=t.logo)==null?void 0:i.element,bgColor:t.bgColor})]})},fs=ls.div`
795
799
  display: flex;
@@ -1281,6 +1285,7 @@ Resources:
1281
1285
  /* Same as primary color, but can be used with rgba */
1282
1286
  --primary-color-rgb: ${t=>`${Lt(t.accentColor).r}, ${Lt(t.accentColor).g}, ${Lt(t.accentColor).b}`};
1283
1287
  --primary-color-bg-1: rgba(var(--primary-color-rgb), 0.15);
1288
+ --primary-color-bg-2: rgba(var(--primary-color-rgb), 0.2);
1284
1289
 
1285
1290
  --success-light: #4bd089;
1286
1291
  --success-dark: #22874f;
@@ -1455,4 +1460,4 @@ Resources:
1455
1460
  align-items: center;
1456
1461
  justify-content: center;
1457
1462
  height: 100%;
1458
- `;import{jsx as Gt,jsxs as sa}from"react/jsx-runtime";function ta(t){return typeof t=="string"&&t.length===25}var ot;function oa(){if(!ot){let t=U.get(Se);return Promise.resolve(t||null)}return ot.getAccessToken()}var ra=t=>{if(!ta(t.appId))throw new c("Cannot initialize the Privy provider with an invalid Privy app ID");return ot||(ot=new ze({appId:t.appId,apiURL:Eo})),Gt(na,{...t,client:ot})},ia=(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)}},na=t=>{let e=t.client,[o,r]=fe(!1),[i,n]=fe(!1),[s,p]=fe(!1),[m,u]=fe(null),[P,A]=fe(!1),[k,y]=fe({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}),[d,b]=fe(null),[C,H]=fe(!1),ge=ia(k,d);Li(()=>{async function l(){let a=await e.getAppSettings();y(a),e.connectors.initialize(),I();let x=await e.getAuthenticatedUser();p(!!x),u(x),n(!0)}l()},[e]);let I=()=>{let l=new URLSearchParams(window.location.search),a=l.get("privy_oauth_code"),x=l.get("privy_oauth_state"),N=l.get("privy_oauth_provider");a&&x&&N&&(e.startAuthFlow(new Ie(N,a,x)),b(N),r(!0))};Li(()=>{i&&s&&m===null&&e.getAuthenticatedUser().then(u)},[i,s,m,e]);let F={ready:i,authenticated:s,user:m,walletConnectors:e.connectors,linkWallet:()=>{b("wallet"),H(!0),r(!0)},linkEmail:()=>{b("email"),H(!0),r(!0)},linkPhone:()=>{b("sms"),H(!0),r(!0)},linkGoogle:async()=>{await Z.initLoginWithOAuth("google")},linkTwitter:async()=>{await Z.initLoginWithOAuth("twitter")},linkDiscord:async()=>{await Z.initLoginWithOAuth("discord")},linkGithub:async()=>{await Z.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(),u(null),p(!1),b(null),H(!1),r(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>{if(!e.connectors.initialized)throw new c("Connector is not loaded");return e.connectors.getEthereumProvider()},getEthersProvider:()=>{if(!e.connectors.initialized)throw new c("Connector is not loaded");return new ea(new ye(e.connectors.getEthereumProvider()))},getWeb3jsProvider:()=>{if(!e.connectors.initialized)throw new c("Connector is not loaded");return new at(e.connectors.getEthereumProvider())},unlinkWallet:async l=>{let a=await e.unlinkWallet(l);return u(a),a},unlinkEmail:async l=>{let a=await e.unlinkEmail(l);return u(a),a},unlinkPhone:async l=>{let a=await e.unlinkPhone(l);return u(a),a},unlinkGoogle:async l=>{let a=await e.unlinkOAuth("google",l);return u(a),a},unlinkTwitter:async l=>{let a=await e.unlinkOAuth("twitter",l);return u(a),a},unlinkDiscord:async l=>{let a=await e.unlinkOAuth("discord",l);return u(a),a},unlinkGithub:async l=>{let a=await e.unlinkOAuth("github",l);return u(a),a},setActiveWallet:l=>{if(!m)return;let a=e.setActiveWallet(l,m);u(a)},forkSession:()=>e.forkSession()},Z=(()=>({isLinking:C,getAuthFlow:()=>e.authFlow,getAuthMeta:()=>{var l;return(l=e.authFlow)==null?void 0:l.meta},closePrivyModal:()=>{var l;i&&s&&m&&((l=t.onSuccess)==null||l.call(t,m,P)),e.authFlow=void 0,b(null),H(!1),A(!1),r(!1)},initLoginWithWallet:l=>{if(!e.connectors)throw new c("Connector not initialized");l||(l="metamask"),e.startAuthFlow(new je(e.connectors,l))},loginWithWallet:async()=>{if(!(e.authFlow instanceof je))throw new c("Must initialize SIWE flow first.");let l,a;C?(l=await e.link(),l&&(l=He(l))):{user:l,isNewUser:a}=await e.authenticate(),u(l||m||null),A(a||!1),p(!0)},initLoginWithOAuth:async l=>{e.startAuthFlow(new Ie(l));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 l,a;i&&s?l=await e.link():{user:l,isNewUser:a}=await e.authenticate(),u(l),A(a||!1),p(!0)},initLoginWithEmail:async l=>{let a=new Ze(l);e.startAuthFlow(a),await a.sendCodeEmail()},initLoginWithSms:async l=>{let a=new $e(l);e.startAuthFlow(a),await a.sendSmsCode()},resendEmailCode:async()=>{var l;await((l=e.authFlow)==null?void 0:l.sendCodeEmail())},resendSmsCode:async()=>{var l;await((l=e.authFlow)==null?void 0:l.sendSmsCode())},loginWithCode:async l=>{if(e.authFlow instanceof Ze)e.authFlow.meta.emailCode=l.trim();else if(e.authFlow instanceof $e)e.authFlow.meta.smsCode=l.trim();else throw new c("Must initialize a passwordless code flow first");let a,x;C?a=await e.link():{user:a,isNewUser:x}=await e.authenticate(),u(a||m||null),A(x||!1),p(!0)}}))();return sa(Xt.Provider,{value:F,children:[t.children,Gt(eo.Provider,{value:Z,children:Gt(er,{appSettings:k,options:ge,visible:o,authenticated:s,children:o&&Gt(xi,{})})})]})};export{ye as AsExternalProvider,Be as ConnectorManager,ze as PrivyClient,ra as PrivyProvider,q as PrivyProxyProvider,zt as VERSION,oa as getAccessToken,R as usePrivy};
1463
+ `;import{jsx as Gt,jsxs as sa}from"react/jsx-runtime";function ta(t){return typeof t=="string"&&t.length===25}var ot;function oa(){if(!ot){let t=U.get(Se);return Promise.resolve(t||null)}return ot.getAccessToken()}var ra=t=>{if(!ta(t.appId))throw new c("Cannot initialize the Privy provider with an invalid Privy app ID");return ot||(ot=new ze({appId:t.appId,apiURL:Eo})),Gt(na,{...t,client:ot})},ia=(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)}},na=t=>{let e=t.client,[o,r]=fe(!1),[i,n]=fe(!1),[s,p]=fe(!1),[m,u]=fe(null),[P,A]=fe(!1),[k,y]=fe({accentColor:"#696ffd",theme:"System",showWalletLoginFirst:!0,allowlistConfig:{errorTitle:null,errorDetail:null,errorCtaText:null,errorCtaLink:null},walletAuth:!0,emailAuth:!0,smsAuth:!1,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,githubOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null}),[d,b]=fe(null),[C,H]=fe(!1),ge=ia(k,d);Li(()=>{async function l(){let a=await e.getAppSettings();y(a),e.connectors.initialize(),I();let x=await e.getAuthenticatedUser();p(!!x),u(x),n(!0)}l()},[e]);let I=()=>{let l=new URLSearchParams(window.location.search),a=l.get("privy_oauth_code"),x=l.get("privy_oauth_state"),N=l.get("privy_oauth_provider");a&&x&&N&&(e.startAuthFlow(new Ie(N,a,x)),b(N),r(!0))};Li(()=>{i&&s&&m===null&&e.getAuthenticatedUser().then(u)},[i,s,m,e]);let F={ready:i,authenticated:s,user:m,walletConnectors:e.connectors,linkWallet:()=>{b("wallet"),H(!0),r(!0)},linkEmail:()=>{b("email"),H(!0),r(!0)},linkPhone:()=>{b("sms"),H(!0),r(!0)},linkGoogle:async()=>{await Z.initLoginWithOAuth("google")},linkTwitter:async()=>{await Z.initLoginWithOAuth("twitter")},linkDiscord:async()=>{await Z.initLoginWithOAuth("discord")},linkGithub:async()=>{await Z.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(),u(null),p(!1),b(null),H(!1),r(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>{if(!e.connectors.initialized)throw new c("Connector is not loaded");return e.connectors.getEthereumProvider()},getEthersProvider:()=>{if(!e.connectors.initialized)throw new c("Connector is not loaded");return new ea(new ye(e.connectors.getEthereumProvider()))},getWeb3jsProvider:()=>{if(!e.connectors.initialized)throw new c("Connector is not loaded");return new at(e.connectors.getEthereumProvider())},unlinkWallet:async l=>{let a=await e.unlinkWallet(l);return u(a),a},unlinkEmail:async l=>{let a=await e.unlinkEmail(l);return u(a),a},unlinkPhone:async l=>{let a=await e.unlinkPhone(l);return u(a),a},unlinkGoogle:async l=>{let a=await e.unlinkOAuth("google",l);return u(a),a},unlinkTwitter:async l=>{let a=await e.unlinkOAuth("twitter",l);return u(a),a},unlinkDiscord:async l=>{let a=await e.unlinkOAuth("discord",l);return u(a),a},unlinkGithub:async l=>{let a=await e.unlinkOAuth("github",l);return u(a),a},setActiveWallet:l=>{if(!m)return;let a=e.setActiveWallet(l,m);u(a)},forkSession:()=>e.forkSession()},Z=(()=>({isLinking:C,getAuthFlow:()=>e.authFlow,getAuthMeta:()=>{var l;return(l=e.authFlow)==null?void 0:l.meta},closePrivyModal:()=>{var l;i&&s&&m&&((l=t.onSuccess)==null||l.call(t,m,P)),e.authFlow=void 0,b(null),H(!1),A(!1),r(!1)},initLoginWithWallet:l=>{if(!e.connectors)throw new c("Connector not initialized");l||(l="metamask"),e.startAuthFlow(new je(e.connectors,l))},loginWithWallet:async()=>{if(!(e.authFlow instanceof je))throw new c("Must initialize SIWE flow first.");let l,a;C?(l=await e.link(),l&&(l=He(l))):{user:l,isNewUser:a}=await e.authenticate(),u(l||m||null),A(a||!1),p(!0)},initLoginWithOAuth:async l=>{e.startAuthFlow(new Ie(l));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 l,a;i&&s?l=await e.link():{user:l,isNewUser:a}=await e.authenticate(),u(l),A(a||!1),p(!0)},initLoginWithEmail:async l=>{let a=new Ze(l);e.startAuthFlow(a),await a.sendCodeEmail()},initLoginWithSms:async l=>{let a=new $e(l);e.startAuthFlow(a),await a.sendSmsCode()},resendEmailCode:async()=>{var l;await((l=e.authFlow)==null?void 0:l.sendCodeEmail())},resendSmsCode:async()=>{var l;await((l=e.authFlow)==null?void 0:l.sendSmsCode())},loginWithCode:async l=>{if(e.authFlow instanceof Ze)e.authFlow.meta.emailCode=l.trim();else if(e.authFlow instanceof $e)e.authFlow.meta.smsCode=l.trim();else throw new c("Must initialize a passwordless code flow first");let a,x;C?a=await e.link():{user:a,isNewUser:x}=await e.authenticate(),u(a||m||null),A(x||!1),p(!0)}}))();return sa(Xt.Provider,{value:F,children:[t.children,Gt(eo.Provider,{value:Z,children:Gt(er,{appSettings:k,options:ge,visible:o,authenticated:s,children:o&&Gt(xi,{})})})]})};export{ye as AsExternalProvider,Be as ConnectorManager,ze as PrivyClient,ra as PrivyProvider,q as PrivyProxyProvider,zt as VERSION,oa as getAccessToken,R as usePrivy};
package/dist/index.d.ts CHANGED
@@ -177,8 +177,8 @@ interface AppSettings {
177
177
  interface AllowlistConfig {
178
178
  errorTitle: string | null;
179
179
  errorDetail: string | null;
180
- ctaText: string | null;
181
- ctaLink: string | null;
180
+ errorCtaText: string | null;
181
+ errorCtaLink: string | null;
182
182
  }
183
183
 
184
184
  declare function getAccessToken(): Promise<string | null>;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Mi=Object.create;var mt=Object.defineProperty;var Ni=Object.getOwnPropertyDescriptor;var Oi=Object.getOwnPropertyNames;var Ui=Object.getPrototypeOf,Fi=Object.prototype.hasOwnProperty;var Di=(t,e)=>{for(var o in e)mt(t,o,{get:e[o],enumerable:!0})},Oo=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Oi(e))!Fi.call(t,i)&&i!==o&&mt(t,i,{get:()=>e[i],enumerable:!(r=Ni(e,i))||r.enumerable});return t};var v=(t,e,o)=>(o=t!=null?Mi(Ui(t)):{},Oo(e||!t||!t.__esModule?mt(o,"default",{value:t,enumerable:!0}):o,t)),Gi=t=>Oo(mt({},"__esModule",{value:!0}),t);var hs={};Di(hs,{AsExternalProvider:()=>be,ConnectorManager:()=>je,PrivyClient:()=>Ze,PrivyProvider:()=>Ii,PrivyProxyProvider:()=>te,VERSION:()=>ft,getAccessToken:()=>Wi,usePrivy:()=>N});module.exports=Gi(hs);var Q=require("react");var yt=v(require("axios"));var Uo=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}]`:""}`}},Ge=class extends ee{constructor(o,r,i,n){super(i,n);this.type=o;this.status=r}},p=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"}},M=t=>{if(t instanceof ee)return t;if(!Uo.default.isAxiosError(t))return q(t);if(!t.response)return new Ge("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new Ge(e||"ApiError",t.response.status,o||r,t)},q=t=>t instanceof ee?t:t instanceof Error?new p(t.message,t):new p(`Internal error: ${t}`);var Fo="1.13.0-beta.9";var Do="https://api.privy.io/v0",Go=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",et="4df5e2316331463a9130964bd6078dfa",Vo=1e4,Ve=1400,ft=Fo;var Be="privy:token",gt="privy:refresh_token",wt="privy:connectors",Bo="walletconnect";var Ct=class{constructor(e,o,r){this.appId=e,this.sdkVersion=ft,this.client=o,this.defaults=r}async get(e,o){try{return await yt.default.get(e,await this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(r){throw M(r)}}async post(e,o,r){try{return await yt.default.post(e,o,await this.buildConfig(r))}catch(i){throw M(i)}}async delete(e,o){try{return await yt.default.delete(e,await this.buildConfig(o))}catch(r){throw M(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 Ho=v(require("jose")),ue=class{static parse(e){try{return new ue(e)}catch{return null}}constructor(e){this.value=e,this._decoded=Ho.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 Ce=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 Xt=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]}},eo=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 Bi(){return typeof window<"u"&&window.localStorage?new eo:new Xt}var j=Bi();var zo=require("@ethersproject/logger");var He=class extends z{constructor(){super("Wallet timeout");this.type="wallet_error"}},ve=t=>{if(t instanceof z)return t;if((t==null?void 0:t.code)&&(t==null?void 0:t.reason)){let e=new ze(t);return t.code===zo.ErrorCode.ACTION_REJECTED&&(e.details=Ie.E4001_USER_REJECTED_REQUEST),e}return t!=null&&t.code?new ze(t):new z("Unknown connector error",t)},to=class extends ee{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},ze=class extends to{constructor(o){var n,a,u;let r=o;super(r.message,r.code,r.data);let i=Object.values(Ie).find(f=>f.eipCode===r.code);this.details=i||Ie.UNKNOWN_ERROR,r.code===-32002&&((n=r.message)!=null&&n.includes("already pending for origin")?(a=r.message)!=null&&a.includes("wallet_requestPermissions")?this.details=Ie.E32002_CONNECTION_ALREADY_PENDING:this.details=Ie.E32002_REQUEST_ALREADY_PENDING:(u=r.message)!=null&&u.includes("Already processing")&&r.message.includes("eth_requestAccounts")&&(this.details=Ie.E32002_WALLET_LOCKED))}},Hi={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}},zi={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}},ji={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}},Ie={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...ji,...zi},vt={...Hi,...Ie};var Zi=12e4,oo=(t=new He,e=Zi)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),te=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),oo()]).catch(o=>{throw ve(o)})}},be=class extends te{constructor(o){super(o)}},bt=class extends te{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var $o=require("@ethersproject/address");var jo=require("@ethersproject/address");var Zo=require("@ethersproject/providers"),xe=class{constructor(e,o,r){this.createSiweMessage=(e,o,r,i,n,a,u)=>`${r} wants you to sign in with your Ethereum account:
1
+ "use strict";var Mi=Object.create;var mt=Object.defineProperty;var Ni=Object.getOwnPropertyDescriptor;var Oi=Object.getOwnPropertyNames;var Ui=Object.getPrototypeOf,Fi=Object.prototype.hasOwnProperty;var Di=(t,e)=>{for(var o in e)mt(t,o,{get:e[o],enumerable:!0})},Oo=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Oi(e))!Fi.call(t,i)&&i!==o&&mt(t,i,{get:()=>e[i],enumerable:!(r=Ni(e,i))||r.enumerable});return t};var v=(t,e,o)=>(o=t!=null?Mi(Ui(t)):{},Oo(e||!t||!t.__esModule?mt(o,"default",{value:t,enumerable:!0}):o,t)),Gi=t=>Oo(mt({},"__esModule",{value:!0}),t);var hs={};Di(hs,{AsExternalProvider:()=>be,ConnectorManager:()=>je,PrivyClient:()=>Ze,PrivyProvider:()=>Ii,PrivyProxyProvider:()=>te,VERSION:()=>ft,getAccessToken:()=>Wi,usePrivy:()=>N});module.exports=Gi(hs);var Q=require("react");var yt=v(require("axios"));var Uo=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}]`:""}`}},Ge=class extends ee{constructor(o,r,i,n){super(i,n);this.type=o;this.status=r}},p=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"}},M=t=>{if(t instanceof ee)return t;if(!Uo.default.isAxiosError(t))return q(t);if(!t.response)return new Ge("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new Ge(e||"ApiError",t.response.status,o||r,t)},q=t=>t instanceof ee?t:t instanceof Error?new p(t.message,t):new p(`Internal error: ${t}`);var Fo="1.13.0";var Do="https://api.privy.io/v0",Go=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",et="4df5e2316331463a9130964bd6078dfa",Vo=1e4,Ve=1400,ft=Fo;var Be="privy:token",gt="privy:refresh_token",wt="privy:connectors",Bo="walletconnect";var Ct=class{constructor(e,o,r){this.appId=e,this.sdkVersion=ft,this.client=o,this.defaults=r}async get(e,o){try{return await yt.default.get(e,await this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(r){throw M(r)}}async post(e,o,r){try{return await yt.default.post(e,o,await this.buildConfig(r))}catch(i){throw M(i)}}async delete(e,o){try{return await yt.default.delete(e,await this.buildConfig(o))}catch(r){throw M(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 Ho=v(require("jose")),ue=class{static parse(e){try{return new ue(e)}catch{return null}}constructor(e){this.value=e,this._decoded=Ho.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 Ce=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 Xt=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]}},eo=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 Bi(){return typeof window<"u"&&window.localStorage?new eo:new Xt}var j=Bi();var zo=require("@ethersproject/logger");var He=class extends z{constructor(){super("Wallet timeout");this.type="wallet_error"}},ve=t=>{if(t instanceof z)return t;if((t==null?void 0:t.code)&&(t==null?void 0:t.reason)){let e=new ze(t);return t.code===zo.ErrorCode.ACTION_REJECTED&&(e.details=Ie.E4001_USER_REJECTED_REQUEST),e}return t!=null&&t.code?new ze(t):new z("Unknown connector error",t)},to=class extends ee{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},ze=class extends to{constructor(o){var n,a,u;let r=o;super(r.message,r.code,r.data);let i=Object.values(Ie).find(f=>f.eipCode===r.code);this.details=i||Ie.UNKNOWN_ERROR,r.code===-32002&&((n=r.message)!=null&&n.includes("already pending for origin")?(a=r.message)!=null&&a.includes("wallet_requestPermissions")?this.details=Ie.E32002_CONNECTION_ALREADY_PENDING:this.details=Ie.E32002_REQUEST_ALREADY_PENDING:(u=r.message)!=null&&u.includes("Already processing")&&r.message.includes("eth_requestAccounts")&&(this.details=Ie.E32002_WALLET_LOCKED))}},Hi={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}},zi={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}},ji={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}},Ie={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...ji,...zi},vt={...Hi,...Ie};var Zi=12e4,oo=(t=new He,e=Zi)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),te=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),oo()]).catch(o=>{throw ve(o)})}},be=class extends te{constructor(o){super(o)}},bt=class extends te{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var $o=require("@ethersproject/address");var jo=require("@ethersproject/address");var Zo=require("@ethersproject/providers"),xe=class{constructor(e,o,r){this.createSiweMessage=(e,o,r,i,n,a,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: ${a}
10
10
  Issued At: ${n}
11
11
  Resources:
12
- - https://privy.io`;this.provider=o,this.walletType=e,this.address=r,this.chain=null,this.connected=!1}async fetchAddress(){if(!this.address){let e=await this.provider.request({method:"eth_accounts"});Array.isArray(e)&&e.length>0&&(this.address=(0,jo.getAddress)(e[0]))}return this.address}async fetchChainId(){if(!this.chain){let e=await this.provider.request({method:"eth_chainId"}),o=Number(e);this.chain=String(o)}return this.chain}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.fetchAddress(),r=await this.fetchChainId();return{address:o,chainId:r,chainType:"ethereum",walletType:e}}async sign(e){return new Zo.Web3Provider(new be(this.provider)).getSigner().signMessage(e)}prepareMessage(e,o,r){let i=window.location.host,n=window.location.origin,a="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,a)}};var qo=require("react-device-detect"),xt=class extends xe{constructor(e,o){super("metamask",e,o)}async connect(e){var o;return this.provider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async r=>{r.isMetaMask&&this.provider.setProvider(r)}),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return await this.fetchAddress()!==null}async promptConnection(){try{let e="";qo.isMobile||await this.provider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]});let o=await this.provider.request({method:"eth_requestAccounts"});if(o.length>0&&(e=(0,$o.getAddress)(o[0])),!e||e==="")throw new z("Unable to retrieve address");this.connected=!0,this.address=e}catch(e){throw ve(e)}}};var Ko=require("@ethersproject/address");var Jo=v(require("@coinbase/wallet-sdk"));var $i=()=>{let t=`https://mainnet.infura.io/v3/${et}`,e=1;return new Jo.default({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(t,e)},Lt=class extends xe{constructor(e,o){super("coinbase_wallet",e,o)}async connect(e){return this.provider.setProvider($i()),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return await this.fetchAddress()!==null}async promptConnection(){try{let e="",o=await this.provider.request({method:"eth_requestAccounts"});if(o.length>0&&(e=(0,Ko.getAddress)(o[0])),!e||e==="")throw new z("Unable to retrieve address");this.connected=!0}catch(e){throw ve(e)}}};var ro=v(require("@walletconnect/web3-provider"));var At=class extends xe{constructor(e,o){super("wallet_connect",e,o)}async connect(e){let o=new ro.default({infuraId:et});return this.provider.setProvider(o),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return this.provider.walletProvider.connected}async promptConnection(){try{let e="",o=new ro.default({infuraId:et});this.provider.setProvider(o);let r=await Promise.race([o.enable(),oo()]);if(r.length>0&&(e=r[0]),!e||e==="")throw new z("Unable to retrieve address");this.connected=!0}catch(e){throw ve(e)}}};var io=()=>{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},Et=()=>{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},Yo=()=>{var e;let t=j.get(wt);return t?(e=t.find(o=>o.active))==null?void 0:e.address:null},no=(t,e)=>{switch(t){case"metamask":return new xt(new te,e);case"coinbase_wallet":return new Lt(new te,e);case"wallet_connect":return new At(new te,e)}},je=class{constructor(){this.getEthereumProvider=()=>{var e;return((e=this.activeWalletConnector)==null?void 0:e.provider)||new te};this.walletConnectors=[],this.initialized=!1}initialize(){this.initialized||(this.load(),this.activeWalletConnector&&this.activeWalletConnector.connect({showPrompt:!1}).then(()=>this.initialized=!0),this.initialized=!0)}initializeLinkedWallets(e){e.linkedAccounts.forEach(()=>{})}load(){(j.get(wt)||[]).forEach(o=>{let r=no(o.walletType,o.address);this.addWalletConnector(r),o.active&&this.setActiveWallet(o.address)})}save(){let e=this.walletConnectors.map(o=>{var r;return{address:o.address,walletType:o.walletType,active:o.address===((r=this.activeWalletConnector)==null?void 0:r.address)}});j.put(wt,e)}destroy(){this.walletConnectors=[],this.initialized=!1,this.activeWalletConnector=void 0,j.del(Bo)}addWalletConnector(e){this.walletConnectors.find(r=>r.address===e.address&&r.walletType===e.walletType)||this.walletConnectors.push(e)}removeWallet(e){var r;if(this.walletConnectors=this.walletConnectors.filter(i=>i.address!==e),e===((r=this.activeWalletConnector)==null?void 0:r.address))if(this.walletConnectors.length>0){let i=this.walletConnectors[this.walletConnectors.length-1];this.setActiveWallet(i.address)}else this.activeWalletConnector=void 0;this.save()}async activeWalletSign(e){return this.activeWalletConnector?await this.activeWalletConnector.connect({showPrompt:!1})?this.activeWalletConnector.sign(e):null:(console.error("Cannot sign, no wallet is active. Is a wallet connected?"),null)}setActiveWallet(e){let o=this.walletConnectors.find(r=>r.address===e);return o?(this.activeWalletConnector=o,this.save(),!0):!1}};function Le(t){return new Date(t*1e3)}function qi(t){return t.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:Le(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:Le(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:Le(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:Le(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:Le(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:Le(e.verified_at)};case"github_oauth":return{subject:e.subject,username:e.username,name:e.name,email:e.email,type:e.type,verifiedAt:Le(e.verified_at)};default:throw new p("Unrecognized account type")}})}function Re(t,e){return t.sort((o,r)=>r.verifiedAt.getTime()-o.verifiedAt.getTime()),t.find(o=>o.type===e)}function tt(t){let e=Yo();if(!e)return t.wallet&&console.warn("[Privy] User has linked wallets but no active wallet"),t;let o=t.linkedAccounts.find(i=>i.type==="wallet"&&i.address===e),r=Object.assign({},t);return r.wallet=o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},r}function he(t){if(!t)return null;let e=qi(t.linked_accounts),o=Re(e,"wallet"),r=Re(e,"email"),i=Re(e,"phone"),n=Re(e,"google_oauth"),a=Re(e,"twitter_oauth"),u=Re(e,"discord_oauth"),f=Re(e,"github_oauth"),m={id:t.id,createdAt:Le(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:a&&{subject:a.subject,username:a.username,name:a.name},discord:u&&{subject:u.subject,username:u.username,email:u.email},github:f&&{subject:f.subject,username:f.username,name:f.name,email:f.email}};return tt(m)}var Qo=()=>"/api/v1/sessions",Xo=()=>"/api/v1/sessions/logout",er=()=>"/api/v1/sessions/fork",tr=()=>"/api/v1/siwe/init",or=()=>"/api/v1/siwe/authenticate",rr=()=>"/api/v1/siwe/link",ir=()=>"/api/v1/passwordless/init",nr=()=>"/api/v1/passwordless/authenticate",sr=()=>"/api/v1/passwordless/link",ar=()=>"/api/v1/passwordless_sms/init",lr=()=>"/api/v1/passwordless_sms/authenticate",dr=()=>"/api/v1/passwordless_sms/link",cr=()=>"/api/v1/oauth/init",pr=()=>"/api/v1/oauth/authenticate",ur=()=>"/api/v1/oauth/link",hr=()=>"/api/v1/siwe/unlink",mr=()=>"/api/v1/passwordless/unlink",fr=()=>"/api/v1/passwordless_sms/unlink",gr=()=>"/api/v1/oauth/unlink";var Ki=30,kt=class{constructor(){this.authenticateOnce=new Ce(async e=>this._authenticate(e)),this.linkOnce=new Ce(async e=>this._link(e)),this.refreshOnce=new Ce(this._refresh.bind(this)),this.destroyOnce=new Ce(this._destroy.bind(this)),this.forkSessionOnce=new Ce(this._forkSession.bind(this))}get token(){try{let e=j.get(Be);return typeof e=="string"?new ue(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=j.get(gt);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=ue.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: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 p("Session has no API instance");if(!this.client)throw new p("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(Qo(),{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 Ge&&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(Xo(),{refresh_token:this.refreshToken}))}catch{console.warn("Error destroying session")}this.destroyLocalState()}async _forkSession(){if(!this.api)throw new p("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(er(),{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)}storeToken(e){typeof e=="string"?j.put(Be,e):j.del(Be)}storeRefreshToken(e){typeof e=="string"?j.put(gt,e):j.del(gt)}};var so,Ze=class{constructor(e){let o=e.apiURL||Do,r=e.timeout||Vo;this.appId=e.appId,this.connectors=new je,so||(so=new kt),this.session=so,this.api=new Ct(e.appId,this,{baseURL:o,timeout:r}),this.session.api=this.api,this.session.client=this}authenticate(){if(!this.authFlow)throw new p("No auth flow in progress.");return this.session.authenticate(this.authFlow)}link(){if(!this.authFlow)throw new p("No auth flow in progress.");return this.session.link(this.authFlow)}async logout(){await this.session.destroy(),this.connectors.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post(mr(),{address:e});return he(o.data)}catch(o){throw q(o)}}async unlinkPhone(e){try{let o=await this.api.post(fr(),{phoneNumber:e});return he(o.data)}catch(o){throw q(o)}}async unlinkWallet(e){try{let o=await this.api.post(hr(),{address:e});return he(o.data)}catch(o){throw q(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(gr(),{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=ue.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(n=>n.type==="wallet"?n.address:null).includes(e))throw new p("Cannot set an unlinked address as active.");if(!this.connectors.setActiveWallet(e))throw new p("Error setting the active wallet.");return tt(o)}async forkSession(){return await this.session.forkSession()}};var Ti=require("@ethersproject/providers");var _t=require("react");var w=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var ao=(0,_t.createContext)({ready:!1,authenticated:!1,user:null,walletConnectors: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}),N=()=>(0,_t.useContext)(ao);var ot=class{constructor(e,o){this.meta={walletType:o},this.connectors=e,this.walletConnector=no(o,null)}async authenticate(){if(!this.api)throw new p("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(or(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),{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 M(e)}}async link(){if(!this.api)throw new p("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(rr(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),r.data}catch(e){throw M(e)}}async promptConnectAndSign(e){let o=await this.walletConnector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(tr(),{address:r}),a=this.walletConnector.prepareMessage(i,r,n.data.nonce),u=await this.walletConnector.sign(a);return{message:a,signature:u}}};var rt=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new p("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new p("Email and email code must be set prior to calling authenticate.");try{let e=nr(),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 M(e)}}async link(){if(!this.api)throw new p("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new p("Email and email code must be set prior to calling authenticate.");try{let e=sr();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw M(e)}}async sendCodeEmail(e){if(!this.api)throw new p("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new p("Email must be set when initialzing authentication.");try{let o=ir();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw M(o)}}};var it=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new p("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new p("phone number and sms code must be set prior to calling authenticate.");try{let e=lr(),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 M(e)}}async link(){if(!this.api)throw new p("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new p("phone number and sms code must be set prior to calling authenticate.");try{let e=dr();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw M(e)}}async sendSmsCode(e){if(!this.api)throw new p("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new p("phone nNumber must be set when initialzing authentication.");try{let o=ar();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw M(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 p("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new p("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new p("User denied confirmation during OAuth flow");try{let e=pr(),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 M(e)}}async link(){if(!this.api)throw new p("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new p("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new p("User denied confirmation during OAuth flow");try{let e=ur();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw M(e)}}async getAuthorizationUrl(){if(!this.api)throw new p("Auth flow has no API instance");if(!this.meta.provider)throw new p("Provider must be set when initialzing OAuth authentication.");try{let e=cr();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw M(e)}}};var uc=require("wicg-inert"),_i=v(require("react-dom")),Kt=v(require("styled-components"));var le=require("react");var yr=require("react/jsx-runtime");function wr(t){return(0,yr.jsx)("link",{rel:"prefetch",href:t.src})}var Pt=require("react/jsx-runtime"),Cr=(0,le.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}),vr=t=>{let e=t.appSettings,o=t.authenticated,r=t.visible,[i,n]=(0,le.useState)("LANDING"),[a,u]=(0,le.useState)("LANDING");(0,le.useEffect)(()=>{o||n("LANDING")},[o]),(0,le.useEffect)(()=>{r||(u("LANDING"),n("LANDING"))},[r]);let f={ready:!!(e!=null&&e.id),app:e,options:t.options,currentScreen:i,lastScreen:a,navigate:m=>{u(i),n(m)},navigateBack:()=>{n(a)}};return(0,Pt.jsxs)(Cr.Provider,{value:f,children:[e&&e.logoUrl&&(0,Pt.jsx)(wr,{src:e.logoUrl}),t.children]})},y=()=>(0,le.useContext)(Cr);var zt=require("react"),Ye=v(require("styled-components"));var Lr=v(require("styled-components"));var lo=require("react/jsx-runtime"),br=({style:t,...e})=>(0,lo.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,lo.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});var co=require("react/jsx-runtime"),xr=({style:t,...e})=>(0,co.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,co.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});var St=require("react");var po=(0,St.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}),W=()=>(0,St.useContext)(po);var K=require("react/jsx-runtime"),Ji=()=>(0,K.jsx)("div",{}),Yi=({backFn:t})=>(0,K.jsx)("div",{children:(0,K.jsx)(xr,{onClick:t})}),Qi=t=>(0,K.jsx)("div",{children:(0,K.jsx)("div",{children:(0,K.jsx)(br,{onClick:t.onClose})})});var E=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=W();return(0,K.jsxs)(Xi,{children:[t?(0,K.jsx)(Yi,{backFn:t}):(0,K.jsx)(Ji,{}),(0,K.jsx)(Qi,{onClose:e||o})]})},Xi=Lr.default.div`
12
+ - https://privy.io`;this.provider=o,this.walletType=e,this.address=r,this.chain=null,this.connected=!1}async fetchAddress(){if(!this.address){let e=await this.provider.request({method:"eth_accounts"});Array.isArray(e)&&e.length>0&&(this.address=(0,jo.getAddress)(e[0]))}return this.address}async fetchChainId(){if(!this.chain){let e=await this.provider.request({method:"eth_chainId"}),o=Number(e);this.chain=String(o)}return this.chain}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.fetchAddress(),r=await this.fetchChainId();return{address:o,chainId:r,chainType:"ethereum",walletType:e}}async sign(e){return new Zo.Web3Provider(new be(this.provider)).getSigner().signMessage(e)}prepareMessage(e,o,r){let i=window.location.host,n=window.location.origin,a="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,a)}};var qo=require("react-device-detect"),xt=class extends xe{constructor(e,o){super("metamask",e,o)}async connect(e){var o;return this.provider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async r=>{r.isMetaMask&&this.provider.setProvider(r)}),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return await this.fetchAddress()!==null}async promptConnection(){try{let e="";qo.isMobile||await this.provider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]});let o=await this.provider.request({method:"eth_requestAccounts"});if(o.length>0&&(e=(0,$o.getAddress)(o[0])),!e||e==="")throw new z("Unable to retrieve address");this.connected=!0,this.address=e}catch(e){throw ve(e)}}};var Ko=require("@ethersproject/address");var Jo=v(require("@coinbase/wallet-sdk"));var $i=()=>{let t=`https://mainnet.infura.io/v3/${et}`,e=1;return new Jo.default({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(t,e)},Lt=class extends xe{constructor(e,o){super("coinbase_wallet",e,o)}async connect(e){return this.provider.setProvider($i()),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return await this.fetchAddress()!==null}async promptConnection(){try{let e="",o=await this.provider.request({method:"eth_requestAccounts"});if(o.length>0&&(e=(0,Ko.getAddress)(o[0])),!e||e==="")throw new z("Unable to retrieve address");this.connected=!0}catch(e){throw ve(e)}}};var ro=v(require("@walletconnect/web3-provider"));var At=class extends xe{constructor(e,o){super("wallet_connect",e,o)}async connect(e){let o=new ro.default({infuraId:et});return this.provider.setProvider(o),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return this.provider.walletProvider.connected}async promptConnection(){try{let e="",o=new ro.default({infuraId:et});this.provider.setProvider(o);let r=await Promise.race([o.enable(),oo()]);if(r.length>0&&(e=r[0]),!e||e==="")throw new z("Unable to retrieve address");this.connected=!0}catch(e){throw ve(e)}}};var io=()=>{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},Et=()=>{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},Yo=()=>{var e;let t=j.get(wt);return t?(e=t.find(o=>o.active))==null?void 0:e.address:null},no=(t,e)=>{switch(t){case"metamask":return new xt(new te,e);case"coinbase_wallet":return new Lt(new te,e);case"wallet_connect":return new At(new te,e)}},je=class{constructor(){this.getEthereumProvider=()=>{var e;return((e=this.activeWalletConnector)==null?void 0:e.provider)||new te};this.walletConnectors=[],this.initialized=!1}initialize(){this.initialized||(this.load(),this.activeWalletConnector&&this.activeWalletConnector.connect({showPrompt:!1}).then(()=>this.initialized=!0),this.initialized=!0)}initializeLinkedWallets(e){e.linkedAccounts.forEach(()=>{})}load(){(j.get(wt)||[]).forEach(o=>{let r=no(o.walletType,o.address);this.addWalletConnector(r),o.active&&this.setActiveWallet(o.address)})}save(){let e=this.walletConnectors.map(o=>{var r;return{address:o.address,walletType:o.walletType,active:o.address===((r=this.activeWalletConnector)==null?void 0:r.address)}});j.put(wt,e)}destroy(){this.walletConnectors=[],this.initialized=!1,this.activeWalletConnector=void 0,j.del(Bo)}addWalletConnector(e){this.walletConnectors.find(r=>r.address===e.address&&r.walletType===e.walletType)||this.walletConnectors.push(e)}removeWallet(e){var r;if(this.walletConnectors=this.walletConnectors.filter(i=>i.address!==e),e===((r=this.activeWalletConnector)==null?void 0:r.address))if(this.walletConnectors.length>0){let i=this.walletConnectors[this.walletConnectors.length-1];this.setActiveWallet(i.address)}else this.activeWalletConnector=void 0;this.save()}async activeWalletSign(e){return this.activeWalletConnector?await this.activeWalletConnector.connect({showPrompt:!1})?this.activeWalletConnector.sign(e):null:(console.error("Cannot sign, no wallet is active. Is a wallet connected?"),null)}setActiveWallet(e){let o=this.walletConnectors.find(r=>r.address===e);return o?(this.activeWalletConnector=o,this.save(),!0):!1}};function Le(t){return new Date(t*1e3)}function qi(t){return t.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:Le(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:Le(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:Le(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:Le(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:Le(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:Le(e.verified_at)};case"github_oauth":return{subject:e.subject,username:e.username,name:e.name,email:e.email,type:e.type,verifiedAt:Le(e.verified_at)};default:throw new p("Unrecognized account type")}})}function Re(t,e){return t.sort((o,r)=>r.verifiedAt.getTime()-o.verifiedAt.getTime()),t.find(o=>o.type===e)}function tt(t){let e=Yo();if(!e)return t.wallet&&console.warn("[Privy] User has linked wallets but no active wallet"),t;let o=t.linkedAccounts.find(i=>i.type==="wallet"&&i.address===e),r=Object.assign({},t);return r.wallet=o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},r}function he(t){if(!t)return null;let e=qi(t.linked_accounts),o=Re(e,"wallet"),r=Re(e,"email"),i=Re(e,"phone"),n=Re(e,"google_oauth"),a=Re(e,"twitter_oauth"),u=Re(e,"discord_oauth"),f=Re(e,"github_oauth"),m={id:t.id,createdAt:Le(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:a&&{subject:a.subject,username:a.username,name:a.name},discord:u&&{subject:u.subject,username:u.username,email:u.email},github:f&&{subject:f.subject,username:f.username,name:f.name,email:f.email}};return tt(m)}var Qo=()=>"/api/v1/sessions",Xo=()=>"/api/v1/sessions/logout",er=()=>"/api/v1/sessions/fork",tr=()=>"/api/v1/siwe/init",or=()=>"/api/v1/siwe/authenticate",rr=()=>"/api/v1/siwe/link",ir=()=>"/api/v1/passwordless/init",nr=()=>"/api/v1/passwordless/authenticate",sr=()=>"/api/v1/passwordless/link",ar=()=>"/api/v1/passwordless_sms/init",lr=()=>"/api/v1/passwordless_sms/authenticate",dr=()=>"/api/v1/passwordless_sms/link",cr=()=>"/api/v1/oauth/init",pr=()=>"/api/v1/oauth/authenticate",ur=()=>"/api/v1/oauth/link",hr=()=>"/api/v1/siwe/unlink",mr=()=>"/api/v1/passwordless/unlink",fr=()=>"/api/v1/passwordless_sms/unlink",gr=()=>"/api/v1/oauth/unlink";var Ki=30,kt=class{constructor(){this.authenticateOnce=new Ce(async e=>this._authenticate(e)),this.linkOnce=new Ce(async e=>this._link(e)),this.refreshOnce=new Ce(this._refresh.bind(this)),this.destroyOnce=new Ce(this._destroy.bind(this)),this.forkSessionOnce=new Ce(this._forkSession.bind(this))}get token(){try{let e=j.get(Be);return typeof e=="string"?new ue(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=j.get(gt);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=ue.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: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 p("Session has no API instance");if(!this.client)throw new p("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(Qo(),{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 Ge&&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(Xo(),{refresh_token:this.refreshToken}))}catch{console.warn("Error destroying session")}this.destroyLocalState()}async _forkSession(){if(!this.api)throw new p("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(er(),{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)}storeToken(e){typeof e=="string"?j.put(Be,e):j.del(Be)}storeRefreshToken(e){typeof e=="string"?j.put(gt,e):j.del(gt)}};var so,Ze=class{constructor(e){let o=e.apiURL||Do,r=e.timeout||Vo;this.appId=e.appId,this.connectors=new je,so||(so=new kt),this.session=so,this.api=new Ct(e.appId,this,{baseURL:o,timeout:r}),this.session.api=this.api,this.session.client=this}authenticate(){if(!this.authFlow)throw new p("No auth flow in progress.");return this.session.authenticate(this.authFlow)}link(){if(!this.authFlow)throw new p("No auth flow in progress.");return this.session.link(this.authFlow)}async logout(){await this.session.destroy(),this.connectors.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post(mr(),{address:e});return he(o.data)}catch(o){throw q(o)}}async unlinkPhone(e){try{let o=await this.api.post(fr(),{phoneNumber:e});return he(o.data)}catch(o){throw q(o)}}async unlinkWallet(e){try{let o=await this.api.post(hr(),{address:e});return he(o.data)}catch(o){throw q(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(gr(),{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=ue.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,errorCtaText:e.data.allowlist_config.cta_text,errorCtaLink: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(n=>n.type==="wallet"?n.address:null).includes(e))throw new p("Cannot set an unlinked address as active.");if(!this.connectors.setActiveWallet(e))throw new p("Error setting the active wallet.");return tt(o)}async forkSession(){return await this.session.forkSession()}};var Ti=require("@ethersproject/providers");var _t=require("react");var w=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var ao=(0,_t.createContext)({ready:!1,authenticated:!1,user:null,walletConnectors: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}),N=()=>(0,_t.useContext)(ao);var ot=class{constructor(e,o){this.meta={walletType:o},this.connectors=e,this.walletConnector=no(o,null)}async authenticate(){if(!this.api)throw new p("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(or(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),{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 M(e)}}async link(){if(!this.api)throw new p("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(rr(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),r.data}catch(e){throw M(e)}}async promptConnectAndSign(e){let o=await this.walletConnector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(tr(),{address:r}),a=this.walletConnector.prepareMessage(i,r,n.data.nonce),u=await this.walletConnector.sign(a);return{message:a,signature:u}}};var rt=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new p("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new p("Email and email code must be set prior to calling authenticate.");try{let e=nr(),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 M(e)}}async link(){if(!this.api)throw new p("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new p("Email and email code must be set prior to calling authenticate.");try{let e=sr();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw M(e)}}async sendCodeEmail(e){if(!this.api)throw new p("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new p("Email must be set when initialzing authentication.");try{let o=ir();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw M(o)}}};var it=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new p("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new p("phone number and sms code must be set prior to calling authenticate.");try{let e=lr(),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 M(e)}}async link(){if(!this.api)throw new p("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new p("phone number and sms code must be set prior to calling authenticate.");try{let e=dr();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw M(e)}}async sendSmsCode(e){if(!this.api)throw new p("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new p("phone nNumber must be set when initialzing authentication.");try{let o=ar();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw M(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 p("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new p("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new p("User denied confirmation during OAuth flow");try{let e=pr(),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 M(e)}}async link(){if(!this.api)throw new p("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new p("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new p("User denied confirmation during OAuth flow");try{let e=ur();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw M(e)}}async getAuthorizationUrl(){if(!this.api)throw new p("Auth flow has no API instance");if(!this.meta.provider)throw new p("Provider must be set when initialzing OAuth authentication.");try{let e=cr();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw M(e)}}};var uc=require("wicg-inert"),_i=v(require("react-dom")),Kt=v(require("styled-components"));var le=require("react");var yr=require("react/jsx-runtime");function wr(t){return(0,yr.jsx)("link",{rel:"prefetch",href:t.src})}var Pt=require("react/jsx-runtime"),Cr=(0,le.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}),vr=t=>{let e=t.appSettings,o=t.authenticated,r=t.visible,[i,n]=(0,le.useState)("LANDING"),[a,u]=(0,le.useState)("LANDING");(0,le.useEffect)(()=>{o||n("LANDING")},[o]),(0,le.useEffect)(()=>{r||(u("LANDING"),n("LANDING"))},[r]);let f={ready:!!(e!=null&&e.id),app:e,options:t.options,currentScreen:i,lastScreen:a,navigate:m=>{u(i),n(m)},navigateBack:()=>{n(a)}};return(0,Pt.jsxs)(Cr.Provider,{value:f,children:[e&&e.logoUrl&&(0,Pt.jsx)(wr,{src:e.logoUrl}),t.children]})},y=()=>(0,le.useContext)(Cr);var zt=require("react"),Ye=v(require("styled-components"));var Lr=v(require("styled-components"));var lo=require("react/jsx-runtime"),br=({style:t,...e})=>(0,lo.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,lo.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});var co=require("react/jsx-runtime"),xr=({style:t,...e})=>(0,co.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,co.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});var St=require("react");var po=(0,St.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}),W=()=>(0,St.useContext)(po);var K=require("react/jsx-runtime"),Ji=()=>(0,K.jsx)("div",{}),Yi=({backFn:t})=>(0,K.jsx)("div",{children:(0,K.jsx)(xr,{onClick:t})}),Qi=t=>(0,K.jsx)("div",{children:(0,K.jsx)("div",{children:(0,K.jsx)(br,{onClick:t.onClose})})});var E=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=W();return(0,K.jsxs)(Xi,{children:[t?(0,K.jsx)(Yi,{backFn:t}):(0,K.jsx)(Ji,{}),(0,K.jsx)(Qi,{onClose:e||o})]})},Xi=Lr.default.div`
13
13
  height: 30px;
14
14
  display: flex;
15
15
  align-items: center;
@@ -744,7 +744,7 @@ Resources:
744
744
  border-color: var(--primary-color);
745
745
  border-bottom-color: var(--primary-color);
746
746
  }
747
- `;var ko=require("react/jsx-runtime"),Kr=({style:t,...e})=>(0,ko.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,ko.jsx)("path",{"fill-rule":"evenodd",d:"M12 1.5a5.25 5.25 0 00-5.25 5.25v3a3 3 0 00-3 3v6.75a3 3 0 003 3h10.5a3 3 0 003-3v-6.75a3 3 0 00-3-3v-3c0-2.9-2.35-5.25-5.25-5.25zm3.75 8.25v-3a3.75 3.75 0 10-7.5 0v3h7.5z","clip-rule":"evenodd"})});var I=require("react/jsx-runtime"),Yr=()=>{let{navigate:t,app:e}=y(),o=(e==null?void 0:e.allowlistConfig.errorTitle)||"You don't have access to this app",r=(e==null?void 0:e.allowlistConfig.errorDetail)||"Try with a different account?";return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(E,{}),(0,I.jsxs)(Rn,{children:[(0,I.jsx)(Nn,{children:(0,I.jsxs)("div",{children:[(0,I.jsx)(qr,{}),(0,I.jsx)(Kr,{style:{width:"38px",height:"38px",strokeWidth:"1",stroke:"var(--primary-color)",fill:"var(--primary-color)"}})]})}),(0,I.jsxs)(Mn,{children:[typeof o=="string"?(0,I.jsx)("h3",{children:o}):(0,I.jsx)(I.Fragment,{children:o}),typeof r=="string"?(0,I.jsx)("p",{children:r}):(0,I.jsx)(I.Fragment,{children:r})]}),e!=null&&e.allowlistConfig.ctaLink?(0,I.jsx)(Jr,{onClick:()=>{typeof window<"u"&&(e==null?void 0:e.allowlistConfig.ctaLink)&&(window.location.href=e.allowlistConfig.ctaLink)},visible:!0,disabled:!1,children:e.allowlistConfig.ctaText}):(0,I.jsx)(Jr,{onClick:()=>{t("LANDING")},visible:!0,disabled:!1,children:"Okay"})]})]})},Rn=dt.default.div`
747
+ `;var ko=require("react/jsx-runtime"),Kr=({style:t,...e})=>(0,ko.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,ko.jsx)("path",{"fill-rule":"evenodd",d:"M12 1.5a5.25 5.25 0 00-5.25 5.25v3a3 3 0 00-3 3v6.75a3 3 0 003 3h10.5a3 3 0 003-3v-6.75a3 3 0 00-3-3v-3c0-2.9-2.35-5.25-5.25-5.25zm3.75 8.25v-3a3.75 3.75 0 10-7.5 0v3h7.5z","clip-rule":"evenodd"})});var I=require("react/jsx-runtime"),Yr=()=>{let{navigate:t,app:e}=y(),o=(e==null?void 0:e.allowlistConfig.errorTitle)||"You don't have access to this app",r=(e==null?void 0:e.allowlistConfig.errorDetail)||"Have you been invited?",i=(e==null?void 0:e.allowlistConfig.errorCtaText)||"Try another account";return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(E,{}),(0,I.jsxs)(Rn,{children:[(0,I.jsx)(Nn,{children:(0,I.jsxs)("div",{children:[(0,I.jsx)(qr,{}),(0,I.jsx)(Kr,{style:{width:"38px",height:"38px",strokeWidth:"1",stroke:"var(--primary-color)",fill:"var(--primary-color)"}})]})}),(0,I.jsxs)(Mn,{children:[typeof o=="string"?(0,I.jsx)("h3",{children:o}):(0,I.jsx)(I.Fragment,{children:o}),typeof r=="string"?(0,I.jsx)("p",{children:r}):(0,I.jsx)(I.Fragment,{children:r})]}),e!=null&&e.allowlistConfig.errorCtaLink?(0,I.jsx)(Jr,{as:"a",href:e.allowlistConfig.errorCtaLink,visible:!0,children:i}):(0,I.jsx)(Jr,{onClick:()=>{t("LANDING")},visible:!0,children:i})]})]})},Rn=dt.default.div`
748
748
  display: flex;
749
749
  flex-direction: column;
750
750
  align-items: center;
@@ -788,8 +788,12 @@ Resources:
788
788
  background-color: var(--primary-color-bg-1);
789
789
  border-radius: var(--border-radius-sm);
790
790
  min-width: 144px;
791
- opacity: ${t=>t.visible?"1":"0"};
792
- transition: opacity 200ms;
791
+ opacity: ${t=>t.visible?"0.95":"0"};
792
+ transition: opacity 200ms, background-color 200ms;
793
+
794
+ :hover {
795
+ background-color: var(--primary-color-bg-2);
796
+ }
793
797
  }
794
798
  `;var ci=require("react"),Y=v(require("styled-components"));var Xr=v(require("qrcode")),ei=v(require("styled-components"));var x=require("react/jsx-runtime"),$=7,_o=(t,e,o,r,i)=>{for(let n=e;n<e+r;n++)for(let a=o;a<o+i;a++){let u=t==null?void 0:t[a];u&&u[n]&&(u[n]=0)}return t},On=t=>{let e=Xr.default.create(t,{errorCorrectionLevel:"high"}).modules,o=Or(Array.from(e.data),e.size);return o=_o(o,0,0,$,$),o=_o(o,o.length-$,0,$,$),o=_o(o,0,o.length-$,$,$),o},Un=({x:t,y:e,cellSize:o,bgColor:r,fgColor:i})=>(0,x.jsx)(x.Fragment,{children:[0,1,2].map(n=>(0,x.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}`))}),Fn=({cellSize:t,matrixSize:e,bgColor:o,fgColor:r})=>{let i=[[0,0],[(e-$)*t,0],[0,(e-$)*t]];return(0,x.jsx)(x.Fragment,{children:i.map(([n,a])=>(0,x.jsx)(Un,{x:n,y:a,cellSize:t,bgColor:o,fgColor:r}))})},Dn=({matrix:t,cellSize:e,color:o})=>(0,x.jsx)(x.Fragment,{children:t.map((r,i)=>r.map((n,a)=>n?(0,x.jsx)("circle",{r:e/2.5,cx:i*e+e/2,cy:a*e+e/2,fill:o},`circle-${i}-${a}`):(0,x.jsx)(x.Fragment,{})))}),Qr=(t,e)=>t-t%e,Gn=({outputSize:t,cellSize:e,element:o,size:r,padding:i,bgColor:n})=>{if(!o)return(0,x.jsx)(x.Fragment,{});let a=r||40,u=i||4,f=o,m=t/2-a/2-u;return(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)("rect",{x:Qr(m,e),y:Qr(m,e),width:a+u*2+(m%e?e+.5:.5),height:a+u*2+(m%e?e+.5:.5),fill:n}),(0,x.jsx)(f,{x:t/2-a/2,y:t/2-a/2,height:a,width:a})]})},Vn=t=>{var i;let e=t.outputSize,o=On(t.url),r=e/o.length;return(0,x.jsxs)("svg",{height:t.outputSize,width:t.outputSize,viewBox:`0 0 ${t.outputSize} ${t.outputSize}`,style:{height:"100%",width:"100%"},children:[(0,x.jsx)(Dn,{matrix:o,cellSize:r,color:t.fgColor}),(0,x.jsx)(Fn,{cellSize:r,matrixSize:o.length,fgColor:t.fgColor,bgColor:t.bgColor}),(0,x.jsx)(Gn,{outputSize:t.outputSize,cellSize:r,element:(i=t.logo)==null?void 0:i.element,bgColor:t.bgColor})]})},Bn=ei.default.div`
795
799
  display: flex;
@@ -1281,6 +1285,7 @@ Resources:
1281
1285
  /* Same as primary color, but can be used with rgba */
1282
1286
  --primary-color-rgb: ${t=>`${Gt(t.accentColor).r}, ${Gt(t.accentColor).g}, ${Gt(t.accentColor).b}`};
1283
1287
  --primary-color-bg-1: rgba(var(--primary-color-rgb), 0.15);
1288
+ --primary-color-bg-2: rgba(var(--primary-color-rgb), 0.2);
1284
1289
 
1285
1290
  --success-light: #4bd089;
1286
1291
  --success-dark: #22874f;
@@ -1455,4 +1460,4 @@ Resources:
1455
1460
  align-items: center;
1456
1461
  justify-content: center;
1457
1462
  height: 100%;
1458
- `;var De=require("react/jsx-runtime");function cs(t){return typeof t=="string"&&t.length===25}var ht;function Wi(){if(!ht){let t=j.get(Be);return Promise.resolve(t||null)}return ht.getAccessToken()}var Ii=t=>{if(!cs(t.appId))throw new p("Cannot initialize the Privy provider with an invalid Privy app ID");return ht||(ht=new Ze({appId:t.appId,apiURL:Go})),(0,De.jsx)(us,{...t,client:ht})},ps=(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)}},us=t=>{let e=t.client,[o,r]=(0,Q.useState)(!1),[i,n]=(0,Q.useState)(!1),[a,u]=(0,Q.useState)(!1),[f,m]=(0,Q.useState)(null),[R,_]=(0,Q.useState)(!1),[T,C]=(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}),[c,L]=(0,Q.useState)(null),[b,X]=(0,Q.useState)(!1),We=ps(T,c);(0,Q.useEffect)(()=>{async function d(){let l=await e.getAppSettings();C(l),e.connectors.initialize(),G();let A=await e.getAuthenticatedUser();u(!!A),m(A),n(!0)}d()},[e]);let G=()=>{let d=new URLSearchParams(window.location.search),l=d.get("privy_oauth_code"),A=d.get("privy_oauth_state"),H=d.get("privy_oauth_provider");l&&A&&H&&(e.startAuthFlow(new $e(H,l,A)),L(H),r(!0))};(0,Q.useEffect)(()=>{i&&a&&f===null&&e.getAuthenticatedUser().then(m)},[i,a,f,e]);let Z={ready:i,authenticated:a,user:f,walletConnectors:e.connectors,linkWallet:()=>{L("wallet"),X(!0),r(!0)},linkEmail:()=>{L("email"),X(!0),r(!0)},linkPhone:()=>{L("sms"),X(!0),r(!0)},linkGoogle:async()=>{await se.initLoginWithOAuth("google")},linkTwitter:async()=>{await se.initLoginWithOAuth("twitter")},linkDiscord:async()=>{await se.initLoginWithOAuth("discord")},linkGithub:async()=>{await se.initLoginWithOAuth("github")},login:()=>{if(i&&a){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),X(!1),r(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>{if(!e.connectors.initialized)throw new p("Connector is not loaded");return e.connectors.getEthereumProvider()},getEthersProvider:()=>{if(!e.connectors.initialized)throw new p("Connector is not loaded");return new Ti.Web3Provider(new be(e.connectors.getEthereumProvider()))},getWeb3jsProvider:()=>{if(!e.connectors.initialized)throw new p("Connector is not loaded");return new bt(e.connectors.getEthereumProvider())},unlinkWallet:async d=>{let l=await e.unlinkWallet(d);return m(l),l},unlinkEmail:async d=>{let l=await e.unlinkEmail(d);return m(l),l},unlinkPhone:async d=>{let l=await e.unlinkPhone(d);return m(l),l},unlinkGoogle:async d=>{let l=await e.unlinkOAuth("google",d);return m(l),l},unlinkTwitter:async d=>{let l=await e.unlinkOAuth("twitter",d);return m(l),l},unlinkDiscord:async d=>{let l=await e.unlinkOAuth("discord",d);return m(l),l},unlinkGithub:async d=>{let l=await e.unlinkOAuth("github",d);return m(l),l},setActiveWallet:d=>{if(!f)return;let l=e.setActiveWallet(d,f);m(l)},forkSession:()=>e.forkSession()},se=(()=>({isLinking:b,getAuthFlow:()=>e.authFlow,getAuthMeta:()=>{var d;return(d=e.authFlow)==null?void 0:d.meta},closePrivyModal:()=>{var d;i&&a&&f&&((d=t.onSuccess)==null||d.call(t,f,R)),e.authFlow=void 0,L(null),X(!1),_(!1),r(!1)},initLoginWithWallet:d=>{if(!e.connectors)throw new p("Connector not initialized");d||(d="metamask"),e.startAuthFlow(new ot(e.connectors,d))},loginWithWallet:async()=>{if(!(e.authFlow instanceof ot))throw new p("Must initialize SIWE flow first.");let d,l;b?(d=await e.link(),d&&(d=tt(d))):{user:d,isNewUser:l}=await e.authenticate(),m(d||f||null),_(l||!1),u(!0)},initLoginWithOAuth:async d=>{e.startAuthFlow(new $e(d));let l=await e.authFlow.getAuthorizationUrl();l&&l.url&&window.location.assign(l.url)},loginWithOAuth:async()=>{if(!(e.authFlow instanceof $e))throw new p("Must initialize OAuth flow before calling loginWithOAuth");let d,l;i&&a?d=await e.link():{user:d,isNewUser:l}=await e.authenticate(),m(d),_(l||!1),u(!0)},initLoginWithEmail:async d=>{let l=new rt(d);e.startAuthFlow(l),await l.sendCodeEmail()},initLoginWithSms:async d=>{let l=new it(d);e.startAuthFlow(l),await l.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 rt)e.authFlow.meta.emailCode=d.trim();else if(e.authFlow instanceof it)e.authFlow.meta.smsCode=d.trim();else throw new p("Must initialize a passwordless code flow first");let l,A;b?l=await e.link():{user:l,isNewUser:A}=await e.authenticate(),m(l||f||null),_(A||!1),u(!0)}}))();return(0,De.jsxs)(ao.Provider,{value:Z,children:[t.children,(0,De.jsx)(po.Provider,{value:se,children:(0,De.jsx)(vr,{appSettings:T,options:We,visible:o,authenticated:a,children:o&&(0,De.jsx)(Si,{})})})]})};0&&(module.exports={AsExternalProvider,ConnectorManager,PrivyClient,PrivyProvider,PrivyProxyProvider,VERSION,getAccessToken,usePrivy});
1463
+ `;var De=require("react/jsx-runtime");function cs(t){return typeof t=="string"&&t.length===25}var ht;function Wi(){if(!ht){let t=j.get(Be);return Promise.resolve(t||null)}return ht.getAccessToken()}var Ii=t=>{if(!cs(t.appId))throw new p("Cannot initialize the Privy provider with an invalid Privy app ID");return ht||(ht=new Ze({appId:t.appId,apiURL:Go})),(0,De.jsx)(us,{...t,client:ht})},ps=(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)}},us=t=>{let e=t.client,[o,r]=(0,Q.useState)(!1),[i,n]=(0,Q.useState)(!1),[a,u]=(0,Q.useState)(!1),[f,m]=(0,Q.useState)(null),[R,_]=(0,Q.useState)(!1),[T,C]=(0,Q.useState)({accentColor:"#696ffd",theme:"System",showWalletLoginFirst:!0,allowlistConfig:{errorTitle:null,errorDetail:null,errorCtaText:null,errorCtaLink:null},walletAuth:!0,emailAuth:!0,smsAuth:!1,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,githubOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null}),[c,L]=(0,Q.useState)(null),[b,X]=(0,Q.useState)(!1),We=ps(T,c);(0,Q.useEffect)(()=>{async function d(){let l=await e.getAppSettings();C(l),e.connectors.initialize(),G();let A=await e.getAuthenticatedUser();u(!!A),m(A),n(!0)}d()},[e]);let G=()=>{let d=new URLSearchParams(window.location.search),l=d.get("privy_oauth_code"),A=d.get("privy_oauth_state"),H=d.get("privy_oauth_provider");l&&A&&H&&(e.startAuthFlow(new $e(H,l,A)),L(H),r(!0))};(0,Q.useEffect)(()=>{i&&a&&f===null&&e.getAuthenticatedUser().then(m)},[i,a,f,e]);let Z={ready:i,authenticated:a,user:f,walletConnectors:e.connectors,linkWallet:()=>{L("wallet"),X(!0),r(!0)},linkEmail:()=>{L("email"),X(!0),r(!0)},linkPhone:()=>{L("sms"),X(!0),r(!0)},linkGoogle:async()=>{await se.initLoginWithOAuth("google")},linkTwitter:async()=>{await se.initLoginWithOAuth("twitter")},linkDiscord:async()=>{await se.initLoginWithOAuth("discord")},linkGithub:async()=>{await se.initLoginWithOAuth("github")},login:()=>{if(i&&a){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),X(!1),r(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>{if(!e.connectors.initialized)throw new p("Connector is not loaded");return e.connectors.getEthereumProvider()},getEthersProvider:()=>{if(!e.connectors.initialized)throw new p("Connector is not loaded");return new Ti.Web3Provider(new be(e.connectors.getEthereumProvider()))},getWeb3jsProvider:()=>{if(!e.connectors.initialized)throw new p("Connector is not loaded");return new bt(e.connectors.getEthereumProvider())},unlinkWallet:async d=>{let l=await e.unlinkWallet(d);return m(l),l},unlinkEmail:async d=>{let l=await e.unlinkEmail(d);return m(l),l},unlinkPhone:async d=>{let l=await e.unlinkPhone(d);return m(l),l},unlinkGoogle:async d=>{let l=await e.unlinkOAuth("google",d);return m(l),l},unlinkTwitter:async d=>{let l=await e.unlinkOAuth("twitter",d);return m(l),l},unlinkDiscord:async d=>{let l=await e.unlinkOAuth("discord",d);return m(l),l},unlinkGithub:async d=>{let l=await e.unlinkOAuth("github",d);return m(l),l},setActiveWallet:d=>{if(!f)return;let l=e.setActiveWallet(d,f);m(l)},forkSession:()=>e.forkSession()},se=(()=>({isLinking:b,getAuthFlow:()=>e.authFlow,getAuthMeta:()=>{var d;return(d=e.authFlow)==null?void 0:d.meta},closePrivyModal:()=>{var d;i&&a&&f&&((d=t.onSuccess)==null||d.call(t,f,R)),e.authFlow=void 0,L(null),X(!1),_(!1),r(!1)},initLoginWithWallet:d=>{if(!e.connectors)throw new p("Connector not initialized");d||(d="metamask"),e.startAuthFlow(new ot(e.connectors,d))},loginWithWallet:async()=>{if(!(e.authFlow instanceof ot))throw new p("Must initialize SIWE flow first.");let d,l;b?(d=await e.link(),d&&(d=tt(d))):{user:d,isNewUser:l}=await e.authenticate(),m(d||f||null),_(l||!1),u(!0)},initLoginWithOAuth:async d=>{e.startAuthFlow(new $e(d));let l=await e.authFlow.getAuthorizationUrl();l&&l.url&&window.location.assign(l.url)},loginWithOAuth:async()=>{if(!(e.authFlow instanceof $e))throw new p("Must initialize OAuth flow before calling loginWithOAuth");let d,l;i&&a?d=await e.link():{user:d,isNewUser:l}=await e.authenticate(),m(d),_(l||!1),u(!0)},initLoginWithEmail:async d=>{let l=new rt(d);e.startAuthFlow(l),await l.sendCodeEmail()},initLoginWithSms:async d=>{let l=new it(d);e.startAuthFlow(l),await l.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 rt)e.authFlow.meta.emailCode=d.trim();else if(e.authFlow instanceof it)e.authFlow.meta.smsCode=d.trim();else throw new p("Must initialize a passwordless code flow first");let l,A;b?l=await e.link():{user:l,isNewUser:A}=await e.authenticate(),m(l||f||null),_(A||!1),u(!0)}}))();return(0,De.jsxs)(ao.Provider,{value:Z,children:[t.children,(0,De.jsx)(po.Provider,{value:se,children:(0,De.jsx)(vr,{appSettings:T,options:We,visible:o,authenticated:a,children:o&&(0,De.jsx)(Si,{})})})]})};0&&(module.exports={AsExternalProvider,ConnectorManager,PrivyClient,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.9",
3
+ "version": "1.13.0",
4
4
  "description": "React client for the Privy Auth API",
5
5
  "keywords": [
6
6
  "authentication",