@privy-io/react-auth 1.8.0-beta.3 → 1.8.0-beta.4

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 a5=Object.create;var t2=Object.defineProperty;var l5=Object.getOwnPropertyDescriptor;var r5=Object.getOwnPropertyNames;var n5=Object.getPrototypeOf,s5=Object.prototype.hasOwnProperty;var C5=(i,e)=>{for(var o in e)t2(i,o,{get:e[o],enumerable:!0})},M4=(i,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of r5(e))!s5.call(i,l)&&l!==o&&t2(i,l,{get:()=>e[l],enumerable:!(a=l5(e,l))||a.enumerable});return i};var g=(i,e,o)=>(o=i!=null?a5(n5(i)):{},M4(e||!i||!i.__esModule?t2(o,"default",{value:i,enumerable:!0}):o,i)),d5=i=>M4(t2({},"__esModule",{value:!0}),i);var _6={};C5(_6,{PrivyProvider:()=>i5,VERSION:()=>o2,usePrivy:()=>x});module.exports=d5(_6);var K=require("react");var a2=g(require("axios"));var w4=g(require("axios")),i1=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}]`:""}`}},e2=class extends i1{constructor(o,a,l,C){super(l,C);this.type=o;this.status=a}},b=class extends i1{constructor(o,a){super(o,a);this.type="client_error"}};var Y=class extends i1{constructor(o,a){super(o,a);this.type="connector_error"}},D=i=>{if(i instanceof i1)return i;if(!w4.default.isAxiosError(i))return J(i);if(!i.response)return new e2("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new e2(e||"ApiError",i.response.status,o||a,i)},J=i=>i instanceof i1?i:i instanceof Error?new b(i.message,i):new b(`Internal error: ${i}`);var y4="1.8.0-beta.3";var v4="https://api.privy.io/v0",Z4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",i2="4df5e2316331463a9130964bd6078dfa",x4=1e4,X=1200,o2=y4;var l2=class{constructor(e,o,a){this.appId=e,this.sdkVersion=o2,this.session=o,this.defaults=a}async get(e,o){try{return await a2.default.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw D(a)}}async post(e,o,a){try{return await a2.default.post(e,o,this.buildConfig(a))}catch(l){throw D(l)}}async delete(e,o){try{return await a2.default.delete(e,this.buildConfig(o))}catch(a){throw D(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 L4=g(require("jwt-decode")),M1=class{static parse(e){try{return new M1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=(0,L4.default)(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}isExpired(e=0){let o=Date.now(),a=(this.expiration-e)*1e3;return o>=a}};var w1=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]}},U2=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 p5(){return typeof window<"u"&&window.localStorage?new U2:new W2}var Q=p5();var h5=i=>{var e;return(e=i.map(o=>{if(o.type==="wallet")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3),chainType:o.chain_type}}).filter(o=>o))==null?void 0:e[0]},f5=i=>{var e;return(e=i.map(o=>{if(o.type==="email")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},u5=i=>{var e;return(e=i.map(o=>{if(o.type==="phone")return{number:o.phoneNumber,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},m5=i=>{var e;return(e=i.map(o=>{if(o.type==="google_oauth")return{subject:o.subject,email:o.email,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},b5=i=>{var e;return(e=i.map(o=>{if(o.type==="twitter_oauth")return{subject:o.subject,username:o.username,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},k5=i=>{var e;return(e=i.map(o=>{if(o.type==="discord_oauth")return{subject:o.subject,username:o.username,email:o.email,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]};function f1(i){if(!i)return null;let e=f5(i.linked_accounts),o=u5(i.linked_accounts),a=h5(i.linked_accounts),l=m5(i.linked_accounts),C=b5(i.linked_accounts),c=k5(i.linked_accounts);return{id:i.id,createdAt:new Date(i.created_at*1e3),linkedAccounts:[...a?[a]:[],...e?[e]:[],...o?[o]:[],...l?[l]:[],...C?[C]:[],...c?[c]:[]],email:e&&{address:e==null?void 0:e.address},phone:o&&{number:o==null?void 0:o.number},wallet:a&&{address:a.address,chainType:a.chainType,chainId:a.chainId,walletType:a.walletType},google:l&&{subject:l.subject,email:l.email,name:l.name},twitter:C&&{subject:C.subject,username:C.username,name:C.name},discord:c&&{subject:c.subject,username:c.username,email:c.email}}}var E4=()=>"/api/v1/sessions",A4=()=>"/api/v1/sessions/logout",P4=()=>"/api/v1/sessions/fork",_4=()=>"/api/v1/siwe/init",T4=()=>"/api/v1/siwe/authenticate",S4=()=>"/api/v1/passwordless/init",I4=()=>"/api/v1/passwordless/authenticate",O4=()=>"/api/v1/passwordless_sms/init",R4=()=>"/api/v1/passwordless_sms/authenticate",N4=()=>"/api/v1/oauth/init",W4=()=>"/api/v1/oauth/authenticate",U4=()=>"/api/v1/siwe/unlink",D4=()=>"/api/v1/passwordless/unlink",F4=()=>"/api/v1/passwordless_sms/unlink",H4=()=>"/api/v1/oauth/unlink";var g5=30,D2="privy:token",F2="privy:refresh_token",r2=class{constructor(){this.authenticateOnce=new w1(async e=>this._authenticate(e)),this.refreshOnce=new w1(this._refresh.bind(this)),this.destroyOnce=new w1(this._destroy.bind(this)),this.forkSessionOnce=new w1(this._forkSession.bind(this))}get token(){try{let e=Q.get(D2);return typeof e=="string"?new M1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=Q.get(F2);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=M1.parse(this.token);return e!==null&&!e.isExpired(g5)}authenticate(e){return this.authenticateOnce.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:l}=await e.authenticate();return o&&this.storeToken(o),a&&this.storeRefreshToken(a),f1(l)}catch(o){throw console.warn("Error authenticating session"),J(o)}}async _refresh(){if(!this.api)throw new b("Session has no API instance");let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let a=await this.api.post(E4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),f1(a.data.user)}catch(a){throw J(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(A4(),{})),this.destroyLocalState()}catch(o){throw console.warn("Error destroying session"),J(o)}}async _forkSession(){if(!this.api)throw new b("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(P4(),{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"?Q.put(D2,e):Q.del(D2)}storeRefreshToken(e){typeof e=="string"?Q.put(F2,e):Q.del(F2)}};var G4=require("@ethersproject/address"),G2=g(require("@walletconnect/web3-provider"));var V4=require("ethers");var P1=class extends Y{constructor(){super("Wallet timeout");this.type="wallet_error"}},n2=i=>{if(i instanceof Y)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new _1(i);return i.code===V4.ethers.errors.ACTION_REJECTED&&(e.details=y1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new _1(i):new Y("Unknown connector error",i)},H2=class extends i1{constructor(o,a,l){super(o);this.type="provider_error";this.code=a,this.data=l}},_1=class extends H2{constructor(o){var C,c,m;let a=o;super(a.message,a.code,a.data);let l=Object.values(y1).find(M=>M.eipCode===a.code);this.details=l||y1.UNKNOWN_ERROR,a.code===-32002&&((C=a.message)!=null&&C.includes("already pending for origin")?(c=a.message)!=null&&c.includes("wallet_requestPermissions")?this.details=y1.E32002_CONNECTION_ALREADY_PENDING:this.details=y1.E32002_REQUEST_ALREADY_PENDING:(m=a.message)!=null&&m.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=y1.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}},y1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...y5,...w5},s2={...M5,...y1};var v5=3e4,V2=(i=new P1,e=v5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),T1=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 Y(`A wallet request of type ${e.method} was made to a disconnected wallet: `);return Promise.race([this.walletProvider.request(e),V2()]).catch(o=>{throw n2(o)})}},S1=class extends T1{constructor(o){super(o)}},C2=class extends T1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var j4=require("ethers");var B4=["metamask","coinbase_wallet","wallet_connect"];var z4=g(require("@coinbase/wallet-sdk")),B2="privy:wallet_type",Z5="walletconnect",x5=()=>{let i=`https://mainnet.infura.io/v3/${i2}`,e=1;return new z4.default({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},j2=()=>{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},$4=()=>{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},d2=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,l,C,c,m)=>`${a} wants you to sign in with your Ethereum account:
1
+ "use strict";var a5=Object.create;var t2=Object.defineProperty;var l5=Object.getOwnPropertyDescriptor;var r5=Object.getOwnPropertyNames;var n5=Object.getPrototypeOf,s5=Object.prototype.hasOwnProperty;var C5=(i,e)=>{for(var o in e)t2(i,o,{get:e[o],enumerable:!0})},M4=(i,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of r5(e))!s5.call(i,l)&&l!==o&&t2(i,l,{get:()=>e[l],enumerable:!(a=l5(e,l))||a.enumerable});return i};var g=(i,e,o)=>(o=i!=null?a5(n5(i)):{},M4(e||!i||!i.__esModule?t2(o,"default",{value:i,enumerable:!0}):o,i)),d5=i=>M4(t2({},"__esModule",{value:!0}),i);var _6={};C5(_6,{PrivyProvider:()=>i5,VERSION:()=>o2,usePrivy:()=>x});module.exports=d5(_6);var K=require("react");var a2=g(require("axios"));var w4=g(require("axios")),i1=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}]`:""}`}},e2=class extends i1{constructor(o,a,l,C){super(l,C);this.type=o;this.status=a}},b=class extends i1{constructor(o,a){super(o,a);this.type="client_error"}};var Y=class extends i1{constructor(o,a){super(o,a);this.type="connector_error"}},D=i=>{if(i instanceof i1)return i;if(!w4.default.isAxiosError(i))return J(i);if(!i.response)return new e2("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new e2(e||"ApiError",i.response.status,o||a,i)},J=i=>i instanceof i1?i:i instanceof Error?new b(i.message,i):new b(`Internal error: ${i}`);var y4="1.8.0-beta.4";var v4="https://api.privy.io/v0",Z4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",i2="4df5e2316331463a9130964bd6078dfa",x4=1e4,X=1200,o2=y4;var l2=class{constructor(e,o,a){this.appId=e,this.sdkVersion=o2,this.session=o,this.defaults=a}async get(e,o){try{return await a2.default.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw D(a)}}async post(e,o,a){try{return await a2.default.post(e,o,this.buildConfig(a))}catch(l){throw D(l)}}async delete(e,o){try{return await a2.default.delete(e,this.buildConfig(o))}catch(a){throw D(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 L4=g(require("jwt-decode")),M1=class{static parse(e){try{return new M1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=(0,L4.default)(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}isExpired(e=0){let o=Date.now(),a=(this.expiration-e)*1e3;return o>=a}};var w1=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]}},U2=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 p5(){return typeof window<"u"&&window.localStorage?new U2:new W2}var Q=p5();var h5=i=>{var e;return(e=i.map(o=>{if(o.type==="wallet")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3),chainType:o.chain_type}}).filter(o=>o))==null?void 0:e[0]},f5=i=>{var e;return(e=i.map(o=>{if(o.type==="email")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},u5=i=>{var e;return(e=i.map(o=>{if(o.type==="phone")return{number:o.phoneNumber,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},m5=i=>{var e;return(e=i.map(o=>{if(o.type==="google_oauth")return{subject:o.subject,email:o.email,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},b5=i=>{var e;return(e=i.map(o=>{if(o.type==="twitter_oauth")return{subject:o.subject,username:o.username,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},k5=i=>{var e;return(e=i.map(o=>{if(o.type==="discord_oauth")return{subject:o.subject,username:o.username,email:o.email,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]};function f1(i){if(!i)return null;let e=f5(i.linked_accounts),o=u5(i.linked_accounts),a=h5(i.linked_accounts),l=m5(i.linked_accounts),C=b5(i.linked_accounts),c=k5(i.linked_accounts);return{id:i.id,createdAt:new Date(i.created_at*1e3),linkedAccounts:[...a?[a]:[],...e?[e]:[],...o?[o]:[],...l?[l]:[],...C?[C]:[],...c?[c]:[]],email:e&&{address:e==null?void 0:e.address},phone:o&&{number:o==null?void 0:o.number},wallet:a&&{address:a.address,chainType:a.chainType,chainId:a.chainId,walletType:a.walletType},google:l&&{subject:l.subject,email:l.email,name:l.name},twitter:C&&{subject:C.subject,username:C.username,name:C.name},discord:c&&{subject:c.subject,username:c.username,email:c.email}}}var E4=()=>"/api/v1/sessions",A4=()=>"/api/v1/sessions/logout",P4=()=>"/api/v1/sessions/fork",_4=()=>"/api/v1/siwe/init",T4=()=>"/api/v1/siwe/authenticate",S4=()=>"/api/v1/passwordless/init",I4=()=>"/api/v1/passwordless/authenticate",O4=()=>"/api/v1/passwordless_sms/init",R4=()=>"/api/v1/passwordless_sms/authenticate",N4=()=>"/api/v1/oauth/init",W4=()=>"/api/v1/oauth/authenticate",U4=()=>"/api/v1/siwe/unlink",D4=()=>"/api/v1/passwordless/unlink",F4=()=>"/api/v1/passwordless_sms/unlink",H4=()=>"/api/v1/oauth/unlink";var g5=30,D2="privy:token",F2="privy:refresh_token",r2=class{constructor(){this.authenticateOnce=new w1(async e=>this._authenticate(e)),this.refreshOnce=new w1(this._refresh.bind(this)),this.destroyOnce=new w1(this._destroy.bind(this)),this.forkSessionOnce=new w1(this._forkSession.bind(this))}get token(){try{let e=Q.get(D2);return typeof e=="string"?new M1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=Q.get(F2);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=M1.parse(this.token);return e!==null&&!e.isExpired(g5)}authenticate(e){return this.authenticateOnce.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:l}=await e.authenticate();return o&&this.storeToken(o),a&&this.storeRefreshToken(a),f1(l)}catch(o){throw console.warn("Error authenticating session"),J(o)}}async _refresh(){if(!this.api)throw new b("Session has no API instance");let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let a=await this.api.post(E4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),f1(a.data.user)}catch(a){throw J(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(A4(),{})),this.destroyLocalState()}catch(o){throw console.warn("Error destroying session"),J(o)}}async _forkSession(){if(!this.api)throw new b("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(P4(),{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"?Q.put(D2,e):Q.del(D2)}storeRefreshToken(e){typeof e=="string"?Q.put(F2,e):Q.del(F2)}};var G4=require("@ethersproject/address"),G2=g(require("@walletconnect/web3-provider"));var V4=require("ethers");var P1=class extends Y{constructor(){super("Wallet timeout");this.type="wallet_error"}},n2=i=>{if(i instanceof Y)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new _1(i);return i.code===V4.ethers.errors.ACTION_REJECTED&&(e.details=y1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new _1(i):new Y("Unknown connector error",i)},H2=class extends i1{constructor(o,a,l){super(o);this.type="provider_error";this.code=a,this.data=l}},_1=class extends H2{constructor(o){var C,c,m;let a=o;super(a.message,a.code,a.data);let l=Object.values(y1).find(M=>M.eipCode===a.code);this.details=l||y1.UNKNOWN_ERROR,a.code===-32002&&((C=a.message)!=null&&C.includes("already pending for origin")?(c=a.message)!=null&&c.includes("wallet_requestPermissions")?this.details=y1.E32002_CONNECTION_ALREADY_PENDING:this.details=y1.E32002_REQUEST_ALREADY_PENDING:(m=a.message)!=null&&m.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=y1.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}},y1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...y5,...w5},s2={...M5,...y1};var v5=3e4,V2=(i=new P1,e=v5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),T1=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 Y(`A wallet request of type ${e.method} was made to a disconnected wallet: `);return Promise.race([this.walletProvider.request(e),V2()]).catch(o=>{throw n2(o)})}},S1=class extends T1{constructor(o){super(o)}},C2=class extends T1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var j4=require("ethers");var B4=["metamask","coinbase_wallet","wallet_connect"];var z4=g(require("@coinbase/wallet-sdk")),B2="privy:wallet_type",Z5="walletconnect",x5=()=>{let i=`https://mainnet.infura.io/v3/${i2}`,e=1;return new z4.default({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},j2=()=>{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},$4=()=>{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},d2=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,l,C,c,m)=>`${a} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${m}
@@ -177,7 +177,7 @@ Resources:
177
177
  && > a {
178
178
  color: var(--primary-color);
179
179
  }
180
- `;function r3(i){let{privacyPolicyUrl:e,termsAndConditionsUrl:o}=i.app,a=typeof e=="string",l=typeof o=="string",C=a&&l;return!a&&!l?null:(0,t1.jsxs)(P5,{children:["By logging in I agree to the"," ",l&&(0,t1.jsx)("a",{href:o,target:"_blank",children:C?"Terms":"Terms of Service"}),C&&" & ",a&&(0,t1.jsx)("a",{href:e,target:"_blank",children:"Privacy Policy"})]})}var r1=({protectedByPrivy:i})=>(0,t1.jsx)(c1,{hideOnMobile:i,children:i?(0,t1.jsxs)(t1.Fragment,{children:[(0,t1.jsx)(l3,{}),(0,t1.jsx)("span",{children:(0,t1.jsx)("a",{href:"https://www.privy.io/how-it-works",target:"_blank",children:"Protected by Privy"})})]}):null}),c1=a4.default.div`
180
+ `;function r3(i){let{privacyPolicyUrl:e,termsAndConditionsUrl:o}=i.app,a=typeof e=="string",l=typeof o=="string",C=a&&l;return!a&&!l?null:(0,t1.jsxs)(P5,{children:["By logging in I agree to the"," ",l&&(0,t1.jsx)("a",{href:o,target:"_blank",children:C?"Terms":"Terms of Service"}),C&&" & ",a&&(0,t1.jsx)("a",{href:e,target:"_blank",children:"Privacy Policy"})]})}var r1=({protectedByPrivy:i})=>(0,t1.jsx)(c1,{hideOnMobile:i,children:i?(0,t1.jsxs)(t1.Fragment,{children:[(0,t1.jsx)(l3,{}),(0,t1.jsx)("span",{children:(0,t1.jsx)("a",{href:"https://www.privy.io/",target:"_blank",children:"Protected by Privy"})})]}):null}),c1=a4.default.div`
181
181
  height: 20px;
182
182
  font-size: 12px;
183
183
  display: flex;
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import{useEffect as Z2,useState as h1}from"react";import P2 from"axios";import J3 from"axios";var j=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}]`:""}`}},F1=class extends j{constructor(o,a,l,s){super(l,s);this.type=o;this.status=a}},m=class extends j{constructor(o,a){super(o,a);this.type="client_error"}};var F=class extends j{constructor(o,a){super(o,a);this.type="connector_error"}},N=i=>{if(i instanceof j)return i;if(!J3.isAxiosError(i))return H(i);if(!i.response)return new F1("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new F1(e||"ApiError",i.response.status,o||a,i)},H=i=>i instanceof j?i:i instanceof Error?new m(i.message,i):new m(`Internal error: ${i}`);var C4="1.8.0-beta.3";var d4="https://api.privy.io/v0",c4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",H1="4df5e2316331463a9130964bd6078dfa",p4=1e4,V=1200,A2=C4;var V1=class{constructor(e,o,a){this.appId=e,this.sdkVersion=A2,this.session=o,this.defaults=a}async get(e,o){try{return await P2.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw N(a)}}async post(e,o,a){try{return await P2.post(e,o,this.buildConfig(a))}catch(l){throw N(l)}}async delete(e,o){try{return await P2.delete(e,this.buildConfig(o))}catch(a){throw N(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 Q3 from"jwt-decode";var o1=class{static parse(e){try{return new o1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=Q3(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}isExpired(e=0){let o=Date.now(),a=(this.expiration-e)*1e3;return o>=a}};var a1=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]}},T2=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 t5(){return typeof window<"u"&&window.localStorage?new T2:new _2}var B=t5();var e5=i=>{var e;return(e=i.map(o=>{if(o.type==="wallet")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3),chainType:o.chain_type}}).filter(o=>o))==null?void 0:e[0]},i5=i=>{var e;return(e=i.map(o=>{if(o.type==="email")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},o5=i=>{var e;return(e=i.map(o=>{if(o.type==="phone")return{number:o.phoneNumber,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},a5=i=>{var e;return(e=i.map(o=>{if(o.type==="google_oauth")return{subject:o.subject,email:o.email,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},l5=i=>{var e;return(e=i.map(o=>{if(o.type==="twitter_oauth")return{subject:o.subject,username:o.username,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},r5=i=>{var e;return(e=i.map(o=>{if(o.type==="discord_oauth")return{subject:o.subject,username:o.username,email:o.email,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]};function X(i){if(!i)return null;let e=i5(i.linked_accounts),o=o5(i.linked_accounts),a=e5(i.linked_accounts),l=a5(i.linked_accounts),s=l5(i.linked_accounts),d=r5(i.linked_accounts);return{id:i.id,createdAt:new Date(i.created_at*1e3),linkedAccounts:[...a?[a]:[],...e?[e]:[],...o?[o]:[],...l?[l]:[],...s?[s]:[],...d?[d]:[]],email:e&&{address:e==null?void 0:e.address},phone:o&&{number:o==null?void 0:o.number},wallet:a&&{address:a.address,chainType:a.chainType,chainId:a.chainId,walletType:a.walletType},google:l&&{subject:l.subject,email:l.email,name:l.name},twitter:s&&{subject:s.subject,username:s.username,name:s.name},discord:d&&{subject:d.subject,username:d.username,email:d.email}}}var h4=()=>"/api/v1/sessions",f4=()=>"/api/v1/sessions/logout",u4=()=>"/api/v1/sessions/fork",m4=()=>"/api/v1/siwe/init",b4=()=>"/api/v1/siwe/authenticate",k4=()=>"/api/v1/passwordless/init",g4=()=>"/api/v1/passwordless/authenticate",M4=()=>"/api/v1/passwordless_sms/init",w4=()=>"/api/v1/passwordless_sms/authenticate",y4=()=>"/api/v1/oauth/init",v4=()=>"/api/v1/oauth/authenticate",Z4=()=>"/api/v1/siwe/unlink",x4=()=>"/api/v1/passwordless/unlink",L4=()=>"/api/v1/passwordless_sms/unlink",E4=()=>"/api/v1/oauth/unlink";var n5=30,S2="privy:token",I2="privy:refresh_token",B1=class{constructor(){this.authenticateOnce=new a1(async e=>this._authenticate(e)),this.refreshOnce=new a1(this._refresh.bind(this)),this.destroyOnce=new a1(this._destroy.bind(this)),this.forkSessionOnce=new a1(this._forkSession.bind(this))}get token(){try{let e=B.get(S2);return typeof e=="string"?new o1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=B.get(I2);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=o1.parse(this.token);return e!==null&&!e.isExpired(n5)}authenticate(e){return this.authenticateOnce.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:l}=await e.authenticate();return o&&this.storeToken(o),a&&this.storeRefreshToken(a),X(l)}catch(o){throw console.warn("Error authenticating session"),H(o)}}async _refresh(){if(!this.api)throw new m("Session has no API instance");let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let a=await this.api.post(h4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),X(a.data.user)}catch(a){throw H(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(f4(),{})),this.destroyLocalState()}catch(o){throw console.warn("Error destroying session"),H(o)}}async _forkSession(){if(!this.api)throw new m("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 H(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?B.put(S2,e):B.del(S2)}storeRefreshToken(e){typeof e=="string"?B.put(I2,e):B.del(I2)}};import{getAddress as h5}from"@ethersproject/address";import P4 from"@walletconnect/web3-provider";import{ethers as s5}from"ethers";var u1=class extends F{constructor(){super("Wallet timeout");this.type="wallet_error"}},G1=i=>{if(i instanceof F)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new m1(i);return i.code===s5.errors.ACTION_REJECTED&&(e.details=l1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new m1(i):new F("Unknown connector error",i)},O2=class extends j{constructor(o,a,l){super(o);this.type="provider_error";this.code=a,this.data=l}},m1=class extends O2{constructor(o){var s,d,u;let a=o;super(a.message,a.code,a.data);let l=Object.values(l1).find(k=>k.eipCode===a.code);this.details=l||l1.UNKNOWN_ERROR,a.code===-32002&&((s=a.message)!=null&&s.includes("already pending for origin")?(d=a.message)!=null&&d.includes("wallet_requestPermissions")?this.details=l1.E32002_CONNECTION_ALREADY_PENDING:this.details=l1.E32002_REQUEST_ALREADY_PENDING:(u=a.message)!=null&&u.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=l1.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}},d5={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}},c5={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}},l1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...c5,...d5},j1={...C5,...l1};var p5=3e4,R2=(i=new u1,e=p5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),b1=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 F(`A wallet request of type ${e.method} was made to a disconnected wallet: `);return Promise.race([this.walletProvider.request(e),R2()]).catch(o=>{throw G1(o)})}},k1=class extends b1{constructor(o){super(o)}},z1=class extends b1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};import{providers as f5}from"ethers";var A4=["metamask","coinbase_wallet","wallet_connect"];import u5 from"@coinbase/wallet-sdk";var N2="privy:wallet_type",m5="walletconnect",b5=()=>{let i=`https://mainnet.infura.io/v3/${H1}`,e=1;return new u5({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},W2=()=>{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},_4=()=>{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},$1=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,l,s,d,u)=>`${a} wants you to sign in with your Ethereum account:
1
+ import{useEffect as Z2,useState as h1}from"react";import P2 from"axios";import J3 from"axios";var j=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}]`:""}`}},F1=class extends j{constructor(o,a,l,s){super(l,s);this.type=o;this.status=a}},m=class extends j{constructor(o,a){super(o,a);this.type="client_error"}};var F=class extends j{constructor(o,a){super(o,a);this.type="connector_error"}},N=i=>{if(i instanceof j)return i;if(!J3.isAxiosError(i))return H(i);if(!i.response)return new F1("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new F1(e||"ApiError",i.response.status,o||a,i)},H=i=>i instanceof j?i:i instanceof Error?new m(i.message,i):new m(`Internal error: ${i}`);var C4="1.8.0-beta.4";var d4="https://api.privy.io/v0",c4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",H1="4df5e2316331463a9130964bd6078dfa",p4=1e4,V=1200,A2=C4;var V1=class{constructor(e,o,a){this.appId=e,this.sdkVersion=A2,this.session=o,this.defaults=a}async get(e,o){try{return await P2.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw N(a)}}async post(e,o,a){try{return await P2.post(e,o,this.buildConfig(a))}catch(l){throw N(l)}}async delete(e,o){try{return await P2.delete(e,this.buildConfig(o))}catch(a){throw N(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 Q3 from"jwt-decode";var o1=class{static parse(e){try{return new o1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=Q3(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}isExpired(e=0){let o=Date.now(),a=(this.expiration-e)*1e3;return o>=a}};var a1=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]}},T2=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 t5(){return typeof window<"u"&&window.localStorage?new T2:new _2}var B=t5();var e5=i=>{var e;return(e=i.map(o=>{if(o.type==="wallet")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3),chainType:o.chain_type}}).filter(o=>o))==null?void 0:e[0]},i5=i=>{var e;return(e=i.map(o=>{if(o.type==="email")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},o5=i=>{var e;return(e=i.map(o=>{if(o.type==="phone")return{number:o.phoneNumber,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},a5=i=>{var e;return(e=i.map(o=>{if(o.type==="google_oauth")return{subject:o.subject,email:o.email,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},l5=i=>{var e;return(e=i.map(o=>{if(o.type==="twitter_oauth")return{subject:o.subject,username:o.username,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},r5=i=>{var e;return(e=i.map(o=>{if(o.type==="discord_oauth")return{subject:o.subject,username:o.username,email:o.email,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]};function X(i){if(!i)return null;let e=i5(i.linked_accounts),o=o5(i.linked_accounts),a=e5(i.linked_accounts),l=a5(i.linked_accounts),s=l5(i.linked_accounts),d=r5(i.linked_accounts);return{id:i.id,createdAt:new Date(i.created_at*1e3),linkedAccounts:[...a?[a]:[],...e?[e]:[],...o?[o]:[],...l?[l]:[],...s?[s]:[],...d?[d]:[]],email:e&&{address:e==null?void 0:e.address},phone:o&&{number:o==null?void 0:o.number},wallet:a&&{address:a.address,chainType:a.chainType,chainId:a.chainId,walletType:a.walletType},google:l&&{subject:l.subject,email:l.email,name:l.name},twitter:s&&{subject:s.subject,username:s.username,name:s.name},discord:d&&{subject:d.subject,username:d.username,email:d.email}}}var h4=()=>"/api/v1/sessions",f4=()=>"/api/v1/sessions/logout",u4=()=>"/api/v1/sessions/fork",m4=()=>"/api/v1/siwe/init",b4=()=>"/api/v1/siwe/authenticate",k4=()=>"/api/v1/passwordless/init",g4=()=>"/api/v1/passwordless/authenticate",M4=()=>"/api/v1/passwordless_sms/init",w4=()=>"/api/v1/passwordless_sms/authenticate",y4=()=>"/api/v1/oauth/init",v4=()=>"/api/v1/oauth/authenticate",Z4=()=>"/api/v1/siwe/unlink",x4=()=>"/api/v1/passwordless/unlink",L4=()=>"/api/v1/passwordless_sms/unlink",E4=()=>"/api/v1/oauth/unlink";var n5=30,S2="privy:token",I2="privy:refresh_token",B1=class{constructor(){this.authenticateOnce=new a1(async e=>this._authenticate(e)),this.refreshOnce=new a1(this._refresh.bind(this)),this.destroyOnce=new a1(this._destroy.bind(this)),this.forkSessionOnce=new a1(this._forkSession.bind(this))}get token(){try{let e=B.get(S2);return typeof e=="string"?new o1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=B.get(I2);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=o1.parse(this.token);return e!==null&&!e.isExpired(n5)}authenticate(e){return this.authenticateOnce.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:l}=await e.authenticate();return o&&this.storeToken(o),a&&this.storeRefreshToken(a),X(l)}catch(o){throw console.warn("Error authenticating session"),H(o)}}async _refresh(){if(!this.api)throw new m("Session has no API instance");let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let a=await this.api.post(h4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),X(a.data.user)}catch(a){throw H(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(f4(),{})),this.destroyLocalState()}catch(o){throw console.warn("Error destroying session"),H(o)}}async _forkSession(){if(!this.api)throw new m("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 H(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?B.put(S2,e):B.del(S2)}storeRefreshToken(e){typeof e=="string"?B.put(I2,e):B.del(I2)}};import{getAddress as h5}from"@ethersproject/address";import P4 from"@walletconnect/web3-provider";import{ethers as s5}from"ethers";var u1=class extends F{constructor(){super("Wallet timeout");this.type="wallet_error"}},G1=i=>{if(i instanceof F)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new m1(i);return i.code===s5.errors.ACTION_REJECTED&&(e.details=l1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new m1(i):new F("Unknown connector error",i)},O2=class extends j{constructor(o,a,l){super(o);this.type="provider_error";this.code=a,this.data=l}},m1=class extends O2{constructor(o){var s,d,u;let a=o;super(a.message,a.code,a.data);let l=Object.values(l1).find(k=>k.eipCode===a.code);this.details=l||l1.UNKNOWN_ERROR,a.code===-32002&&((s=a.message)!=null&&s.includes("already pending for origin")?(d=a.message)!=null&&d.includes("wallet_requestPermissions")?this.details=l1.E32002_CONNECTION_ALREADY_PENDING:this.details=l1.E32002_REQUEST_ALREADY_PENDING:(u=a.message)!=null&&u.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=l1.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}},d5={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}},c5={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}},l1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...c5,...d5},j1={...C5,...l1};var p5=3e4,R2=(i=new u1,e=p5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),b1=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 F(`A wallet request of type ${e.method} was made to a disconnected wallet: `);return Promise.race([this.walletProvider.request(e),R2()]).catch(o=>{throw G1(o)})}},k1=class extends b1{constructor(o){super(o)}},z1=class extends b1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};import{providers as f5}from"ethers";var A4=["metamask","coinbase_wallet","wallet_connect"];import u5 from"@coinbase/wallet-sdk";var N2="privy:wallet_type",m5="walletconnect",b5=()=>{let i=`https://mainnet.infura.io/v3/${H1}`,e=1;return new u5({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},W2=()=>{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},_4=()=>{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},$1=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,l,s,d,u)=>`${a} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${u}
@@ -177,7 +177,7 @@ Resources:
177
177
  && > a {
178
178
  color: var(--primary-color);
179
179
  }
180
- `;function X4(i){let{privacyPolicyUrl:e,termsAndConditionsUrl:o}=i.app,a=typeof e=="string",l=typeof o=="string",s=a&&l;return!a&&!l?null:Q4(U5,{children:["By logging in I agree to the"," ",l&&y1("a",{href:o,target:"_blank",children:s?"Terms":"Terms of Service"}),s&&" & ",a&&y1("a",{href:e,target:"_blank",children:"Privacy Policy"})]})}var K=({protectedByPrivy:i})=>y1(J,{hideOnMobile:i,children:i?Q4(D5,{children:[y1(Y4,{}),y1("span",{children:y1("a",{href:"https://www.privy.io/how-it-works",target:"_blank",children:"Protected by Privy"})})]}):null}),J=J4.div`
180
+ `;function X4(i){let{privacyPolicyUrl:e,termsAndConditionsUrl:o}=i.app,a=typeof e=="string",l=typeof o=="string",s=a&&l;return!a&&!l?null:Q4(U5,{children:["By logging in I agree to the"," ",l&&y1("a",{href:o,target:"_blank",children:s?"Terms":"Terms of Service"}),s&&" & ",a&&y1("a",{href:e,target:"_blank",children:"Privacy Policy"})]})}var K=({protectedByPrivy:i})=>y1(J,{hideOnMobile:i,children:i?Q4(D5,{children:[y1(Y4,{}),y1("span",{children:y1("a",{href:"https://www.privy.io/",target:"_blank",children:"Protected by Privy"})})]}):null}),J=J4.div`
181
181
  height: 20px;
182
182
  font-size: 12px;
183
183
  display: flex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privy-io/react-auth",
3
- "version": "1.8.0-beta.3",
3
+ "version": "1.8.0-beta.4",
4
4
  "description": "React client for the Privy Auth API",
5
5
  "keywords": [
6
6
  "authentication",