@privy-io/react-auth 1.56.1 → 1.56.2-beta-20240219150536
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 +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
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 $2,Web3Provider as ac}from"@ethersproject/providers";import{createStore as q2}from"mipd";import{useCallback as j2,useEffect as lo,useMemo as K2,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.1";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 $2,Web3Provider as ac}from"@ethersproject/providers";import{createStore as q2}from"mipd";import{useCallback as j2,useEffect as lo,useMemo as K2,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-20240219150536";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.d.ts
CHANGED
|
@@ -1589,6 +1589,7 @@ interface PrivyClientConfig {
|
|
|
1589
1589
|
*/
|
|
1590
1590
|
requireUserPasswordOnCreate?: boolean;
|
|
1591
1591
|
/**
|
|
1592
|
+
* @deprecated. Instead, use the server-driven configuration found in the Privy console: https://dashboard.privy.io/apps/YOUR_APP_ID/embedded.
|
|
1592
1593
|
* If true, Privy will not prompt or instantiate any UI for embedded wallet signatures and transactions.
|
|
1593
1594
|
* If false, embedded wallet actions will raise a modal and require user confirmation to proceed.
|
|
1594
1595
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Uy=Object.create;var ra=Object.defineProperty;var Fy=Object.getOwnPropertyDescriptor;var By=Object.getOwnPropertyNames;var Hy=Object.getPrototypeOf,Gy=Object.prototype.hasOwnProperty;var Vy=(e,t)=>{for(var o in t)ra(e,o,{get:t[o],enumerable:!0})},Zc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of By(t))!Gy.call(e,n)&&n!==o&&ra(e,n,{get:()=>t[n],enumerable:!(r=Fy(t,n))||r.enumerable});return e};var A=(e,t,o)=>(o=e!=null?Uy(Hy(e)):{},Zc(t||!e||!e.__esModule?ra(o,"default",{value:e,enumerable:!0}):o,e)),zy=e=>Zc(ra({},"__esModule",{value:!0}),e);var yl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Xc=(e,t,o)=>(yl(e,t,"read from private field"),o?o.call(e):t.get(e)),na=(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)},gl=(e,t,o,r)=>(yl(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var ed=(e,t,o)=>(yl(e,t,"access private method"),o);var iC={};Vy(iC,{AsExternalProvider:()=>io,Captcha:()=>La,ConnectorManager:()=>Rn,PrivyClient:()=>In,PrivyProvider:()=>gy,PrivyProxyProvider:()=>Ce,SUPPORTED_CHAINS:()=>hi,VERSION:()=>ua,WalletConnector:()=>mt,addRpcUrlOverrideToChain:()=>Wy,errorIndicatesMaxMfaRetries:()=>ls,errorIndicatesMfaTimeout:()=>Kr,errorIndicatesMfaVerificationFailed:()=>Yr,getAccessToken:()=>tt,useConnectWallet:()=>xy,useCreateWallet:()=>_y,useLogin:()=>wy,useLoginWithEmail:()=>Ey,useLoginWithSms:()=>Ty,useLogout:()=>by,useMfa:()=>an,useMfaEnrollment:()=>ai,useModalStatus:()=>ky,usePrivy:()=>B,useRegisterMfaListener:()=>Fa,useToken:()=>Iy,useWallets:()=>ui});module.exports=zy(iC);var ea=require("@ethersproject/address"),yi=require("@ethersproject/providers"),my=require("mipd"),$=require("react");var td=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}},v=class extends nt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},ia=class extends v{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 td.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 v(e.message,e):new v(`Internal error: ${e}`);var fn=class extends v{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},At=class extends v{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},aa=class extends v{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var sa=()=>"/api/v1/sessions",la=()=>"/api/v1/sessions/logout",od=()=>"/api/v1/sessions/fork",ca=()=>"/api/v1/sessions/fork/recover",rd=()=>"/api/v1/siwe/init",nd=()=>"/api/v1/siwe/authenticate",id=()=>"/api/v1/siwe/link",ad=()=>"/api/v1/farcaster/init",sd=()=>"/api/v1/farcaster/authenticate",ld=()=>"/api/v1/farcaster/link",cd=()=>"/api/v1/farcaster/status",dd=()=>"/api/v1/passwordless/init",pd=()=>"/api/v1/passwordless/authenticate",ud=()=>"/api/v1/passwordless/link",md=()=>"/api/v1/passwordless_sms/init",fd=()=>"/api/v1/passwordless_sms/authenticate",hd=()=>"/api/v1/passwordless_sms/link",yd=()=>"/api/v1/oauth/init",gd=()=>"/api/v1/oauth/authenticate",vd=()=>"/api/v1/oauth/link",wd=()=>"/api/v1/siwe/unlink",Cd=()=>"/api/v1/passwordless/unlink",bd=()=>"/api/v1/passwordless_sms/unlink",Ed=()=>"/api/v1/oauth/unlink",Td=()=>"/api/v1/farcaster/unlink",Pd=()=>"/api/v1/analytics_events",xd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Sd=()=>"/api/v1/custom_jwt_account/authenticate",_d=()=>"/api/v1/mfa/passwordless_sms/init";var Ad=()=>"/api/v1/mfa/passwordless_sms/enroll";var kd=()=>"/api/v1/users/me/accept_terms";var hn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=Sd(),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 Fr=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=pd(),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=ud();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=dd();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw de(r)}}};var Rd=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 Ei=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 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(sd(),{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(ld(),{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(ad(),{token:this.captchaToken});Rd.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(cd(),{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 xl=require("jose");var Id="1.56.1";var da="4df5e2316331463a9130964bd6078dfa",Wd="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Md="34357d3c125c2bcf2ce2bc3309d98715",pa="https://auth.privy.io",Nd=2e4,pt=1400,Ld=2500,ua=Id;var Br="privy:token",vl="privy-token",ma="privy:refresh_token",wl="privy-refresh-token",fa="privy-session",Ti="privy:session_transfer_token",qy="privy:wallet",Pi="privy:caid",yn="privy:state_code",gn="privy:code_verifier",ha=e=>`${qy}:${e}`,Cl="privy:connectors",bl="privy:connections";var Hr=12e4,$o=1,El="0x1",vn=3e4,Od="https://api.moonpay.com/v1",Dd="https://api.moonpay.com/v1",Ud="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Fd="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Bd="0x420000000000000000000000000000000000000F",Hd=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Gd(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Vd(e){return crypto.getRandomValues(new Uint8Array(e))}var ya=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)}},Tl=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 zd(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function jy(){return typeof window<"u"&&window.localStorage?new Tl:new ya}function Ky(){return typeof window<"u"&&window.sessionStorage?new Pl:new ya}var to=Ky(),ie=jy();var Yy="S256",Jy="S256",mr=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=to.get(gn);if(!t)throw new v("Authentication error.");try{let o=gd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return to.del(gn),{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=to.get(gn);if(!t)throw new v("Authentication error.");try{let o=vd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return to.del(gn),r}catch(o){throw de(o)}}createCodeVerifier(){return xl.base64url.encode(Vd(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Yy){if(o==Jy){let r=await Gd(t);return xl.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();to.put(gn,t);let o=this.createStateCode();to.put(yn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=yd();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 Gr=class{constructor(t,o){this.createSiweMessage=(t,o,r,n,i,a,l)=>`${r} wants you to sign in with your Ethereum account:
|
|
1
|
+
"use strict";var Uy=Object.create;var ra=Object.defineProperty;var Fy=Object.getOwnPropertyDescriptor;var By=Object.getOwnPropertyNames;var Hy=Object.getPrototypeOf,Gy=Object.prototype.hasOwnProperty;var Vy=(e,t)=>{for(var o in t)ra(e,o,{get:t[o],enumerable:!0})},Zc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of By(t))!Gy.call(e,n)&&n!==o&&ra(e,n,{get:()=>t[n],enumerable:!(r=Fy(t,n))||r.enumerable});return e};var A=(e,t,o)=>(o=e!=null?Uy(Hy(e)):{},Zc(t||!e||!e.__esModule?ra(o,"default",{value:e,enumerable:!0}):o,e)),zy=e=>Zc(ra({},"__esModule",{value:!0}),e);var yl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Xc=(e,t,o)=>(yl(e,t,"read from private field"),o?o.call(e):t.get(e)),na=(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)},gl=(e,t,o,r)=>(yl(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var ed=(e,t,o)=>(yl(e,t,"access private method"),o);var iC={};Vy(iC,{AsExternalProvider:()=>io,Captcha:()=>La,ConnectorManager:()=>Rn,PrivyClient:()=>In,PrivyProvider:()=>gy,PrivyProxyProvider:()=>Ce,SUPPORTED_CHAINS:()=>hi,VERSION:()=>ua,WalletConnector:()=>mt,addRpcUrlOverrideToChain:()=>Wy,errorIndicatesMaxMfaRetries:()=>ls,errorIndicatesMfaTimeout:()=>Kr,errorIndicatesMfaVerificationFailed:()=>Yr,getAccessToken:()=>tt,useConnectWallet:()=>xy,useCreateWallet:()=>_y,useLogin:()=>wy,useLoginWithEmail:()=>Ey,useLoginWithSms:()=>Ty,useLogout:()=>by,useMfa:()=>an,useMfaEnrollment:()=>ai,useModalStatus:()=>ky,usePrivy:()=>B,useRegisterMfaListener:()=>Fa,useToken:()=>Iy,useWallets:()=>ui});module.exports=zy(iC);var ea=require("@ethersproject/address"),yi=require("@ethersproject/providers"),my=require("mipd"),$=require("react");var td=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}},v=class extends nt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},ia=class extends v{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 td.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 v(e.message,e):new v(`Internal error: ${e}`);var fn=class extends v{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},At=class extends v{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},aa=class extends v{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var sa=()=>"/api/v1/sessions",la=()=>"/api/v1/sessions/logout",od=()=>"/api/v1/sessions/fork",ca=()=>"/api/v1/sessions/fork/recover",rd=()=>"/api/v1/siwe/init",nd=()=>"/api/v1/siwe/authenticate",id=()=>"/api/v1/siwe/link",ad=()=>"/api/v1/farcaster/init",sd=()=>"/api/v1/farcaster/authenticate",ld=()=>"/api/v1/farcaster/link",cd=()=>"/api/v1/farcaster/status",dd=()=>"/api/v1/passwordless/init",pd=()=>"/api/v1/passwordless/authenticate",ud=()=>"/api/v1/passwordless/link",md=()=>"/api/v1/passwordless_sms/init",fd=()=>"/api/v1/passwordless_sms/authenticate",hd=()=>"/api/v1/passwordless_sms/link",yd=()=>"/api/v1/oauth/init",gd=()=>"/api/v1/oauth/authenticate",vd=()=>"/api/v1/oauth/link",wd=()=>"/api/v1/siwe/unlink",Cd=()=>"/api/v1/passwordless/unlink",bd=()=>"/api/v1/passwordless_sms/unlink",Ed=()=>"/api/v1/oauth/unlink",Td=()=>"/api/v1/farcaster/unlink",Pd=()=>"/api/v1/analytics_events",xd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Sd=()=>"/api/v1/custom_jwt_account/authenticate",_d=()=>"/api/v1/mfa/passwordless_sms/init";var Ad=()=>"/api/v1/mfa/passwordless_sms/enroll";var kd=()=>"/api/v1/users/me/accept_terms";var hn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=Sd(),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 Fr=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=pd(),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=ud();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=dd();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw de(r)}}};var Rd=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 Ei=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 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(sd(),{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(ld(),{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(ad(),{token:this.captchaToken});Rd.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(cd(),{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 xl=require("jose");var Id="1.56.2-beta-20240219150536";var da="4df5e2316331463a9130964bd6078dfa",Wd="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Md="34357d3c125c2bcf2ce2bc3309d98715",pa="https://auth.privy.io",Nd=2e4,pt=1400,Ld=2500,ua=Id;var Br="privy:token",vl="privy-token",ma="privy:refresh_token",wl="privy-refresh-token",fa="privy-session",Ti="privy:session_transfer_token",qy="privy:wallet",Pi="privy:caid",yn="privy:state_code",gn="privy:code_verifier",ha=e=>`${qy}:${e}`,Cl="privy:connectors",bl="privy:connections";var Hr=12e4,$o=1,El="0x1",vn=3e4,Od="https://api.moonpay.com/v1",Dd="https://api.moonpay.com/v1",Ud="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Fd="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Bd="0x420000000000000000000000000000000000000F",Hd=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Gd(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Vd(e){return crypto.getRandomValues(new Uint8Array(e))}var ya=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)}},Tl=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 zd(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function jy(){return typeof window<"u"&&window.localStorage?new Tl:new ya}function Ky(){return typeof window<"u"&&window.sessionStorage?new Pl:new ya}var to=Ky(),ie=jy();var Yy="S256",Jy="S256",mr=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=to.get(gn);if(!t)throw new v("Authentication error.");try{let o=gd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return to.del(gn),{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=to.get(gn);if(!t)throw new v("Authentication error.");try{let o=vd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return to.del(gn),r}catch(o){throw de(o)}}createCodeVerifier(){return xl.base64url.encode(Vd(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Yy){if(o==Jy){let r=await Gd(t);return xl.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();to.put(gn,t);let o=this.createStateCode();to.put(yn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=yd();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 Gr=class{constructor(t,o){this.createSiweMessage=(t,o,r,n,i,a,l)=>`${r} wants you to sign in with your Ethereum account:
|
|
2
2
|
${o}
|
|
3
3
|
|
|
4
4
|
${l}
|
package/package.json
CHANGED