@privy-io/react-auth 1.57.2-beta-20240228011320 → 1.57.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +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 vs=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var gc=(e,t,o)=>(vs(e,t,"read from private field"),o?o.call(e):t.get(e)),vi=(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)},ws=(e,t,o,r)=>(vs(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var vc=(e,t,o)=>(vs(e,t,"access private method"),o);import{getAddress as ys}from"@ethersproject/address";import{StaticJsonRpcProvider as l2,Web3Provider as uc}from"@ethersproject/providers";import{createStore as c2}from"mipd";import{useCallback as d2,useEffect as _o,useMemo as p2,useRef as hi,useState as xe}from"react";import{FetchError as Oh}from"ofetch";var Le=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 Le{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},w=class extends Le{constructor(o,r,n){super(o,r,n);this.type="client_error"}},wi=class extends w{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var j=class extends Le{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},ae=e=>{if(e instanceof Le)return e;if(!(e instanceof Oh))return $e(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)},$e=e=>e instanceof Le?e:e instanceof Error?new w(e.message,e):new w(`Internal error: ${e}`);var kr=class extends w{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},st=class extends w{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},Ci=class extends w{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var bi=()=>"/api/v1/sessions",Ei=()=>"/api/v1/sessions/logout",wc=()=>"/api/v1/sessions/fork",Ti=()=>"/api/v1/sessions/fork/recover",Cc=()=>"/api/v1/siwe/init",bc=()=>"/api/v1/siwe/authenticate",Ec=()=>"/api/v1/siwe/link",Tc=()=>"/api/v1/farcaster/init",Pc=()=>"/api/v1/farcaster/authenticate",xc=()=>"/api/v1/farcaster/link",Sc=()=>"/api/v1/farcaster/status",_c=()=>"/api/v1/passwordless/init",Ac=()=>"/api/v1/passwordless/authenticate",kc=()=>"/api/v1/passwordless/link",Rc=()=>"/api/v1/passwordless_sms/init",Ic=()=>"/api/v1/passwordless_sms/authenticate",Wc=()=>"/api/v1/passwordless_sms/link",Mc=()=>"/api/v1/oauth/init",Nc=()=>"/api/v1/oauth/authenticate",Lc=()=>"/api/v1/oauth/link",Oc=()=>"/api/v1/siwe/unlink",Dc=()=>"/api/v1/passwordless/unlink",Uc=()=>"/api/v1/passwordless_sms/unlink",Fc=()=>"/api/v1/oauth/unlink",Bc=()=>"/api/v1/farcaster/unlink",Hc=()=>"/api/v1/analytics_events",Gc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Vc=()=>"/api/v1/custom_jwt_account/authenticate",zc=()=>"/api/v1/mfa/passwordless_sms/init";var $c=()=>"/api/v1/mfa/passwordless_sms/enroll";var qc=()=>"/api/v1/users/me/accept_terms";var Rr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");try{let t=Vc(),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 ae(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 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=Ac(),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 ae(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=kc();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw ae(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=_c();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw ae(r)}}};import{isMobile as Dh}from"react-device-detect";var qe=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 xn=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new qe(this._startChannelOnce.bind(this)),this.pollForReady=new qe(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(Pc(),{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 ae(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 ae(t)}}async _startChannelOnce(){if(!this.api)throw new w("Auth flow has no API instance");let t=await this.api.post(Tc(),{token:this.captchaToken});Dh&&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(Sc(),{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 sd}from"jose";var jc="1.57.2-beta-20240228011320";var Pi="4df5e2316331463a9130964bd6078dfa",Kc="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Yc="34357d3c125c2bcf2ce2bc3309d98715",xi="https://auth.privy.io",Jc=2e4,je=1400,Qc=2500,Cs=jc;var or="privy:token",bs="privy-token",Si="privy:refresh_token",Es="privy-refresh-token",_i="privy-session",Sn="privy:session_transfer_token",Fh="privy:wallet",_n="privy:caid",Ir="privy:state_code",Wr="privy:code_verifier",Ai=e=>`${Fh}:${e}`,Ts="privy:connectors",Ps="privy:connections";var rr=12e4,yo=1,xs="0x1",Mr=3e4,Zc="https://api.moonpay.com/v1",Xc="https://api.moonpay.com/v1",ed="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",td="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",od="0x420000000000000000000000000000000000000F",rd=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function nd(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function id(e){return crypto.getRandomValues(new Uint8Array(e))}var ki=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)}},Ss=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)}},_s=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 ad(){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 Ss:new ki}function Hh(){return typeof window<"u"&&window.sessionStorage?new _s:new ki}var Wt=Hh(),re=Bh();var Gh="S256",Vh="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 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=Wt.get(Wr);if(!t)throw new w("Authentication error.");try{let o=Nc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Wt.del(Wr),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=ae(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=Wt.get(Wr);if(!t)throw new w("Authentication error.");try{let o=Lc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Wt.del(Wr),r}catch(o){throw ae(o)}}createCodeVerifier(){return sd.encode(id(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Gh){if(o==Vh){let r=await nd(t);return sd.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();Wt.put(Wr,t);let o=this.createStateCode();Wt.put(Ir,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=Mc();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 ae(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 vs=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var gc=(e,t,o)=>(vs(e,t,"read from private field"),o?o.call(e):t.get(e)),vi=(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)},ws=(e,t,o,r)=>(vs(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var vc=(e,t,o)=>(vs(e,t,"access private method"),o);import{getAddress as ys}from"@ethersproject/address";import{StaticJsonRpcProvider as l2,Web3Provider as uc}from"@ethersproject/providers";import{createStore as c2}from"mipd";import{useCallback as d2,useEffect as _o,useMemo as p2,useRef as hi,useState as xe}from"react";import{FetchError as Oh}from"ofetch";var Le=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 Le{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},w=class extends Le{constructor(o,r,n){super(o,r,n);this.type="client_error"}},wi=class extends w{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var j=class extends Le{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},ae=e=>{if(e instanceof Le)return e;if(!(e instanceof Oh))return $e(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)},$e=e=>e instanceof Le?e:e instanceof Error?new w(e.message,e):new w(`Internal error: ${e}`);var kr=class extends w{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},st=class extends w{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},Ci=class extends w{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var bi=()=>"/api/v1/sessions",Ei=()=>"/api/v1/sessions/logout",wc=()=>"/api/v1/sessions/fork",Ti=()=>"/api/v1/sessions/fork/recover",Cc=()=>"/api/v1/siwe/init",bc=()=>"/api/v1/siwe/authenticate",Ec=()=>"/api/v1/siwe/link",Tc=()=>"/api/v1/farcaster/init",Pc=()=>"/api/v1/farcaster/authenticate",xc=()=>"/api/v1/farcaster/link",Sc=()=>"/api/v1/farcaster/status",_c=()=>"/api/v1/passwordless/init",Ac=()=>"/api/v1/passwordless/authenticate",kc=()=>"/api/v1/passwordless/link",Rc=()=>"/api/v1/passwordless_sms/init",Ic=()=>"/api/v1/passwordless_sms/authenticate",Wc=()=>"/api/v1/passwordless_sms/link",Mc=()=>"/api/v1/oauth/init",Nc=()=>"/api/v1/oauth/authenticate",Lc=()=>"/api/v1/oauth/link",Oc=()=>"/api/v1/siwe/unlink",Dc=()=>"/api/v1/passwordless/unlink",Uc=()=>"/api/v1/passwordless_sms/unlink",Fc=()=>"/api/v1/oauth/unlink",Bc=()=>"/api/v1/farcaster/unlink",Hc=()=>"/api/v1/analytics_events",Gc=()=>"/api/v1/plugins/moonpay_on_ramp/sign",Vc=()=>"/api/v1/custom_jwt_account/authenticate",zc=()=>"/api/v1/mfa/passwordless_sms/init";var $c=()=>"/api/v1/mfa/passwordless_sms/enroll";var qc=()=>"/api/v1/users/me/accept_terms";var Rr=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new w("Auth flow has no API instance");try{let t=Vc(),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 ae(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 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=Ac(),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 ae(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=kc();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw ae(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=_c();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw ae(r)}}};import{isMobile as Dh}from"react-device-detect";var qe=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 xn=class{constructor(t){this._meta={};this.captchaToken=t,this.startChannelOnce=new qe(this._startChannelOnce.bind(this)),this.pollForReady=new qe(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(Pc(),{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 ae(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 ae(t)}}async _startChannelOnce(){if(!this.api)throw new w("Auth flow has no API instance");let t=await this.api.post(Tc(),{token:this.captchaToken});Dh&&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(Sc(),{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 sd}from"jose";var jc="1.57.2";var Pi="4df5e2316331463a9130964bd6078dfa",Kc="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Yc="34357d3c125c2bcf2ce2bc3309d98715",xi="https://auth.privy.io",Jc=2e4,je=1400,Qc=2500,Cs=jc;var or="privy:token",bs="privy-token",Si="privy:refresh_token",Es="privy-refresh-token",_i="privy-session",Sn="privy:session_transfer_token",Fh="privy:wallet",_n="privy:caid",Ir="privy:state_code",Wr="privy:code_verifier",Ai=e=>`${Fh}:${e}`,Ts="privy:connectors",Ps="privy:connections";var rr=12e4,yo=1,xs="0x1",Mr=3e4,Zc="https://api.moonpay.com/v1",Xc="https://api.moonpay.com/v1",ed="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",td="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",od="0x420000000000000000000000000000000000000F",rd=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function nd(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function id(e){return crypto.getRandomValues(new Uint8Array(e))}var ki=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)}},Ss=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)}},_s=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 ad(){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 Ss:new ki}function Hh(){return typeof window<"u"&&window.sessionStorage?new _s:new ki}var Wt=Hh(),re=Bh();var Gh="S256",Vh="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 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=Wt.get(Wr);if(!t)throw new w("Authentication error.");try{let o=Nc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Wt.del(Wr),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=ae(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=Wt.get(Wr);if(!t)throw new w("Authentication error.");try{let o=Lc(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return Wt.del(Wr),r}catch(o){throw ae(o)}}createCodeVerifier(){return sd.encode(id(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Gh){if(o==Vh){let r=await nd(t);return sd.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();Wt.put(Wr,t);let o=this.createStateCode();Wt.put(Ir,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=Mc();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 ae(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 Sg=Object.create;var ta=Object.defineProperty;var _g=Object.getOwnPropertyDescriptor;var Ag=Object.getOwnPropertyNames;var kg=Object.getPrototypeOf,Rg=Object.prototype.hasOwnProperty;var Ig=(e,t)=>{for(var o in t)ta(e,o,{get:t[o],enumerable:!0})},jc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ag(t))!Rg.call(e,n)&&n!==o&&ta(e,n,{get:()=>t[n],enumerable:!(r=_g(t,n))||r.enumerable});return e};var f=(e,t,o)=>(o=e!=null?Sg(kg(e)):{},jc(t||!e||!e.__esModule?ta(o,"default",{value:e,enumerable:!0}):o,e)),Wg=e=>jc(ta({},"__esModule",{value:!0}),e);var sl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Kc=(e,t,o)=>(sl(e,t,"read from private field"),o?o.call(e):t.get(e)),oa=(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)},ll=(e,t,o,r)=>(sl(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var Yc=(e,t,o)=>(sl(e,t,"access private method"),o);var YC={};Ig(YC,{AsExternalProvider:()=>co,Captcha:()=>Ka,ConnectorManager:()=>Mn,PrivyClient:()=>Nn,PrivyProvider:()=>Xy,PrivyProxyProvider:()=>xe,SUPPORTED_CHAINS:()=>Rn,VERSION:()=>da,WalletConnector:()=>ft,addRpcUrlOverrideToChain:()=>Eg,errorIndicatesMaxMfaRetries:()=>vs,errorIndicatesMfaTimeout:()=>Yr,errorIndicatesMfaVerificationFailed:()=>Jr,getAccessToken:()=>qe,useConnectWallet:()=>sg,useCreateWallet:()=>cg,useLogin:()=>tg,useLoginWithEmail:()=>ng,useLoginWithSms:()=>ig,useLogout:()=>rg,useMfa:()=>sn,useMfaEnrollment:()=>si,useModalStatus:()=>wg,usePrivy:()=>V,useRegisterMfaListener:()=>Za,useSendTransaction:()=>pg,useSetWalletPassword:()=>mg,useSignMessage:()=>hg,useSignTypedData:()=>gg,useToken:()=>bg,useWallets:()=>mi});module.exports=Wg(YC);var Zi=require("@ethersproject/address"),gi=require("@ethersproject/providers"),Ky=require("mipd"),K=require("react");var Jc=require("ofetch"),tt=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 tt{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},C=class extends tt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},ra=class extends C{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var J=class extends tt{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},he=e=>{if(e instanceof tt)return e;if(!(e instanceof Jc.FetchError))return pt(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)},pt=e=>e instanceof tt?e:e instanceof Error?new C(e.message,e):new C(`Internal error: ${e}`);var yn=class extends C{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},It=class extends C{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},na=class extends C{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var ia=()=>"/api/v1/sessions",aa=()=>"/api/v1/sessions/logout",Qc=()=>"/api/v1/sessions/fork",sa=()=>"/api/v1/sessions/fork/recover",Zc=()=>"/api/v1/siwe/init",Xc=()=>"/api/v1/siwe/authenticate",ed=()=>"/api/v1/siwe/link",td=()=>"/api/v1/farcaster/init",od=()=>"/api/v1/farcaster/authenticate",rd=()=>"/api/v1/farcaster/link",nd=()=>"/api/v1/farcaster/status",id=()=>"/api/v1/passwordless/init",ad=()=>"/api/v1/passwordless/authenticate",sd=()=>"/api/v1/passwordless/link",ld=()=>"/api/v1/passwordless_sms/init",cd=()=>"/api/v1/passwordless_sms/authenticate",dd=()=>"/api/v1/passwordless_sms/link",pd=()=>"/api/v1/oauth/init",ud=()=>"/api/v1/oauth/authenticate",md=()=>"/api/v1/oauth/link",fd=()=>"/api/v1/siwe/unlink",hd=()=>"/api/v1/passwordless/unlink",yd=()=>"/api/v1/passwordless_sms/unlink",gd=()=>"/api/v1/oauth/unlink",vd=()=>"/api/v1/farcaster/unlink",wd=()=>"/api/v1/analytics_events",Cd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",bd=()=>"/api/v1/custom_jwt_account/authenticate",Ed=()=>"/api/v1/mfa/passwordless_sms/init";var Td=()=>"/api/v1/mfa/passwordless_sms/enroll";var Pd=()=>"/api/v1/users/me/accept_terms";var gn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");try{let t=bd(),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 he(t)}}async link(){throw new Error("Unimplemented")}};var Br=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=ad(),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 he(t)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=sd();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw he(t)}}async sendCodeEmail(t,o){if(!this.api)throw new C("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new C("Email must be set when initialzing authentication.");try{let r=id();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw he(r)}}};var xd=require("react-device-detect");var ut=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 ut(this._startChannelOnce.bind(this)),this.pollForReady=new ut(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.channelToken)throw new C("Auth flow must be initialized first");try{let t=await this.api.post(od(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new C("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 he(t)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");try{return await this.api.post(rd(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw he(t)}}async _startChannelOnce(){if(!this.api)throw new C("Auth flow has no API instance");let t=await this.api.post(td(),{token:this.captchaToken});xd.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 C("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.channelToken)throw new C("Auth flow must be initialized first");let t=await this.api.get(nd(),{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 yl=require("jose");var Sd="1.57.2-beta-20240228011320";var la="4df5e2316331463a9130964bd6078dfa",_d="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Ad="34357d3c125c2bcf2ce2bc3309d98715",ca="https://auth.privy.io",kd=2e4,mt=1400,Rd=2500,da=Sd;var Hr="privy:token",cl="privy-token",pa="privy:refresh_token",dl="privy-refresh-token",ua="privy-session",bi="privy:session_transfer_token",Ng="privy:wallet",Ei="privy:caid",vn="privy:state_code",wn="privy:code_verifier",ma=e=>`${Ng}:${e}`,pl="privy:connectors",ul="privy:connections";var Gr=12e4,Qo=1,ml="0x1",Cn=3e4,Id="https://api.moonpay.com/v1",Wd="https://api.moonpay.com/v1",Md="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Nd="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Ld="0x420000000000000000000000000000000000000F",Od=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Dd(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Ud(e){return crypto.getRandomValues(new Uint8Array(e))}var fa=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)}},fl=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)}},hl=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 Fd(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Lg(){return typeof window<"u"&&window.localStorage?new fl:new fa}function Og(){return typeof window<"u"&&window.sessionStorage?new hl:new fa}var io=Og(),ce=Lg();var Dg="S256",Ug="S256",hr=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=io.get(wn);if(!t)throw new C("Authentication error.");try{let o=ud(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return io.del(wn),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=he(o);throw r.privyErrorCode?new C(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new C("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new C("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=io.get(wn);if(!t)throw new C("Authentication error.");try{let o=md(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return io.del(wn),r}catch(o){throw he(o)}}createCodeVerifier(){return yl.base64url.encode(Ud(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Dg){if(o==Ug){let r=await Dd(t);return yl.base64url.encode(r)}else return t}async getAuthorizationUrl(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.provider)throw new C("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();io.put(wn,t);let o=this.createStateCode();io.put(vn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=pd();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 he(n)}}};var Vr=class{constructor(t,o){this.createSiweMessage=(t,o,r,n,i,a,l)=>`${r} wants you to sign in with your Ethereum account:
|
|
1
|
+
"use strict";var Sg=Object.create;var ta=Object.defineProperty;var _g=Object.getOwnPropertyDescriptor;var Ag=Object.getOwnPropertyNames;var kg=Object.getPrototypeOf,Rg=Object.prototype.hasOwnProperty;var Ig=(e,t)=>{for(var o in t)ta(e,o,{get:t[o],enumerable:!0})},jc=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ag(t))!Rg.call(e,n)&&n!==o&&ta(e,n,{get:()=>t[n],enumerable:!(r=_g(t,n))||r.enumerable});return e};var f=(e,t,o)=>(o=e!=null?Sg(kg(e)):{},jc(t||!e||!e.__esModule?ta(o,"default",{value:e,enumerable:!0}):o,e)),Wg=e=>jc(ta({},"__esModule",{value:!0}),e);var sl=(e,t,o)=>{if(!t.has(e))throw TypeError("Cannot "+o)};var Kc=(e,t,o)=>(sl(e,t,"read from private field"),o?o.call(e):t.get(e)),oa=(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)},ll=(e,t,o,r)=>(sl(e,t,"write to private field"),r?r.call(e,o):t.set(e,o),o);var Yc=(e,t,o)=>(sl(e,t,"access private method"),o);var YC={};Ig(YC,{AsExternalProvider:()=>co,Captcha:()=>Ka,ConnectorManager:()=>Mn,PrivyClient:()=>Nn,PrivyProvider:()=>Xy,PrivyProxyProvider:()=>xe,SUPPORTED_CHAINS:()=>Rn,VERSION:()=>da,WalletConnector:()=>ft,addRpcUrlOverrideToChain:()=>Eg,errorIndicatesMaxMfaRetries:()=>vs,errorIndicatesMfaTimeout:()=>Yr,errorIndicatesMfaVerificationFailed:()=>Jr,getAccessToken:()=>qe,useConnectWallet:()=>sg,useCreateWallet:()=>cg,useLogin:()=>tg,useLoginWithEmail:()=>ng,useLoginWithSms:()=>ig,useLogout:()=>rg,useMfa:()=>sn,useMfaEnrollment:()=>si,useModalStatus:()=>wg,usePrivy:()=>V,useRegisterMfaListener:()=>Za,useSendTransaction:()=>pg,useSetWalletPassword:()=>mg,useSignMessage:()=>hg,useSignTypedData:()=>gg,useToken:()=>bg,useWallets:()=>mi});module.exports=Wg(YC);var Zi=require("@ethersproject/address"),gi=require("@ethersproject/providers"),Ky=require("mipd"),K=require("react");var Jc=require("ofetch"),tt=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 tt{constructor(o,r,n,i,a){super(n,i,a);this.type=o;this.status=r}},C=class extends tt{constructor(o,r,n){super(o,r,n);this.type="client_error"}},ra=class extends C{constructor(){super("Request timed out",void 0,"client_request_timeout")}};var J=class extends tt{constructor(o,r,n){super(o,r,n);this.type="connector_error"}},he=e=>{if(e instanceof tt)return e;if(!(e instanceof Jc.FetchError))return pt(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)},pt=e=>e instanceof tt?e:e instanceof Error?new C(e.message,e):new C(`Internal error: ${e}`);var yn=class extends C{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},It=class extends C{constructor(t="Embedded wallet error",o){super(t,o,"unknown_embedded_wallet_error")}},na=class extends C{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}};var ia=()=>"/api/v1/sessions",aa=()=>"/api/v1/sessions/logout",Qc=()=>"/api/v1/sessions/fork",sa=()=>"/api/v1/sessions/fork/recover",Zc=()=>"/api/v1/siwe/init",Xc=()=>"/api/v1/siwe/authenticate",ed=()=>"/api/v1/siwe/link",td=()=>"/api/v1/farcaster/init",od=()=>"/api/v1/farcaster/authenticate",rd=()=>"/api/v1/farcaster/link",nd=()=>"/api/v1/farcaster/status",id=()=>"/api/v1/passwordless/init",ad=()=>"/api/v1/passwordless/authenticate",sd=()=>"/api/v1/passwordless/link",ld=()=>"/api/v1/passwordless_sms/init",cd=()=>"/api/v1/passwordless_sms/authenticate",dd=()=>"/api/v1/passwordless_sms/link",pd=()=>"/api/v1/oauth/init",ud=()=>"/api/v1/oauth/authenticate",md=()=>"/api/v1/oauth/link",fd=()=>"/api/v1/siwe/unlink",hd=()=>"/api/v1/passwordless/unlink",yd=()=>"/api/v1/passwordless_sms/unlink",gd=()=>"/api/v1/oauth/unlink",vd=()=>"/api/v1/farcaster/unlink",wd=()=>"/api/v1/analytics_events",Cd=()=>"/api/v1/plugins/moonpay_on_ramp/sign",bd=()=>"/api/v1/custom_jwt_account/authenticate",Ed=()=>"/api/v1/mfa/passwordless_sms/init";var Td=()=>"/api/v1/mfa/passwordless_sms/enroll";var Pd=()=>"/api/v1/users/me/accept_terms";var gn=class{constructor(t){this.meta={token:t}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");try{let t=bd(),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 he(t)}}async link(){throw new Error("Unimplemented")}};var Br=class{constructor(t,o){this.meta={email:t,captchaToken:o}}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=ad(),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 he(t)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new C("Email and email code must be set prior to calling authenticate.");try{let t=sd();return await this.api.post(t,{email:this.meta.email,code:this.meta.emailCode})}catch(t){throw he(t)}}async sendCodeEmail(t,o){if(!this.api)throw new C("Auth flow has no API instance");if(t&&(this.meta.email=t),o&&(this.meta.captchaToken=o),!this.meta.email)throw new C("Email must be set when initialzing authentication.");try{let r=id();return await this.api.post(r,{email:this.meta.email,token:this.meta.captchaToken})}catch(r){throw he(r)}}};var xd=require("react-device-detect");var ut=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 ut(this._startChannelOnce.bind(this)),this.pollForReady=new ut(this._pollForReady.bind(this))}get meta(){return this._meta}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.channelToken)throw new C("Auth flow must be initialized first");try{let t=await this.api.post(od(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid});if(!t)throw new C("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 he(t)}}async link(){if(!this.api)throw new C("Auth flow has no API instance");try{return await this.api.post(rd(),{channel_token:this.meta.channelToken,message:this.message,signature:this.signature,fid:this.fid})}catch(t){throw he(t)}}async _startChannelOnce(){if(!this.api)throw new C("Auth flow has no API instance");let t=await this.api.post(td(),{token:this.captchaToken});xd.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 C("Auth flow has no API instance");await this.startChannelOnce.execute()}async _pollForReady(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.channelToken)throw new C("Auth flow must be initialized first");let t=await this.api.get(nd(),{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 yl=require("jose");var Sd="1.57.2";var la="4df5e2316331463a9130964bd6078dfa",_d="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",Ad="34357d3c125c2bcf2ce2bc3309d98715",ca="https://auth.privy.io",kd=2e4,mt=1400,Rd=2500,da=Sd;var Hr="privy:token",cl="privy-token",pa="privy:refresh_token",dl="privy-refresh-token",ua="privy-session",bi="privy:session_transfer_token",Ng="privy:wallet",Ei="privy:caid",vn="privy:state_code",wn="privy:code_verifier",ma=e=>`${Ng}:${e}`,pl="privy:connectors",ul="privy:connections";var Gr=12e4,Qo=1,ml="0x1",Cn=3e4,Id="https://api.moonpay.com/v1",Wd="https://api.moonpay.com/v1",Md="pk_live_hirbpu0cVcLHrjktC9l7fbc9ctjv0SL",Nd="pk_test_fqWjXZMSFwloh7orvJsRfjiUHXJqFzI",Ld="0x420000000000000000000000000000000000000F",Od=["function getL1Fee(bytes memory _data) external view returns (uint256)"];async function Dd(e){let t=new TextEncoder().encode(e),o=await crypto.subtle.digest("SHA-256",t);return new Uint8Array(o)}function Ud(e){return crypto.getRandomValues(new Uint8Array(e))}var fa=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)}},fl=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)}},hl=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 Fd(){try{let e="privy:__session_storage__test",t="blobby";return window.sessionStorage.setItem(e,t),window.sessionStorage.removeItem(e),!0}catch{return!1}}function Lg(){return typeof window<"u"&&window.localStorage?new fl:new fa}function Og(){return typeof window<"u"&&window.sessionStorage?new hl:new fa}var io=Og(),ce=Lg();var Dg="S256",Ug="S256",hr=class{constructor(t,o,r){this.meta={provider:t},this.meta.authorizationCode=o,this.meta.stateCode=r}addCaptchaToken(t){this.meta.captchaToken=t}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=io.get(wn);if(!t)throw new C("Authentication error.");try{let o=ud(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return io.del(wn),{user:r.user,token:r.token,refresh_token:r.refresh_token,is_new_user:r.is_new_user}}catch(o){let r=he(o);throw r.privyErrorCode?new C(r.message||"Invalid code during OAuth flow.",void 0,r.privyErrorCode):r.message==="User denied confirmation during OAuth flow"?new C("Invalid code during oauth flow.",void 0,"oauth_user_denied"):new C("Invalid code during OAuth flow.",void 0,"unknown_auth_error")}}async link(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new C("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new C("User denied confirmation during OAuth flow");let t=io.get(wn);if(!t)throw new C("Authentication error.");try{let o=md(),r=await this.api.post(o,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode,code_verifier:t});return io.del(wn),r}catch(o){throw he(o)}}createCodeVerifier(){return yl.base64url.encode(Ud(36))}createStateCode(){return this.createCodeVerifier()}async deriveCodeChallengeFromCodeVerifier(t,o=Dg){if(o==Ug){let r=await Dd(t);return yl.base64url.encode(r)}else return t}async getAuthorizationUrl(){if(!this.api)throw new C("Auth flow has no API instance");if(!this.meta.provider)throw new C("Provider must be set when initializing OAuth authentication.");let t=this.createCodeVerifier();io.put(wn,t);let o=this.createStateCode();io.put(vn,o);let r=await this.deriveCodeChallengeFromCodeVerifier(t);try{let n=pd();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 he(n)}}};var Vr=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