@privy-io/react-auth 1.56.2-beta-20240220161216 → 1.56.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 fs=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var mc=(e,t,o)=>(fs(e,t,"read from private field"),o?o.call(e):t.get(e)),fi=(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)},hs=(e,t,o,r)=>(fs(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var fc=(e,t,o)=>(fs(e,t,"access private method"),o);import{getAddress as us}from"@ethersproject/address";import{StaticJsonRpcProvider as q2,Web3Provider as ac}from"@ethersproject/providers";import{createStore as j2}from"mipd";import{useCallback as K2,useEffect as lo,useMemo as Y2,useRef as pi,useState as be}from"react";import{FetchError as xh}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}]`:""}`}},Gt=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"}},hi=class extends v{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var $=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 xh))return Ge(e);if(!e.response)return new Gt("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new Gt(t||"ApiError",e.response.status,o||r,e,n)},Ge=e=>e instanceof Oe?e:e instanceof Error?new v(e.message,e):new v(`Internal error: ${e}`);var xr=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")}},yi=class extends v{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var gi=()=>"/api/v1/sessions",vi=()=>"/api/v1/sessions/logout",hc=()=>"/api/v1/sessions/fork",wi=()=>"/api/v1/sessions/fork/recover",yc=()=>"/api/v1/siwe/init",gc=()=>"/api/v1/siwe/authenticate",vc=()=>"/api/v1/siwe/link",wc=()=>"/api/v1/farcaster/init",Cc=()=>"/api/v1/farcaster/authenticate",bc=()=>"/api/v1/farcaster/link",Ec=()=>"/api/v1/farcaster/status",Tc=()=>"/api/v1/passwordless/init",Pc=()=>"/api/v1/passwordless/authenticate",xc=()=>"/api/v1/passwordless/link",Sc=()=>"/api/v1/passwordless_sms/init",_c=()=>"/api/v1/passwordless_sms/authenticate",Ac=()=>"/api/v1/passwordless_sms/link",kc=()=>"/api/v1/oauth/init",Rc=()=>"/api/v1/oauth/authenticate",Ic=()=>"/api/v1/oauth/link",Wc=()=>"/api/v1/siwe/unlink",Mc=()=>"/api/v1/passwordless/unlink",Nc=()=>"/api/v1/passwordless_sms/unlink",Lc=()=>"/api/v1/oauth/unlink",Oc=()=>"/api/v1/farcaster/unlink",Dc=()=>"/api/v1/analytics_events",Uc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Fc=()=>"/api/v1/custom_jwt_account/authenticate",Bc=()=>"/api/v1/mfa/passwordless_sms/init";var Hc=()=>"/api/v1/mfa/passwordless_sms/enroll";var Gc=()=>"/api/v1/users/me/accept_terms";var Sr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=Fc(),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 Qo=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=Pc(),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=xc();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=Tc();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw oe(r)}}};import{isMobile as Sh}from"react-device-detect";var Ve=class{constructor(t){this.promise=null;this.fn=t}execute(t){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(t)}finally{this.promise=null}})()),this.promise}};var bn=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new Ve(this._startChannelOnce.bind(this)),this.pollForReady=new Ve(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new 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(Cc(),{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(bc(),{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(wc(),{token:this.captchaToken});Sh&&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(Ec(),{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 rd}from"jose";var Vc="1.56.2-beta-20240220161216";var Ci="4df5e2316331463a9130964bd6078dfa",zc="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",$c="34357d3c125c2bcf2ce2bc3309d98715",bi="https://auth.privy.io",qc=2e4,ze=1400,jc=2500,ys=Vc;var Zo="privy:token",gs="privy-token",Ei="privy:refresh_token",vs="privy-refresh-token",Ti="privy-session",En="privy:session_transfer_token",Ah="privy:wallet",Tn="privy:caid",_r="privy:state_code",Ar="privy:code_verifier",Pi=e=>`${Ah}:${e}`,ws="privy:connectors",Cs="privy:connections";var Xo=12e4,co=1,bs="0x1",kr=3e4,Kc="https://api.moonpay.com/v1",Yc="https://api.moonpay.com/v1",Jc="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Qc="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Zc="0x420000000000000000000000000000000000000F",Xc=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function ed(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function td(e){return crypto.getRandomValues(new Uint8Array(e))}var xi=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)}},Es=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)}},Ts=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 od(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function kh(){return typeof window<"u"&&window.localStorage?new Es:new xi}function Rh(){return typeof window<"u"&&window.sessionStorage?new Ts:new xi}var _t=Rh(),X=kh();var Ih="S256",Wh="S256",_o=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=_t.get(Ar);if(!t)throw new v("Authentication error.");try{let o=Rc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return _t.del(Ar),{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=_t.get(Ar);if(!t)throw new v("Authentication error.");try{let o=Ic(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return _t.del(Ar),r}catch(o){throw oe(o)}}createCodeVerifier(){return rd.encode(td(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Ih){if(o==Wh){let r=await ed(t);return rd.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();_t.put(Ar,t);let o=this.createStateCode();_t.put(_r,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=kc();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 er=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 fs=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var mc=(e,t,o)=>(fs(e,t,"read from private field"),o?o.call(e):t.get(e)),fi=(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)},hs=(e,t,o,r)=>(fs(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var fc=(e,t,o)=>(fs(e,t,"access private method"),o);import{getAddress as us}from"@ethersproject/address";import{StaticJsonRpcProvider as q2,Web3Provider as ac}from"@ethersproject/providers";import{createStore as j2}from"mipd";import{useCallback as K2,useEffect as lo,useMemo as Y2,useRef as pi,useState as be}from"react";import{FetchError as xh}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}]`:""}`}},Gt=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"}},hi=class extends v{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var $=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 xh))return Ge(e);if(!e.response)return new Gt("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new Gt(t||"ApiError",e.response.status,o||r,e,n)},Ge=e=>e instanceof Oe?e:e instanceof Error?new v(e.message,e):new v(`Internal error: ${e}`);var xr=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")}},yi=class extends v{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var gi=()=>"/api/v1/sessions",vi=()=>"/api/v1/sessions/logout",hc=()=>"/api/v1/sessions/fork",wi=()=>"/api/v1/sessions/fork/recover",yc=()=>"/api/v1/siwe/init",gc=()=>"/api/v1/siwe/authenticate",vc=()=>"/api/v1/siwe/link",wc=()=>"/api/v1/farcaster/init",Cc=()=>"/api/v1/farcaster/authenticate",bc=()=>"/api/v1/farcaster/link",Ec=()=>"/api/v1/farcaster/status",Tc=()=>"/api/v1/passwordless/init",Pc=()=>"/api/v1/passwordless/authenticate",xc=()=>"/api/v1/passwordless/link",Sc=()=>"/api/v1/passwordless_sms/init",_c=()=>"/api/v1/passwordless_sms/authenticate",Ac=()=>"/api/v1/passwordless_sms/link",kc=()=>"/api/v1/oauth/init",Rc=()=>"/api/v1/oauth/authenticate",Ic=()=>"/api/v1/oauth/link",Wc=()=>"/api/v1/siwe/unlink",Mc=()=>"/api/v1/passwordless/unlink",Nc=()=>"/api/v1/passwordless_sms/unlink",Lc=()=>"/api/v1/oauth/unlink",Oc=()=>"/api/v1/farcaster/unlink",Dc=()=>"/api/v1/analytics_events",Uc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Fc=()=>"/api/v1/custom_jwt_account/authenticate",Bc=()=>"/api/v1/mfa/passwordless_sms/init";var Hc=()=>"/api/v1/mfa/passwordless_sms/enroll";var Gc=()=>"/api/v1/users/me/accept_terms";var Sr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=Fc(),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 Qo=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=Pc(),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=xc();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=Tc();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw oe(r)}}};import{isMobile as Sh}from"react-device-detect";var Ve=class{constructor(t){this.promise=null;this.fn=t}execute(t){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(t)}finally{this.promise=null}})()),this.promise}};var bn=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new Ve(this._startChannelOnce.bind(this)),this.pollForReady=new Ve(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new 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(Cc(),{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(bc(),{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(wc(),{token:this.captchaToken});Sh&&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(Ec(),{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 rd}from"jose";var Vc="1.56.2";var Ci="4df5e2316331463a9130964bd6078dfa",zc="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",$c="34357d3c125c2bcf2ce2bc3309d98715",bi="https://auth.privy.io",qc=2e4,ze=1400,jc=2500,ys=Vc;var Zo="privy:token",gs="privy-token",Ei="privy:refresh_token",vs="privy-refresh-token",Ti="privy-session",En="privy:session_transfer_token",Ah="privy:wallet",Tn="privy:caid",_r="privy:state_code",Ar="privy:code_verifier",Pi=e=>`${Ah}:${e}`,ws="privy:connectors",Cs="privy:connections";var Xo=12e4,co=1,bs="0x1",kr=3e4,Kc="https://api.moonpay.com/v1",Yc="https://api.moonpay.com/v1",Jc="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Qc="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Zc="0x420000000000000000000000000000000000000F",Xc=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function ed(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function td(e){return crypto.getRandomValues(new Uint8Array(e))}var xi=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)}},Es=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)}},Ts=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 od(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function kh(){return typeof window<"u"&&window.localStorage?new Es:new xi}function Rh(){return typeof window<"u"&&window.sessionStorage?new Ts:new xi}var _t=Rh(),X=kh();var Ih="S256",Wh="S256",_o=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=_t.get(Ar);if(!t)throw new v("Authentication error.");try{let o=Rc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return _t.del(Ar),{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=_t.get(Ar);if(!t)throw new v("Authentication error.");try{let o=Ic(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return _t.del(Ar),r}catch(o){throw oe(o)}}createCodeVerifier(){return rd.encode(td(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Ih){if(o==Wh){let r=await ed(t);return rd.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();_t.put(Ar,t);let o=this.createStateCode();_t.put(_r,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=kc();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 er=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 sg=Object.create;var Qi=Object.defineProperty;var lg=Object.getOwnPropertyDescriptor;var cg=Object.getOwnPropertyNames;var dg=Object.getPrototypeOf,pg=Object.prototype.hasOwnProperty;var ug=(e,t)=>{for(var o in t)Qi(e,o,{get:t[o],enumerable:!0})},Gc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of cg(t))!pg.call(e,n)&&n!==o&&Qi(e,n,{get:()=>t[n],enumerable:!(r=lg(t,n))||r.enumerable});return e};var f=(e,t,o)=>(o=e!=null?sg(dg(e)):{},Gc(t||!e||!e.__esModule?Qi(o,"default",{value:e,enumerable:!0}):o,e)),mg=e=>Gc(Qi({},"__esModule",{value:!0}),e);var rl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Vc=(e,t,o)=>(rl(e,t,"read from private field"),o?o.call(e):t.get(e)),Zi=(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)},nl=(e,t,o,r)=>(rl(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var zc=(e,t,o)=>(rl(e,t,"access private method"),o);var AC={};ug(AC,{AsExternalProvider:()=>io,Captcha:()=>ka,ConnectorManager:()=>_n,PrivyClient:()=>An,PrivyProvider:()=>By,PrivyProxyProvider:()=>Ce,SUPPORTED_CHAINS:()=>ci,VERSION:()=>aa,WalletConnector:()=>mt,addRpcUrlOverrideToChain:()=>tg,errorIndicatesMaxMfaRetries:()=>Xa,errorIndicatesMfaTimeout:()=>$r,errorIndicatesMfaVerificationFailed:()=>qr,getAccessToken:()=>tt,useConnectWallet:()=>Ky,useCreateWallet:()=>Jy,useLogin:()=>Gy,useLoginWithEmail:()=>$y,useLoginWithSms:()=>qy,useLogout:()=>zy,useMfa:()=>on,useMfaEnrollment:()=>ei,useModalStatus:()=>Zy,usePrivy:()=>B,useRegisterMfaListener:()=>Ma,useToken:()=>eg,useWallets:()=>ai});module.exports=mg(AC);var Ki=require("@ethersproject/address"),di=require("@ethersproject/providers"),Oy=require("mipd"),$=require("react");var $c=require("ofetch"),nt=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}]`:""}`}},Co=class extends nt{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},w=class extends nt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},Xi=class extends w{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var K=class extends nt{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},de=e=>{if(e instanceof nt)return e;if(!(e instanceof $c.FetchError))return ct(e);if(!e.response)return new Co("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new Co(t||"ApiError",e.response.status,o||r,e,n)},ct=e=>e instanceof nt?e:e instanceof Error?new w(e.message,e):new w(`Internal error: ${e}`);var pn=class extends w{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},At=class extends w{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},ea=class extends w{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var ta=()=>"/api/v1/sessions",oa=()=>"/api/v1/sessions/logout",qc=()=>"/api/v1/sessions/fork",ra=()=>"/api/v1/sessions/fork/recover",jc=()=>"/api/v1/siwe/init",Kc=()=>"/api/v1/siwe/authenticate",Yc=()=>"/api/v1/siwe/link",Jc=()=>"/api/v1/farcaster/init",Qc=()=>"/api/v1/farcaster/authenticate",Zc=()=>"/api/v1/farcaster/link",Xc=()=>"/api/v1/farcaster/status",ed=()=>"/api/v1/passwordless/init",td=()=>"/api/v1/passwordless/authenticate",od=()=>"/api/v1/passwordless/link",rd=()=>"/api/v1/passwordless_sms/init",nd=()=>"/api/v1/passwordless_sms/authenticate",id=()=>"/api/v1/passwordless_sms/link",ad=()=>"/api/v1/oauth/init",sd=()=>"/api/v1/oauth/authenticate",ld=()=>"/api/v1/oauth/link",cd=()=>"/api/v1/siwe/unlink",dd=()=>"/api/v1/passwordless/unlink",pd=()=>"/api/v1/passwordless_sms/unlink",ud=()=>"/api/v1/oauth/unlink",md=()=>"/api/v1/farcaster/unlink",fd=()=>"/api/v1/analytics_events",hd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",yd=()=>"/api/v1/custom_jwt_account/authenticate",gd=()=>"/api/v1/mfa/passwordless_sms/init";var vd=()=>"/api/v1/mfa/passwordless_sms/enroll";var wd=()=>"/api/v1/users/me/accept_terms";var un=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");try{let t=yd(),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 Or=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new w("Email and email code must be set prior to calling authenticate.");try{let t=td(),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 w("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new w("Email and email code must be set prior to calling authenticate.");try{let t=od();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 w("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new w("Email must be set when initialzing authentication.");try{let r=ed();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw de(r)}}};var Cd=require("react-device-detect");var dt=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 yi=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new dt(this._startChannelOnce.bind(this)),this.pollForReady=new dt(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.channelToken)throw new w("Auth flow must be initialized first");try{let t=await this.api.post(Qc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new w("No response from authentication");return{user:t.user,token:t.token,refresh_token:t.refresh_token,is_new_user:t.is_new_user}}catch(t){throw de(t)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");try{return await this.api.post(Zc(),{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 w("Auth flow has no API instance");let t=await this.api.post(Jc(),{token:this.captchaToken});Cd.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 w("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.channelToken)throw new w("Auth flow must be initialized first");let t=await this.api.get(Xc(),{headers:{"farcaster-channel-token":this.meta.channelToken}});return t.state==="completed"?(this.message=t.message,this.signature=t.signature,this.fid=t.fid,!0):!1}};var ul=require("jose");var bd="1.56.2-beta-20240220161216";var na="4df5e2316331463a9130964bd6078dfa",Ed="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Td="34357d3c125c2bcf2ce2bc3309d98715",ia="https://auth.privy.io",Pd=2e4,pt=1400,xd=2500,aa=bd;var Dr="privy:token",il="privy-token",sa="privy:refresh_token",al="privy-refresh-token",la="privy-session",gi="privy:session_transfer_token",hg="privy:wallet",vi="privy:caid",mn="privy:state_code",fn="privy:code_verifier",ca=e=>`${hg}:${e}`,sl="privy:connectors",ll="privy:connections";var Ur=12e4,zo=1,cl="0x1",hn=3e4,Sd="https://api.moonpay.com/v1",_d="https://api.moonpay.com/v1",Ad="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",kd="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Rd="0x420000000000000000000000000000000000000F",Id=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Wd(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Md(e){return crypto.getRandomValues(new Uint8Array(e))}var da=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)}},dl=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 Nd(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function yg(){return typeof window<"u"&&window.localStorage?new dl:new da}function gg(){return typeof window<"u"&&window.sessionStorage?new pl:new da}var to=gg(),ie=yg();var vg="S256",wg="S256",pr=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new w("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new w("User denied confirmation during OAuth flow");let t=to.get(fn);if(!t)throw new w("Authentication error.");try{let o=sd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return to.del(fn),{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 w(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new w("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new w("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new w("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new w("User denied confirmation during OAuth flow");let t=to.get(fn);if(!t)throw new w("Authentication error.");try{let o=ld(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return to.del(fn),r}catch(o){throw de(o)}}createCodeVerifier(){return ul.base64url.encode(Md(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=vg){if(o==wg){let r=await Wd(t);return ul.base64url.encode(r)}else return t}async getAuthorizationUrl(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.provider)throw new w("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();to.put(fn,t);let o=this.createStateCode();to.put(mn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=ad();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 Fr=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 sg=Object.create;var Qi=Object.defineProperty;var lg=Object.getOwnPropertyDescriptor;var cg=Object.getOwnPropertyNames;var dg=Object.getPrototypeOf,pg=Object.prototype.hasOwnProperty;var ug=(e,t)=>{for(var o in t)Qi(e,o,{get:t[o],enumerable:!0})},Gc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of cg(t))!pg.call(e,n)&&n!==o&&Qi(e,n,{get:()=>t[n],enumerable:!(r=lg(t,n))||r.enumerable});return e};var f=(e,t,o)=>(o=e!=null?sg(dg(e)):{},Gc(t||!e||!e.__esModule?Qi(o,"default",{value:e,enumerable:!0}):o,e)),mg=e=>Gc(Qi({},"__esModule",{value:!0}),e);var rl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Vc=(e,t,o)=>(rl(e,t,"read from private field"),o?o.call(e):t.get(e)),Zi=(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)},nl=(e,t,o,r)=>(rl(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var zc=(e,t,o)=>(rl(e,t,"access private method"),o);var AC={};ug(AC,{AsExternalProvider:()=>io,Captcha:()=>ka,ConnectorManager:()=>_n,PrivyClient:()=>An,PrivyProvider:()=>By,PrivyProxyProvider:()=>Ce,SUPPORTED_CHAINS:()=>ci,VERSION:()=>aa,WalletConnector:()=>mt,addRpcUrlOverrideToChain:()=>tg,errorIndicatesMaxMfaRetries:()=>Xa,errorIndicatesMfaTimeout:()=>$r,errorIndicatesMfaVerificationFailed:()=>qr,getAccessToken:()=>tt,useConnectWallet:()=>Ky,useCreateWallet:()=>Jy,useLogin:()=>Gy,useLoginWithEmail:()=>$y,useLoginWithSms:()=>qy,useLogout:()=>zy,useMfa:()=>on,useMfaEnrollment:()=>ei,useModalStatus:()=>Zy,usePrivy:()=>B,useRegisterMfaListener:()=>Ma,useToken:()=>eg,useWallets:()=>ai});module.exports=mg(AC);var Ki=require("@ethersproject/address"),di=require("@ethersproject/providers"),Oy=require("mipd"),$=require("react");var $c=require("ofetch"),nt=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}]`:""}`}},Co=class extends nt{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},w=class extends nt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},Xi=class extends w{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var K=class extends nt{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},de=e=>{if(e instanceof nt)return e;if(!(e instanceof $c.FetchError))return ct(e);if(!e.response)return new Co("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new Co(t||"ApiError",e.response.status,o||r,e,n)},ct=e=>e instanceof nt?e:e instanceof Error?new w(e.message,e):new w(`Internal error: ${e}`);var pn=class extends w{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},At=class extends w{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},ea=class extends w{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var ta=()=>"/api/v1/sessions",oa=()=>"/api/v1/sessions/logout",qc=()=>"/api/v1/sessions/fork",ra=()=>"/api/v1/sessions/fork/recover",jc=()=>"/api/v1/siwe/init",Kc=()=>"/api/v1/siwe/authenticate",Yc=()=>"/api/v1/siwe/link",Jc=()=>"/api/v1/farcaster/init",Qc=()=>"/api/v1/farcaster/authenticate",Zc=()=>"/api/v1/farcaster/link",Xc=()=>"/api/v1/farcaster/status",ed=()=>"/api/v1/passwordless/init",td=()=>"/api/v1/passwordless/authenticate",od=()=>"/api/v1/passwordless/link",rd=()=>"/api/v1/passwordless_sms/init",nd=()=>"/api/v1/passwordless_sms/authenticate",id=()=>"/api/v1/passwordless_sms/link",ad=()=>"/api/v1/oauth/init",sd=()=>"/api/v1/oauth/authenticate",ld=()=>"/api/v1/oauth/link",cd=()=>"/api/v1/siwe/unlink",dd=()=>"/api/v1/passwordless/unlink",pd=()=>"/api/v1/passwordless_sms/unlink",ud=()=>"/api/v1/oauth/unlink",md=()=>"/api/v1/farcaster/unlink",fd=()=>"/api/v1/analytics_events",hd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",yd=()=>"/api/v1/custom_jwt_account/authenticate",gd=()=>"/api/v1/mfa/passwordless_sms/init";var vd=()=>"/api/v1/mfa/passwordless_sms/enroll";var wd=()=>"/api/v1/users/me/accept_terms";var un=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");try{let t=yd(),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 Or=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new w("Email and email code must be set prior to calling authenticate.");try{let t=td(),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 w("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new w("Email and email code must be set prior to calling authenticate.");try{let t=od();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 w("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new w("Email must be set when initialzing authentication.");try{let r=ed();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw de(r)}}};var Cd=require("react-device-detect");var dt=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 yi=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new dt(this._startChannelOnce.bind(this)),this.pollForReady=new dt(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.channelToken)throw new w("Auth flow must be initialized first");try{let t=await this.api.post(Qc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new w("No response from authentication");return{user:t.user,token:t.token,refresh_token:t.refresh_token,is_new_user:t.is_new_user}}catch(t){throw de(t)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");try{return await this.api.post(Zc(),{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 w("Auth flow has no API instance");let t=await this.api.post(Jc(),{token:this.captchaToken});Cd.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 w("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.channelToken)throw new w("Auth flow must be initialized first");let t=await this.api.get(Xc(),{headers:{"farcaster-channel-token":this.meta.channelToken}});return t.state==="completed"?(this.message=t.message,this.signature=t.signature,this.fid=t.fid,!0):!1}};var ul=require("jose");var bd="1.56.2";var na="4df5e2316331463a9130964bd6078dfa",Ed="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Td="34357d3c125c2bcf2ce2bc3309d98715",ia="https://auth.privy.io",Pd=2e4,pt=1400,xd=2500,aa=bd;var Dr="privy:token",il="privy-token",sa="privy:refresh_token",al="privy-refresh-token",la="privy-session",gi="privy:session_transfer_token",hg="privy:wallet",vi="privy:caid",mn="privy:state_code",fn="privy:code_verifier",ca=e=>`${hg}:${e}`,sl="privy:connectors",ll="privy:connections";var Ur=12e4,zo=1,cl="0x1",hn=3e4,Sd="https://api.moonpay.com/v1",_d="https://api.moonpay.com/v1",Ad="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",kd="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Rd="0x420000000000000000000000000000000000000F",Id=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Wd(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Md(e){return crypto.getRandomValues(new Uint8Array(e))}var da=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)}},dl=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 Nd(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function yg(){return typeof window<"u"&&window.localStorage?new dl:new da}function gg(){return typeof window<"u"&&window.sessionStorage?new pl:new da}var to=gg(),ie=yg();var vg="S256",wg="S256",pr=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new w("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new w("User denied confirmation during OAuth flow");let t=to.get(fn);if(!t)throw new w("Authentication error.");try{let o=sd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return to.del(fn),{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 w(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new w("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new w("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new w("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new w("User denied confirmation during OAuth flow");let t=to.get(fn);if(!t)throw new w("Authentication error.");try{let o=ld(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return to.del(fn),r}catch(o){throw de(o)}}createCodeVerifier(){return ul.base64url.encode(Md(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=vg){if(o==wg){let r=await Wd(t);return ul.base64url.encode(r)}else return t}async getAuthorizationUrl(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.provider)throw new w("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();to.put(fn,t);let o=this.createStateCode();to.put(mn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=ad();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 Fr=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.56.2-beta-20240220161216",
2
+ "version": "1.56.2",
3
3
  "name": "@privy-io/react-auth",
4
4
  "description": "React client for the Privy Auth API",
5
5
  "keywords": [