@privy-io/react-auth 1.57.1-beta-20240227144952 → 1.57.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var gs=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var yc=(e,t,o)=>(gs(e,t,"read from private field"),o?o.call(e):t.get(e)),gi=(e,t,o)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,o)},vs=(e,t,o,r)=>(gs(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var gc=(e,t,o)=>(gs(e,t,"access private method"),o);import{getAddress as hs}from"@ethersproject/address";import{StaticJsonRpcProvider as l2,Web3Provider as pc}from"@ethersproject/providers";import{createStore as c2}from"mipd";import{useCallback as d2,useEffect as xo,useMemo as p2,useRef as fi,useState as Pe}from"react";import{FetchError as Oh}from"ofetch";var Ne=class extends Error{constructor(o,r,n){super(o);r instanceof Error&&(this.cause=r),this.privyErrorCode=n}toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},zt=class extends Ne{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},w=class extends Ne{constructor(o,r,n){super(o,r,n);this.type="client_error"}},vi=class extends w{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var q=class extends Ne{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},ie=e=>{if(e instanceof Ne)return e;if(!(e instanceof Oh))return Ge(e);if(!e.response)return new zt("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new zt(t||"ApiError",e.response.status,o||r,e,n)},Ge=e=>e instanceof Ne?e:e instanceof Error?new w(e.message,e):new w(`Internal error: ${e}`);var Ar=class extends w{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},at=class extends w{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},wi=class extends w{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var Ci=()=>"/api/v1/sessions",bi=()=>"/api/v1/sessions/logout",vc=()=>"/api/v1/sessions/fork",Ei=()=>"/api/v1/sessions/fork/recover",wc=()=>"/api/v1/siwe/init",Cc=()=>"/api/v1/siwe/authenticate",bc=()=>"/api/v1/siwe/link",Ec=()=>"/api/v1/farcaster/init",Tc=()=>"/api/v1/farcaster/authenticate",Pc=()=>"/api/v1/farcaster/link",xc=()=>"/api/v1/farcaster/status",Sc=()=>"/api/v1/passwordless/init",_c=()=>"/api/v1/passwordless/authenticate",Ac=()=>"/api/v1/passwordless/link",kc=()=>"/api/v1/passwordless_sms/init",Rc=()=>"/api/v1/passwordless_sms/authenticate",Ic=()=>"/api/v1/passwordless_sms/link",Wc=()=>"/api/v1/oauth/init",Mc=()=>"/api/v1/oauth/authenticate",Nc=()=>"/api/v1/oauth/link",Lc=()=>"/api/v1/siwe/unlink",Oc=()=>"/api/v1/passwordless/unlink",Dc=()=>"/api/v1/passwordless_sms/unlink",Uc=()=>"/api/v1/oauth/unlink",Fc=()=>"/api/v1/farcaster/unlink",Bc=()=>"/api/v1/analytics_events",Hc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Gc=()=>"/api/v1/custom_jwt_account/authenticate",Vc=()=>"/api/v1/mfa/passwordless_sms/init";var zc=()=>"/api/v1/mfa/passwordless_sms/enroll";var $c=()=>"/api/v1/users/me/accept_terms";var kr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");try{let t=Gc(),o=await this.api.post(t,{token:this.meta.token});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw ie(t)}}async link(){throw new Error("Unimplemented")}};var er=class{constructor(t,o){this.meta={email:t,captchaToken:o}}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 t=_c(),o=await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw ie(t)}}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 t=Ac();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw ie(t)}}async sendCodeEmail(t,o){if(!this.api)throw new w("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new w("Email must be set when initialzing authentication.");try{let r=Sc();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw ie(r)}}};import{isMobile as Dh}from"react-device-detect";var Ve=class{constructor(t){this.promise=null;this.fn=t}execute(t){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(t)}finally{this.promise=null}})()),this.promise}};var Pn=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new Ve(this._startChannelOnce.bind(this)),this.pollForReady=new Ve(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.channelToken)throw new w("Auth flow must be initialized first");try{let t=await this.api.post(Tc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new w("No response from authentication");return{user:t.user,token:t.token,refresh_token:t.refresh_token,is_new_user:t.is_new_user}}catch(t){throw ie(t)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");try{return await this.api.post(Pc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw ie(t)}}async _startChannelOnce(){if(!this.api)throw new w("Auth flow has no API instance");let t=await this.api.post(Ec(),{token:this.captchaToken});Dh&&t.connect_uri&&window.open(t.connect_uri,"_blank","noopener noreferrer"),this._meta={connectUri:t.connect_uri,channelToken:t.channel_token}}async initializeFarcasterConnect(){if(!this.api)throw new w("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.channelToken)throw new w("Auth flow must be initialized first");let t=await this.api.get(xc(),{headers:{"farcaster-channel-token":this.meta.channelToken}});return t.state==="completed"?(this.message=t.message,this.signature=t.signature,this.fid=t.fid,!0):!1}};import{base64url as ad}from"jose";var qc="1.57.1-beta-20240227144952";var Ti="4df5e2316331463a9130964bd6078dfa",jc="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Kc="34357d3c125c2bcf2ce2bc3309d98715",Pi="https://auth.privy.io",Yc=2e4,ze=1400,Jc=2500,ws=qc;var tr="privy:token",Cs="privy-token",xi="privy:refresh_token",bs="privy-refresh-token",Si="privy-session",xn="privy:session_transfer_token",Fh="privy:wallet",Sn="privy:caid",Rr="privy:state_code",Ir="privy:code_verifier",_i=e=>`${Fh}:${e}`,Es="privy:connectors",Ts="privy:connections";var or=12e4,fo=1,Ps="0x1",Wr=3e4,Qc="https://api.moonpay.com/v1",Zc="https://api.moonpay.com/v1",Xc="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",ed="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",td="0x420000000000000000000000000000000000000F",od=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function rd(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function nd(e){return crypto.getRandomValues(new Uint8Array(e))}var Ai=class{constructor(){this._cache={}}get(t){return this._cache[t]}put(t,o){o!==void 0?this._cache[t]=o:this.del(t)}del(t){delete this._cache[t]}getKeys(){return Object.keys(this._cache)}},xs=class{get(t){let o=localStorage.getItem(t);return o===null?void 0:JSON.parse(o)}put(t,o){o!==void 0?localStorage.setItem(t,JSON.stringify(o)):this.del(t)}del(t){localStorage.removeItem(t)}getKeys(){return Object.entries(localStorage).map(([t])=>t)}},Ss=class{get(t){let o=sessionStorage.getItem(t);return o===null?void 0:JSON.parse(o)}put(t,o){o!==void 0?sessionStorage.setItem(t,JSON.stringify(o)):this.del(t)}del(t){sessionStorage.removeItem(t)}getKeys(){return Object.entries(sessionStorage).map(([t])=>t)}};function id(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Bh(){return typeof window<"u"&&window.localStorage?new xs:new Ai}function Hh(){return typeof window<"u"&&window.sessionStorage?new Ss:new Ai}var It=Hh(),re=Bh();var Gh="S256",Vh="S256",ko=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}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");let t=It.get(Ir);if(!t)throw new w("Authentication error.");try{let o=Mc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return It.del(Ir),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=ie(o);throw r.privyErrorCode?new w(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new w("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new w("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}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");let t=It.get(Ir);if(!t)throw new w("Authentication error.");try{let o=Nc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return It.del(Ir),r}catch(o){throw ie(o)}}createCodeVerifier(){return ad.encode(nd(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Gh){if(o==Vh){let r=await rd(t);return ad.encode(r)}else return t}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 initializing OAuth authentication.");let t=this.createCodeVerifier();It.put(Ir,t);let o=this.createStateCode();It.put(Rr,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=Wc();return await this.api.post(n,{provider:this.meta.provider,redirect_to:window.location.href,token:this.meta.captchaToken,code_challenge:r,state_code:o})}catch(n){throw ie(n)}}};var rr=class{constructor(t,o){this.createSiweMessage=(t,o,r,n,i,a,l)=>`${r} wants you to sign in with your Ethereum account:
1
+ var gs=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var yc=(e,t,o)=>(gs(e,t,"read from private field"),o?o.call(e):t.get(e)),gi=(e,t,o)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,o)},vs=(e,t,o,r)=>(gs(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var gc=(e,t,o)=>(gs(e,t,"access private method"),o);import{getAddress as hs}from"@ethersproject/address";import{StaticJsonRpcProvider as l2,Web3Provider as pc}from"@ethersproject/providers";import{createStore as c2}from"mipd";import{useCallback as d2,useEffect as xo,useMemo as p2,useRef as fi,useState as Pe}from"react";import{FetchError as Oh}from"ofetch";var Ne=class extends Error{constructor(o,r,n){super(o);r instanceof Error&&(this.cause=r),this.privyErrorCode=n}toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},zt=class extends Ne{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},w=class extends Ne{constructor(o,r,n){super(o,r,n);this.type="client_error"}},vi=class extends w{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var q=class extends Ne{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},ie=e=>{if(e instanceof Ne)return e;if(!(e instanceof Oh))return Ge(e);if(!e.response)return new zt("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new zt(t||"ApiError",e.response.status,o||r,e,n)},Ge=e=>e instanceof Ne?e:e instanceof Error?new w(e.message,e):new w(`Internal error: ${e}`);var Ar=class extends w{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},at=class extends w{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},wi=class extends w{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var Ci=()=>"/api/v1/sessions",bi=()=>"/api/v1/sessions/logout",vc=()=>"/api/v1/sessions/fork",Ei=()=>"/api/v1/sessions/fork/recover",wc=()=>"/api/v1/siwe/init",Cc=()=>"/api/v1/siwe/authenticate",bc=()=>"/api/v1/siwe/link",Ec=()=>"/api/v1/farcaster/init",Tc=()=>"/api/v1/farcaster/authenticate",Pc=()=>"/api/v1/farcaster/link",xc=()=>"/api/v1/farcaster/status",Sc=()=>"/api/v1/passwordless/init",_c=()=>"/api/v1/passwordless/authenticate",Ac=()=>"/api/v1/passwordless/link",kc=()=>"/api/v1/passwordless_sms/init",Rc=()=>"/api/v1/passwordless_sms/authenticate",Ic=()=>"/api/v1/passwordless_sms/link",Wc=()=>"/api/v1/oauth/init",Mc=()=>"/api/v1/oauth/authenticate",Nc=()=>"/api/v1/oauth/link",Lc=()=>"/api/v1/siwe/unlink",Oc=()=>"/api/v1/passwordless/unlink",Dc=()=>"/api/v1/passwordless_sms/unlink",Uc=()=>"/api/v1/oauth/unlink",Fc=()=>"/api/v1/farcaster/unlink",Bc=()=>"/api/v1/analytics_events",Hc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Gc=()=>"/api/v1/custom_jwt_account/authenticate",Vc=()=>"/api/v1/mfa/passwordless_sms/init";var zc=()=>"/api/v1/mfa/passwordless_sms/enroll";var $c=()=>"/api/v1/users/me/accept_terms";var kr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");try{let t=Gc(),o=await this.api.post(t,{token:this.meta.token});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw ie(t)}}async link(){throw new Error("Unimplemented")}};var er=class{constructor(t,o){this.meta={email:t,captchaToken:o}}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 t=_c(),o=await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw ie(t)}}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 t=Ac();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw ie(t)}}async sendCodeEmail(t,o){if(!this.api)throw new w("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new w("Email must be set when initialzing authentication.");try{let r=Sc();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw ie(r)}}};import{isMobile as Dh}from"react-device-detect";var Ve=class{constructor(t){this.promise=null;this.fn=t}execute(t){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(t)}finally{this.promise=null}})()),this.promise}};var Pn=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new Ve(this._startChannelOnce.bind(this)),this.pollForReady=new Ve(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.channelToken)throw new w("Auth flow must be initialized first");try{let t=await this.api.post(Tc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new w("No response from authentication");return{user:t.user,token:t.token,refresh_token:t.refresh_token,is_new_user:t.is_new_user}}catch(t){throw ie(t)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");try{return await this.api.post(Pc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw ie(t)}}async _startChannelOnce(){if(!this.api)throw new w("Auth flow has no API instance");let t=await this.api.post(Ec(),{token:this.captchaToken});Dh&&t.connect_uri&&window.open(t.connect_uri,"_blank","noopener noreferrer"),this._meta={connectUri:t.connect_uri,channelToken:t.channel_token}}async initializeFarcasterConnect(){if(!this.api)throw new w("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.channelToken)throw new w("Auth flow must be initialized first");let t=await this.api.get(xc(),{headers:{"farcaster-channel-token":this.meta.channelToken}});return t.state==="completed"?(this.message=t.message,this.signature=t.signature,this.fid=t.fid,!0):!1}};import{base64url as ad}from"jose";var qc="1.57.1";var Ti="4df5e2316331463a9130964bd6078dfa",jc="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Kc="34357d3c125c2bcf2ce2bc3309d98715",Pi="https://auth.privy.io",Yc=2e4,ze=1400,Jc=2500,ws=qc;var tr="privy:token",Cs="privy-token",xi="privy:refresh_token",bs="privy-refresh-token",Si="privy-session",xn="privy:session_transfer_token",Fh="privy:wallet",Sn="privy:caid",Rr="privy:state_code",Ir="privy:code_verifier",_i=e=>`${Fh}:${e}`,Es="privy:connectors",Ts="privy:connections";var or=12e4,fo=1,Ps="0x1",Wr=3e4,Qc="https://api.moonpay.com/v1",Zc="https://api.moonpay.com/v1",Xc="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",ed="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",td="0x420000000000000000000000000000000000000F",od=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function rd(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function nd(e){return crypto.getRandomValues(new Uint8Array(e))}var Ai=class{constructor(){this._cache={}}get(t){return this._cache[t]}put(t,o){o!==void 0?this._cache[t]=o:this.del(t)}del(t){delete this._cache[t]}getKeys(){return Object.keys(this._cache)}},xs=class{get(t){let o=localStorage.getItem(t);return o===null?void 0:JSON.parse(o)}put(t,o){o!==void 0?localStorage.setItem(t,JSON.stringify(o)):this.del(t)}del(t){localStorage.removeItem(t)}getKeys(){return Object.entries(localStorage).map(([t])=>t)}},Ss=class{get(t){let o=sessionStorage.getItem(t);return o===null?void 0:JSON.parse(o)}put(t,o){o!==void 0?sessionStorage.setItem(t,JSON.stringify(o)):this.del(t)}del(t){sessionStorage.removeItem(t)}getKeys(){return Object.entries(sessionStorage).map(([t])=>t)}};function id(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Bh(){return typeof window<"u"&&window.localStorage?new xs:new Ai}function Hh(){return typeof window<"u"&&window.sessionStorage?new Ss:new Ai}var It=Hh(),re=Bh();var Gh="S256",Vh="S256",ko=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}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");let t=It.get(Ir);if(!t)throw new w("Authentication error.");try{let o=Mc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return It.del(Ir),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=ie(o);throw r.privyErrorCode?new w(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new w("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new w("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}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");let t=It.get(Ir);if(!t)throw new w("Authentication error.");try{let o=Nc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return It.del(Ir),r}catch(o){throw ie(o)}}createCodeVerifier(){return ad.encode(nd(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Gh){if(o==Vh){let r=await rd(t);return ad.encode(r)}else return t}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 initializing OAuth authentication.");let t=this.createCodeVerifier();It.put(Ir,t);let o=this.createStateCode();It.put(Rr,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=Wc();return await this.api.post(n,{provider:this.meta.provider,redirect_to:window.location.href,token:this.meta.captchaToken,code_challenge:r,state_code:o})}catch(n){throw ie(n)}}};var rr=class{constructor(t,o){this.createSiweMessage=(t,o,r,n,i,a,l)=>`${r} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${l}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Cg=Object.create;var ea=Object.defineProperty;var bg=Object.getOwnPropertyDescriptor;var Eg=Object.getOwnPropertyNames;var Tg=Object.getPrototypeOf,Pg=Object.prototype.hasOwnProperty;var xg=(e,t)=>{for(var o in t)ea(e,o,{get:t[o],enumerable:!0})},qc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Eg(t))!Pg.call(e,n)&&n!==o&&ea(e,n,{get:()=>t[n],enumerable:!(r=bg(t,n))||r.enumerable});return e};var f=(e,t,o)=>(o=e!=null?Cg(Tg(e)):{},qc(t||!e||!e.__esModule?ea(o,"default",{value:e,enumerable:!0}):o,e)),Sg=e=>qc(ea({},"__esModule",{value:!0}),e);var al=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var jc=(e,t,o)=>(al(e,t,"read from private field"),o?o.call(e):t.get(e)),ta=(e,t,o)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,o)},sl=(e,t,o,r)=>(al(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var Kc=(e,t,o)=>(al(e,t,"access private method"),o);var VC={};xg(VC,{AsExternalProvider:()=>lo,Captcha:()=>ja,ConnectorManager:()=>Wn,PrivyClient:()=>Mn,PrivyProvider:()=>Zy,PrivyProxyProvider:()=>Pe,SUPPORTED_CHAINS:()=>kn,VERSION:()=>ca,WalletConnector:()=>pt,addRpcUrlOverrideToChain:()=>hg,errorIndicatesMaxMfaRetries:()=>gs,errorIndicatesMfaTimeout:()=>Kr,errorIndicatesMfaVerificationFailed:()=>Yr,getAccessToken:()=>$e,useConnectWallet:()=>ag,useCreateWallet:()=>lg,useLogin:()=>eg,useLoginWithEmail:()=>rg,useLoginWithSms:()=>ng,useLogout:()=>og,useMfa:()=>an,useMfaEnrollment:()=>ai,useModalStatus:()=>ug,usePrivy:()=>G,useRegisterMfaListener:()=>Qa,useSetWalletPassword:()=>dg,useToken:()=>fg,useWallets:()=>ui});module.exports=Sg(VC);var Qi=require("@ethersproject/address"),yi=require("@ethersproject/providers"),jy=require("mipd"),j=require("react");var Yc=require("ofetch"),et=class extends Error{constructor(o,r,n){super(o);r instanceof Error&&(this.cause=r),this.privyErrorCode=n}toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},To=class extends et{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},C=class extends et{constructor(o,r,n){super(o,r,n);this.type="client_error"}},oa=class extends C{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var Y=class extends et{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},fe=e=>{if(e instanceof et)return e;if(!(e instanceof Yc.FetchError))return lt(e);if(!e.response)return new To("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new To(t||"ApiError",e.response.status,o||r,e,n)},lt=e=>e instanceof et?e:e instanceof Error?new C(e.message,e):new C(`Internal error: ${e}`);var hn=class extends C{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},Rt=class extends C{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},ra=class extends C{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var na=()=>"/api/v1/sessions",ia=()=>"/api/v1/sessions/logout",Jc=()=>"/api/v1/sessions/fork",aa=()=>"/api/v1/sessions/fork/recover",Qc=()=>"/api/v1/siwe/init",Zc=()=>"/api/v1/siwe/authenticate",Xc=()=>"/api/v1/siwe/link",ed=()=>"/api/v1/farcaster/init",td=()=>"/api/v1/farcaster/authenticate",od=()=>"/api/v1/farcaster/link",rd=()=>"/api/v1/farcaster/status",nd=()=>"/api/v1/passwordless/init",id=()=>"/api/v1/passwordless/authenticate",ad=()=>"/api/v1/passwordless/link",sd=()=>"/api/v1/passwordless_sms/init",ld=()=>"/api/v1/passwordless_sms/authenticate",cd=()=>"/api/v1/passwordless_sms/link",dd=()=>"/api/v1/oauth/init",pd=()=>"/api/v1/oauth/authenticate",ud=()=>"/api/v1/oauth/link",md=()=>"/api/v1/siwe/unlink",fd=()=>"/api/v1/passwordless/unlink",hd=()=>"/api/v1/passwordless_sms/unlink",yd=()=>"/api/v1/oauth/unlink",gd=()=>"/api/v1/farcaster/unlink",vd=()=>"/api/v1/analytics_events",wd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Cd=()=>"/api/v1/custom_jwt_account/authenticate",bd=()=>"/api/v1/mfa/passwordless_sms/init";var Ed=()=>"/api/v1/mfa/passwordless_sms/enroll";var Td=()=>"/api/v1/users/me/accept_terms";var yn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");try{let t=Cd(),o=await this.api.post(t,{token:this.meta.token});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw fe(t)}}async link(){throw new Error("Unimplemented")}};var Fr=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=id(),o=await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw fe(t)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=ad();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw fe(t)}}async sendCodeEmail(t,o){if(!this.api)throw new C("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new C("Email must be set when initialzing authentication.");try{let r=nd();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw fe(r)}}};var Pd=require("react-device-detect");var ct=class{constructor(t){this.promise=null;this.fn=t}execute(t){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(t)}finally{this.promise=null}})()),this.promise}};var wi=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new ct(this._startChannelOnce.bind(this)),this.pollForReady=new ct(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.channelToken)throw new C("Auth flow must be initialized first");try{let t=await this.api.post(td(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new C("No response from authentication");return{user:t.user,token:t.token,refresh_token:t.refresh_token,is_new_user:t.is_new_user}}catch(t){throw fe(t)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");try{return await this.api.post(od(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw fe(t)}}async _startChannelOnce(){if(!this.api)throw new C("Auth flow has no API instance");let t=await this.api.post(ed(),{token:this.captchaToken});Pd.isMobile&&t.connect_uri&&window.open(t.connect_uri,"_blank","noopener noreferrer"),this._meta={connectUri:t.connect_uri,channelToken:t.channel_token}}async initializeFarcasterConnect(){if(!this.api)throw new C("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.channelToken)throw new C("Auth flow must be initialized first");let t=await this.api.get(rd(),{headers:{"farcaster-channel-token":this.meta.channelToken}});return t.state==="completed"?(this.message=t.message,this.signature=t.signature,this.fid=t.fid,!0):!1}};var hl=require("jose");var xd="1.57.1-beta-20240227144952";var sa="4df5e2316331463a9130964bd6078dfa",Sd="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",_d="34357d3c125c2bcf2ce2bc3309d98715",la="https://auth.privy.io",Ad=2e4,dt=1400,kd=2500,ca=xd;var Br="privy:token",ll="privy-token",da="privy:refresh_token",cl="privy-refresh-token",pa="privy-session",Ci="privy:session_transfer_token",Ag="privy:wallet",bi="privy:caid",gn="privy:state_code",vn="privy:code_verifier",ua=e=>`${Ag}:${e}`,dl="privy:connectors",pl="privy:connections";var Hr=12e4,Yo=1,ul="0x1",wn=3e4,Rd="https://api.moonpay.com/v1",Id="https://api.moonpay.com/v1",Wd="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Md="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Nd="0x420000000000000000000000000000000000000F",Ld=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Od(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Dd(e){return crypto.getRandomValues(new Uint8Array(e))}var ma=class{constructor(){this._cache={}}get(t){return this._cache[t]}put(t,o){o!==void 0?this._cache[t]=o:this.del(t)}del(t){delete this._cache[t]}getKeys(){return Object.keys(this._cache)}},ml=class{get(t){let o=localStorage.getItem(t);return o===null?void 0:JSON.parse(o)}put(t,o){o!==void 0?localStorage.setItem(t,JSON.stringify(o)):this.del(t)}del(t){localStorage.removeItem(t)}getKeys(){return Object.entries(localStorage).map(([t])=>t)}},fl=class{get(t){let o=sessionStorage.getItem(t);return o===null?void 0:JSON.parse(o)}put(t,o){o!==void 0?sessionStorage.setItem(t,JSON.stringify(o)):this.del(t)}del(t){sessionStorage.removeItem(t)}getKeys(){return Object.entries(sessionStorage).map(([t])=>t)}};function Ud(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function kg(){return typeof window<"u"&&window.localStorage?new ml:new ma}function Rg(){return typeof window<"u"&&window.sessionStorage?new fl:new ma}var no=Rg(),ce=kg();var Ig="S256",Wg="S256",fr=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=no.get(vn);if(!t)throw new C("Authentication error.");try{let o=pd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return no.del(vn),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=fe(o);throw r.privyErrorCode?new C(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new C("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new C("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=no.get(vn);if(!t)throw new C("Authentication error.");try{let o=ud(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return no.del(vn),r}catch(o){throw fe(o)}}createCodeVerifier(){return hl.base64url.encode(Dd(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Ig){if(o==Wg){let r=await Od(t);return hl.base64url.encode(r)}else return t}async getAuthorizationUrl(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.provider)throw new C("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();no.put(vn,t);let o=this.createStateCode();no.put(gn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=dd();return await this.api.post(n,{provider:this.meta.provider,redirect_to:window.location.href,token:this.meta.captchaToken,code_challenge:r,state_code:o})}catch(n){throw fe(n)}}};var Gr=class{constructor(t,o){this.createSiweMessage=(t,o,r,n,i,a,l)=>`${r} wants you to sign in with your Ethereum account:
1
+ "use strict";var Cg=Object.create;var ea=Object.defineProperty;var bg=Object.getOwnPropertyDescriptor;var Eg=Object.getOwnPropertyNames;var Tg=Object.getPrototypeOf,Pg=Object.prototype.hasOwnProperty;var xg=(e,t)=>{for(var o in t)ea(e,o,{get:t[o],enumerable:!0})},qc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Eg(t))!Pg.call(e,n)&&n!==o&&ea(e,n,{get:()=>t[n],enumerable:!(r=bg(t,n))||r.enumerable});return e};var f=(e,t,o)=>(o=e!=null?Cg(Tg(e)):{},qc(t||!e||!e.__esModule?ea(o,"default",{value:e,enumerable:!0}):o,e)),Sg=e=>qc(ea({},"__esModule",{value:!0}),e);var al=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var jc=(e,t,o)=>(al(e,t,"read from private field"),o?o.call(e):t.get(e)),ta=(e,t,o)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,o)},sl=(e,t,o,r)=>(al(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var Kc=(e,t,o)=>(al(e,t,"access private method"),o);var VC={};xg(VC,{AsExternalProvider:()=>lo,Captcha:()=>ja,ConnectorManager:()=>Wn,PrivyClient:()=>Mn,PrivyProvider:()=>Zy,PrivyProxyProvider:()=>Pe,SUPPORTED_CHAINS:()=>kn,VERSION:()=>ca,WalletConnector:()=>pt,addRpcUrlOverrideToChain:()=>hg,errorIndicatesMaxMfaRetries:()=>gs,errorIndicatesMfaTimeout:()=>Kr,errorIndicatesMfaVerificationFailed:()=>Yr,getAccessToken:()=>$e,useConnectWallet:()=>ag,useCreateWallet:()=>lg,useLogin:()=>eg,useLoginWithEmail:()=>rg,useLoginWithSms:()=>ng,useLogout:()=>og,useMfa:()=>an,useMfaEnrollment:()=>ai,useModalStatus:()=>ug,usePrivy:()=>G,useRegisterMfaListener:()=>Qa,useSetWalletPassword:()=>dg,useToken:()=>fg,useWallets:()=>ui});module.exports=Sg(VC);var Qi=require("@ethersproject/address"),yi=require("@ethersproject/providers"),jy=require("mipd"),j=require("react");var Yc=require("ofetch"),et=class extends Error{constructor(o,r,n){super(o);r instanceof Error&&(this.cause=r),this.privyErrorCode=n}toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},To=class extends et{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},C=class extends et{constructor(o,r,n){super(o,r,n);this.type="client_error"}},oa=class extends C{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var Y=class extends et{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},fe=e=>{if(e instanceof et)return e;if(!(e instanceof Yc.FetchError))return lt(e);if(!e.response)return new To("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new To(t||"ApiError",e.response.status,o||r,e,n)},lt=e=>e instanceof et?e:e instanceof Error?new C(e.message,e):new C(`Internal error: ${e}`);var hn=class extends C{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},Rt=class extends C{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},ra=class extends C{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var na=()=>"/api/v1/sessions",ia=()=>"/api/v1/sessions/logout",Jc=()=>"/api/v1/sessions/fork",aa=()=>"/api/v1/sessions/fork/recover",Qc=()=>"/api/v1/siwe/init",Zc=()=>"/api/v1/siwe/authenticate",Xc=()=>"/api/v1/siwe/link",ed=()=>"/api/v1/farcaster/init",td=()=>"/api/v1/farcaster/authenticate",od=()=>"/api/v1/farcaster/link",rd=()=>"/api/v1/farcaster/status",nd=()=>"/api/v1/passwordless/init",id=()=>"/api/v1/passwordless/authenticate",ad=()=>"/api/v1/passwordless/link",sd=()=>"/api/v1/passwordless_sms/init",ld=()=>"/api/v1/passwordless_sms/authenticate",cd=()=>"/api/v1/passwordless_sms/link",dd=()=>"/api/v1/oauth/init",pd=()=>"/api/v1/oauth/authenticate",ud=()=>"/api/v1/oauth/link",md=()=>"/api/v1/siwe/unlink",fd=()=>"/api/v1/passwordless/unlink",hd=()=>"/api/v1/passwordless_sms/unlink",yd=()=>"/api/v1/oauth/unlink",gd=()=>"/api/v1/farcaster/unlink",vd=()=>"/api/v1/analytics_events",wd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Cd=()=>"/api/v1/custom_jwt_account/authenticate",bd=()=>"/api/v1/mfa/passwordless_sms/init";var Ed=()=>"/api/v1/mfa/passwordless_sms/enroll";var Td=()=>"/api/v1/users/me/accept_terms";var yn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");try{let t=Cd(),o=await this.api.post(t,{token:this.meta.token});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw fe(t)}}async link(){throw new Error("Unimplemented")}};var Fr=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=id(),o=await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw fe(t)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=ad();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw fe(t)}}async sendCodeEmail(t,o){if(!this.api)throw new C("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new C("Email must be set when initialzing authentication.");try{let r=nd();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw fe(r)}}};var Pd=require("react-device-detect");var ct=class{constructor(t){this.promise=null;this.fn=t}execute(t){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(t)}finally{this.promise=null}})()),this.promise}};var wi=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new ct(this._startChannelOnce.bind(this)),this.pollForReady=new ct(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.channelToken)throw new C("Auth flow must be initialized first");try{let t=await this.api.post(td(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new C("No response from authentication");return{user:t.user,token:t.token,refresh_token:t.refresh_token,is_new_user:t.is_new_user}}catch(t){throw fe(t)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");try{return await this.api.post(od(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw fe(t)}}async _startChannelOnce(){if(!this.api)throw new C("Auth flow has no API instance");let t=await this.api.post(ed(),{token:this.captchaToken});Pd.isMobile&&t.connect_uri&&window.open(t.connect_uri,"_blank","noopener noreferrer"),this._meta={connectUri:t.connect_uri,channelToken:t.channel_token}}async initializeFarcasterConnect(){if(!this.api)throw new C("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.channelToken)throw new C("Auth flow must be initialized first");let t=await this.api.get(rd(),{headers:{"farcaster-channel-token":this.meta.channelToken}});return t.state==="completed"?(this.message=t.message,this.signature=t.signature,this.fid=t.fid,!0):!1}};var hl=require("jose");var xd="1.57.1";var sa="4df5e2316331463a9130964bd6078dfa",Sd="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",_d="34357d3c125c2bcf2ce2bc3309d98715",la="https://auth.privy.io",Ad=2e4,dt=1400,kd=2500,ca=xd;var Br="privy:token",ll="privy-token",da="privy:refresh_token",cl="privy-refresh-token",pa="privy-session",Ci="privy:session_transfer_token",Ag="privy:wallet",bi="privy:caid",gn="privy:state_code",vn="privy:code_verifier",ua=e=>`${Ag}:${e}`,dl="privy:connectors",pl="privy:connections";var Hr=12e4,Yo=1,ul="0x1",wn=3e4,Rd="https://api.moonpay.com/v1",Id="https://api.moonpay.com/v1",Wd="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Md="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Nd="0x420000000000000000000000000000000000000F",Ld=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Od(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Dd(e){return crypto.getRandomValues(new Uint8Array(e))}var ma=class{constructor(){this._cache={}}get(t){return this._cache[t]}put(t,o){o!==void 0?this._cache[t]=o:this.del(t)}del(t){delete this._cache[t]}getKeys(){return Object.keys(this._cache)}},ml=class{get(t){let o=localStorage.getItem(t);return o===null?void 0:JSON.parse(o)}put(t,o){o!==void 0?localStorage.setItem(t,JSON.stringify(o)):this.del(t)}del(t){localStorage.removeItem(t)}getKeys(){return Object.entries(localStorage).map(([t])=>t)}},fl=class{get(t){let o=sessionStorage.getItem(t);return o===null?void 0:JSON.parse(o)}put(t,o){o!==void 0?sessionStorage.setItem(t,JSON.stringify(o)):this.del(t)}del(t){sessionStorage.removeItem(t)}getKeys(){return Object.entries(sessionStorage).map(([t])=>t)}};function Ud(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function kg(){return typeof window<"u"&&window.localStorage?new ml:new ma}function Rg(){return typeof window<"u"&&window.sessionStorage?new fl:new ma}var no=Rg(),ce=kg();var Ig="S256",Wg="S256",fr=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=no.get(vn);if(!t)throw new C("Authentication error.");try{let o=pd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return no.del(vn),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=fe(o);throw r.privyErrorCode?new C(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new C("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new C("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=no.get(vn);if(!t)throw new C("Authentication error.");try{let o=ud(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return no.del(vn),r}catch(o){throw fe(o)}}createCodeVerifier(){return hl.base64url.encode(Dd(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Ig){if(o==Wg){let r=await Od(t);return hl.base64url.encode(r)}else return t}async getAuthorizationUrl(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.provider)throw new C("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();no.put(vn,t);let o=this.createStateCode();no.put(gn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=dd();return await this.api.post(n,{provider:this.meta.provider,redirect_to:window.location.href,token:this.meta.captchaToken,code_challenge:r,state_code:o})}catch(n){throw fe(n)}}};var Gr=class{constructor(t,o){this.createSiweMessage=(t,o,r,n,i,a,l)=>`${r} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${l}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.57.1-beta-20240227144952",
2
+ "version": "1.57.1",
3
3
  "name": "@privy-io/react-auth",
4
4
  "description": "React client for the Privy Auth API",
5
5
  "keywords": [