@privy-io/react-auth 1.54.1-beta-20240122221234 → 1.54.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var ts=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Kl=(e,t,o)=>(ts(e,t,"read from private field"),o?o.call(e):t.get(e)),ai=(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)},os=(e,t,o,r)=>(ts(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var Yl=(e,t,o)=>(ts(e,t,"access private method"),o);import{getAddress as es}from"@ethersproject/address";import{StaticJsonRpcProvider as Mb,Web3Provider as Gl}from"@ethersproject/providers";import{createStore as Lb}from"mipd";import{useCallback as Nb,useEffect as Zt,useMemo as Ob,useRef as Zn,useState as ae}from"react";import{FetchError as Uf}from"ofetch";var Qe=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}]`:""}`}},go=class extends Qe{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},C=class extends Qe{constructor(o,r,n){super(o,r,n);this.type="client_error"}},si=class extends C{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var z=class extends Qe{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},te=e=>{if(e instanceof Qe)return e;if(!(e instanceof Uf))return Xe(e);if(!e.response)return new go("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new go(t||"ApiError",e.response.status,o||r,e,n)},Xe=e=>e instanceof Qe?e:e instanceof Error?new C(e.message,e):new C(`Internal error: ${e}`);var cn=class extends C{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},Ze=class extends C{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},li=class extends C{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var ci=()=>"/api/v1/sessions",di=()=>"/api/v1/sessions/logout",Jl=()=>"/api/v1/sessions/fork",pi=()=>"/api/v1/sessions/fork/recover",Ql=()=>"/api/v1/siwe/init",Zl=()=>"/api/v1/siwe/authenticate",Xl=()=>"/api/v1/siwe/link",ec=()=>"/api/v1/passwordless/init",tc=()=>"/api/v1/passwordless/authenticate",oc=()=>"/api/v1/passwordless/link",rc=()=>"/api/v1/passwordless_sms/init",nc=()=>"/api/v1/passwordless_sms/authenticate",ic=()=>"/api/v1/passwordless_sms/link",ac=()=>"/api/v1/oauth/init",sc=()=>"/api/v1/oauth/authenticate",lc=()=>"/api/v1/oauth/link",cc=()=>"/api/v1/siwe/unlink",dc=()=>"/api/v1/passwordless/unlink",pc=()=>"/api/v1/passwordless_sms/unlink",uc=()=>"/api/v1/oauth/unlink",mc=()=>"/api/v1/analytics_events",fc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",hc=()=>"/api/v1/custom_jwt_account/authenticate",yc=()=>"/api/v1/mfa/passwordless_sms/init";var gc=()=>"/api/v1/mfa/passwordless_sms/enroll";var vr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");try{let t=hc(),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 te(t)}}async link(){throw new Error("Unimplemented")}};var $o=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=tc(),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 te(t)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=oc();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw te(t)}}async sendCodeEmail(t,o){if(!this.api)throw new C("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new C("Email must be set when initialzing authentication.");try{let r=ec();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw te(r)}}};import zf from"create-hash";import{base64url as Rc}from"jose";import Vf from"randombytes";var vc="1.54.0";var ui="4df5e2316331463a9130964bd6078dfa",wc="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Cc="34357d3c125c2bcf2ce2bc3309d98715",mi="https://auth.privy.io",bc=2e4,et=1400,Ec=2500,rs=vc;var jo="privy:token",ns="privy-token",fi="privy:refresh_token",is="privy-refresh-token",hi="privy-session",dn="privy:session_transfer_token",Bf="privy:wallet",pn="privy:caid",wr="privy:state_code",Cr="privy:code_verifier",yi=e=>`${Bf}:${e}`,as="privy:connectors",ss="privy:connections";var qo=12e4,to=1,ls="0x1",br=3e4,Pc="https://api.moonpay.com/v1",Tc="https://api.moonpay.com/v1",xc="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Sc="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",_c="0x420000000000000000000000000000000000000F",kc=["function getL1Fee(bytes memory _data) external view returns (uint256)"];var gi=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)}},ds=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 Ac(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Hf(){return typeof window<"u"&&window.localStorage?new cs:new gi}function Gf(){return typeof window<"u"&&window.sessionStorage?new ds:new gi}var bt=Gf(),Z=Hf();var $f="S256",jf="S256",vo=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=bt.get(Cr);if(!t)throw new C("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 bt.del(Cr),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=te(o);throw r.privyErrorCode?new C(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new C("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new C("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=bt.get(Cr);if(!t)throw new C("Authentication error.");try{let o=lc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return bt.del(Cr),r}catch(o){throw te(o)}}createCodeVerifier(){return Rc.encode(Vf(32))}createStateCode(){return this.createCodeVerifier()}deriveCodeChallengeFromCodeVerifier(t,o=$f){return o==jf?Rc.encode(zf("sha256").update(t).digest()):t}async getAuthorizationUrl(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.provider)throw new C("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();bt.put(Cr,t);let o=this.createStateCode();bt.put(wr,o);let r=this.deriveCodeChallengeFromCodeVerifier(t);try{let n=ac();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 te(n)}}};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 Ko=class{constructor(t){this.createSiweMessage=(t,o,r,n,i,a,s)=>`${r} wants you to sign in with your Ethereum account:
1
+ var ts=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Kl=(e,t,o)=>(ts(e,t,"read from private field"),o?o.call(e):t.get(e)),ai=(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)},os=(e,t,o,r)=>(ts(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var Yl=(e,t,o)=>(ts(e,t,"access private method"),o);import{getAddress as es}from"@ethersproject/address";import{StaticJsonRpcProvider as Mb,Web3Provider as Gl}from"@ethersproject/providers";import{createStore as Lb}from"mipd";import{useCallback as Nb,useEffect as Zt,useMemo as Ob,useRef as Zn,useState as ae}from"react";import{FetchError as Uf}from"ofetch";var Qe=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}]`:""}`}},go=class extends Qe{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},C=class extends Qe{constructor(o,r,n){super(o,r,n);this.type="client_error"}},si=class extends C{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var z=class extends Qe{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},te=e=>{if(e instanceof Qe)return e;if(!(e instanceof Uf))return Xe(e);if(!e.response)return new go("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new go(t||"ApiError",e.response.status,o||r,e,n)},Xe=e=>e instanceof Qe?e:e instanceof Error?new C(e.message,e):new C(`Internal error: ${e}`);var cn=class extends C{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},Ze=class extends C{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},li=class extends C{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var ci=()=>"/api/v1/sessions",di=()=>"/api/v1/sessions/logout",Jl=()=>"/api/v1/sessions/fork",pi=()=>"/api/v1/sessions/fork/recover",Ql=()=>"/api/v1/siwe/init",Zl=()=>"/api/v1/siwe/authenticate",Xl=()=>"/api/v1/siwe/link",ec=()=>"/api/v1/passwordless/init",tc=()=>"/api/v1/passwordless/authenticate",oc=()=>"/api/v1/passwordless/link",rc=()=>"/api/v1/passwordless_sms/init",nc=()=>"/api/v1/passwordless_sms/authenticate",ic=()=>"/api/v1/passwordless_sms/link",ac=()=>"/api/v1/oauth/init",sc=()=>"/api/v1/oauth/authenticate",lc=()=>"/api/v1/oauth/link",cc=()=>"/api/v1/siwe/unlink",dc=()=>"/api/v1/passwordless/unlink",pc=()=>"/api/v1/passwordless_sms/unlink",uc=()=>"/api/v1/oauth/unlink",mc=()=>"/api/v1/analytics_events",fc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",hc=()=>"/api/v1/custom_jwt_account/authenticate",yc=()=>"/api/v1/mfa/passwordless_sms/init";var gc=()=>"/api/v1/mfa/passwordless_sms/enroll";var vr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");try{let t=hc(),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 te(t)}}async link(){throw new Error("Unimplemented")}};var $o=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=tc(),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 te(t)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=oc();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw te(t)}}async sendCodeEmail(t,o){if(!this.api)throw new C("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new C("Email must be set when initialzing authentication.");try{let r=ec();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw te(r)}}};import zf from"create-hash";import{base64url as Rc}from"jose";import Vf from"randombytes";var vc="1.54.1";var ui="4df5e2316331463a9130964bd6078dfa",wc="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Cc="34357d3c125c2bcf2ce2bc3309d98715",mi="https://auth.privy.io",bc=2e4,et=1400,Ec=2500,rs=vc;var jo="privy:token",ns="privy-token",fi="privy:refresh_token",is="privy-refresh-token",hi="privy-session",dn="privy:session_transfer_token",Bf="privy:wallet",pn="privy:caid",wr="privy:state_code",Cr="privy:code_verifier",yi=e=>`${Bf}:${e}`,as="privy:connectors",ss="privy:connections";var qo=12e4,to=1,ls="0x1",br=3e4,Pc="https://api.moonpay.com/v1",Tc="https://api.moonpay.com/v1",xc="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Sc="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",_c="0x420000000000000000000000000000000000000F",kc=["function getL1Fee(bytes memory _data) external view returns (uint256)"];var gi=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)}},ds=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 Ac(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Hf(){return typeof window<"u"&&window.localStorage?new cs:new gi}function Gf(){return typeof window<"u"&&window.sessionStorage?new ds:new gi}var bt=Gf(),Z=Hf();var $f="S256",jf="S256",vo=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=bt.get(Cr);if(!t)throw new C("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 bt.del(Cr),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=te(o);throw r.privyErrorCode?new C(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new C("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new C("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=bt.get(Cr);if(!t)throw new C("Authentication error.");try{let o=lc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return bt.del(Cr),r}catch(o){throw te(o)}}createCodeVerifier(){return Rc.encode(Vf(32))}createStateCode(){return this.createCodeVerifier()}deriveCodeChallengeFromCodeVerifier(t,o=$f){return o==jf?Rc.encode(zf("sha256").update(t).digest()):t}async getAuthorizationUrl(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.provider)throw new C("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();bt.put(Cr,t);let o=this.createStateCode();bt.put(wr,o);let r=this.deriveCodeChallengeFromCodeVerifier(t);try{let n=ac();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 te(n)}}};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 Ko=class{constructor(t){this.createSiweMessage=(t,o,r,n,i,a,s)=>`${r} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${s}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var ey=Object.create;var Ki=Object.defineProperty;var ty=Object.getOwnPropertyDescriptor;var oy=Object.getOwnPropertyNames;var ry=Object.getPrototypeOf,ny=Object.prototype.hasOwnProperty;var iy=(e,t)=>{for(var o in t)Ki(e,o,{get:t[o],enumerable:!0})},Rc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of oy(t))!ny.call(e,n)&&n!==o&&Ki(e,n,{get:()=>t[n],enumerable:!(r=ty(t,n))||r.enumerable});return e};var x=(e,t,o)=>(o=e!=null?ey(ry(e)):{},Rc(t||!e||!e.__esModule?Ki(o,"default",{value:e,enumerable:!0}):o,e)),ay=e=>Rc(Ki({},"__esModule",{value:!0}),e);var tl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Ic=(e,t,o)=>(tl(e,t,"read from private field"),o?o.call(e):t.get(e)),Yi=(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)},ol=(e,t,o,r)=>(tl(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var Wc=(e,t,o)=>(tl(e,t,"access private method"),o);var fw={};iy(fw,{AsExternalProvider:()=>Jt,Captcha:()=>Fi,ConnectorManager:()=>wn,PrivyClient:()=>Cn,PrivyProvider:()=>Ih,PrivyProxyProvider:()=>he,SUPPORTED_CHAINS:()=>ni,VERSION:()=>ra,WalletConnector:()=>nt,errorIndicatesMaxMfaRetries:()=>$a,errorIndicatesMfaTimeout:()=>Or,errorIndicatesMfaVerificationFailed:()=>Dr,getAccessToken:()=>ze,useConnectWallet:()=>Fh,useCreateWallet:()=>Hh,useLogin:()=>Mh,useLoginWithEmail:()=>Oh,useLoginWithSms:()=>Dh,useLogout:()=>Nh,useMfa:()=>jr,useMfaEnrollment:()=>Kn,useModalStatus:()=>zh,usePrivy:()=>V,useRegisterMfaListener:()=>Aa,useToken:()=>$h,useWallets:()=>ti});module.exports=ay(fw);var Bi=require("@ethersproject/address"),ii=require("@ethersproject/providers"),_h=require("mipd"),z=require("react");var Mc=require("ofetch"),wt=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}]`:""}`}},Zo=class extends wt{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},C=class extends wt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},Ji=class extends C{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var j=class extends wt{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},fe=e=>{if(e instanceof wt)return e;if(!(e instanceof Mc.FetchError))return bt(e);if(!e.response)return new Zo("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new Zo(t||"ApiError",e.response.status,o||r,e,n)},bt=e=>e instanceof wt?e:e instanceof Error?new C(e.message,e):new C(`Internal error: ${e}`);var li=class extends C{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},Ct=class extends C{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},Qi=class extends C{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var Zi=()=>"/api/v1/sessions",Xi=()=>"/api/v1/sessions/logout",Lc=()=>"/api/v1/sessions/fork",ea=()=>"/api/v1/sessions/fork/recover",Nc=()=>"/api/v1/siwe/init",Oc=()=>"/api/v1/siwe/authenticate",Dc=()=>"/api/v1/siwe/link",Uc=()=>"/api/v1/passwordless/init",Fc=()=>"/api/v1/passwordless/authenticate",Bc=()=>"/api/v1/passwordless/link",Hc=()=>"/api/v1/passwordless_sms/init",Gc=()=>"/api/v1/passwordless_sms/authenticate",zc=()=>"/api/v1/passwordless_sms/link",Vc=()=>"/api/v1/oauth/init",$c=()=>"/api/v1/oauth/authenticate",jc=()=>"/api/v1/oauth/link",qc=()=>"/api/v1/siwe/unlink",Kc=()=>"/api/v1/passwordless/unlink",Yc=()=>"/api/v1/passwordless_sms/unlink",Jc=()=>"/api/v1/oauth/unlink",Qc=()=>"/api/v1/analytics_events",Zc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Xc=()=>"/api/v1/custom_jwt_account/authenticate",ed=()=>"/api/v1/mfa/passwordless_sms/init";var td=()=>"/api/v1/mfa/passwordless_sms/enroll";var rn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");try{let t=Xc(),o=await this.api.post(t,{token:this.meta.token});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw fe(t)}}async link(){throw new Error("Unimplemented")}};var _r=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=Fc(),o=await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw fe(t)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=Bc();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw fe(t)}}async sendCodeEmail(t,o){if(!this.api)throw new C("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new C("Email must be set when initialzing authentication.");try{let r=Uc();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw fe(r)}}};var fd=x(require("create-hash")),dl=require("jose"),hd=x(require("randombytes"));var od="1.54.0";var ta="4df5e2316331463a9130964bd6078dfa",rd="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",nd="34357d3c125c2bcf2ce2bc3309d98715",oa="https://auth.privy.io",id=2e4,Et=1400,ad=2500,ra=od;var kr="privy:token",rl="privy-token",na="privy:refresh_token",nl="privy-refresh-token",ia="privy-session",ci="privy:session_transfer_token",ly="privy:wallet",di="privy:caid",nn="privy:state_code",an="privy:code_verifier",aa=e=>`${ly}:${e}`,il="privy:connectors",al="privy:connections";var Ar=12e4,No=1,sl="0x1",sn=3e4,sd="https://api.moonpay.com/v1",ld="https://api.moonpay.com/v1",cd="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",dd="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",pd="0x420000000000000000000000000000000000000F",ud=["function getL1Fee(bytes memory _data) external view returns (uint256)"];var sa=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)}},ll=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)}},cl=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 md(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function cy(){return typeof window<"u"&&window.localStorage?new ll:new sa}function dy(){return typeof window<"u"&&window.sessionStorage?new cl:new sa}var jt=dy(),re=cy();var py="S256",uy="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 C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=jt.get(an);if(!t)throw new C("Authentication error.");try{let o=$c(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return jt.del(an),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=fe(o);throw r.privyErrorCode?new C(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new C("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new C("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=jt.get(an);if(!t)throw new C("Authentication error.");try{let o=jc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return jt.del(an),r}catch(o){throw fe(o)}}createCodeVerifier(){return dl.base64url.encode((0,hd.default)(32))}createStateCode(){return this.createCodeVerifier()}deriveCodeChallengeFromCodeVerifier(t,o=py){return o==uy?dl.base64url.encode((0,fd.default)("sha256").update(t).digest()):t}async getAuthorizationUrl(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.provider)throw new C("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();jt.put(an,t);let o=this.createStateCode();jt.put(nn,o);let r=this.deriveCodeChallengeFromCodeVerifier(t);try{let n=Vc();return await this.api.post(n,{provider:this.meta.provider,redirect_to:window.location.href,token:this.meta.captchaToken,code_challenge:r,state_code:o})}catch(n){throw fe(n)}}};var It=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 Rr=class{constructor(t){this.createSiweMessage=(t,o,r,n,i,a,s)=>`${r} wants you to sign in with your Ethereum account:
1
+ "use strict";var ey=Object.create;var Ki=Object.defineProperty;var ty=Object.getOwnPropertyDescriptor;var oy=Object.getOwnPropertyNames;var ry=Object.getPrototypeOf,ny=Object.prototype.hasOwnProperty;var iy=(e,t)=>{for(var o in t)Ki(e,o,{get:t[o],enumerable:!0})},Rc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of oy(t))!ny.call(e,n)&&n!==o&&Ki(e,n,{get:()=>t[n],enumerable:!(r=ty(t,n))||r.enumerable});return e};var x=(e,t,o)=>(o=e!=null?ey(ry(e)):{},Rc(t||!e||!e.__esModule?Ki(o,"default",{value:e,enumerable:!0}):o,e)),ay=e=>Rc(Ki({},"__esModule",{value:!0}),e);var tl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Ic=(e,t,o)=>(tl(e,t,"read from private field"),o?o.call(e):t.get(e)),Yi=(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)},ol=(e,t,o,r)=>(tl(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var Wc=(e,t,o)=>(tl(e,t,"access private method"),o);var fw={};iy(fw,{AsExternalProvider:()=>Jt,Captcha:()=>Fi,ConnectorManager:()=>wn,PrivyClient:()=>Cn,PrivyProvider:()=>Ih,PrivyProxyProvider:()=>he,SUPPORTED_CHAINS:()=>ni,VERSION:()=>ra,WalletConnector:()=>nt,errorIndicatesMaxMfaRetries:()=>$a,errorIndicatesMfaTimeout:()=>Or,errorIndicatesMfaVerificationFailed:()=>Dr,getAccessToken:()=>ze,useConnectWallet:()=>Fh,useCreateWallet:()=>Hh,useLogin:()=>Mh,useLoginWithEmail:()=>Oh,useLoginWithSms:()=>Dh,useLogout:()=>Nh,useMfa:()=>jr,useMfaEnrollment:()=>Kn,useModalStatus:()=>zh,usePrivy:()=>V,useRegisterMfaListener:()=>Aa,useToken:()=>$h,useWallets:()=>ti});module.exports=ay(fw);var Bi=require("@ethersproject/address"),ii=require("@ethersproject/providers"),_h=require("mipd"),z=require("react");var Mc=require("ofetch"),wt=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}]`:""}`}},Zo=class extends wt{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},C=class extends wt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},Ji=class extends C{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var j=class extends wt{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},fe=e=>{if(e instanceof wt)return e;if(!(e instanceof Mc.FetchError))return bt(e);if(!e.response)return new Zo("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new Zo(t||"ApiError",e.response.status,o||r,e,n)},bt=e=>e instanceof wt?e:e instanceof Error?new C(e.message,e):new C(`Internal error: ${e}`);var li=class extends C{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},Ct=class extends C{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},Qi=class extends C{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var Zi=()=>"/api/v1/sessions",Xi=()=>"/api/v1/sessions/logout",Lc=()=>"/api/v1/sessions/fork",ea=()=>"/api/v1/sessions/fork/recover",Nc=()=>"/api/v1/siwe/init",Oc=()=>"/api/v1/siwe/authenticate",Dc=()=>"/api/v1/siwe/link",Uc=()=>"/api/v1/passwordless/init",Fc=()=>"/api/v1/passwordless/authenticate",Bc=()=>"/api/v1/passwordless/link",Hc=()=>"/api/v1/passwordless_sms/init",Gc=()=>"/api/v1/passwordless_sms/authenticate",zc=()=>"/api/v1/passwordless_sms/link",Vc=()=>"/api/v1/oauth/init",$c=()=>"/api/v1/oauth/authenticate",jc=()=>"/api/v1/oauth/link",qc=()=>"/api/v1/siwe/unlink",Kc=()=>"/api/v1/passwordless/unlink",Yc=()=>"/api/v1/passwordless_sms/unlink",Jc=()=>"/api/v1/oauth/unlink",Qc=()=>"/api/v1/analytics_events",Zc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Xc=()=>"/api/v1/custom_jwt_account/authenticate",ed=()=>"/api/v1/mfa/passwordless_sms/init";var td=()=>"/api/v1/mfa/passwordless_sms/enroll";var rn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");try{let t=Xc(),o=await this.api.post(t,{token:this.meta.token});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw fe(t)}}async link(){throw new Error("Unimplemented")}};var _r=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=Fc(),o=await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw fe(t)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=Bc();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw fe(t)}}async sendCodeEmail(t,o){if(!this.api)throw new C("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new C("Email must be set when initialzing authentication.");try{let r=Uc();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw fe(r)}}};var fd=x(require("create-hash")),dl=require("jose"),hd=x(require("randombytes"));var od="1.54.1";var ta="4df5e2316331463a9130964bd6078dfa",rd="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",nd="34357d3c125c2bcf2ce2bc3309d98715",oa="https://auth.privy.io",id=2e4,Et=1400,ad=2500,ra=od;var kr="privy:token",rl="privy-token",na="privy:refresh_token",nl="privy-refresh-token",ia="privy-session",ci="privy:session_transfer_token",ly="privy:wallet",di="privy:caid",nn="privy:state_code",an="privy:code_verifier",aa=e=>`${ly}:${e}`,il="privy:connectors",al="privy:connections";var Ar=12e4,No=1,sl="0x1",sn=3e4,sd="https://api.moonpay.com/v1",ld="https://api.moonpay.com/v1",cd="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",dd="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",pd="0x420000000000000000000000000000000000000F",ud=["function getL1Fee(bytes memory _data) external view returns (uint256)"];var sa=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)}},ll=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)}},cl=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 md(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function cy(){return typeof window<"u"&&window.localStorage?new ll:new sa}function dy(){return typeof window<"u"&&window.sessionStorage?new cl:new sa}var jt=dy(),re=cy();var py="S256",uy="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 C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=jt.get(an);if(!t)throw new C("Authentication error.");try{let o=$c(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return jt.del(an),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=fe(o);throw r.privyErrorCode?new C(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new C("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new C("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=jt.get(an);if(!t)throw new C("Authentication error.");try{let o=jc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return jt.del(an),r}catch(o){throw fe(o)}}createCodeVerifier(){return dl.base64url.encode((0,hd.default)(32))}createStateCode(){return this.createCodeVerifier()}deriveCodeChallengeFromCodeVerifier(t,o=py){return o==uy?dl.base64url.encode((0,fd.default)("sha256").update(t).digest()):t}async getAuthorizationUrl(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.provider)throw new C("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();jt.put(an,t);let o=this.createStateCode();jt.put(nn,o);let r=this.deriveCodeChallengeFromCodeVerifier(t);try{let n=Vc();return await this.api.post(n,{provider:this.meta.provider,redirect_to:window.location.href,token:this.meta.captchaToken,code_challenge:r,state_code:o})}catch(n){throw fe(n)}}};var It=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 Rr=class{constructor(t){this.createSiweMessage=(t,o,r,n,i,a,s)=>`${r} wants you to sign in with your Ethereum account:
2
2
  ${o}
3
3
 
4
4
  ${s}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.54.1-beta-20240122221234",
2
+ "version": "1.54.1",
3
3
  "name": "@privy-io/react-auth",
4
4
  "description": "React client for the Privy Auth API",
5
5
  "keywords": [