@privy-io/react-auth 1.5.0-beta.14 → 1.5.0-beta.15
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 +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var w3=Object.create;var W1=Object.defineProperty;var y3=Object.getOwnPropertyDescriptor;var Z3=Object.getOwnPropertyNames;var v3=Object.getPrototypeOf,L3=Object.prototype.hasOwnProperty;var x3=(i,e)=>{for(var a in e)W1(i,a,{get:e[a],enumerable:!0})},K2=(i,e,a,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Z3(e))!L3.call(i,r)&&r!==a&&W1(i,r,{get:()=>e[r],enumerable:!(l=y3(e,r))||l.enumerable});return i};var u=(i,e,a)=>(a=i!=null?w3(v3(i)):{},K2(e||!i||!i.__esModule?W1(a,"default",{value:i,enumerable:!0}):a,i)),E3=i=>K2(W1({},"__esModule",{value:!0}),i);var T5={};x3(T5,{PrivyProvider:()=>M3,usePrivy:()=>_});module.exports=E3(T5);var U=require("react");var N1=u(require("axios"));var Y2=u(require("axios")),l1=class extends Error{constructor(a,l){super(a);l instanceof Error&&(this.cause=l)}toString(){return`${this.type}: ${this.message}`}},O1=class extends l1{constructor(a,l,r,C){super(r,C);this.type=a;this.status=l}},b=class extends l1{constructor(a,l){super(a,l);this.type="client_error"}};var V=class extends l1{constructor(a,l){super(a,l);this.type="connector_error"}},H=i=>{if(!Y2.default.isAxiosError(i))return X(i);if(!i.response)return new O1("api_error",null,i.message,i);let{type:e,message:a,error:l}=i.response.data;return new O1(e||"ApiError",i.response.status,a||l,i)},X=i=>i instanceof l1?i:i instanceof Error?new b(i.message,i):new b(`Internal error: ${i}`);var J2="1.5.0-beta.14";var D1=class{constructor(e,a,l){this.appId=e,this.sdkVersion=J2,this.session=a,this.defaults=l}async get(e,a){try{return await N1.default.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...a}))}catch(l){throw H(l)}}async post(e,a,l){try{return await N1.default.post(e,a,this.buildConfig(l))}catch(r){throw H(r)}}async delete(e,a){try{return await N1.default.delete(e,this.buildConfig(a))}catch(l){throw H(l)}}buildConfig(e){return e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-sdk-version"]=`react-auth-${this.sdkVersion}`,this.session.token!==null&&(e.headers.authorization=`Bearer ${this.session.token}`),{...this.defaults,...e}}};var X2="https://api.privy.io/v0",Q2=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",c2="70f97dc579834350a5baec117b3c5ae3",t4=1e4,o1=1200,e4=3e4;var i4=u(require("jwt-decode")),m1=class{static parse(e){try{return new m1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=(0,i4.default)(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}isExpired(e=0){let a=Date.now(),l=(this.expiration-e)*1e3;return a>=l}};var b1=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 p2=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,a){a!==void 0?this._cache[e]=a:this.del(e)}del(e){delete this._cache[e]}},h2=class{get(e){let a=localStorage.getItem(e);return a===null?void 0:JSON.parse(a)}put(e,a){a!==void 0?localStorage.setItem(e,JSON.stringify(a)):this.del(e)}del(e){localStorage.removeItem(e)}};function _3(){return typeof window<"u"&&window.localStorage?new h2:new p2}var j=_3();var T3=i=>{var e;return(e=i.map(a=>{if(a.type==="wallet")return{address:a.address,type:a.type,verifiedAt:new Date(a.verified_at*1e3),chainType:a.chain_type}}).filter(a=>a))==null?void 0:e[0]},P3=i=>{var e;return(e=i.map(a=>{if(a.type==="email")return{address:a.address,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]},S3=i=>{var e;return(e=i.map(a=>{if(a.type==="google_oauth")return{subject:a.subject,email:a.email,name:a.name,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]},I3=i=>{var e;return(e=i.map(a=>{if(a.type==="twitter_oauth")return{subject:a.subject,username:a.username,name:a.name,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]},R3=i=>{var e;return(e=i.map(a=>{if(a.type==="discord_oauth")return{subject:a.subject,username:a.username,email:a.email,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]};function k1(i){if(!i)return null;let e=P3(i.linked_accounts),a=T3(i.linked_accounts),l=S3(i.linked_accounts),r=I3(i.linked_accounts),C=R3(i.linked_accounts);return{id:i.id,createdAt:new Date(i.created_at*1e3),linkedAccounts:[...a?[a]:[],...e?[e]:[],...l?[l]:[],...r?[r]:[],...C?[C]:[]],email:e&&{address:e==null?void 0:e.address},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:r&&{subject:r.subject,username:r.username,name:r.name},discord:C&&{subject:C.subject,username:C.username,email:C.email}}}var a4=()=>"/api/v1/sessions",l4=()=>"/api/v1/sessions/logout",o4=()=>"/api/v1/siwe/init",r4=()=>"/api/v1/siwe/authenticate",n4=()=>"/api/v1/passwordless/init",C4=()=>"/api/v1/passwordless/authenticate",s4=()=>"/api/v1/oauth/init",d4=()=>"/api/v1/oauth/authenticate",c4=()=>"/api/v1/siwe/unlink",p4=()=>"/api/v1/passwordless/unlink";var W3=30,f2="privy:token",u2="privy:refresh_token",U1=class{constructor(){this.authenticateOnce=new b1(async e=>this._authenticate(e)),this.refreshOnce=new b1(this._refresh.bind(this)),this.destroyOnce=new b1(this._destroy.bind(this))}get token(){let e=j.get(f2);return typeof e=="string"?e:null}get refreshToken(){let e=j.get(u2);return typeof e=="string"?e:null}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=m1.parse(this.token);return e!==null&&!e.isExpired(W3)}authenticate(e){return this.authenticateOnce.execute(e)}refresh(){return this.refreshOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:a,refresh_token:l,user:r}=await e.authenticate();return a&&this.storeToken(a),l&&this.storeRefreshToken(l),k1(r)}catch(a){throw console.warn("Error authenticating session"),X(a)}}async _refresh(){if(!this.api)throw new b("Session has no API instance");let e=this.token,a=this.refreshToken;if(!e||!a)return null;try{let l=await this.api.post(a4(),{refresh_token:a});return this.storeToken(l.data.token),this.storeRefreshToken(l.data.refresh_token),k1(l.data.user)}catch(l){throw X(l)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(l4(),{})),this.destroyLocalState()}catch(a){throw console.warn("Error destroying session"),X(a)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?j.put(f2,e):j.del(f2)}storeRefreshToken(e){typeof e=="string"?j.put(u2,e):j.del(u2)}};var u4=require("@ethersproject/address"),g2=u(require("@walletconnect/web3-provider"));var M1=class{constructor(e){this.removeListener=(e,a)=>{if(this._provider)return this._provider.removeListener(e,a)};this.setProvider=e=>{this._provider=e,this._subscriptions.forEach(a=>{var l;(l=this._provider)==null||l.on(a.eventName,a.listener)})};this._provider=e,this._subscriptions=[]}on(e,a){if(this._provider)return this._provider.on(e,a);this._subscriptions.push({eventName:e,listener:a})}request(e){if(!this._provider)throw new V(`A wallet request of type ${e.method} was made to a disconnected wallet: `);return this._provider.request(e)}},g1=class extends M1{constructor(a){super(a)}},F1=class extends M1{constructor(e){super(e)}sendAsync(e,a){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var m4=require("ethers");var h4=["metamask","coinbase_wallet","wallet_connect"];var f4=require("ethers");var V1=class extends V{constructor(){super("Wallet timeout");this.type="wallet_error"}},b2=i=>{if(i instanceof V)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new w1(i);return i.code===f4.ethers.errors.ACTION_REJECTED&&(e.details=c1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new w1(i):new V("Unknown connector error",i)},m2=class extends l1{constructor(a,l,r){super(a);this.type="provider_error";this.code=l,this.data=r}},w1=class extends m2{constructor(a){var C,h,M;let l=a;super(l.message,l.code,l.data);let r=Object.values(c1).find(g=>g.eipCode===l.code);this.details=r||c1.UNKNOWN_ERROR,l.code===-32002&&((C=l.message)!=null&&C.includes("already pending for origin")?(h=l.message)!=null&&h.includes("wallet_requestPermissions")?this.details=c1.E32002_CONNECTION_ALREADY_PENDING:this.details=c1.E32002_REQUEST_ALREADY_PENDING:(M=l.message)!=null&&M.includes("Already processing")&&l.message.includes("eth_requestAccounts")&&(this.details=c1.E32002_WALLET_LOCKED))}},O3={ERROR_USER_EXISTS:{message:"User already exists for this address",detail:"Try another address!",retryable:!1},ERROR_TIMED_OUT:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0},ERROR_WALLET_CONNECTION:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0}},N3={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}},D3={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}},c1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...D3,...N3},k2={...O3,...c1};var M2="privy:wallet_type",H1=(i=new V1,e=e4)=>new Promise((a,l)=>setTimeout(()=>{l(i)},e)),w2=()=>{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},y2=()=>{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},B1=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,a,l,r,C,h,M)=>`${l} wants you to sign in with your Ethereum account:
|
|
1
|
+
"use strict";var w3=Object.create;var W1=Object.defineProperty;var y3=Object.getOwnPropertyDescriptor;var Z3=Object.getOwnPropertyNames;var v3=Object.getPrototypeOf,L3=Object.prototype.hasOwnProperty;var x3=(i,e)=>{for(var a in e)W1(i,a,{get:e[a],enumerable:!0})},K2=(i,e,a,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Z3(e))!L3.call(i,r)&&r!==a&&W1(i,r,{get:()=>e[r],enumerable:!(l=y3(e,r))||l.enumerable});return i};var u=(i,e,a)=>(a=i!=null?w3(v3(i)):{},K2(e||!i||!i.__esModule?W1(a,"default",{value:i,enumerable:!0}):a,i)),E3=i=>K2(W1({},"__esModule",{value:!0}),i);var T5={};x3(T5,{PrivyProvider:()=>M3,usePrivy:()=>_});module.exports=E3(T5);var U=require("react");var N1=u(require("axios"));var Y2=u(require("axios")),l1=class extends Error{constructor(a,l){super(a);l instanceof Error&&(this.cause=l)}toString(){return`${this.type}: ${this.message}`}},O1=class extends l1{constructor(a,l,r,C){super(r,C);this.type=a;this.status=l}},b=class extends l1{constructor(a,l){super(a,l);this.type="client_error"}};var V=class extends l1{constructor(a,l){super(a,l);this.type="connector_error"}},H=i=>{if(!Y2.default.isAxiosError(i))return X(i);if(!i.response)return new O1("api_error",null,i.message,i);let{type:e,message:a,error:l}=i.response.data;return new O1(e||"ApiError",i.response.status,a||l,i)},X=i=>i instanceof l1?i:i instanceof Error?new b(i.message,i):new b(`Internal error: ${i}`);var J2="1.5.0-beta.15";var D1=class{constructor(e,a,l){this.appId=e,this.sdkVersion=J2,this.session=a,this.defaults=l}async get(e,a){try{return await N1.default.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...a}))}catch(l){throw H(l)}}async post(e,a,l){try{return await N1.default.post(e,a,this.buildConfig(l))}catch(r){throw H(r)}}async delete(e,a){try{return await N1.default.delete(e,this.buildConfig(a))}catch(l){throw H(l)}}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 X2="https://api.privy.io/v0",Q2=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",c2="70f97dc579834350a5baec117b3c5ae3",t4=1e4,o1=1200,e4=3e4;var i4=u(require("jwt-decode")),m1=class{static parse(e){try{return new m1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=(0,i4.default)(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}isExpired(e=0){let a=Date.now(),l=(this.expiration-e)*1e3;return a>=l}};var b1=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 p2=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,a){a!==void 0?this._cache[e]=a:this.del(e)}del(e){delete this._cache[e]}},h2=class{get(e){let a=localStorage.getItem(e);return a===null?void 0:JSON.parse(a)}put(e,a){a!==void 0?localStorage.setItem(e,JSON.stringify(a)):this.del(e)}del(e){localStorage.removeItem(e)}};function _3(){return typeof window<"u"&&window.localStorage?new h2:new p2}var j=_3();var T3=i=>{var e;return(e=i.map(a=>{if(a.type==="wallet")return{address:a.address,type:a.type,verifiedAt:new Date(a.verified_at*1e3),chainType:a.chain_type}}).filter(a=>a))==null?void 0:e[0]},P3=i=>{var e;return(e=i.map(a=>{if(a.type==="email")return{address:a.address,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]},S3=i=>{var e;return(e=i.map(a=>{if(a.type==="google_oauth")return{subject:a.subject,email:a.email,name:a.name,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]},I3=i=>{var e;return(e=i.map(a=>{if(a.type==="twitter_oauth")return{subject:a.subject,username:a.username,name:a.name,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]},R3=i=>{var e;return(e=i.map(a=>{if(a.type==="discord_oauth")return{subject:a.subject,username:a.username,email:a.email,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]};function k1(i){if(!i)return null;let e=P3(i.linked_accounts),a=T3(i.linked_accounts),l=S3(i.linked_accounts),r=I3(i.linked_accounts),C=R3(i.linked_accounts);return{id:i.id,createdAt:new Date(i.created_at*1e3),linkedAccounts:[...a?[a]:[],...e?[e]:[],...l?[l]:[],...r?[r]:[],...C?[C]:[]],email:e&&{address:e==null?void 0:e.address},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:r&&{subject:r.subject,username:r.username,name:r.name},discord:C&&{subject:C.subject,username:C.username,email:C.email}}}var a4=()=>"/api/v1/sessions",l4=()=>"/api/v1/sessions/logout",o4=()=>"/api/v1/siwe/init",r4=()=>"/api/v1/siwe/authenticate",n4=()=>"/api/v1/passwordless/init",C4=()=>"/api/v1/passwordless/authenticate",s4=()=>"/api/v1/oauth/init",d4=()=>"/api/v1/oauth/authenticate",c4=()=>"/api/v1/siwe/unlink",p4=()=>"/api/v1/passwordless/unlink";var W3=30,f2="privy:token",u2="privy:refresh_token",U1=class{constructor(){this.authenticateOnce=new b1(async e=>this._authenticate(e)),this.refreshOnce=new b1(this._refresh.bind(this)),this.destroyOnce=new b1(this._destroy.bind(this))}get token(){let e=j.get(f2);return typeof e=="string"?e:null}get refreshToken(){let e=j.get(u2);return typeof e=="string"?e:null}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=m1.parse(this.token);return e!==null&&!e.isExpired(W3)}authenticate(e){return this.authenticateOnce.execute(e)}refresh(){return this.refreshOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:a,refresh_token:l,user:r}=await e.authenticate();return a&&this.storeToken(a),l&&this.storeRefreshToken(l),k1(r)}catch(a){throw console.warn("Error authenticating session"),X(a)}}async _refresh(){if(!this.api)throw new b("Session has no API instance");let e=this.token,a=this.refreshToken;if(!e||!a)return null;try{let l=await this.api.post(a4(),{refresh_token:a});return this.storeToken(l.data.token),this.storeRefreshToken(l.data.refresh_token),k1(l.data.user)}catch(l){throw X(l)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(l4(),{})),this.destroyLocalState()}catch(a){throw console.warn("Error destroying session"),X(a)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?j.put(f2,e):j.del(f2)}storeRefreshToken(e){typeof e=="string"?j.put(u2,e):j.del(u2)}};var u4=require("@ethersproject/address"),g2=u(require("@walletconnect/web3-provider"));var M1=class{constructor(e){this.removeListener=(e,a)=>{if(this._provider)return this._provider.removeListener(e,a)};this.setProvider=e=>{this._provider=e,this._subscriptions.forEach(a=>{var l;(l=this._provider)==null||l.on(a.eventName,a.listener)})};this._provider=e,this._subscriptions=[]}on(e,a){if(this._provider)return this._provider.on(e,a);this._subscriptions.push({eventName:e,listener:a})}request(e){if(!this._provider)throw new V(`A wallet request of type ${e.method} was made to a disconnected wallet: `);return this._provider.request(e)}},g1=class extends M1{constructor(a){super(a)}},F1=class extends M1{constructor(e){super(e)}sendAsync(e,a){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};var m4=require("ethers");var h4=["metamask","coinbase_wallet","wallet_connect"];var f4=require("ethers");var V1=class extends V{constructor(){super("Wallet timeout");this.type="wallet_error"}},b2=i=>{if(i instanceof V)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new w1(i);return i.code===f4.ethers.errors.ACTION_REJECTED&&(e.details=c1.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new w1(i):new V("Unknown connector error",i)},m2=class extends l1{constructor(a,l,r){super(a);this.type="provider_error";this.code=l,this.data=r}},w1=class extends m2{constructor(a){var C,h,M;let l=a;super(l.message,l.code,l.data);let r=Object.values(c1).find(g=>g.eipCode===l.code);this.details=r||c1.UNKNOWN_ERROR,l.code===-32002&&((C=l.message)!=null&&C.includes("already pending for origin")?(h=l.message)!=null&&h.includes("wallet_requestPermissions")?this.details=c1.E32002_CONNECTION_ALREADY_PENDING:this.details=c1.E32002_REQUEST_ALREADY_PENDING:(M=l.message)!=null&&M.includes("Already processing")&&l.message.includes("eth_requestAccounts")&&(this.details=c1.E32002_WALLET_LOCKED))}},O3={ERROR_USER_EXISTS:{message:"User already exists for this address",detail:"Try another address!",retryable:!1},ERROR_TIMED_OUT:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0},ERROR_WALLET_CONNECTION:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0}},N3={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}},D3={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}},c1={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...D3,...N3},k2={...O3,...c1};var M2="privy:wallet_type",H1=(i=new V1,e=e4)=>new Promise((a,l)=>setTimeout(()=>{l(i)},e)),w2=()=>{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},y2=()=>{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},B1=class{constructor(){this.walletType=null;this.getEthereumProvider=()=>this.ethProvider;this.createSiweMessage=(e,a,l,r,C,h,M)=>`${l} wants you to sign in with your Ethereum account:
|
|
2
2
|
${a}
|
|
3
3
|
|
|
4
4
|
${M}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{useEffect as t2,useState as a1}from"react";import l2 from"axios";import s3 from"axios";var G=class extends Error{constructor(a,l){super(a);l instanceof Error&&(this.cause=l)}toString(){return`${this.type}: ${this.message}`}},Z1=class extends G{constructor(a,l,o,n){super(o,n);this.type=a;this.status=l}},u=class extends G{constructor(a,l){super(a,l);this.type="client_error"}};var R=class extends G{constructor(a,l){super(a,l);this.type="connector_error"}},W=i=>{if(!s3.isAxiosError(i))return V(i);if(!i.response)return new Z1("api_error",null,i.message,i);let{type:e,message:a,error:l}=i.response.data;return new Z1(e||"ApiError",i.response.status,a||l,i)},V=i=>i instanceof G?i:i instanceof Error?new u(i.message,i):new u(`Internal error: ${i}`);var N2="1.5.0-beta.14";var v1=class{constructor(e,a,l){this.appId=e,this.sdkVersion=N2,this.session=a,this.defaults=l}async get(e,a){try{return await l2.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...a}))}catch(l){throw W(l)}}async post(e,a,l){try{return await l2.post(e,a,this.buildConfig(l))}catch(o){throw W(o)}}async delete(e,a){try{return await l2.delete(e,this.buildConfig(a))}catch(l){throw W(l)}}buildConfig(e){return e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-sdk-version"]=`react-auth-${this.sdkVersion}`,this.session.token!==null&&(e.headers.authorization=`Bearer ${this.session.token}`),{...this.defaults,...e}}};var D2="https://api.privy.io/v0",U2=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",o2="70f97dc579834350a5baec117b3c5ae3",F2=1e4,j=1200,V2=3e4;import c3 from"jwt-decode";var l1=class{static parse(e){try{return new l1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=c3(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}isExpired(e=0){let a=Date.now(),l=(this.expiration-e)*1e3;return a>=l}};var o1=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 r2=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,a){a!==void 0?this._cache[e]=a:this.del(e)}del(e){delete this._cache[e]}},n2=class{get(e){let a=localStorage.getItem(e);return a===null?void 0:JSON.parse(a)}put(e,a){a!==void 0?localStorage.setItem(e,JSON.stringify(a)):this.del(e)}del(e){localStorage.removeItem(e)}};function p3(){return typeof window<"u"&&window.localStorage?new n2:new r2}var N=p3();var h3=i=>{var e;return(e=i.map(a=>{if(a.type==="wallet")return{address:a.address,type:a.type,verifiedAt:new Date(a.verified_at*1e3),chainType:a.chain_type}}).filter(a=>a))==null?void 0:e[0]},f3=i=>{var e;return(e=i.map(a=>{if(a.type==="email")return{address:a.address,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]},u3=i=>{var e;return(e=i.map(a=>{if(a.type==="google_oauth")return{subject:a.subject,email:a.email,name:a.name,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]},m3=i=>{var e;return(e=i.map(a=>{if(a.type==="twitter_oauth")return{subject:a.subject,username:a.username,name:a.name,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]},b3=i=>{var e;return(e=i.map(a=>{if(a.type==="discord_oauth")return{subject:a.subject,username:a.username,email:a.email,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]};function r1(i){if(!i)return null;let e=f3(i.linked_accounts),a=h3(i.linked_accounts),l=u3(i.linked_accounts),o=m3(i.linked_accounts),n=b3(i.linked_accounts);return{id:i.id,createdAt:new Date(i.created_at*1e3),linkedAccounts:[...a?[a]:[],...e?[e]:[],...l?[l]:[],...o?[o]:[],...n?[n]:[]],email:e&&{address:e==null?void 0:e.address},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:o&&{subject:o.subject,username:o.username,name:o.name},discord:n&&{subject:n.subject,username:n.username,email:n.email}}}var H2=()=>"/api/v1/sessions",B2=()=>"/api/v1/sessions/logout",G2=()=>"/api/v1/siwe/init",j2=()=>"/api/v1/siwe/authenticate",z2=()=>"/api/v1/passwordless/init",$2=()=>"/api/v1/passwordless/authenticate",q2=()=>"/api/v1/oauth/init",K2=()=>"/api/v1/oauth/authenticate",Y2=()=>"/api/v1/siwe/unlink",J2=()=>"/api/v1/passwordless/unlink";var k3=30,C2="privy:token",s2="privy:refresh_token",L1=class{constructor(){this.authenticateOnce=new o1(async e=>this._authenticate(e)),this.refreshOnce=new o1(this._refresh.bind(this)),this.destroyOnce=new o1(this._destroy.bind(this))}get token(){let e=N.get(C2);return typeof e=="string"?e:null}get refreshToken(){let e=N.get(s2);return typeof e=="string"?e:null}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=l1.parse(this.token);return e!==null&&!e.isExpired(k3)}authenticate(e){return this.authenticateOnce.execute(e)}refresh(){return this.refreshOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:a,refresh_token:l,user:o}=await e.authenticate();return a&&this.storeToken(a),l&&this.storeRefreshToken(l),r1(o)}catch(a){throw console.warn("Error authenticating session"),V(a)}}async _refresh(){if(!this.api)throw new u("Session has no API instance");let e=this.token,a=this.refreshToken;if(!e||!a)return null;try{let l=await this.api.post(H2(),{refresh_token:a});return this.storeToken(l.data.token),this.storeRefreshToken(l.data.refresh_token),r1(l.data.user)}catch(l){throw V(l)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(B2(),{})),this.destroyLocalState()}catch(a){throw console.warn("Error destroying session"),V(a)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?N.put(C2,e):N.del(C2)}storeRefreshToken(e){typeof e=="string"?N.put(s2,e):N.del(s2)}};import{getAddress as Z3}from"@ethersproject/address";import Q2 from"@walletconnect/web3-provider";var n1=class{constructor(e){this.removeListener=(e,a)=>{if(this._provider)return this._provider.removeListener(e,a)};this.setProvider=e=>{this._provider=e,this._subscriptions.forEach(a=>{var l;(l=this._provider)==null||l.on(a.eventName,a.listener)})};this._provider=e,this._subscriptions=[]}on(e,a){if(this._provider)return this._provider.on(e,a);this._subscriptions.push({eventName:e,listener:a})}request(e){if(!this._provider)throw new R(`A wallet request of type ${e.method} was made to a disconnected wallet: `);return this._provider.request(e)}},C1=class extends n1{constructor(a){super(a)}},x1=class extends n1{constructor(e){super(e)}sendAsync(e,a){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};import{providers as v3}from"ethers";var X2=["metamask","coinbase_wallet","wallet_connect"];import{ethers as M3}from"ethers";var E1=class extends R{constructor(){super("Wallet timeout");this.type="wallet_error"}},c2=i=>{if(i instanceof R)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new s1(i);return i.code===M3.errors.ACTION_REJECTED&&(e.details=J.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new s1(i):new R("Unknown connector error",i)},d2=class extends G{constructor(a,l,o){super(a);this.type="provider_error";this.code=l,this.data=o}},s1=class extends d2{constructor(a){var n,p,b;let l=a;super(l.message,l.code,l.data);let o=Object.values(J).find(k=>k.eipCode===l.code);this.details=o||J.UNKNOWN_ERROR,l.code===-32002&&((n=l.message)!=null&&n.includes("already pending for origin")?(p=l.message)!=null&&p.includes("wallet_requestPermissions")?this.details=J.E32002_CONNECTION_ALREADY_PENDING:this.details=J.E32002_REQUEST_ALREADY_PENDING:(b=l.message)!=null&&b.includes("Already processing")&&l.message.includes("eth_requestAccounts")&&(this.details=J.E32002_WALLET_LOCKED))}},g3={ERROR_USER_EXISTS:{message:"User already exists for this address",detail:"Try another address!",retryable:!1},ERROR_TIMED_OUT:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0},ERROR_WALLET_CONNECTION:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0}},w3={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}},y3={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}},J={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...y3,...w3},p2={...g3,...J};var h2="privy:wallet_type",A1=(i=new E1,e=V2)=>new Promise((a,l)=>setTimeout(()=>{l(i)},e)),f2=()=>{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},u2=()=>{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,a,l,o,n,p,b)=>`${l} wants you to sign in with your Ethereum account:
|
|
1
|
+
import{useEffect as t2,useState as a1}from"react";import l2 from"axios";import s3 from"axios";var G=class extends Error{constructor(a,l){super(a);l instanceof Error&&(this.cause=l)}toString(){return`${this.type}: ${this.message}`}},Z1=class extends G{constructor(a,l,o,n){super(o,n);this.type=a;this.status=l}},u=class extends G{constructor(a,l){super(a,l);this.type="client_error"}};var R=class extends G{constructor(a,l){super(a,l);this.type="connector_error"}},W=i=>{if(!s3.isAxiosError(i))return V(i);if(!i.response)return new Z1("api_error",null,i.message,i);let{type:e,message:a,error:l}=i.response.data;return new Z1(e||"ApiError",i.response.status,a||l,i)},V=i=>i instanceof G?i:i instanceof Error?new u(i.message,i):new u(`Internal error: ${i}`);var N2="1.5.0-beta.15";var v1=class{constructor(e,a,l){this.appId=e,this.sdkVersion=N2,this.session=a,this.defaults=l}async get(e,a){try{return await l2.get(e,this.buildConfig({headers:{"Cache-Control":"no-cache"},...a}))}catch(l){throw W(l)}}async post(e,a,l){try{return await l2.post(e,a,this.buildConfig(l))}catch(o){throw W(o)}}async delete(e,a){try{return await l2.delete(e,this.buildConfig(a))}catch(l){throw W(l)}}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 D2="https://api.privy.io/v0",U2=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",o2="70f97dc579834350a5baec117b3c5ae3",F2=1e4,j=1200,V2=3e4;import c3 from"jwt-decode";var l1=class{static parse(e){try{return new l1(e)}catch{return null}}constructor(e){this.value=e,this._decoded=c3(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}isExpired(e=0){let a=Date.now(),l=(this.expiration-e)*1e3;return a>=l}};var o1=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 r2=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,a){a!==void 0?this._cache[e]=a:this.del(e)}del(e){delete this._cache[e]}},n2=class{get(e){let a=localStorage.getItem(e);return a===null?void 0:JSON.parse(a)}put(e,a){a!==void 0?localStorage.setItem(e,JSON.stringify(a)):this.del(e)}del(e){localStorage.removeItem(e)}};function p3(){return typeof window<"u"&&window.localStorage?new n2:new r2}var N=p3();var h3=i=>{var e;return(e=i.map(a=>{if(a.type==="wallet")return{address:a.address,type:a.type,verifiedAt:new Date(a.verified_at*1e3),chainType:a.chain_type}}).filter(a=>a))==null?void 0:e[0]},f3=i=>{var e;return(e=i.map(a=>{if(a.type==="email")return{address:a.address,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]},u3=i=>{var e;return(e=i.map(a=>{if(a.type==="google_oauth")return{subject:a.subject,email:a.email,name:a.name,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]},m3=i=>{var e;return(e=i.map(a=>{if(a.type==="twitter_oauth")return{subject:a.subject,username:a.username,name:a.name,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]},b3=i=>{var e;return(e=i.map(a=>{if(a.type==="discord_oauth")return{subject:a.subject,username:a.username,email:a.email,type:a.type,verifiedAt:new Date(a.verified_at*1e3)}}).filter(a=>a))==null?void 0:e[0]};function r1(i){if(!i)return null;let e=f3(i.linked_accounts),a=h3(i.linked_accounts),l=u3(i.linked_accounts),o=m3(i.linked_accounts),n=b3(i.linked_accounts);return{id:i.id,createdAt:new Date(i.created_at*1e3),linkedAccounts:[...a?[a]:[],...e?[e]:[],...l?[l]:[],...o?[o]:[],...n?[n]:[]],email:e&&{address:e==null?void 0:e.address},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:o&&{subject:o.subject,username:o.username,name:o.name},discord:n&&{subject:n.subject,username:n.username,email:n.email}}}var H2=()=>"/api/v1/sessions",B2=()=>"/api/v1/sessions/logout",G2=()=>"/api/v1/siwe/init",j2=()=>"/api/v1/siwe/authenticate",z2=()=>"/api/v1/passwordless/init",$2=()=>"/api/v1/passwordless/authenticate",q2=()=>"/api/v1/oauth/init",K2=()=>"/api/v1/oauth/authenticate",Y2=()=>"/api/v1/siwe/unlink",J2=()=>"/api/v1/passwordless/unlink";var k3=30,C2="privy:token",s2="privy:refresh_token",L1=class{constructor(){this.authenticateOnce=new o1(async e=>this._authenticate(e)),this.refreshOnce=new o1(this._refresh.bind(this)),this.destroyOnce=new o1(this._destroy.bind(this))}get token(){let e=N.get(C2);return typeof e=="string"?e:null}get refreshToken(){let e=N.get(s2);return typeof e=="string"?e:null}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=l1.parse(this.token);return e!==null&&!e.isExpired(k3)}authenticate(e){return this.authenticateOnce.execute(e)}refresh(){return this.refreshOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:a,refresh_token:l,user:o}=await e.authenticate();return a&&this.storeToken(a),l&&this.storeRefreshToken(l),r1(o)}catch(a){throw console.warn("Error authenticating session"),V(a)}}async _refresh(){if(!this.api)throw new u("Session has no API instance");let e=this.token,a=this.refreshToken;if(!e||!a)return null;try{let l=await this.api.post(H2(),{refresh_token:a});return this.storeToken(l.data.token),this.storeRefreshToken(l.data.refresh_token),r1(l.data.user)}catch(l){throw V(l)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(B2(),{})),this.destroyLocalState()}catch(a){throw console.warn("Error destroying session"),V(a)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?N.put(C2,e):N.del(C2)}storeRefreshToken(e){typeof e=="string"?N.put(s2,e):N.del(s2)}};import{getAddress as Z3}from"@ethersproject/address";import Q2 from"@walletconnect/web3-provider";var n1=class{constructor(e){this.removeListener=(e,a)=>{if(this._provider)return this._provider.removeListener(e,a)};this.setProvider=e=>{this._provider=e,this._subscriptions.forEach(a=>{var l;(l=this._provider)==null||l.on(a.eventName,a.listener)})};this._provider=e,this._subscriptions=[]}on(e,a){if(this._provider)return this._provider.on(e,a);this._subscriptions.push({eventName:e,listener:a})}request(e){if(!this._provider)throw new R(`A wallet request of type ${e.method} was made to a disconnected wallet: `);return this._provider.request(e)}},C1=class extends n1{constructor(a){super(a)}},x1=class extends n1{constructor(e){super(e)}sendAsync(e,a){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};import{providers as v3}from"ethers";var X2=["metamask","coinbase_wallet","wallet_connect"];import{ethers as M3}from"ethers";var E1=class extends R{constructor(){super("Wallet timeout");this.type="wallet_error"}},c2=i=>{if(i instanceof R)return i;if((i==null?void 0:i.code)&&(i==null?void 0:i.reason)){let e=new s1(i);return i.code===M3.errors.ACTION_REJECTED&&(e.details=J.E4001_USER_REJECTED_REQUEST),e}return i!=null&&i.code?new s1(i):new R("Unknown connector error",i)},d2=class extends G{constructor(a,l,o){super(a);this.type="provider_error";this.code=l,this.data=o}},s1=class extends d2{constructor(a){var n,p,b;let l=a;super(l.message,l.code,l.data);let o=Object.values(J).find(k=>k.eipCode===l.code);this.details=o||J.UNKNOWN_ERROR,l.code===-32002&&((n=l.message)!=null&&n.includes("already pending for origin")?(p=l.message)!=null&&p.includes("wallet_requestPermissions")?this.details=J.E32002_CONNECTION_ALREADY_PENDING:this.details=J.E32002_REQUEST_ALREADY_PENDING:(b=l.message)!=null&&b.includes("Already processing")&&l.message.includes("eth_requestAccounts")&&(this.details=J.E32002_WALLET_LOCKED))}},g3={ERROR_USER_EXISTS:{message:"User already exists for this address",detail:"Try another address!",retryable:!1},ERROR_TIMED_OUT:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0},ERROR_WALLET_CONNECTION:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0}},w3={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}},y3={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}},J={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...y3,...w3},p2={...g3,...J};var h2="privy:wallet_type",A1=(i=new E1,e=V2)=>new Promise((a,l)=>setTimeout(()=>{l(i)},e)),f2=()=>{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},u2=()=>{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,a,l,o,n,p,b)=>`${l} wants you to sign in with your Ethereum account:
|
|
2
2
|
${a}
|
|
3
3
|
|
|
4
4
|
${b}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@privy-io/react-auth",
|
|
3
|
-
"version": "1.5.0-beta.
|
|
3
|
+
"version": "1.5.0-beta.15",
|
|
4
4
|
"description": "React client for the Privy Auth API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authentication",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"README.md"
|
|
35
35
|
],
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build": "npx tsup --minify",
|
|
37
|
+
"build": "npx tsup --clean --minify",
|
|
38
38
|
"watch": "npx tsup --watch",
|
|
39
39
|
"clean": "rm -rf dist",
|
|
40
40
|
"prepublishOnly": "npm run clean && npm run build",
|