@privy-io/react-auth 1.55.1-beta-20240131151821 → 1.55.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 +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var hs=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var uc=(e,t,o)=>(hs(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)},ys=(e,t,o,r)=>(hs(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var mc=(e,t,o)=>(hs(e,t,"access private method"),o);import{getAddress as us}from"@ethersproject/address";import{StaticJsonRpcProvider as R2,Web3Provider as ic}from"@ethersproject/providers";import{createStore as I2}from"mipd";import{useCallback as W2,useEffect as oo,useMemo as M2,useRef as di,useState as ge}from"react";import{isMobile as N2}from"react-device-detect";import{FetchError as vh}from"ofetch";var De=class extends Error{constructor(o,r,n){super(o);r instanceof Error&&(this.cause=r),this.privyErrorCode=n}toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},Ft=class extends De{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},v=class extends De{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 z=class extends De{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},oe=e=>{if(e instanceof De)return e;if(!(e instanceof vh))return Qe(e);if(!e.response)return new Ft("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new Ft(t||"ApiError",e.response.status,o||r,e,n)},Qe=e=>e instanceof De?e:e instanceof Error?new v(e.message,e):new v(`Internal error: ${e}`);var Tr=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",fc=()=>"/api/v1/sessions/fork",wi=()=>"/api/v1/sessions/fork/recover",hc=()=>"/api/v1/siwe/init",yc=()=>"/api/v1/siwe/authenticate",gc=()=>"/api/v1/siwe/link",vc=()=>"/api/v1/farcaster/init",wc=()=>"/api/v1/farcaster/authenticate",Cc=()=>"/api/v1/farcaster/link",bc=()=>"/api/v1/farcaster/status",Ec=()=>"/api/v1/passwordless/init",Pc=()=>"/api/v1/passwordless/authenticate",Tc=()=>"/api/v1/passwordless/link",xc=()=>"/api/v1/passwordless_sms/init",Sc=()=>"/api/v1/passwordless_sms/authenticate",_c=()=>"/api/v1/passwordless_sms/link",kc=()=>"/api/v1/oauth/init",Ac=()=>"/api/v1/oauth/authenticate",Rc=()=>"/api/v1/oauth/link",Ic=()=>"/api/v1/siwe/unlink",Wc=()=>"/api/v1/passwordless/unlink",Mc=()=>"/api/v1/passwordless_sms/unlink",Nc=()=>"/api/v1/oauth/unlink",Lc=()=>"/api/v1/farcaster/unlink",Oc=()=>"/api/v1/analytics_events",Dc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Uc=()=>"/api/v1/custom_jwt_account/authenticate",Fc=()=>"/api/v1/mfa/passwordless_sms/init";var Bc=()=>"/api/v1/mfa/passwordless_sms/enroll";var xr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=Uc(),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 Jo=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=Tc();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=Ec();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw oe(r)}}};var ze=class{constructor(t){this.promise=null;this.fn=t}execute(t){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(t)}finally{this.promise=null}})()),this.promise}};var gn=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new ze(this._startChannelOnce.bind(this)),this.pollForReady=new ze(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(wc(),{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(Cc(),{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(vc(),{token:this.captchaToken});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(bc(),{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 td}from"jose";var Hc="1.55.0";var Ci="4df5e2316331463a9130964bd6078dfa",Gc="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",zc="34357d3c125c2bcf2ce2bc3309d98715",bi="https://auth.privy.io",Vc=2e4,it=1400,$c=2500,gs=Hc;var Qo="privy:token",vs="privy-token",Ei="privy:refresh_token",ws="privy-refresh-token",Pi="privy-session",vn="privy:session_transfer_token",Ch="privy:wallet",wn="privy:caid",Sr="privy:state_code",_r="privy:code_verifier",Ti=e=>`${Ch}:${e}`,Cs="privy:connectors",bs="privy:connections";var Zo=12e4,no=1,Es="0x1",kr=3e4,jc="https://api.moonpay.com/v1",qc="https://api.moonpay.com/v1",Kc="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Yc="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Jc="0x420000000000000000000000000000000000000F",Qc=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Zc(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Xc(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)}},Ps=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 ed(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function bh(){return typeof window<"u"&&window.localStorage?new Ps:new xi}function Eh(){return typeof window<"u"&&window.sessionStorage?new Ts:new xi}var _t=Eh(),ee=bh();var Ph="S256",Th="S256",xo=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=_t.get(_r);if(!t)throw new v("Authentication error.");try{let o=Ac(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return _t.del(_r),{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(_r);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(_r),r}catch(o){throw oe(o)}}createCodeVerifier(){return td.encode(Xc(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Ph){if(o==Th){let r=await Zc(t);return td.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(_r,t);let o=this.createStateCode();_t.put(Sr,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 Xo=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 hs=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var uc=(e,t,o)=>(hs(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)},ys=(e,t,o,r)=>(hs(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var mc=(e,t,o)=>(hs(e,t,"access private method"),o);import{getAddress as us}from"@ethersproject/address";import{StaticJsonRpcProvider as R2,Web3Provider as ic}from"@ethersproject/providers";import{createStore as I2}from"mipd";import{useCallback as W2,useEffect as oo,useMemo as M2,useRef as di,useState as ge}from"react";import{isMobile as N2}from"react-device-detect";import{FetchError as vh}from"ofetch";var De=class extends Error{constructor(o,r,n){super(o);r instanceof Error&&(this.cause=r),this.privyErrorCode=n}toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},Ft=class extends De{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},v=class extends De{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 z=class extends De{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},oe=e=>{if(e instanceof De)return e;if(!(e instanceof vh))return Qe(e);if(!e.response)return new Ft("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new Ft(t||"ApiError",e.response.status,o||r,e,n)},Qe=e=>e instanceof De?e:e instanceof Error?new v(e.message,e):new v(`Internal error: ${e}`);var Tr=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",fc=()=>"/api/v1/sessions/fork",wi=()=>"/api/v1/sessions/fork/recover",hc=()=>"/api/v1/siwe/init",yc=()=>"/api/v1/siwe/authenticate",gc=()=>"/api/v1/siwe/link",vc=()=>"/api/v1/farcaster/init",wc=()=>"/api/v1/farcaster/authenticate",Cc=()=>"/api/v1/farcaster/link",bc=()=>"/api/v1/farcaster/status",Ec=()=>"/api/v1/passwordless/init",Pc=()=>"/api/v1/passwordless/authenticate",Tc=()=>"/api/v1/passwordless/link",xc=()=>"/api/v1/passwordless_sms/init",Sc=()=>"/api/v1/passwordless_sms/authenticate",_c=()=>"/api/v1/passwordless_sms/link",kc=()=>"/api/v1/oauth/init",Ac=()=>"/api/v1/oauth/authenticate",Rc=()=>"/api/v1/oauth/link",Ic=()=>"/api/v1/siwe/unlink",Wc=()=>"/api/v1/passwordless/unlink",Mc=()=>"/api/v1/passwordless_sms/unlink",Nc=()=>"/api/v1/oauth/unlink",Lc=()=>"/api/v1/farcaster/unlink",Oc=()=>"/api/v1/analytics_events",Dc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Uc=()=>"/api/v1/custom_jwt_account/authenticate",Fc=()=>"/api/v1/mfa/passwordless_sms/init";var Bc=()=>"/api/v1/mfa/passwordless_sms/enroll";var xr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=Uc(),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 Jo=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=Tc();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=Ec();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw oe(r)}}};var ze=class{constructor(t){this.promise=null;this.fn=t}execute(t){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(t)}finally{this.promise=null}})()),this.promise}};var gn=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new ze(this._startChannelOnce.bind(this)),this.pollForReady=new ze(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(wc(),{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(Cc(),{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(vc(),{token:this.captchaToken});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(bc(),{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 td}from"jose";var Hc="1.55.1";var Ci="4df5e2316331463a9130964bd6078dfa",Gc="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",zc="34357d3c125c2bcf2ce2bc3309d98715",bi="https://auth.privy.io",Vc=2e4,it=1400,$c=2500,gs=Hc;var Qo="privy:token",vs="privy-token",Ei="privy:refresh_token",ws="privy-refresh-token",Pi="privy-session",vn="privy:session_transfer_token",Ch="privy:wallet",wn="privy:caid",Sr="privy:state_code",_r="privy:code_verifier",Ti=e=>`${Ch}:${e}`,Cs="privy:connectors",bs="privy:connections";var Zo=12e4,no=1,Es="0x1",kr=3e4,jc="https://api.moonpay.com/v1",qc="https://api.moonpay.com/v1",Kc="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Yc="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Jc="0x420000000000000000000000000000000000000F",Qc=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Zc(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Xc(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)}},Ps=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 ed(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function bh(){return typeof window<"u"&&window.localStorage?new Ps:new xi}function Eh(){return typeof window<"u"&&window.sessionStorage?new Ts:new xi}var _t=Eh(),ee=bh();var Ph="S256",Th="S256",xo=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=_t.get(_r);if(!t)throw new v("Authentication error.");try{let o=Ac(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return _t.del(_r),{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(_r);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(_r),r}catch(o){throw oe(o)}}createCodeVerifier(){return td.encode(Xc(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Ph){if(o==Th){let r=await Zc(t);return td.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(_r,t);let o=this.createStateCode();_t.put(Sr,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 Xo=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 ky=Object.create;var na=Object.defineProperty;var Ay=Object.getOwnPropertyDescriptor;var Ry=Object.getOwnPropertyNames;var Iy=Object.getPrototypeOf,Wy=Object.prototype.hasOwnProperty;var My=(e,t)=>{for(var o in t)na(e,o,{get:t[o],enumerable:!0})},Jc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ry(t))!Wy.call(e,n)&&n!==o&&na(e,n,{get:()=>t[n],enumerable:!(r=Ay(t,n))||r.enumerable});return e};var k=(e,t,o)=>(o=e!=null?ky(Iy(e)):{},Jc(t||!e||!e.__esModule?na(o,"default",{value:e,enumerable:!0}):o,e)),Ny=e=>Jc(na({},"__esModule",{value:!0}),e);var yl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Qc=(e,t,o)=>(yl(e,t,"read from private field"),o?o.call(e):t.get(e)),ia=(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 Zc=(e,t,o)=>(yl(e,t,"access private method"),o);var Kw={};My(Kw,{AsExternalProvider:()=>ro,Captcha:()=>Oa,ConnectorManager:()=>An,PrivyClient:()=>Rn,PrivyProvider:()=>sy,PrivyProxyProvider:()=>Ce,SUPPORTED_CHAINS:()=>hi,VERSION:()=>ma,WalletConnector:()=>pt,addRpcUrlOverrideToChain:()=>Ey,errorIndicatesMaxMfaRetries:()=>ns,errorIndicatesMfaTimeout:()=>qr,errorIndicatesMfaVerificationFailed:()=>Kr,getAccessToken:()=>Ze,useConnectWallet:()=>hy,useCreateWallet:()=>gy,useLogin:()=>cy,useLoginWithEmail:()=>uy,useLoginWithSms:()=>my,useLogout:()=>py,useMfa:()=>nn,useMfaEnrollment:()=>ai,useModalStatus:()=>wy,usePrivy:()=>G,useRegisterMfaListener:()=>Ba,useToken:()=>by,useWallets:()=>ui});module.exports=Ny(Kw);var ea=require("@ethersproject/address"),yi=require("@ethersproject/providers"),oy=require("mipd"),V=require("react"),ry=require("react-device-detect");var Xc=require("ofetch"),rt=class extends Error{constructor(o,r,n){super(o);r instanceof Error&&(this.cause=r),this.privyErrorCode=n}toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},ho=class extends rt{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},v=class extends rt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},aa=class extends v{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var j=class extends rt{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},pe=e=>{if(e instanceof rt)return e;if(!(e instanceof Xc.FetchError))return gt(e);if(!e.response)return new ho("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new ho(t||"ApiError",e.response.status,o||r,e,n)},gt=e=>e instanceof rt?e:e instanceof Error?new v(e.message,e):new v(`Internal error: ${e}`);var mn=class extends v{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},St=class extends v{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},sa=class extends v{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var la=()=>"/api/v1/sessions",ca=()=>"/api/v1/sessions/logout",ed=()=>"/api/v1/sessions/fork",da=()=>"/api/v1/sessions/fork/recover",td=()=>"/api/v1/siwe/init",od=()=>"/api/v1/siwe/authenticate",rd=()=>"/api/v1/siwe/link",nd=()=>"/api/v1/farcaster/init",id=()=>"/api/v1/farcaster/authenticate",ad=()=>"/api/v1/farcaster/link",sd=()=>"/api/v1/farcaster/status",ld=()=>"/api/v1/passwordless/init",cd=()=>"/api/v1/passwordless/authenticate",dd=()=>"/api/v1/passwordless/link",pd=()=>"/api/v1/passwordless_sms/init",ud=()=>"/api/v1/passwordless_sms/authenticate",md=()=>"/api/v1/passwordless_sms/link",fd=()=>"/api/v1/oauth/init",hd=()=>"/api/v1/oauth/authenticate",yd=()=>"/api/v1/oauth/link",gd=()=>"/api/v1/siwe/unlink",vd=()=>"/api/v1/passwordless/unlink",wd=()=>"/api/v1/passwordless_sms/unlink",Cd=()=>"/api/v1/oauth/unlink",bd=()=>"/api/v1/farcaster/unlink",Ed=()=>"/api/v1/analytics_events",Pd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Td=()=>"/api/v1/custom_jwt_account/authenticate",xd=()=>"/api/v1/mfa/passwordless_sms/init";var Sd=()=>"/api/v1/mfa/passwordless_sms/enroll";var fn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=Td(),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 pe(t)}}async link(){throw new Error("Unimplemented")}};var Ur=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=cd(),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 pe(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=dd();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw pe(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=ld();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw pe(r)}}};var ct=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 Ci=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new ct(this._startChannelOnce.bind(this)),this.pollForReady=new ct(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(id(),{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 pe(t)}}async link(){if(!this.api)throw new v("Auth flow has no API instance");try{return await this.api.post(ad(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw pe(t)}}async _startChannelOnce(){if(!this.api)throw new v("Auth flow has no API instance");let t=await this.api.post(nd(),{token:this.captchaToken});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(sd(),{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 _d="1.55.0";var pa="4df5e2316331463a9130964bd6078dfa",kd="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Ad="34357d3c125c2bcf2ce2bc3309d98715",ua="https://auth.privy.io",Rd=2e4,_t=1400,Id=2500,ma=_d;var Fr="privy:token",vl="privy-token",fa="privy:refresh_token",wl="privy-refresh-token",ha="privy-session",bi="privy:session_transfer_token",Oy="privy:wallet",Ei="privy:caid",hn="privy:state_code",yn="privy:code_verifier",ya=e=>`${Oy}:${e}`,Cl="privy:connectors",bl="privy:connections";var Br=12e4,Go=1,El="0x1",gn=3e4,Wd="https://api.moonpay.com/v1",Md="https://api.moonpay.com/v1",Nd="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Ld="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Od="0x420000000000000000000000000000000000000F",Dd=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Ud(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Fd(e){return crypto.getRandomValues(new Uint8Array(e))}var ga=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)}},Pl=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)}},Tl=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 Bd(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Dy(){return typeof window<"u"&&window.localStorage?new Pl:new ga}function Uy(){return typeof window<"u"&&window.sessionStorage?new Tl:new ga}var Xt=Uy(),se=Dy();var Fy="S256",By="S256",dr=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=Xt.get(yn);if(!t)throw new v("Authentication error.");try{let o=hd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Xt.del(yn),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=pe(o);throw r.privyErrorCode?new v(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new v("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new v("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=Xt.get(yn);if(!t)throw new v("Authentication error.");try{let o=yd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Xt.del(yn),r}catch(o){throw pe(o)}}createCodeVerifier(){return xl.base64url.encode(Fd(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Fy){if(o==By){let r=await Ud(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();Xt.put(yn,t);let o=this.createStateCode();Xt.put(hn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=fd();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 pe(n)}}};var Hr=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 ky=Object.create;var na=Object.defineProperty;var Ay=Object.getOwnPropertyDescriptor;var Ry=Object.getOwnPropertyNames;var Iy=Object.getPrototypeOf,Wy=Object.prototype.hasOwnProperty;var My=(e,t)=>{for(var o in t)na(e,o,{get:t[o],enumerable:!0})},Jc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ry(t))!Wy.call(e,n)&&n!==o&&na(e,n,{get:()=>t[n],enumerable:!(r=Ay(t,n))||r.enumerable});return e};var k=(e,t,o)=>(o=e!=null?ky(Iy(e)):{},Jc(t||!e||!e.__esModule?na(o,"default",{value:e,enumerable:!0}):o,e)),Ny=e=>Jc(na({},"__esModule",{value:!0}),e);var yl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Qc=(e,t,o)=>(yl(e,t,"read from private field"),o?o.call(e):t.get(e)),ia=(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 Zc=(e,t,o)=>(yl(e,t,"access private method"),o);var Kw={};My(Kw,{AsExternalProvider:()=>ro,Captcha:()=>Oa,ConnectorManager:()=>An,PrivyClient:()=>Rn,PrivyProvider:()=>sy,PrivyProxyProvider:()=>Ce,SUPPORTED_CHAINS:()=>hi,VERSION:()=>ma,WalletConnector:()=>pt,addRpcUrlOverrideToChain:()=>Ey,errorIndicatesMaxMfaRetries:()=>ns,errorIndicatesMfaTimeout:()=>qr,errorIndicatesMfaVerificationFailed:()=>Kr,getAccessToken:()=>Ze,useConnectWallet:()=>hy,useCreateWallet:()=>gy,useLogin:()=>cy,useLoginWithEmail:()=>uy,useLoginWithSms:()=>my,useLogout:()=>py,useMfa:()=>nn,useMfaEnrollment:()=>ai,useModalStatus:()=>wy,usePrivy:()=>G,useRegisterMfaListener:()=>Ba,useToken:()=>by,useWallets:()=>ui});module.exports=Ny(Kw);var ea=require("@ethersproject/address"),yi=require("@ethersproject/providers"),oy=require("mipd"),V=require("react"),ry=require("react-device-detect");var Xc=require("ofetch"),rt=class extends Error{constructor(o,r,n){super(o);r instanceof Error&&(this.cause=r),this.privyErrorCode=n}toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},ho=class extends rt{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},v=class extends rt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},aa=class extends v{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var j=class extends rt{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},pe=e=>{if(e instanceof rt)return e;if(!(e instanceof Xc.FetchError))return gt(e);if(!e.response)return new ho("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new ho(t||"ApiError",e.response.status,o||r,e,n)},gt=e=>e instanceof rt?e:e instanceof Error?new v(e.message,e):new v(`Internal error: ${e}`);var mn=class extends v{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},St=class extends v{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},sa=class extends v{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var la=()=>"/api/v1/sessions",ca=()=>"/api/v1/sessions/logout",ed=()=>"/api/v1/sessions/fork",da=()=>"/api/v1/sessions/fork/recover",td=()=>"/api/v1/siwe/init",od=()=>"/api/v1/siwe/authenticate",rd=()=>"/api/v1/siwe/link",nd=()=>"/api/v1/farcaster/init",id=()=>"/api/v1/farcaster/authenticate",ad=()=>"/api/v1/farcaster/link",sd=()=>"/api/v1/farcaster/status",ld=()=>"/api/v1/passwordless/init",cd=()=>"/api/v1/passwordless/authenticate",dd=()=>"/api/v1/passwordless/link",pd=()=>"/api/v1/passwordless_sms/init",ud=()=>"/api/v1/passwordless_sms/authenticate",md=()=>"/api/v1/passwordless_sms/link",fd=()=>"/api/v1/oauth/init",hd=()=>"/api/v1/oauth/authenticate",yd=()=>"/api/v1/oauth/link",gd=()=>"/api/v1/siwe/unlink",vd=()=>"/api/v1/passwordless/unlink",wd=()=>"/api/v1/passwordless_sms/unlink",Cd=()=>"/api/v1/oauth/unlink",bd=()=>"/api/v1/farcaster/unlink",Ed=()=>"/api/v1/analytics_events",Pd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Td=()=>"/api/v1/custom_jwt_account/authenticate",xd=()=>"/api/v1/mfa/passwordless_sms/init";var Sd=()=>"/api/v1/mfa/passwordless_sms/enroll";var fn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=Td(),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 pe(t)}}async link(){throw new Error("Unimplemented")}};var Ur=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=cd(),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 pe(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=dd();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw pe(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=ld();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw pe(r)}}};var ct=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 Ci=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new ct(this._startChannelOnce.bind(this)),this.pollForReady=new ct(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(id(),{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 pe(t)}}async link(){if(!this.api)throw new v("Auth flow has no API instance");try{return await this.api.post(ad(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw pe(t)}}async _startChannelOnce(){if(!this.api)throw new v("Auth flow has no API instance");let t=await this.api.post(nd(),{token:this.captchaToken});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(sd(),{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 _d="1.55.1";var pa="4df5e2316331463a9130964bd6078dfa",kd="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Ad="34357d3c125c2bcf2ce2bc3309d98715",ua="https://auth.privy.io",Rd=2e4,_t=1400,Id=2500,ma=_d;var Fr="privy:token",vl="privy-token",fa="privy:refresh_token",wl="privy-refresh-token",ha="privy-session",bi="privy:session_transfer_token",Oy="privy:wallet",Ei="privy:caid",hn="privy:state_code",yn="privy:code_verifier",ya=e=>`${Oy}:${e}`,Cl="privy:connectors",bl="privy:connections";var Br=12e4,Go=1,El="0x1",gn=3e4,Wd="https://api.moonpay.com/v1",Md="https://api.moonpay.com/v1",Nd="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Ld="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Od="0x420000000000000000000000000000000000000F",Dd=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Ud(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Fd(e){return crypto.getRandomValues(new Uint8Array(e))}var ga=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)}},Pl=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)}},Tl=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 Bd(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Dy(){return typeof window<"u"&&window.localStorage?new Pl:new ga}function Uy(){return typeof window<"u"&&window.sessionStorage?new Tl:new ga}var Xt=Uy(),se=Dy();var Fy="S256",By="S256",dr=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=Xt.get(yn);if(!t)throw new v("Authentication error.");try{let o=hd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Xt.del(yn),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=pe(o);throw r.privyErrorCode?new v(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new v("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new v("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new v("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new v("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new v("User denied confirmation during OAuth flow");let t=Xt.get(yn);if(!t)throw new v("Authentication error.");try{let o=yd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Xt.del(yn),r}catch(o){throw pe(o)}}createCodeVerifier(){return xl.base64url.encode(Fd(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Fy){if(o==By){let r=await Ud(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();Xt.put(yn,t);let o=this.createStateCode();Xt.put(hn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=fd();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 pe(n)}}};var Hr=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