@privy-io/react-auth 1.17.0-beta.2 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{Web3Provider as u1}from"@ethersproject/providers";import{useEffect as Nn,useState as te}from"react";import Un from"axios";var ne=class extends Error{constructor(o,r){super(o);r instanceof Error&&(this.cause=r)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},je=class extends ne{constructor(o,r,i,n){super(i,n);this.type=o;this.status=r}},y=class extends ne{constructor(o,r){super(o,r);this.type="client_error"}};var B=class extends ne{constructor(o,r){super(o,r);this.type="connector_error"}},U=t=>{if(t instanceof ne)return t;if(!Un.isAxiosError(t))return oe(t);if(!t.response)return new je("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new je(e||"ApiError",t.response.status,o||r,t)},oe=t=>t instanceof ne?t:t instanceof Error?new y(t.message,t):new y(`Internal error: ${t}`);var vr=()=>"/api/v1/sessions",Cr=()=>"/api/v1/sessions/logout",br=()=>"/api/v1/sessions/fork",xr=()=>"/api/v1/siwe/init",Er=()=>"/api/v1/siwe/authenticate",Lr=()=>"/api/v1/siwe/link",Ar=()=>"/api/v1/passwordless/init",_r=()=>"/api/v1/passwordless/authenticate",Pr=()=>"/api/v1/passwordless/link",Sr=()=>"/api/v1/passwordless_sms/init",kr=()=>"/api/v1/passwordless_sms/authenticate",Tr=()=>"/api/v1/passwordless_sms/link",Wr=()=>"/api/v1/oauth/init",Ir=()=>"/api/v1/oauth/authenticate",Rr=()=>"/api/v1/oauth/link",Mr=()=>"/api/v1/siwe/unlink",Nr=()=>"/api/v1/passwordless/unlink",Or=()=>"/api/v1/passwordless_sms/unlink",Ur=()=>"/api/v1/oauth/unlink";var ft=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new y("Email and email code must be set prior to calling authenticate.");try{let e=_r(),o=await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw U(e)}}async link(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new y("Email and email code must be set prior to calling authenticate.");try{let e=Pr();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw U(e)}}async sendCodeEmail(e){if(!this.api)throw new y("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new y("Email must be set when initialzing authentication.");try{let o=Ar();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw U(o)}}};var Ze=class{constructor(e,o,r){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=r}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new y("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new y("User denied confirmation during OAuth flow");try{let e=Ir(),o=await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw U(e)}}async link(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new y("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new y("User denied confirmation during OAuth flow");try{let e=Rr();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw U(e)}}async getAuthorizationUrl(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.provider)throw new y("Provider must be set when initialzing OAuth authentication.");try{let e=Wr();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw U(e)}}};var gt=class{constructor(e,o){this.meta={walletType:o},this.connectors=e,this.walletConnector=this.connectors.createWalletConnector(o,null)}async authenticate(){if(!this.api)throw new y("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Er(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),await this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),{user:r.data.user,token:r.data.token,refresh_token:r.data.refresh_token,is_new_user:r.data.is_new_user}}catch(e){throw U(e)}}async link(){if(!this.api)throw new y("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Lr(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),await this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),r.data}catch(e){throw U(e)}}async promptConnectAndSign(e){let o=await this.walletConnector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(xr(),{address:r}),s=this.walletConnector.prepareMessage(i,r,n.data.nonce),a=await this.walletConnector.sign(s);return{message:s,signature:a}}};var yt=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new y("phone number and sms code must be set prior to calling authenticate.");try{let e=kr(),o=await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw U(e)}}async link(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new y("phone number and sms code must be set prior to calling authenticate.");try{let e=Tr();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw U(e)}}async sendSmsCode(e){if(!this.api)throw new y("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new y("phone nNumber must be set when initialzing authentication.");try{let o=Sr();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw U(o)}}};import{getAddress as es}from"@ethersproject/address";var Dr="1.17.0-beta.2";var Fr="https://api.privy.io/v0",Po=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",wt="4df5e2316331463a9130964bd6078dfa",Gr=1e4,re=1400,So=Dr;var qe="privy:token",Ut="privy:refresh_token",Dt="privy:connectors",Br="walletconnect",ko=3e4;var To=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,o){o!==void 0?this._cache[e]=o:this.del(e)}del(e){delete this._cache[e]}getKeys(){return Object.keys(this._cache)}},Wo=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}getKeys(){return Object.entries(localStorage).map(([e])=>e)}};function Fn(){return typeof window<"u"&&window.localStorage?new Wo:new To}var Z=Fn();import Zn from"@coinbase/wallet-sdk";import{getAddress as qn}from"@ethersproject/address";import{getAddress as $n}from"@ethersproject/address";import{Web3Provider as jn}from"@ethersproject/providers";import{ErrorCode as Gn}from"@ethersproject/logger";var Ke=class extends B{constructor(){super("Wallet timeout");this.type="wallet_error"}},Pe=t=>{if(t instanceof B)return t;if((t==null?void 0:t.code)&&(t==null?void 0:t.reason)){let e=new Je(t);return t.code===Gn.ACTION_REJECTED&&(e.details=Ue.E4001_USER_REJECTED_REQUEST),e}return t!=null&&t.code?new Je(t):new B("Unknown connector error",t)},Io=class extends ne{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},Je=class extends Io{constructor(o){var n,s,a;let r=o;super(r.message,r.code,r.data);let i=Object.values(Ue).find(p=>p.eipCode===r.code);this.details=i||Ue.UNKNOWN_ERROR,r.code===-32002&&((n=r.message)!=null&&n.includes("already pending for origin")?(s=r.message)!=null&&s.includes("wallet_requestPermissions")?this.details=Ue.E32002_CONNECTION_ALREADY_PENDING:this.details=Ue.E32002_REQUEST_ALREADY_PENDING:(a=r.message)!=null&&a.includes("Already processing")&&r.message.includes("eth_requestAccounts")&&(this.details=Ue.E32002_WALLET_LOCKED))}},Bn={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}},Vn={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}},Hn={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}},Ue={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...Hn,...Vn},Ye={...Bn,...Ue};var zn=12e4,Ro=(t=new Ke,e=zn)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),de=class{constructor(e){this.removeListener=(e,o)=>{if(this.walletProvider)return this.walletProvider.removeListener(e,o)};this.setProvider=e=>{this.walletProvider=e,this._subscriptions.forEach(o=>{var r;(r=this.walletProvider)==null||r.on(o.eventName,o.listener)})};this.walletProvider=e,this._subscriptions=[]}on(e,o){if(this.walletProvider)return this.walletProvider.on(e,o);this._subscriptions.push({eventName:e,listener:o})}async 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),Ro()]).catch(o=>{throw Pe(o)})}},fe=class extends de{constructor(o){super(o)}},Ft=class extends de{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var ge=class{constructor(e,o,r){this.createSiweMessage=(e,o,r,i,n,s,a)=>`${r} wants you to sign in with your Ethereum account:
1
+ import{Web3Provider as u1}from"@ethersproject/providers";import{useEffect as Nn,useState as te}from"react";import Un from"axios";var ne=class extends Error{constructor(o,r){super(o);r instanceof Error&&(this.cause=r)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},je=class extends ne{constructor(o,r,i,n){super(i,n);this.type=o;this.status=r}},y=class extends ne{constructor(o,r){super(o,r);this.type="client_error"}};var B=class extends ne{constructor(o,r){super(o,r);this.type="connector_error"}},U=t=>{if(t instanceof ne)return t;if(!Un.isAxiosError(t))return oe(t);if(!t.response)return new je("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new je(e||"ApiError",t.response.status,o||r,t)},oe=t=>t instanceof ne?t:t instanceof Error?new y(t.message,t):new y(`Internal error: ${t}`);var vr=()=>"/api/v1/sessions",Cr=()=>"/api/v1/sessions/logout",br=()=>"/api/v1/sessions/fork",xr=()=>"/api/v1/siwe/init",Er=()=>"/api/v1/siwe/authenticate",Lr=()=>"/api/v1/siwe/link",Ar=()=>"/api/v1/passwordless/init",_r=()=>"/api/v1/passwordless/authenticate",Pr=()=>"/api/v1/passwordless/link",Sr=()=>"/api/v1/passwordless_sms/init",kr=()=>"/api/v1/passwordless_sms/authenticate",Tr=()=>"/api/v1/passwordless_sms/link",Wr=()=>"/api/v1/oauth/init",Ir=()=>"/api/v1/oauth/authenticate",Rr=()=>"/api/v1/oauth/link",Mr=()=>"/api/v1/siwe/unlink",Nr=()=>"/api/v1/passwordless/unlink",Or=()=>"/api/v1/passwordless_sms/unlink",Ur=()=>"/api/v1/oauth/unlink";var ft=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new y("Email and email code must be set prior to calling authenticate.");try{let e=_r(),o=await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw U(e)}}async link(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new y("Email and email code must be set prior to calling authenticate.");try{let e=Pr();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw U(e)}}async sendCodeEmail(e){if(!this.api)throw new y("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new y("Email must be set when initialzing authentication.");try{let o=Ar();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw U(o)}}};var Ze=class{constructor(e,o,r){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=r}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new y("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new y("User denied confirmation during OAuth flow");try{let e=Ir(),o=await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw U(e)}}async link(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new y("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new y("User denied confirmation during OAuth flow");try{let e=Rr();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw U(e)}}async getAuthorizationUrl(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.provider)throw new y("Provider must be set when initialzing OAuth authentication.");try{let e=Wr();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw U(e)}}};var gt=class{constructor(e,o){this.meta={walletType:o},this.connectors=e,this.walletConnector=this.connectors.createWalletConnector(o,null)}async authenticate(){if(!this.api)throw new y("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Er(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),await this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),{user:r.data.user,token:r.data.token,refresh_token:r.data.refresh_token,is_new_user:r.data.is_new_user}}catch(e){throw U(e)}}async link(){if(!this.api)throw new y("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Lr(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),await this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),r.data}catch(e){throw U(e)}}async promptConnectAndSign(e){let o=await this.walletConnector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(xr(),{address:r}),s=this.walletConnector.prepareMessage(i,r,n.data.nonce),a=await this.walletConnector.sign(s);return{message:s,signature:a}}};var yt=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new y("phone number and sms code must be set prior to calling authenticate.");try{let e=kr(),o=await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw U(e)}}async link(){if(!this.api)throw new y("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new y("phone number and sms code must be set prior to calling authenticate.");try{let e=Tr();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw U(e)}}async sendSmsCode(e){if(!this.api)throw new y("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new y("phone nNumber must be set when initialzing authentication.");try{let o=Sr();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw U(o)}}};import{getAddress as es}from"@ethersproject/address";var Dr="1.17.0";var Fr="https://api.privy.io/v0",Po=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",wt="4df5e2316331463a9130964bd6078dfa",Gr=1e4,re=1400,So=Dr;var qe="privy:token",Ut="privy:refresh_token",Dt="privy:connectors",Br="walletconnect",ko=3e4;var To=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,o){o!==void 0?this._cache[e]=o:this.del(e)}del(e){delete this._cache[e]}getKeys(){return Object.keys(this._cache)}},Wo=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}getKeys(){return Object.entries(localStorage).map(([e])=>e)}};function Fn(){return typeof window<"u"&&window.localStorage?new Wo:new To}var Z=Fn();import Zn from"@coinbase/wallet-sdk";import{getAddress as qn}from"@ethersproject/address";import{getAddress as $n}from"@ethersproject/address";import{Web3Provider as jn}from"@ethersproject/providers";import{ErrorCode as Gn}from"@ethersproject/logger";var Ke=class extends B{constructor(){super("Wallet timeout");this.type="wallet_error"}},Pe=t=>{if(t instanceof B)return t;if((t==null?void 0:t.code)&&(t==null?void 0:t.reason)){let e=new Je(t);return t.code===Gn.ACTION_REJECTED&&(e.details=Ue.E4001_USER_REJECTED_REQUEST),e}return t!=null&&t.code?new Je(t):new B("Unknown connector error",t)},Io=class extends ne{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},Je=class extends Io{constructor(o){var n,s,a;let r=o;super(r.message,r.code,r.data);let i=Object.values(Ue).find(p=>p.eipCode===r.code);this.details=i||Ue.UNKNOWN_ERROR,r.code===-32002&&((n=r.message)!=null&&n.includes("already pending for origin")?(s=r.message)!=null&&s.includes("wallet_requestPermissions")?this.details=Ue.E32002_CONNECTION_ALREADY_PENDING:this.details=Ue.E32002_REQUEST_ALREADY_PENDING:(a=r.message)!=null&&a.includes("Already processing")&&r.message.includes("eth_requestAccounts")&&(this.details=Ue.E32002_WALLET_LOCKED))}},Bn={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}},Vn={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}},Hn={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}},Ue={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...Hn,...Vn},Ye={...Bn,...Ue};var zn=12e4,Ro=(t=new Ke,e=zn)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),de=class{constructor(e){this.removeListener=(e,o)=>{if(this.walletProvider)return this.walletProvider.removeListener(e,o)};this.setProvider=e=>{this.walletProvider=e,this._subscriptions.forEach(o=>{var r;(r=this.walletProvider)==null||r.on(o.eventName,o.listener)})};this.walletProvider=e,this._subscriptions=[]}on(e,o){if(this.walletProvider)return this.walletProvider.on(e,o);this._subscriptions.push({eventName:e,listener:o})}async 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),Ro()]).catch(o=>{throw Pe(o)})}},fe=class extends de{constructor(o){super(o)}},Ft=class extends de{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var ge=class{constructor(e,o,r){this.createSiweMessage=(e,o,r,i,n,s,a)=>`${r} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${a}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var $n=Object.create;var Xt=Object.defineProperty;var jn=Object.getOwnPropertyDescriptor;var Zn=Object.getOwnPropertyNames;var qn=Object.getPrototypeOf,Kn=Object.prototype.hasOwnProperty;var Jn=(t,e)=>{for(var o in e)Xt(t,o,{get:e[o],enumerable:!0})},Rr=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Zn(e))!Kn.call(t,i)&&i!==o&&Xt(t,i,{get:()=>e[i],enumerable:!(r=jn(e,i))||r.enumerable});return t};var E=(t,e,o)=>(o=t!=null?$n(qn(t)):{},Rr(e||!t||!t.__esModule?Xt(o,"default",{value:t,enumerable:!0}):o,t)),Yn=t=>Rr(Xt({},"__esModule",{value:!0}),t);var ol={};Jn(ol,{AsExternalProvider:()=>Se,ConnectorManager:()=>ft,PrivyClient:()=>gt,PrivyProvider:()=>zn,PrivyProxyProvider:()=>Ce,VERSION:()=>Qt,WalletConnector:()=>ke,getAccessToken:()=>Hn,usePrivy:()=>q});module.exports=Yn(ol);var Vn=require("@ethersproject/providers"),Y=require("react");var Mr=E(require("axios")),ve=class extends Error{constructor(o,r){super(o);r instanceof Error&&(this.cause=r)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},ct=class extends ve{constructor(o,r,i,n){super(i,n);this.type=o;this.status=r}},w=class extends ve{constructor(o,r){super(o,r);this.type="client_error"}};var Z=class extends ve{constructor(o,r){super(o,r);this.type="connector_error"}},V=t=>{if(t instanceof ve)return t;if(!Mr.default.isAxiosError(t))return ue(t);if(!t.response)return new ct("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new ct(e||"ApiError",t.response.status,o||r,t)},ue=t=>t instanceof ve?t:t instanceof Error?new w(t.message,t):new w(`Internal error: ${t}`);var Nr=()=>"/api/v1/sessions",Or=()=>"/api/v1/sessions/logout",Ur=()=>"/api/v1/sessions/fork",Dr=()=>"/api/v1/siwe/init",Fr=()=>"/api/v1/siwe/authenticate",Gr=()=>"/api/v1/siwe/link",Br=()=>"/api/v1/passwordless/init",Vr=()=>"/api/v1/passwordless/authenticate",Hr=()=>"/api/v1/passwordless/link",zr=()=>"/api/v1/passwordless_sms/init",$r=()=>"/api/v1/passwordless_sms/authenticate",jr=()=>"/api/v1/passwordless_sms/link",Zr=()=>"/api/v1/oauth/init",qr=()=>"/api/v1/oauth/authenticate",Kr=()=>"/api/v1/oauth/link",Jr=()=>"/api/v1/siwe/unlink",Yr=()=>"/api/v1/passwordless/unlink",Xr=()=>"/api/v1/passwordless_sms/unlink",Qr=()=>"/api/v1/oauth/unlink";var Mt=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new w("Email and email code must be set prior to calling authenticate.");try{let e=Vr(),o=await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw V(e)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new w("Email and email code must be set prior to calling authenticate.");try{let e=Hr();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw V(e)}}async sendCodeEmail(e){if(!this.api)throw new w("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new w("Email must be set when initialzing authentication.");try{let o=Br();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw V(o)}}};var dt=class{constructor(e,o,r){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=r}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new w("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new w("User denied confirmation during OAuth flow");try{let e=qr(),o=await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw V(e)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new w("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new w("User denied confirmation during OAuth flow");try{let e=Kr();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw V(e)}}async getAuthorizationUrl(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.provider)throw new w("Provider must be set when initialzing OAuth authentication.");try{let e=Zr();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw V(e)}}};var Nt=class{constructor(e,o){this.meta={walletType:o},this.connectors=e,this.walletConnector=this.connectors.createWalletConnector(o,null)}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Fr(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),await this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),{user:r.data.user,token:r.data.token,refresh_token:r.data.refresh_token,is_new_user:r.data.is_new_user}}catch(e){throw V(e)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Gr(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),await this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),r.data}catch(e){throw V(e)}}async promptConnectAndSign(e){let o=await this.walletConnector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(Dr(),{address:r}),s=this.walletConnector.prepareMessage(i,r,n.data.nonce),a=await this.walletConnector.sign(s);return{message:s,signature:a}}};var Ot=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new w("phone number and sms code must be set prior to calling authenticate.");try{let e=$r(),o=await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw V(e)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new w("phone number and sms code must be set prior to calling authenticate.");try{let e=jr();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw V(e)}}async sendSmsCode(e){if(!this.api)throw new w("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new w("phone nNumber must be set when initialzing authentication.");try{let o=zr();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw V(o)}}};var wi=require("@ethersproject/address");var ei="1.17.0-beta.2";var ti="https://api.privy.io/v0",Ho=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",Ut="4df5e2316331463a9130964bd6078dfa",oi=1e4,he=1400,Qt=ei;var pt="privy:token",eo="privy:refresh_token",to="privy:connectors",ri="walletconnect",zo=3e4;var $o=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,o){o!==void 0?this._cache[e]=o:this.del(e)}del(e){delete this._cache[e]}getKeys(){return Object.keys(this._cache)}},jo=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}getKeys(){return Object.entries(localStorage).map(([e])=>e)}};function Qn(){return typeof window<"u"&&window.localStorage?new jo:new $o}var re=Qn();var ai=E(require("@coinbase/wallet-sdk")),li=require("@ethersproject/address");var ni=require("@ethersproject/address"),si=require("@ethersproject/providers");var ii=require("@ethersproject/logger");var ut=class extends Z{constructor(){super("Wallet timeout");this.type="wallet_error"}},Ve=t=>{if(t instanceof Z)return t;if((t==null?void 0:t.code)&&(t==null?void 0:t.reason)){let e=new ht(t);return t.code===ii.ErrorCode.ACTION_REJECTED&&(e.details=ot.E4001_USER_REJECTED_REQUEST),e}return t!=null&&t.code?new ht(t):new Z("Unknown connector error",t)},Zo=class extends ve{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},ht=class extends Zo{constructor(o){var n,s,a;let r=o;super(r.message,r.code,r.data);let i=Object.values(ot).find(h=>h.eipCode===r.code);this.details=i||ot.UNKNOWN_ERROR,r.code===-32002&&((n=r.message)!=null&&n.includes("already pending for origin")?(s=r.message)!=null&&s.includes("wallet_requestPermissions")?this.details=ot.E32002_CONNECTION_ALREADY_PENDING:this.details=ot.E32002_REQUEST_ALREADY_PENDING:(a=r.message)!=null&&a.includes("Already processing")&&r.message.includes("eth_requestAccounts")&&(this.details=ot.E32002_WALLET_LOCKED))}},es={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}},ts={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}},os={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}},ot={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...os,...ts},mt={...es,...ot};var rs=12e4,qo=(t=new ut,e=rs)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),Ce=class{constructor(e){this.removeListener=(e,o)=>{if(this.walletProvider)return this.walletProvider.removeListener(e,o)};this.setProvider=e=>{this.walletProvider=e,this._subscriptions.forEach(o=>{var r;(r=this.walletProvider)==null||r.on(o.eventName,o.listener)})};this.walletProvider=e,this._subscriptions=[]}on(e,o){if(this.walletProvider)return this.walletProvider.on(e,o);this._subscriptions.push({eventName:e,listener:o})}async request(e){if(!this.walletProvider)throw new Z(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),qo()]).catch(o=>{throw Ve(o)})}},Se=class extends Ce{constructor(o){super(o)}},oo=class extends Ce{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var ke=class{constructor(e,o,r){this.createSiweMessage=(e,o,r,i,n,s,a)=>`${r} wants you to sign in with your Ethereum account:
1
+ "use strict";var $n=Object.create;var Xt=Object.defineProperty;var jn=Object.getOwnPropertyDescriptor;var Zn=Object.getOwnPropertyNames;var qn=Object.getPrototypeOf,Kn=Object.prototype.hasOwnProperty;var Jn=(t,e)=>{for(var o in e)Xt(t,o,{get:e[o],enumerable:!0})},Rr=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Zn(e))!Kn.call(t,i)&&i!==o&&Xt(t,i,{get:()=>e[i],enumerable:!(r=jn(e,i))||r.enumerable});return t};var E=(t,e,o)=>(o=t!=null?$n(qn(t)):{},Rr(e||!t||!t.__esModule?Xt(o,"default",{value:t,enumerable:!0}):o,t)),Yn=t=>Rr(Xt({},"__esModule",{value:!0}),t);var ol={};Jn(ol,{AsExternalProvider:()=>Se,ConnectorManager:()=>ft,PrivyClient:()=>gt,PrivyProvider:()=>zn,PrivyProxyProvider:()=>Ce,VERSION:()=>Qt,WalletConnector:()=>ke,getAccessToken:()=>Hn,usePrivy:()=>q});module.exports=Yn(ol);var Vn=require("@ethersproject/providers"),Y=require("react");var Mr=E(require("axios")),ve=class extends Error{constructor(o,r){super(o);r instanceof Error&&(this.cause=r)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},ct=class extends ve{constructor(o,r,i,n){super(i,n);this.type=o;this.status=r}},w=class extends ve{constructor(o,r){super(o,r);this.type="client_error"}};var Z=class extends ve{constructor(o,r){super(o,r);this.type="connector_error"}},V=t=>{if(t instanceof ve)return t;if(!Mr.default.isAxiosError(t))return ue(t);if(!t.response)return new ct("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new ct(e||"ApiError",t.response.status,o||r,t)},ue=t=>t instanceof ve?t:t instanceof Error?new w(t.message,t):new w(`Internal error: ${t}`);var Nr=()=>"/api/v1/sessions",Or=()=>"/api/v1/sessions/logout",Ur=()=>"/api/v1/sessions/fork",Dr=()=>"/api/v1/siwe/init",Fr=()=>"/api/v1/siwe/authenticate",Gr=()=>"/api/v1/siwe/link",Br=()=>"/api/v1/passwordless/init",Vr=()=>"/api/v1/passwordless/authenticate",Hr=()=>"/api/v1/passwordless/link",zr=()=>"/api/v1/passwordless_sms/init",$r=()=>"/api/v1/passwordless_sms/authenticate",jr=()=>"/api/v1/passwordless_sms/link",Zr=()=>"/api/v1/oauth/init",qr=()=>"/api/v1/oauth/authenticate",Kr=()=>"/api/v1/oauth/link",Jr=()=>"/api/v1/siwe/unlink",Yr=()=>"/api/v1/passwordless/unlink",Xr=()=>"/api/v1/passwordless_sms/unlink",Qr=()=>"/api/v1/oauth/unlink";var Mt=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new w("Email and email code must be set prior to calling authenticate.");try{let e=Vr(),o=await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw V(e)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new w("Email and email code must be set prior to calling authenticate.");try{let e=Hr();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw V(e)}}async sendCodeEmail(e){if(!this.api)throw new w("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new w("Email must be set when initialzing authentication.");try{let o=Br();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw V(o)}}};var dt=class{constructor(e,o,r){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=r}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new w("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new w("User denied confirmation during OAuth flow");try{let e=qr(),o=await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw V(e)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new w("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new w("User denied confirmation during OAuth flow");try{let e=Kr();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw V(e)}}async getAuthorizationUrl(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.provider)throw new w("Provider must be set when initialzing OAuth authentication.");try{let e=Zr();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw V(e)}}};var Nt=class{constructor(e,o){this.meta={walletType:o},this.connectors=e,this.walletConnector=this.connectors.createWalletConnector(o,null)}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Fr(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),await this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),{user:r.data.user,token:r.data.token,refresh_token:r.data.refresh_token,is_new_user:r.data.is_new_user}}catch(e){throw V(e)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Gr(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),await this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),r.data}catch(e){throw V(e)}}async promptConnectAndSign(e){let o=await this.walletConnector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(Dr(),{address:r}),s=this.walletConnector.prepareMessage(i,r,n.data.nonce),a=await this.walletConnector.sign(s);return{message:s,signature:a}}};var Ot=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new w("phone number and sms code must be set prior to calling authenticate.");try{let e=$r(),o=await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw V(e)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new w("phone number and sms code must be set prior to calling authenticate.");try{let e=jr();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw V(e)}}async sendSmsCode(e){if(!this.api)throw new w("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new w("phone nNumber must be set when initialzing authentication.");try{let o=zr();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw V(o)}}};var wi=require("@ethersproject/address");var ei="1.17.0";var ti="https://api.privy.io/v0",Ho=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",Ut="4df5e2316331463a9130964bd6078dfa",oi=1e4,he=1400,Qt=ei;var pt="privy:token",eo="privy:refresh_token",to="privy:connectors",ri="walletconnect",zo=3e4;var $o=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,o){o!==void 0?this._cache[e]=o:this.del(e)}del(e){delete this._cache[e]}getKeys(){return Object.keys(this._cache)}},jo=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}getKeys(){return Object.entries(localStorage).map(([e])=>e)}};function Qn(){return typeof window<"u"&&window.localStorage?new jo:new $o}var re=Qn();var ai=E(require("@coinbase/wallet-sdk")),li=require("@ethersproject/address");var ni=require("@ethersproject/address"),si=require("@ethersproject/providers");var ii=require("@ethersproject/logger");var ut=class extends Z{constructor(){super("Wallet timeout");this.type="wallet_error"}},Ve=t=>{if(t instanceof Z)return t;if((t==null?void 0:t.code)&&(t==null?void 0:t.reason)){let e=new ht(t);return t.code===ii.ErrorCode.ACTION_REJECTED&&(e.details=ot.E4001_USER_REJECTED_REQUEST),e}return t!=null&&t.code?new ht(t):new Z("Unknown connector error",t)},Zo=class extends ve{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},ht=class extends Zo{constructor(o){var n,s,a;let r=o;super(r.message,r.code,r.data);let i=Object.values(ot).find(h=>h.eipCode===r.code);this.details=i||ot.UNKNOWN_ERROR,r.code===-32002&&((n=r.message)!=null&&n.includes("already pending for origin")?(s=r.message)!=null&&s.includes("wallet_requestPermissions")?this.details=ot.E32002_CONNECTION_ALREADY_PENDING:this.details=ot.E32002_REQUEST_ALREADY_PENDING:(a=r.message)!=null&&a.includes("Already processing")&&r.message.includes("eth_requestAccounts")&&(this.details=ot.E32002_WALLET_LOCKED))}},es={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}},ts={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}},os={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}},ot={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...os,...ts},mt={...es,...ot};var rs=12e4,qo=(t=new ut,e=rs)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),Ce=class{constructor(e){this.removeListener=(e,o)=>{if(this.walletProvider)return this.walletProvider.removeListener(e,o)};this.setProvider=e=>{this.walletProvider=e,this._subscriptions.forEach(o=>{var r;(r=this.walletProvider)==null||r.on(o.eventName,o.listener)})};this.walletProvider=e,this._subscriptions=[]}on(e,o){if(this.walletProvider)return this.walletProvider.on(e,o);this._subscriptions.push({eventName:e,listener:o})}async request(e){if(!this.walletProvider)throw new Z(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),qo()]).catch(o=>{throw Ve(o)})}},Se=class extends Ce{constructor(o){super(o)}},oo=class extends Ce{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var ke=class{constructor(e,o,r){this.createSiweMessage=(e,o,r,i,n,s,a)=>`${r} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${a}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privy-io/react-auth",
3
- "version": "1.17.0-beta.2",
3
+ "version": "1.17.0",
4
4
  "description": "React client for the Privy Auth API",
5
5
  "keywords": [
6
6
  "authentication",