@privy-io/react-auth 1.8.0-beta.9 → 1.8.0
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/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var a5=Object.create;var t2=Object.defineProperty;var l5=Object.getOwnPropertyDescriptor;var r5=Object.getOwnPropertyNames;var n5=Object.getPrototypeOf,s5=Object.prototype.hasOwnProperty;var C5=(i,e)=>{for(var o in e)t2(i,o,{get:e[o],enumerable:!0})},w4=(i,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of r5(e))!s5.call(i,l)&&l!==o&&t2(i,l,{get:()=>e[l],enumerable:!(a=l5(e,l))||a.enumerable});return i};var g=(i,e,o)=>(o=i!=null?a5(n5(i)):{},w4(e||!i||!i.__esModule?t2(o,"default",{value:i,enumerable:!0}):o,i)),d5=i=>w4(t2({},"__esModule",{value:!0}),i);var _6={};C5(_6,{PrivyProvider:()=>i5,VERSION:()=>o2,usePrivy:()=>x});module.exports=d5(_6);var K=require("react");var a2=g(require("axios"));var y4=g(require("axios")),i1=class extends Error{constructor(o,a){super(o);a instanceof Error&&(this.cause=a)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},e2=class extends i1{constructor(o,a,l,C){super(l,C);this.type=o;this.status=a}},b=class extends i1{constructor(o,a){super(o,a);this.type="client_error"}};var Y=class extends i1{constructor(o,a){super(o,a);this.type="connector_error"}},D=i=>{if(i instanceof i1)return i;if(!y4.default.isAxiosError(i))return J(i);if(!i.response)return new e2("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new e2(e||"ApiError",i.response.status,o||a,i)},J=i=>i instanceof i1?i:i instanceof Error?new b(i.message,i):new b(`Internal error: ${i}`);var v4="1.8.0-beta.9";var Z4="https://api.privy.io/v0",x4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",i2="4df5e2316331463a9130964bd6078dfa",L4=1e4,X=1200,o2=v4;var l2=class{constructor(e,o,a){this.appId=e,this.sdkVersion=o2,this.session=o,this.defaults=a}async get(e,o){try{return await a2.default.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw D(a)}}async post(e,o,a){try{return await a2.default.post(e,o,this.buildConfig(a))}catch(l){throw D(l)}}async delete(e,o){try{return await a2.default.delete(e,this.buildConfig(o))}catch(a){throw D(a)}}buildConfig(e){return e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-client"]=`react-auth:${this.sdkVersion}`,this.session.token!==null&&(e.headers.authorization=`Bearer ${this.session.token}`),{...this.defaults,...e}}};var E4=g(require("jwt-decode")),M1=class{static parse(e){try{return new M1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=(0,E4.default)(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}isExpired(e=0){let o=Date.now(),a=(this.expiration-e)*1e3;return o>=a}};var w1=class{constructor(e){this.promise=null;this.fn=e}execute(e){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(e)}finally{this.promise=null}})()),this.promise}};var U2=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,o){o!==void 0?this._cache[e]=o:this.del(e)}del(e){delete this._cache[e]}},D2=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}};function p5(){return typeof window<"u"&&window.localStorage?new D2:new U2}var Q=p5();var h5=i=>{var e;return(e=i.map(o=>{if(o.type==="wallet")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3),chainType:o.chain_type}}).filter(o=>o))==null?void 0:e[0]},f5=i=>{var e;return(e=i.map(o=>{if(o.type==="email")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},u5=i=>{var e;return(e=i.map(o=>{if(o.type==="phone")return{number:o.phoneNumber,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},m5=i=>{var e;return(e=i.map(o=>{if(o.type==="google_oauth")return{subject:o.subject,email:o.email,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},b5=i=>{var e;return(e=i.map(o=>{if(o.type==="twitter_oauth")return{subject:o.subject,username:o.username,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},k5=i=>{var e;return(e=i.map(o=>{if(o.type==="discord_oauth")return{subject:o.subject,username:o.username,email:o.email,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]};function f1(i){if(!i)return null;let e=f5(i.linked_accounts),o=u5(i.linked_accounts),a=h5(i.linked_accounts),l=m5(i.linked_accounts),C=b5(i.linked_accounts),c=k5(i.linked_accounts);return{id:i.id,createdAt:new Date(i.created_at*1e3),linkedAccounts:[...a?[a]:[],...e?[e]:[],...o?[o]:[],...l?[l]:[],...C?[C]:[],...c?[c]:[]],email:e&&{address:e==null?void 0:e.address},phone:o&&{number:o==null?void 0:o.number},wallet:a&&{address:a.address,chainType:a.chainType,chainId:a.chainId,walletType:a.walletType},google:l&&{subject:l.subject,email:l.email,name:l.name},twitter:C&&{subject:C.subject,username:C.username,name:C.name},discord:c&&{subject:c.subject,username:c.username,email:c.email}}}var A4=()=>"/api/v1/sessions",P4=()=>"/api/v1/sessions/logout",_4=()=>"/api/v1/sessions/fork",T4=()=>"/api/v1/siwe/init",S4=()=>"/api/v1/siwe/authenticate",I4=()=>"/api/v1/passwordless/init",O4=()=>"/api/v1/passwordless/authenticate",N4=()=>"/api/v1/passwordless_sms/init",R4=()=>"/api/v1/passwordless_sms/authenticate",W4=()=>"/api/v1/oauth/init",U4=()=>"/api/v1/oauth/authenticate",D4=()=>"/api/v1/siwe/unlink",F4=()=>"/api/v1/passwordless/unlink",H4=()=>"/api/v1/passwordless_sms/unlink",V4=()=>"/api/v1/oauth/unlink";var g5=30,F2="privy:token",H2="privy:refresh_token",r2=class{constructor(){this.authenticateOnce=new w1(async e=>this._authenticate(e)),this.refreshOnce=new w1(this._refresh.bind(this)),this.destroyOnce=new w1(this._destroy.bind(this)),this.forkSessionOnce=new w1(this._forkSession.bind(this))}get token(){try{let e=Q.get(F2);return typeof e=="string"?new M1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=Q.get(H2);return typeof e=="string"?e:null}catch(e){return console.error(e),this.destroyLocalState(),null}}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=M1.parse(this.token);return e!==null&&!e.isExpired(g5)}authenticate(e){return this.authenticateOnce.execute(e)}refresh(){return this.refreshOnce.execute()}forkSession(){return this.forkSessionOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:o,refresh_token:a,user:l}=await e.authenticate();return o&&this.storeToken(o),a&&this.storeRefreshToken(a),f1(l)}catch(o){throw console.warn("Error authenticating session"),J(o)}}async _refresh(){if(!this.api)throw new b("Session has no API instance");let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let a=await this.api.post(A4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),f1(a.data.user)}catch(a){throw J(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(P4(),{})),this.destroyLocalState()}catch(o){throw console.warn("Error destroying session"),J(o)}}async _forkSession(){if(!this.api)throw new b("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(_4(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw J(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?Q.put(F2,e):Q.del(F2)}storeRefreshToken(e){typeof e=="string"?Q.put(H2,e):Q.del(H2)}};var j4=require("@ethersproject/address"),j2=g(require("@walletconnect/web3-provider"));var B4=require("ethers");var P1=class extends Y{constructor(){super("Wallet timeout");this.type="wallet_error"}},n2=i=>{if(i instanceof Y)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new _1(i);return i.code===B4.ethers.errors.ACTION_REJECTED&&(e.details=y1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new _1(i):new Y("Unknown connector error",i)},V2=class extends i1{constructor(o,a,l){super(o);this.type="provider_error";this.code=a,this.data=l}},_1=class extends V2{constructor(o){var C,c,m;let a=o;super(a.message,a.code,a.data);let l=Object.values(y1).find(M=>M.eipCode===a.code);this.details=l||y1.UNKNOWN_ERROR,a.code===-32002&&((C=a.message)!=null&&C.includes("already pending for origin")?(c=a.message)!=null&&c.includes("wallet_requestPermissions")?this.details=y1.E32002_CONNECTION_ALREADY_PENDING:this.details=y1.E32002_REQUEST_ALREADY_PENDING:(m=a.message)!=null&&m.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=y1.E32002_WALLET_LOCKED))}},M5={ERROR_USER_EXISTS:{message:"User already exists for this address",detail:"Try another address!",retryable:!1},ERROR_TIMED_OUT:{message:"Wallet request timed out",detail:"Please try connecting again.",retryable:!0},ERROR_WALLET_CONNECTION:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0}},w5={E32002_CONNECTION_ALREADY_PENDING:{eipCode:-32002,message:"Connection request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_REQUEST_ALREADY_PENDING:{eipCode:-32002,message:"Resource request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_WALLET_LOCKED:{eipCode:-32002,message:"Wallet might be locked",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E4001_USER_REJECTED_REQUEST:{eipCode:4001,message:"Signature rejected",detail:"Please try signing again.",retryable:!0}},y5={E4001_DEFAULT_USER_REJECTED_REQUEST:{eipCode:4001,message:"User Rejected Request",detail:"The user rejected the request.",default:!0,retryable:!0},E4100_DEFAULT_UNAUTHORIZED:{eipCode:4100,message:"Unauthorized",detail:"The requested method and/or account has not been authorized by the user.",default:!0,retryable:!1},E4200_DEFAULT_UNSUPPORTED_METHOD:{eipCode:4200,message:"Unsupported Method",detail:"The Provider does not support the requested method.",default:!0,retryable:!1},E4900_DEFAULT_DISCONNECTED:{eipCode:4900,message:"Disconnected",detail:"The Provider is disconnected from all chains.",default:!0,retryable:!0},E4901_DEFAULT_CHAIN_DISCONNECTED:{eipCode:4901,message:"Chain Disconnected",detail:"The Provider is not connected to the requested chain.",default:!0,retryable:!0},E32700_DEFAULT_PARSE_ERROR:{eipCode:-32700,message:"Parse error",detail:"Invalid JSON",default:!0,retryable:!1},E32600_DEFAULT_INVALID_REQUEST:{eipCode:-32600,message:"Invalid request",detail:"JSON is not a valid request object",default:!0,retryable:!1},E32601_DEFAULT_METHOD_NOT_FOUND:{eipCode:-32601,message:"Method not found",detail:"Method does not exist",default:!0,retryable:!1},E32602_DEFAULT_INVALID_PARAMS:{eipCode:-32602,message:"Invalid params",detail:"Invalid method parameters",default:!0,retryable:!1},E32603_DEFAULT_INTERNAL_ERROR:{eipCode:-32603,message:"Internal error",detail:"Internal JSON-RPC error",default:!0,retryable:!0},E32000_DEFAULT_INVALID_INPUT:{eipCode:-32e3,message:"Invalid input",detail:"Missing or invalid parameters",default:!0,retryable:!1},E32001_DEFAULT_RESOURCE_NOT_FOUND:{eipCode:-32001,message:"Resource not found",detail:"Requested resource not found",default:!0,retryable:!1},E32002_DEFAULT_RESOURCE_UNAVAILABLE:{eipCode:-32002,message:"Resource unavailable",detail:"Requested resource not available",default:!0,retryable:!0},E32003_DEFAULT_TRANSACTION_REJECTED:{eipCode:-32003,message:"Transaction rejected",detail:"Transaction creation failed",default:!0,retryable:!0},E32004_DEFAULT_METHOD_NOT_SUPPORTED:{eipCode:-32004,message:"Method not supported",detail:"Method is not implemented",default:!0,retryable:!1},E32005_DEFAULT_LIMIT_EXCEEDED:{eipCode:-32005,message:"Limit exceeded",detail:"Request exceeds defined limit",default:!0,retryable:!1},E32006_DEFAULT_JSON_RPC_VERSION_NOT_SUPPORTED:{eipCode:-32006,message:"JSON-RPC version not supported",detail:"Version of JSON-RPC protocol is not supported",default:!0,retryable:!1}},y1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...y5,...w5},s2={...M5,...y1};var v5=12e4,B2=(i=new P1,e=v5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),T1=class{constructor(e){this.removeListener=(e,o)=>{if(this.walletProvider)return this.walletProvider.removeListener(e,o)};this.setProvider=e=>{this.walletProvider=e,this._subscriptions.forEach(o=>{var a;(a=this.walletProvider)==null||a.on(o.eventName,o.listener)})};this.walletProvider=e,this._subscriptions=[]}on(e,o){if(this.walletProvider)return this.walletProvider.on(e,o);this._subscriptions.push({eventName:e,listener:o})}request(e){if(!this.walletProvider)throw new Y(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),B2()]).catch(o=>{throw n2(o)})}},S1=class extends T1{constructor(o){super(o)}},C2=class extends T1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var z4=require("ethers");var G4=["metamask","coinbase_wallet","wallet_connect"];var $4=g(require("@coinbase/wallet-sdk")),G2="privy:wallet_type",Z5="walletconnect",x5=()=>{let i=`https://mainnet.infura.io/v3/${i2}`,e=1;return new $4.default({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},z2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isMetaMask)return!0}return!1},c2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isCoinbaseWallet)return!0}return!1},d2=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,l,C,c,m)=>`${a} wants you to sign in with your Ethereum account:
|
|
1
|
+
"use strict";var a5=Object.create;var t2=Object.defineProperty;var l5=Object.getOwnPropertyDescriptor;var r5=Object.getOwnPropertyNames;var n5=Object.getPrototypeOf,s5=Object.prototype.hasOwnProperty;var C5=(i,e)=>{for(var o in e)t2(i,o,{get:e[o],enumerable:!0})},w4=(i,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of r5(e))!s5.call(i,l)&&l!==o&&t2(i,l,{get:()=>e[l],enumerable:!(a=l5(e,l))||a.enumerable});return i};var g=(i,e,o)=>(o=i!=null?a5(n5(i)):{},w4(e||!i||!i.__esModule?t2(o,"default",{value:i,enumerable:!0}):o,i)),d5=i=>w4(t2({},"__esModule",{value:!0}),i);var _6={};C5(_6,{PrivyProvider:()=>i5,VERSION:()=>o2,usePrivy:()=>x});module.exports=d5(_6);var K=require("react");var a2=g(require("axios"));var y4=g(require("axios")),i1=class extends Error{constructor(o,a){super(o);a instanceof Error&&(this.cause=a)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},e2=class extends i1{constructor(o,a,l,C){super(l,C);this.type=o;this.status=a}},b=class extends i1{constructor(o,a){super(o,a);this.type="client_error"}};var Y=class extends i1{constructor(o,a){super(o,a);this.type="connector_error"}},D=i=>{if(i instanceof i1)return i;if(!y4.default.isAxiosError(i))return J(i);if(!i.response)return new e2("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new e2(e||"ApiError",i.response.status,o||a,i)},J=i=>i instanceof i1?i:i instanceof Error?new b(i.message,i):new b(`Internal error: ${i}`);var v4="1.8.0";var Z4="https://api.privy.io/v0",x4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",i2="4df5e2316331463a9130964bd6078dfa",L4=1e4,X=1200,o2=v4;var l2=class{constructor(e,o,a){this.appId=e,this.sdkVersion=o2,this.session=o,this.defaults=a}async get(e,o){try{return await a2.default.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw D(a)}}async post(e,o,a){try{return await a2.default.post(e,o,this.buildConfig(a))}catch(l){throw D(l)}}async delete(e,o){try{return await a2.default.delete(e,this.buildConfig(o))}catch(a){throw D(a)}}buildConfig(e){return e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-client"]=`react-auth:${this.sdkVersion}`,this.session.token!==null&&(e.headers.authorization=`Bearer ${this.session.token}`),{...this.defaults,...e}}};var E4=g(require("jwt-decode")),M1=class{static parse(e){try{return new M1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=(0,E4.default)(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}isExpired(e=0){let o=Date.now(),a=(this.expiration-e)*1e3;return o>=a}};var w1=class{constructor(e){this.promise=null;this.fn=e}execute(e){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(e)}finally{this.promise=null}})()),this.promise}};var U2=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,o){o!==void 0?this._cache[e]=o:this.del(e)}del(e){delete this._cache[e]}},D2=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}};function p5(){return typeof window<"u"&&window.localStorage?new D2:new U2}var Q=p5();var h5=i=>{var e;return(e=i.map(o=>{if(o.type==="wallet")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3),chainType:o.chain_type}}).filter(o=>o))==null?void 0:e[0]},f5=i=>{var e;return(e=i.map(o=>{if(o.type==="email")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},u5=i=>{var e;return(e=i.map(o=>{if(o.type==="phone")return{number:o.phoneNumber,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},m5=i=>{var e;return(e=i.map(o=>{if(o.type==="google_oauth")return{subject:o.subject,email:o.email,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},b5=i=>{var e;return(e=i.map(o=>{if(o.type==="twitter_oauth")return{subject:o.subject,username:o.username,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},k5=i=>{var e;return(e=i.map(o=>{if(o.type==="discord_oauth")return{subject:o.subject,username:o.username,email:o.email,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]};function f1(i){if(!i)return null;let e=f5(i.linked_accounts),o=u5(i.linked_accounts),a=h5(i.linked_accounts),l=m5(i.linked_accounts),C=b5(i.linked_accounts),c=k5(i.linked_accounts);return{id:i.id,createdAt:new Date(i.created_at*1e3),linkedAccounts:[...a?[a]:[],...e?[e]:[],...o?[o]:[],...l?[l]:[],...C?[C]:[],...c?[c]:[]],email:e&&{address:e==null?void 0:e.address},phone:o&&{number:o==null?void 0:o.number},wallet:a&&{address:a.address,chainType:a.chainType,chainId:a.chainId,walletType:a.walletType},google:l&&{subject:l.subject,email:l.email,name:l.name},twitter:C&&{subject:C.subject,username:C.username,name:C.name},discord:c&&{subject:c.subject,username:c.username,email:c.email}}}var A4=()=>"/api/v1/sessions",P4=()=>"/api/v1/sessions/logout",_4=()=>"/api/v1/sessions/fork",T4=()=>"/api/v1/siwe/init",S4=()=>"/api/v1/siwe/authenticate",I4=()=>"/api/v1/passwordless/init",O4=()=>"/api/v1/passwordless/authenticate",N4=()=>"/api/v1/passwordless_sms/init",R4=()=>"/api/v1/passwordless_sms/authenticate",W4=()=>"/api/v1/oauth/init",U4=()=>"/api/v1/oauth/authenticate",D4=()=>"/api/v1/siwe/unlink",F4=()=>"/api/v1/passwordless/unlink",H4=()=>"/api/v1/passwordless_sms/unlink",V4=()=>"/api/v1/oauth/unlink";var g5=30,F2="privy:token",H2="privy:refresh_token",r2=class{constructor(){this.authenticateOnce=new w1(async e=>this._authenticate(e)),this.refreshOnce=new w1(this._refresh.bind(this)),this.destroyOnce=new w1(this._destroy.bind(this)),this.forkSessionOnce=new w1(this._forkSession.bind(this))}get token(){try{let e=Q.get(F2);return typeof e=="string"?new M1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=Q.get(H2);return typeof e=="string"?e:null}catch(e){return console.error(e),this.destroyLocalState(),null}}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=M1.parse(this.token);return e!==null&&!e.isExpired(g5)}authenticate(e){return this.authenticateOnce.execute(e)}refresh(){return this.refreshOnce.execute()}forkSession(){return this.forkSessionOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:o,refresh_token:a,user:l}=await e.authenticate();return o&&this.storeToken(o),a&&this.storeRefreshToken(a),f1(l)}catch(o){throw console.warn("Error authenticating session"),J(o)}}async _refresh(){if(!this.api)throw new b("Session has no API instance");let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let a=await this.api.post(A4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),f1(a.data.user)}catch(a){throw J(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(P4(),{})),this.destroyLocalState()}catch(o){throw console.warn("Error destroying session"),J(o)}}async _forkSession(){if(!this.api)throw new b("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(_4(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw J(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?Q.put(F2,e):Q.del(F2)}storeRefreshToken(e){typeof e=="string"?Q.put(H2,e):Q.del(H2)}};var j4=require("@ethersproject/address"),j2=g(require("@walletconnect/web3-provider"));var B4=require("ethers");var P1=class extends Y{constructor(){super("Wallet timeout");this.type="wallet_error"}},n2=i=>{if(i instanceof Y)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new _1(i);return i.code===B4.ethers.errors.ACTION_REJECTED&&(e.details=y1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new _1(i):new Y("Unknown connector error",i)},V2=class extends i1{constructor(o,a,l){super(o);this.type="provider_error";this.code=a,this.data=l}},_1=class extends V2{constructor(o){var C,c,m;let a=o;super(a.message,a.code,a.data);let l=Object.values(y1).find(M=>M.eipCode===a.code);this.details=l||y1.UNKNOWN_ERROR,a.code===-32002&&((C=a.message)!=null&&C.includes("already pending for origin")?(c=a.message)!=null&&c.includes("wallet_requestPermissions")?this.details=y1.E32002_CONNECTION_ALREADY_PENDING:this.details=y1.E32002_REQUEST_ALREADY_PENDING:(m=a.message)!=null&&m.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=y1.E32002_WALLET_LOCKED))}},M5={ERROR_USER_EXISTS:{message:"User already exists for this address",detail:"Try another address!",retryable:!1},ERROR_TIMED_OUT:{message:"Wallet request timed out",detail:"Please try connecting again.",retryable:!0},ERROR_WALLET_CONNECTION:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0}},w5={E32002_CONNECTION_ALREADY_PENDING:{eipCode:-32002,message:"Connection request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_REQUEST_ALREADY_PENDING:{eipCode:-32002,message:"Resource request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_WALLET_LOCKED:{eipCode:-32002,message:"Wallet might be locked",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E4001_USER_REJECTED_REQUEST:{eipCode:4001,message:"Signature rejected",detail:"Please try signing again.",retryable:!0}},y5={E4001_DEFAULT_USER_REJECTED_REQUEST:{eipCode:4001,message:"User Rejected Request",detail:"The user rejected the request.",default:!0,retryable:!0},E4100_DEFAULT_UNAUTHORIZED:{eipCode:4100,message:"Unauthorized",detail:"The requested method and/or account has not been authorized by the user.",default:!0,retryable:!1},E4200_DEFAULT_UNSUPPORTED_METHOD:{eipCode:4200,message:"Unsupported Method",detail:"The Provider does not support the requested method.",default:!0,retryable:!1},E4900_DEFAULT_DISCONNECTED:{eipCode:4900,message:"Disconnected",detail:"The Provider is disconnected from all chains.",default:!0,retryable:!0},E4901_DEFAULT_CHAIN_DISCONNECTED:{eipCode:4901,message:"Chain Disconnected",detail:"The Provider is not connected to the requested chain.",default:!0,retryable:!0},E32700_DEFAULT_PARSE_ERROR:{eipCode:-32700,message:"Parse error",detail:"Invalid JSON",default:!0,retryable:!1},E32600_DEFAULT_INVALID_REQUEST:{eipCode:-32600,message:"Invalid request",detail:"JSON is not a valid request object",default:!0,retryable:!1},E32601_DEFAULT_METHOD_NOT_FOUND:{eipCode:-32601,message:"Method not found",detail:"Method does not exist",default:!0,retryable:!1},E32602_DEFAULT_INVALID_PARAMS:{eipCode:-32602,message:"Invalid params",detail:"Invalid method parameters",default:!0,retryable:!1},E32603_DEFAULT_INTERNAL_ERROR:{eipCode:-32603,message:"Internal error",detail:"Internal JSON-RPC error",default:!0,retryable:!0},E32000_DEFAULT_INVALID_INPUT:{eipCode:-32e3,message:"Invalid input",detail:"Missing or invalid parameters",default:!0,retryable:!1},E32001_DEFAULT_RESOURCE_NOT_FOUND:{eipCode:-32001,message:"Resource not found",detail:"Requested resource not found",default:!0,retryable:!1},E32002_DEFAULT_RESOURCE_UNAVAILABLE:{eipCode:-32002,message:"Resource unavailable",detail:"Requested resource not available",default:!0,retryable:!0},E32003_DEFAULT_TRANSACTION_REJECTED:{eipCode:-32003,message:"Transaction rejected",detail:"Transaction creation failed",default:!0,retryable:!0},E32004_DEFAULT_METHOD_NOT_SUPPORTED:{eipCode:-32004,message:"Method not supported",detail:"Method is not implemented",default:!0,retryable:!1},E32005_DEFAULT_LIMIT_EXCEEDED:{eipCode:-32005,message:"Limit exceeded",detail:"Request exceeds defined limit",default:!0,retryable:!1},E32006_DEFAULT_JSON_RPC_VERSION_NOT_SUPPORTED:{eipCode:-32006,message:"JSON-RPC version not supported",detail:"Version of JSON-RPC protocol is not supported",default:!0,retryable:!1}},y1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...y5,...w5},s2={...M5,...y1};var v5=12e4,B2=(i=new P1,e=v5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),T1=class{constructor(e){this.removeListener=(e,o)=>{if(this.walletProvider)return this.walletProvider.removeListener(e,o)};this.setProvider=e=>{this.walletProvider=e,this._subscriptions.forEach(o=>{var a;(a=this.walletProvider)==null||a.on(o.eventName,o.listener)})};this.walletProvider=e,this._subscriptions=[]}on(e,o){if(this.walletProvider)return this.walletProvider.on(e,o);this._subscriptions.push({eventName:e,listener:o})}request(e){if(!this.walletProvider)throw new Y(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),B2()]).catch(o=>{throw n2(o)})}},S1=class extends T1{constructor(o){super(o)}},C2=class extends T1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var z4=require("ethers");var G4=["metamask","coinbase_wallet","wallet_connect"];var $4=g(require("@coinbase/wallet-sdk")),G2="privy:wallet_type",Z5="walletconnect",x5=()=>{let i=`https://mainnet.infura.io/v3/${i2}`,e=1;return new $4.default({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},z2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isMetaMask)return!0}return!1},c2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isCoinbaseWallet)return!0}return!1},d2=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,l,C,c,m)=>`${a} wants you to sign in with your Ethereum account:
|
|
2
2
|
${o}
|
|
3
3
|
|
|
4
4
|
${m}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{useEffect as x2,useState as h1}from"react";import _2 from"axios";import J3 from"axios";var j=class extends Error{constructor(o,a){super(o);a instanceof Error&&(this.cause=a)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},F1=class extends j{constructor(o,a,l,s){super(l,s);this.type=o;this.status=a}},m=class extends j{constructor(o,a){super(o,a);this.type="client_error"}};var F=class extends j{constructor(o,a){super(o,a);this.type="connector_error"}},R=i=>{if(i instanceof j)return i;if(!J3.isAxiosError(i))return H(i);if(!i.response)return new F1("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new F1(e||"ApiError",i.response.status,o||a,i)},H=i=>i instanceof j?i:i instanceof Error?new m(i.message,i):new m(`Internal error: ${i}`);var d4="1.8.0-beta.9";var c4="https://api.privy.io/v0",p4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",H1="4df5e2316331463a9130964bd6078dfa",h4=1e4,V=1200,P2=d4;var V1=class{constructor(e,o,a){this.appId=e,this.sdkVersion=P2,this.session=o,this.defaults=a}async get(e,o){try{return await _2.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw R(a)}}async post(e,o,a){try{return await _2.post(e,o,this.buildConfig(a))}catch(l){throw R(l)}}async delete(e,o){try{return await _2.delete(e,this.buildConfig(o))}catch(a){throw R(a)}}buildConfig(e){return e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-client"]=`react-auth:${this.sdkVersion}`,this.session.token!==null&&(e.headers.authorization=`Bearer ${this.session.token}`),{...this.defaults,...e}}};import Q3 from"jwt-decode";var o1=class{static parse(e){try{return new o1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=Q3(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}isExpired(e=0){let o=Date.now(),a=(this.expiration-e)*1e3;return o>=a}};var a1=class{constructor(e){this.promise=null;this.fn=e}execute(e){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(e)}finally{this.promise=null}})()),this.promise}};var T2=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,o){o!==void 0?this._cache[e]=o:this.del(e)}del(e){delete this._cache[e]}},S2=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}};function t5(){return typeof window<"u"&&window.localStorage?new S2:new T2}var B=t5();var e5=i=>{var e;return(e=i.map(o=>{if(o.type==="wallet")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3),chainType:o.chain_type}}).filter(o=>o))==null?void 0:e[0]},i5=i=>{var e;return(e=i.map(o=>{if(o.type==="email")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},o5=i=>{var e;return(e=i.map(o=>{if(o.type==="phone")return{number:o.phoneNumber,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},a5=i=>{var e;return(e=i.map(o=>{if(o.type==="google_oauth")return{subject:o.subject,email:o.email,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},l5=i=>{var e;return(e=i.map(o=>{if(o.type==="twitter_oauth")return{subject:o.subject,username:o.username,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},r5=i=>{var e;return(e=i.map(o=>{if(o.type==="discord_oauth")return{subject:o.subject,username:o.username,email:o.email,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]};function X(i){if(!i)return null;let e=i5(i.linked_accounts),o=o5(i.linked_accounts),a=e5(i.linked_accounts),l=a5(i.linked_accounts),s=l5(i.linked_accounts),d=r5(i.linked_accounts);return{id:i.id,createdAt:new Date(i.created_at*1e3),linkedAccounts:[...a?[a]:[],...e?[e]:[],...o?[o]:[],...l?[l]:[],...s?[s]:[],...d?[d]:[]],email:e&&{address:e==null?void 0:e.address},phone:o&&{number:o==null?void 0:o.number},wallet:a&&{address:a.address,chainType:a.chainType,chainId:a.chainId,walletType:a.walletType},google:l&&{subject:l.subject,email:l.email,name:l.name},twitter:s&&{subject:s.subject,username:s.username,name:s.name},discord:d&&{subject:d.subject,username:d.username,email:d.email}}}var f4=()=>"/api/v1/sessions",u4=()=>"/api/v1/sessions/logout",m4=()=>"/api/v1/sessions/fork",b4=()=>"/api/v1/siwe/init",k4=()=>"/api/v1/siwe/authenticate",g4=()=>"/api/v1/passwordless/init",M4=()=>"/api/v1/passwordless/authenticate",w4=()=>"/api/v1/passwordless_sms/init",y4=()=>"/api/v1/passwordless_sms/authenticate",v4=()=>"/api/v1/oauth/init",Z4=()=>"/api/v1/oauth/authenticate",x4=()=>"/api/v1/siwe/unlink",L4=()=>"/api/v1/passwordless/unlink",E4=()=>"/api/v1/passwordless_sms/unlink",A4=()=>"/api/v1/oauth/unlink";var n5=30,I2="privy:token",O2="privy:refresh_token",B1=class{constructor(){this.authenticateOnce=new a1(async e=>this._authenticate(e)),this.refreshOnce=new a1(this._refresh.bind(this)),this.destroyOnce=new a1(this._destroy.bind(this)),this.forkSessionOnce=new a1(this._forkSession.bind(this))}get token(){try{let e=B.get(I2);return typeof e=="string"?new o1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=B.get(O2);return typeof e=="string"?e:null}catch(e){return console.error(e),this.destroyLocalState(),null}}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=o1.parse(this.token);return e!==null&&!e.isExpired(n5)}authenticate(e){return this.authenticateOnce.execute(e)}refresh(){return this.refreshOnce.execute()}forkSession(){return this.forkSessionOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:o,refresh_token:a,user:l}=await e.authenticate();return o&&this.storeToken(o),a&&this.storeRefreshToken(a),X(l)}catch(o){throw console.warn("Error authenticating session"),H(o)}}async _refresh(){if(!this.api)throw new m("Session has no API instance");let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let a=await this.api.post(f4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),X(a.data.user)}catch(a){throw H(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(u4(),{})),this.destroyLocalState()}catch(o){throw console.warn("Error destroying session"),H(o)}}async _forkSession(){if(!this.api)throw new m("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(m4(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw H(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?B.put(I2,e):B.del(I2)}storeRefreshToken(e){typeof e=="string"?B.put(O2,e):B.del(O2)}};import{getAddress as h5}from"@ethersproject/address";import _4 from"@walletconnect/web3-provider";import{ethers as s5}from"ethers";var u1=class extends F{constructor(){super("Wallet timeout");this.type="wallet_error"}},G1=i=>{if(i instanceof F)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new m1(i);return i.code===s5.errors.ACTION_REJECTED&&(e.details=l1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new m1(i):new F("Unknown connector error",i)},N2=class extends j{constructor(o,a,l){super(o);this.type="provider_error";this.code=a,this.data=l}},m1=class extends N2{constructor(o){var s,d,u;let a=o;super(a.message,a.code,a.data);let l=Object.values(l1).find(k=>k.eipCode===a.code);this.details=l||l1.UNKNOWN_ERROR,a.code===-32002&&((s=a.message)!=null&&s.includes("already pending for origin")?(d=a.message)!=null&&d.includes("wallet_requestPermissions")?this.details=l1.E32002_CONNECTION_ALREADY_PENDING:this.details=l1.E32002_REQUEST_ALREADY_PENDING:(u=a.message)!=null&&u.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=l1.E32002_WALLET_LOCKED))}},C5={ERROR_USER_EXISTS:{message:"User already exists for this address",detail:"Try another address!",retryable:!1},ERROR_TIMED_OUT:{message:"Wallet request timed out",detail:"Please try connecting again.",retryable:!0},ERROR_WALLET_CONNECTION:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0}},d5={E32002_CONNECTION_ALREADY_PENDING:{eipCode:-32002,message:"Connection request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_REQUEST_ALREADY_PENDING:{eipCode:-32002,message:"Resource request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_WALLET_LOCKED:{eipCode:-32002,message:"Wallet might be locked",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E4001_USER_REJECTED_REQUEST:{eipCode:4001,message:"Signature rejected",detail:"Please try signing again.",retryable:!0}},c5={E4001_DEFAULT_USER_REJECTED_REQUEST:{eipCode:4001,message:"User Rejected Request",detail:"The user rejected the request.",default:!0,retryable:!0},E4100_DEFAULT_UNAUTHORIZED:{eipCode:4100,message:"Unauthorized",detail:"The requested method and/or account has not been authorized by the user.",default:!0,retryable:!1},E4200_DEFAULT_UNSUPPORTED_METHOD:{eipCode:4200,message:"Unsupported Method",detail:"The Provider does not support the requested method.",default:!0,retryable:!1},E4900_DEFAULT_DISCONNECTED:{eipCode:4900,message:"Disconnected",detail:"The Provider is disconnected from all chains.",default:!0,retryable:!0},E4901_DEFAULT_CHAIN_DISCONNECTED:{eipCode:4901,message:"Chain Disconnected",detail:"The Provider is not connected to the requested chain.",default:!0,retryable:!0},E32700_DEFAULT_PARSE_ERROR:{eipCode:-32700,message:"Parse error",detail:"Invalid JSON",default:!0,retryable:!1},E32600_DEFAULT_INVALID_REQUEST:{eipCode:-32600,message:"Invalid request",detail:"JSON is not a valid request object",default:!0,retryable:!1},E32601_DEFAULT_METHOD_NOT_FOUND:{eipCode:-32601,message:"Method not found",detail:"Method does not exist",default:!0,retryable:!1},E32602_DEFAULT_INVALID_PARAMS:{eipCode:-32602,message:"Invalid params",detail:"Invalid method parameters",default:!0,retryable:!1},E32603_DEFAULT_INTERNAL_ERROR:{eipCode:-32603,message:"Internal error",detail:"Internal JSON-RPC error",default:!0,retryable:!0},E32000_DEFAULT_INVALID_INPUT:{eipCode:-32e3,message:"Invalid input",detail:"Missing or invalid parameters",default:!0,retryable:!1},E32001_DEFAULT_RESOURCE_NOT_FOUND:{eipCode:-32001,message:"Resource not found",detail:"Requested resource not found",default:!0,retryable:!1},E32002_DEFAULT_RESOURCE_UNAVAILABLE:{eipCode:-32002,message:"Resource unavailable",detail:"Requested resource not available",default:!0,retryable:!0},E32003_DEFAULT_TRANSACTION_REJECTED:{eipCode:-32003,message:"Transaction rejected",detail:"Transaction creation failed",default:!0,retryable:!0},E32004_DEFAULT_METHOD_NOT_SUPPORTED:{eipCode:-32004,message:"Method not supported",detail:"Method is not implemented",default:!0,retryable:!1},E32005_DEFAULT_LIMIT_EXCEEDED:{eipCode:-32005,message:"Limit exceeded",detail:"Request exceeds defined limit",default:!0,retryable:!1},E32006_DEFAULT_JSON_RPC_VERSION_NOT_SUPPORTED:{eipCode:-32006,message:"JSON-RPC version not supported",detail:"Version of JSON-RPC protocol is not supported",default:!0,retryable:!1}},l1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...c5,...d5},j1={...C5,...l1};var p5=12e4,R2=(i=new u1,e=p5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),b1=class{constructor(e){this.removeListener=(e,o)=>{if(this.walletProvider)return this.walletProvider.removeListener(e,o)};this.setProvider=e=>{this.walletProvider=e,this._subscriptions.forEach(o=>{var a;(a=this.walletProvider)==null||a.on(o.eventName,o.listener)})};this.walletProvider=e,this._subscriptions=[]}on(e,o){if(this.walletProvider)return this.walletProvider.on(e,o);this._subscriptions.push({eventName:e,listener:o})}request(e){if(!this.walletProvider)throw new F(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),R2()]).catch(o=>{throw G1(o)})}},k1=class extends b1{constructor(o){super(o)}},z1=class extends b1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};import{providers as f5}from"ethers";var P4=["metamask","coinbase_wallet","wallet_connect"];import u5 from"@coinbase/wallet-sdk";var W2="privy:wallet_type",m5="walletconnect",b5=()=>{let i=`https://mainnet.infura.io/v3/${H1}`,e=1;return new u5({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},U2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isMetaMask)return!0}return!1},q1=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isCoinbaseWallet)return!0}return!1},$1=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,l,s,d,u)=>`${a} wants you to sign in with your Ethereum account:
|
|
1
|
+
import{useEffect as x2,useState as h1}from"react";import _2 from"axios";import J3 from"axios";var j=class extends Error{constructor(o,a){super(o);a instanceof Error&&(this.cause=a)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},F1=class extends j{constructor(o,a,l,s){super(l,s);this.type=o;this.status=a}},m=class extends j{constructor(o,a){super(o,a);this.type="client_error"}};var F=class extends j{constructor(o,a){super(o,a);this.type="connector_error"}},R=i=>{if(i instanceof j)return i;if(!J3.isAxiosError(i))return H(i);if(!i.response)return new F1("api_error",null,i.message,i);let{type:e,message:o,error:a}=i.response.data;return new F1(e||"ApiError",i.response.status,o||a,i)},H=i=>i instanceof j?i:i instanceof Error?new m(i.message,i):new m(`Internal error: ${i}`);var d4="1.8.0";var c4="https://api.privy.io/v0",p4=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",H1="4df5e2316331463a9130964bd6078dfa",h4=1e4,V=1200,P2=d4;var V1=class{constructor(e,o,a){this.appId=e,this.sdkVersion=P2,this.session=o,this.defaults=a}async get(e,o){try{return await _2.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(a){throw R(a)}}async post(e,o,a){try{return await _2.post(e,o,this.buildConfig(a))}catch(l){throw R(l)}}async delete(e,o){try{return await _2.delete(e,this.buildConfig(o))}catch(a){throw R(a)}}buildConfig(e){return e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-client"]=`react-auth:${this.sdkVersion}`,this.session.token!==null&&(e.headers.authorization=`Bearer ${this.session.token}`),{...this.defaults,...e}}};import Q3 from"jwt-decode";var o1=class{static parse(e){try{return new o1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=Q3(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}isExpired(e=0){let o=Date.now(),a=(this.expiration-e)*1e3;return o>=a}};var a1=class{constructor(e){this.promise=null;this.fn=e}execute(e){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(e)}finally{this.promise=null}})()),this.promise}};var T2=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,o){o!==void 0?this._cache[e]=o:this.del(e)}del(e){delete this._cache[e]}},S2=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}};function t5(){return typeof window<"u"&&window.localStorage?new S2:new T2}var B=t5();var e5=i=>{var e;return(e=i.map(o=>{if(o.type==="wallet")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3),chainType:o.chain_type}}).filter(o=>o))==null?void 0:e[0]},i5=i=>{var e;return(e=i.map(o=>{if(o.type==="email")return{address:o.address,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},o5=i=>{var e;return(e=i.map(o=>{if(o.type==="phone")return{number:o.phoneNumber,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},a5=i=>{var e;return(e=i.map(o=>{if(o.type==="google_oauth")return{subject:o.subject,email:o.email,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},l5=i=>{var e;return(e=i.map(o=>{if(o.type==="twitter_oauth")return{subject:o.subject,username:o.username,name:o.name,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]},r5=i=>{var e;return(e=i.map(o=>{if(o.type==="discord_oauth")return{subject:o.subject,username:o.username,email:o.email,type:o.type,verifiedAt:new Date(o.verified_at*1e3)}}).filter(o=>o))==null?void 0:e[0]};function X(i){if(!i)return null;let e=i5(i.linked_accounts),o=o5(i.linked_accounts),a=e5(i.linked_accounts),l=a5(i.linked_accounts),s=l5(i.linked_accounts),d=r5(i.linked_accounts);return{id:i.id,createdAt:new Date(i.created_at*1e3),linkedAccounts:[...a?[a]:[],...e?[e]:[],...o?[o]:[],...l?[l]:[],...s?[s]:[],...d?[d]:[]],email:e&&{address:e==null?void 0:e.address},phone:o&&{number:o==null?void 0:o.number},wallet:a&&{address:a.address,chainType:a.chainType,chainId:a.chainId,walletType:a.walletType},google:l&&{subject:l.subject,email:l.email,name:l.name},twitter:s&&{subject:s.subject,username:s.username,name:s.name},discord:d&&{subject:d.subject,username:d.username,email:d.email}}}var f4=()=>"/api/v1/sessions",u4=()=>"/api/v1/sessions/logout",m4=()=>"/api/v1/sessions/fork",b4=()=>"/api/v1/siwe/init",k4=()=>"/api/v1/siwe/authenticate",g4=()=>"/api/v1/passwordless/init",M4=()=>"/api/v1/passwordless/authenticate",w4=()=>"/api/v1/passwordless_sms/init",y4=()=>"/api/v1/passwordless_sms/authenticate",v4=()=>"/api/v1/oauth/init",Z4=()=>"/api/v1/oauth/authenticate",x4=()=>"/api/v1/siwe/unlink",L4=()=>"/api/v1/passwordless/unlink",E4=()=>"/api/v1/passwordless_sms/unlink",A4=()=>"/api/v1/oauth/unlink";var n5=30,I2="privy:token",O2="privy:refresh_token",B1=class{constructor(){this.authenticateOnce=new a1(async e=>this._authenticate(e)),this.refreshOnce=new a1(this._refresh.bind(this)),this.destroyOnce=new a1(this._destroy.bind(this)),this.forkSessionOnce=new a1(this._forkSession.bind(this))}get token(){try{let e=B.get(I2);return typeof e=="string"?new o1(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=B.get(O2);return typeof e=="string"?e:null}catch(e){return console.error(e),this.destroyLocalState(),null}}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=o1.parse(this.token);return e!==null&&!e.isExpired(n5)}authenticate(e){return this.authenticateOnce.execute(e)}refresh(){return this.refreshOnce.execute()}forkSession(){return this.forkSessionOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:o,refresh_token:a,user:l}=await e.authenticate();return o&&this.storeToken(o),a&&this.storeRefreshToken(a),X(l)}catch(o){throw console.warn("Error authenticating session"),H(o)}}async _refresh(){if(!this.api)throw new m("Session has no API instance");let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let a=await this.api.post(f4(),{refresh_token:o});return this.storeToken(a.data.token),this.storeRefreshToken(a.data.refresh_token),X(a.data.user)}catch(a){throw H(a)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(u4(),{})),this.destroyLocalState()}catch(o){throw console.warn("Error destroying session"),H(o)}}async _forkSession(){if(!this.api)throw new m("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(m4(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw H(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?B.put(I2,e):B.del(I2)}storeRefreshToken(e){typeof e=="string"?B.put(O2,e):B.del(O2)}};import{getAddress as h5}from"@ethersproject/address";import _4 from"@walletconnect/web3-provider";import{ethers as s5}from"ethers";var u1=class extends F{constructor(){super("Wallet timeout");this.type="wallet_error"}},G1=i=>{if(i instanceof F)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new m1(i);return i.code===s5.errors.ACTION_REJECTED&&(e.details=l1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new m1(i):new F("Unknown connector error",i)},N2=class extends j{constructor(o,a,l){super(o);this.type="provider_error";this.code=a,this.data=l}},m1=class extends N2{constructor(o){var s,d,u;let a=o;super(a.message,a.code,a.data);let l=Object.values(l1).find(k=>k.eipCode===a.code);this.details=l||l1.UNKNOWN_ERROR,a.code===-32002&&((s=a.message)!=null&&s.includes("already pending for origin")?(d=a.message)!=null&&d.includes("wallet_requestPermissions")?this.details=l1.E32002_CONNECTION_ALREADY_PENDING:this.details=l1.E32002_REQUEST_ALREADY_PENDING:(u=a.message)!=null&&u.includes("Already processing")&&a.message.includes("eth_requestAccounts")&&(this.details=l1.E32002_WALLET_LOCKED))}},C5={ERROR_USER_EXISTS:{message:"User already exists for this address",detail:"Try another address!",retryable:!1},ERROR_TIMED_OUT:{message:"Wallet request timed out",detail:"Please try connecting again.",retryable:!0},ERROR_WALLET_CONNECTION:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0}},d5={E32002_CONNECTION_ALREADY_PENDING:{eipCode:-32002,message:"Connection request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_REQUEST_ALREADY_PENDING:{eipCode:-32002,message:"Resource request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_WALLET_LOCKED:{eipCode:-32002,message:"Wallet might be locked",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E4001_USER_REJECTED_REQUEST:{eipCode:4001,message:"Signature rejected",detail:"Please try signing again.",retryable:!0}},c5={E4001_DEFAULT_USER_REJECTED_REQUEST:{eipCode:4001,message:"User Rejected Request",detail:"The user rejected the request.",default:!0,retryable:!0},E4100_DEFAULT_UNAUTHORIZED:{eipCode:4100,message:"Unauthorized",detail:"The requested method and/or account has not been authorized by the user.",default:!0,retryable:!1},E4200_DEFAULT_UNSUPPORTED_METHOD:{eipCode:4200,message:"Unsupported Method",detail:"The Provider does not support the requested method.",default:!0,retryable:!1},E4900_DEFAULT_DISCONNECTED:{eipCode:4900,message:"Disconnected",detail:"The Provider is disconnected from all chains.",default:!0,retryable:!0},E4901_DEFAULT_CHAIN_DISCONNECTED:{eipCode:4901,message:"Chain Disconnected",detail:"The Provider is not connected to the requested chain.",default:!0,retryable:!0},E32700_DEFAULT_PARSE_ERROR:{eipCode:-32700,message:"Parse error",detail:"Invalid JSON",default:!0,retryable:!1},E32600_DEFAULT_INVALID_REQUEST:{eipCode:-32600,message:"Invalid request",detail:"JSON is not a valid request object",default:!0,retryable:!1},E32601_DEFAULT_METHOD_NOT_FOUND:{eipCode:-32601,message:"Method not found",detail:"Method does not exist",default:!0,retryable:!1},E32602_DEFAULT_INVALID_PARAMS:{eipCode:-32602,message:"Invalid params",detail:"Invalid method parameters",default:!0,retryable:!1},E32603_DEFAULT_INTERNAL_ERROR:{eipCode:-32603,message:"Internal error",detail:"Internal JSON-RPC error",default:!0,retryable:!0},E32000_DEFAULT_INVALID_INPUT:{eipCode:-32e3,message:"Invalid input",detail:"Missing or invalid parameters",default:!0,retryable:!1},E32001_DEFAULT_RESOURCE_NOT_FOUND:{eipCode:-32001,message:"Resource not found",detail:"Requested resource not found",default:!0,retryable:!1},E32002_DEFAULT_RESOURCE_UNAVAILABLE:{eipCode:-32002,message:"Resource unavailable",detail:"Requested resource not available",default:!0,retryable:!0},E32003_DEFAULT_TRANSACTION_REJECTED:{eipCode:-32003,message:"Transaction rejected",detail:"Transaction creation failed",default:!0,retryable:!0},E32004_DEFAULT_METHOD_NOT_SUPPORTED:{eipCode:-32004,message:"Method not supported",detail:"Method is not implemented",default:!0,retryable:!1},E32005_DEFAULT_LIMIT_EXCEEDED:{eipCode:-32005,message:"Limit exceeded",detail:"Request exceeds defined limit",default:!0,retryable:!1},E32006_DEFAULT_JSON_RPC_VERSION_NOT_SUPPORTED:{eipCode:-32006,message:"JSON-RPC version not supported",detail:"Version of JSON-RPC protocol is not supported",default:!0,retryable:!1}},l1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...c5,...d5},j1={...C5,...l1};var p5=12e4,R2=(i=new u1,e=p5)=>new Promise((o,a)=>setTimeout(()=>{a(i)},e)),b1=class{constructor(e){this.removeListener=(e,o)=>{if(this.walletProvider)return this.walletProvider.removeListener(e,o)};this.setProvider=e=>{this.walletProvider=e,this._subscriptions.forEach(o=>{var a;(a=this.walletProvider)==null||a.on(o.eventName,o.listener)})};this.walletProvider=e,this._subscriptions=[]}on(e,o){if(this.walletProvider)return this.walletProvider.on(e,o);this._subscriptions.push({eventName:e,listener:o})}request(e){if(!this.walletProvider)throw new F(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),R2()]).catch(o=>{throw G1(o)})}},k1=class extends b1{constructor(o){super(o)}},z1=class extends b1{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};import{providers as f5}from"ethers";var P4=["metamask","coinbase_wallet","wallet_connect"];import u5 from"@coinbase/wallet-sdk";var W2="privy:wallet_type",m5="walletconnect",b5=()=>{let i=`https://mainnet.infura.io/v3/${H1}`,e=1;return new u5({appName:"Privy",darkMode:!1,headlessMode:!1}).makeWeb3Provider(i,e)},U2=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isMetaMask)return!0}return!1},q1=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let i of window.ethereum.providers)if(i.isCoinbaseWallet)return!0}return!1},$1=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,o,a,l,s,d,u)=>`${a} wants you to sign in with your Ethereum account:
|
|
2
2
|
${o}
|
|
3
3
|
|
|
4
4
|
${u}
|