@privy-io/react-auth 1.14.0-beta.2 → 1.14.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +11 -11
- package/dist/index.d.ts +0 -6
- package/dist/index.js +11 -11
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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}},
|
|
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}},p=class extends z{constructor(o,r){super(o,r);this.type="client_error"}};var U=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 p(t.message,t):new p(`Internal error: ${t}`);var Lo="1.14.1-beta.1";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 se=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]}getKeys(){return Object.keys(this._cache)}},$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)}getKeys(){return Object.entries(localStorage).map(([e])=>e)}};function _i(){return typeof window<"u"&&window.localStorage?new $t:new Zt}var R=_i();import{ErrorCode as Pi}from"@ethersproject/logger";var Te=class extends U{constructor(){super("Wallet timeout");this.type="wallet_error"}},ae=t=>{if(t instanceof U)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 U("Unknown connector error",t)},Kt=class extends z{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},We=class extends Kt{constructor(o){var n,s,c;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:(c=r.message)!=null&&c.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,qt=(t=new Te,e=Ii)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),K=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 U(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),qt()]).catch(o=>{throw ae(o)})}},ye=class extends K{constructor(o){super(o)}},at=class extends K{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 Q=class{constructor(e,o,r){this.createSiweMessage=(e,o,r,i,n,s,c)=>`${r} wants you to sign in with your Ethereum account:
|
|
2
2
|
${o}
|
|
3
3
|
|
|
4
|
-
${
|
|
4
|
+
${c}
|
|
5
5
|
|
|
6
6
|
URI: ${i}
|
|
7
7
|
Version: 1
|
|
@@ -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 Q{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 U("Unable to retrieve address");this.connected=!0,this.address=e}catch(e){throw ae(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 Q{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 U("Unable to retrieve address");this.connected=!0}catch(e){throw ae(e)}}};import So from"@walletconnect/web3-provider";var Jt=class extends Q{constructor(o,r,i){super("wallet_connect",r,i);this._globalConnector=o,this._provider=this._globalConnector.getProviderForAddress(i)}async connect(o){return this.provider.setProvider(this._provider),(!await this.isConnected()||o.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return this.provider.walletProvider.connected}async promptConnection(){try{let o="";this.provider.setProvider(this._provider);let r=await Promise.race([this._provider.enable(),qt()]);if(r.length>0&&(o=r[0]),this._globalConnector.indexProvider(this._provider),!o||o==="")throw new U("Unable to retrieve address");this.connected=!0}catch(o){throw ae(o)}}},ct=class{constructor(){this._storageIdToProvider={},this._addressToStorageId={},R.getKeys().forEach(e=>{if(e.startsWith("walletconnect")){let o=new So({infuraId:Ve,storageId:e});o.enable(),this._storageIdToProvider[e]=o;for(let r of o.accounts)this._addressToStorageId[r]=e}})}build(e,o){return new Jt(this,e,o)}async destroy(){Object.values(this._storageIdToProvider).forEach(async e=>{await e.disconnect()})}getProviderForAddress(e){let o=_o,r=()=>`walletconnect:${Math.random().toString(36).slice(2)}`;e===null?o=r():o=this._addressToStorageId[e]||r();let i=new So({infuraId:Ve,storageId:o});return this._storageIdToProvider[o]=i,i}indexProvider(e){this._storageIdToProvider[e.storageId]=e;for(let o of e.accounts)this._addressToStorageId[o]=e.storageId}};var Yt=()=>{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=R.get(it);return t?(e=t.find(o=>o.active))==null?void 0:e.address:null},Be=class{constructor(){this.getEthereumProvider=()=>{var e;return((e=this.activeWalletConnector)==null?void 0:e.provider)||new K};this.walletConnectors=[],this.walletConnectGlobalWalletConnector=new ct,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(){(R.get(it)||[]).forEach(o=>{let r=this.createWalletConnector(o.walletType,o.address);this.addWalletConnector(r),o.active&&(this.activeWalletConnector=r)}),this.save()}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)}});R.put(it,e)}destroy(){this.walletConnectors=[],this.initialized=!1,this.activeWalletConnector=void 0}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}createWalletConnector(e,o){switch(e){case"metamask":return new lt(new K,o);case"coinbase_wallet":return new dt(new K,o);case"wallet_connect":return this.walletConnectGlobalWalletConnector.build(new K,o)}}};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 X(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",Ko=()=>"/api/v1/passwordless_sms/unlink",qo=()=>"/api/v1/oauth/unlink";var Vi=30,ut=class{constructor(){this.authenticateOnce=new se(async e=>this._authenticate(e)),this.linkOnce=new se(async e=>this._link(e)),this.refreshOnce=new se(this._refresh.bind(this)),this.destroyOnce=new se(this._destroy.bind(this)),this.forkSessionOnce=new se(this._forkSession.bind(this))}get token(){try{let e=R.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=R.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:X(i),isNewUser:n}}catch(o){throw console.warn("Error authenticating session"),V(o)}}async _link(e){try{let o=await e.link();return X(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");await this.client.getAccessToken({disableAutoRefresh:!0});let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let r=await this.api.post(Wo(),{refresh_token:o},{headers:{authorization:`Bearer ${e}`}});return this.storeToken(r.data.token),this.storeRefreshToken(r.data.refresh_token),X(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"?R.put(Se,e):R.del(Se)}storeRefreshToken(e){typeof e=="string"?R.put(rt,e):R.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 X(o.data)}catch(o){throw V(o)}}async unlinkPhone(e){try{let o=await this.api.post(Ko(),{phoneNumber:e});return X(o.data)}catch(o){throw V(o)}}async unlinkWallet(e){try{let o=await this.api.post(Zo(),{address:e});return X(o.data)}catch(o){throw V(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(qo(),{provider:e,subject:o});return X(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}),M=()=>Hi(Xt);var je=class{constructor(e,o){this.meta={walletType:o},this.connectors=e,this.walletConnector=this.connectors.createWalletConnector(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 Ks 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 Ki}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 Ki(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 qi,useContext as Ji}from"react";var eo=qi({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 te,jsxs as on}from"react/jsx-runtime";var Qi=()=>te("div",{}),Xi=({backFn:t})=>te("div",{children:te(ir,{onClick:t})}),en=t=>te("div",{children:te("div",{children:te(or,{onClick:t.onClose})})});var L=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=_();return on(tn,{children:[t?te(Xi,{backFn:t}):te(Qi,{}),te(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.",c=new Date().toISOString();return this.createSiweMessage(e,o,i,n,c,r,s)}};import{isMobile as Oi}from"react-device-detect";var lt=class extends Q{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 U("Unable to retrieve address");this.connected=!0,this.address=e}catch(e){throw ae(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 Q{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 U("Unable to retrieve address");this.connected=!0}catch(e){throw ae(e)}}};import So from"@walletconnect/web3-provider";var Jt=class extends Q{constructor(o,r,i){super("wallet_connect",r,i);this._globalConnector=o,this._provider=this._globalConnector.getProviderForAddress(i)}async connect(o){return this.provider.setProvider(this._provider),(!await this.isConnected()||o.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return this.provider.walletProvider.connected}async promptConnection(){try{let o="";this.provider.setProvider(this._provider);let r=await Promise.race([this._provider.enable(),qt()]);if(r.length>0&&(o=r[0]),this._globalConnector.indexProvider(this._provider),!o||o==="")throw new U("Unable to retrieve address");this.connected=!0}catch(o){throw ae(o)}}},ct=class{constructor(){this._storageIdToProvider={},this._addressToStorageId={},R.getKeys().forEach(e=>{if(e.startsWith("walletconnect")){let o=new So({infuraId:Ve,storageId:e});o.enable(),this._storageIdToProvider[e]=o;for(let r of o.accounts)this._addressToStorageId[r]=e}})}build(e,o){return new Jt(this,e,o)}async destroy(){Object.values(this._storageIdToProvider).forEach(async e=>{await e.disconnect()})}getProviderForAddress(e){let o=_o,r=()=>`walletconnect:${Math.random().toString(36).slice(2)}`;e===null?o=r():o=this._addressToStorageId[e]||r();let i=new So({infuraId:Ve,storageId:o});return this._storageIdToProvider[o]=i,i}indexProvider(e){this._storageIdToProvider[e.storageId]=e;for(let o of e.accounts)this._addressToStorageId[o]=e.storageId}};var Yt=()=>{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=R.get(it);return t?(e=t.find(o=>o.active))==null?void 0:e.address:null},Be=class{constructor(){this.getEthereumProvider=()=>{var e;return((e=this.activeWalletConnector)==null?void 0:e.provider)||new K};this.walletConnectors=[],this.walletConnectGlobalWalletConnector=new ct}initialize(){this.load(),this.activeWalletConnector&&this.activeWalletConnector.connect({showPrompt:!1})}initializeLinkedWallets(e){e.linkedAccounts.forEach(()=>{})}load(){(R.get(it)||[]).forEach(o=>{let r=this.createWalletConnector(o.walletType,o.address);this.addWalletConnector(r),o.active&&(this.activeWalletConnector=r)})}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)}});R.put(it,e)}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}createWalletConnector(e,o){switch(e){case"metamask":return new lt(new K,o);case"coinbase_wallet":return new dt(new K,o);case"wallet_connect":return this.walletConnectGlobalWalletConnector.build(new K,o)}}};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 p("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 X(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"),c=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:c&&{subject:c.subject,username:c.username,email:c.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",Ko=()=>"/api/v1/passwordless_sms/unlink",qo=()=>"/api/v1/oauth/unlink";var Vi=30,ut=class{constructor(){this.authenticateOnce=new se(async e=>this._authenticate(e)),this.linkOnce=new se(async e=>this._link(e)),this.refreshOnce=new se(this._refresh.bind(this)),this.destroyOnce=new se(this._destroy.bind(this)),this.forkSessionOnce=new se(this._forkSession.bind(this))}get token(){try{let e=R.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=R.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:X(i),isNewUser:n}}catch(o){throw console.warn("Error authenticating session"),V(o)}}async _link(e){try{let o=await e.link();return X(o)}catch(o){throw console.warn("Error linking account"),V(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");await this.client.getAccessToken({disableAutoRefresh:!0});let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let r=await this.api.post(Wo(),{refresh_token:o},{headers:{authorization:`Bearer ${e}`}});return this.storeToken(r.data.token),this.storeRefreshToken(r.data.refresh_token),X(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 p("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"?R.put(Se,e):R.del(Se)}storeRefreshToken(e){typeof e=="string"?R.put(rt,e):R.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 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.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 X(o.data)}catch(o){throw V(o)}}async unlinkPhone(e){try{let o=await this.api.post(Ko(),{phoneNumber:e});return X(o.data)}catch(o){throw V(o)}}async unlinkWallet(e){try{let o=await this.api.post(Zo(),{address:e});return X(o.data)}catch(o){throw V(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(qo(),{provider:e,subject:o});return X(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 p("Cannot set an unlinked address as active.");if(!this.connectors.setActiveWallet(e))throw new p("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}),M=()=>Hi(Xt);var je=class{constructor(e,o){this.meta={walletType:o},this.connectors=e,this.walletConnector=this.connectors.createWalletConnector(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(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 p("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),c=await this.walletConnector.sign(s);return{message:s,signature:c}}};var Ze=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=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 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=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 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=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 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=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 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=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 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=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 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=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 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=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 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=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 Ks 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 Ki}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,c]=Qo("LANDING");Yo(()=>{o||n("LANDING")},[o]),Yo(()=>{r||(c("LANDING"),n("LANDING"))},[r]);let m={ready:!!(e!=null&&e.id),app:e,options:t.options,currentScreen:i,lastScreen:s,navigate:u=>{c(i),n(u)},navigateBack:()=>{n(s)}};return Ki(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 qi,useContext as Ji}from"react";var eo=qi({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 te,jsxs as on}from"react/jsx-runtime";var Qi=()=>te("div",{}),Xi=({backFn:t})=>te("div",{children:te(ir,{onClick:t})}),en=t=>te("div",{children:te("div",{children:te(or,{onClick:t.onClose})})});var L=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=_();return on(tn,{children:[t?te(Xi,{backFn:t}):te(Qi,{}),te(en,{onClose:e||o})]})},tn=Yi.div`
|
|
13
13
|
height: 30px;
|
|
14
14
|
display: flex;
|
|
15
15
|
align-items: center;
|
|
@@ -292,7 +292,7 @@ Resources:
|
|
|
292
292
|
border-color: var(--fail-light);
|
|
293
293
|
border-bottom-color: var(--fail-light);
|
|
294
294
|
}
|
|
295
|
-
`;import{isPossiblePhoneNumber as kn}from"libphonenumber-js/min";var br=t=>!!String(t).toLowerCase().match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/),xr=t=>kn(String(t),"US"),Lt=t=>{var e=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;t=t.replace(e,function(r,i,n,s){return i+i+n+n+s+s});var o=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return{r:parseInt((o==null?void 0:o[1])||"00",16),g:parseInt((o==null?void 0:o[2])||"00",16),b:parseInt((o==null?void 0:o[3])||"00",16)}},Lr=(t,e)=>{var o=t.slice(0);let r=[];for(;o.length;)r.push(o.splice(0,e));return r};import{Fragment as Mn,jsx as ie,jsxs as io}from"react/jsx-runtime";var At=t=>{let[e,o]=ro(""),[r,i]=ro(!1),[n,s]=ro(null),{authenticated:
|
|
295
|
+
`;import{isPossiblePhoneNumber as kn}from"libphonenumber-js/min";var br=t=>!!String(t).toLowerCase().match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/),xr=t=>kn(String(t),"US"),Lt=t=>{var e=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;t=t.replace(e,function(r,i,n,s){return i+i+n+n+s+s});var o=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return{r:parseInt((o==null?void 0:o[1])||"00",16),g:parseInt((o==null?void 0:o[2])||"00",16),b:parseInt((o==null?void 0:o[3])||"00",16)}},Lr=(t,e)=>{var o=t.slice(0);let r=[];for(;o.length;)r.push(o.splice(0,e));return r};import{Fragment as Mn,jsx as ie,jsxs as io}from"react/jsx-runtime";var At=t=>{let[e,o]=ro(""),[r,i]=ro(!1),[n,s]=ro(null),{authenticated:c}=M(),{initLoginWithEmail:m}=_(),{navigate:u,options:P}=g(),A=P.wallet;_n(()=>{let d=document.querySelector("#email-input");d==null||d.focus()},[]);let k=br(e),y=()=>{i(!0),m(e).then(()=>{u("AWAITING_PASSWORDLESS_CODE")}).catch(d=>{let b=(d==null?void 0:d.status)===401&&(d==null?void 0:d.message)==="User is not allowed to login to this app.";(d==null?void 0:d.status)===422?s(d.message):b?u("ALLOWLIST_REJECTION_SCREEN"):s("Issue submitting email"),i(!1)})};return io(Mn,{children:[io(Pn,{stacked:t.stacked,children:[io(Wn,{standalone:t.stacked,children:[ie(bt,{}),ie("input",{id:"email-input",type:"email",placeholder:"your@email.com",onChange:d=>o(d.target.value),onKeyUp:d=>{d.key==="Enter"&&y()},value:e,autoComplete:"email"})]}),t.stacked?null:ie(Sn,{disabled:r||!k,onClick:y,children:r?ie(ue,{color:"var(--disabled-fg)",style:{height:"1rem",width:"1rem",borderWidth:"2px"}}):"Submit"})]}),n||c||!A?ie(Rn,{fail:!!n,children:n||""}):null,!n&&!c&&A?ie(In,{children:ie("span",{children:"Get started without a wallet."})}):null,t.stacked?ie(Tn,{disabled:r||!k,onClick:y,children:r?ie(ue,{color:"var(--disabled-fg)",style:{height:"1rem",width:"1rem",borderWidth:"2px"}}):"Submit"}):null]})},Pn=Ne.div`
|
|
296
296
|
display: flex;
|
|
297
297
|
border: 1px solid var(--border-color-1);
|
|
298
298
|
width: 100%;
|
|
@@ -412,7 +412,7 @@ Resources:
|
|
|
412
412
|
opacity: ${t=>t.success||t.fail?"1":"0"};
|
|
413
413
|
|
|
414
414
|
transition: ${t=>t.fail?"":"all 150ms ease-in-out"};
|
|
415
|
-
`;import{useEffect as Nn,useState as no}from"react";import be from"styled-components";import{jsx as Ar}from"react/jsx-runtime";var Et=({style:t,...e})=>Ar("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 20 20",strokeWidth:1.5,stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:Ar("path",{d:"M2.5 4.16667C2.5 3.72464 2.67559 3.30072 2.98816 2.98816C3.30072 2.67559 3.72464 2.5 4.16667 2.5H6.9C7.07483 2.50013 7.24519 2.55525 7.38696 2.65754C7.52874 2.75984 7.63475 2.90413 7.69 3.07L8.93833 6.81417C9.00158 7.00445 8.9941 7.21116 8.91726 7.39637C8.84042 7.58158 8.69938 7.73288 8.52 7.8225L6.63917 8.76417C7.5611 10.8046 9.19538 12.4389 11.2358 13.3608L12.1775 11.48C12.2671 11.3006 12.4184 11.1596 12.6036 11.0827C12.7888 11.0059 12.9956 10.9984 13.1858 11.0617L16.93 12.31C17.096 12.3653 17.2404 12.4714 17.3427 12.6134C17.445 12.7553 17.5 12.9259 17.5 13.1008V15.8333C17.5 16.2754 17.3244 16.6993 17.0118 17.0118C16.6993 17.3244 16.2754 17.5 15.8333 17.5H15C8.09667 17.5 2.5 11.9033 2.5 5V4.16667Z",strokeLinecap:"round",strokeLinejoin:"round"})});import{Fragment as Bn,jsx as ne,jsxs as so}from"react/jsx-runtime";var kt=t=>{let[e,o]=no(""),[r,i]=no(!1),[n,s]=no(null),{authenticated:
|
|
415
|
+
`;import{useEffect as Nn,useState as no}from"react";import be from"styled-components";import{jsx as Ar}from"react/jsx-runtime";var Et=({style:t,...e})=>Ar("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 20 20",strokeWidth:1.5,stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:Ar("path",{d:"M2.5 4.16667C2.5 3.72464 2.67559 3.30072 2.98816 2.98816C3.30072 2.67559 3.72464 2.5 4.16667 2.5H6.9C7.07483 2.50013 7.24519 2.55525 7.38696 2.65754C7.52874 2.75984 7.63475 2.90413 7.69 3.07L8.93833 6.81417C9.00158 7.00445 8.9941 7.21116 8.91726 7.39637C8.84042 7.58158 8.69938 7.73288 8.52 7.8225L6.63917 8.76417C7.5611 10.8046 9.19538 12.4389 11.2358 13.3608L12.1775 11.48C12.2671 11.3006 12.4184 11.1596 12.6036 11.0827C12.7888 11.0059 12.9956 10.9984 13.1858 11.0617L16.93 12.31C17.096 12.3653 17.2404 12.4714 17.3427 12.6134C17.445 12.7553 17.5 12.9259 17.5 13.1008V15.8333C17.5 16.2754 17.3244 16.6993 17.0118 17.0118C16.6993 17.3244 16.2754 17.5 15.8333 17.5H15C8.09667 17.5 2.5 11.9033 2.5 5V4.16667Z",strokeLinecap:"round",strokeLinejoin:"round"})});import{Fragment as Bn,jsx as ne,jsxs as so}from"react/jsx-runtime";var kt=t=>{let[e,o]=no(""),[r,i]=no(!1),[n,s]=no(null),{authenticated:c}=M(),{initLoginWithSms:m}=_(),{navigate:u,options:P}=g(),A=P.wallet;Nn(()=>{let d=document.querySelector("#phone-number-input");d==null||d.focus()},[]);let k=xr(e),y=()=>{i(!0),m(e).then(()=>{u("AWAITING_PASSWORDLESS_CODE")}).catch(d=>{let b=(d==null?void 0:d.status)===401&&(d==null?void 0:d.message)==="User is not allowed to login to this app.";(d==null?void 0:d.status)===422?s(d.message):b?u("ALLOWLIST_REJECTION_SCREEN"):s("Issue submitting phone number"),i(!1)})};return so(Bn,{children:[so(On,{stacked:t.stacked,children:[so(Dn,{standalone:t.stacked,children:[ne(Et,{}),ne("input",{id:"phone-number-input",type:"tel",placeholder:"555 555 5555",onChange:d=>{o(d.target.value)},onKeyUp:d=>{d.key==="Enter"&&y()},value:e,autoComplete:"tel"})]}),t.stacked?null:ne(Un,{disabled:r||!k,onClick:y,children:r?ne(Er,{color:"var(--disabled-fg)"}):"Submit"})]}),n||c||!A?ne(Vn,{fail:!!n,children:n||""}):null,!n&&!c&&A?ne(Gn,{children:ne("span",{children:"Don\u2019t have a wallet? Start exploring with your phone or socials."})}):null,t.stacked?ne(Fn,{disabled:r||!k,onClick:y,children:r?ne(Er,{color:"var(--disabled-fg)"}):"Submit"}):null]})},On=be.div`
|
|
416
416
|
display: flex;
|
|
417
417
|
border: 1px solid var(--border-color-1);
|
|
418
418
|
width: 100%;
|
|
@@ -537,7 +537,7 @@ Resources:
|
|
|
537
537
|
width: 1rem;
|
|
538
538
|
border-width: 2px;
|
|
539
539
|
}
|
|
540
|
-
`;import{jsx as kr}from"react/jsx-runtime";var _r=()=>{let{app:t}=g();return t!=null&&t.logoUrl?kr("div",{children:kr("img",{src:t.logoUrl,alt:`${t==null?void 0:t.name} logo`,style:{objectFit:"contain",width:"200px",height:"80px"}})}):null};import{isMobile as Pr}from"react-device-detect";import{Fragment as xe,jsx as v,jsxs as he}from"react/jsx-runtime";var Tr=()=>{let{ready:t}=M(),{getAuthMeta:e,isLinking:o}=_(),{app:r,navigate:i,options:n}=g(),s=n.email,
|
|
540
|
+
`;import{jsx as kr}from"react/jsx-runtime";var _r=()=>{let{app:t}=g();return t!=null&&t.logoUrl?kr("div",{children:kr("img",{src:t.logoUrl,alt:`${t==null?void 0:t.name} logo`,style:{objectFit:"contain",width:"200px",height:"80px"}})}):null};import{isMobile as Pr}from"react-device-detect";import{Fragment as xe,jsx as v,jsxs as he}from"react/jsx-runtime";var Tr=()=>{let{ready:t}=M(),{getAuthMeta:e,isLinking:o}=_(),{app:r,navigate:i,options:n}=g(),s=n.email,c=n.sms,m=n.wallet,u=n.google,P=n.twitter,A=n.discord,k=n.github,y=m&&(r==null?void 0:r.showWalletLoginFirst)?0:1,[d,b]=zn(y),C=e(),H=(C==null?void 0:C.authorizationCode)&&(C==null?void 0:C.stateCode)&&(C==null?void 0:C.provider);Hn(()=>{H?i("AWAITING_OAUTH_SCREEN"):o&&s?i("LINK_EMAIL_SCREEN"):o&&c?i("LINK_PHONE_SCREEN"):o&&m&&i("LINK_WALLET_SCREEN")},[t]);let ge=d==0,I=d==1,F=()=>v(xe,{children:m&&v(jn,{active:ge,onClick:()=>b(0)})}),E=()=>v(xe,{children:(s||c)&&v(Zn,{active:I,onClick:()=>b(1),email:s,sms:c,google:u,twitter:P,discord:A,github:k})});return he(xe,{children:[v(L,{},"header"),v(qn,{walletOnly:!s&&!c&&!u&&!P&&!A&&!k,hasTerms:!!((r==null?void 0:r.privacyPolicyUrl)||(r==null?void 0:r.termsAndConditionsUrl)),children:v(_r,{})}),v(ce,{children:r!=null&&r.showWalletLoginFirst?he(xe,{children:[v(F,{}),v(E,{})]}):he(xe,{children:[v(E,{}),v(F,{})]})}),r&&v(hr,{app:r}),v(q,{protectedByPrivy:!0})]})};function jn(t){return he(Ir,{active:t.active,onClick:t.onClick,children:[v(Wr,{active:t.active,children:v("h4",{children:"Connect Wallet"})}),t.active&&he(xe,{children:[v(mt,{}),v(ft,{})]})]})}function Zn(t){let e=t.google||t.discord||t.github||t.twitter&&!Pr,o=t.email?"Email":"Phone";return he(Ir,{active:t.active,onClick:t.onClick,children:[v(Wr,{active:t.active,children:v("h4",{children:e?`${o} & Social`:o})}),t.active&&t.email&&v(At,{}),t.active&&t.sms&&!t.email&&v(kt,{}),t.active&&e&&v($n,{google:t.google,twitter:t.twitter&&!Pr,discord:t.discord,github:t.github})]})}function $n(t){return he(xe,{children:[he(Kn,{children:[v(Sr,{}),v("p",{children:" Or "}),v(Sr,{})]}),v(Cr,{showGoogle:t.google,showDiscord:t.discord,showGithub:t.github,showTwitter:t.twitter})]})}var Wr=Ye.div`
|
|
541
541
|
font-weight: ${t=>t.active?600:500};
|
|
542
542
|
color: ${t=>t.active?"inherit":"var(--light-theme-fg-3)"};
|
|
543
543
|
display: flex;
|
|
@@ -631,7 +631,7 @@ Resources:
|
|
|
631
631
|
border-color: var(--light-theme-bg-3);
|
|
632
632
|
border-width: 1px;
|
|
633
633
|
}
|
|
634
|
-
`;import{Fragment as ao,jsx as B,jsxs as Ue}from"react/jsx-runtime";var lo=6,Ur=new Array(lo).fill(""),Qn=1400;var Fr=()=>{var E,Z,l;let{app:t}=g(),{closePrivyModal:e,resendEmailCode:o,resendSmsCode:r,getAuthMeta:i,loginWithCode:n}=_(),{authenticated:s,user:
|
|
634
|
+
`;import{Fragment as ao,jsx as B,jsxs as Ue}from"react/jsx-runtime";var lo=6,Ur=new Array(lo).fill(""),Qn=1400;var Fr=()=>{var E,Z,l;let{app:t}=g(),{closePrivyModal:e,resendEmailCode:o,resendSmsCode:r,getAuthMeta:i,loginWithCode:n}=_(),{authenticated:s,user:c}=M(),[m,u]=Pt(Ur),[P,A]=Pt(!1),[k,y]=Pt(null),[d,b]=Pt(null),C=(E=i())!=null&&E.email?0:1;Or(()=>{if(s&&P){let a=setTimeout(e,Pe);return()=>clearTimeout(a)}},[s,P,c]),Or(()=>{if(k&&d===0){let a=setTimeout(()=>{u(Ur),y(null);let x=document.querySelector("input[name=code-0]");x==null||x.focus()},Qn);return()=>clearTimeout(a)}},[k]);let H=a=>{var xo;let x=a.currentTarget.value.replace(" ","");if(x==="")return;if(isNaN(Number(x))){y("Code should be numeric"),b(1);return}y(null),b(null);let O=Number((xo=a.currentTarget.name)==null?void 0:xo.charAt(5)),Vt=[...x||[""]].slice(0,lo-O),Bt=[...m.slice(0,O),...Vt,...m.slice(O+Vt.length)];u(Bt);let Ai=Vt.length,bo=Math.min(Math.max(O+Ai,0),lo-1);if(!isNaN(Number(a.currentTarget.value))){let $=document.querySelector(`input[name=code-${bo}]`);$==null||$.focus()}if(Bt.every($=>$&&!isNaN(+$))){let $=document.querySelector(`input[name=code-${bo}]`);$==null||$.blur(),n(Bt.join("")).then(()=>A(!0)).catch(Ht=>{(Ht==null?void 0:Ht.status)===422?y("Invalid or expired verification code"):y("Issue verifying code"),b(0)})}a.preventDefault()},ge=a=>{d===1&&(y(null),b(null));let x=[...m.slice(0,a),"",...m.slice(a+1)];if(u(x),a>0){let O=document.querySelector(`input[name=code-${a-1}]`);O==null||O.focus()}},I=`Verify your ${C==0?"email":"phone"}`,F=C==0?`Please check ${(Z=i())==null?void 0:Z.email} for an email from privy.io and enter your code below.`:`Please check ${(l=i())==null?void 0:l.phoneNumber} for a message from ${(t==null?void 0:t.name)||"privy.io"} and enter your code below.`;return Ue(ao,{children:[B(L,{},"header"),Ue(Xn,{children:[B(Le,{title:I,description:F}),Ue(gr,{children:[Ue(es,{children:[B(ts,{fail:!!k,success:P,children:B("span",{children:k||(P?"Success!":"")})}),B("div",{children:m.map((a,x)=>B("input",{name:`code-${x}`,type:"text",value:m[x],onChange:H,onKeyUp:O=>{O.key==="Backspace"&&ge(x)},inputMode:"numeric",autoFocus:x===0,pattern:"[0-9]",className:`${P?"success":""} ${k?"fail":""}`,autoComplete:"one-time-code"},x))})]}),B(os,{children:C==0?Ue(ao,{children:[B("span",{children:"Didn't get an email?"}),B("button",{onClick:o,children:"Resend Code"})]}):Ue(ao,{children:[B("span",{children:"Didn't get a message?"}),B("button",{onClick:r,children:"Resend Code"})]})})]})]}),B(q,{protectedByPrivy:!0})]})},Xn=St.div`
|
|
635
635
|
display: flex;
|
|
636
636
|
flex-direction: column;
|
|
637
637
|
align-items: flex-start;
|
|
@@ -795,7 +795,7 @@ Resources:
|
|
|
795
795
|
background-color: var(--primary-color-bg-2);
|
|
796
796
|
}
|
|
797
797
|
}
|
|
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 N,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
|
|
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 N,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 c=t==null?void 0:t[s];c&&c[n]&&(c[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})=>N(Fe,{children:[0,1,2].map(n=>N("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 N(Fe,{children:i.map(([n,s])=>N(cs,{x:n,y:s,cellSize:t,bgColor:o,fgColor:r}))})},us=({matrix:t,cellSize:e,color:o})=>N(Fe,{children:t.map((r,i)=>r.map((n,s)=>n?N("circle",{r:e/2.5,cx:i*e+e/2,cy:s*e+e/2,fill:o},`circle-${i}-${s}`):N(Fe,{})))}),zr=(t,e)=>t-t%e,hs=({outputSize:t,cellSize:e,element:o,size:r,padding:i,bgColor:n})=>{if(!o)return N(Fe,{});let s=r||40,c=i||4,m=o,u=t/2-s/2-c;return Zr(Fe,{children:[N("rect",{x:zr(u,e),y:zr(u,e),width:s+c*2+(u%e?e+.5:.5),height:s+c*2+(u%e?e+.5:.5),fill:n}),N(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:[N(us,{matrix:o,cellSize:r,color:t.fgColor}),N(ps,{cellSize:r,matrixSize:o.length,fgColor:t.fgColor,bgColor:t.bgColor}),N(hs,{outputSize:t.outputSize,cellSize:r,element:(i=t.logo)==null?void 0:i.element,bgColor:t.bgColor})]})},fs=ls.div`
|
|
799
799
|
display: flex;
|
|
800
800
|
justify-content: center;
|
|
801
801
|
align-items: center;
|
|
@@ -995,7 +995,7 @@ Resources:
|
|
|
995
995
|
`,ks=j.div`
|
|
996
996
|
display: flex;
|
|
997
997
|
justify-content: center;
|
|
998
|
-
`;import{useEffect as ni,useState as et}from"react";import Nt from"styled-components";import{Fragment as Ws,jsx as Ee,jsxs as Mt}from"react/jsx-runtime";var yo=2,si={metamask:{name:"MetaMask",component:ve},coinbase_wallet:{name:"Coinbase Wallet",component:de},wallet_connect:{name:"WalletConnect",component:ht}},ai=()=>{let[t,e]=et(!1),[o,r]=et("metamask"),[i,n]=et(void 0),{navigate:s,navigateBack:
|
|
998
|
+
`;import{useEffect as ni,useState as et}from"react";import Nt from"styled-components";import{Fragment as Ws,jsx as Ee,jsxs as Mt}from"react/jsx-runtime";var yo=2,si={metamask:{name:"MetaMask",component:ve},coinbase_wallet:{name:"Coinbase Wallet",component:de},wallet_connect:{name:"WalletConnect",component:ht}},ai=()=>{let[t,e]=et(!1),[o,r]=et("metamask"),[i,n]=et(void 0),{navigate:s,navigateBack:c}=g(),{getAuthMeta:m,closePrivyModal:u,loginWithWallet:P}=_(),[A,k]=et(0),{user:y}=M(),[d,b]=et((y==null?void 0:y.linkedAccounts.length)||0);ni(()=>{var F;r(((F=m())==null?void 0:F.walletType)||"metamask"),n(void 0),P().then(()=>e(!0)).catch(E=>{E instanceof z?console.error(E.cause):console.error(E);let Z=(E==null?void 0:E.status)===401&&(E==null?void 0:E.message)==="User is not allowed to login to this app.";(E==null?void 0:E.status)===422?n(st.ERROR_USER_EXISTS):Z?s("ALLOWLIST_REJECTION_SCREEN"):E instanceof We&&!E.details.default?n(E.details):E instanceof Te?n(st.ERROR_TIMED_OUT):n(st.ERROR_WALLET_CONNECTION)})},[A]),ni(()=>{if(t){let F=setTimeout(u,Pe);return()=>clearTimeout(F)}},[y]);let C=si[o].name,H=si[o].component,ge=t?`Successfully connected with ${C}`:i?i.message:`Waiting for ${C}`,I="";if(t){let F=(y==null?void 0:y.linkedAccounts.length)||0;d===F?I="Wallet was already linked.":I="You\u2019re good to go!"}else if(A>=yo&&i)I="Unable to connect wallet";else if(i)I=i.detail;else switch(I="Don\u2019t see your wallet modal? Check your other browser windows.",o){case"wallet_connect":I="Open your mobile wallet app to continue";break;case"coinbase_wallet":pt()||(I="Open the Coinbase app on your phone to continue.");break;default:I="Don\u2019t see your wallet modal? Check your other browser windows."}return Mt(Ws,{children:[Ee(L,{backFn:c}),Mt(_s,{children:[Ee(Ss,{children:Mt("div",{children:[Ee(xt,{success:t,fail:!!i}),Ee(H,{style:{width:"38px",height:"38px"}})]})}),Mt(Ps,{children:[Ee("h3",{children:ge}),Ee("p",{children:I})]}),Ee(Ts,{onClick:()=>{k(A+1),n(void 0)},visible:!t&&(i==null?void 0:i.retryable)&&A<yo,disabled:!t&&(!(i!=null&&i.retryable)||A>=yo),children:"Retry"})]})]})},_s=Nt.div`
|
|
999
999
|
display: flex;
|
|
1000
1000
|
flex-direction: column;
|
|
1001
1001
|
align-items: center;
|
|
@@ -1354,7 +1354,7 @@ Resources:
|
|
|
1354
1354
|
display: none;
|
|
1355
1355
|
}
|
|
1356
1356
|
}
|
|
1357
|
-
`;import{useEffect as qs}from"react";import{useEffect as hi,useState as mi}from"react";import Dt from"styled-components";import{Fragment as Bs,jsx as ke,jsxs as Ft}from"react/jsx-runtime";var fi={google:{name:"Google",component:vt},discord:{name:"Discord",component:wt},github:{name:"Github",component:yt},twitter:{name:"Twitter",component:gt}},Us=t=>t.charAt(0).toUpperCase()+t.slice(1),Co=()=>{let t=new URL(window.location.href);t.searchParams.delete("privy_oauth_code"),t.searchParams.delete("privy_oauth_provider"),t.searchParams.delete("privy_oauth_state"),window.history.pushState({},"",t)},gi=()=>{var d;let[t,e]=mi(!1),[o,r]=mi(void 0),{getAuthMeta:i,initLoginWithOAuth:n,loginWithOAuth:s,closePrivyModal:
|
|
1357
|
+
`;import{useEffect as qs}from"react";import{useEffect as hi,useState as mi}from"react";import Dt from"styled-components";import{Fragment as Bs,jsx as ke,jsxs as Ft}from"react/jsx-runtime";var fi={google:{name:"Google",component:vt},discord:{name:"Discord",component:wt},github:{name:"Github",component:yt},twitter:{name:"Twitter",component:gt}},Us=t=>t.charAt(0).toUpperCase()+t.slice(1),Co=()=>{let t=new URL(window.location.href);t.searchParams.delete("privy_oauth_code"),t.searchParams.delete("privy_oauth_provider"),t.searchParams.delete("privy_oauth_state"),window.history.pushState({},"",t)},gi=()=>{var d;let[t,e]=mi(!1),[o,r]=mi(void 0),{getAuthMeta:i,initLoginWithOAuth:n,loginWithOAuth:s,closePrivyModal:c}=_(),{ready:m}=M(),u=((d=i())==null?void 0:d.provider)||"google",P=fi[u].name,A=fi[u].component;hi(()=>{!m||s().then(()=>{Co(),e(!0)}).catch(b=>{let C={retryable:!1,message:"Authentication failed."};b.message.includes("Another user has already linked this")?C.detail="This account has already been linked to another user.":b.message==="Invalid code during oauth flow."?(C.retryable=!0,C.detail="Something went wrong. Try again."):b.message==="User denied confirmation during OAuth flow"&&(C.detail=`Retry and check ${Us(u)} to finish connecting your account.`,C.retryable=!0),Co(),r(C)})},[m]),hi(()=>{if(!t)return;let b=setTimeout(c,Pe);return()=>clearTimeout(b)},[t]);let k=t?`Successfully connected with ${P}`:o?o.message:`Verifying connection to ${P}`,y="";return t?y="You\u2019re good to go!":o?y=o.detail:y="Just a few moments more",Ft(Bs,{children:[ke(L,{}),Ft(Fs,{children:[ke(Gs,{children:Ft("div",{children:[ke(xt,{success:t,fail:!!o}),ke(A,{style:{width:"38px",height:"38px"},logoFill:"primary"})]})}),Ft(Ds,{children:[ke("h3",{children:k}),ke("p",{children:y})]}),ke(Vs,{onClick:()=>{Co(),n(u),r(void 0)},visible:!t&&(o==null?void 0:o.retryable),disabled:!t&&!(o!=null&&o.retryable),children:"Retry"})]})]})},Fs=Dt.div`
|
|
1358
1358
|
display: flex;
|
|
1359
1359
|
flex-direction: column;
|
|
1360
1360
|
align-items: center;
|
|
@@ -1460,4 +1460,4 @@ Resources:
|
|
|
1460
1460
|
align-items: center;
|
|
1461
1461
|
justify-content: center;
|
|
1462
1462
|
height: 100%;
|
|
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=R.get(Se);return Promise.resolve(t||null)}return ot.getAccessToken()}var ra=t=>{if(!ta(t.appId))throw new
|
|
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=R.get(Se);return Promise.resolve(t||null)}return ot.getAccessToken()}var ra=t=>{if(!ta(t.appId))throw new p("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,c]=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();c(!!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"),O=l.get("privy_oauth_provider");a&&x&&O&&(e.startAuthFlow(new Ie(O,a,x)),b(O),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),c(!1),b(null),H(!1),r(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>e.connectors.getEthereumProvider(),getEthersProvider:()=>new ea(new ye(e.connectors.getEthereumProvider())),getWeb3jsProvider:()=>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 p("Connector not initialized");l||(l="metamask"),e.startAuthFlow(new je(e.connectors,l))},loginWithWallet:async()=>{if(!(e.authFlow instanceof je))throw new p("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),c(!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 p("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),c(!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 p("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),c(!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,K as PrivyProxyProvider,zt as VERSION,Q as WalletConnector,oa as getAccessToken,M as usePrivy};
|
package/dist/index.d.ts
CHANGED
|
@@ -320,7 +320,6 @@ declare class ConnectorManager {
|
|
|
320
320
|
walletConnectors: WalletConnector[];
|
|
321
321
|
activeWalletConnector?: WalletConnector;
|
|
322
322
|
walletConnectGlobalWalletConnector: WalletConnectGlobalWalletConnector;
|
|
323
|
-
initialized: boolean;
|
|
324
323
|
constructor();
|
|
325
324
|
initialize(): void;
|
|
326
325
|
getEthereumProvider: () => EIP1193Provider;
|
|
@@ -333,11 +332,6 @@ declare class ConnectorManager {
|
|
|
333
332
|
initializeLinkedWallets(user: User): void;
|
|
334
333
|
load(): void;
|
|
335
334
|
save(): void;
|
|
336
|
-
/**
|
|
337
|
-
* Note that we purposefully don't delete CONNECTORS_STATE_KEY from localStorage
|
|
338
|
-
* This is because we can't recuperate state from the server state along yet (PRI-569).
|
|
339
|
-
*/
|
|
340
|
-
destroy(): void;
|
|
341
335
|
addWalletConnector(walletConnector: WalletConnector): void;
|
|
342
336
|
removeWallet(address: string): void;
|
|
343
337
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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:()=>xe,ConnectorManager:()=>je,PrivyClient:()=>Ze,PrivyProvider:()=>Ii,PrivyProxyProvider:()=>te,VERSION:()=>ft,WalletConnector:()=>le,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}},
|
|
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:()=>xe,ConnectorManager:()=>je,PrivyClient:()=>Ze,PrivyProvider:()=>Ii,PrivyProxyProvider:()=>te,VERSION:()=>ft,WalletConnector:()=>le,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}},u=class extends ee{constructor(o,r){super(o,r);this.type="client_error"}};var j=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 K(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)},K=t=>t instanceof ee?t:t instanceof Error?new u(t.message,t):new u(`Internal error: ${t}`);var Fo="1.14.1-beta.1";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")),he=class{static parse(e){try{return new he(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 ve=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]}getKeys(){return Object.keys(this._cache)}},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)}getKeys(){return Object.entries(localStorage).map(([e])=>e)}};function Bi(){return typeof window<"u"&&window.localStorage?new eo:new Xt}var V=Bi();var zo=require("@ethersproject/logger");var He=class extends j{constructor(){super("Wallet timeout");this.type="wallet_error"}},be=t=>{if(t instanceof j)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 j("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,p;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:(p=r.message)!=null&&p.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 j(`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 be(o)})}},xe=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"),le=class{constructor(e,o,r){this.createSiweMessage=(e,o,r,i,n,a,p)=>`${r} wants you to sign in with your Ethereum account:
|
|
2
2
|
${o}
|
|
3
3
|
|
|
4
|
-
${
|
|
4
|
+
${p}
|
|
5
5
|
|
|
6
6
|
URI: ${i}
|
|
7
7
|
Version: 1
|
|
@@ -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 xe(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 Ko=require("react-device-detect"),xt=class extends le{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="";Ko.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 j("Unable to retrieve address");this.connected=!0,this.address=e}catch(e){throw be(e)}}};var qo=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 le{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,qo.getAddress)(o[0])),!e||e==="")throw new j("Unable to retrieve address");this.connected=!0}catch(e){throw be(e)}}};var ro=v(require("@walletconnect/web3-provider"));var io=class extends le{constructor(o,r,i){super("wallet_connect",r,i);this._globalConnector=o,this._provider=this._globalConnector.getProviderForAddress(i)}async connect(o){return this.provider.setProvider(this._provider),(!await this.isConnected()||o.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return this.provider.walletProvider.connected}async promptConnection(){try{let o="";this.provider.setProvider(this._provider);let r=await Promise.race([this._provider.enable(),oo()]);if(r.length>0&&(o=r[0]),this._globalConnector.indexProvider(this._provider),!o||o==="")throw new j("Unable to retrieve address");this.connected=!0}catch(o){throw be(o)}}},At=class{constructor(){this._storageIdToProvider={},this._addressToStorageId={},V.getKeys().forEach(e=>{if(e.startsWith("walletconnect")){let o=new ro.default({infuraId:et,storageId:e});o.enable(),this._storageIdToProvider[e]=o;for(let r of o.accounts)this._addressToStorageId[r]=e}})}build(e,o){return new io(this,e,o)}async destroy(){Object.values(this._storageIdToProvider).forEach(async e=>{await e.disconnect()})}getProviderForAddress(e){let o=Bo,r=()=>`walletconnect:${Math.random().toString(36).slice(2)}`;e===null?o=r():o=this._addressToStorageId[e]||r();let i=new ro.default({infuraId:et,storageId:o});return this._storageIdToProvider[o]=i,i}indexProvider(e){this._storageIdToProvider[e.storageId]=e;for(let o of e.accounts)this._addressToStorageId[o]=e.storageId}};var no=()=>{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=V.get(wt);return t?(e=t.find(o=>o.active))==null?void 0:e.address:null},je=class{constructor(){this.getEthereumProvider=()=>{var e;return((e=this.activeWalletConnector)==null?void 0:e.provider)||new te};this.walletConnectors=[],this.walletConnectGlobalWalletConnector=new At,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(){(V.get(wt)||[]).forEach(o=>{let r=this.createWalletConnector(o.walletType,o.address);this.addWalletConnector(r),o.active&&(this.activeWalletConnector=r)}),this.save()}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)}});V.put(wt,e)}destroy(){this.walletConnectors=[],this.initialized=!1,this.activeWalletConnector=void 0}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}createWalletConnector(e,o){switch(e){case"metamask":return new xt(new te,o);case"coinbase_wallet":return new Lt(new te,o);case"wallet_connect":return this.walletConnectGlobalWalletConnector.build(new te,o)}}};function Le(t){return new Date(t*1e3)}function Ki(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 me(t){if(!t)return null;let e=Ki(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 qi=30,kt=class{constructor(){this.authenticateOnce=new ve(async e=>this._authenticate(e)),this.linkOnce=new ve(async e=>this._link(e)),this.refreshOnce=new ve(this._refresh.bind(this)),this.destroyOnce=new ve(this._destroy.bind(this)),this.forkSessionOnce=new ve(this._forkSession.bind(this))}get token(){try{let e=V.get(Be);return typeof e=="string"?new he(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=V.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=he.parse(this.token);return e!==null&&!e.isExpired(qi)}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:me(i),isNewUser:n}}catch(o){throw console.warn("Error authenticating session"),K(o)}}async _link(e){try{let o=await e.link();return me(o)}catch(o){throw console.warn("Error linking account"),K(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");await this.client.getAccessToken({disableAutoRefresh:!0});let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let r=await this.api.post(Qo(),{refresh_token:o},{headers:{authorization:`Bearer ${e}`}});return this.storeToken(r.data.token),this.storeRefreshToken(r.data.refresh_token),me(r.data.user)}catch(r){if(r instanceof Ge&&r.status===400&&r.message==="Invalid auth token")return this.destroyLocalState(),null;throw K(r)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(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 K(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?V.put(Be,e):V.del(Be)}storeRefreshToken(e){typeof e=="string"?V.put(gt,e):V.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 me(o.data)}catch(o){throw K(o)}}async unlinkPhone(e){try{let o=await this.api.post(fr(),{phoneNumber:e});return me(o.data)}catch(o){throw K(o)}}async unlinkWallet(e){try{let o=await this.api.post(hr(),{address:e});return me(o.data)}catch(o){throw K(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(gr(),{provider:e,subject:o});return me(r.data)}catch(r){throw K(r)}}async getAuthenticatedUser(){return this.session.hasRefreshCredentials()?this.session.refresh():null}async getAccessToken(e){var o;return this.session.hasActiveToken()?((o=he.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 K(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=this.connectors.createWalletConnector(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")),qt=v(require("styled-components"));var de=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,de.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,de.useState)("LANDING"),[a,u]=(0,de.useState)("LANDING");(0,de.useEffect)(()=>{o||n("LANDING")},[o]),(0,de.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,de.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 q=require("react/jsx-runtime"),Ji=()=>(0,q.jsx)("div",{}),Yi=({backFn:t})=>(0,q.jsx)("div",{children:(0,q.jsx)(xr,{onClick:t})}),Qi=t=>(0,q.jsx)("div",{children:(0,q.jsx)("div",{children:(0,q.jsx)(br,{onClick:t.onClose})})});var E=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=W();return(0,q.jsxs)(Xi,{children:[t?(0,q.jsx)(Yi,{backFn:t}):(0,q.jsx)(Ji,{}),(0,q.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 xe(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.",p=new Date().toISOString();return this.createSiweMessage(e,o,i,n,p,r,a)}};var Ko=require("react-device-detect"),xt=class extends le{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="";Ko.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 j("Unable to retrieve address");this.connected=!0,this.address=e}catch(e){throw be(e)}}};var qo=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 le{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,qo.getAddress)(o[0])),!e||e==="")throw new j("Unable to retrieve address");this.connected=!0}catch(e){throw be(e)}}};var ro=v(require("@walletconnect/web3-provider"));var io=class extends le{constructor(o,r,i){super("wallet_connect",r,i);this._globalConnector=o,this._provider=this._globalConnector.getProviderForAddress(i)}async connect(o){return this.provider.setProvider(this._provider),(!await this.isConnected()||o.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return this.provider.walletProvider.connected}async promptConnection(){try{let o="";this.provider.setProvider(this._provider);let r=await Promise.race([this._provider.enable(),oo()]);if(r.length>0&&(o=r[0]),this._globalConnector.indexProvider(this._provider),!o||o==="")throw new j("Unable to retrieve address");this.connected=!0}catch(o){throw be(o)}}},At=class{constructor(){this._storageIdToProvider={},this._addressToStorageId={},V.getKeys().forEach(e=>{if(e.startsWith("walletconnect")){let o=new ro.default({infuraId:et,storageId:e});o.enable(),this._storageIdToProvider[e]=o;for(let r of o.accounts)this._addressToStorageId[r]=e}})}build(e,o){return new io(this,e,o)}async destroy(){Object.values(this._storageIdToProvider).forEach(async e=>{await e.disconnect()})}getProviderForAddress(e){let o=Bo,r=()=>`walletconnect:${Math.random().toString(36).slice(2)}`;e===null?o=r():o=this._addressToStorageId[e]||r();let i=new ro.default({infuraId:et,storageId:o});return this._storageIdToProvider[o]=i,i}indexProvider(e){this._storageIdToProvider[e.storageId]=e;for(let o of e.accounts)this._addressToStorageId[o]=e.storageId}};var no=()=>{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=V.get(wt);return t?(e=t.find(o=>o.active))==null?void 0:e.address:null},je=class{constructor(){this.getEthereumProvider=()=>{var e;return((e=this.activeWalletConnector)==null?void 0:e.provider)||new te};this.walletConnectors=[],this.walletConnectGlobalWalletConnector=new At}initialize(){this.load(),this.activeWalletConnector&&this.activeWalletConnector.connect({showPrompt:!1})}initializeLinkedWallets(e){e.linkedAccounts.forEach(()=>{})}load(){(V.get(wt)||[]).forEach(o=>{let r=this.createWalletConnector(o.walletType,o.address);this.addWalletConnector(r),o.active&&(this.activeWalletConnector=r)})}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)}});V.put(wt,e)}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}createWalletConnector(e,o){switch(e){case"metamask":return new xt(new te,o);case"coinbase_wallet":return new Lt(new te,o);case"wallet_connect":return this.walletConnectGlobalWalletConnector.build(new te,o)}}};function Le(t){return new Date(t*1e3)}function Ki(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 u("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 me(t){if(!t)return null;let e=Ki(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"),p=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:p&&{subject:p.subject,username:p.username,email:p.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 qi=30,kt=class{constructor(){this.authenticateOnce=new ve(async e=>this._authenticate(e)),this.linkOnce=new ve(async e=>this._link(e)),this.refreshOnce=new ve(this._refresh.bind(this)),this.destroyOnce=new ve(this._destroy.bind(this)),this.forkSessionOnce=new ve(this._forkSession.bind(this))}get token(){try{let e=V.get(Be);return typeof e=="string"?new he(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=V.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=he.parse(this.token);return e!==null&&!e.isExpired(qi)}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:me(i),isNewUser:n}}catch(o){throw console.warn("Error authenticating session"),K(o)}}async _link(e){try{let o=await e.link();return me(o)}catch(o){throw console.warn("Error linking account"),K(o)}}async _refresh(){if(!this.api)throw new u("Session has no API instance");if(!this.client)throw new u("Session has no PrivyClient instance");await this.client.getAccessToken({disableAutoRefresh:!0});let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let r=await this.api.post(Qo(),{refresh_token:o},{headers:{authorization:`Bearer ${e}`}});return this.storeToken(r.data.token),this.storeRefreshToken(r.data.refresh_token),me(r.data.user)}catch(r){if(r instanceof Ge&&r.status===400&&r.message==="Invalid auth token")return this.destroyLocalState(),null;throw K(r)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(Xo(),{refresh_token:this.refreshToken}))}catch{console.warn("Error destroying session")}this.destroyLocalState()}async _forkSession(){if(!this.api)throw new u("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(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 K(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?V.put(Be,e):V.del(Be)}storeRefreshToken(e){typeof e=="string"?V.put(gt,e):V.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 u("No auth flow in progress.");return this.session.authenticate(this.authFlow)}link(){if(!this.authFlow)throw new u("No auth flow in progress.");return this.session.link(this.authFlow)}async logout(){await this.session.destroy(),this.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 me(o.data)}catch(o){throw K(o)}}async unlinkPhone(e){try{let o=await this.api.post(fr(),{phoneNumber:e});return me(o.data)}catch(o){throw K(o)}}async unlinkWallet(e){try{let o=await this.api.post(hr(),{address:e});return me(o.data)}catch(o){throw K(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(gr(),{provider:e,subject:o});return me(r.data)}catch(r){throw K(r)}}async getAuthenticatedUser(){return this.session.hasRefreshCredentials()?this.session.refresh():null}async getAccessToken(e){var o;return this.session.hasActiveToken()?((o=he.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 K(e)}}setActiveWallet(e,o){if(!o.linkedAccounts.map(n=>n.type==="wallet"?n.address:null).includes(e))throw new u("Cannot set an unlinked address as active.");if(!this.connectors.setActiveWallet(e))throw new u("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=this.connectors.createWalletConnector(o,null)}async authenticate(){if(!this.api)throw new u("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 u("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),p=await this.walletConnector.sign(a);return{message:a,signature:p}}};var rt=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new u("Email and email code must be set prior to calling authenticate.");try{let e=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 u("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new u("Email and email code must be set prior to calling authenticate.");try{let e=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 u("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new u("Email must be set when initialzing authentication.");try{let o=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 u("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new u("phone number and sms code must be set prior to calling authenticate.");try{let e=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 u("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new u("phone number and sms code must be set prior to calling authenticate.");try{let e=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 u("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new u("phone nNumber must be set when initialzing authentication.");try{let o=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 u("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new u("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new u("User denied confirmation during OAuth flow");try{let e=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 u("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new u("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new u("User denied confirmation during OAuth flow");try{let e=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 u("Auth flow has no API instance");if(!this.meta.provider)throw new u("Provider must be set when initialzing OAuth authentication.");try{let e=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")),qt=v(require("styled-components"));var de=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,de.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,de.useState)("LANDING"),[a,p]=(0,de.useState)("LANDING");(0,de.useEffect)(()=>{o||n("LANDING")},[o]),(0,de.useEffect)(()=>{r||(p("LANDING"),n("LANDING"))},[r]);let f={ready:!!(e!=null&&e.id),app:e,options:t.options,currentScreen:i,lastScreen:a,navigate:m=>{p(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,de.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 q=require("react/jsx-runtime"),Ji=()=>(0,q.jsx)("div",{}),Yi=({backFn:t})=>(0,q.jsx)("div",{children:(0,q.jsx)(xr,{onClick:t})}),Qi=t=>(0,q.jsx)("div",{children:(0,q.jsx)("div",{children:(0,q.jsx)(br,{onClick:t.onClose})})});var E=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=W();return(0,q.jsxs)(Xi,{children:[t?(0,q.jsx)(Yi,{backFn:t}):(0,q.jsx)(Ji,{}),(0,q.jsx)(Qi,{onClose:e||o})]})},Xi=Lr.default.div`
|
|
13
13
|
height: 30px;
|
|
14
14
|
display: flex;
|
|
15
15
|
align-items: center;
|
|
@@ -292,7 +292,7 @@ Resources:
|
|
|
292
292
|
border-color: var(--fail-light);
|
|
293
293
|
border-bottom-color: var(--fail-light);
|
|
294
294
|
}
|
|
295
|
-
`;var Rr=require("libphonenumber-js/min");var Mr=t=>!!String(t).toLowerCase().match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/),Nr=t=>(0,Rr.isPossiblePhoneNumber)(String(t),"US"),Gt=t=>{var e=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;t=t.replace(e,function(r,i,n,a){return i+i+n+n+a+a});var o=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return{r:parseInt((o==null?void 0:o[1])||"00",16),g:parseInt((o==null?void 0:o[2])||"00",16),b:parseInt((o==null?void 0:o[3])||"00",16)}},Or=(t,e)=>{var o=t.slice(0);let r=[];for(;o.length;)r.push(o.splice(0,e));return r};var F=require("react/jsx-runtime"),Vt=t=>{let[e,o]=(0,qe.useState)(""),[r,i]=(0,qe.useState)(!1),[n,a]=(0,qe.useState)(null),{authenticated:
|
|
295
|
+
`;var Rr=require("libphonenumber-js/min");var Mr=t=>!!String(t).toLowerCase().match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/),Nr=t=>(0,Rr.isPossiblePhoneNumber)(String(t),"US"),Gt=t=>{var e=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;t=t.replace(e,function(r,i,n,a){return i+i+n+n+a+a});var o=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return{r:parseInt((o==null?void 0:o[1])||"00",16),g:parseInt((o==null?void 0:o[2])||"00",16),b:parseInt((o==null?void 0:o[3])||"00",16)}},Or=(t,e)=>{var o=t.slice(0);let r=[];for(;o.length;)r.push(o.splice(0,e));return r};var F=require("react/jsx-runtime"),Vt=t=>{let[e,o]=(0,qe.useState)(""),[r,i]=(0,qe.useState)(!1),[n,a]=(0,qe.useState)(null),{authenticated:p}=N(),{initLoginWithEmail:f}=W(),{navigate:m,options:R}=y(),_=R.wallet;(0,qe.useEffect)(()=>{let c=document.querySelector("#email-input");c==null||c.focus()},[]);let T=Mr(e),C=()=>{i(!0),f(e).then(()=>{m("AWAITING_PASSWORDLESS_CODE")}).catch(c=>{let L=(c==null?void 0:c.status)===401&&(c==null?void 0:c.message)==="User is not allowed to login to this app.";(c==null?void 0:c.status)===422?a(c.message):L?m("ALLOWLIST_REJECTION_SCREEN"):a("Issue submitting email"),i(!1)})};return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(dn,{stacked:t.stacked,children:[(0,F.jsxs)(un,{standalone:t.stacked,children:[(0,F.jsx)(Ft,{}),(0,F.jsx)("input",{id:"email-input",type:"email",placeholder:"your@email.com",onChange:c=>o(c.target.value),onKeyUp:c=>{c.key==="Enter"&&C()},value:e,autoComplete:"email"})]}),t.stacked?null:(0,F.jsx)(cn,{disabled:r||!T,onClick:C,children:r?(0,F.jsx)(_e,{color:"var(--disabled-fg)",style:{height:"1rem",width:"1rem",borderWidth:"2px"}}):"Submit"})]}),n||p||!_?(0,F.jsx)(mn,{fail:!!n,children:n||""}):null,!n&&!p&&_?(0,F.jsx)(hn,{children:(0,F.jsx)("span",{children:"Get started without a wallet."})}):null,t.stacked?(0,F.jsx)(pn,{disabled:r||!T,onClick:C,children:r?(0,F.jsx)(_e,{color:"var(--disabled-fg)",style:{height:"1rem",width:"1rem",borderWidth:"2px"}}):"Submit"}):null]})},dn=Oe.default.div`
|
|
296
296
|
display: flex;
|
|
297
297
|
border: 1px solid var(--border-color-1);
|
|
298
298
|
width: 100%;
|
|
@@ -412,7 +412,7 @@ Resources:
|
|
|
412
412
|
opacity: ${t=>t.success||t.fail?"1":"0"};
|
|
413
413
|
|
|
414
414
|
transition: ${t=>t.fail?"":"all 150ms ease-in-out"};
|
|
415
|
-
`;var Je=require("react"),Pe=v(require("styled-components"));var xo=require("react/jsx-runtime"),Bt=({style:t,...e})=>(0,xo.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 20 20",strokeWidth:1.5,stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:(0,xo.jsx)("path",{d:"M2.5 4.16667C2.5 3.72464 2.67559 3.30072 2.98816 2.98816C3.30072 2.67559 3.72464 2.5 4.16667 2.5H6.9C7.07483 2.50013 7.24519 2.55525 7.38696 2.65754C7.52874 2.75984 7.63475 2.90413 7.69 3.07L8.93833 6.81417C9.00158 7.00445 8.9941 7.21116 8.91726 7.39637C8.84042 7.58158 8.69938 7.73288 8.52 7.8225L6.63917 8.76417C7.5611 10.8046 9.19538 12.4389 11.2358 13.3608L12.1775 11.48C12.2671 11.3006 12.4184 11.1596 12.6036 11.0827C12.7888 11.0059 12.9956 10.9984 13.1858 11.0617L16.93 12.31C17.096 12.3653 17.2404 12.4714 17.3427 12.6134C17.445 12.7553 17.5 12.9259 17.5 13.1008V15.8333C17.5 16.2754 17.3244 16.6993 17.0118 17.0118C16.6993 17.3244 16.2754 17.5 15.8333 17.5H15C8.09667 17.5 2.5 11.9033 2.5 5V4.16667Z",strokeLinecap:"round",strokeLinejoin:"round"})});var D=require("react/jsx-runtime"),Ht=t=>{let[e,o]=(0,Je.useState)(""),[r,i]=(0,Je.useState)(!1),[n,a]=(0,Je.useState)(null),{authenticated:
|
|
415
|
+
`;var Je=require("react"),Pe=v(require("styled-components"));var xo=require("react/jsx-runtime"),Bt=({style:t,...e})=>(0,xo.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 20 20",strokeWidth:1.5,stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:(0,xo.jsx)("path",{d:"M2.5 4.16667C2.5 3.72464 2.67559 3.30072 2.98816 2.98816C3.30072 2.67559 3.72464 2.5 4.16667 2.5H6.9C7.07483 2.50013 7.24519 2.55525 7.38696 2.65754C7.52874 2.75984 7.63475 2.90413 7.69 3.07L8.93833 6.81417C9.00158 7.00445 8.9941 7.21116 8.91726 7.39637C8.84042 7.58158 8.69938 7.73288 8.52 7.8225L6.63917 8.76417C7.5611 10.8046 9.19538 12.4389 11.2358 13.3608L12.1775 11.48C12.2671 11.3006 12.4184 11.1596 12.6036 11.0827C12.7888 11.0059 12.9956 10.9984 13.1858 11.0617L16.93 12.31C17.096 12.3653 17.2404 12.4714 17.3427 12.6134C17.445 12.7553 17.5 12.9259 17.5 13.1008V15.8333C17.5 16.2754 17.3244 16.6993 17.0118 17.0118C16.6993 17.3244 16.2754 17.5 15.8333 17.5H15C8.09667 17.5 2.5 11.9033 2.5 5V4.16667Z",strokeLinecap:"round",strokeLinejoin:"round"})});var D=require("react/jsx-runtime"),Ht=t=>{let[e,o]=(0,Je.useState)(""),[r,i]=(0,Je.useState)(!1),[n,a]=(0,Je.useState)(null),{authenticated:p}=N(),{initLoginWithSms:f}=W(),{navigate:m,options:R}=y(),_=R.wallet;(0,Je.useEffect)(()=>{let c=document.querySelector("#phone-number-input");c==null||c.focus()},[]);let T=Nr(e),C=()=>{i(!0),f(e).then(()=>{m("AWAITING_PASSWORDLESS_CODE")}).catch(c=>{let L=(c==null?void 0:c.status)===401&&(c==null?void 0:c.message)==="User is not allowed to login to this app.";(c==null?void 0:c.status)===422?a(c.message):L?m("ALLOWLIST_REJECTION_SCREEN"):a("Issue submitting phone number"),i(!1)})};return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(fn,{stacked:t.stacked,children:[(0,D.jsxs)(yn,{standalone:t.stacked,children:[(0,D.jsx)(Bt,{}),(0,D.jsx)("input",{id:"phone-number-input",type:"tel",placeholder:"555 555 5555",onChange:c=>{o(c.target.value)},onKeyUp:c=>{c.key==="Enter"&&C()},value:e,autoComplete:"tel"})]}),t.stacked?null:(0,D.jsx)(gn,{disabled:r||!T,onClick:C,children:r?(0,D.jsx)(Ur,{color:"var(--disabled-fg)"}):"Submit"})]}),n||p||!_?(0,D.jsx)(vn,{fail:!!n,children:n||""}):null,!n&&!p&&_?(0,D.jsx)(Cn,{children:(0,D.jsx)("span",{children:"Don\u2019t have a wallet? Start exploring with your phone or socials."})}):null,t.stacked?(0,D.jsx)(wn,{disabled:r||!T,onClick:C,children:r?(0,D.jsx)(Ur,{color:"var(--disabled-fg)"}):"Submit"}):null]})},fn=Pe.default.div`
|
|
416
416
|
display: flex;
|
|
417
417
|
border: 1px solid var(--border-color-1);
|
|
418
418
|
width: 100%;
|
|
@@ -537,7 +537,7 @@ Resources:
|
|
|
537
537
|
width: 1rem;
|
|
538
538
|
border-width: 2px;
|
|
539
539
|
}
|
|
540
|
-
`;var Lo=require("react/jsx-runtime"),Fr=()=>{let{app:t}=y();return t!=null&&t.logoUrl?(0,Lo.jsx)("div",{children:(0,Lo.jsx)("img",{src:t.logoUrl,alt:`${t==null?void 0:t.name} logo`,style:{objectFit:"contain",width:"200px",height:"80px"}})}):null};var Ao=require("react-device-detect"),h=require("react/jsx-runtime");var Gr=()=>{let{ready:t}=N(),{getAuthMeta:e,isLinking:o}=W(),{app:r,navigate:i,options:n}=y(),a=n.email,
|
|
540
|
+
`;var Lo=require("react/jsx-runtime"),Fr=()=>{let{app:t}=y();return t!=null&&t.logoUrl?(0,Lo.jsx)("div",{children:(0,Lo.jsx)("img",{src:t.logoUrl,alt:`${t==null?void 0:t.name} logo`,style:{objectFit:"contain",width:"200px",height:"80px"}})}):null};var Ao=require("react-device-detect"),h=require("react/jsx-runtime");var Gr=()=>{let{ready:t}=N(),{getAuthMeta:e,isLinking:o}=W(),{app:r,navigate:i,options:n}=y(),a=n.email,p=n.sms,f=n.wallet,m=n.google,R=n.twitter,_=n.discord,T=n.github,C=f&&(r==null?void 0:r.showWalletLoginFirst)?0:1,[c,L]=(0,zt.useState)(C),b=e(),X=(b==null?void 0:b.authorizationCode)&&(b==null?void 0:b.stateCode)&&(b==null?void 0:b.provider);(0,zt.useEffect)(()=>{X?i("AWAITING_OAUTH_SCREEN"):o&&a?i("LINK_EMAIL_SCREEN"):o&&p?i("LINK_PHONE_SCREEN"):o&&f&&i("LINK_WALLET_SCREEN")},[t]);let We=c==0,G=c==1,Z=()=>(0,h.jsx)(h.Fragment,{children:f&&(0,h.jsx)(bn,{active:We,onClick:()=>L(0)})}),P=()=>(0,h.jsx)(h.Fragment,{children:(a||p)&&(0,h.jsx)(xn,{active:G,onClick:()=>L(1),email:a,sms:p,google:m,twitter:R,discord:_,github:T})});return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(E,{},"header"),(0,h.jsx)(En,{walletOnly:!a&&!p&&!m&&!R&&!_&&!T,hasTerms:!!((r==null?void 0:r.privacyPolicyUrl)||(r==null?void 0:r.termsAndConditionsUrl)),children:(0,h.jsx)(Fr,{})}),(0,h.jsx)(Ee,{children:r!=null&&r.showWalletLoginFirst?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Z,{}),(0,h.jsx)(P,{})]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(P,{}),(0,h.jsx)(Z,{})]})}),r&&(0,h.jsx)(Pr,{app:r}),(0,h.jsx)(ce,{protectedByPrivy:!0})]})};function bn(t){return(0,h.jsxs)(Br,{active:t.active,onClick:t.onClick,children:[(0,h.jsx)(Vr,{active:t.active,children:(0,h.jsx)("h4",{children:"Connect Wallet"})}),t.active&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(It,{}),(0,h.jsx)(Rt,{})]})]})}function xn(t){let e=t.google||t.discord||t.github||t.twitter&&!Ao.isMobile,o=t.email?"Email":"Phone";return(0,h.jsxs)(Br,{active:t.active,onClick:t.onClick,children:[(0,h.jsx)(Vr,{active:t.active,children:(0,h.jsx)("h4",{children:e?`${o} & Social`:o})}),t.active&&t.email&&(0,h.jsx)(Vt,{}),t.active&&t.sms&&!t.email&&(0,h.jsx)(Ht,{}),t.active&&e&&(0,h.jsx)(Ln,{google:t.google,twitter:t.twitter&&!Ao.isMobile,discord:t.discord,github:t.github})]})}function Ln(t){return(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(An,{children:[(0,h.jsx)(Dr,{}),(0,h.jsx)("p",{children:" Or "}),(0,h.jsx)(Dr,{})]}),(0,h.jsx)(Tr,{showGoogle:t.google,showDiscord:t.discord,showGithub:t.github,showTwitter:t.twitter})]})}var Vr=Ye.default.div`
|
|
541
541
|
font-weight: ${t=>t.active?600:500};
|
|
542
542
|
color: ${t=>t.active?"inherit":"var(--light-theme-fg-3)"};
|
|
543
543
|
display: flex;
|
|
@@ -631,7 +631,7 @@ Resources:
|
|
|
631
631
|
border-color: var(--light-theme-bg-3);
|
|
632
632
|
border-width: 1px;
|
|
633
633
|
}
|
|
634
|
-
`;var k=require("react/jsx-runtime"),Eo=6,jr=new Array(Eo).fill(""),Pn=1400;var Zr=()=>{var P,se,d;let{app:t}=y(),{closePrivyModal:e,resendEmailCode:o,resendSmsCode:r,getAuthMeta:i,loginWithCode:n}=W(),{authenticated:a,user:
|
|
634
|
+
`;var k=require("react/jsx-runtime"),Eo=6,jr=new Array(Eo).fill(""),Pn=1400;var Zr=()=>{var P,se,d;let{app:t}=y(),{closePrivyModal:e,resendEmailCode:o,resendSmsCode:r,getAuthMeta:i,loginWithCode:n}=W(),{authenticated:a,user:p}=N(),[f,m]=(0,Se.useState)(jr),[R,_]=(0,Se.useState)(!1),[T,C]=(0,Se.useState)(null),[c,L]=(0,Se.useState)(null),b=(P=i())!=null&&P.email?0:1;(0,Se.useEffect)(()=>{if(a&&R){let l=setTimeout(e,Ve);return()=>clearTimeout(l)}},[a,R,p]),(0,Se.useEffect)(()=>{if(T&&c===0){let l=setTimeout(()=>{m(jr),C(null);let A=document.querySelector("input[name=code-0]");A==null||A.focus()},Pn);return()=>clearTimeout(l)}},[T]);let X=l=>{var No;let A=l.currentTarget.value.replace(" ","");if(A==="")return;if(isNaN(Number(A))){C("Code should be numeric"),L(1);return}C(null),L(null);let z=Number((No=l.currentTarget.name)==null?void 0:No.charAt(5)),Jt=[...A||[""]].slice(0,Eo-z),Yt=[...f.slice(0,z),...Jt,...f.slice(z+Jt.length)];m(Yt);let Ri=Jt.length,Mo=Math.min(Math.max(z+Ri,0),Eo-1);if(!isNaN(Number(l.currentTarget.value))){let ae=document.querySelector(`input[name=code-${Mo}]`);ae==null||ae.focus()}if(Yt.every(ae=>ae&&!isNaN(+ae))){let ae=document.querySelector(`input[name=code-${Mo}]`);ae==null||ae.blur(),n(Yt.join("")).then(()=>_(!0)).catch(Qt=>{(Qt==null?void 0:Qt.status)===422?C("Invalid or expired verification code"):C("Issue verifying code"),L(0)})}l.preventDefault()},We=l=>{c===1&&(C(null),L(null));let A=[...f.slice(0,l),"",...f.slice(l+1)];if(m(A),l>0){let z=document.querySelector(`input[name=code-${l-1}]`);z==null||z.focus()}},G=`Verify your ${b==0?"email":"phone"}`,Z=b==0?`Please check ${(se=i())==null?void 0:se.email} for an email from privy.io and enter your code below.`:`Please check ${(d=i())==null?void 0:d.phoneNumber} for a message from ${(t==null?void 0:t.name)||"privy.io"} and enter your code below.`;return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(E,{},"header"),(0,k.jsxs)(Sn,{children:[(0,k.jsx)(Ue,{title:G,description:Z}),(0,k.jsxs)(Sr,{children:[(0,k.jsxs)(Tn,{children:[(0,k.jsx)(Wn,{fail:!!T,success:R,children:(0,k.jsx)("span",{children:T||(R?"Success!":"")})}),(0,k.jsx)("div",{children:f.map((l,A)=>(0,k.jsx)("input",{name:`code-${A}`,type:"text",value:f[A],onChange:X,onKeyUp:z=>{z.key==="Backspace"&&We(A)},inputMode:"numeric",autoFocus:A===0,pattern:"[0-9]",className:`${R?"success":""} ${T?"fail":""}`,autoComplete:"one-time-code"},A))})]}),(0,k.jsx)(In,{children:b==0?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)("span",{children:"Didn't get an email?"}),(0,k.jsx)("button",{onClick:o,children:"Resend Code"})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)("span",{children:"Didn't get a message?"}),(0,k.jsx)("button",{onClick:r,children:"Resend Code"})]})})]})]}),(0,k.jsx)(ce,{protectedByPrivy:!0})]})},Sn=lt.default.div`
|
|
635
635
|
display: flex;
|
|
636
636
|
flex-direction: column;
|
|
637
637
|
align-items: flex-start;
|
|
@@ -795,7 +795,7 @@ Resources:
|
|
|
795
795
|
background-color: var(--primary-color-bg-2);
|
|
796
796
|
}
|
|
797
797
|
}
|
|
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
|
|
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 p=t==null?void 0:t[a];p&&p[n]&&(p[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,p=i||4,f=o,m=t/2-a/2-p;return(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)("rect",{x:Qr(m,e),y:Qr(m,e),width:a+p*2+(m%e?e+.5:.5),height:a+p*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`
|
|
799
799
|
display: flex;
|
|
800
800
|
justify-content: center;
|
|
801
801
|
align-items: center;
|
|
@@ -995,7 +995,7 @@ Resources:
|
|
|
995
995
|
`,qn=Y.default.div`
|
|
996
996
|
display: flex;
|
|
997
997
|
justify-content: center;
|
|
998
|
-
`;var Ce=require("react");var pt=v(require("styled-components"));var B=require("react/jsx-runtime"),Io=2,fi={metamask:{name:"MetaMask",component:Me},coinbase_wallet:{name:"Coinbase Wallet",component:Ae},wallet_connect:{name:"WalletConnect",component:Tt}},gi=()=>{let[t,e]=(0,Ce.useState)(!1),[o,r]=(0,Ce.useState)("metamask"),[i,n]=(0,Ce.useState)(void 0),{navigate:a,navigateBack:
|
|
998
|
+
`;var Ce=require("react");var pt=v(require("styled-components"));var B=require("react/jsx-runtime"),Io=2,fi={metamask:{name:"MetaMask",component:Me},coinbase_wallet:{name:"Coinbase Wallet",component:Ae},wallet_connect:{name:"WalletConnect",component:Tt}},gi=()=>{let[t,e]=(0,Ce.useState)(!1),[o,r]=(0,Ce.useState)("metamask"),[i,n]=(0,Ce.useState)(void 0),{navigate:a,navigateBack:p}=y(),{getAuthMeta:f,closePrivyModal:m,loginWithWallet:R}=W(),[_,T]=(0,Ce.useState)(0),{user:C}=N(),[c,L]=(0,Ce.useState)((C==null?void 0:C.linkedAccounts.length)||0);(0,Ce.useEffect)(()=>{var Z;r(((Z=f())==null?void 0:Z.walletType)||"metamask"),n(void 0),R().then(()=>e(!0)).catch(P=>{P instanceof ee?console.error(P.cause):console.error(P);let se=(P==null?void 0:P.status)===401&&(P==null?void 0:P.message)==="User is not allowed to login to this app.";(P==null?void 0:P.status)===422?n(vt.ERROR_USER_EXISTS):se?a("ALLOWLIST_REJECTION_SCREEN"):P instanceof ze&&!P.details.default?n(P.details):P instanceof He?n(vt.ERROR_TIMED_OUT):n(vt.ERROR_WALLET_CONNECTION)})},[_]),(0,Ce.useEffect)(()=>{if(t){let Z=setTimeout(m,Ve);return()=>clearTimeout(Z)}},[C]);let b=fi[o].name,X=fi[o].component,We=t?`Successfully connected with ${b}`:i?i.message:`Waiting for ${b}`,G="";if(t){let Z=(C==null?void 0:C.linkedAccounts.length)||0;c===Z?G="Wallet was already linked.":G="You\u2019re good to go!"}else if(_>=Io&&i)G="Unable to connect wallet";else if(i)G=i.detail;else switch(G="Don\u2019t see your wallet modal? Check your other browser windows.",o){case"wallet_connect":G="Open your mobile wallet app to continue";break;case"coinbase_wallet":Et()||(G="Open the Coinbase app on your phone to continue.");break;default:G="Don\u2019t see your wallet modal? Check your other browser windows."}return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(E,{backFn:p}),(0,B.jsxs)(Jn,{children:[(0,B.jsx)(Qn,{children:(0,B.jsxs)("div",{children:[(0,B.jsx)(Dt,{success:t,fail:!!i}),(0,B.jsx)(X,{style:{width:"38px",height:"38px"}})]})}),(0,B.jsxs)(Yn,{children:[(0,B.jsx)("h3",{children:We}),(0,B.jsx)("p",{children:G})]}),(0,B.jsx)(Xn,{onClick:()=>{T(_+1),n(void 0)},visible:!t&&(i==null?void 0:i.retryable)&&_<Io,disabled:!t&&(!(i!=null&&i.retryable)||_>=Io),children:"Retry"})]})]})},Jn=pt.default.div`
|
|
999
999
|
display: flex;
|
|
1000
1000
|
flex-direction: column;
|
|
1001
1001
|
align-items: center;
|
|
@@ -1354,7 +1354,7 @@ Resources:
|
|
|
1354
1354
|
display: none;
|
|
1355
1355
|
}
|
|
1356
1356
|
}
|
|
1357
|
-
`;var Pi=require("react");var Xe=require("react");var ut=v(require("styled-components"));var H=require("react/jsx-runtime"),xi={google:{name:"Google",component:Ut},discord:{name:"Discord",component:Nt},github:{name:"Github",component:Ot},twitter:{name:"Twitter",component:Mt}},ts=t=>t.charAt(0).toUpperCase()+t.slice(1),Ro=()=>{let t=new URL(window.location.href);t.searchParams.delete("privy_oauth_code"),t.searchParams.delete("privy_oauth_provider"),t.searchParams.delete("privy_oauth_state"),window.history.pushState({},"",t)},Li=()=>{var c;let[t,e]=(0,Xe.useState)(!1),[o,r]=(0,Xe.useState)(void 0),{getAuthMeta:i,initLoginWithOAuth:n,loginWithOAuth:a,closePrivyModal:
|
|
1357
|
+
`;var Pi=require("react");var Xe=require("react");var ut=v(require("styled-components"));var H=require("react/jsx-runtime"),xi={google:{name:"Google",component:Ut},discord:{name:"Discord",component:Nt},github:{name:"Github",component:Ot},twitter:{name:"Twitter",component:Mt}},ts=t=>t.charAt(0).toUpperCase()+t.slice(1),Ro=()=>{let t=new URL(window.location.href);t.searchParams.delete("privy_oauth_code"),t.searchParams.delete("privy_oauth_provider"),t.searchParams.delete("privy_oauth_state"),window.history.pushState({},"",t)},Li=()=>{var c;let[t,e]=(0,Xe.useState)(!1),[o,r]=(0,Xe.useState)(void 0),{getAuthMeta:i,initLoginWithOAuth:n,loginWithOAuth:a,closePrivyModal:p}=W(),{ready:f}=N(),m=((c=i())==null?void 0:c.provider)||"google",R=xi[m].name,_=xi[m].component;(0,Xe.useEffect)(()=>{!f||a().then(()=>{Ro(),e(!0)}).catch(L=>{let b={retryable:!1,message:"Authentication failed."};L.message.includes("Another user has already linked this")?b.detail="This account has already been linked to another user.":L.message==="Invalid code during oauth flow."?(b.retryable=!0,b.detail="Something went wrong. Try again."):L.message==="User denied confirmation during OAuth flow"&&(b.detail=`Retry and check ${ts(m)} to finish connecting your account.`,b.retryable=!0),Ro(),r(b)})},[f]),(0,Xe.useEffect)(()=>{if(!t)return;let L=setTimeout(p,Ve);return()=>clearTimeout(L)},[t]);let T=t?`Successfully connected with ${R}`:o?o.message:`Verifying connection to ${R}`,C="";return t?C="You\u2019re good to go!":o?C=o.detail:C="Just a few moments more",(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(E,{}),(0,H.jsxs)(os,{children:[(0,H.jsx)(is,{children:(0,H.jsxs)("div",{children:[(0,H.jsx)(Dt,{success:t,fail:!!o}),(0,H.jsx)(_,{style:{width:"38px",height:"38px"},logoFill:"primary"})]})}),(0,H.jsxs)(rs,{children:[(0,H.jsx)("h3",{children:T}),(0,H.jsx)("p",{children:C})]}),(0,H.jsx)(ns,{onClick:()=>{Ro(),n(m),r(void 0)},visible:!t&&(o==null?void 0:o.retryable),disabled:!t&&!(o!=null&&o.retryable),children:"Retry"})]})]})},os=ut.default.div`
|
|
1358
1358
|
display: flex;
|
|
1359
1359
|
flex-direction: column;
|
|
1360
1360
|
align-items: center;
|
|
@@ -1460,4 +1460,4 @@ Resources:
|
|
|
1460
1460
|
align-items: center;
|
|
1461
1461
|
justify-content: center;
|
|
1462
1462
|
height: 100%;
|
|
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=V.get(Be);return Promise.resolve(t||null)}return ht.getAccessToken()}var Ii=t=>{if(!cs(t.appId))throw new
|
|
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=V.get(Be);return Promise.resolve(t||null)}return ht.getAccessToken()}var Ii=t=>{if(!cs(t.appId))throw new u("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,p]=(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();p(!!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"),z=d.get("privy_oauth_provider");l&&A&&z&&(e.startAuthFlow(new $e(z,l,A)),L(z),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),p(!1),L(null),X(!1),r(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>e.connectors.getEthereumProvider(),getEthersProvider:()=>new Ti.Web3Provider(new xe(e.connectors.getEthereumProvider())),getWeb3jsProvider:()=>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 u("Connector not initialized");d||(d="metamask"),e.startAuthFlow(new ot(e.connectors,d))},loginWithWallet:async()=>{if(!(e.authFlow instanceof ot))throw new u("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),p(!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 u("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),p(!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 u("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),p(!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,WalletConnector,getAccessToken,usePrivy});
|