@privy-io/react-auth 1.59.3 → 1.59.4-beta-20240312133648

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 js=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var Jc=(e,t,r)=>(js(e,t,"read from private field"),r?r.call(e):t.get(e)),Li=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},Ks=(e,t,r,o)=>(js(e,t,"write to private field"),o?o.call(e,r):t.set(e,r),r);var Zc=(e,t,r)=>(js(e,t,"access private method"),r);import{getAddress as Vs}from"@ethersproject/address";import{Web3Provider as $c}from"@ethersproject/providers";import{createStore as p4}from"mipd";import{useCallback as u4,useEffect as Ir,useMemo as m4,useRef as Wn,useState as ke}from"react";import{FetchError as My}from"ofetch";var He=class extends Error{constructor(r,o,n){super(r);o instanceof Error&&(this.cause=o),this.privyErrorCode=n}toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},Xt=class extends He{constructor(r,o,n,i,a){super(n,i,a);this.type=r;this.status=o}},P=class extends He{constructor(r,o,n){super(r,o,n);this.type="client_error"}},Oi=class extends P{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var Y=class extends He{constructor(r,o,n){super(r,o,n);this.type="connector_error"}},se=e=>{if(e instanceof He)return e;if(!(e instanceof My))return Ze(e);if(!e.response)return new Xt("api_error",null,e.message,e);let{type:t,message:r,error:o,code:n}=e.data;return new Xt(t||"ApiError",e.response.status,r||o,e,n)},Ze=e=>e instanceof He?e:e instanceof Error?new P(e.message,e):new P(`Internal error: ${e}`);var Io=class extends P{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},mt=class extends P{constructor(t="Embedded wallet error",r){super(t,r,"unknown_embedded_wallet_error")}},Ni=class extends P{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var Di="/api/v1/sessions",Ui="/api/v1/sessions/logout",Qc="/api/v1/sessions/fork",Fi="/api/v1/sessions/fork/recover",Xc="/api/v1/siwe/init",ed="/api/v1/siwe/authenticate",td="/api/v1/siwe/link",rd="/api/v1/siwe/unlink",od="/api/v1/farcaster/init",nd="/api/v1/farcaster/authenticate",id="/api/v1/farcaster/link",ad="/api/v1/farcaster/status",sd="/api/v1/farcaster/unlink",ld="/api/v1/passwordless/init",cd="/api/v1/passwordless/authenticate",dd="/api/v1/passwordless/link",pd="/api/v1/passwordless/unlink",ud="/api/v1/passwordless/update",md="/api/v1/passwordless_sms/init",fd="/api/v1/passwordless_sms/link",hd="/api/v1/passwordless_sms/unlink",yd="/api/v1/passwordless_sms/authenticate",gd="/api/v1/oauth/init",vd="/api/v1/oauth/authenticate",wd="/api/v1/oauth/link",Cd="/api/v1/oauth/unlink";var bd="/api/v1/mfa/passwordless_sms/init",Ed="/api/v1/mfa/passwordless_sms/enroll";var Pd="/api/v1/users/me/accept_terms",Td="/api/v1/analytics_events",xd="/api/v1/plugins/moonpay_on_ramp/sign",Sd="/api/v1/custom_jwt_account/authenticate";var Mo=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new P("Auth flow has no API instance");try{let t=await this.api.post(Sd,{token:this.meta.token});return{user:t.user,token:t.token,refresh_token:t.refresh_token,is_new_user:t.is_new_user}}catch(t){throw se(t)}}async link(){throw new Error("Unimplemented")}};var Lr=class{constructor(t,r){this.meta={email:t,captchaToken:r}}async authenticate(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new P("Email and email code must be set prior to calling authenticate.");try{let t=await this.api.post(cd,{email:this.meta.email,code:this.meta.emailCode});return{user:t.user,token:t.token,refresh_token:t.refresh_token,is_new_user:t.is_new_user}}catch(t){throw se(t)}}async link(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new P("Email and email code must be set prior to calling authenticate.");try{return await this.api.post(dd,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw se(t)}}async sendCodeEmail(t,r){if(!this.api)throw new P("Auth flow has no API instance");if(t&&(this.meta.email=t),r&&(this.meta.captchaToken=r),!this.meta.email)throw new P("Email must be set when initialzing authentication.");try{return await this.api.post(ld,{email:this.meta.email,token:this.meta.captchaToken})}catch(o){throw se(o)}}},Bi=class extends Lr{constructor(r,o,n){super(o,n);this.meta={email:o,captchaToken:n,oldAddress:r}}async link(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode||!this.meta.oldAddress)throw new P("Email, email code, and an old email address must be set prior to calling update.");try{return await this.api.post(ud,{oldAddress:this.meta.oldAddress,newAddress:this.meta.email,code:this.meta.emailCode})}catch(r){throw se(r)}}};import{isMobile as Wy}from"react-device-detect";var Qe=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 Nn=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new Qe(this._startChannelOnce.bind(this)),this.pollForReady=new Qe(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.channelToken)throw new P("Auth flow must be initialized first");try{let t=await this.api.post(nd,{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new P("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 se(t)}}async link(){if(!this.api)throw new P("Auth flow has no API instance");try{return await this.api.post(id,{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw se(t)}}async _startChannelOnce(){if(!this.api)throw new P("Auth flow has no API instance");let t=await this.api.post(od,{token:this.captchaToken});Wy&&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 P("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.channelToken)throw new P("Auth flow must be initialized first");let t=await this.api.get(ad,{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 Fd}from"jose";var _d="1.59.3";var Ys="4df5e2316331463a9130964bd6078dfa",Js="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Ad="34357d3c125c2bcf2ce2bc3309d98715",Hi="https://auth.privy.io",kd=2e4,Xe=1400,Rd=2500,Zs=_d;var lo="privy:token",Qs="privy-token",Gi="privy:refresh_token",Xs="privy-refresh-token",Vi="privy-session",Dn="privy:session_transfer_token",Oy="privy:wallet",Un="privy:caid",co="privy:state_code",Wo="privy:code_verifier",Fn="privy:headless_oauth",zi=e=>`${Oy}:${e}`,el="privy:connectors",tl="privy:connections";var po=12e4,br=1,rl="0x1",Lo=3e4,Id="https://api.moonpay.com/v1",Md="https://api.moonpay.com/v1",Wd="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Ld="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Od="0x420000000000000000000000000000000000000F",Nd=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Dd(e){let t=new TextEncoder().encode(e),r=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(r)}function Ud(e){return crypto.getRandomValues(new Uint8Array(e))}var $i=class{constructor(){this._cache={}}get(t){return this._cache[t]}put(t,r){r!==void 0?this._cache[t]=r:this.del(t)}del(t){delete this._cache[t]}getKeys(){return Object.keys(this._cache)}},ol=class{get(t){let r=localStorage.getItem(t);return r===null?void 0:JSON.parse(r)}put(t,r){r!==void 0?localStorage.setItem(t,JSON.stringify(r)):this.del(t)}del(t){localStorage.removeItem(t)}getKeys(){return Object.entries(localStorage).map(([t])=>t)}},nl=class{get(t){let r=sessionStorage.getItem(t);return r===null?void 0:JSON.parse(r)}put(t,r){r!==void 0?sessionStorage.setItem(t,JSON.stringify(r)):this.del(t)}del(t){sessionStorage.removeItem(t)}getKeys(){return Object.entries(sessionStorage).map(([t])=>t)}};function il(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Ny(){return typeof window<"u"&&window.localStorage?new ol:new $i}function Dy(){return typeof window<"u"&&window.sessionStorage?new nl:new $i}var Ge=Dy(),le=Ny();function qi(){return!!Ge.get(Fn)}var Uy="S256",Fy="S256",er=class{constructor(t){let r=typeof t.headless=="boolean"?t.headless:qi();this.meta={...t,headless: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 P("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new P("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new P("User denied confirmation during OAuth flow");let t=Ge.get(Wo);if(!t)throw new P("Authentication error.");try{let r=await this.api.post(vd,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Ge.del(Wo),this.meta.headless&&Ge.del(Fn),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(r){let o=se(r);throw o.privyErrorCode?new P(o.message||"Invalid code during OAuth flow.",void 0,o.privyErrorCode):o.message==="User denied confirmation during OAuth flow"?new P("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new P("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new P("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new P("User denied confirmation during OAuth flow");let t=Ge.get(Wo);if(!t)throw new P("Authentication error.");try{let r=await this.api.post(wd,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Ge.del(Wo),r}catch(r){throw se(r)}}createCodeVerifier(){return Fd.encode(Ud(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,r=Uy){if(r==Fy){let o=await Dd(t);return Fd.encode(o)}else return t}async getAuthorizationUrl(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.provider)throw new P("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();Ge.put(Wo,t);let r=this.createStateCode();Ge.put(co,r);let o=await this.deriveCodeChallengeFromCodeVerifier(t);this.meta.headless&&Ge.put(Fn,!0);try{return await this.api.post(gd,{provider:this.meta.provider,redirect_to:window.location.href,token:this.meta.captchaToken,code_challenge:o,state_code:r})}catch(n){throw se(n)}}};function al(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Bd(e,t){let r={detail:"",retryable:!1},o=al(t);return e?.privyErrorCode==="linked_to_another_user"&&(r.detail="This account has already been linked to another user."),e?.privyErrorCode==="invalid_credentials"&&(r.retryable=!0,r.detail="Something went wrong. Try again."),e.privyErrorCode==="oauth_user_denied"&&(r.detail=`Retry and check ${o} to finish connecting your account.`,r.retryable=!0),e?.privyErrorCode==="too_many_requests"&&(r.detail="Too many requests. Please wait before trying again."),e?.privyErrorCode==="oauth_account_suspended"&&(r.detail=`Your ${o} account is suspended. Please try another login method.`),r}function Hn(){let e=new URLSearchParams(window.location.search),t=e.get("privy_oauth_code"),r=e.get("privy_oauth_state"),o=e.get("privy_oauth_provider");return!t||!r||!o?{inProgress:!1}:{inProgress:!0,authorizationCode:t,stateCode:r,provider:o,headless:qi()}}function Gn(){let e=new URL(window.location.href);e.searchParams.delete("privy_oauth_code"),e.searchParams.delete("privy_oauth_provider"),e.searchParams.delete("privy_oauth_state"),Ge.del(co),window.history.pushState({},"",e)}var uo=class{constructor(t,r){this.createSiweMessage=(t,r,o,n,i,a,l)=>`${o} wants you to sign in with your Ethereum account:
1
+ var js=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var Jc=(e,t,r)=>(js(e,t,"read from private field"),r?r.call(e):t.get(e)),Li=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},Ks=(e,t,r,o)=>(js(e,t,"write to private field"),o?o.call(e,r):t.set(e,r),r);var Zc=(e,t,r)=>(js(e,t,"access private method"),r);import{getAddress as Vs}from"@ethersproject/address";import{Web3Provider as $c}from"@ethersproject/providers";import{createStore as p4}from"mipd";import{useCallback as u4,useEffect as Ir,useMemo as m4,useRef as Wn,useState as ke}from"react";import{FetchError as My}from"ofetch";var He=class extends Error{constructor(r,o,n){super(r);o instanceof Error&&(this.cause=o),this.privyErrorCode=n}toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},Xt=class extends He{constructor(r,o,n,i,a){super(n,i,a);this.type=r;this.status=o}},P=class extends He{constructor(r,o,n){super(r,o,n);this.type="client_error"}},Oi=class extends P{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var Y=class extends He{constructor(r,o,n){super(r,o,n);this.type="connector_error"}},se=e=>{if(e instanceof He)return e;if(!(e instanceof My))return Ze(e);if(!e.response)return new Xt("api_error",null,e.message,e);let{type:t,message:r,error:o,code:n}=e.data;return new Xt(t||"ApiError",e.response.status,r||o,e,n)},Ze=e=>e instanceof He?e:e instanceof Error?new P(e.message,e):new P(`Internal error: ${e}`);var Io=class extends P{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},mt=class extends P{constructor(t="Embedded wallet error",r){super(t,r,"unknown_embedded_wallet_error")}},Ni=class extends P{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var Di="/api/v1/sessions",Ui="/api/v1/sessions/logout",Qc="/api/v1/sessions/fork",Fi="/api/v1/sessions/fork/recover",Xc="/api/v1/siwe/init",ed="/api/v1/siwe/authenticate",td="/api/v1/siwe/link",rd="/api/v1/siwe/unlink",od="/api/v1/farcaster/init",nd="/api/v1/farcaster/authenticate",id="/api/v1/farcaster/link",ad="/api/v1/farcaster/status",sd="/api/v1/farcaster/unlink",ld="/api/v1/passwordless/init",cd="/api/v1/passwordless/authenticate",dd="/api/v1/passwordless/link",pd="/api/v1/passwordless/unlink",ud="/api/v1/passwordless/update",md="/api/v1/passwordless_sms/init",fd="/api/v1/passwordless_sms/link",hd="/api/v1/passwordless_sms/unlink",yd="/api/v1/passwordless_sms/authenticate",gd="/api/v1/oauth/init",vd="/api/v1/oauth/authenticate",wd="/api/v1/oauth/link",Cd="/api/v1/oauth/unlink";var bd="/api/v1/mfa/passwordless_sms/init",Ed="/api/v1/mfa/passwordless_sms/enroll";var Pd="/api/v1/users/me/accept_terms",Td="/api/v1/analytics_events",xd="/api/v1/plugins/moonpay_on_ramp/sign",Sd="/api/v1/custom_jwt_account/authenticate";var Mo=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new P("Auth flow has no API instance");try{let t=await this.api.post(Sd,{token:this.meta.token});return{user:t.user,token:t.token,refresh_token:t.refresh_token,is_new_user:t.is_new_user}}catch(t){throw se(t)}}async link(){throw new Error("Unimplemented")}};var Lr=class{constructor(t,r){this.meta={email:t,captchaToken:r}}async authenticate(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new P("Email and email code must be set prior to calling authenticate.");try{let t=await this.api.post(cd,{email:this.meta.email,code:this.meta.emailCode});return{user:t.user,token:t.token,refresh_token:t.refresh_token,is_new_user:t.is_new_user}}catch(t){throw se(t)}}async link(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new P("Email and email code must be set prior to calling authenticate.");try{return await this.api.post(dd,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw se(t)}}async sendCodeEmail(t,r){if(!this.api)throw new P("Auth flow has no API instance");if(t&&(this.meta.email=t),r&&(this.meta.captchaToken=r),!this.meta.email)throw new P("Email must be set when initialzing authentication.");try{return await this.api.post(ld,{email:this.meta.email,token:this.meta.captchaToken})}catch(o){throw se(o)}}},Bi=class extends Lr{constructor(r,o,n){super(o,n);this.meta={email:o,captchaToken:n,oldAddress:r}}async link(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode||!this.meta.oldAddress)throw new P("Email, email code, and an old email address must be set prior to calling update.");try{return await this.api.post(ud,{oldAddress:this.meta.oldAddress,newAddress:this.meta.email,code:this.meta.emailCode})}catch(r){throw se(r)}}};import{isMobile as Wy}from"react-device-detect";var Qe=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 Nn=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new Qe(this._startChannelOnce.bind(this)),this.pollForReady=new Qe(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.channelToken)throw new P("Auth flow must be initialized first");try{let t=await this.api.post(nd,{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new P("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 se(t)}}async link(){if(!this.api)throw new P("Auth flow has no API instance");try{return await this.api.post(id,{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw se(t)}}async _startChannelOnce(){if(!this.api)throw new P("Auth flow has no API instance");let t=await this.api.post(od,{token:this.captchaToken});Wy&&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 P("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.channelToken)throw new P("Auth flow must be initialized first");let t=await this.api.get(ad,{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 Fd}from"jose";var _d="1.59.4-beta-20240312133648";var Ys="4df5e2316331463a9130964bd6078dfa",Js="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Ad="34357d3c125c2bcf2ce2bc3309d98715",Hi="https://auth.privy.io",kd=2e4,Xe=1400,Rd=2500,Zs=_d;var lo="privy:token",Qs="privy-token",Gi="privy:refresh_token",Xs="privy-refresh-token",Vi="privy-session",Dn="privy:session_transfer_token",Oy="privy:wallet",Un="privy:caid",co="privy:state_code",Wo="privy:code_verifier",Fn="privy:headless_oauth",zi=e=>`${Oy}:${e}`,el="privy:connectors",tl="privy:connections";var po=12e4,br=1,rl="0x1",Lo=3e4,Id="https://api.moonpay.com/v1",Md="https://api.moonpay.com/v1",Wd="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Ld="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Od="0x420000000000000000000000000000000000000F",Nd=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Dd(e){let t=new TextEncoder().encode(e),r=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(r)}function Ud(e){return crypto.getRandomValues(new Uint8Array(e))}var $i=class{constructor(){this._cache={}}get(t){return this._cache[t]}put(t,r){r!==void 0?this._cache[t]=r:this.del(t)}del(t){delete this._cache[t]}getKeys(){return Object.keys(this._cache)}},ol=class{get(t){let r=localStorage.getItem(t);return r===null?void 0:JSON.parse(r)}put(t,r){r!==void 0?localStorage.setItem(t,JSON.stringify(r)):this.del(t)}del(t){localStorage.removeItem(t)}getKeys(){return Object.entries(localStorage).map(([t])=>t)}},nl=class{get(t){let r=sessionStorage.getItem(t);return r===null?void 0:JSON.parse(r)}put(t,r){r!==void 0?sessionStorage.setItem(t,JSON.stringify(r)):this.del(t)}del(t){sessionStorage.removeItem(t)}getKeys(){return Object.entries(sessionStorage).map(([t])=>t)}};function il(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Ny(){return typeof window<"u"&&window.localStorage?new ol:new $i}function Dy(){return typeof window<"u"&&window.sessionStorage?new nl:new $i}var Ge=Dy(),le=Ny();function qi(){return!!Ge.get(Fn)}var Uy="S256",Fy="S256",er=class{constructor(t){let r=typeof t.headless=="boolean"?t.headless:qi();this.meta={...t,headless: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 P("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new P("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new P("User denied confirmation during OAuth flow");let t=Ge.get(Wo);if(!t)throw new P("Authentication error.");try{let r=await this.api.post(vd,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Ge.del(Wo),this.meta.headless&&Ge.del(Fn),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(r){let o=se(r);throw o.privyErrorCode?new P(o.message||"Invalid code during OAuth flow.",void 0,o.privyErrorCode):o.message==="User denied confirmation during OAuth flow"?new P("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new P("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new P("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new P("User denied confirmation during OAuth flow");let t=Ge.get(Wo);if(!t)throw new P("Authentication error.");try{let r=await this.api.post(wd,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Ge.del(Wo),r}catch(r){throw se(r)}}createCodeVerifier(){return Fd.encode(Ud(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,r=Uy){if(r==Fy){let o=await Dd(t);return Fd.encode(o)}else return t}async getAuthorizationUrl(){if(!this.api)throw new P("Auth flow has no API instance");if(!this.meta.provider)throw new P("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();Ge.put(Wo,t);let r=this.createStateCode();Ge.put(co,r);let o=await this.deriveCodeChallengeFromCodeVerifier(t);this.meta.headless&&Ge.put(Fn,!0);try{return await this.api.post(gd,{provider:this.meta.provider,redirect_to:window.location.href,token:this.meta.captchaToken,code_challenge:o,state_code:r})}catch(n){throw se(n)}}};function al(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Bd(e,t){let r={detail:"",retryable:!1},o=al(t);return e?.privyErrorCode==="linked_to_another_user"&&(r.detail="This account has already been linked to another user."),e?.privyErrorCode==="invalid_credentials"&&(r.retryable=!0,r.detail="Something went wrong. Try again."),e.privyErrorCode==="oauth_user_denied"&&(r.detail=`Retry and check ${o} to finish connecting your account.`,r.retryable=!0),e?.privyErrorCode==="too_many_requests"&&(r.detail="Too many requests. Please wait before trying again."),e?.privyErrorCode==="oauth_account_suspended"&&(r.detail=`Your ${o} account is suspended. Please try another login method.`),r}function Hn(){let e=new URLSearchParams(window.location.search),t=e.get("privy_oauth_code"),r=e.get("privy_oauth_state"),o=e.get("privy_oauth_provider");return!t||!r||!o?{inProgress:!1}:{inProgress:!0,authorizationCode:t,stateCode:r,provider:o,headless:qi()}}function Gn(){let e=new URL(window.location.href);e.searchParams.delete("privy_oauth_code"),e.searchParams.delete("privy_oauth_provider"),e.searchParams.delete("privy_oauth_state"),Ge.del(co),window.history.pushState({},"",e)}var uo=class{constructor(t,r){this.createSiweMessage=(t,r,o,n,i,a,l)=>`${o} wants you to sign in with your Ethereum account:
2
2
  ${r}
3
3
 
4
4
  ${l}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var E1=Object.create;var Ca=Object.defineProperty;var P1=Object.getOwnPropertyDescriptor;var T1=Object.getOwnPropertyNames;var x1=Object.getPrototypeOf,S1=Object.prototype.hasOwnProperty;var _1=(e,t)=>{for(var r in t)Ca(e,r,{get:t[r],enumerable:!0})},Rd=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of T1(t))!S1.call(e,n)&&n!==r&&Ca(e,n,{get:()=>t[n],enumerable:!(o=P1(t,n))||o.enumerable});return e};var h=(e,t,r)=>(r=e!=null?E1(x1(e)):{},Rd(t||!e||!e.__esModule?Ca(r,"default",{value:e,enumerable:!0}):r,e)),A1=e=>Rd(Ca({},"__esModule",{value:!0}),e);var Fl=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var Id=(e,t,r)=>(Fl(e,t,"read from private field"),r?r.call(e):t.get(e)),ba=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},Bl=(e,t,r,o)=>(Fl(e,t,"write to private field"),o?o.call(e,r):t.set(e,r),r);var Md=(e,t,r)=>(Fl(e,t,"access private method"),r);var $2={};_1($2,{AsExternalProvider:()=>gr,Captcha:()=>gs,ConnectorManager:()=>Un,PrivyClient:()=>Fn,PrivyProvider:()=>$g,PrivyProxyProvider:()=>ke,SUPPORTED_CHAINS:()=>On,VERSION:()=>ka,WalletConnector:()=>Et,addRpcUrlOverrideToChain:()=>v1,errorIndicatesMaxMfaRetries:()=>Fs,errorIndicatesMfaTimeout:()=>nn,errorIndicatesMfaVerificationFailed:()=>an,getAccessToken:()=>Ye,useConnectWallet:()=>r1,useCreateWallet:()=>n1,useFundWallet:()=>i1,useLinkAccount:()=>e1,useLogin:()=>jg,useLoginWithEmail:()=>Zg,useLoginWithOAuth:()=>Jg,useLoginWithSms:()=>Qg,useLogout:()=>Yg,useMfa:()=>fn,useMfaEnrollment:()=>yi,useModalStatus:()=>h1,usePrivy:()=>G,useRegisterMfaListener:()=>bs,useSendTransaction:()=>s1,useSetWalletPassword:()=>c1,useSignMessage:()=>p1,useSignTypedData:()=>m1,useToken:()=>g1,useWallets:()=>Ti});module.exports=A1($2);var ga=require("@ethersproject/address"),Ol=require("@ethersproject/providers"),Bg=require("mipd"),J=require("react");var Wd=require("ofetch"),lt=class extends Error{constructor(r,o,n){super(r);o instanceof Error&&(this.cause=o),this.privyErrorCode=n}toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},Nr=class extends lt{constructor(r,o,n,i,a){super(n,i,a);this.type=r;this.status=o}},T=class extends lt{constructor(r,o,n){super(r,o,n);this.type="client_error"}},Ea=class extends T{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var X=class extends lt{constructor(r,o,n){super(r,o,n);this.type="connector_error"}},fe=e=>{if(e instanceof lt)return e;if(!(e instanceof Wd.FetchError))return vt(e);if(!e.response)return new Nr("api_error",null,e.message,e);let{type:t,message:r,error:o,code:n}=e.data;return new Nr(t||"ApiError",e.response.status,r||o,e,n)},vt=e=>e instanceof lt?e:e instanceof Error?new T(e.message,e):new T(`Internal error: ${e}`);var bn=class extends T{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},Ft=class extends T{constructor(t="Embedded wallet error",r){super(t,r,"unknown_embedded_wallet_error")}},Pa=class extends T{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var Ta="/api/v1/sessions",xa="/api/v1/sessions/logout",Ld="/api/v1/sessions/fork",Sa="/api/v1/sessions/fork/recover",Od="/api/v1/siwe/init",Nd="/api/v1/siwe/authenticate",Dd="/api/v1/siwe/link",Ud="/api/v1/siwe/unlink",Fd="/api/v1/farcaster/init",Bd="/api/v1/farcaster/authenticate",Hd="/api/v1/farcaster/link",Gd="/api/v1/farcaster/status",Vd="/api/v1/farcaster/unlink",zd="/api/v1/passwordless/init",$d="/api/v1/passwordless/authenticate",qd="/api/v1/passwordless/link",jd="/api/v1/passwordless/unlink",Kd="/api/v1/passwordless/update",Yd="/api/v1/passwordless_sms/init",Jd="/api/v1/passwordless_sms/link",Zd="/api/v1/passwordless_sms/unlink",Qd="/api/v1/passwordless_sms/authenticate",Xd="/api/v1/oauth/init",ep="/api/v1/oauth/authenticate",tp="/api/v1/oauth/link",rp="/api/v1/oauth/unlink";var op="/api/v1/mfa/passwordless_sms/init",np="/api/v1/mfa/passwordless_sms/enroll";var ip="/api/v1/users/me/accept_terms",ap="/api/v1/analytics_events",sp="/api/v1/plugins/moonpay_on_ramp/sign",lp="/api/v1/custom_jwt_account/authenticate";var En=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new T("Auth flow has no API instance");try{let t=await this.api.post(lp,{token:this.meta.token});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(){throw new Error("Unimplemented")}};var Po=class{constructor(t,r){this.meta={email:t,captchaToken:r}}async authenticate(){if(!this.api)throw new T("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new T("Email and email code must be set prior to calling authenticate.");try{let t=await this.api.post($d,{email:this.meta.email,code:this.meta.emailCode});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 T("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new T("Email and email code must be set prior to calling authenticate.");try{return await this.api.post(qd,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw fe(t)}}async sendCodeEmail(t,r){if(!this.api)throw new T("Auth flow has no API instance");if(t&&(this.meta.email=t),r&&(this.meta.captchaToken=r),!this.meta.email)throw new T("Email must be set when initialzing authentication.");try{return await this.api.post(zd,{email:this.meta.email,token:this.meta.captchaToken})}catch(o){throw fe(o)}}},_a=class extends Po{constructor(r,o,n){super(o,n);this.meta={email:o,captchaToken:n,oldAddress:r}}async link(){if(!this.api)throw new T("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode||!this.meta.oldAddress)throw new T("Email, email code, and an old email address must be set prior to calling update.");try{return await this.api.post(Kd,{oldAddress:this.meta.oldAddress,newAddress:this.meta.email,code:this.meta.emailCode})}catch(r){throw fe(r)}}};var cp=require("react-device-detect");var wt=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 ki=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new wt(this._startChannelOnce.bind(this)),this.pollForReady=new wt(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new T("Auth flow has no API instance");if(!this.meta.channelToken)throw new T("Auth flow must be initialized first");try{let t=await this.api.post(Bd,{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new T("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 T("Auth flow has no API instance");try{return await this.api.post(Hd,{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 T("Auth flow has no API instance");let t=await this.api.post(Fd,{token:this.captchaToken});cp.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 T("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new T("Auth flow has no API instance");if(!this.meta.channelToken)throw new T("Auth flow must be initialized first");let t=await this.api.get(Gd,{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 Zl=require("jose");var dp="1.59.3";var Hl="4df5e2316331463a9130964bd6078dfa",Gl="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",pp="34357d3c125c2bcf2ce2bc3309d98715",Aa="https://auth.privy.io",up=2e4,Ct=1400,mp=2500,ka=dp;var Ko="privy:token",Vl="privy-token",Ra="privy:refresh_token",zl="privy-refresh-token",Ia="privy-session",Ri="privy:session_transfer_token",R1="privy:wallet",Ii="privy:caid",Yo="privy:state_code",Pn="privy:code_verifier",Mi="privy:headless_oauth",Ma=e=>`${R1}:${e}`,$l="privy:connectors",ql="privy:connections";var Jo=12e4,no=1,jl="0x1",Tn=3e4,fp="https://api.moonpay.com/v1",hp="https://api.moonpay.com/v1",yp="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",gp="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",vp="0x420000000000000000000000000000000000000F",wp=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Cp(e){let t=new TextEncoder().encode(e),r=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(r)}function bp(e){return crypto.getRandomValues(new Uint8Array(e))}var Wa=class{constructor(){this._cache={}}get(t){return this._cache[t]}put(t,r){r!==void 0?this._cache[t]=r:this.del(t)}del(t){delete this._cache[t]}getKeys(){return Object.keys(this._cache)}},Kl=class{get(t){let r=localStorage.getItem(t);return r===null?void 0:JSON.parse(r)}put(t,r){r!==void 0?localStorage.setItem(t,JSON.stringify(r)):this.del(t)}del(t){localStorage.removeItem(t)}getKeys(){return Object.entries(localStorage).map(([t])=>t)}},Yl=class{get(t){let r=sessionStorage.getItem(t);return r===null?void 0:JSON.parse(r)}put(t,r){r!==void 0?sessionStorage.setItem(t,JSON.stringify(r)):this.del(t)}del(t){sessionStorage.removeItem(t)}getKeys(){return Object.entries(sessionStorage).map(([t])=>t)}};function Jl(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function I1(){return typeof window<"u"&&window.localStorage?new Kl:new Wa}function M1(){return typeof window<"u"&&window.sessionStorage?new Yl:new Wa}var ct=M1(),he=I1();function La(){return!!ct.get(Mi)}var W1="S256",L1="S256",Dr=class{constructor(t){let r=typeof t.headless=="boolean"?t.headless:La();this.meta={...t,headless: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 T("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new T("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new T("User denied confirmation during OAuth flow");let t=ct.get(Pn);if(!t)throw new T("Authentication error.");try{let r=await this.api.post(ep,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return ct.del(Pn),this.meta.headless&&ct.del(Mi),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(r){let o=fe(r);throw o.privyErrorCode?new T(o.message||"Invalid code during OAuth flow.",void 0,o.privyErrorCode):o.message==="User denied confirmation during OAuth flow"?new T("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new T("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new T("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new T("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new T("User denied confirmation during OAuth flow");let t=ct.get(Pn);if(!t)throw new T("Authentication error.");try{let r=await this.api.post(tp,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return ct.del(Pn),r}catch(r){throw fe(r)}}createCodeVerifier(){return Zl.base64url.encode(bp(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,r=W1){if(r==L1){let o=await Cp(t);return Zl.base64url.encode(o)}else return t}async getAuthorizationUrl(){if(!this.api)throw new T("Auth flow has no API instance");if(!this.meta.provider)throw new T("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();ct.put(Pn,t);let r=this.createStateCode();ct.put(Yo,r);let o=await this.deriveCodeChallengeFromCodeVerifier(t);this.meta.headless&&ct.put(Mi,!0);try{return await this.api.post(Xd,{provider:this.meta.provider,redirect_to:window.location.href,token:this.meta.captchaToken,code_challenge:o,state_code:r})}catch(n){throw fe(n)}}};function Ql(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Ep(e,t){let r={detail:"",retryable:!1},o=Ql(t);return e?.privyErrorCode==="linked_to_another_user"&&(r.detail="This account has already been linked to another user."),e?.privyErrorCode==="invalid_credentials"&&(r.retryable=!0,r.detail="Something went wrong. Try again."),e.privyErrorCode==="oauth_user_denied"&&(r.detail=`Retry and check ${o} to finish connecting your account.`,r.retryable=!0),e?.privyErrorCode==="too_many_requests"&&(r.detail="Too many requests. Please wait before trying again."),e?.privyErrorCode==="oauth_account_suspended"&&(r.detail=`Your ${o} account is suspended. Please try another login method.`),r}function Li(){let e=new URLSearchParams(window.location.search),t=e.get("privy_oauth_code"),r=e.get("privy_oauth_state"),o=e.get("privy_oauth_provider");return!t||!r||!o?{inProgress:!1}:{inProgress:!0,authorizationCode:t,stateCode:r,provider:o,headless:La()}}function Oi(){let e=new URL(window.location.href);e.searchParams.delete("privy_oauth_code"),e.searchParams.delete("privy_oauth_provider"),e.searchParams.delete("privy_oauth_state"),ct.del(Yo),window.history.pushState({},"",e)}var Zo=class{constructor(t,r){this.createSiweMessage=(t,r,o,n,i,a,l)=>`${o} wants you to sign in with your Ethereum account:
1
+ "use strict";var E1=Object.create;var Ca=Object.defineProperty;var P1=Object.getOwnPropertyDescriptor;var T1=Object.getOwnPropertyNames;var x1=Object.getPrototypeOf,S1=Object.prototype.hasOwnProperty;var _1=(e,t)=>{for(var r in t)Ca(e,r,{get:t[r],enumerable:!0})},Rd=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of T1(t))!S1.call(e,n)&&n!==r&&Ca(e,n,{get:()=>t[n],enumerable:!(o=P1(t,n))||o.enumerable});return e};var h=(e,t,r)=>(r=e!=null?E1(x1(e)):{},Rd(t||!e||!e.__esModule?Ca(r,"default",{value:e,enumerable:!0}):r,e)),A1=e=>Rd(Ca({},"__esModule",{value:!0}),e);var Fl=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var Id=(e,t,r)=>(Fl(e,t,"read from private field"),r?r.call(e):t.get(e)),ba=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},Bl=(e,t,r,o)=>(Fl(e,t,"write to private field"),o?o.call(e,r):t.set(e,r),r);var Md=(e,t,r)=>(Fl(e,t,"access private method"),r);var $2={};_1($2,{AsExternalProvider:()=>gr,Captcha:()=>gs,ConnectorManager:()=>Un,PrivyClient:()=>Fn,PrivyProvider:()=>$g,PrivyProxyProvider:()=>ke,SUPPORTED_CHAINS:()=>On,VERSION:()=>ka,WalletConnector:()=>Et,addRpcUrlOverrideToChain:()=>v1,errorIndicatesMaxMfaRetries:()=>Fs,errorIndicatesMfaTimeout:()=>nn,errorIndicatesMfaVerificationFailed:()=>an,getAccessToken:()=>Ye,useConnectWallet:()=>r1,useCreateWallet:()=>n1,useFundWallet:()=>i1,useLinkAccount:()=>e1,useLogin:()=>jg,useLoginWithEmail:()=>Zg,useLoginWithOAuth:()=>Jg,useLoginWithSms:()=>Qg,useLogout:()=>Yg,useMfa:()=>fn,useMfaEnrollment:()=>yi,useModalStatus:()=>h1,usePrivy:()=>G,useRegisterMfaListener:()=>bs,useSendTransaction:()=>s1,useSetWalletPassword:()=>c1,useSignMessage:()=>p1,useSignTypedData:()=>m1,useToken:()=>g1,useWallets:()=>Ti});module.exports=A1($2);var ga=require("@ethersproject/address"),Ol=require("@ethersproject/providers"),Bg=require("mipd"),J=require("react");var Wd=require("ofetch"),lt=class extends Error{constructor(r,o,n){super(r);o instanceof Error&&(this.cause=o),this.privyErrorCode=n}toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},Nr=class extends lt{constructor(r,o,n,i,a){super(n,i,a);this.type=r;this.status=o}},T=class extends lt{constructor(r,o,n){super(r,o,n);this.type="client_error"}},Ea=class extends T{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var X=class extends lt{constructor(r,o,n){super(r,o,n);this.type="connector_error"}},fe=e=>{if(e instanceof lt)return e;if(!(e instanceof Wd.FetchError))return vt(e);if(!e.response)return new Nr("api_error",null,e.message,e);let{type:t,message:r,error:o,code:n}=e.data;return new Nr(t||"ApiError",e.response.status,r||o,e,n)},vt=e=>e instanceof lt?e:e instanceof Error?new T(e.message,e):new T(`Internal error: ${e}`);var bn=class extends T{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},Ft=class extends T{constructor(t="Embedded wallet error",r){super(t,r,"unknown_embedded_wallet_error")}},Pa=class extends T{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var Ta="/api/v1/sessions",xa="/api/v1/sessions/logout",Ld="/api/v1/sessions/fork",Sa="/api/v1/sessions/fork/recover",Od="/api/v1/siwe/init",Nd="/api/v1/siwe/authenticate",Dd="/api/v1/siwe/link",Ud="/api/v1/siwe/unlink",Fd="/api/v1/farcaster/init",Bd="/api/v1/farcaster/authenticate",Hd="/api/v1/farcaster/link",Gd="/api/v1/farcaster/status",Vd="/api/v1/farcaster/unlink",zd="/api/v1/passwordless/init",$d="/api/v1/passwordless/authenticate",qd="/api/v1/passwordless/link",jd="/api/v1/passwordless/unlink",Kd="/api/v1/passwordless/update",Yd="/api/v1/passwordless_sms/init",Jd="/api/v1/passwordless_sms/link",Zd="/api/v1/passwordless_sms/unlink",Qd="/api/v1/passwordless_sms/authenticate",Xd="/api/v1/oauth/init",ep="/api/v1/oauth/authenticate",tp="/api/v1/oauth/link",rp="/api/v1/oauth/unlink";var op="/api/v1/mfa/passwordless_sms/init",np="/api/v1/mfa/passwordless_sms/enroll";var ip="/api/v1/users/me/accept_terms",ap="/api/v1/analytics_events",sp="/api/v1/plugins/moonpay_on_ramp/sign",lp="/api/v1/custom_jwt_account/authenticate";var En=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new T("Auth flow has no API instance");try{let t=await this.api.post(lp,{token:this.meta.token});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(){throw new Error("Unimplemented")}};var Po=class{constructor(t,r){this.meta={email:t,captchaToken:r}}async authenticate(){if(!this.api)throw new T("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new T("Email and email code must be set prior to calling authenticate.");try{let t=await this.api.post($d,{email:this.meta.email,code:this.meta.emailCode});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 T("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new T("Email and email code must be set prior to calling authenticate.");try{return await this.api.post(qd,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw fe(t)}}async sendCodeEmail(t,r){if(!this.api)throw new T("Auth flow has no API instance");if(t&&(this.meta.email=t),r&&(this.meta.captchaToken=r),!this.meta.email)throw new T("Email must be set when initialzing authentication.");try{return await this.api.post(zd,{email:this.meta.email,token:this.meta.captchaToken})}catch(o){throw fe(o)}}},_a=class extends Po{constructor(r,o,n){super(o,n);this.meta={email:o,captchaToken:n,oldAddress:r}}async link(){if(!this.api)throw new T("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode||!this.meta.oldAddress)throw new T("Email, email code, and an old email address must be set prior to calling update.");try{return await this.api.post(Kd,{oldAddress:this.meta.oldAddress,newAddress:this.meta.email,code:this.meta.emailCode})}catch(r){throw fe(r)}}};var cp=require("react-device-detect");var wt=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 ki=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new wt(this._startChannelOnce.bind(this)),this.pollForReady=new wt(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new T("Auth flow has no API instance");if(!this.meta.channelToken)throw new T("Auth flow must be initialized first");try{let t=await this.api.post(Bd,{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new T("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 T("Auth flow has no API instance");try{return await this.api.post(Hd,{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 T("Auth flow has no API instance");let t=await this.api.post(Fd,{token:this.captchaToken});cp.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 T("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new T("Auth flow has no API instance");if(!this.meta.channelToken)throw new T("Auth flow must be initialized first");let t=await this.api.get(Gd,{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 Zl=require("jose");var dp="1.59.4-beta-20240312133648";var Hl="4df5e2316331463a9130964bd6078dfa",Gl="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",pp="34357d3c125c2bcf2ce2bc3309d98715",Aa="https://auth.privy.io",up=2e4,Ct=1400,mp=2500,ka=dp;var Ko="privy:token",Vl="privy-token",Ra="privy:refresh_token",zl="privy-refresh-token",Ia="privy-session",Ri="privy:session_transfer_token",R1="privy:wallet",Ii="privy:caid",Yo="privy:state_code",Pn="privy:code_verifier",Mi="privy:headless_oauth",Ma=e=>`${R1}:${e}`,$l="privy:connectors",ql="privy:connections";var Jo=12e4,no=1,jl="0x1",Tn=3e4,fp="https://api.moonpay.com/v1",hp="https://api.moonpay.com/v1",yp="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",gp="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",vp="0x420000000000000000000000000000000000000F",wp=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Cp(e){let t=new TextEncoder().encode(e),r=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(r)}function bp(e){return crypto.getRandomValues(new Uint8Array(e))}var Wa=class{constructor(){this._cache={}}get(t){return this._cache[t]}put(t,r){r!==void 0?this._cache[t]=r:this.del(t)}del(t){delete this._cache[t]}getKeys(){return Object.keys(this._cache)}},Kl=class{get(t){let r=localStorage.getItem(t);return r===null?void 0:JSON.parse(r)}put(t,r){r!==void 0?localStorage.setItem(t,JSON.stringify(r)):this.del(t)}del(t){localStorage.removeItem(t)}getKeys(){return Object.entries(localStorage).map(([t])=>t)}},Yl=class{get(t){let r=sessionStorage.getItem(t);return r===null?void 0:JSON.parse(r)}put(t,r){r!==void 0?sessionStorage.setItem(t,JSON.stringify(r)):this.del(t)}del(t){sessionStorage.removeItem(t)}getKeys(){return Object.entries(sessionStorage).map(([t])=>t)}};function Jl(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function I1(){return typeof window<"u"&&window.localStorage?new Kl:new Wa}function M1(){return typeof window<"u"&&window.sessionStorage?new Yl:new Wa}var ct=M1(),he=I1();function La(){return!!ct.get(Mi)}var W1="S256",L1="S256",Dr=class{constructor(t){let r=typeof t.headless=="boolean"?t.headless:La();this.meta={...t,headless: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 T("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new T("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new T("User denied confirmation during OAuth flow");let t=ct.get(Pn);if(!t)throw new T("Authentication error.");try{let r=await this.api.post(ep,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return ct.del(Pn),this.meta.headless&&ct.del(Mi),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(r){let o=fe(r);throw o.privyErrorCode?new T(o.message||"Invalid code during OAuth flow.",void 0,o.privyErrorCode):o.message==="User denied confirmation during OAuth flow"?new T("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new T("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new T("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new T("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new T("User denied confirmation during OAuth flow");let t=ct.get(Pn);if(!t)throw new T("Authentication error.");try{let r=await this.api.post(tp,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return ct.del(Pn),r}catch(r){throw fe(r)}}createCodeVerifier(){return Zl.base64url.encode(bp(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,r=W1){if(r==L1){let o=await Cp(t);return Zl.base64url.encode(o)}else return t}async getAuthorizationUrl(){if(!this.api)throw new T("Auth flow has no API instance");if(!this.meta.provider)throw new T("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();ct.put(Pn,t);let r=this.createStateCode();ct.put(Yo,r);let o=await this.deriveCodeChallengeFromCodeVerifier(t);this.meta.headless&&ct.put(Mi,!0);try{return await this.api.post(Xd,{provider:this.meta.provider,redirect_to:window.location.href,token:this.meta.captchaToken,code_challenge:o,state_code:r})}catch(n){throw fe(n)}}};function Ql(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Ep(e,t){let r={detail:"",retryable:!1},o=Ql(t);return e?.privyErrorCode==="linked_to_another_user"&&(r.detail="This account has already been linked to another user."),e?.privyErrorCode==="invalid_credentials"&&(r.retryable=!0,r.detail="Something went wrong. Try again."),e.privyErrorCode==="oauth_user_denied"&&(r.detail=`Retry and check ${o} to finish connecting your account.`,r.retryable=!0),e?.privyErrorCode==="too_many_requests"&&(r.detail="Too many requests. Please wait before trying again."),e?.privyErrorCode==="oauth_account_suspended"&&(r.detail=`Your ${o} account is suspended. Please try another login method.`),r}function Li(){let e=new URLSearchParams(window.location.search),t=e.get("privy_oauth_code"),r=e.get("privy_oauth_state"),o=e.get("privy_oauth_provider");return!t||!r||!o?{inProgress:!1}:{inProgress:!0,authorizationCode:t,stateCode:r,provider:o,headless:La()}}function Oi(){let e=new URL(window.location.href);e.searchParams.delete("privy_oauth_code"),e.searchParams.delete("privy_oauth_provider"),e.searchParams.delete("privy_oauth_state"),ct.del(Yo),window.history.pushState({},"",e)}var Zo=class{constructor(t,r){this.createSiweMessage=(t,r,o,n,i,a,l)=>`${o} wants you to sign in with your Ethereum account:
2
2
  ${r}
3
3
 
4
4
  ${l}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.59.3",
2
+ "version": "1.59.4-beta-20240312133648",
3
3
  "name": "@privy-io/react-auth",
4
4
  "sideEffects": false,
5
5
  "description": "React client for the Privy Auth API",
@@ -64,7 +64,7 @@
64
64
  "encoding": "^0.1.13",
65
65
  "eventemitter3": "^5.0.1",
66
66
  "fast-password-entropy": "^1.1.1",
67
- "jose": "^4.11.2",
67
+ "jose": "^4.15.5",
68
68
  "js-cookie": "^3.0.5",
69
69
  "libphonenumber-js": "^1.10.14",
70
70
  "lokijs": "^1.5.12",