@privy-io/react-auth 1.55.2-beta-20240207215612 → 1.55.2

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 us=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var lc=(e,t,o)=>(us(e,t,"read from private field"),o?o.call(e):t.get(e)),pi=(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)},ms=(e,t,o,r)=>(us(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var cc=(e,t,o)=>(us(e,t,"access private method"),o);import{getAddress as cs}from"@ethersproject/address";import{StaticJsonRpcProvider as R2,Web3Provider as tc}from"@ethersproject/providers";import{createStore as I2}from"mipd";import{useCallback as W2,useEffect as ro,useMemo as M2,useRef as si,useState as we}from"react";import{FetchError as yh}from"ofetch";var Oe=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}]`:""}`}},Ft=class extends Oe{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},v=class extends Oe{constructor(o,r,n){super(o,r,n);this.type="client_error"}},ui=class extends v{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var V=class extends Oe{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},oe=e=>{if(e instanceof Oe)return e;if(!(e instanceof yh))return Qe(e);if(!e.response)return new Ft("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new Ft(t||"ApiError",e.response.status,o||r,e,n)},Qe=e=>e instanceof Oe?e:e instanceof Error?new v(e.message,e):new v(`Internal error: ${e}`);var Pr=class extends v{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},nt=class extends v{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},mi=class extends v{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var fi=()=>"/api/v1/sessions",hi=()=>"/api/v1/sessions/logout",dc=()=>"/api/v1/sessions/fork",yi=()=>"/api/v1/sessions/fork/recover",pc=()=>"/api/v1/siwe/init",uc=()=>"/api/v1/siwe/authenticate",mc=()=>"/api/v1/siwe/link",fc=()=>"/api/v1/farcaster/init",hc=()=>"/api/v1/farcaster/authenticate",yc=()=>"/api/v1/farcaster/link",gc=()=>"/api/v1/farcaster/status",vc=()=>"/api/v1/passwordless/init",wc=()=>"/api/v1/passwordless/authenticate",Cc=()=>"/api/v1/passwordless/link",bc=()=>"/api/v1/passwordless_sms/init",Ec=()=>"/api/v1/passwordless_sms/authenticate",Pc=()=>"/api/v1/passwordless_sms/link",Tc=()=>"/api/v1/oauth/init",xc=()=>"/api/v1/oauth/authenticate",Sc=()=>"/api/v1/oauth/link",_c=()=>"/api/v1/siwe/unlink",kc=()=>"/api/v1/passwordless/unlink",Ac=()=>"/api/v1/passwordless_sms/unlink",Rc=()=>"/api/v1/oauth/unlink",Ic=()=>"/api/v1/farcaster/unlink",Wc=()=>"/api/v1/analytics_events",Mc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Nc=()=>"/api/v1/custom_jwt_account/authenticate",Lc=()=>"/api/v1/mfa/passwordless_sms/init";var Oc=()=>"/api/v1/mfa/passwordless_sms/enroll";var Tr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=Nc(),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 oe(t)}}async link(){throw new Error("Unimplemented")}};var Yo=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new v("Email and email code must be set prior to calling authenticate.");try{let t=wc(),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 oe(t)}}async link(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new v("Email and email code must be set prior to calling authenticate.");try{let t=Cc();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw oe(t)}}async sendCodeEmail(t,o){if(!this.api)throw new v("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new v("Email must be set when initialzing authentication.");try{let r=vc();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw oe(r)}}};import{isMobile as gh}from"react-device-detect";var Ge=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 gn=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new Ge(this._startChannelOnce.bind(this)),this.pollForReady=new Ge(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.channelToken)throw new v("Auth flow must be initialized first");try{let t=await this.api.post(hc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new v("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 oe(t)}}async link(){if(!this.api)throw new v("Auth flow has no API instance");try{return await this.api.post(yc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw oe(t)}}async _startChannelOnce(){if(!this.api)throw new v("Auth flow has no API instance");let t=await this.api.post(fc(),{token:this.captchaToken});gh&&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 v("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.channelToken)throw new v("Auth flow must be initialized first");let t=await this.api.get(gc(),{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 Qc}from"jose";var Dc="1.55.2-beta-20240207215612";var gi="4df5e2316331463a9130964bd6078dfa",Uc="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Fc="34357d3c125c2bcf2ce2bc3309d98715",vi="https://auth.privy.io",Bc=2e4,ze=1400,Hc=2500,fs=Dc;var Jo="privy:token",hs="privy-token",wi="privy:refresh_token",ys="privy-refresh-token",Ci="privy-session",vn="privy:session_transfer_token",wh="privy:wallet",wn="privy:caid",xr="privy:state_code",Sr="privy:code_verifier",bi=e=>`${wh}:${e}`,gs="privy:connectors",vs="privy:connections";var Qo=12e4,io=1,ws="0x1",_r=3e4,Gc="https://api.moonpay.com/v1",zc="https://api.moonpay.com/v1",Vc="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",$c="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",jc="0x420000000000000000000000000000000000000F",qc=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Kc(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Yc(e){return crypto.getRandomValues(new Uint8Array(e))}var Ei=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)}},Cs=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)}},bs=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 Jc(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Ch(){return typeof window<"u"&&window.localStorage?new Cs:new Ei}function bh(){return typeof window<"u"&&window.sessionStorage?new bs:new Ei}var xt=bh(),ee=Ch();var Eh="S256",Ph="S256",xo=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 v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=xt.get(Sr);if(!t)throw new v("Authentication error.");try{let o=xc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return xt.del(Sr),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=oe(o);throw r.privyErrorCode?new v(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new v("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new v("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=xt.get(Sr);if(!t)throw new v("Authentication error.");try{let o=Sc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return xt.del(Sr),r}catch(o){throw oe(o)}}createCodeVerifier(){return Qc.encode(Yc(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Eh){if(o==Ph){let r=await Kc(t);return Qc.encode(r)}else return t}async getAuthorizationUrl(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.provider)throw new v("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();xt.put(Sr,t);let o=this.createStateCode();xt.put(xr,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=Tc();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 oe(n)}}};var Zo=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 us=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var lc=(e,t,o)=>(us(e,t,"read from private field"),o?o.call(e):t.get(e)),pi=(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)},ms=(e,t,o,r)=>(us(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var cc=(e,t,o)=>(us(e,t,"access private method"),o);import{getAddress as cs}from"@ethersproject/address";import{StaticJsonRpcProvider as R2,Web3Provider as tc}from"@ethersproject/providers";import{createStore as I2}from"mipd";import{useCallback as W2,useEffect as ro,useMemo as M2,useRef as si,useState as we}from"react";import{FetchError as yh}from"ofetch";var Oe=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}]`:""}`}},Ft=class extends Oe{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},v=class extends Oe{constructor(o,r,n){super(o,r,n);this.type="client_error"}},ui=class extends v{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var V=class extends Oe{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},oe=e=>{if(e instanceof Oe)return e;if(!(e instanceof yh))return Qe(e);if(!e.response)return new Ft("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new Ft(t||"ApiError",e.response.status,o||r,e,n)},Qe=e=>e instanceof Oe?e:e instanceof Error?new v(e.message,e):new v(`Internal error: ${e}`);var Pr=class extends v{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},nt=class extends v{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},mi=class extends v{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var fi=()=>"/api/v1/sessions",hi=()=>"/api/v1/sessions/logout",dc=()=>"/api/v1/sessions/fork",yi=()=>"/api/v1/sessions/fork/recover",pc=()=>"/api/v1/siwe/init",uc=()=>"/api/v1/siwe/authenticate",mc=()=>"/api/v1/siwe/link",fc=()=>"/api/v1/farcaster/init",hc=()=>"/api/v1/farcaster/authenticate",yc=()=>"/api/v1/farcaster/link",gc=()=>"/api/v1/farcaster/status",vc=()=>"/api/v1/passwordless/init",wc=()=>"/api/v1/passwordless/authenticate",Cc=()=>"/api/v1/passwordless/link",bc=()=>"/api/v1/passwordless_sms/init",Ec=()=>"/api/v1/passwordless_sms/authenticate",Pc=()=>"/api/v1/passwordless_sms/link",Tc=()=>"/api/v1/oauth/init",xc=()=>"/api/v1/oauth/authenticate",Sc=()=>"/api/v1/oauth/link",_c=()=>"/api/v1/siwe/unlink",kc=()=>"/api/v1/passwordless/unlink",Ac=()=>"/api/v1/passwordless_sms/unlink",Rc=()=>"/api/v1/oauth/unlink",Ic=()=>"/api/v1/farcaster/unlink",Wc=()=>"/api/v1/analytics_events",Mc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Nc=()=>"/api/v1/custom_jwt_account/authenticate",Lc=()=>"/api/v1/mfa/passwordless_sms/init";var Oc=()=>"/api/v1/mfa/passwordless_sms/enroll";var Tr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=Nc(),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 oe(t)}}async link(){throw new Error("Unimplemented")}};var Yo=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new v("Email and email code must be set prior to calling authenticate.");try{let t=wc(),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 oe(t)}}async link(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new v("Email and email code must be set prior to calling authenticate.");try{let t=Cc();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw oe(t)}}async sendCodeEmail(t,o){if(!this.api)throw new v("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new v("Email must be set when initialzing authentication.");try{let r=vc();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw oe(r)}}};import{isMobile as gh}from"react-device-detect";var Ge=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 gn=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new Ge(this._startChannelOnce.bind(this)),this.pollForReady=new Ge(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.channelToken)throw new v("Auth flow must be initialized first");try{let t=await this.api.post(hc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new v("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 oe(t)}}async link(){if(!this.api)throw new v("Auth flow has no API instance");try{return await this.api.post(yc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw oe(t)}}async _startChannelOnce(){if(!this.api)throw new v("Auth flow has no API instance");let t=await this.api.post(fc(),{token:this.captchaToken});gh&&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 v("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.channelToken)throw new v("Auth flow must be initialized first");let t=await this.api.get(gc(),{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 Qc}from"jose";var Dc="1.55.2";var gi="4df5e2316331463a9130964bd6078dfa",Uc="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Fc="34357d3c125c2bcf2ce2bc3309d98715",vi="https://auth.privy.io",Bc=2e4,ze=1400,Hc=2500,fs=Dc;var Jo="privy:token",hs="privy-token",wi="privy:refresh_token",ys="privy-refresh-token",Ci="privy-session",vn="privy:session_transfer_token",wh="privy:wallet",wn="privy:caid",xr="privy:state_code",Sr="privy:code_verifier",bi=e=>`${wh}:${e}`,gs="privy:connectors",vs="privy:connections";var Qo=12e4,io=1,ws="0x1",_r=3e4,Gc="https://api.moonpay.com/v1",zc="https://api.moonpay.com/v1",Vc="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",$c="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",jc="0x420000000000000000000000000000000000000F",qc=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Kc(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Yc(e){return crypto.getRandomValues(new Uint8Array(e))}var Ei=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)}},Cs=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)}},bs=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 Jc(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Ch(){return typeof window<"u"&&window.localStorage?new Cs:new Ei}function bh(){return typeof window<"u"&&window.sessionStorage?new bs:new Ei}var xt=bh(),ee=Ch();var Eh="S256",Ph="S256",xo=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 v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=xt.get(Sr);if(!t)throw new v("Authentication error.");try{let o=xc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return xt.del(Sr),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=oe(o);throw r.privyErrorCode?new v(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new v("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new v("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=xt.get(Sr);if(!t)throw new v("Authentication error.");try{let o=Sc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return xt.del(Sr),r}catch(o){throw oe(o)}}createCodeVerifier(){return Qc.encode(Yc(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Eh){if(o==Ph){let r=await Kc(t);return Qc.encode(r)}else return t}async getAuthorizationUrl(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.provider)throw new v("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();xt.put(Sr,t);let o=this.createStateCode();xt.put(xr,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=Tc();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 oe(n)}}};var Zo=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 _y=Object.create;var ta=Object.defineProperty;var ky=Object.getOwnPropertyDescriptor;var Ay=Object.getOwnPropertyNames;var Ry=Object.getPrototypeOf,Iy=Object.prototype.hasOwnProperty;var Wy=(e,t)=>{for(var o in t)ta(e,o,{get:t[o],enumerable:!0})},qc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ay(t))!Iy.call(e,n)&&n!==o&&ta(e,n,{get:()=>t[n],enumerable:!(r=ky(t,n))||r.enumerable});return e};var k=(e,t,o)=>(o=e!=null?_y(Ry(e)):{},qc(t||!e||!e.__esModule?ta(o,"default",{value:e,enumerable:!0}):o,e)),My=e=>qc(ta({},"__esModule",{value:!0}),e);var hl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Kc=(e,t,o)=>(hl(e,t,"read from private field"),o?o.call(e):t.get(e)),oa=(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)},yl=(e,t,o,r)=>(hl(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var Yc=(e,t,o)=>(hl(e,t,"access private method"),o);var qw={};Wy(qw,{AsExternalProvider:()=>oo,Captcha:()=>Ma,ConnectorManager:()=>kn,PrivyClient:()=>An,PrivyProvider:()=>ay,PrivyProxyProvider:()=>Ce,SUPPORTED_CHAINS:()=>fi,VERSION:()=>da,WalletConnector:()=>pt,addRpcUrlOverrideToChain:()=>by,errorIndicatesMaxMfaRetries:()=>os,errorIndicatesMfaTimeout:()=>jr,errorIndicatesMfaVerificationFailed:()=>qr,getAccessToken:()=>Xe,useConnectWallet:()=>fy,useCreateWallet:()=>yy,useLogin:()=>ly,useLoginWithEmail:()=>py,useLoginWithSms:()=>uy,useLogout:()=>dy,useMfa:()=>rn,useMfaEnrollment:()=>ii,useModalStatus:()=>vy,usePrivy:()=>B,useRegisterMfaListener:()=>Da,useToken:()=>Cy,useWallets:()=>pi});module.exports=My(qw);var Qi=require("@ethersproject/address"),hi=require("@ethersproject/providers"),oy=require("mipd"),$=require("react");var Jc=require("ofetch"),rt=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}]`:""}`}},yo=class extends rt{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},v=class extends rt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},ra=class extends v{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var q=class extends rt{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},de=e=>{if(e instanceof rt)return e;if(!(e instanceof Jc.FetchError))return gt(e);if(!e.response)return new yo("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new yo(t||"ApiError",e.response.status,o||r,e,n)},gt=e=>e instanceof rt?e:e instanceof Error?new v(e.message,e):new v(`Internal error: ${e}`);var un=class extends v{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},St=class extends v{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},na=class extends v{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var ia=()=>"/api/v1/sessions",aa=()=>"/api/v1/sessions/logout",Qc=()=>"/api/v1/sessions/fork",sa=()=>"/api/v1/sessions/fork/recover",Zc=()=>"/api/v1/siwe/init",Xc=()=>"/api/v1/siwe/authenticate",ed=()=>"/api/v1/siwe/link",td=()=>"/api/v1/farcaster/init",od=()=>"/api/v1/farcaster/authenticate",rd=()=>"/api/v1/farcaster/link",nd=()=>"/api/v1/farcaster/status",id=()=>"/api/v1/passwordless/init",ad=()=>"/api/v1/passwordless/authenticate",sd=()=>"/api/v1/passwordless/link",ld=()=>"/api/v1/passwordless_sms/init",cd=()=>"/api/v1/passwordless_sms/authenticate",dd=()=>"/api/v1/passwordless_sms/link",pd=()=>"/api/v1/oauth/init",ud=()=>"/api/v1/oauth/authenticate",md=()=>"/api/v1/oauth/link",fd=()=>"/api/v1/siwe/unlink",hd=()=>"/api/v1/passwordless/unlink",yd=()=>"/api/v1/passwordless_sms/unlink",gd=()=>"/api/v1/oauth/unlink",vd=()=>"/api/v1/farcaster/unlink",wd=()=>"/api/v1/analytics_events",Cd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",bd=()=>"/api/v1/custom_jwt_account/authenticate",Ed=()=>"/api/v1/mfa/passwordless_sms/init";var Pd=()=>"/api/v1/mfa/passwordless_sms/enroll";var mn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=bd(),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 de(t)}}async link(){throw new Error("Unimplemented")}};var Dr=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new v("Email and email code must be set prior to calling authenticate.");try{let t=ad(),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 de(t)}}async link(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new v("Email and email code must be set prior to calling authenticate.");try{let t=sd();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw de(t)}}async sendCodeEmail(t,o){if(!this.api)throw new v("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new v("Email must be set when initialzing authentication.");try{let r=id();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw de(r)}}};var Td=require("react-device-detect");var lt=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 lt(this._startChannelOnce.bind(this)),this.pollForReady=new lt(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.channelToken)throw new v("Auth flow must be initialized first");try{let t=await this.api.post(od(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new v("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 de(t)}}async link(){if(!this.api)throw new v("Auth flow has no API instance");try{return await this.api.post(rd(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw de(t)}}async _startChannelOnce(){if(!this.api)throw new v("Auth flow has no API instance");let t=await this.api.post(td(),{token:this.captchaToken});Td.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 v("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.channelToken)throw new v("Auth flow must be initialized first");let t=await this.api.get(nd(),{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 Tl=require("jose");var xd="1.55.2-beta-20240207215612";var la="4df5e2316331463a9130964bd6078dfa",Sd="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",_d="34357d3c125c2bcf2ce2bc3309d98715",ca="https://auth.privy.io",kd=2e4,ct=1400,Ad=2500,da=xd;var Ur="privy:token",gl="privy-token",pa="privy:refresh_token",vl="privy-refresh-token",ua="privy-session",Ci="privy:session_transfer_token",Ly="privy:wallet",bi="privy:caid",fn="privy:state_code",hn="privy:code_verifier",ma=e=>`${Ly}:${e}`,wl="privy:connectors",Cl="privy:connections";var Fr=12e4,Go=1,bl="0x1",yn=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 fa=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)}},El=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)}},Pl=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 Oy(){return typeof window<"u"&&window.localStorage?new El:new fa}function Dy(){return typeof window<"u"&&window.sessionStorage?new Pl:new fa}var Zt=Dy(),ae=Oy();var Uy="S256",Fy="S256",dr=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 v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=Zt.get(hn);if(!t)throw new v("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 Zt.del(hn),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=de(o);throw r.privyErrorCode?new v(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new v("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new v("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=Zt.get(hn);if(!t)throw new v("Authentication error.");try{let o=md(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Zt.del(hn),r}catch(o){throw de(o)}}createCodeVerifier(){return Tl.base64url.encode(Dd(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Uy){if(o==Fy){let r=await Od(t);return Tl.base64url.encode(r)}else return t}async getAuthorizationUrl(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.provider)throw new v("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();Zt.put(hn,t);let o=this.createStateCode();Zt.put(fn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=pd();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 de(n)}}};var Br=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 _y=Object.create;var ta=Object.defineProperty;var ky=Object.getOwnPropertyDescriptor;var Ay=Object.getOwnPropertyNames;var Ry=Object.getPrototypeOf,Iy=Object.prototype.hasOwnProperty;var Wy=(e,t)=>{for(var o in t)ta(e,o,{get:t[o],enumerable:!0})},qc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ay(t))!Iy.call(e,n)&&n!==o&&ta(e,n,{get:()=>t[n],enumerable:!(r=ky(t,n))||r.enumerable});return e};var k=(e,t,o)=>(o=e!=null?_y(Ry(e)):{},qc(t||!e||!e.__esModule?ta(o,"default",{value:e,enumerable:!0}):o,e)),My=e=>qc(ta({},"__esModule",{value:!0}),e);var hl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Kc=(e,t,o)=>(hl(e,t,"read from private field"),o?o.call(e):t.get(e)),oa=(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)},yl=(e,t,o,r)=>(hl(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var Yc=(e,t,o)=>(hl(e,t,"access private method"),o);var qw={};Wy(qw,{AsExternalProvider:()=>oo,Captcha:()=>Ma,ConnectorManager:()=>kn,PrivyClient:()=>An,PrivyProvider:()=>ay,PrivyProxyProvider:()=>Ce,SUPPORTED_CHAINS:()=>fi,VERSION:()=>da,WalletConnector:()=>pt,addRpcUrlOverrideToChain:()=>by,errorIndicatesMaxMfaRetries:()=>os,errorIndicatesMfaTimeout:()=>jr,errorIndicatesMfaVerificationFailed:()=>qr,getAccessToken:()=>Xe,useConnectWallet:()=>fy,useCreateWallet:()=>yy,useLogin:()=>ly,useLoginWithEmail:()=>py,useLoginWithSms:()=>uy,useLogout:()=>dy,useMfa:()=>rn,useMfaEnrollment:()=>ii,useModalStatus:()=>vy,usePrivy:()=>B,useRegisterMfaListener:()=>Da,useToken:()=>Cy,useWallets:()=>pi});module.exports=My(qw);var Qi=require("@ethersproject/address"),hi=require("@ethersproject/providers"),oy=require("mipd"),$=require("react");var Jc=require("ofetch"),rt=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}]`:""}`}},yo=class extends rt{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},v=class extends rt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},ra=class extends v{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var q=class extends rt{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},de=e=>{if(e instanceof rt)return e;if(!(e instanceof Jc.FetchError))return gt(e);if(!e.response)return new yo("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new yo(t||"ApiError",e.response.status,o||r,e,n)},gt=e=>e instanceof rt?e:e instanceof Error?new v(e.message,e):new v(`Internal error: ${e}`);var un=class extends v{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},St=class extends v{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},na=class extends v{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var ia=()=>"/api/v1/sessions",aa=()=>"/api/v1/sessions/logout",Qc=()=>"/api/v1/sessions/fork",sa=()=>"/api/v1/sessions/fork/recover",Zc=()=>"/api/v1/siwe/init",Xc=()=>"/api/v1/siwe/authenticate",ed=()=>"/api/v1/siwe/link",td=()=>"/api/v1/farcaster/init",od=()=>"/api/v1/farcaster/authenticate",rd=()=>"/api/v1/farcaster/link",nd=()=>"/api/v1/farcaster/status",id=()=>"/api/v1/passwordless/init",ad=()=>"/api/v1/passwordless/authenticate",sd=()=>"/api/v1/passwordless/link",ld=()=>"/api/v1/passwordless_sms/init",cd=()=>"/api/v1/passwordless_sms/authenticate",dd=()=>"/api/v1/passwordless_sms/link",pd=()=>"/api/v1/oauth/init",ud=()=>"/api/v1/oauth/authenticate",md=()=>"/api/v1/oauth/link",fd=()=>"/api/v1/siwe/unlink",hd=()=>"/api/v1/passwordless/unlink",yd=()=>"/api/v1/passwordless_sms/unlink",gd=()=>"/api/v1/oauth/unlink",vd=()=>"/api/v1/farcaster/unlink",wd=()=>"/api/v1/analytics_events",Cd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",bd=()=>"/api/v1/custom_jwt_account/authenticate",Ed=()=>"/api/v1/mfa/passwordless_sms/init";var Pd=()=>"/api/v1/mfa/passwordless_sms/enroll";var mn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=bd(),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 de(t)}}async link(){throw new Error("Unimplemented")}};var Dr=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new v("Email and email code must be set prior to calling authenticate.");try{let t=ad(),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 de(t)}}async link(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new v("Email and email code must be set prior to calling authenticate.");try{let t=sd();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw de(t)}}async sendCodeEmail(t,o){if(!this.api)throw new v("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new v("Email must be set when initialzing authentication.");try{let r=id();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw de(r)}}};var Td=require("react-device-detect");var lt=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 lt(this._startChannelOnce.bind(this)),this.pollForReady=new lt(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.channelToken)throw new v("Auth flow must be initialized first");try{let t=await this.api.post(od(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new v("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 de(t)}}async link(){if(!this.api)throw new v("Auth flow has no API instance");try{return await this.api.post(rd(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw de(t)}}async _startChannelOnce(){if(!this.api)throw new v("Auth flow has no API instance");let t=await this.api.post(td(),{token:this.captchaToken});Td.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 v("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.channelToken)throw new v("Auth flow must be initialized first");let t=await this.api.get(nd(),{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 Tl=require("jose");var xd="1.55.2";var la="4df5e2316331463a9130964bd6078dfa",Sd="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",_d="34357d3c125c2bcf2ce2bc3309d98715",ca="https://auth.privy.io",kd=2e4,ct=1400,Ad=2500,da=xd;var Ur="privy:token",gl="privy-token",pa="privy:refresh_token",vl="privy-refresh-token",ua="privy-session",Ci="privy:session_transfer_token",Ly="privy:wallet",bi="privy:caid",fn="privy:state_code",hn="privy:code_verifier",ma=e=>`${Ly}:${e}`,wl="privy:connectors",Cl="privy:connections";var Fr=12e4,Go=1,bl="0x1",yn=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 fa=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)}},El=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)}},Pl=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 Oy(){return typeof window<"u"&&window.localStorage?new El:new fa}function Dy(){return typeof window<"u"&&window.sessionStorage?new Pl:new fa}var Zt=Dy(),ae=Oy();var Uy="S256",Fy="S256",dr=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 v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=Zt.get(hn);if(!t)throw new v("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 Zt.del(hn),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=de(o);throw r.privyErrorCode?new v(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new v("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new v("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=Zt.get(hn);if(!t)throw new v("Authentication error.");try{let o=md(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Zt.del(hn),r}catch(o){throw de(o)}}createCodeVerifier(){return Tl.base64url.encode(Dd(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Uy){if(o==Fy){let r=await Od(t);return Tl.base64url.encode(r)}else return t}async getAuthorizationUrl(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.provider)throw new v("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();Zt.put(hn,t);let o=this.createStateCode();Zt.put(fn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=pd();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 de(n)}}};var Br=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.55.2-beta-20240207215612",
2
+ "version": "1.55.2",
3
3
  "name": "@privy-io/react-auth",
4
4
  "description": "React client for the Privy Auth API",
5
5
  "keywords": [