@privy-io/react-auth 1.10.0-beta.10 → 1.10.0-beta.11

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 a2=Object.defineProperty;var d5=Object.getOwnPropertyDescriptor;var c5=Object.getOwnPropertyNames;var p5=Object.getPrototypeOf,h5=Object.prototype.hasOwnProperty;var f5=(i,e)=>{for(var o in e)a2(i,o,{get:e[o],enumerable:!0})},v4=(i,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of c5(e))!h5.call(i,r)&&r!==o&&a2(i,r,{get:()=>e[r],enumerable:!(a=d5(e,r))||a.enumerable});return i};var y=(i,e,o)=>(o=i!=null?C5(p5(i)):{},v4(e||!i||!i.__esModule?a2(o,"default",{value:i,enumerable:!0}):o,i)),u5=i=>v4(a2({},"__esModule",{value:!0}),i);var _6={};f5(_6,{PrivyProvider:()=>n5,VERSION:()=>n2,getAccessToken:()=>l5,usePrivy:()=>I});module.exports=u5(_6);var G=require("react");var d2=y(require("axios"));var x4=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}]`:""}`}},r2=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(!x4.default.isAxiosError(i))return j(i);if(!i.response)return new r2("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new r2(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 Z4="1.10.0-beta.10";var L4="https://api.privy.io/v0",E4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",l2="4df5e2316331463a9130964bd6078dfa",A4=1e4,S1=1200,P4=365*24*60*60,n2=Z4,_4="ES256",S4="privy.io",T1="privy:token",s2="privy:refresh_token",C2="privy:wallet_type",T4="walletconnect";var c2=class{constructor(e,o,a){this.appId=e,this.sdkVersion=n2,this.session=o,this.defaults=a}async get(e,o){try{return await d2.default.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw P(a)}}async post(e,o,a){try{return await d2.default.post(e,o,this.buildConfig(a))}catch(r){throw P(r)}}async delete(e,o){try{return await d2.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 I1=y(require("jose"));var h1=class{static parse(e){try{return new h1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=I1.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 I1.importSPKI(e,_4);try{return await I1.jwtVerify(this.value,r,{issuer:S4,audience:o,clockTolerance:a}),!0}catch{return!1}}};var f1=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 B2=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]}},j2=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 b5(){return typeof window<"u"&&window.localStorage?new j2:new B2}var V=b5();function y1(i){return new Date(i*1e3)}function k5(i){return i.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:y1(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:y1(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:y1(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:y1(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:y1(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:y1(e.verified_at)};default:throw new d("Unrecognized account type")}})}function R1(i,e){return i.sort((o,a)=>a.verifiedAt.getTime()-o.verifiedAt.getTime()),i.find(o=>o.type===e)}function l1(i){if(!i)return null;let e=k5(i.linked_accounts),o=R1(e,"wallet"),a=R1(e,"email"),r=R1(e,"phone"),n=R1(e,"google_oauth"),C=R1(e,"twitter_oauth"),f=R1(e,"discord_oauth");return{id:i.id,createdAt:y1(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:f&&{subject:f.subject,username:f.username,email:f.email}}}var I4=()=>"/api/v1/sessions",R4=()=>"/api/v1/sessions/logout",W4=()=>"/api/v1/sessions/fork",O4=()=>"/api/v1/siwe/init",N4=()=>"/api/v1/siwe/authenticate",U4=()=>"/api/v1/siwe/link",D4=()=>"/api/v1/passwordless/init",F4=()=>"/api/v1/passwordless/authenticate",H4=()=>"/api/v1/passwordless/link",V4=()=>"/api/v1/passwordless_sms/init",G4=()=>"/api/v1/passwordless_sms/authenticate",B4=()=>"/api/v1/passwordless_sms/link",j4=()=>"/api/v1/oauth/init",z4=()=>"/api/v1/oauth/authenticate",$4=()=>"/api/v1/oauth/link",K4=()=>"/api/v1/siwe/unlink",q4=()=>"/api/v1/passwordless/unlink",Y4=()=>"/api/v1/passwordless_sms/unlink",J4=()=>"/api/v1/oauth/unlink";var g5=30,p2=class{constructor(){this.authenticateOnce=new f1(async e=>this._authenticate(e)),this.linkOnce=new f1(async e=>this._link(e)),this.refreshOnce=new f1(this._refresh.bind(this)),this.destroyOnce=new f1(this._destroy.bind(this)),this.forkSessionOnce=new f1(this._forkSession.bind(this))}get token(){try{let e=V.get(T1);return typeof e=="string"?new h1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=V.get(s2);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=h1.parse(this.token);return e!==null&&!e.isExpired(g5)}async hasValidToken(e,o,a=0){let r=h1.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),l1(r)}catch(o){throw console.warn("Error authenticating session"),j(o)}}async _link(e){try{let o=await e.link();return l1(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(I4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),l1(a.data.user)}catch(a){throw j(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(R4(),{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(W4(),{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)}storeToken(e){typeof e=="string"?V.put(T1,e):V.del(T1)}storeRefreshToken(e){typeof e=="string"?V.put(s2,e):V.del(s2)}};var t3=require("@ethersproject/address"),K2=y(require("@walletconnect/web3-provider"));var X4=require("@ethersproject/logger");var W1=class extends B{constructor(){super("Wallet timeout");this.type="wallet_error"}},h2=i=>{if(i instanceof B)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new O1(i);return i.code===X4.ErrorCode.ACTION_REJECTED&&(e.details=v1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new O1(i):new B("Unknown connector error",i)},z2=class extends q{constructor(o,a,r){super(o);this.type="provider_error";this.code=a,this.data=r}},O1=class extends z2{constructor(o){var n,C,f;let a=o;super(a.message,a.code,a.data);let r=Object.values(v1).find(u=>u.eipCode===a.code);this.details=r||v1.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=v1.E32002_CONNECTION_ALREADY_PENDING:this.details=v1.E32002_REQUEST_ALREADY_PENDING:(f=a.message)!=null&&f.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=v1.E32002_WALLET_LOCKED))}},M5={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}},w5={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}},y5={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}},v1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...y5,...w5},f2={...M5,...v1};var v5=12e4,$2=(i=new W1,e=v5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),N1=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),$2()]).catch(o=>{throw h2(o)})}},U1=class extends N1{constructor(o){super(o)}},u2=class extends N1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var e3=require("@ethersproject/providers");var Q4=["metamask","coinbase_wallet","wallet_connect"];var i3=y(require("@coinbase/wallet-sdk")),x5=()=>{let i=`https://mainnet.infura.io/v3/${l2}`,e=1;return new i3.default({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},q2=()=>{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},b2=()=>{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},m2=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,r,n,C,f)=>`${a} wants you to sign in with your Ethereum account:
1
+ "use strict";var C5=Object.create;var a2=Object.defineProperty;var d5=Object.getOwnPropertyDescriptor;var c5=Object.getOwnPropertyNames;var p5=Object.getPrototypeOf,h5=Object.prototype.hasOwnProperty;var f5=(i,e)=>{for(var o in e)a2(i,o,{get:e[o],enumerable:!0})},v4=(i,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of c5(e))!h5.call(i,r)&&r!==o&&a2(i,r,{get:()=>e[r],enumerable:!(a=d5(e,r))||a.enumerable});return i};var y=(i,e,o)=>(o=i!=null?C5(p5(i)):{},v4(e||!i||!i.__esModule?a2(o,"default",{value:i,enumerable:!0}):o,i)),u5=i=>v4(a2({},"__esModule",{value:!0}),i);var _6={};f5(_6,{PrivyProvider:()=>n5,VERSION:()=>n2,getAccessToken:()=>l5,usePrivy:()=>I});module.exports=u5(_6);var G=require("react");var d2=y(require("axios"));var x4=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}]`:""}`}},r2=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(!x4.default.isAxiosError(i))return j(i);if(!i.response)return new r2("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new r2(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 Z4="1.10.0-beta.11";var L4="https://api.privy.io/v0",E4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",l2="4df5e2316331463a9130964bd6078dfa",A4=1e4,S1=1200,P4=365*24*60*60,n2=Z4,_4="ES256",S4="privy.io",T1="privy:token",s2="privy:refresh_token",C2="privy:wallet_type",T4="walletconnect";var c2=class{constructor(e,o,a){this.appId=e,this.sdkVersion=n2,this.session=o,this.defaults=a}async get(e,o){try{return await d2.default.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw P(a)}}async post(e,o,a){try{return await d2.default.post(e,o,this.buildConfig(a))}catch(r){throw P(r)}}async delete(e,o){try{return await d2.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 I1=y(require("jose"));var h1=class{static parse(e){try{return new h1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=I1.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 I1.importSPKI(e,_4);try{return await I1.jwtVerify(this.value,r,{issuer:S4,audience:o,clockTolerance:a}),!0}catch{return!1}}};var f1=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 B2=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]}},j2=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 b5(){return typeof window<"u"&&window.localStorage?new j2:new B2}var V=b5();function y1(i){return new Date(i*1e3)}function k5(i){return i.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:y1(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:y1(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:y1(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:y1(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:y1(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:y1(e.verified_at)};default:throw new d("Unrecognized account type")}})}function R1(i,e){return i.sort((o,a)=>a.verifiedAt.getTime()-o.verifiedAt.getTime()),i.find(o=>o.type===e)}function l1(i){if(!i)return null;let e=k5(i.linked_accounts),o=R1(e,"wallet"),a=R1(e,"email"),r=R1(e,"phone"),n=R1(e,"google_oauth"),C=R1(e,"twitter_oauth"),f=R1(e,"discord_oauth");return{id:i.id,createdAt:y1(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:f&&{subject:f.subject,username:f.username,email:f.email}}}var I4=()=>"/api/v1/sessions",R4=()=>"/api/v1/sessions/logout",W4=()=>"/api/v1/sessions/fork",O4=()=>"/api/v1/siwe/init",N4=()=>"/api/v1/siwe/authenticate",U4=()=>"/api/v1/siwe/link",D4=()=>"/api/v1/passwordless/init",F4=()=>"/api/v1/passwordless/authenticate",H4=()=>"/api/v1/passwordless/link",V4=()=>"/api/v1/passwordless_sms/init",G4=()=>"/api/v1/passwordless_sms/authenticate",B4=()=>"/api/v1/passwordless_sms/link",j4=()=>"/api/v1/oauth/init",z4=()=>"/api/v1/oauth/authenticate",$4=()=>"/api/v1/oauth/link",K4=()=>"/api/v1/siwe/unlink",q4=()=>"/api/v1/passwordless/unlink",Y4=()=>"/api/v1/passwordless_sms/unlink",J4=()=>"/api/v1/oauth/unlink";var g5=30,p2=class{constructor(){this.authenticateOnce=new f1(async e=>this._authenticate(e)),this.linkOnce=new f1(async e=>this._link(e)),this.refreshOnce=new f1(this._refresh.bind(this)),this.destroyOnce=new f1(this._destroy.bind(this)),this.forkSessionOnce=new f1(this._forkSession.bind(this))}get token(){try{let e=V.get(T1);return typeof e=="string"?new h1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=V.get(s2);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=h1.parse(this.token);return e!==null&&!e.isExpired(g5)}async hasValidToken(e,o,a=0){let r=h1.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),l1(r)}catch(o){throw console.warn("Error authenticating session"),j(o)}}async _link(e){try{let o=await e.link();return l1(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(I4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),l1(a.data.user)}catch(a){throw j(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(R4(),{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(W4(),{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)}storeToken(e){typeof e=="string"?V.put(T1,e):V.del(T1)}storeRefreshToken(e){typeof e=="string"?V.put(s2,e):V.del(s2)}};var t3=require("@ethersproject/address"),K2=y(require("@walletconnect/web3-provider"));var X4=require("@ethersproject/logger");var W1=class extends B{constructor(){super("Wallet timeout");this.type="wallet_error"}},h2=i=>{if(i instanceof B)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new O1(i);return i.code===X4.ErrorCode.ACTION_REJECTED&&(e.details=v1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new O1(i):new B("Unknown connector error",i)},z2=class extends q{constructor(o,a,r){super(o);this.type="provider_error";this.code=a,this.data=r}},O1=class extends z2{constructor(o){var n,C,f;let a=o;super(a.message,a.code,a.data);let r=Object.values(v1).find(u=>u.eipCode===a.code);this.details=r||v1.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=v1.E32002_CONNECTION_ALREADY_PENDING:this.details=v1.E32002_REQUEST_ALREADY_PENDING:(f=a.message)!=null&&f.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=v1.E32002_WALLET_LOCKED))}},M5={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}},w5={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}},y5={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}},v1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...y5,...w5},f2={...M5,...v1};var v5=12e4,$2=(i=new W1,e=v5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),N1=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),$2()]).catch(o=>{throw h2(o)})}},U1=class extends N1{constructor(o){super(o)}},u2=class extends N1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var e3=require("@ethersproject/providers");var Q4=["metamask","coinbase_wallet","wallet_connect"];var i3=y(require("@coinbase/wallet-sdk")),x5=()=>{let i=`https://mainnet.infura.io/v3/${l2}`,e=1;return new i3.default({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},q2=()=>{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},b2=()=>{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},m2=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,r,n,C,f)=>`${a} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${f}
@@ -1356,4 +1356,4 @@ Resources:
1356
1356
  align-items: center;
1357
1357
  justify-content: center;
1358
1358
  height: 100%;
1359
- `;var r1=require("react/jsx-runtime");function E6(i){return typeof i=="string"&&i.length===25}var F2;function l5(){if(!F2){let i=V.get(T1);return Promise.resolve(i||null)}return F2.getAccessToken()}var n5=i=>{if(!E6(i.appId))throw new d("Cannot initialize the Privy provider with an invalid Privy app ID");let[e,o]=(0,G.useState)(null);return(0,G.useEffect)(()=>{F2=new k2({appId:i.appId,apiURL:E4}),o(F2)},[]),e===null?(0,r1.jsx)(r1.Fragment,{}):(0,r1.jsx)(P6,{...i,client:e})},A6=(i,e)=>{if(e)return{email:!1,sms:!1,wallet:!1,google:!1,twitter:!1,discord:!1,[e]:!0};let o=!!(i!=null&&i.emailAuth),a=!!(i!=null&&i.smsAuth);return o&&a&&(console.warn("Enabling both email and SMS passwordless is not currently supported. Disabling SMS."),a=!1),{email:o,sms:a,wallet:!!(i!=null&&i.walletAuth),google:!!(i!=null&&i.googleOAuth),twitter:!!(i!=null&&i.twitterOAuth),discord:!!(i!=null&&i.discordOAuth)}},P6=i=>{let e=i.client,[o,a]=(0,G.useState)(!1),[r,n]=(0,G.useState)(!1),[C,f]=(0,G.useState)(!1),[u,M]=(0,G.useState)(null),[x,T]=(0,G.useState)({accentColor:"#696ffd",theme:"System",emailAuth:!0,smsAuth:!1,walletAuth:!0,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null}),[E,w]=(0,G.useState)(null),[h,b]=(0,G.useState)(!1);(0,G.useEffect)(()=>{async function s(){let c=await e.getAppSettings();T(c)}s()},[]);let _=A6(x,E),S=()=>{let s=new URLSearchParams(window.location.search),c=s.get("privy_oauth_code"),$1=s.get("privy_oauth_state"),_1=s.get("privy_oauth_provider");c&&$1&&_1&&(e.startAuthFlow(new D1(_1,c,$1)),w(_1),a(!0))};(0,G.useEffect)(()=>{async function s(){S();let c=await e.getAuthenticatedUser();f(!!c),M(c),n(!0)}s()},[]),(0,G.useEffect)(()=>{r&&C&&u===null&&e.getAuthenticatedUser().then(M)},[r,C,u]);let c1={ready:r,authenticated:C,user:u,linkWallet:()=>{w("wallet"),b(!0),a(!0)},linkEmail:()=>{w("email"),b(!0),a(!0)},linkPhone:()=>{w("sms"),b(!0),a(!0)},linkGoogle:async()=>{await p1.initLoginWithOAuth("google")},linkTwitter:async()=>{await p1.initLoginWithOAuth("twitter")},linkDiscord:async()=>{await p1.initLoginWithOAuth("discord")},login:()=>{a(!0)},logout:async()=>{await e.logout(),M(null),f(!1),w(null),b(!1),a(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>e.connector.getEthereumProvider(),getEthersProvider:()=>new r5.Web3Provider(new U1(e.connector.getEthereumProvider())),getWeb3jsProvider:()=>new u2(e.connector.getEthereumProvider()),unlinkWallet:async s=>{let c=await e.unlinkWallet(s);return M(c),c},unlinkEmail:async s=>{let c=await e.unlinkEmail(s);return M(c),c},unlinkPhone:async s=>{let c=await e.unlinkPhone(s);return M(c),c},unlinkGoogle:async s=>{let c=await e.unlinkOAuth("google",s);return M(c),c},unlinkTwitter:async s=>{let c=await e.unlinkOAuth("twitter",s);return M(c),c},unlinkDiscord:async s=>{let c=await e.unlinkOAuth("discord",s);return M(c),c},forkSession:()=>e.forkSession()},p1={isLinking:h,getAuthFlow:()=>e.authFlow,getAuthMeta:()=>{var s;return(s=e.authFlow)==null?void 0:s.meta},closePrivyModal:()=>{var s;r&&C&&u&&((s=i.onSuccess)==null||s.call(i,u)),e.authFlow=void 0,w(null),b(!1),a(!1)},initLoginWithWallet:s=>{s||(s="metamask"),e.connector.walletType=s,e.startAuthFlow(new K1(e.connector))},initLoginWithOAuth:async s=>{e.startAuthFlow(new D1(s));let c=await e.authFlow.getAuthorizationUrl();c&&c.url&&window.location.assign(c.url)},loginWithOAuth:async()=>{if(!(e.authFlow instanceof D1))throw new d("Must initialize OAuth flow before calling loginWithOAuth");let c=await(r&&C?e.link():e.authenticate());M(c||u||null),f(!0)},loginWithWallet:async()=>{if(!(e.authFlow instanceof K1))throw new d("Must initialize SIWE flow first.");let s=await(h?e.link():e.authenticate());M(s||u||null),f(!0)},loginWithEmail:async s=>{let c=new q1(s);e.startAuthFlow(c),await c.sendCodeEmail()},loginWithSms:async s=>{let c=new Y1(s);e.startAuthFlow(c),await c.sendSmsCode()},resendEmailCode:async()=>{var s;await((s=e.authFlow)==null?void 0:s.sendCodeEmail())},resendSmsCode:async()=>{var s;await((s=e.authFlow)==null?void 0:s.sendSmsCode())},loginWithCode:async s=>{if(e.authFlow instanceof q1)e.authFlow.meta.emailCode=s.trim();else if(e.authFlow instanceof Y1)e.authFlow.meta.smsCode=s.trim();else throw new d("Must initialize a passwordless code flow first");let c=await(h?e.link():e.authenticate());M(c||u||null),f(!0)}};return(0,r1.jsxs)(J2.Provider,{value:c1,children:[i.children,(0,r1.jsx)(t4.Provider,{value:p1,children:(0,r1.jsx)(l3,{appSettings:x,options:_,visible:o,authenticated:C,children:o&&(0,r1.jsx)(a5,{})})})]})};0&&(module.exports={PrivyProvider,VERSION,getAccessToken,usePrivy});
1359
+ `;var r1=require("react/jsx-runtime");function E6(i){return typeof i=="string"&&i.length===25}var F2;function l5(){if(!F2){let i=V.get(T1);return Promise.resolve(i||null)}return F2.getAccessToken()}var n5=i=>{if(!E6(i.appId))throw new d("Cannot initialize the Privy provider with an invalid Privy app ID");let[e,o]=(0,G.useState)(null);return(0,G.useEffect)(()=>{F2=new k2({appId:i.appId,apiURL:E4}),o(F2)},[]),e===null?(0,r1.jsx)(r1.Fragment,{}):(0,r1.jsx)(P6,{...i,client:e})},A6=(i,e)=>{if(e)return{email:!1,sms:!1,wallet:!1,google:!1,twitter:!1,discord:!1,[e]:!0};let o=!!(i!=null&&i.emailAuth),a=!!(i!=null&&i.smsAuth);return o&&a&&(console.warn("Enabling both email and SMS passwordless is not currently supported. Disabling SMS."),a=!1),{email:o,sms:a,wallet:!!(i!=null&&i.walletAuth),google:!!(i!=null&&i.googleOAuth),twitter:!!(i!=null&&i.twitterOAuth),discord:!!(i!=null&&i.discordOAuth)}},P6=i=>{let e=i.client,[o,a]=(0,G.useState)(!1),[r,n]=(0,G.useState)(!1),[C,f]=(0,G.useState)(!1),[u,M]=(0,G.useState)(null),[x,T]=(0,G.useState)({accentColor:"#696ffd",theme:"System",emailAuth:!0,smsAuth:!1,walletAuth:!0,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null}),[E,w]=(0,G.useState)(null),[h,b]=(0,G.useState)(!1);(0,G.useEffect)(()=>{async function s(){let c=await e.getAppSettings();T(c)}s()},[]);let _=A6(x,E),S=()=>{let s=new URLSearchParams(window.location.search),c=s.get("privy_oauth_code"),$1=s.get("privy_oauth_state"),_1=s.get("privy_oauth_provider");c&&$1&&_1&&(e.startAuthFlow(new D1(_1,c,$1)),w(_1),a(!0))};(0,G.useEffect)(()=>{async function s(){S();let c=await e.getAuthenticatedUser();f(!!c),M(c),n(!0)}s()},[]),(0,G.useEffect)(()=>{r&&C&&u===null&&e.getAuthenticatedUser().then(M)},[r,C,u]);let c1={ready:r,authenticated:C,user:u,linkWallet:()=>{w("wallet"),b(!0),a(!0)},linkEmail:()=>{w("email"),b(!0),a(!0)},linkPhone:()=>{w("sms"),b(!0),a(!0)},linkGoogle:async()=>{await p1.initLoginWithOAuth("google")},linkTwitter:async()=>{await p1.initLoginWithOAuth("twitter")},linkDiscord:async()=>{await p1.initLoginWithOAuth("discord")},login:()=>{if(r&&C){console.warn("Attempted to log in, but user is already logged in. Use a `link` helper instead.");return}a(!0)},logout:async()=>{await e.logout(),M(null),f(!1),w(null),b(!1),a(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>e.connector.getEthereumProvider(),getEthersProvider:()=>new r5.Web3Provider(new U1(e.connector.getEthereumProvider())),getWeb3jsProvider:()=>new u2(e.connector.getEthereumProvider()),unlinkWallet:async s=>{let c=await e.unlinkWallet(s);return M(c),c},unlinkEmail:async s=>{let c=await e.unlinkEmail(s);return M(c),c},unlinkPhone:async s=>{let c=await e.unlinkPhone(s);return M(c),c},unlinkGoogle:async s=>{let c=await e.unlinkOAuth("google",s);return M(c),c},unlinkTwitter:async s=>{let c=await e.unlinkOAuth("twitter",s);return M(c),c},unlinkDiscord:async s=>{let c=await e.unlinkOAuth("discord",s);return M(c),c},forkSession:()=>e.forkSession()},p1={isLinking:h,getAuthFlow:()=>e.authFlow,getAuthMeta:()=>{var s;return(s=e.authFlow)==null?void 0:s.meta},closePrivyModal:()=>{var s;r&&C&&u&&((s=i.onSuccess)==null||s.call(i,u)),e.authFlow=void 0,w(null),b(!1),a(!1)},initLoginWithWallet:s=>{s||(s="metamask"),e.connector.walletType=s,e.startAuthFlow(new K1(e.connector))},initLoginWithOAuth:async s=>{e.startAuthFlow(new D1(s));let c=await e.authFlow.getAuthorizationUrl();c&&c.url&&window.location.assign(c.url)},loginWithOAuth:async()=>{if(!(e.authFlow instanceof D1))throw new d("Must initialize OAuth flow before calling loginWithOAuth");let c=await(r&&C?e.link():e.authenticate());M(c||u||null),f(!0)},loginWithWallet:async()=>{if(!(e.authFlow instanceof K1))throw new d("Must initialize SIWE flow first.");let s=await(h?e.link():e.authenticate());M(s||u||null),f(!0)},loginWithEmail:async s=>{let c=new q1(s);e.startAuthFlow(c),await c.sendCodeEmail()},loginWithSms:async s=>{let c=new Y1(s);e.startAuthFlow(c),await c.sendSmsCode()},resendEmailCode:async()=>{var s;await((s=e.authFlow)==null?void 0:s.sendCodeEmail())},resendSmsCode:async()=>{var s;await((s=e.authFlow)==null?void 0:s.sendSmsCode())},loginWithCode:async s=>{if(e.authFlow instanceof q1)e.authFlow.meta.emailCode=s.trim();else if(e.authFlow instanceof Y1)e.authFlow.meta.smsCode=s.trim();else throw new d("Must initialize a passwordless code flow first");let c=await(h?e.link():e.authenticate());M(c||u||null),f(!0)}};return(0,r1.jsxs)(J2.Provider,{value:c1,children:[i.children,(0,r1.jsx)(t4.Provider,{value:p1,children:(0,r1.jsx)(l3,{appSettings:x,options:_,visible:o,authenticated:C,children:o&&(0,r1.jsx)(a5,{})})})]})};0&&(module.exports={PrivyProvider,VERSION,getAccessToken,usePrivy});
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import{useEffect as A2,useState as l1}from"react";import R2 from"axios";import r5 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}]`:""}`}},j1=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"}},Z=i=>{if(i instanceof F)return i;if(!r5.isAxiosError(i))return U(i);if(!i.response)return new j1("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new j1(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 d4="1.10.0-beta.10";var c4="https://api.privy.io/v0",p4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",z1="4df5e2316331463a9130964bd6078dfa",h4=1e4,m1=1200,f4=365*24*60*60,I2=d4,u4="ES256",m4="privy.io",b1="privy:token",$1="privy:refresh_token",K1="privy:wallet_type",b4="walletconnect";var q1=class{constructor(e,o,a){this.appId=e,this.sdkVersion=I2,this.session=o,this.defaults=a}async get(e,o){try{return await R2.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw Z(a)}}async post(e,o,a){try{return await R2.post(e,o,this.buildConfig(a))}catch(r){throw Z(r)}}async delete(e,o){try{return await R2.delete(e,this.buildConfig(o))}catch(a){throw Z(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 k1 from"jose";var Q=class{static parse(e){try{return new Q(e)}catch{return null}}constructor(e){this.value=e,this._decoded=k1.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 k1.importSPKI(e,u4);try{return await k1.jwtVerify(this.value,r,{issuer:m4,audience:o,clockTolerance:a}),!0}catch{return!1}}};var t1=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 W2=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]}},O2=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 n5(){return typeof window<"u"&&window.localStorage?new O2:new W2}var W=n5();function n1(i){return new Date(i*1e3)}function s5(i){return i.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:n1(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:n1(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:n1(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:n1(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:n1(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:n1(e.verified_at)};default:throw new C("Unrecognized account type")}})}function g1(i,e){return i.sort((o,a)=>a.verifiedAt.getTime()-o.verifiedAt.getTime()),i.find(o=>o.type===e)}function j(i){if(!i)return null;let e=s5(i.linked_accounts),o=g1(e,"wallet"),a=g1(e,"email"),r=g1(e,"phone"),l=g1(e,"google_oauth"),s=g1(e,"twitter_oauth"),h=g1(e,"discord_oauth");return{id:i.id,createdAt:n1(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:h&&{subject:h.subject,username:h.username,email:h.email}}}var k4=()=>"/api/v1/sessions",g4=()=>"/api/v1/sessions/logout",M4=()=>"/api/v1/sessions/fork",w4=()=>"/api/v1/siwe/init",y4=()=>"/api/v1/siwe/authenticate",v4=()=>"/api/v1/siwe/link",x4=()=>"/api/v1/passwordless/init",Z4=()=>"/api/v1/passwordless/authenticate",L4=()=>"/api/v1/passwordless/link",E4=()=>"/api/v1/passwordless_sms/init",A4=()=>"/api/v1/passwordless_sms/authenticate",P4=()=>"/api/v1/passwordless_sms/link",_4=()=>"/api/v1/oauth/init",S4=()=>"/api/v1/oauth/authenticate",T4=()=>"/api/v1/oauth/link",I4=()=>"/api/v1/siwe/unlink",R4=()=>"/api/v1/passwordless/unlink",W4=()=>"/api/v1/passwordless_sms/unlink",O4=()=>"/api/v1/oauth/unlink";var C5=30,Y1=class{constructor(){this.authenticateOnce=new t1(async e=>this._authenticate(e)),this.linkOnce=new t1(async e=>this._link(e)),this.refreshOnce=new t1(this._refresh.bind(this)),this.destroyOnce=new t1(this._destroy.bind(this)),this.forkSessionOnce=new t1(this._forkSession.bind(this))}get token(){try{let e=W.get(b1);return typeof e=="string"?new Q(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=W.get($1);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=Q.parse(this.token);return e!==null&&!e.isExpired(C5)}async hasValidToken(e,o,a=0){let r=Q.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),j(r)}catch(o){throw console.warn("Error authenticating session"),U(o)}}async _link(e){try{let o=await e.link();return j(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(k4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),j(a.data.user)}catch(a){throw U(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(g4(),{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(M4(),{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)}storeToken(e){typeof e=="string"?W.put(b1,e):W.del(b1)}storeRefreshToken(e){typeof e=="string"?W.put($1,e):W.del($1)}};import{getAddress as u5}from"@ethersproject/address";import U4 from"@walletconnect/web3-provider";import{ErrorCode as d5}from"@ethersproject/logger";var M1=class extends N{constructor(){super("Wallet timeout");this.type="wallet_error"}},J1=i=>{if(i instanceof N)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new w1(i);return i.code===d5.ACTION_REJECTED&&(e.details=s1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new w1(i):new N("Unknown connector error",i)},N2=class extends F{constructor(o,a,r){super(o);this.type="provider_error";this.code=a,this.data=r}},w1=class extends N2{constructor(o){var l,s,h;let a=o;super(a.message,a.code,a.data);let r=Object.values(s1).find(f=>f.eipCode===a.code);this.details=r||s1.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=s1.E32002_CONNECTION_ALREADY_PENDING:this.details=s1.E32002_REQUEST_ALREADY_PENDING:(h=a.message)!=null&&h.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=s1.E32002_WALLET_LOCKED))}},c5={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}},p5={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}},h5={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}},s1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...h5,...p5},X1={...c5,...s1};var f5=12e4,U2=(i=new M1,e=f5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),y1=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),U2()]).catch(o=>{throw J1(o)})}},v1=class extends y1{constructor(o){super(o)}},Q1=class extends y1{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 m5}from"@ethersproject/providers";var N4=["metamask","coinbase_wallet","wallet_connect"];import b5 from"@coinbase/wallet-sdk";var k5=()=>{let i=`https://mainnet.infura.io/v3/${z1}`,e=1;return new b5({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},D2=()=>{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},e2=()=>{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},t2=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,r,l,s,h)=>`${a} wants you to sign in with your Ethereum account:
1
+ import{useEffect as A2,useState as l1}from"react";import R2 from"axios";import r5 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}]`:""}`}},j1=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"}},Z=i=>{if(i instanceof F)return i;if(!r5.isAxiosError(i))return U(i);if(!i.response)return new j1("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new j1(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 d4="1.10.0-beta.11";var c4="https://api.privy.io/v0",p4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",z1="4df5e2316331463a9130964bd6078dfa",h4=1e4,m1=1200,f4=365*24*60*60,I2=d4,u4="ES256",m4="privy.io",b1="privy:token",$1="privy:refresh_token",K1="privy:wallet_type",b4="walletconnect";var q1=class{constructor(e,o,a){this.appId=e,this.sdkVersion=I2,this.session=o,this.defaults=a}async get(e,o){try{return await R2.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw Z(a)}}async post(e,o,a){try{return await R2.post(e,o,this.buildConfig(a))}catch(r){throw Z(r)}}async delete(e,o){try{return await R2.delete(e,this.buildConfig(o))}catch(a){throw Z(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 k1 from"jose";var Q=class{static parse(e){try{return new Q(e)}catch{return null}}constructor(e){this.value=e,this._decoded=k1.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 k1.importSPKI(e,u4);try{return await k1.jwtVerify(this.value,r,{issuer:m4,audience:o,clockTolerance:a}),!0}catch{return!1}}};var t1=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 W2=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]}},O2=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 n5(){return typeof window<"u"&&window.localStorage?new O2:new W2}var W=n5();function n1(i){return new Date(i*1e3)}function s5(i){return i.map(e=>{switch(e.type){case"wallet":return{address:e.address,type:e.type,verifiedAt:n1(e.verified_at),chainType:e.chain_type};case"email":return{address:e.address,type:e.type,verifiedAt:n1(e.verified_at)};case"phone":return{number:e.phoneNumber,type:e.type,verifiedAt:n1(e.verified_at)};case"google_oauth":return{subject:e.subject,email:e.email,name:e.name,type:e.type,verifiedAt:n1(e.verified_at)};case"twitter_oauth":return{subject:e.subject,username:e.username,name:e.name,type:e.type,verifiedAt:n1(e.verified_at)};case"discord_oauth":return{subject:e.subject,username:e.username,email:e.email,type:e.type,verifiedAt:n1(e.verified_at)};default:throw new C("Unrecognized account type")}})}function g1(i,e){return i.sort((o,a)=>a.verifiedAt.getTime()-o.verifiedAt.getTime()),i.find(o=>o.type===e)}function j(i){if(!i)return null;let e=s5(i.linked_accounts),o=g1(e,"wallet"),a=g1(e,"email"),r=g1(e,"phone"),l=g1(e,"google_oauth"),s=g1(e,"twitter_oauth"),h=g1(e,"discord_oauth");return{id:i.id,createdAt:n1(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:h&&{subject:h.subject,username:h.username,email:h.email}}}var k4=()=>"/api/v1/sessions",g4=()=>"/api/v1/sessions/logout",M4=()=>"/api/v1/sessions/fork",w4=()=>"/api/v1/siwe/init",y4=()=>"/api/v1/siwe/authenticate",v4=()=>"/api/v1/siwe/link",x4=()=>"/api/v1/passwordless/init",Z4=()=>"/api/v1/passwordless/authenticate",L4=()=>"/api/v1/passwordless/link",E4=()=>"/api/v1/passwordless_sms/init",A4=()=>"/api/v1/passwordless_sms/authenticate",P4=()=>"/api/v1/passwordless_sms/link",_4=()=>"/api/v1/oauth/init",S4=()=>"/api/v1/oauth/authenticate",T4=()=>"/api/v1/oauth/link",I4=()=>"/api/v1/siwe/unlink",R4=()=>"/api/v1/passwordless/unlink",W4=()=>"/api/v1/passwordless_sms/unlink",O4=()=>"/api/v1/oauth/unlink";var C5=30,Y1=class{constructor(){this.authenticateOnce=new t1(async e=>this._authenticate(e)),this.linkOnce=new t1(async e=>this._link(e)),this.refreshOnce=new t1(this._refresh.bind(this)),this.destroyOnce=new t1(this._destroy.bind(this)),this.forkSessionOnce=new t1(this._forkSession.bind(this))}get token(){try{let e=W.get(b1);return typeof e=="string"?new Q(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=W.get($1);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=Q.parse(this.token);return e!==null&&!e.isExpired(C5)}async hasValidToken(e,o,a=0){let r=Q.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),j(r)}catch(o){throw console.warn("Error authenticating session"),U(o)}}async _link(e){try{let o=await e.link();return j(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(k4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),j(a.data.user)}catch(a){throw U(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(g4(),{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(M4(),{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)}storeToken(e){typeof e=="string"?W.put(b1,e):W.del(b1)}storeRefreshToken(e){typeof e=="string"?W.put($1,e):W.del($1)}};import{getAddress as u5}from"@ethersproject/address";import U4 from"@walletconnect/web3-provider";import{ErrorCode as d5}from"@ethersproject/logger";var M1=class extends N{constructor(){super("Wallet timeout");this.type="wallet_error"}},J1=i=>{if(i instanceof N)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new w1(i);return i.code===d5.ACTION_REJECTED&&(e.details=s1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new w1(i):new N("Unknown connector error",i)},N2=class extends F{constructor(o,a,r){super(o);this.type="provider_error";this.code=a,this.data=r}},w1=class extends N2{constructor(o){var l,s,h;let a=o;super(a.message,a.code,a.data);let r=Object.values(s1).find(f=>f.eipCode===a.code);this.details=r||s1.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=s1.E32002_CONNECTION_ALREADY_PENDING:this.details=s1.E32002_REQUEST_ALREADY_PENDING:(h=a.message)!=null&&h.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=s1.E32002_WALLET_LOCKED))}},c5={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}},p5={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}},h5={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}},s1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...h5,...p5},X1={...c5,...s1};var f5=12e4,U2=(i=new M1,e=f5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),y1=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),U2()]).catch(o=>{throw J1(o)})}},v1=class extends y1{constructor(o){super(o)}},Q1=class extends y1{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 m5}from"@ethersproject/providers";var N4=["metamask","coinbase_wallet","wallet_connect"];import b5 from"@coinbase/wallet-sdk";var k5=()=>{let i=`https://mainnet.infura.io/v3/${z1}`,e=1;return new b5({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},D2=()=>{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},e2=()=>{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},t2=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,r,l,s,h)=>`${a} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${h}
@@ -1356,4 +1356,4 @@ Resources:
1356
1356
  align-items: center;
1357
1357
  justify-content: center;
1358
1358
  height: 100%;
1359
- `;import{Fragment as M7,jsx as B1,jsxs as w7}from"react/jsx-runtime";function u7(i){return typeof i=="string"&&i.length===25}var P2;function m7(){if(!P2){let i=W.get(b1);return Promise.resolve(i||null)}return P2.getAccessToken()}var b7=i=>{if(!u7(i.appId))throw new C("Cannot initialize the Privy provider with an invalid Privy app ID");let[e,o]=l1(null);return A2(()=>{P2=new i2({appId:i.appId,apiURL:p4}),o(P2)},[]),e===null?B1(M7,{}):B1(g7,{...i,client:e})},k7=(i,e)=>{if(e)return{email:!1,sms:!1,wallet:!1,google:!1,twitter:!1,discord:!1,[e]:!0};let o=!!(i!=null&&i.emailAuth),a=!!(i!=null&&i.smsAuth);return o&&a&&(console.warn("Enabling both email and SMS passwordless is not currently supported. Disabling SMS."),a=!1),{email:o,sms:a,wallet:!!(i!=null&&i.walletAuth),google:!!(i!=null&&i.googleOAuth),twitter:!!(i!=null&&i.twitterOAuth),discord:!!(i!=null&&i.discordOAuth)}},g7=i=>{let e=i.client,[o,a]=l1(!1),[r,l]=l1(!1),[s,h]=l1(!1),[f,g]=l1(null),[w,_]=l1({accentColor:"#696ffd",theme:"System",emailAuth:!0,smsAuth:!1,walletAuth:!0,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null}),[v,M]=l1(null),[p,m]=l1(!1);A2(()=>{async function n(){let c=await e.getAppSettings();_(c)}n()},[]);let A=k7(w,v),P=()=>{let n=new URLSearchParams(window.location.search),c=n.get("privy_oauth_code"),W1=n.get("privy_oauth_state"),u1=n.get("privy_oauth_provider");c&&W1&&u1&&(e.startAuthFlow(new x1(u1,c,W1)),M(u1),a(!0))};A2(()=>{async function n(){P();let c=await e.getAuthenticatedUser();h(!!c),g(c),l(!0)}n()},[]),A2(()=>{r&&s&&f===null&&e.getAuthenticatedUser().then(g)},[r,s,f]);let J={ready:r,authenticated:s,user:f,linkWallet:()=>{M("wallet"),m(!0),a(!0)},linkEmail:()=>{M("email"),m(!0),a(!0)},linkPhone:()=>{M("sms"),m(!0),a(!0)},linkGoogle:async()=>{await X.initLoginWithOAuth("google")},linkTwitter:async()=>{await X.initLoginWithOAuth("twitter")},linkDiscord:async()=>{await X.initLoginWithOAuth("discord")},login:()=>{a(!0)},logout:async()=>{await e.logout(),g(null),h(!1),M(null),m(!1),a(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>e.connector.getEthereumProvider(),getEthersProvider:()=>new f7(new v1(e.connector.getEthereumProvider())),getWeb3jsProvider:()=>new Q1(e.connector.getEthereumProvider()),unlinkWallet:async n=>{let c=await e.unlinkWallet(n);return g(c),c},unlinkEmail:async n=>{let c=await e.unlinkEmail(n);return g(c),c},unlinkPhone:async n=>{let c=await e.unlinkPhone(n);return g(c),c},unlinkGoogle:async n=>{let c=await e.unlinkOAuth("google",n);return g(c),c},unlinkTwitter:async n=>{let c=await e.unlinkOAuth("twitter",n);return g(c),c},unlinkDiscord:async n=>{let c=await e.unlinkOAuth("discord",n);return g(c),c},forkSession:()=>e.forkSession()},X={isLinking:p,getAuthFlow:()=>e.authFlow,getAuthMeta:()=>{var n;return(n=e.authFlow)==null?void 0:n.meta},closePrivyModal:()=>{var n;r&&s&&f&&((n=i.onSuccess)==null||n.call(i,f)),e.authFlow=void 0,M(null),m(!1),a(!1)},initLoginWithWallet:n=>{n||(n="metamask"),e.connector.walletType=n,e.startAuthFlow(new O1(e.connector))},initLoginWithOAuth:async n=>{e.startAuthFlow(new x1(n));let c=await e.authFlow.getAuthorizationUrl();c&&c.url&&window.location.assign(c.url)},loginWithOAuth:async()=>{if(!(e.authFlow instanceof x1))throw new C("Must initialize OAuth flow before calling loginWithOAuth");let c=await(r&&s?e.link():e.authenticate());g(c||f||null),h(!0)},loginWithWallet:async()=>{if(!(e.authFlow instanceof O1))throw new C("Must initialize SIWE flow first.");let n=await(p?e.link():e.authenticate());g(n||f||null),h(!0)},loginWithEmail:async n=>{let c=new N1(n);e.startAuthFlow(c),await c.sendCodeEmail()},loginWithSms:async n=>{let c=new U1(n);e.startAuthFlow(c),await c.sendSmsCode()},resendEmailCode:async()=>{var n;await((n=e.authFlow)==null?void 0:n.sendCodeEmail())},resendSmsCode:async()=>{var n;await((n=e.authFlow)==null?void 0:n.sendSmsCode())},loginWithCode:async n=>{if(e.authFlow instanceof N1)e.authFlow.meta.emailCode=n.trim();else if(e.authFlow instanceof U1)e.authFlow.meta.smsCode=n.trim();else throw new C("Must initialize a passwordless code flow first");let c=await(p?e.link():e.authenticate());g(c||f||null),h(!0)}};return w7(H2.Provider,{value:J,children:[i.children,B1(V2.Provider,{value:X,children:B1(G4,{appSettings:w,options:A,visible:o,authenticated:s,children:o&&B1(o5,{})})})]})};export{b7 as PrivyProvider,I2 as VERSION,m7 as getAccessToken,I as usePrivy};
1359
+ `;import{Fragment as M7,jsx as B1,jsxs as w7}from"react/jsx-runtime";function u7(i){return typeof i=="string"&&i.length===25}var P2;function m7(){if(!P2){let i=W.get(b1);return Promise.resolve(i||null)}return P2.getAccessToken()}var b7=i=>{if(!u7(i.appId))throw new C("Cannot initialize the Privy provider with an invalid Privy app ID");let[e,o]=l1(null);return A2(()=>{P2=new i2({appId:i.appId,apiURL:p4}),o(P2)},[]),e===null?B1(M7,{}):B1(g7,{...i,client:e})},k7=(i,e)=>{if(e)return{email:!1,sms:!1,wallet:!1,google:!1,twitter:!1,discord:!1,[e]:!0};let o=!!(i!=null&&i.emailAuth),a=!!(i!=null&&i.smsAuth);return o&&a&&(console.warn("Enabling both email and SMS passwordless is not currently supported. Disabling SMS."),a=!1),{email:o,sms:a,wallet:!!(i!=null&&i.walletAuth),google:!!(i!=null&&i.googleOAuth),twitter:!!(i!=null&&i.twitterOAuth),discord:!!(i!=null&&i.discordOAuth)}},g7=i=>{let e=i.client,[o,a]=l1(!1),[r,l]=l1(!1),[s,h]=l1(!1),[f,g]=l1(null),[w,_]=l1({accentColor:"#696ffd",theme:"System",emailAuth:!0,smsAuth:!1,walletAuth:!0,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null}),[v,M]=l1(null),[p,m]=l1(!1);A2(()=>{async function n(){let c=await e.getAppSettings();_(c)}n()},[]);let A=k7(w,v),P=()=>{let n=new URLSearchParams(window.location.search),c=n.get("privy_oauth_code"),W1=n.get("privy_oauth_state"),u1=n.get("privy_oauth_provider");c&&W1&&u1&&(e.startAuthFlow(new x1(u1,c,W1)),M(u1),a(!0))};A2(()=>{async function n(){P();let c=await e.getAuthenticatedUser();h(!!c),g(c),l(!0)}n()},[]),A2(()=>{r&&s&&f===null&&e.getAuthenticatedUser().then(g)},[r,s,f]);let J={ready:r,authenticated:s,user:f,linkWallet:()=>{M("wallet"),m(!0),a(!0)},linkEmail:()=>{M("email"),m(!0),a(!0)},linkPhone:()=>{M("sms"),m(!0),a(!0)},linkGoogle:async()=>{await X.initLoginWithOAuth("google")},linkTwitter:async()=>{await X.initLoginWithOAuth("twitter")},linkDiscord:async()=>{await X.initLoginWithOAuth("discord")},login:()=>{if(r&&s){console.warn("Attempted to log in, but user is already logged in. Use a `link` helper instead.");return}a(!0)},logout:async()=>{await e.logout(),g(null),h(!1),M(null),m(!1),a(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>e.connector.getEthereumProvider(),getEthersProvider:()=>new f7(new v1(e.connector.getEthereumProvider())),getWeb3jsProvider:()=>new Q1(e.connector.getEthereumProvider()),unlinkWallet:async n=>{let c=await e.unlinkWallet(n);return g(c),c},unlinkEmail:async n=>{let c=await e.unlinkEmail(n);return g(c),c},unlinkPhone:async n=>{let c=await e.unlinkPhone(n);return g(c),c},unlinkGoogle:async n=>{let c=await e.unlinkOAuth("google",n);return g(c),c},unlinkTwitter:async n=>{let c=await e.unlinkOAuth("twitter",n);return g(c),c},unlinkDiscord:async n=>{let c=await e.unlinkOAuth("discord",n);return g(c),c},forkSession:()=>e.forkSession()},X={isLinking:p,getAuthFlow:()=>e.authFlow,getAuthMeta:()=>{var n;return(n=e.authFlow)==null?void 0:n.meta},closePrivyModal:()=>{var n;r&&s&&f&&((n=i.onSuccess)==null||n.call(i,f)),e.authFlow=void 0,M(null),m(!1),a(!1)},initLoginWithWallet:n=>{n||(n="metamask"),e.connector.walletType=n,e.startAuthFlow(new O1(e.connector))},initLoginWithOAuth:async n=>{e.startAuthFlow(new x1(n));let c=await e.authFlow.getAuthorizationUrl();c&&c.url&&window.location.assign(c.url)},loginWithOAuth:async()=>{if(!(e.authFlow instanceof x1))throw new C("Must initialize OAuth flow before calling loginWithOAuth");let c=await(r&&s?e.link():e.authenticate());g(c||f||null),h(!0)},loginWithWallet:async()=>{if(!(e.authFlow instanceof O1))throw new C("Must initialize SIWE flow first.");let n=await(p?e.link():e.authenticate());g(n||f||null),h(!0)},loginWithEmail:async n=>{let c=new N1(n);e.startAuthFlow(c),await c.sendCodeEmail()},loginWithSms:async n=>{let c=new U1(n);e.startAuthFlow(c),await c.sendSmsCode()},resendEmailCode:async()=>{var n;await((n=e.authFlow)==null?void 0:n.sendCodeEmail())},resendSmsCode:async()=>{var n;await((n=e.authFlow)==null?void 0:n.sendSmsCode())},loginWithCode:async n=>{if(e.authFlow instanceof N1)e.authFlow.meta.emailCode=n.trim();else if(e.authFlow instanceof U1)e.authFlow.meta.smsCode=n.trim();else throw new C("Must initialize a passwordless code flow first");let c=await(p?e.link():e.authenticate());g(c||f||null),h(!0)}};return w7(H2.Provider,{value:J,children:[i.children,B1(V2.Provider,{value:X,children:B1(G4,{appSettings:w,options:A,visible:o,authenticated:s,children:o&&B1(o5,{})})})]})};export{b7 as PrivyProvider,I2 as VERSION,m7 as getAccessToken,I as usePrivy};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privy-io/react-auth",
3
- "version": "1.10.0-beta.10",
3
+ "version": "1.10.0-beta.11",
4
4
  "description": "React client for the Privy Auth API",
5
5
  "keywords": [
6
6
  "authentication",