@privy-io/react-auth 1.10.0 → 1.10.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/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var c5=Object.create;var l2=Object.defineProperty;var p5=Object.getOwnPropertyDescriptor;var h5=Object.getOwnPropertyNames;var f5=Object.getPrototypeOf,u5=Object.prototype.hasOwnProperty;var m5=(i,e)=>{for(var o in e)l2(i,o,{get:e[o],enumerable:!0})},L4=(i,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of h5(e))!u5.call(i,r)&&r!==o&&l2(i,r,{get:()=>e[r],enumerable:!(a=p5(e,r))||a.enumerable});return i};var y=(i,e,o)=>(o=i!=null?c5(f5(i)):{},L4(e||!i||!i.__esModule?l2(o,"default",{value:i,enumerable:!0}):o,i)),b5=i=>L4(l2({},"__esModule",{value:!0}),i);var I6={};m5(I6,{PrivyProvider:()=>C5,VERSION:()=>C2,getAccessToken:()=>s5,usePrivy:()=>R});module.exports=b5(I6);var G=require("react");var p2=y(require("axios"));var A4=y(require("axios")),q=class extends Error{constructor(o,a){super(o);a instanceof Error&&(this.cause=a)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},n2=class extends q{constructor(o,a,r,n){super(r,n);this.type=o;this.status=a}},d=class extends q{constructor(o,a){super(o,a);this.type="client_error"}};var B=class extends q{constructor(o,a){super(o,a);this.type="connector_error"}},P=i=>{if(i instanceof q)return i;if(!A4.default.isAxiosError(i))return j(i);if(!i.response)return new n2("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new n2(e||"ApiError",i.response.status,o||a,i)},j=i=>i instanceof q?i:i instanceof Error?new d(i.message,i):new d(`Internal error: ${i}`);var E4="1.10.0";var _4="https://api.privy.io/v0",P4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",s2="4df5e2316331463a9130964bd6078dfa",S4=1e4,I1=1200,T4=365*24*60*60,C2=E4,I4="ES256",R4="privy.io",R1="privy:token",d2="privy:refresh_token",e1="privy:active_wallet",c2="privy:wallet_type",W4="walletconnect";var h2=class{constructor(e,o,a){this.appId=e,this.sdkVersion=C2,this.session=o,this.defaults=a}async get(e,o){try{return await p2.default.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw P(a)}}async post(e,o,a){try{return await p2.default.post(e,o,this.buildConfig(a))}catch(r){throw P(r)}}async delete(e,o){try{return await p2.default.delete(e,this.buildConfig(o))}catch(a){throw P(a)}}buildConfig(e){return e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-client"]=`react-auth:${this.sdkVersion}`,this.session.token!==null&&(e.headers.authorization=`Bearer ${this.session.token}`),{...this.defaults,...e}}};var W1=y(require("jose"));var f1=class{static parse(e){try{return new f1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=W1.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(),a=(this.expiration-e)*1e3;return o>=a}async isValid(e,o,a=0){let r=await W1.importSPKI(e,I4);try{return await W1.jwtVerify(this.value,r,{issuer:R4,audience:o,clockTolerance:a}),!0}catch{return!1}}};var u1=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 $2=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]}},K2=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}};function g5(){return typeof window<"u"&&window.localStorage?new K2:new $2}var Z=g5();function v1(i){return new Date(i*1e3)}function w5(i){return i.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:v1(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:v1(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:v1(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:v1(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:v1(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:v1(e.verified_at)};default:throw new d("Unrecognized account type")}})}function M5(i,e){return e.find(o=>o.type==="wallet"&&o.address===i)}function x1(i,e){return i.sort((o,a)=>a.verifiedAt.getTime()-o.verifiedAt.getTime()),i.find(o=>o.type===e)}function q1(i){let e=i.linkedAccounts.map(C=>C.type==="wallet"?C.address:null),a=Z.get(e1);if(!a||!e.includes(a)){Z.del(e1);let C=x1(i.linkedAccounts,"wallet");C&&(a=C.address,Z.put(e1,a))}let r=M5(a,i.linkedAccounts),n=Object.assign({},i);return n.wallet=r&&{address:r.address,chainType:r.chainType,chainId:r.chainId,walletType:r.walletType},n}function n1(i){if(!i)return null;let e=w5(i.linked_accounts),o=x1(e,"wallet"),a=x1(e,"email"),r=x1(e,"phone"),n=x1(e,"google_oauth"),C=x1(e,"twitter_oauth"),u=x1(e,"discord_oauth"),f={id:i.id,createdAt:v1(i.created_at),linkedAccounts:e,email:a&&{address:a==null?void 0:a.address},phone:r&&{number:r==null?void 0:r.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:C&&{subject:C.subject,username:C.username,name:C.name},discord:u&&{subject:u.subject,username:u.username,email:u.email}};return q1(f)}var O4=()=>"/api/v1/sessions",N4=()=>"/api/v1/sessions/logout",U4=()=>"/api/v1/sessions/fork",D4=()=>"/api/v1/siwe/init",F4=()=>"/api/v1/siwe/authenticate",V4=()=>"/api/v1/siwe/link",H4=()=>"/api/v1/passwordless/init",G4=()=>"/api/v1/passwordless/authenticate",B4=()=>"/api/v1/passwordless/link",j4=()=>"/api/v1/passwordless_sms/init",z4=()=>"/api/v1/passwordless_sms/authenticate",$4=()=>"/api/v1/passwordless_sms/link",K4=()=>"/api/v1/oauth/init",q4=()=>"/api/v1/oauth/authenticate",Y4=()=>"/api/v1/oauth/link",J4=()=>"/api/v1/siwe/unlink",X4=()=>"/api/v1/passwordless/unlink",Q4=()=>"/api/v1/passwordless_sms/unlink",t3=()=>"/api/v1/oauth/unlink";var y5=30,f2=class{constructor(){this.authenticateOnce=new u1(async e=>this._authenticate(e)),this.linkOnce=new u1(async e=>this._link(e)),this.refreshOnce=new u1(this._refresh.bind(this)),this.destroyOnce=new u1(this._destroy.bind(this)),this.forkSessionOnce=new u1(this._forkSession.bind(this))}get token(){try{let e=Z.get(R1);return typeof e=="string"?new f1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=Z.get(d2);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=f1.parse(this.token);return e!==null&&!e.isExpired(y5)}async hasValidToken(e,o,a=0){let r=f1.parse(this.token);return r!==null&&await r.isValid(e,o,a)}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:a,user:r}=await e.authenticate();return this.storeToken(o),this.storeRefreshToken(a),n1(r)}catch(o){throw console.warn("Error authenticating session"),j(o)}}async _link(e){try{let o=await e.link();return n1(o)}catch(o){throw console.warn("Error linking account"),j(o)}}async _refresh(){if(!this.api)throw new d("Session has no API instance");let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let a=await this.api.post(O4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),n1(a.data.user)}catch(a){throw j(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(N4(),{refresh_token:this.refreshToken}))}catch{console.warn("Error destroying session")}this.destroyLocalState()}async _forkSession(){if(!this.api)throw new d("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(U4(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw j(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null),Z.del(e1)}storeToken(e){typeof e=="string"?Z.put(R1,e):Z.del(R1)}storeRefreshToken(e){typeof e=="string"?Z.put(d2,e):Z.del(d2)}};var o3=require("@ethersproject/address"),J2=y(require("@walletconnect/web3-provider"));var e3=require("@ethersproject/logger");var O1=class extends B{constructor(){super("Wallet timeout");this.type="wallet_error"}},u2=i=>{if(i instanceof B)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new N1(i);return i.code===e3.ErrorCode.ACTION_REJECTED&&(e.details=Z1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new N1(i):new B("Unknown connector error",i)},q2=class extends q{constructor(o,a,r){super(o);this.type="provider_error";this.code=a,this.data=r}},N1=class extends q2{constructor(o){var n,C,u;let a=o;super(a.message,a.code,a.data);let r=Object.values(Z1).find(f=>f.eipCode===a.code);this.details=r||Z1.UNKNOWN_ERROR,a.code===-32002&&((n=a.message)!=null&&n.includes("already pending for origin")?(C=a.message)!=null&&C.includes("wallet_requestPermissions")?this.details=Z1.E32002_CONNECTION_ALREADY_PENDING:this.details=Z1.E32002_REQUEST_ALREADY_PENDING:(u=a.message)!=null&&u.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=Z1.E32002_WALLET_LOCKED))}},v5={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}},x5={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}},Z5={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}},Z1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...Z5,...x5},m2={...v5,...Z1};var L5=12e4,Y2=(i=new O1,e=L5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),U1=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 a;(a=this.walletProvider)==null||a.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 B(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),Y2()]).catch(o=>{throw u2(o)})}},D1=class extends U1{constructor(o){super(o)}},b2=class extends U1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var a3=require("@ethersproject/providers");var i3=["metamask","coinbase_wallet","wallet_connect"];var r3=y(require("@coinbase/wallet-sdk")),A5=()=>{let i=`https://mainnet.infura.io/v3/${s2}`,e=1;return new r3.default({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},X2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isMetaMask)return!0}return!1},g2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isCoinbaseWallet)return!0}return!1},k2=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,r,n,C,u)=>`${a} wants you to sign in with your Ethereum account:
1
+ "use strict";var c5=Object.create;var l2=Object.defineProperty;var p5=Object.getOwnPropertyDescriptor;var h5=Object.getOwnPropertyNames;var f5=Object.getPrototypeOf,u5=Object.prototype.hasOwnProperty;var m5=(i,e)=>{for(var o in e)l2(i,o,{get:e[o],enumerable:!0})},L4=(i,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of h5(e))!u5.call(i,r)&&r!==o&&l2(i,r,{get:()=>e[r],enumerable:!(a=p5(e,r))||a.enumerable});return i};var y=(i,e,o)=>(o=i!=null?c5(f5(i)):{},L4(e||!i||!i.__esModule?l2(o,"default",{value:i,enumerable:!0}):o,i)),b5=i=>L4(l2({},"__esModule",{value:!0}),i);var I6={};m5(I6,{PrivyProvider:()=>C5,VERSION:()=>C2,getAccessToken:()=>s5,usePrivy:()=>R});module.exports=b5(I6);var G=require("react");var p2=y(require("axios"));var A4=y(require("axios")),q=class extends Error{constructor(o,a){super(o);a instanceof Error&&(this.cause=a)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},n2=class extends q{constructor(o,a,r,n){super(r,n);this.type=o;this.status=a}},d=class extends q{constructor(o,a){super(o,a);this.type="client_error"}};var B=class extends q{constructor(o,a){super(o,a);this.type="connector_error"}},P=i=>{if(i instanceof q)return i;if(!A4.default.isAxiosError(i))return j(i);if(!i.response)return new n2("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new n2(e||"ApiError",i.response.status,o||a,i)},j=i=>i instanceof q?i:i instanceof Error?new d(i.message,i):new d(`Internal error: ${i}`);var E4="1.10.1";var _4="https://api.privy.io/v0",P4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",s2="4df5e2316331463a9130964bd6078dfa",S4=1e4,I1=1200,T4=365*24*60*60,C2=E4,I4="ES256",R4="privy.io",R1="privy:token",d2="privy:refresh_token",e1="privy:active_wallet",c2="privy:wallet_type",W4="walletconnect";var h2=class{constructor(e,o,a){this.appId=e,this.sdkVersion=C2,this.session=o,this.defaults=a}async get(e,o){try{return await p2.default.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw P(a)}}async post(e,o,a){try{return await p2.default.post(e,o,this.buildConfig(a))}catch(r){throw P(r)}}async delete(e,o){try{return await p2.default.delete(e,this.buildConfig(o))}catch(a){throw P(a)}}buildConfig(e){return e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-client"]=`react-auth:${this.sdkVersion}`,this.session.token!==null&&(e.headers.authorization=`Bearer ${this.session.token}`),{...this.defaults,...e}}};var W1=y(require("jose"));var f1=class{static parse(e){try{return new f1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=W1.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(),a=(this.expiration-e)*1e3;return o>=a}async isValid(e,o,a=0){let r=await W1.importSPKI(e,I4);try{return await W1.jwtVerify(this.value,r,{issuer:R4,audience:o,clockTolerance:a}),!0}catch{return!1}}};var u1=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 $2=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]}},K2=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}};function g5(){return typeof window<"u"&&window.localStorage?new K2:new $2}var Z=g5();function v1(i){return new Date(i*1e3)}function w5(i){return i.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:v1(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:v1(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:v1(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:v1(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:v1(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:v1(e.verified_at)};default:throw new d("Unrecognized account type")}})}function M5(i,e){return e.find(o=>o.type==="wallet"&&o.address===i)}function x1(i,e){return i.sort((o,a)=>a.verifiedAt.getTime()-o.verifiedAt.getTime()),i.find(o=>o.type===e)}function q1(i){let e=i.linkedAccounts.map(C=>C.type==="wallet"?C.address:null),a=Z.get(e1);if(!a||!e.includes(a)){Z.del(e1);let C=x1(i.linkedAccounts,"wallet");C&&(a=C.address,Z.put(e1,a))}let r=M5(a,i.linkedAccounts),n=Object.assign({},i);return n.wallet=r&&{address:r.address,chainType:r.chainType,chainId:r.chainId,walletType:r.walletType},n}function n1(i){if(!i)return null;let e=w5(i.linked_accounts),o=x1(e,"wallet"),a=x1(e,"email"),r=x1(e,"phone"),n=x1(e,"google_oauth"),C=x1(e,"twitter_oauth"),u=x1(e,"discord_oauth"),f={id:i.id,createdAt:v1(i.created_at),linkedAccounts:e,email:a&&{address:a==null?void 0:a.address},phone:r&&{number:r==null?void 0:r.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:C&&{subject:C.subject,username:C.username,name:C.name},discord:u&&{subject:u.subject,username:u.username,email:u.email}};return q1(f)}var O4=()=>"/api/v1/sessions",N4=()=>"/api/v1/sessions/logout",U4=()=>"/api/v1/sessions/fork",D4=()=>"/api/v1/siwe/init",F4=()=>"/api/v1/siwe/authenticate",V4=()=>"/api/v1/siwe/link",H4=()=>"/api/v1/passwordless/init",G4=()=>"/api/v1/passwordless/authenticate",B4=()=>"/api/v1/passwordless/link",j4=()=>"/api/v1/passwordless_sms/init",z4=()=>"/api/v1/passwordless_sms/authenticate",$4=()=>"/api/v1/passwordless_sms/link",K4=()=>"/api/v1/oauth/init",q4=()=>"/api/v1/oauth/authenticate",Y4=()=>"/api/v1/oauth/link",J4=()=>"/api/v1/siwe/unlink",X4=()=>"/api/v1/passwordless/unlink",Q4=()=>"/api/v1/passwordless_sms/unlink",t3=()=>"/api/v1/oauth/unlink";var y5=30,f2=class{constructor(){this.authenticateOnce=new u1(async e=>this._authenticate(e)),this.linkOnce=new u1(async e=>this._link(e)),this.refreshOnce=new u1(this._refresh.bind(this)),this.destroyOnce=new u1(this._destroy.bind(this)),this.forkSessionOnce=new u1(this._forkSession.bind(this))}get token(){try{let e=Z.get(R1);return typeof e=="string"?new f1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=Z.get(d2);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=f1.parse(this.token);return e!==null&&!e.isExpired(y5)}async hasValidToken(e,o,a=0){let r=f1.parse(this.token);return r!==null&&await r.isValid(e,o,a)}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:a,user:r}=await e.authenticate();return this.storeToken(o),this.storeRefreshToken(a),n1(r)}catch(o){throw console.warn("Error authenticating session"),j(o)}}async _link(e){try{let o=await e.link();return n1(o)}catch(o){throw console.warn("Error linking account"),j(o)}}async _refresh(){if(!this.api)throw new d("Session has no API instance");let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let a=await this.api.post(O4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),n1(a.data.user)}catch(a){throw j(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(N4(),{refresh_token:this.refreshToken}))}catch{console.warn("Error destroying session")}this.destroyLocalState()}async _forkSession(){if(!this.api)throw new d("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(U4(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw j(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null),Z.del(e1)}storeToken(e){typeof e=="string"?Z.put(R1,e):Z.del(R1)}storeRefreshToken(e){typeof e=="string"?Z.put(d2,e):Z.del(d2)}};var o3=require("@ethersproject/address"),J2=y(require("@walletconnect/web3-provider"));var e3=require("@ethersproject/logger");var O1=class extends B{constructor(){super("Wallet timeout");this.type="wallet_error"}},u2=i=>{if(i instanceof B)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new N1(i);return i.code===e3.ErrorCode.ACTION_REJECTED&&(e.details=Z1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new N1(i):new B("Unknown connector error",i)},q2=class extends q{constructor(o,a,r){super(o);this.type="provider_error";this.code=a,this.data=r}},N1=class extends q2{constructor(o){var n,C,u;let a=o;super(a.message,a.code,a.data);let r=Object.values(Z1).find(f=>f.eipCode===a.code);this.details=r||Z1.UNKNOWN_ERROR,a.code===-32002&&((n=a.message)!=null&&n.includes("already pending for origin")?(C=a.message)!=null&&C.includes("wallet_requestPermissions")?this.details=Z1.E32002_CONNECTION_ALREADY_PENDING:this.details=Z1.E32002_REQUEST_ALREADY_PENDING:(u=a.message)!=null&&u.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=Z1.E32002_WALLET_LOCKED))}},v5={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}},x5={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}},Z5={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}},Z1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...Z5,...x5},m2={...v5,...Z1};var L5=12e4,Y2=(i=new O1,e=L5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),U1=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 a;(a=this.walletProvider)==null||a.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 B(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),Y2()]).catch(o=>{throw u2(o)})}},D1=class extends U1{constructor(o){super(o)}},b2=class extends U1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var a3=require("@ethersproject/providers");var i3=["metamask","coinbase_wallet","wallet_connect"];var r3=y(require("@coinbase/wallet-sdk")),A5=()=>{let i=`https://mainnet.infura.io/v3/${s2}`,e=1;return new r3.default({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},X2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isMetaMask)return!0}return!1},g2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isCoinbaseWallet)return!0}return!1},k2=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,r,n,C,u)=>`${a} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${u}
@@ -9,7 +9,7 @@ Chain ID: ${e}
9
9
  Nonce: ${C}
10
10
  Issued At: ${n}
11
11
  Resources:
12
- - https://privy.io`;this.ethProvider=new U1}initialize(){let e=Z.get(c2);i3.includes(e)&&(this.walletType=e,this.connect({showPrompt:!1}))}destroy(){this.walletType=null,Z.del(c2),Z.del(W4)}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.address(),a=await this.chainId();return{address:o,chainId:a,chainType:"ethereum",walletType:e}}async connect(e){var o;switch(this.walletType){case"metamask":this.ethProvider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async r=>{r.isMetaMask&&this.ethProvider.setProvider(r)});break;case"coinbase_wallet":this.ethProvider.setProvider(A5());break;case"wallet_connect":let a=new J2.default({infuraId:s2});this.ethProvider.setProvider(a);break;default:throw new B(`Unsupported wallet: ${this.walletType}`)}return(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(this.walletType),this.getConnectedWallet()}async isConnected(){switch(this.walletType){case"metamask":return await this.address()!==null;case"coinbase_wallet":return await this.address()!==null;case"wallet_connect":return this.ethProvider.walletProvider.connected;default:throw new B(`Unsupported wallet: ${this.walletType}`)}}async promptConnection(e){try{switch(e){case"metamask":await this.ethProvider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]}),await this.ethProvider.request({method:"eth_requestAccounts"});break;case"coinbase_wallet":await this.ethProvider.request({method:"eth_requestAccounts"});break;case"wallet_connect":let o=new J2.default({infuraId:s2});this.ethProvider.setProvider(o),await Promise.race([o.enable(),Y2()]);break;default:throw new B(`Unsupported wallet: ${this.walletType}`)}Z.put(c2,e)}catch(o){throw u2(o)}}async sign(e){return new a3.Web3Provider(new D1(this.getEthereumProvider())).getSigner().signMessage(e)}prepareMessage(e,o,a){let r=window.location.host,n=window.location.origin,C=`Welcome! Before continuing, ${r} needs to verify you own this wallet. Signing this message proves ownership. Please note that signing is NOT a transaction, there are NO fees, and this signature does NOT authorize any future transaction requests.`,u=new Date().toISOString();return this.createSiweMessage(e,o,r,n,u,a,C)}async chainId(){let e=await this.getEthereumProvider().request({method:"eth_chainId"}),o=Number(e);return String(o)}async address(){let e=await this.getEthereumProvider().request({method:"eth_accounts"});return Array.isArray(e)&&e.length>0?(0,o3.getAddress)(e[0]):null}};var Q2,w2=class{constructor(e){let o=e.apiURL||_4,a=e.timeout||S4;this.appId=e.appId,this.connector=new k2,this.connector.initialize(),Q2||(Q2=new f2),this.session=Q2,this.api=new h2(e.appId,this.session,{baseURL:o,timeout:a}),this.session.api=this.api}authenticate(){if(!this.authFlow)throw new d("No auth flow in progress.");return this.session.authenticate(this.authFlow)}link(){if(!this.authFlow)throw new d("No auth flow in progress.");return this.session.link(this.authFlow)}async logout(){await this.session.destroy(),this.connector.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post(X4(),{address:e});return n1(o.data)}catch(o){throw j(o)}}async unlinkPhone(e){try{let o=await this.api.post(Q4(),{phoneNumber:e});return n1(o.data)}catch(o){throw j(o)}}async unlinkWallet(e){try{let o=await this.api.post(J4(),{address:e});return n1(o.data)}catch(o){throw j(o)}}async unlinkOAuth(e,o){try{let a=await this.api.post(t3(),{provider:e,subject:o});return n1(a.data)}catch(a){throw j(a)}}async getAuthenticatedUser(){return this.session.hasRefreshCredentials()?this.session.refresh():null}async getAccessToken(){if(this.session.hasActiveToken()){let{verificationKey:e,id:o}=await this.getAppSettings();return await this.session.hasValidToken(e,o,T4)?this.session.token:(await this.logout(),null)}else return 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,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,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 j(e)}}setActiveWallet(e,o){if(!o.linkedAccounts.map(r=>r.type==="wallet"?r.address:null).includes(e))throw new d("Cannot set an unlinked address as active.");return Z.put(e1,e),q1(o)}async forkSession(){return await this.session.forkSession()}};var n5=require("@ethersproject/providers");var M2=require("react");var m=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var t4=(0,M2.createContext)({ready:!1,authenticated:!1,user:null,login:m,linkEmail:m,linkPhone:m,linkWallet:m,linkGoogle:m,linkTwitter:m,linkDiscord:m,logout:m,getAccessToken:m,getEthereumProvider:m,getEthersProvider:m,getWeb3jsProvider:m,unlinkEmail:m,unlinkPhone:m,unlinkWallet:m,unlinkGoogle:m,unlinkTwitter:m,unlinkDiscord:m,setActiveWallet:m,forkSession:m}),R=()=>(0,M2.useContext)(t4);var Y1=class{constructor(e){this.connector=e,this.meta={wallet:this.connector.walletType}}async authenticate(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.connector.walletType)throw new d("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),a=await this.api.post(F4(),{message:e,signature:o});return{user:a.data.user,token:a.data.token,refresh_token:a.data.refresh_token}}catch(e){throw P(e)}}async link(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.connector.walletType)throw new d("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api);return(await this.api.post(V4(),{message:e,signature:o})).data}catch(e){throw P(e)}}async promptConnectAndSign(e){let o=await this.connector.connect({showPrompt:!0}),a=o.address,r=o.chainId,n=await e.post(D4(),{address:a}),C=this.connector.prepareMessage(r,a,n.data.nonce),u=await this.connector.sign(C);return{message:C,signature:u}}getEthereumProvider(){return this.connector.getEthereumProvider()}};var J1=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new d("Email and email code must be set prior to calling authenticate.");try{let e=G4(),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}}catch(e){throw P(e)}}async link(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new d("Email and email code must be set prior to calling authenticate.");try{let e=B4();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw P(e)}}async sendCodeEmail(e){if(!this.api)throw new d("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new d("Email must be set when initialzing authentication.");try{let o=H4();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw P(o)}}};var X1=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new d("phone number and sms code must be set prior to calling authenticate.");try{let e=z4(),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}}catch(e){throw P(e)}}async link(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new d("phone number and sms code must be set prior to calling authenticate.");try{let e=$4();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw P(e)}}async sendSmsCode(e){if(!this.api)throw new d("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new d("phone nNumber must be set when initialzing authentication.");try{let o=j4();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw P(o)}}};var F1=class{constructor(e,o,a){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=a}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new d("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new d("User denied confirmation during OAuth flow");try{let e=q4(),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}}catch(e){throw P(e)}}async link(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new d("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new d("User denied confirmation during OAuth flow");try{let e=Y4();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw P(e)}}async getAuthorizationUrl(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.provider)throw new d("Provider must be set when initialzing OAuth authentication.");try{let e=K4();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw P(e)}}};var ot=require("wicg-inert"),a5=y(require("react-dom")),H2=y(require("styled-components"));var i1=require("react");var n3=require("react/jsx-runtime");function l3(i){return(0,n3.jsx)("link",{rel:"prefetch",href:i.src})}var y2=require("react/jsx-runtime"),s3=(0,i1.createContext)({ready:!1,app:null,options:{email:!0,sms:!1,wallet:!0,google:!1,twitter:!1,discord:!1},currentScreen:"LANDING",lastScreen:"LANDING",navigate:m,navigateBack:m}),C3=i=>{let e=i.appSettings,o=i.authenticated,a=i.visible,[r,n]=(0,i1.useState)(null),[C,u]=(0,i1.useState)(null);(0,i1.useEffect)(()=>{o||n(null)},[o]),(0,i1.useEffect)(()=>{a||(u("LANDING"),n("LANDING"))},[a]);let f={ready:!!(e!=null&&e.id),app:e,options:i.options,currentScreen:r||"LANDING",lastScreen:C||"LANDING",navigate:k=>{u(r),n(k)},navigateBack:()=>{n(C)}};return(0,y2.jsxs)(s3.Provider,{value:f,children:[e&&e.logoUrl&&(0,y2.jsx)(l3,{src:e.logoUrl}),i.children]})},g=()=>(0,i1.useContext)(s3);var N2=require("react"),B1=y(require("styled-components"));var p3=y(require("styled-components"));var e4=require("react/jsx-runtime"),d3=({style:i,...e})=>(0,e4.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",...i},...e,children:(0,e4.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});var i4=require("react/jsx-runtime"),c3=({style:i,...e})=>(0,i4.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",...i},...e,children:(0,i4.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});var v2=require("react");var o4=(0,v2.createContext)({isLinking:!1,getAuthMeta:m,getAuthFlow:m,closePrivyModal:m,initLoginWithWallet:m,loginWithWallet:m,loginWithCode:m,loginWithEmail:m,loginWithSms:m,resendEmailCode:m,resendSmsCode:m,initLoginWithOAuth:m,loginWithOAuth:m}),_=()=>(0,v2.useContext)(o4);var z=require("react/jsx-runtime"),E5=()=>(0,z.jsx)("div",{}),_5=({backFn:i})=>(0,z.jsx)("div",{children:(0,z.jsx)(c3,{onClick:i})}),P5=()=>{let{closePrivyModal:i}=_();return(0,z.jsx)("div",{children:(0,z.jsx)("div",{children:(0,z.jsx)(d3,{onClick:i})})})};var L=({backFn:i})=>(0,z.jsxs)(S5,{children:[i?(0,z.jsx)(_5,{backFn:i}):(0,z.jsx)(E5,{}),(0,z.jsx)(P5,{})]}),S5=p3.default.div`
12
+ - https://privy.io`;this.ethProvider=new U1}initialize(){let e=Z.get(c2);i3.includes(e)&&(this.walletType=e,this.connect({showPrompt:!1}))}destroy(){this.walletType=null,Z.del(c2),Z.del(W4)}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.address(),a=await this.chainId();return{address:o,chainId:a,chainType:"ethereum",walletType:e}}async connect(e){var o;switch(this.walletType){case"metamask":this.ethProvider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async r=>{r.isMetaMask&&this.ethProvider.setProvider(r)});break;case"coinbase_wallet":this.ethProvider.setProvider(A5());break;case"wallet_connect":let a=new J2.default({infuraId:s2});this.ethProvider.setProvider(a);break;default:throw new B(`Unsupported wallet: ${this.walletType}`)}return(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(this.walletType),this.getConnectedWallet()}async isConnected(){switch(this.walletType){case"metamask":return await this.address()!==null;case"coinbase_wallet":return await this.address()!==null;case"wallet_connect":return this.ethProvider.walletProvider.connected;default:throw new B(`Unsupported wallet: ${this.walletType}`)}}async promptConnection(e){try{switch(e){case"metamask":await this.ethProvider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]}),await this.ethProvider.request({method:"eth_requestAccounts"});break;case"coinbase_wallet":await this.ethProvider.request({method:"eth_requestAccounts"});break;case"wallet_connect":let o=new J2.default({infuraId:s2});this.ethProvider.setProvider(o),await Promise.race([o.enable(),Y2()]);break;default:throw new B(`Unsupported wallet: ${this.walletType}`)}Z.put(c2,e)}catch(o){throw u2(o)}}async sign(e){return new a3.Web3Provider(new D1(this.getEthereumProvider())).getSigner().signMessage(e)}prepareMessage(e,o,a){let r=window.location.host,n=window.location.origin,C="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,r,n,u,a,C)}async chainId(){let e=await this.getEthereumProvider().request({method:"eth_chainId"}),o=Number(e);return String(o)}async address(){let e=await this.getEthereumProvider().request({method:"eth_accounts"});return Array.isArray(e)&&e.length>0?(0,o3.getAddress)(e[0]):null}};var Q2,w2=class{constructor(e){let o=e.apiURL||_4,a=e.timeout||S4;this.appId=e.appId,this.connector=new k2,this.connector.initialize(),Q2||(Q2=new f2),this.session=Q2,this.api=new h2(e.appId,this.session,{baseURL:o,timeout:a}),this.session.api=this.api}authenticate(){if(!this.authFlow)throw new d("No auth flow in progress.");return this.session.authenticate(this.authFlow)}link(){if(!this.authFlow)throw new d("No auth flow in progress.");return this.session.link(this.authFlow)}async logout(){await this.session.destroy(),this.connector.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post(X4(),{address:e});return n1(o.data)}catch(o){throw j(o)}}async unlinkPhone(e){try{let o=await this.api.post(Q4(),{phoneNumber:e});return n1(o.data)}catch(o){throw j(o)}}async unlinkWallet(e){try{let o=await this.api.post(J4(),{address:e});return n1(o.data)}catch(o){throw j(o)}}async unlinkOAuth(e,o){try{let a=await this.api.post(t3(),{provider:e,subject:o});return n1(a.data)}catch(a){throw j(a)}}async getAuthenticatedUser(){return this.session.hasRefreshCredentials()?this.session.refresh():null}async getAccessToken(){if(this.session.hasActiveToken()){let{verificationKey:e,id:o}=await this.getAppSettings();return await this.session.hasValidToken(e,o,T4)?this.session.token:(await this.logout(),null)}else return 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,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,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 j(e)}}setActiveWallet(e,o){if(!o.linkedAccounts.map(r=>r.type==="wallet"?r.address:null).includes(e))throw new d("Cannot set an unlinked address as active.");return Z.put(e1,e),q1(o)}async forkSession(){return await this.session.forkSession()}};var n5=require("@ethersproject/providers");var M2=require("react");var m=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var t4=(0,M2.createContext)({ready:!1,authenticated:!1,user:null,login:m,linkEmail:m,linkPhone:m,linkWallet:m,linkGoogle:m,linkTwitter:m,linkDiscord:m,logout:m,getAccessToken:m,getEthereumProvider:m,getEthersProvider:m,getWeb3jsProvider:m,unlinkEmail:m,unlinkPhone:m,unlinkWallet:m,unlinkGoogle:m,unlinkTwitter:m,unlinkDiscord:m,setActiveWallet:m,forkSession:m}),R=()=>(0,M2.useContext)(t4);var Y1=class{constructor(e){this.connector=e,this.meta={wallet:this.connector.walletType}}async authenticate(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.connector.walletType)throw new d("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),a=await this.api.post(F4(),{message:e,signature:o});return{user:a.data.user,token:a.data.token,refresh_token:a.data.refresh_token}}catch(e){throw P(e)}}async link(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.connector.walletType)throw new d("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api);return(await this.api.post(V4(),{message:e,signature:o})).data}catch(e){throw P(e)}}async promptConnectAndSign(e){let o=await this.connector.connect({showPrompt:!0}),a=o.address,r=o.chainId,n=await e.post(D4(),{address:a}),C=this.connector.prepareMessage(r,a,n.data.nonce),u=await this.connector.sign(C);return{message:C,signature:u}}getEthereumProvider(){return this.connector.getEthereumProvider()}};var J1=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new d("Email and email code must be set prior to calling authenticate.");try{let e=G4(),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}}catch(e){throw P(e)}}async link(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new d("Email and email code must be set prior to calling authenticate.");try{let e=B4();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw P(e)}}async sendCodeEmail(e){if(!this.api)throw new d("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new d("Email must be set when initialzing authentication.");try{let o=H4();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw P(o)}}};var X1=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new d("phone number and sms code must be set prior to calling authenticate.");try{let e=z4(),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}}catch(e){throw P(e)}}async link(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new d("phone number and sms code must be set prior to calling authenticate.");try{let e=$4();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw P(e)}}async sendSmsCode(e){if(!this.api)throw new d("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new d("phone nNumber must be set when initialzing authentication.");try{let o=j4();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw P(o)}}};var F1=class{constructor(e,o,a){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=a}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new d("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new d("User denied confirmation during OAuth flow");try{let e=q4(),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}}catch(e){throw P(e)}}async link(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new d("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new d("User denied confirmation during OAuth flow");try{let e=Y4();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw P(e)}}async getAuthorizationUrl(){if(!this.api)throw new d("Auth flow has no API instance");if(!this.meta.provider)throw new d("Provider must be set when initialzing OAuth authentication.");try{let e=K4();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw P(e)}}};var ot=require("wicg-inert"),a5=y(require("react-dom")),H2=y(require("styled-components"));var i1=require("react");var n3=require("react/jsx-runtime");function l3(i){return(0,n3.jsx)("link",{rel:"prefetch",href:i.src})}var y2=require("react/jsx-runtime"),s3=(0,i1.createContext)({ready:!1,app:null,options:{email:!0,sms:!1,wallet:!0,google:!1,twitter:!1,discord:!1},currentScreen:"LANDING",lastScreen:"LANDING",navigate:m,navigateBack:m}),C3=i=>{let e=i.appSettings,o=i.authenticated,a=i.visible,[r,n]=(0,i1.useState)(null),[C,u]=(0,i1.useState)(null);(0,i1.useEffect)(()=>{o||n(null)},[o]),(0,i1.useEffect)(()=>{a||(u("LANDING"),n("LANDING"))},[a]);let f={ready:!!(e!=null&&e.id),app:e,options:i.options,currentScreen:r||"LANDING",lastScreen:C||"LANDING",navigate:k=>{u(r),n(k)},navigateBack:()=>{n(C)}};return(0,y2.jsxs)(s3.Provider,{value:f,children:[e&&e.logoUrl&&(0,y2.jsx)(l3,{src:e.logoUrl}),i.children]})},g=()=>(0,i1.useContext)(s3);var N2=require("react"),B1=y(require("styled-components"));var p3=y(require("styled-components"));var e4=require("react/jsx-runtime"),d3=({style:i,...e})=>(0,e4.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",...i},...e,children:(0,e4.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});var i4=require("react/jsx-runtime"),c3=({style:i,...e})=>(0,i4.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",...i},...e,children:(0,i4.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});var v2=require("react");var o4=(0,v2.createContext)({isLinking:!1,getAuthMeta:m,getAuthFlow:m,closePrivyModal:m,initLoginWithWallet:m,loginWithWallet:m,loginWithCode:m,loginWithEmail:m,loginWithSms:m,resendEmailCode:m,resendSmsCode:m,initLoginWithOAuth:m,loginWithOAuth:m}),_=()=>(0,v2.useContext)(o4);var z=require("react/jsx-runtime"),E5=()=>(0,z.jsx)("div",{}),_5=({backFn:i})=>(0,z.jsx)("div",{children:(0,z.jsx)(c3,{onClick:i})}),P5=()=>{let{closePrivyModal:i}=_();return(0,z.jsx)("div",{children:(0,z.jsx)("div",{children:(0,z.jsx)(d3,{onClick:i})})})};var L=({backFn:i})=>(0,z.jsxs)(S5,{children:[i?(0,z.jsx)(_5,{backFn:i}):(0,z.jsx)(E5,{}),(0,z.jsx)(P5,{})]}),S5=p3.default.div`
13
13
  height: 30px;
14
14
  display: flex;
15
15
  align-items: center;
@@ -535,7 +535,7 @@ Resources:
535
535
  width: 1rem;
536
536
  border-width: 2px;
537
537
  }
538
- `;var u4=require("react/jsx-runtime"),Z3=()=>{let{app:i}=g();return i!=null&&i.logoUrl?(0,u4.jsx)("div",{children:(0,u4.jsx)("img",{src:i.logoUrl,alt:`${i==null?void 0:i.name} logo`,style:{objectFit:"contain",width:"200px",height:"80px"}})}):null};var m4=require("react-device-detect"),w=require("react/jsx-runtime");var A3=()=>{let{ready:i}=R(),{getAuthMeta:e,isLinking:o}=_(),{app:a,navigate:r,options:n}=g(),C=n.email,u=n.sms,f=n.wallet,k=n.google,x=n.twitter,S=n.discord,E=f?0:1,[M,p]=(0,N2.useState)(E),b=e(),T=(b==null?void 0:b.authorizationCode)&&(b==null?void 0:b.stateCode)&&(b==null?void 0:b.provider);(0,N2.useEffect)(()=>{T?r("AWAITING_OAUTH_SCREEN"):o&&C?r("LINK_EMAIL_SCREEN"):o&&u?r("LINK_PHONE_SCREEN"):o&&f&&r("LINK_WALLET_SCREEN")},[i]);let I=M==0,p1=M==1;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(L,{},"header"),(0,w.jsx)(e6,{walletOnly:!C&&!u&&!k&&!x&&!S,children:(0,w.jsx)(Z3,{})}),(0,w.jsxs)(m1,{children:[f&&(0,w.jsx)(J5,{active:I,onClick:()=>p(0)}),(C||u)&&(0,w.jsx)(X5,{active:p1,onClick:()=>p(1),email:C,sms:u,google:k,twitter:x,discord:S})]}),a&&(0,w.jsx)(m3,{app:a}),(0,w.jsx)(o1,{protectedByPrivy:!0})]})};function J5(i){return(0,w.jsxs)(_3,{active:i.active,onClick:i.onClick,children:[(0,w.jsx)(E3,{active:i.active,children:(0,w.jsx)("h4",{children:"Connect Wallet"})}),i.active&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(L2,{}),(0,w.jsx)(A2,{})]})]})}function X5(i){let e=i.google||i.discord||i.twitter&&!m4.isMobile,o=i.email?"Email":"Phone";return(0,w.jsxs)(_3,{active:i.active,onClick:i.onClick,children:[(0,w.jsx)(E3,{active:i.active,children:(0,w.jsxs)("h4",{children:["Sign In with ",e?`${o} & Social`:o]})}),i.active&&i.email&&(0,w.jsx)(R2,{}),i.active&&i.sms&&!i.email&&(0,w.jsx)(O2,{}),i.active&&e&&(0,w.jsx)(Q5,{google:i.google,twitter:i.twitter&&!m4.isMobile,discord:i.discord})]})}function Q5(i){return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(t6,{children:[(0,w.jsx)(L3,{}),(0,w.jsx)("p",{children:" Or "}),(0,w.jsx)(L3,{})]}),(0,w.jsx)(k3,{showGoogle:i.google,showDiscord:i.discord,showTwitter:i.twitter})]})}var E3=B1.default.div`
538
+ `;var u4=require("react/jsx-runtime"),Z3=()=>{let{app:i}=g();return i!=null&&i.logoUrl?(0,u4.jsx)("div",{children:(0,u4.jsx)("img",{src:i.logoUrl,alt:`${i==null?void 0:i.name} logo`,style:{objectFit:"contain",width:"200px",height:"80px"}})}):null};var m4=require("react-device-detect"),w=require("react/jsx-runtime");var A3=()=>{let{ready:i}=R(),{getAuthMeta:e,isLinking:o}=_(),{app:a,navigate:r,options:n}=g(),C=n.email,u=n.sms,f=n.wallet,k=n.google,x=n.twitter,S=n.discord,E=f?0:1,[M,p]=(0,N2.useState)(E),b=e(),T=(b==null?void 0:b.authorizationCode)&&(b==null?void 0:b.stateCode)&&(b==null?void 0:b.provider);(0,N2.useEffect)(()=>{T?r("AWAITING_OAUTH_SCREEN"):o&&C?r("LINK_EMAIL_SCREEN"):o&&u?r("LINK_PHONE_SCREEN"):o&&f&&r("LINK_WALLET_SCREEN")},[i]);let I=M==0,p1=M==1;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(L,{},"header"),(0,w.jsx)(e6,{walletOnly:!C&&!u&&!k&&!x&&!S,hasTerms:!!((a==null?void 0:a.privacyPolicyUrl)||(a==null?void 0:a.termsAndConditionsUrl)),children:(0,w.jsx)(Z3,{})}),(0,w.jsxs)(m1,{children:[f&&(0,w.jsx)(J5,{active:I,onClick:()=>p(0)}),(C||u)&&(0,w.jsx)(X5,{active:p1,onClick:()=>p(1),email:C,sms:u,google:k,twitter:x,discord:S})]}),a&&(0,w.jsx)(m3,{app:a}),(0,w.jsx)(o1,{protectedByPrivy:!0})]})};function J5(i){return(0,w.jsxs)(_3,{active:i.active,onClick:i.onClick,children:[(0,w.jsx)(E3,{active:i.active,children:(0,w.jsx)("h4",{children:"Connect Wallet"})}),i.active&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(L2,{}),(0,w.jsx)(A2,{})]})]})}function X5(i){let e=i.google||i.discord||i.twitter&&!m4.isMobile,o=i.email?"Email":"Phone";return(0,w.jsxs)(_3,{active:i.active,onClick:i.onClick,children:[(0,w.jsx)(E3,{active:i.active,children:(0,w.jsxs)("h4",{children:["Sign In with ",e?`${o} & Social`:o]})}),i.active&&i.email&&(0,w.jsx)(R2,{}),i.active&&i.sms&&!i.email&&(0,w.jsx)(O2,{}),i.active&&e&&(0,w.jsx)(Q5,{google:i.google,twitter:i.twitter&&!m4.isMobile,discord:i.discord})]})}function Q5(i){return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(t6,{children:[(0,w.jsx)(L3,{}),(0,w.jsx)("p",{children:" Or "}),(0,w.jsx)(L3,{})]}),(0,w.jsx)(k3,{showGoogle:i.google,showDiscord:i.discord,showTwitter:i.twitter})]})}var E3=B1.default.div`
539
539
  font-weight: ${i=>i.active?600:500};
540
540
  color: ${i=>i.active?"inherit":"#6b7280"};
541
541
  display: flex;
@@ -588,15 +588,11 @@ Resources:
588
588
  // So...
589
589
  // - Wallet + other => 114px padding for logo, -24px on the top
590
590
  // - Wallet only => 176px padding for the logo, -24px on the top
591
+ // - Terms => 36px
591
592
  // Lastly, apply a 10px cheat upwards, which helps in particular for when
592
593
  // the logo is close to the top (mobile or full wallet-open design)
593
- margin-top: 28px;
594
- margin-bottom: 62px;
595
-
596
- ${({walletOnly:i})=>i&&`
597
- margin-top: 59px;
598
- margin-bottom: 93px;
599
- `}
594
+ margin-top: ${i=>`${28+(i.walletOnly?31:0)-(i.hasTerms?18:0)}px`};
595
+ margin-bottom: ${i=>`${60+(i.walletOnly?31:0)-(i.hasTerms?18:0)}px`};
600
596
  `;var w1=require("react");var o2=y(require("styled-components"));var i2=y(require("styled-components")),c1=require("react/jsx-runtime"),P1=({title:i,description:e,children:o,...a})=>(0,c1.jsxs)(S3,{...a,children:[(0,c1.jsx)("h3",{children:i}),typeof e=="string"?(0,c1.jsx)("p",{children:e}):null,o]}),P3=(0,i2.default)(P1)`
601
597
  margin-bottom: 24px;
602
598
  `,j1=({title:i,description:e,icon:o,children:a,...r})=>(0,c1.jsxs)(i6,{...r,children:[o?(0,c1.jsx)(o6,{children:o}):null,(0,c1.jsx)("h3",{children:i}),typeof e=="string"?(0,c1.jsx)("p",{children:e}):null,a]}),S3=i2.default.div`
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import{useEffect as S2,useState as n1}from"react";import N2 from"axios";import n5 from"axios";var F=class extends Error{constructor(o,a){super(o);a instanceof Error&&(this.cause=a)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},$1=class extends F{constructor(o,a,r,l){super(r,l);this.type=o;this.status=a}},C=class extends F{constructor(o,a){super(o,a);this.type="client_error"}};var N=class extends F{constructor(o,a){super(o,a);this.type="connector_error"}},L=i=>{if(i instanceof F)return i;if(!n5.isAxiosError(i))return U(i);if(!i.response)return new $1("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new $1(e||"ApiError",i.response.status,o||a,i)},U=i=>i instanceof F?i:i instanceof Error?new C(i.message,i):new C(`Internal error: ${i}`);var h4="1.10.0";var f4="https://api.privy.io/v0",u4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",K1="4df5e2316331463a9130964bd6078dfa",m4=1e4,k1=1200,b4=365*24*60*60,O2=h4,k4="ES256",g4="privy.io",g1="privy:token",q1="privy:refresh_token",B="privy:active_wallet",Y1="privy:wallet_type",w4="walletconnect";var J1=class{constructor(e,o,a){this.appId=e,this.sdkVersion=O2,this.session=o,this.defaults=a}async get(e,o){try{return await N2.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw L(a)}}async post(e,o,a){try{return await N2.post(e,o,this.buildConfig(a))}catch(r){throw L(r)}}async delete(e,o){try{return await N2.delete(e,this.buildConfig(o))}catch(a){throw L(a)}}buildConfig(e){return e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-client"]=`react-auth:${this.sdkVersion}`,this.session.token!==null&&(e.headers.authorization=`Bearer ${this.session.token}`),{...this.defaults,...e}}};import*as w1 from"jose";var t1=class{static parse(e){try{return new t1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=w1.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(),a=(this.expiration-e)*1e3;return o>=a}async isValid(e,o,a=0){let r=await w1.importSPKI(e,k4);try{return await w1.jwtVerify(this.value,r,{issuer:g4,audience:o,clockTolerance:a}),!0}catch{return!1}}};var e1=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 U2=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]}},D2=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}};function C5(){return typeof window<"u"&&window.localStorage?new D2:new U2}var y=C5();function s1(i){return new Date(i*1e3)}function d5(i){return i.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:s1(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:s1(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:s1(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:s1(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:s1(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:s1(e.verified_at)};default:throw new C("Unrecognized account type")}})}function c5(i,e){return e.find(o=>o.type==="wallet"&&o.address===i)}function C1(i,e){return i.sort((o,a)=>a.verifiedAt.getTime()-o.verifiedAt.getTime()),i.find(o=>o.type===e)}function N1(i){let e=i.linkedAccounts.map(s=>s.type==="wallet"?s.address:null),a=y.get(B);if(!a||!e.includes(a)){y.del(B);let s=C1(i.linkedAccounts,"wallet");s&&(a=s.address,y.put(B,a))}let r=c5(a,i.linkedAccounts),l=Object.assign({},i);return l.wallet=r&&{address:r.address,chainType:r.chainType,chainId:r.chainId,walletType:r.walletType},l}function z(i){if(!i)return null;let e=d5(i.linked_accounts),o=C1(e,"wallet"),a=C1(e,"email"),r=C1(e,"phone"),l=C1(e,"google_oauth"),s=C1(e,"twitter_oauth"),f=C1(e,"discord_oauth"),h={id:i.id,createdAt:s1(i.created_at),linkedAccounts:e,email:a&&{address:a==null?void 0:a.address},phone:r&&{number:r==null?void 0:r.number},wallet:o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},google:l&&{subject:l.subject,email:l.email,name:l.name},twitter:s&&{subject:s.subject,username:s.username,name:s.name},discord:f&&{subject:f.subject,username:f.username,email:f.email}};return N1(h)}var M4=()=>"/api/v1/sessions",y4=()=>"/api/v1/sessions/logout",v4=()=>"/api/v1/sessions/fork",x4=()=>"/api/v1/siwe/init",Z4=()=>"/api/v1/siwe/authenticate",L4=()=>"/api/v1/siwe/link",A4=()=>"/api/v1/passwordless/init",E4=()=>"/api/v1/passwordless/authenticate",_4=()=>"/api/v1/passwordless/link",P4=()=>"/api/v1/passwordless_sms/init",S4=()=>"/api/v1/passwordless_sms/authenticate",T4=()=>"/api/v1/passwordless_sms/link",I4=()=>"/api/v1/oauth/init",R4=()=>"/api/v1/oauth/authenticate",W4=()=>"/api/v1/oauth/link",O4=()=>"/api/v1/siwe/unlink",N4=()=>"/api/v1/passwordless/unlink",U4=()=>"/api/v1/passwordless_sms/unlink",D4=()=>"/api/v1/oauth/unlink";var p5=30,X1=class{constructor(){this.authenticateOnce=new e1(async e=>this._authenticate(e)),this.linkOnce=new e1(async e=>this._link(e)),this.refreshOnce=new e1(this._refresh.bind(this)),this.destroyOnce=new e1(this._destroy.bind(this)),this.forkSessionOnce=new e1(this._forkSession.bind(this))}get token(){try{let e=y.get(g1);return typeof e=="string"?new t1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=y.get(q1);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=t1.parse(this.token);return e!==null&&!e.isExpired(p5)}async hasValidToken(e,o,a=0){let r=t1.parse(this.token);return r!==null&&await r.isValid(e,o,a)}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:a,user:r}=await e.authenticate();return this.storeToken(o),this.storeRefreshToken(a),z(r)}catch(o){throw console.warn("Error authenticating session"),U(o)}}async _link(e){try{let o=await e.link();return z(o)}catch(o){throw console.warn("Error linking account"),U(o)}}async _refresh(){if(!this.api)throw new C("Session has no API instance");let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let a=await this.api.post(M4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),z(a.data.user)}catch(a){throw U(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(y4(),{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(v4(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw U(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null),y.del(B)}storeToken(e){typeof e=="string"?y.put(g1,e):y.del(g1)}storeRefreshToken(e){typeof e=="string"?y.put(q1,e):y.del(q1)}};import{getAddress as k5}from"@ethersproject/address";import V4 from"@walletconnect/web3-provider";import{ErrorCode as h5}from"@ethersproject/logger";var M1=class extends N{constructor(){super("Wallet timeout");this.type="wallet_error"}},Q1=i=>{if(i instanceof N)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new y1(i);return i.code===h5.ACTION_REJECTED&&(e.details=d1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new y1(i):new N("Unknown connector error",i)},F2=class extends F{constructor(o,a,r){super(o);this.type="provider_error";this.code=a,this.data=r}},y1=class extends F2{constructor(o){var l,s,f;let a=o;super(a.message,a.code,a.data);let r=Object.values(d1).find(h=>h.eipCode===a.code);this.details=r||d1.UNKNOWN_ERROR,a.code===-32002&&((l=a.message)!=null&&l.includes("already pending for origin")?(s=a.message)!=null&&s.includes("wallet_requestPermissions")?this.details=d1.E32002_CONNECTION_ALREADY_PENDING:this.details=d1.E32002_REQUEST_ALREADY_PENDING:(f=a.message)!=null&&f.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=d1.E32002_WALLET_LOCKED))}},f5={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}},u5={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}},m5={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}},d1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...m5,...u5},t2={...f5,...d1};var b5=12e4,V2=(i=new M1,e=b5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),v1=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 a;(a=this.walletProvider)==null||a.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 N(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),V2()]).catch(o=>{throw Q1(o)})}},x1=class extends v1{constructor(o){super(o)}},e2=class extends v1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};import{Web3Provider as g5}from"@ethersproject/providers";var F4=["metamask","coinbase_wallet","wallet_connect"];import w5 from"@coinbase/wallet-sdk";var M5=()=>{let i=`https://mainnet.infura.io/v3/${K1}`,e=1;return new w5({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},H2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isMetaMask)return!0}return!1},o2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isCoinbaseWallet)return!0}return!1},i2=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,r,l,s,f)=>`${a} wants you to sign in with your Ethereum account:
1
+ import{useEffect as S2,useState as n1}from"react";import N2 from"axios";import n5 from"axios";var F=class extends Error{constructor(o,a){super(o);a instanceof Error&&(this.cause=a)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},$1=class extends F{constructor(o,a,r,l){super(r,l);this.type=o;this.status=a}},C=class extends F{constructor(o,a){super(o,a);this.type="client_error"}};var N=class extends F{constructor(o,a){super(o,a);this.type="connector_error"}},L=i=>{if(i instanceof F)return i;if(!n5.isAxiosError(i))return U(i);if(!i.response)return new $1("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new $1(e||"ApiError",i.response.status,o||a,i)},U=i=>i instanceof F?i:i instanceof Error?new C(i.message,i):new C(`Internal error: ${i}`);var h4="1.10.1";var f4="https://api.privy.io/v0",u4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",K1="4df5e2316331463a9130964bd6078dfa",m4=1e4,k1=1200,b4=365*24*60*60,O2=h4,k4="ES256",g4="privy.io",g1="privy:token",q1="privy:refresh_token",B="privy:active_wallet",Y1="privy:wallet_type",w4="walletconnect";var J1=class{constructor(e,o,a){this.appId=e,this.sdkVersion=O2,this.session=o,this.defaults=a}async get(e,o){try{return await N2.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw L(a)}}async post(e,o,a){try{return await N2.post(e,o,this.buildConfig(a))}catch(r){throw L(r)}}async delete(e,o){try{return await N2.delete(e,this.buildConfig(o))}catch(a){throw L(a)}}buildConfig(e){return e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-client"]=`react-auth:${this.sdkVersion}`,this.session.token!==null&&(e.headers.authorization=`Bearer ${this.session.token}`),{...this.defaults,...e}}};import*as w1 from"jose";var t1=class{static parse(e){try{return new t1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=w1.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(),a=(this.expiration-e)*1e3;return o>=a}async isValid(e,o,a=0){let r=await w1.importSPKI(e,k4);try{return await w1.jwtVerify(this.value,r,{issuer:g4,audience:o,clockTolerance:a}),!0}catch{return!1}}};var e1=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 U2=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]}},D2=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}};function C5(){return typeof window<"u"&&window.localStorage?new D2:new U2}var y=C5();function s1(i){return new Date(i*1e3)}function d5(i){return i.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:s1(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:s1(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:s1(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:s1(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:s1(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:s1(e.verified_at)};default:throw new C("Unrecognized account type")}})}function c5(i,e){return e.find(o=>o.type==="wallet"&&o.address===i)}function C1(i,e){return i.sort((o,a)=>a.verifiedAt.getTime()-o.verifiedAt.getTime()),i.find(o=>o.type===e)}function N1(i){let e=i.linkedAccounts.map(s=>s.type==="wallet"?s.address:null),a=y.get(B);if(!a||!e.includes(a)){y.del(B);let s=C1(i.linkedAccounts,"wallet");s&&(a=s.address,y.put(B,a))}let r=c5(a,i.linkedAccounts),l=Object.assign({},i);return l.wallet=r&&{address:r.address,chainType:r.chainType,chainId:r.chainId,walletType:r.walletType},l}function z(i){if(!i)return null;let e=d5(i.linked_accounts),o=C1(e,"wallet"),a=C1(e,"email"),r=C1(e,"phone"),l=C1(e,"google_oauth"),s=C1(e,"twitter_oauth"),f=C1(e,"discord_oauth"),h={id:i.id,createdAt:s1(i.created_at),linkedAccounts:e,email:a&&{address:a==null?void 0:a.address},phone:r&&{number:r==null?void 0:r.number},wallet:o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},google:l&&{subject:l.subject,email:l.email,name:l.name},twitter:s&&{subject:s.subject,username:s.username,name:s.name},discord:f&&{subject:f.subject,username:f.username,email:f.email}};return N1(h)}var M4=()=>"/api/v1/sessions",y4=()=>"/api/v1/sessions/logout",v4=()=>"/api/v1/sessions/fork",x4=()=>"/api/v1/siwe/init",Z4=()=>"/api/v1/siwe/authenticate",L4=()=>"/api/v1/siwe/link",A4=()=>"/api/v1/passwordless/init",E4=()=>"/api/v1/passwordless/authenticate",_4=()=>"/api/v1/passwordless/link",P4=()=>"/api/v1/passwordless_sms/init",S4=()=>"/api/v1/passwordless_sms/authenticate",T4=()=>"/api/v1/passwordless_sms/link",I4=()=>"/api/v1/oauth/init",R4=()=>"/api/v1/oauth/authenticate",W4=()=>"/api/v1/oauth/link",O4=()=>"/api/v1/siwe/unlink",N4=()=>"/api/v1/passwordless/unlink",U4=()=>"/api/v1/passwordless_sms/unlink",D4=()=>"/api/v1/oauth/unlink";var p5=30,X1=class{constructor(){this.authenticateOnce=new e1(async e=>this._authenticate(e)),this.linkOnce=new e1(async e=>this._link(e)),this.refreshOnce=new e1(this._refresh.bind(this)),this.destroyOnce=new e1(this._destroy.bind(this)),this.forkSessionOnce=new e1(this._forkSession.bind(this))}get token(){try{let e=y.get(g1);return typeof e=="string"?new t1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=y.get(q1);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=t1.parse(this.token);return e!==null&&!e.isExpired(p5)}async hasValidToken(e,o,a=0){let r=t1.parse(this.token);return r!==null&&await r.isValid(e,o,a)}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:a,user:r}=await e.authenticate();return this.storeToken(o),this.storeRefreshToken(a),z(r)}catch(o){throw console.warn("Error authenticating session"),U(o)}}async _link(e){try{let o=await e.link();return z(o)}catch(o){throw console.warn("Error linking account"),U(o)}}async _refresh(){if(!this.api)throw new C("Session has no API instance");let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let a=await this.api.post(M4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),z(a.data.user)}catch(a){throw U(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(y4(),{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(v4(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw U(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null),y.del(B)}storeToken(e){typeof e=="string"?y.put(g1,e):y.del(g1)}storeRefreshToken(e){typeof e=="string"?y.put(q1,e):y.del(q1)}};import{getAddress as k5}from"@ethersproject/address";import V4 from"@walletconnect/web3-provider";import{ErrorCode as h5}from"@ethersproject/logger";var M1=class extends N{constructor(){super("Wallet timeout");this.type="wallet_error"}},Q1=i=>{if(i instanceof N)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new y1(i);return i.code===h5.ACTION_REJECTED&&(e.details=d1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new y1(i):new N("Unknown connector error",i)},F2=class extends F{constructor(o,a,r){super(o);this.type="provider_error";this.code=a,this.data=r}},y1=class extends F2{constructor(o){var l,s,f;let a=o;super(a.message,a.code,a.data);let r=Object.values(d1).find(h=>h.eipCode===a.code);this.details=r||d1.UNKNOWN_ERROR,a.code===-32002&&((l=a.message)!=null&&l.includes("already pending for origin")?(s=a.message)!=null&&s.includes("wallet_requestPermissions")?this.details=d1.E32002_CONNECTION_ALREADY_PENDING:this.details=d1.E32002_REQUEST_ALREADY_PENDING:(f=a.message)!=null&&f.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=d1.E32002_WALLET_LOCKED))}},f5={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}},u5={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}},m5={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}},d1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...m5,...u5},t2={...f5,...d1};var b5=12e4,V2=(i=new M1,e=b5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),v1=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 a;(a=this.walletProvider)==null||a.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 N(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),V2()]).catch(o=>{throw Q1(o)})}},x1=class extends v1{constructor(o){super(o)}},e2=class extends v1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};import{Web3Provider as g5}from"@ethersproject/providers";var F4=["metamask","coinbase_wallet","wallet_connect"];import w5 from"@coinbase/wallet-sdk";var M5=()=>{let i=`https://mainnet.infura.io/v3/${K1}`,e=1;return new w5({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},H2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isMetaMask)return!0}return!1},o2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isCoinbaseWallet)return!0}return!1},i2=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,r,l,s,f)=>`${a} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${f}
@@ -9,7 +9,7 @@ Chain ID: ${e}
9
9
  Nonce: ${s}
10
10
  Issued At: ${l}
11
11
  Resources:
12
- - https://privy.io`;this.ethProvider=new v1}initialize(){let e=y.get(Y1);F4.includes(e)&&(this.walletType=e,this.connect({showPrompt:!1}))}destroy(){this.walletType=null,y.del(Y1),y.del(w4)}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.address(),a=await this.chainId();return{address:o,chainId:a,chainType:"ethereum",walletType:e}}async connect(e){var o;switch(this.walletType){case"metamask":this.ethProvider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async r=>{r.isMetaMask&&this.ethProvider.setProvider(r)});break;case"coinbase_wallet":this.ethProvider.setProvider(M5());break;case"wallet_connect":let a=new V4({infuraId:K1});this.ethProvider.setProvider(a);break;default:throw new N(`Unsupported wallet: ${this.walletType}`)}return(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(this.walletType),this.getConnectedWallet()}async isConnected(){switch(this.walletType){case"metamask":return await this.address()!==null;case"coinbase_wallet":return await this.address()!==null;case"wallet_connect":return this.ethProvider.walletProvider.connected;default:throw new N(`Unsupported wallet: ${this.walletType}`)}}async promptConnection(e){try{switch(e){case"metamask":await this.ethProvider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]}),await this.ethProvider.request({method:"eth_requestAccounts"});break;case"coinbase_wallet":await this.ethProvider.request({method:"eth_requestAccounts"});break;case"wallet_connect":let o=new V4({infuraId:K1});this.ethProvider.setProvider(o),await Promise.race([o.enable(),V2()]);break;default:throw new N(`Unsupported wallet: ${this.walletType}`)}y.put(Y1,e)}catch(o){throw Q1(o)}}async sign(e){return new g5(new x1(this.getEthereumProvider())).getSigner().signMessage(e)}prepareMessage(e,o,a){let r=window.location.host,l=window.location.origin,s=`Welcome! Before continuing, ${r} needs to verify you own this wallet. Signing this message proves ownership. Please note that signing is NOT a transaction, there are NO fees, and this signature does NOT authorize any future transaction requests.`,f=new Date().toISOString();return this.createSiweMessage(e,o,r,l,f,a,s)}async chainId(){let e=await this.getEthereumProvider().request({method:"eth_chainId"}),o=Number(e);return String(o)}async address(){let e=await this.getEthereumProvider().request({method:"eth_accounts"});return Array.isArray(e)&&e.length>0?k5(e[0]):null}};var G2,a2=class{constructor(e){let o=e.apiURL||f4,a=e.timeout||m4;this.appId=e.appId,this.connector=new i2,this.connector.initialize(),G2||(G2=new X1),this.session=G2,this.api=new J1(e.appId,this.session,{baseURL:o,timeout:a}),this.session.api=this.api}authenticate(){if(!this.authFlow)throw new C("No auth flow in progress.");return this.session.authenticate(this.authFlow)}link(){if(!this.authFlow)throw new C("No auth flow in progress.");return this.session.link(this.authFlow)}async logout(){await this.session.destroy(),this.connector.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post(N4(),{address:e});return z(o.data)}catch(o){throw U(o)}}async unlinkPhone(e){try{let o=await this.api.post(U4(),{phoneNumber:e});return z(o.data)}catch(o){throw U(o)}}async unlinkWallet(e){try{let o=await this.api.post(O4(),{address:e});return z(o.data)}catch(o){throw U(o)}}async unlinkOAuth(e,o){try{let a=await this.api.post(D4(),{provider:e,subject:o});return z(a.data)}catch(a){throw U(a)}}async getAuthenticatedUser(){return this.session.hasRefreshCredentials()?this.session.refresh():null}async getAccessToken(){if(this.session.hasActiveToken()){let{verificationKey:e,id:o}=await this.getAppSettings();return await this.session.hasValidToken(e,o,b4)?this.session.token:(await this.logout(),null)}else return 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,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,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 U(e)}}setActiveWallet(e,o){if(!o.linkedAccounts.map(r=>r.type==="wallet"?r.address:null).includes(e))throw new C("Cannot set an unlinked address as active.");return y.put(B,e),N1(o)}async forkSession(){return await this.session.forkSession()}};import{Web3Provider as b7}from"@ethersproject/providers";import{createContext as y5,useContext as v5}from"react";var u=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var B2=y5({ready:!1,authenticated:!1,user:null,login:u,linkEmail:u,linkPhone:u,linkWallet:u,linkGoogle:u,linkTwitter:u,linkDiscord:u,logout:u,getAccessToken:u,getEthereumProvider:u,getEthersProvider:u,getWeb3jsProvider:u,unlinkEmail:u,unlinkPhone:u,unlinkWallet:u,unlinkGoogle:u,unlinkTwitter:u,unlinkDiscord:u,setActiveWallet:u,forkSession:u}),R=()=>v5(B2);var U1=class{constructor(e){this.connector=e,this.meta={wallet:this.connector.walletType}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.connector.walletType)throw new C("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),a=await this.api.post(Z4(),{message:e,signature:o});return{user:a.data.user,token:a.data.token,refresh_token:a.data.refresh_token}}catch(e){throw L(e)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.connector.walletType)throw new C("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api);return(await this.api.post(L4(),{message:e,signature:o})).data}catch(e){throw L(e)}}async promptConnectAndSign(e){let o=await this.connector.connect({showPrompt:!0}),a=o.address,r=o.chainId,l=await e.post(x4(),{address:a}),s=this.connector.prepareMessage(r,a,l.data.nonce),f=await this.connector.sign(s);return{message:s,signature:f}}getEthereumProvider(){return this.connector.getEthereumProvider()}};var D1=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=E4(),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}}catch(e){throw L(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=_4();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw L(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=A4();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw L(o)}}};var F1=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=S4(),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}}catch(e){throw L(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=T4();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw L(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=P4();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw L(o)}}};var Z1=class{constructor(e,o,a){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=a}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=R4(),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}}catch(e){throw L(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=W4();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw L(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=I4();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw L(e)}}};import"wicg-inert";import c7 from"react-dom";import d4 from"styled-components";import{createContext as Z5,useContext as L5,useEffect as G4,useState as B4}from"react";import{jsx as x5}from"react/jsx-runtime";function H4(i){return x5("link",{rel:"prefetch",href:i.src})}import{jsx as A5,jsxs as E5}from"react/jsx-runtime";var j4=Z5({ready:!1,app:null,options:{email:!0,sms:!1,wallet:!0,google:!1,twitter:!1,discord:!1},currentScreen:"LANDING",lastScreen:"LANDING",navigate:u,navigateBack:u}),z4=i=>{let e=i.appSettings,o=i.authenticated,a=i.visible,[r,l]=B4(null),[s,f]=B4(null);G4(()=>{o||l(null)},[o]),G4(()=>{a||(f("LANDING"),l("LANDING"))},[a]);let h={ready:!!(e!=null&&e.id),app:e,options:i.options,currentScreen:r||"LANDING",lastScreen:s||"LANDING",navigate:k=>{f(r),l(k)},navigateBack:()=>{l(s)}};return E5(j4.Provider,{value:h,children:[e&&e.logoUrl&&A5(H4,{src:e.logoUrl}),i.children]})},g=()=>L5(j4);import{useEffect as w6,useState as M6}from"react";import G1 from"styled-components";import S5 from"styled-components";import{jsx as $4}from"react/jsx-runtime";var K4=({style:i,...e})=>$4("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",...i},...e,children:$4("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});import{jsx as q4}from"react/jsx-runtime";var Y4=({style:i,...e})=>q4("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",...i},...e,children:q4("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});import{createContext as _5,useContext as P5}from"react";var j2=_5({isLinking:!1,getAuthMeta:u,getAuthFlow:u,closePrivyModal:u,initLoginWithWallet:u,loginWithWallet:u,loginWithCode:u,loginWithEmail:u,loginWithSms:u,resendEmailCode:u,resendSmsCode:u,initLoginWithOAuth:u,loginWithOAuth:u}),Z=()=>P5(j2);import{jsx as $,jsxs as O5}from"react/jsx-runtime";var T5=()=>$("div",{}),I5=({backFn:i})=>$("div",{children:$(Y4,{onClick:i})}),R5=()=>{let{closePrivyModal:i}=Z();return $("div",{children:$("div",{children:$(K4,{onClick:i})})})};var v=({backFn:i})=>O5(W5,{children:[i?$(I5,{backFn:i}):$(T5,{}),$(R5,{})]}),W5=S5.div`
12
+ - https://privy.io`;this.ethProvider=new v1}initialize(){let e=y.get(Y1);F4.includes(e)&&(this.walletType=e,this.connect({showPrompt:!1}))}destroy(){this.walletType=null,y.del(Y1),y.del(w4)}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.address(),a=await this.chainId();return{address:o,chainId:a,chainType:"ethereum",walletType:e}}async connect(e){var o;switch(this.walletType){case"metamask":this.ethProvider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async r=>{r.isMetaMask&&this.ethProvider.setProvider(r)});break;case"coinbase_wallet":this.ethProvider.setProvider(M5());break;case"wallet_connect":let a=new V4({infuraId:K1});this.ethProvider.setProvider(a);break;default:throw new N(`Unsupported wallet: ${this.walletType}`)}return(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(this.walletType),this.getConnectedWallet()}async isConnected(){switch(this.walletType){case"metamask":return await this.address()!==null;case"coinbase_wallet":return await this.address()!==null;case"wallet_connect":return this.ethProvider.walletProvider.connected;default:throw new N(`Unsupported wallet: ${this.walletType}`)}}async promptConnection(e){try{switch(e){case"metamask":await this.ethProvider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]}),await this.ethProvider.request({method:"eth_requestAccounts"});break;case"coinbase_wallet":await this.ethProvider.request({method:"eth_requestAccounts"});break;case"wallet_connect":let o=new V4({infuraId:K1});this.ethProvider.setProvider(o),await Promise.race([o.enable(),V2()]);break;default:throw new N(`Unsupported wallet: ${this.walletType}`)}y.put(Y1,e)}catch(o){throw Q1(o)}}async sign(e){return new g5(new x1(this.getEthereumProvider())).getSigner().signMessage(e)}prepareMessage(e,o,a){let r=window.location.host,l=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.",f=new Date().toISOString();return this.createSiweMessage(e,o,r,l,f,a,s)}async chainId(){let e=await this.getEthereumProvider().request({method:"eth_chainId"}),o=Number(e);return String(o)}async address(){let e=await this.getEthereumProvider().request({method:"eth_accounts"});return Array.isArray(e)&&e.length>0?k5(e[0]):null}};var G2,a2=class{constructor(e){let o=e.apiURL||f4,a=e.timeout||m4;this.appId=e.appId,this.connector=new i2,this.connector.initialize(),G2||(G2=new X1),this.session=G2,this.api=new J1(e.appId,this.session,{baseURL:o,timeout:a}),this.session.api=this.api}authenticate(){if(!this.authFlow)throw new C("No auth flow in progress.");return this.session.authenticate(this.authFlow)}link(){if(!this.authFlow)throw new C("No auth flow in progress.");return this.session.link(this.authFlow)}async logout(){await this.session.destroy(),this.connector.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post(N4(),{address:e});return z(o.data)}catch(o){throw U(o)}}async unlinkPhone(e){try{let o=await this.api.post(U4(),{phoneNumber:e});return z(o.data)}catch(o){throw U(o)}}async unlinkWallet(e){try{let o=await this.api.post(O4(),{address:e});return z(o.data)}catch(o){throw U(o)}}async unlinkOAuth(e,o){try{let a=await this.api.post(D4(),{provider:e,subject:o});return z(a.data)}catch(a){throw U(a)}}async getAuthenticatedUser(){return this.session.hasRefreshCredentials()?this.session.refresh():null}async getAccessToken(){if(this.session.hasActiveToken()){let{verificationKey:e,id:o}=await this.getAppSettings();return await this.session.hasValidToken(e,o,b4)?this.session.token:(await this.logout(),null)}else return 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,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,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 U(e)}}setActiveWallet(e,o){if(!o.linkedAccounts.map(r=>r.type==="wallet"?r.address:null).includes(e))throw new C("Cannot set an unlinked address as active.");return y.put(B,e),N1(o)}async forkSession(){return await this.session.forkSession()}};import{Web3Provider as b7}from"@ethersproject/providers";import{createContext as y5,useContext as v5}from"react";var u=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var B2=y5({ready:!1,authenticated:!1,user:null,login:u,linkEmail:u,linkPhone:u,linkWallet:u,linkGoogle:u,linkTwitter:u,linkDiscord:u,logout:u,getAccessToken:u,getEthereumProvider:u,getEthersProvider:u,getWeb3jsProvider:u,unlinkEmail:u,unlinkPhone:u,unlinkWallet:u,unlinkGoogle:u,unlinkTwitter:u,unlinkDiscord:u,setActiveWallet:u,forkSession:u}),R=()=>v5(B2);var U1=class{constructor(e){this.connector=e,this.meta={wallet:this.connector.walletType}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.connector.walletType)throw new C("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),a=await this.api.post(Z4(),{message:e,signature:o});return{user:a.data.user,token:a.data.token,refresh_token:a.data.refresh_token}}catch(e){throw L(e)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.connector.walletType)throw new C("Wallet must be specified");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api);return(await this.api.post(L4(),{message:e,signature:o})).data}catch(e){throw L(e)}}async promptConnectAndSign(e){let o=await this.connector.connect({showPrompt:!0}),a=o.address,r=o.chainId,l=await e.post(x4(),{address:a}),s=this.connector.prepareMessage(r,a,l.data.nonce),f=await this.connector.sign(s);return{message:s,signature:f}}getEthereumProvider(){return this.connector.getEthereumProvider()}};var D1=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=E4(),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}}catch(e){throw L(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=_4();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw L(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=A4();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw L(o)}}};var F1=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=S4(),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}}catch(e){throw L(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=T4();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw L(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=P4();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw L(o)}}};var Z1=class{constructor(e,o,a){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=a}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=R4(),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}}catch(e){throw L(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=W4();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw L(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=I4();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw L(e)}}};import"wicg-inert";import c7 from"react-dom";import d4 from"styled-components";import{createContext as Z5,useContext as L5,useEffect as G4,useState as B4}from"react";import{jsx as x5}from"react/jsx-runtime";function H4(i){return x5("link",{rel:"prefetch",href:i.src})}import{jsx as A5,jsxs as E5}from"react/jsx-runtime";var j4=Z5({ready:!1,app:null,options:{email:!0,sms:!1,wallet:!0,google:!1,twitter:!1,discord:!1},currentScreen:"LANDING",lastScreen:"LANDING",navigate:u,navigateBack:u}),z4=i=>{let e=i.appSettings,o=i.authenticated,a=i.visible,[r,l]=B4(null),[s,f]=B4(null);G4(()=>{o||l(null)},[o]),G4(()=>{a||(f("LANDING"),l("LANDING"))},[a]);let h={ready:!!(e!=null&&e.id),app:e,options:i.options,currentScreen:r||"LANDING",lastScreen:s||"LANDING",navigate:k=>{f(r),l(k)},navigateBack:()=>{l(s)}};return E5(j4.Provider,{value:h,children:[e&&e.logoUrl&&A5(H4,{src:e.logoUrl}),i.children]})},g=()=>L5(j4);import{useEffect as w6,useState as M6}from"react";import G1 from"styled-components";import S5 from"styled-components";import{jsx as $4}from"react/jsx-runtime";var K4=({style:i,...e})=>$4("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",...i},...e,children:$4("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});import{jsx as q4}from"react/jsx-runtime";var Y4=({style:i,...e})=>q4("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",...i},...e,children:q4("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});import{createContext as _5,useContext as P5}from"react";var j2=_5({isLinking:!1,getAuthMeta:u,getAuthFlow:u,closePrivyModal:u,initLoginWithWallet:u,loginWithWallet:u,loginWithCode:u,loginWithEmail:u,loginWithSms:u,resendEmailCode:u,resendSmsCode:u,initLoginWithOAuth:u,loginWithOAuth:u}),Z=()=>P5(j2);import{jsx as $,jsxs as O5}from"react/jsx-runtime";var T5=()=>$("div",{}),I5=({backFn:i})=>$("div",{children:$(Y4,{onClick:i})}),R5=()=>{let{closePrivyModal:i}=Z();return $("div",{children:$("div",{children:$(K4,{onClick:i})})})};var v=({backFn:i})=>O5(W5,{children:[i?$(I5,{backFn:i}):$(T5,{}),$(R5,{})]}),W5=S5.div`
13
13
  height: 30px;
14
14
  display: flex;
15
15
  align-items: center;
@@ -535,7 +535,7 @@ Resources:
535
535
  width: 1rem;
536
536
  border-width: 2px;
537
537
  }
538
- `;import{jsx as b3}from"react/jsx-runtime";var k3=()=>{let{app:i}=g();return i!=null&&i.logoUrl?b3("div",{children:b3("img",{src:i.logoUrl,alt:`${i==null?void 0:i.name} logo`,style:{objectFit:"contain",width:"200px",height:"80px"}})}):null};import{isMobile as g3}from"react-device-detect";import{Fragment as X2,jsx as A,jsxs as a1}from"react/jsx-runtime";var M3=()=>{let{ready:i}=R(),{getAuthMeta:e,isLinking:o}=Z(),{app:a,navigate:r,options:l}=g(),s=l.email,f=l.sms,h=l.wallet,k=l.google,M=l.twitter,E=l.discord,x=h?0:1,[w,p]=M6(x),m=e(),P=(m==null?void 0:m.authorizationCode)&&(m==null?void 0:m.stateCode)&&(m==null?void 0:m.provider);w6(()=>{P?r("AWAITING_OAUTH_SCREEN"):o&&s?r("LINK_EMAIL_SCREEN"):o&&f?r("LINK_PHONE_SCREEN"):o&&h&&r("LINK_WALLET_SCREEN")},[i]);let S=w==0,X=w==1;return a1(X2,{children:[A(v,{},"header"),A(L6,{walletOnly:!s&&!f&&!k&&!M&&!E,children:A(k3,{})}),a1(i1,{children:[h&&A(y6,{active:S,onClick:()=>p(0)}),(s||f)&&A(v6,{active:X,onClick:()=>p(1),email:s,sms:f,google:k,twitter:M,discord:E})]}),a&&A(l3,{app:a}),A(j,{protectedByPrivy:!0})]})};function y6(i){return a1(v3,{active:i.active,onClick:i.onClick,children:[A(y3,{active:i.active,children:A("h4",{children:"Connect Wallet"})}),i.active&&a1(X2,{children:[A(l2,{}),A(n2,{})]})]})}function v6(i){let e=i.google||i.discord||i.twitter&&!g3,o=i.email?"Email":"Phone";return a1(v3,{active:i.active,onClick:i.onClick,children:[A(y3,{active:i.active,children:a1("h4",{children:["Sign In with ",e?`${o} & Social`:o]})}),i.active&&i.email&&A(m2,{}),i.active&&i.sms&&!i.email&&A(k2,{}),i.active&&e&&A(x6,{google:i.google,twitter:i.twitter&&!g3,discord:i.discord})]})}function x6(i){return a1(X2,{children:[a1(Z6,{children:[A(w3,{}),A("p",{children:" Or "}),A(w3,{})]}),A(c3,{showGoogle:i.google,showDiscord:i.discord,showTwitter:i.twitter})]})}var y3=G1.div`
538
+ `;import{jsx as b3}from"react/jsx-runtime";var k3=()=>{let{app:i}=g();return i!=null&&i.logoUrl?b3("div",{children:b3("img",{src:i.logoUrl,alt:`${i==null?void 0:i.name} logo`,style:{objectFit:"contain",width:"200px",height:"80px"}})}):null};import{isMobile as g3}from"react-device-detect";import{Fragment as X2,jsx as A,jsxs as a1}from"react/jsx-runtime";var M3=()=>{let{ready:i}=R(),{getAuthMeta:e,isLinking:o}=Z(),{app:a,navigate:r,options:l}=g(),s=l.email,f=l.sms,h=l.wallet,k=l.google,M=l.twitter,E=l.discord,x=h?0:1,[w,p]=M6(x),m=e(),P=(m==null?void 0:m.authorizationCode)&&(m==null?void 0:m.stateCode)&&(m==null?void 0:m.provider);w6(()=>{P?r("AWAITING_OAUTH_SCREEN"):o&&s?r("LINK_EMAIL_SCREEN"):o&&f?r("LINK_PHONE_SCREEN"):o&&h&&r("LINK_WALLET_SCREEN")},[i]);let S=w==0,X=w==1;return a1(X2,{children:[A(v,{},"header"),A(L6,{walletOnly:!s&&!f&&!k&&!M&&!E,hasTerms:!!((a==null?void 0:a.privacyPolicyUrl)||(a==null?void 0:a.termsAndConditionsUrl)),children:A(k3,{})}),a1(i1,{children:[h&&A(y6,{active:S,onClick:()=>p(0)}),(s||f)&&A(v6,{active:X,onClick:()=>p(1),email:s,sms:f,google:k,twitter:M,discord:E})]}),a&&A(l3,{app:a}),A(j,{protectedByPrivy:!0})]})};function y6(i){return a1(v3,{active:i.active,onClick:i.onClick,children:[A(y3,{active:i.active,children:A("h4",{children:"Connect Wallet"})}),i.active&&a1(X2,{children:[A(l2,{}),A(n2,{})]})]})}function v6(i){let e=i.google||i.discord||i.twitter&&!g3,o=i.email?"Email":"Phone";return a1(v3,{active:i.active,onClick:i.onClick,children:[A(y3,{active:i.active,children:a1("h4",{children:["Sign In with ",e?`${o} & Social`:o]})}),i.active&&i.email&&A(m2,{}),i.active&&i.sms&&!i.email&&A(k2,{}),i.active&&e&&A(x6,{google:i.google,twitter:i.twitter&&!g3,discord:i.discord})]})}function x6(i){return a1(X2,{children:[a1(Z6,{children:[A(w3,{}),A("p",{children:" Or "}),A(w3,{})]}),A(c3,{showGoogle:i.google,showDiscord:i.discord,showTwitter:i.twitter})]})}var y3=G1.div`
539
539
  font-weight: ${i=>i.active?600:500};
540
540
  color: ${i=>i.active?"inherit":"#6b7280"};
541
541
  display: flex;
@@ -588,15 +588,11 @@ Resources:
588
588
  // So...
589
589
  // - Wallet + other => 114px padding for logo, -24px on the top
590
590
  // - Wallet only => 176px padding for the logo, -24px on the top
591
+ // - Terms => 36px
591
592
  // Lastly, apply a 10px cheat upwards, which helps in particular for when
592
593
  // the logo is close to the top (mobile or full wallet-open design)
593
- margin-top: 28px;
594
- margin-bottom: 62px;
595
-
596
- ${({walletOnly:i})=>i&&`
597
- margin-top: 59px;
598
- margin-bottom: 93px;
599
- `}
594
+ margin-top: ${i=>`${28+(i.walletOnly?31:0)-(i.hasTerms?18:0)}px`};
595
+ margin-bottom: ${i=>`${60+(i.walletOnly?31:0)-(i.hasTerms?18:0)}px`};
600
596
  `;import{useEffect as A3,useState as w2}from"react";import M2 from"styled-components";import g2 from"styled-components";import{jsx as B1,jsxs as L3}from"react/jsx-runtime";var f1=({title:i,description:e,children:o,...a})=>L3(Z3,{...a,children:[B1("h3",{children:i}),typeof e=="string"?B1("p",{children:e}):null,o]}),x3=g2(f1)`
601
597
  margin-bottom: 24px;
602
598
  `,S1=({title:i,description:e,icon:o,children:a,...r})=>L3(A6,{...r,children:[o?B1(E6,{children:o}):null,B1("h3",{children:i}),typeof e=="string"?B1("p",{children:e}):null,a]}),Z3=g2.div`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privy-io/react-auth",
3
- "version": "1.10.0",
3
+ "version": "1.10.1",
4
4
  "description": "React client for the Privy Auth API",
5
5
  "keywords": [
6
6
  "authentication",