@privy-io/react-auth 1.57.0-beta-20240222192530 → 1.57.0-beta-20240222215500
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 ys=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var fc=(e,t,o)=>(ys(e,t,"read from private field"),o?o.call(e):t.get(e)),yi=(e,t,o)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,o)},gs=(e,t,o,r)=>(ys(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var hc=(e,t,o)=>(ys(e,t,"access private method"),o);import{getAddress as fs}from"@ethersproject/address";import{StaticJsonRpcProvider as ZE,Web3Provider as sc}from"@ethersproject/providers";import{createStore as XE}from"mipd";import{useCallback as e2,useEffect as uo,useMemo as t2,useRef as fi,useState as Te}from"react";import{FetchError as Rh}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}]`:""}`}},$t=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"}},gi=class extends v{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var q=class extends De{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},ie=e=>{if(e instanceof De)return e;if(!(e instanceof Rh))return Ve(e);if(!e.response)return new $t("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new $t(t||"ApiError",e.response.status,o||r,e,n)},Ve=e=>e instanceof De?e:e instanceof Error?new v(e.message,e):new v(`Internal error: ${e}`);var Ar=class extends v{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},lt=class extends v{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},vi=class extends v{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var wi=()=>"/api/v1/sessions",Ci=()=>"/api/v1/sessions/logout",yc=()=>"/api/v1/sessions/fork",bi=()=>"/api/v1/sessions/fork/recover",gc=()=>"/api/v1/siwe/init",vc=()=>"/api/v1/siwe/authenticate",wc=()=>"/api/v1/siwe/link",Cc=()=>"/api/v1/farcaster/init",bc=()=>"/api/v1/farcaster/authenticate",Ec=()=>"/api/v1/farcaster/link",Tc=()=>"/api/v1/farcaster/status",Pc=()=>"/api/v1/passwordless/init",xc=()=>"/api/v1/passwordless/authenticate",Sc=()=>"/api/v1/passwordless/link",_c=()=>"/api/v1/passwordless_sms/init",Ac=()=>"/api/v1/passwordless_sms/authenticate",kc=()=>"/api/v1/passwordless_sms/link",Rc=()=>"/api/v1/oauth/init",Ic=()=>"/api/v1/oauth/authenticate",Wc=()=>"/api/v1/oauth/link",Mc=()=>"/api/v1/siwe/unlink",Nc=()=>"/api/v1/passwordless/unlink",Lc=()=>"/api/v1/passwordless_sms/unlink",Oc=()=>"/api/v1/oauth/unlink",Dc=()=>"/api/v1/farcaster/unlink",Uc=()=>"/api/v1/analytics_events",Fc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Bc=()=>"/api/v1/custom_jwt_account/authenticate",Hc=()=>"/api/v1/mfa/passwordless_sms/init";var Gc=()=>"/api/v1/mfa/passwordless_sms/enroll";var Vc=()=>"/api/v1/users/me/accept_terms";var kr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=Bc(),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 ie(t)}}async link(){throw new Error("Unimplemented")}};var tr=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=xc(),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 ie(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=Sc();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw ie(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=Pc();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw ie(r)}}};import{isMobile as Ih}from"react-device-detect";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 Pn=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(bc(),{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 ie(t)}}async link(){if(!this.api)throw new v("Auth flow has no API instance");try{return await this.api.post(Ec(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw ie(t)}}async _startChannelOnce(){if(!this.api)throw new v("Auth flow has no API instance");let t=await this.api.post(Cc(),{token:this.captchaToken});Ih&&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(Tc(),{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 nd}from"jose";var zc="1.57.0-beta-20240222192530";var Ei="4df5e2316331463a9130964bd6078dfa",$c="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",qc="34357d3c125c2bcf2ce2bc3309d98715",Ti="https://auth.privy.io",jc=2e4,$e=1400,Kc=2500,vs=zc;var or="privy:token",ws="privy-token",Pi="privy:refresh_token",Cs="privy-refresh-token",xi="privy-session",xn="privy:session_transfer_token",Mh="privy:wallet",Sn="privy:caid",Rr="privy:state_code",Ir="privy:code_verifier",Si=e=>`${Mh}:${e}`,bs="privy:connectors",Es="privy:connections";var rr=12e4,ho=1,Ts="0x1",Wr=3e4,Yc="https://api.moonpay.com/v1",Jc="https://api.moonpay.com/v1",Qc="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Zc="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Xc="0x420000000000000000000000000000000000000F",ed=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function td(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function od(e){return crypto.getRandomValues(new Uint8Array(e))}var _i=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)}},xs=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 rd(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Nh(){return typeof window<"u"&&window.localStorage?new Ps:new _i}function Lh(){return typeof window<"u"&&window.sessionStorage?new xs:new _i}var It=Lh(),oe=Nh();var Oh="S256",Dh="S256",Ro=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=It.get(Ir);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 It.del(Ir),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=ie(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=It.get(Ir);if(!t)throw new v("Authentication error.");try{let o=Wc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return It.del(Ir),r}catch(o){throw ie(o)}}createCodeVerifier(){return nd.encode(od(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Oh){if(o==Dh){let r=await td(t);return nd.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();It.put(Ir,t);let o=this.createStateCode();It.put(Rr,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=Rc();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 ie(n)}}};var nr=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 ys=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var fc=(e,t,o)=>(ys(e,t,"read from private field"),o?o.call(e):t.get(e)),yi=(e,t,o)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,o)},gs=(e,t,o,r)=>(ys(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var hc=(e,t,o)=>(ys(e,t,"access private method"),o);import{getAddress as fs}from"@ethersproject/address";import{StaticJsonRpcProvider as ZE,Web3Provider as sc}from"@ethersproject/providers";import{createStore as XE}from"mipd";import{useCallback as e2,useEffect as uo,useMemo as t2,useRef as fi,useState as Te}from"react";import{FetchError as Rh}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}]`:""}`}},$t=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"}},gi=class extends v{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var q=class extends De{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},ie=e=>{if(e instanceof De)return e;if(!(e instanceof Rh))return Ve(e);if(!e.response)return new $t("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new $t(t||"ApiError",e.response.status,o||r,e,n)},Ve=e=>e instanceof De?e:e instanceof Error?new v(e.message,e):new v(`Internal error: ${e}`);var Ar=class extends v{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},lt=class extends v{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},vi=class extends v{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var wi=()=>"/api/v1/sessions",Ci=()=>"/api/v1/sessions/logout",yc=()=>"/api/v1/sessions/fork",bi=()=>"/api/v1/sessions/fork/recover",gc=()=>"/api/v1/siwe/init",vc=()=>"/api/v1/siwe/authenticate",wc=()=>"/api/v1/siwe/link",Cc=()=>"/api/v1/farcaster/init",bc=()=>"/api/v1/farcaster/authenticate",Ec=()=>"/api/v1/farcaster/link",Tc=()=>"/api/v1/farcaster/status",Pc=()=>"/api/v1/passwordless/init",xc=()=>"/api/v1/passwordless/authenticate",Sc=()=>"/api/v1/passwordless/link",_c=()=>"/api/v1/passwordless_sms/init",Ac=()=>"/api/v1/passwordless_sms/authenticate",kc=()=>"/api/v1/passwordless_sms/link",Rc=()=>"/api/v1/oauth/init",Ic=()=>"/api/v1/oauth/authenticate",Wc=()=>"/api/v1/oauth/link",Mc=()=>"/api/v1/siwe/unlink",Nc=()=>"/api/v1/passwordless/unlink",Lc=()=>"/api/v1/passwordless_sms/unlink",Oc=()=>"/api/v1/oauth/unlink",Dc=()=>"/api/v1/farcaster/unlink",Uc=()=>"/api/v1/analytics_events",Fc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Bc=()=>"/api/v1/custom_jwt_account/authenticate",Hc=()=>"/api/v1/mfa/passwordless_sms/init";var Gc=()=>"/api/v1/mfa/passwordless_sms/enroll";var Vc=()=>"/api/v1/users/me/accept_terms";var kr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new v("Auth flow has no API instance");try{let t=Bc(),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 ie(t)}}async link(){throw new Error("Unimplemented")}};var tr=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=xc(),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 ie(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=Sc();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw ie(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=Pc();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw ie(r)}}};import{isMobile as Ih}from"react-device-detect";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 Pn=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(bc(),{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 ie(t)}}async link(){if(!this.api)throw new v("Auth flow has no API instance");try{return await this.api.post(Ec(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw ie(t)}}async _startChannelOnce(){if(!this.api)throw new v("Auth flow has no API instance");let t=await this.api.post(Cc(),{token:this.captchaToken});Ih&&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(Tc(),{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 nd}from"jose";var zc="1.57.0-beta-20240222215500";var Ei="4df5e2316331463a9130964bd6078dfa",$c="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",qc="34357d3c125c2bcf2ce2bc3309d98715",Ti="https://auth.privy.io",jc=2e4,$e=1400,Kc=2500,vs=zc;var or="privy:token",ws="privy-token",Pi="privy:refresh_token",Cs="privy-refresh-token",xi="privy-session",xn="privy:session_transfer_token",Mh="privy:wallet",Sn="privy:caid",Rr="privy:state_code",Ir="privy:code_verifier",Si=e=>`${Mh}:${e}`,bs="privy:connectors",Es="privy:connections";var rr=12e4,ho=1,Ts="0x1",Wr=3e4,Yc="https://api.moonpay.com/v1",Jc="https://api.moonpay.com/v1",Qc="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Zc="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Xc="0x420000000000000000000000000000000000000F",ed=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function td(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function od(e){return crypto.getRandomValues(new Uint8Array(e))}var _i=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)}},xs=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 rd(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Nh(){return typeof window<"u"&&window.localStorage?new Ps:new _i}function Lh(){return typeof window<"u"&&window.sessionStorage?new xs:new _i}var It=Lh(),oe=Nh();var Oh="S256",Dh="S256",Ro=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=It.get(Ir);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 It.del(Ir),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=ie(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=It.get(Ir);if(!t)throw new v("Authentication error.");try{let o=Wc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return It.del(Ir),r}catch(o){throw ie(o)}}createCodeVerifier(){return nd.encode(od(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Oh){if(o==Dh){let r=await td(t);return nd.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();It.put(Ir,t);let o=this.createStateCode();It.put(Rr,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=Rc();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 ie(n)}}};var nr=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 mg=Object.create;var Zi=Object.defineProperty;var fg=Object.getOwnPropertyDescriptor;var hg=Object.getOwnPropertyNames;var yg=Object.getPrototypeOf,gg=Object.prototype.hasOwnProperty;var vg=(e,t)=>{for(var o in t)Zi(e,o,{get:t[o],enumerable:!0})},Vc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of hg(t))!gg.call(e,n)&&n!==o&&Zi(e,n,{get:()=>t[n],enumerable:!(r=fg(t,n))||r.enumerable});return e};var f=(e,t,o)=>(o=e!=null?mg(yg(e)):{},Vc(t||!e||!e.__esModule?Zi(o,"default",{value:e,enumerable:!0}):o,e)),wg=e=>Vc(Zi({},"__esModule",{value:!0}),e);var nl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var zc=(e,t,o)=>(nl(e,t,"read from private field"),o?o.call(e):t.get(e)),Xi=(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)},il=(e,t,o,r)=>(nl(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var $c=(e,t,o)=>(nl(e,t,"access private method"),o);var OC={};vg(OC,{AsExternalProvider:()=>lo,Captcha:()=>Ia,ConnectorManager:()=>Rn,PrivyClient:()=>In,PrivyProvider:()=>zy,PrivyProxyProvider:()=>Se,SUPPORTED_CHAINS:()=>mi,VERSION:()=>sa,WalletConnector:()=>ut,addRpcUrlOverrideToChain:()=>sg,errorIndicatesMaxMfaRetries:()=>ts,errorIndicatesMfaTimeout:()=>Kr,errorIndicatesMfaVerificationFailed:()=>Yr,getAccessToken:()=>je,useConnectWallet:()=>Zy,useCreateWallet:()=>eg,useLogin:()=>qy,useLoginWithEmail:()=>Yy,useLoginWithSms:()=>Jy,useLogout:()=>Ky,useMfa:()=>an,useMfaEnrollment:()=>ni,useModalStatus:()=>ng,usePrivy:()=>B,useRegisterMfaListener:()=>La,useSetWalletPassword:()=>og,useToken:()=>ag,useWallets:()=>di});module.exports=wg(OC);var Ji=require("@ethersproject/address"),fi=require("@ethersproject/providers"),Fy=require("mipd"),q=require("react");var qc=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}]`:""}`}},Po=class extends rt{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},w=class extends rt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},ea=class extends w{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var Y=class extends rt{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},fe=e=>{if(e instanceof rt)return e;if(!(e instanceof qc.FetchError))return ct(e);if(!e.response)return new Po("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new Po(t||"ApiError",e.response.status,o||r,e,n)},ct=e=>e instanceof rt?e:e instanceof Error?new w(e.message,e):new w(`Internal error: ${e}`);var fn=class extends w{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},It=class extends w{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},ta=class extends w{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var oa=()=>"/api/v1/sessions",ra=()=>"/api/v1/sessions/logout",jc=()=>"/api/v1/sessions/fork",na=()=>"/api/v1/sessions/fork/recover",Kc=()=>"/api/v1/siwe/init",Yc=()=>"/api/v1/siwe/authenticate",Jc=()=>"/api/v1/siwe/link",Qc=()=>"/api/v1/farcaster/init",Zc=()=>"/api/v1/farcaster/authenticate",Xc=()=>"/api/v1/farcaster/link",ed=()=>"/api/v1/farcaster/status",td=()=>"/api/v1/passwordless/init",od=()=>"/api/v1/passwordless/authenticate",rd=()=>"/api/v1/passwordless/link",nd=()=>"/api/v1/passwordless_sms/init",id=()=>"/api/v1/passwordless_sms/authenticate",ad=()=>"/api/v1/passwordless_sms/link",sd=()=>"/api/v1/oauth/init",ld=()=>"/api/v1/oauth/authenticate",cd=()=>"/api/v1/oauth/link",dd=()=>"/api/v1/siwe/unlink",pd=()=>"/api/v1/passwordless/unlink",ud=()=>"/api/v1/passwordless_sms/unlink",md=()=>"/api/v1/oauth/unlink",fd=()=>"/api/v1/farcaster/unlink",hd=()=>"/api/v1/analytics_events",yd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",gd=()=>"/api/v1/custom_jwt_account/authenticate",vd=()=>"/api/v1/mfa/passwordless_sms/init";var wd=()=>"/api/v1/mfa/passwordless_sms/enroll";var Cd=()=>"/api/v1/users/me/accept_terms";var hn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");try{let t=gd(),o=await this.api.post(t,{token:this.meta.token});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw fe(t)}}async link(){throw new Error("Unimplemented")}};var Fr=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new w("Email and email code must be set prior to calling authenticate.");try{let t=od(),o=await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw fe(t)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new w("Email and email code must be set prior to calling authenticate.");try{let t=rd();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw fe(t)}}async sendCodeEmail(t,o){if(!this.api)throw new w("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new w("Email must be set when initialzing authentication.");try{let r=td();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw fe(r)}}};var bd=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 vi=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new dt(this._startChannelOnce.bind(this)),this.pollForReady=new dt(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.channelToken)throw new w("Auth flow must be initialized first");try{let t=await this.api.post(Zc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new w("No response from authentication");return{user:t.user,token:t.token,refresh_token:t.refresh_token,is_new_user:t.is_new_user}}catch(t){throw fe(t)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");try{return await this.api.post(Xc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw fe(t)}}async _startChannelOnce(){if(!this.api)throw new w("Auth flow has no API instance");let t=await this.api.post(Qc(),{token:this.captchaToken});bd.isMobile&&t.connect_uri&&window.open(t.connect_uri,"_blank","noopener noreferrer"),this._meta={connectUri:t.connect_uri,channelToken:t.channel_token}}async initializeFarcasterConnect(){if(!this.api)throw new w("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.channelToken)throw new w("Auth flow must be initialized first");let t=await this.api.get(ed(),{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 ml=require("jose");var Ed="1.57.0-beta-20240222192530";var ia="4df5e2316331463a9130964bd6078dfa",Td="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Pd="34357d3c125c2bcf2ce2bc3309d98715",aa="https://auth.privy.io",xd=2e4,pt=1400,Sd=2500,sa=Ed;var Br="privy:token",al="privy-token",la="privy:refresh_token",sl="privy-refresh-token",ca="privy-session",wi="privy:session_transfer_token",bg="privy:wallet",Ci="privy:caid",yn="privy:state_code",gn="privy:code_verifier",da=e=>`${bg}:${e}`,ll="privy:connectors",cl="privy:connections";var Hr=12e4,Yo=1,dl="0x1",vn=3e4,_d="https://api.moonpay.com/v1",Ad="https://api.moonpay.com/v1",kd="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Rd="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Id="0x420000000000000000000000000000000000000F",Wd=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Md(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Nd(e){return crypto.getRandomValues(new Uint8Array(e))}var pa=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)}},ul=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 Ld(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Eg(){return typeof window<"u"&&window.localStorage?new pl:new pa}function Tg(){return typeof window<"u"&&window.sessionStorage?new ul:new pa}var no=Tg(),le=Eg();var Pg="S256",xg="S256",fr=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new w("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new w("User denied confirmation during OAuth flow");let t=no.get(gn);if(!t)throw new w("Authentication error.");try{let o=ld(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return no.del(gn),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=fe(o);throw r.privyErrorCode?new w(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new w("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new w("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new w("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new w("User denied confirmation during OAuth flow");let t=no.get(gn);if(!t)throw new w("Authentication error.");try{let o=cd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return no.del(gn),r}catch(o){throw fe(o)}}createCodeVerifier(){return ml.base64url.encode(Nd(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Pg){if(o==xg){let r=await Md(t);return ml.base64url.encode(r)}else return t}async getAuthorizationUrl(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.provider)throw new w("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();no.put(gn,t);let o=this.createStateCode();no.put(yn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=sd();return await this.api.post(n,{provider:this.meta.provider,redirect_to:window.location.href,token:this.meta.captchaToken,code_challenge:r,state_code:o})}catch(n){throw fe(n)}}};var 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 mg=Object.create;var Zi=Object.defineProperty;var fg=Object.getOwnPropertyDescriptor;var hg=Object.getOwnPropertyNames;var yg=Object.getPrototypeOf,gg=Object.prototype.hasOwnProperty;var vg=(e,t)=>{for(var o in t)Zi(e,o,{get:t[o],enumerable:!0})},Vc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of hg(t))!gg.call(e,n)&&n!==o&&Zi(e,n,{get:()=>t[n],enumerable:!(r=fg(t,n))||r.enumerable});return e};var f=(e,t,o)=>(o=e!=null?mg(yg(e)):{},Vc(t||!e||!e.__esModule?Zi(o,"default",{value:e,enumerable:!0}):o,e)),wg=e=>Vc(Zi({},"__esModule",{value:!0}),e);var nl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var zc=(e,t,o)=>(nl(e,t,"read from private field"),o?o.call(e):t.get(e)),Xi=(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)},il=(e,t,o,r)=>(nl(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var $c=(e,t,o)=>(nl(e,t,"access private method"),o);var OC={};vg(OC,{AsExternalProvider:()=>lo,Captcha:()=>Ia,ConnectorManager:()=>Rn,PrivyClient:()=>In,PrivyProvider:()=>zy,PrivyProxyProvider:()=>Se,SUPPORTED_CHAINS:()=>mi,VERSION:()=>sa,WalletConnector:()=>ut,addRpcUrlOverrideToChain:()=>sg,errorIndicatesMaxMfaRetries:()=>ts,errorIndicatesMfaTimeout:()=>Kr,errorIndicatesMfaVerificationFailed:()=>Yr,getAccessToken:()=>je,useConnectWallet:()=>Zy,useCreateWallet:()=>eg,useLogin:()=>qy,useLoginWithEmail:()=>Yy,useLoginWithSms:()=>Jy,useLogout:()=>Ky,useMfa:()=>an,useMfaEnrollment:()=>ni,useModalStatus:()=>ng,usePrivy:()=>B,useRegisterMfaListener:()=>La,useSetWalletPassword:()=>og,useToken:()=>ag,useWallets:()=>di});module.exports=wg(OC);var Ji=require("@ethersproject/address"),fi=require("@ethersproject/providers"),Fy=require("mipd"),q=require("react");var qc=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}]`:""}`}},Po=class extends rt{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},w=class extends rt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},ea=class extends w{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var Y=class extends rt{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},fe=e=>{if(e instanceof rt)return e;if(!(e instanceof qc.FetchError))return ct(e);if(!e.response)return new Po("api_error",null,e.message,e);let{type:t,message:o,error:r,code:n}=e.data;return new Po(t||"ApiError",e.response.status,o||r,e,n)},ct=e=>e instanceof rt?e:e instanceof Error?new w(e.message,e):new w(`Internal error: ${e}`);var fn=class extends w{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},It=class extends w{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},ta=class extends w{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var oa=()=>"/api/v1/sessions",ra=()=>"/api/v1/sessions/logout",jc=()=>"/api/v1/sessions/fork",na=()=>"/api/v1/sessions/fork/recover",Kc=()=>"/api/v1/siwe/init",Yc=()=>"/api/v1/siwe/authenticate",Jc=()=>"/api/v1/siwe/link",Qc=()=>"/api/v1/farcaster/init",Zc=()=>"/api/v1/farcaster/authenticate",Xc=()=>"/api/v1/farcaster/link",ed=()=>"/api/v1/farcaster/status",td=()=>"/api/v1/passwordless/init",od=()=>"/api/v1/passwordless/authenticate",rd=()=>"/api/v1/passwordless/link",nd=()=>"/api/v1/passwordless_sms/init",id=()=>"/api/v1/passwordless_sms/authenticate",ad=()=>"/api/v1/passwordless_sms/link",sd=()=>"/api/v1/oauth/init",ld=()=>"/api/v1/oauth/authenticate",cd=()=>"/api/v1/oauth/link",dd=()=>"/api/v1/siwe/unlink",pd=()=>"/api/v1/passwordless/unlink",ud=()=>"/api/v1/passwordless_sms/unlink",md=()=>"/api/v1/oauth/unlink",fd=()=>"/api/v1/farcaster/unlink",hd=()=>"/api/v1/analytics_events",yd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",gd=()=>"/api/v1/custom_jwt_account/authenticate",vd=()=>"/api/v1/mfa/passwordless_sms/init";var wd=()=>"/api/v1/mfa/passwordless_sms/enroll";var Cd=()=>"/api/v1/users/me/accept_terms";var hn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");try{let t=gd(),o=await this.api.post(t,{token:this.meta.token});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw fe(t)}}async link(){throw new Error("Unimplemented")}};var Fr=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new w("Email and email code must be set prior to calling authenticate.");try{let t=od(),o=await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode});return{user:o.user,token:o.token,refresh_token:o.refresh_token,is_new_user:o.is_new_user}}catch(t){throw fe(t)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new w("Email and email code must be set prior to calling authenticate.");try{let t=rd();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw fe(t)}}async sendCodeEmail(t,o){if(!this.api)throw new w("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new w("Email must be set when initialzing authentication.");try{let r=td();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw fe(r)}}};var bd=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 vi=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new dt(this._startChannelOnce.bind(this)),this.pollForReady=new dt(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.channelToken)throw new w("Auth flow must be initialized first");try{let t=await this.api.post(Zc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new w("No response from authentication");return{user:t.user,token:t.token,refresh_token:t.refresh_token,is_new_user:t.is_new_user}}catch(t){throw fe(t)}}async link(){if(!this.api)throw new w("Auth flow has no API instance");try{return await this.api.post(Xc(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw fe(t)}}async _startChannelOnce(){if(!this.api)throw new w("Auth flow has no API instance");let t=await this.api.post(Qc(),{token:this.captchaToken});bd.isMobile&&t.connect_uri&&window.open(t.connect_uri,"_blank","noopener noreferrer"),this._meta={connectUri:t.connect_uri,channelToken:t.channel_token}}async initializeFarcasterConnect(){if(!this.api)throw new w("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.channelToken)throw new w("Auth flow must be initialized first");let t=await this.api.get(ed(),{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 ml=require("jose");var Ed="1.57.0-beta-20240222215500";var ia="4df5e2316331463a9130964bd6078dfa",Td="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Pd="34357d3c125c2bcf2ce2bc3309d98715",aa="https://auth.privy.io",xd=2e4,pt=1400,Sd=2500,sa=Ed;var Br="privy:token",al="privy-token",la="privy:refresh_token",sl="privy-refresh-token",ca="privy-session",wi="privy:session_transfer_token",bg="privy:wallet",Ci="privy:caid",yn="privy:state_code",gn="privy:code_verifier",da=e=>`${bg}:${e}`,ll="privy:connectors",cl="privy:connections";var Hr=12e4,Yo=1,dl="0x1",vn=3e4,_d="https://api.moonpay.com/v1",Ad="https://api.moonpay.com/v1",kd="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Rd="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Id="0x420000000000000000000000000000000000000F",Wd=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Md(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Nd(e){return crypto.getRandomValues(new Uint8Array(e))}var pa=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)}},ul=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 Ld(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Eg(){return typeof window<"u"&&window.localStorage?new pl:new pa}function Tg(){return typeof window<"u"&&window.sessionStorage?new ul:new pa}var no=Tg(),le=Eg();var Pg="S256",xg="S256",fr=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new w("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new w("User denied confirmation during OAuth flow");let t=no.get(gn);if(!t)throw new w("Authentication error.");try{let o=ld(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return no.del(gn),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=fe(o);throw r.privyErrorCode?new w(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new w("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new w("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new w("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new w("User denied confirmation during OAuth flow");let t=no.get(gn);if(!t)throw new w("Authentication error.");try{let o=cd(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return no.del(gn),r}catch(o){throw fe(o)}}createCodeVerifier(){return ml.base64url.encode(Nd(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Pg){if(o==xg){let r=await Md(t);return ml.base64url.encode(r)}else return t}async getAuthorizationUrl(){if(!this.api)throw new w("Auth flow has no API instance");if(!this.meta.provider)throw new w("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();no.put(gn,t);let o=this.createStateCode();no.put(yn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=sd();return await this.api.post(n,{provider:this.meta.provider,redirect_to:window.location.href,token:this.meta.captchaToken,code_challenge:r,state_code:o})}catch(n){throw fe(n)}}};var 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