@privy-io/js-sdk-core 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +2047 -1
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.ts +50 -173
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2078 -1
- package/dist/index.js.map +1 -0
- package/package.json +14 -6
package/dist/esm/index.js
CHANGED
|
@@ -1 +1,2047 @@
|
|
|
1
|
-
var ne=(a,e,t)=>{if(!e.has(a))throw TypeError("Cannot "+t)};var r=(a,e,t)=>(ne(a,e,"read from private field"),t?t.call(a):e.get(a)),n=(a,e,t)=>{if(e.has(a))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(a):e.set(a,t)},o=(a,e,t,s)=>(ne(a,e,"write to private field"),s?s.call(a,t):e.set(a,t),t);var _=(a,e,t)=>(ne(a,e,"access private method"),t);import{TextEncoder as Et}from"text-encoding";import{logout as st}from"@privy-io/core-api";import{authenticateCustomJwtAccount as Ve}from"@privy-io/core-api";var w,A=class{constructor(e){n(this,w,void 0);o(this,w,e)}async syncWithToken(e){let t=await r(this,w).fetch(Ve,{body:{token:e}});return r(this,w).session.storeToken(t.token),r(this,w).session.storeRefreshToken(t.refresh_token),t}};w=new WeakMap;import{passwordlessAuthenticate as ze,passwordlessInit as Ye,passwordlessLink as Qe,passwordlessUnlink as Xe}from"@privy-io/core-api";var y,q=class{constructor(e){n(this,y,void 0);o(this,y,e)}async sendCode(e,t){return r(this,y).fetch(Ye,{body:{email:e,token:t}})}async loginWithCode(e,t){let s=await r(this,y).fetch(ze,{body:{email:e,code:t}});return r(this,y).session.storeToken(s.token),r(this,y).session.storeRefreshToken(s.refresh_token),s}async linkWithCode(e,t){return r(this,y).fetch(Qe,{body:{email:e,code:t}})}async unlink(e){return r(this,y).fetch(Xe,{body:{address:e}})}};y=new WeakMap;import{passwordlessSmsAuthenticate as Ze,passwordlessSmsInit as et,passwordlessSmsLink as tt,passwordlessSmsUnlink as rt}from"@privy-io/core-api";var m,U=class{constructor(e){n(this,m,void 0);o(this,m,e)}async sendCode(e,t){return r(this,m).fetch(et,{body:{phoneNumber:e,token:t}})}async loginWithCode(e,t){let s=await r(this,m).fetch(Ze,{body:{phoneNumber:e,code:t}});return r(this,m).session.storeToken(s.token),r(this,m).session.storeRefreshToken(s.refresh_token),s}async linkWithCode(e,t){return r(this,m).fetch(tt,{body:{phoneNumber:e,code:t}})}async unlink(e){return r(this,m).fetch(rt,{body:{phoneNumber:e}})}};m=new WeakMap;var u,O=class{constructor(e){n(this,u,void 0);o(this,u,e),this.phone=new U(r(this,u)),this.email=new q(r(this,u)),this.customProvider=new A(r(this,u))}async logout(){try{await r(this,u).fetch(st,{body:{refresh_token:r(this,u).session.refreshToken??void 0}})}catch{console.warn("Error destroying session")}r(this,u).session.destroyLocalState()}};u=new WeakMap;var ue={id:42161,name:"Arbitrum One",network:"arbitrum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://arb-mainnet.g.alchemy.com/v2"],webSocket:["wss://arb-mainnet.g.alchemy.com/v2"]},infura:{http:["https://arbitrum-mainnet.infura.io/v3"],webSocket:["wss://arbitrum-mainnet.infura.io/ws/v3"]},default:{http:["https://arb1.arbitrum.io/rpc"]},public:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{etherscan:{name:"Arbiscan",url:"https://arbiscan.io"},default:{name:"Arbiscan",url:"https://arbiscan.io"}}};var ve={id:421613,name:"Arbitrum Goerli",network:"arbitrum-goerli",nativeCurrency:{name:"Goerli Ether",symbol:"AGOR",decimals:18},rpcUrls:{alchemy:{http:["https://arb-goerli.g.alchemy.com/v2"],webSocket:["wss://arb-goerli.g.alchemy.com/v2"]},infura:{http:["https://arbitrum-goerli.infura.io/v3"],webSocket:["wss://arbitrum-goerli.infura.io/ws/v3"]},default:{http:["https://goerli-rollup.arbitrum.io/rpc"]},public:{http:["https://goerli-rollup.arbitrum.io/rpc"]}},blockExplorers:{etherscan:{name:"Arbiscan",url:"https://goerli.arbiscan.io/"},default:{name:"Arbiscan",url:"https://goerli.arbiscan.io/"}},testnet:!0};var fe={id:43114,name:"Avalanche",network:"avalanche",nativeCurrency:{decimals:18,name:"Avalanche",symbol:"AVAX"},rpcUrls:{default:{http:["https://api.avax.network/ext/bc/C/rpc"]},public:{http:["https://api.avax.network/ext/bc/C/rpc"]}},blockExplorers:{etherscan:{name:"SnowTrace",url:"https://snowtrace.io"},default:{name:"SnowTrace",url:"https://snowtrace.io"}}};var ge={id:43113,name:"Avalanche Fuji",network:"avalanche-fuji",nativeCurrency:{decimals:18,name:"Avalanche Fuji",symbol:"AVAX"},rpcUrls:{default:{http:["https://api.avax-test.network/ext/bc/C/rpc"]},public:{http:["https://api.avax-test.network/ext/bc/C/rpc"]}},blockExplorers:{etherscan:{name:"SnowTrace",url:"https://testnet.snowtrace.io"},default:{name:"SnowTrace",url:"https://testnet.snowtrace.io"}},testnet:!0};var be={id:8453,network:"base",name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{blast:{http:["https://base-mainnet.blastapi.io"],webSocket:["wss://base-mainnet.blastapi.io"]},default:{http:["https://mainnet.base.org"]},public:{http:["https://mainnet.base.org"]}},blockExplorers:{etherscan:{name:"Basescan",url:"https://basescan.org"},default:{name:"Basescan",url:"https://basescan.org"}},testnet:!0};var Re={id:84531,network:"base-goerli",name:"Base Goerli Testnet",nativeCurrency:{name:"Goerli Ether",symbol:"ETH",decimals:18},rpcUrls:{blast:{http:["https://base-goerli.blastapi.io"],webSocket:["wss://base-goerli.blastapi.io"]},default:{http:["https://goerli.base.org"]},public:{http:["https://goerli.base.org"]}},blockExplorers:{etherscan:{name:"Basescan",url:"https://goerli.basescan.org"},default:{name:"Basescan",url:"https://goerli.basescan.org"}},testnet:!0};var Te={id:42220,name:"Celo Mainnet",network:"celo",nativeCurrency:{decimals:18,name:"CELO",symbol:"CELO"},rpcUrls:{default:{http:["https://forno.celo.org"]},infura:{http:["https://celo-mainnet.infura.io/v3"]},public:{http:["https://forno.celo.org"]}},blockExplorers:{default:{name:"Celo Explorer",url:"https://explorer.celo.org/mainnet"},etherscan:{name:"CeloScan",url:"https://celoscan.io"}},testnet:!1};var we={id:44787,name:"Celo Alfajores Testnet",network:"celo-alfajores",nativeCurrency:{decimals:18,name:"CELO",symbol:"CELO"},rpcUrls:{default:{http:["https://alfajores-forno.celo-testnet.org"]},infura:{http:["https://celo-alfajores.infura.io/v3"]},public:{http:["https://alfajores-forno.celo-testnet.org"]}},blockExplorers:{default:{name:"Celo Explorer",url:"https://explorer.celo.org/alfajores"},etherscan:{name:"CeloScan",url:"https://alfajores.celoscan.io/"}},testnet:!0};var Ee={id:314,name:"Filecoin - Mainnet",network:"filecoin-mainnet",nativeCurrency:{decimals:18,name:"filecoin",symbol:"FIL"},rpcUrls:{default:{http:["https://api.node.glif.io/rpc/v1"]},public:{http:["https://api.node.glif.io/rpc/v1"]}},blockExplorers:{default:{name:"Filfox",url:"https://filfox.info/en"},filscan:{name:"Filscan",url:"https://filscan.io"},filscout:{name:"Filscout",url:"https://filscout.io/en"},glif:{name:"Glif",url:"https://explorer.glif.io"}}};var ke={id:314159,name:"Filecoin - Calibration testnet",network:"filecoin-calibration",nativeCurrency:{decimals:18,name:"testnet filecoin",symbol:"tFIL"},rpcUrls:{default:{http:["https://api.calibration.node.glif.io/rpc/v1"]},public:{http:["https://api.calibration.node.glif.io/rpc/v1"]}},blockExplorers:{default:{name:"Filscan",url:"https://calibration.filscan.io"}}};var Pe={id:5,network:"goerli",name:"Goerli",nativeCurrency:{name:"Goerli Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://eth-goerli.g.alchemy.com/v2"],webSocket:["wss://eth-goerli.g.alchemy.com/v2"]},infura:{http:["https://goerli.infura.io/v3"],webSocket:["wss://goerli.infura.io/ws/v3"]},default:{http:["https://rpc.ankr.com/eth_goerli"]},public:{http:["https://rpc.ankr.com/eth_goerli"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://goerli.etherscan.io"},default:{name:"Etherscan",url:"https://goerli.etherscan.io"}},testnet:!0};var _e={id:59144,network:"linea-mainnet",name:"Linea Mainnet",nativeCurrency:{name:"Linea Ether",symbol:"ETH",decimals:18},rpcUrls:{infura:{http:["https://linea-mainnet.infura.io/v3"],webSocket:["wss://linea-mainnet.infura.io/ws/v3"]},default:{http:["https://rpc.linea.build"],webSocket:["wss://rpc.linea.build"]},public:{http:["https://rpc.linea.build"],webSocket:["wss://rpc.linea.build"]}},blockExplorers:{default:{name:"Etherscan",url:"https://lineascan.build"},etherscan:{name:"Etherscan",url:"https://lineascan.build"}},testnet:!1};var Ce={id:59140,network:"linea-testnet",name:"Linea Goerli Testnet",nativeCurrency:{name:"Linea Ether",symbol:"ETH",decimals:18},rpcUrls:{infura:{http:["https://linea-goerli.infura.io/v3"],webSocket:["wss://linea-goerli.infura.io/ws/v3"]},default:{http:["https://rpc.goerli.linea.build"],webSocket:["wss://rpc.goerli.linea.build"]},public:{http:["https://rpc.goerli.linea.build"],webSocket:["wss://rpc.goerli.linea.build"]}},blockExplorers:{default:{name:"Etherscan",url:"https://goerli.lineascan.build"},etherscan:{name:"Etherscan",url:"https://goerli.lineascan.build"}},testnet:!0};var xe={id:1,network:"homestead",name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://eth-mainnet.g.alchemy.com/v2"],webSocket:["wss://eth-mainnet.g.alchemy.com/v2"]},infura:{http:["https://mainnet.infura.io/v3"],webSocket:["wss://mainnet.infura.io/ws/v3"]},default:{http:["https://cloudflare-eth.com"]},public:{http:["https://cloudflare-eth.com"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://etherscan.io"},default:{name:"Etherscan",url:"https://etherscan.io"}}};var Ie={id:10,name:"OP Mainnet",network:"optimism",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://opt-mainnet.g.alchemy.com/v2"],webSocket:["wss://opt-mainnet.g.alchemy.com/v2"]},infura:{http:["https://optimism-mainnet.infura.io/v3"],webSocket:["wss://optimism-mainnet.infura.io/ws/v3"]},default:{http:["https://mainnet.optimism.io"]},public:{http:["https://mainnet.optimism.io"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://optimistic.etherscan.io"},default:{name:"Optimism Explorer",url:"https://explorer.optimism.io"}}};var Se={id:420,name:"Optimism Goerli Testnet",network:"optimism-goerli",nativeCurrency:{name:"Goerli Ether",symbol:"ETH",decimals:18},rpcUrls:{alchemy:{http:["https://opt-goerli.g.alchemy.com/v2"],webSocket:["wss://opt-goerli.g.alchemy.com/v2"]},infura:{http:["https://optimism-goerli.infura.io/v3"],webSocket:["wss://optimism-goerli.infura.io/ws/v3"]},default:{http:["https://goerli.optimism.io"]},public:{http:["https://goerli.optimism.io"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://goerli-optimism.etherscan.io"},default:{name:"Etherscan",url:"https://goerli-optimism.etherscan.io"}},testnet:!0};var We={id:137,name:"Polygon Mainnet",network:"matic",nativeCurrency:{name:"MATIC",symbol:"MATIC",decimals:18},rpcUrls:{alchemy:{http:["https://polygon-mainnet.g.alchemy.com/v2"],webSocket:["wss://polygon-mainnet.g.alchemy.com/v2"]},infura:{http:["https://polygon-mainnet.infura.io/v3"],webSocket:["wss://polygon-mainnet.infura.io/ws/v3"]},default:{http:["https://polygon-rpc.com"]},public:{http:["https://polygon-rpc.com"]}},blockExplorers:{etherscan:{name:"PolygonScan",url:"https://polygonscan.com"},default:{name:"PolygonScan",url:"https://polygonscan.com"}}};var De={id:80001,name:"Mumbai",network:"maticmum",nativeCurrency:{name:"MATIC",symbol:"MATIC",decimals:18},rpcUrls:{alchemy:{http:["https://polygon-mumbai.g.alchemy.com/v2"],webSocket:["wss://polygon-mumbai.g.alchemy.com/v2"]},infura:{http:["https://polygon-mumbai.infura.io/v3"],webSocket:["wss://polygon-mumbai.infura.io/ws/v3"]},default:{http:["https://matic-mumbai.chainstacklabs.com"]},public:{http:["https://matic-mumbai.chainstacklabs.com"]}},blockExplorers:{etherscan:{name:"PolygonScan",url:"https://mumbai.polygonscan.com"},default:{name:"PolygonScan",url:"https://mumbai.polygonscan.com"}},testnet:!0};var Ae={id:11155111,network:"sepolia",name:"Sepolia",nativeCurrency:{name:"Sepolia Ether",symbol:"SEP",decimals:18},rpcUrls:{alchemy:{http:["https://eth-sepolia.g.alchemy.com/v2"],webSocket:["wss://eth-sepolia.g.alchemy.com/v2"]},infura:{http:["https://sepolia.infura.io/v3"],webSocket:["wss://sepolia.infura.io/ws/v3"]},default:{http:["https://rpc.sepolia.org"]},public:{http:["https://rpc.sepolia.org"]}},blockExplorers:{etherscan:{name:"Etherscan",url:"https://sepolia.etherscan.io"},default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}},testnet:!0};var oe=[ue,ve,Pe,Ae,xe,Ie,Se,We,De,Te,we,Ee,ke,be,Re,_e,Ce,fe,ge],kr=new Set(oe.map(a=>a.id));import{StaticJsonRpcProvider as Me}from"@ethersproject/providers";import lt from"eventemitter3";var qe=["error","invalid_request_arguments","wallet_not_on_device","invalid_recovery_pin","insufficient_funds"];var ie=class extends Error{constructor(t,s,i){super(t);s instanceof Error&&(this.cause=s),this.privyErrorCode=i}toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}};var g=class extends Error{constructor(t,s){super(s);this.type=t}},M=class extends ie{constructor(t,s,i){super(t,s,i);this.type="connector_error"}},N=class extends Error{constructor(t,s,i){super(t);this.code=s,this.data=i}};function at(a){let e=a.type;return typeof e=="string"&&qe.includes(e)}function pe(a){return at(a)&&a.type==="wallet_not_on_device"}var nt=["eth_accounts","eth_requestAccounts","eth_chainId","eth_estimateGas","wallet_switchEthereumChain"],ot=["eth_sign","eth_populateTransactionRequest","eth_signTransaction","personal_sign","eth_signTypedData_v4"],Ue=a=>ot.includes(a),Oe=a=>nt.includes(a);var it="4df5e2316331463a9130964bd6078dfa",pt="fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d",le=(a,e,t)=>{let s=Number(a),i=e.find(l=>l.id===s);if(!i)throw new M(`Unsupported chainId ${a}`,4901);let p;if(t.rpcUrls[s]?p=t.rpcUrls[s]:i.rpcUrls.infura?.http[0]?p=i.rpcUrls.infura.http[0]+"/"+it:i.rpcUrls.blast?.http[0]?p=i.rpcUrls.blast.http[0]+"/"+pt:p=i.rpcUrls.default?.http[0],!p)throw new M(`No RPC url found for ${a}`);return p};var j,L,E,b,H,R,k=class extends lt{constructor({walletProxy:t,privyInternal:s,address:i,chains:p,chainId:l=1}){super();n(this,j,void 0);n(this,L,void 0);n(this,E,void 0);n(this,b,void 0);n(this,H,void 0);n(this,R,void 0);o(this,j,t),o(this,L,s),o(this,E,i),o(this,b,l),o(this,H,p),o(this,R,new Me(le(l,p,{rpcUrls:[]})))}async request(t){return Ue(t.method)?this.handleIFrameRpc(t):Oe(t.method)?this.handleStatic(t):t.method==="eth_estimateGas"?this.handleEstimateGas(t):this.handleJsonRpc(t)}async handleStatic(t){switch(t.method){case"eth_accounts":case"eth_requestAccounts":return r(this,E)?[r(this,E)]:[];case"eth_chainId":return`0x${r(this,b).toString(16)}`;case"wallet_switchEthereumChain":return this.handleSwitchEthereumChain(t)}}async handleEstimateGas(t){if(!t.params||!Array.isArray(t.params))throw new Error("Invalid params for eth_estimateGas");delete t.params[0].gasPrice,delete t.params[0].maxFeePerGas,delete t.params[0].maxPriorityFeePerGas;let s={...t.params[0],chainId:`0x${r(this,b).toString(16)}`};try{return await r(this,R).send("eth_estimateGas",[s])}catch{return delete s.from,await r(this,R).send("eth_estimateGas",[s])}}handleSwitchEthereumChain(t){if(!t.params||!Array.isArray(t.params))throw new N(`Invalid params for ${t.method}`,4200);let s;if(typeof t.params[0]=="string")s=t.params[0];else if("chainId"in t.params[0]&&typeof t.params[0].chainId=="string")s=t.params[0].chainId;else throw new N(`Invalid params for ${t.method}`,4200);o(this,b,Number(s)),o(this,R,new Me(le(r(this,b),r(this,H),{rpcUrls:[]}))),this.emit("chainChanged",s)}async handleIFrameRpc(t){try{let s=await r(this,L).getAccessToken();if(!s)throw new Error("Missing privy token. User must be logged in");return(await r(this,j).rpc({request:t,address:r(this,E),accessToken:s})).response.data}catch(s){throw console.error(s),new Error("Unable to make wallet request")}}async handleJsonRpc(t){return r(this,R).send(t.method,t.params??[])}};j=new WeakMap,L=new WeakMap,E=new WeakMap,b=new WeakMap,H=new WeakMap,R=new WeakMap;var X=class{constructor(){this.callbacks={}}enqueue(e,t){this.callbacks[e]=t}dequeue(e,t){let s=this.callbacks[t];if(!s)throw new Error(`cannot dequeue ${e} event: no event found for id ${t}`);switch(delete this.callbacks[t],e){case"privy:iframe:ready":return s;case"privy:wallet:create":return s;case"privy:wallet:connect":return s;case"privy:wallet:recover":return s;case"privy:wallet:rpc":return s;default:throw new Error(`invalid wallet event type ${e}`)}}};var F=15e3;function C(a){return a.error!==void 0}var ct=function(a){return()=>`id-${a++}`}(0),dt=(a,e)=>typeof e=="bigint"?e.toString():e,ht=(a,e)=>`${a}${JSON.stringify(e,dt)}`,yt=a=>new Promise(e=>{setTimeout(e,a)}),G=(a,e)=>Promise.race([a,new Promise((t,s)=>{setTimeout(s,e)})]),v,x=class{constructor(e){n(this,v,void 0);this.ready=!1,this.cache=new Map,this.eventCallbacks=new X,o(this,v,e)}async create(e,t=F){return await this.waitForReady(),G(this.invoke("privy:wallet:create",e,r(this,v)),t)}async connect(e,t=F){return await this.waitForReady(),G(this.invoke("privy:wallet:connect",e,r(this,v)),t)}async recover(e,t=F){return await this.waitForReady(),G(this.invoke("privy:wallet:recover",e,r(this,v)),t)}async setPassword(e,t=F){return await this.waitForReady(),G(this.invoke("privy:wallet:set-recovery-password",e,r(this,v)),t)}async rpc(e,t=F){return await this.waitForReady(),G(this.invoke("privy:wallet:rpc",e,r(this,v)),t)}handleEmbeddedWalletMessages(e){switch(e.event){case"privy:iframe:ready":let t=this.eventCallbacks.dequeue(e.event,e.id);return C(e)?t.reject(new g(e.error.type,e.error.message)):t.resolve(e.data);case"privy:wallet:create":let s=this.eventCallbacks.dequeue(e.event,e.id);return C(e)?s.reject(new g(e.error.type,e.error.message)):s.resolve(e.data);case"privy:wallet:connect":let i=this.eventCallbacks.dequeue(e.event,e.id);return C(e)?i.reject(new g(e.error.type,e.error.message)):i.resolve(e.data);case"privy:wallet:recover":let p=this.eventCallbacks.dequeue(e.event,e.id);return C(e)?p.reject(new g(e.error.type,e.error.message)):p.resolve(e.data);case"privy:wallet:rpc":let l=this.eventCallbacks.dequeue(e.event,e.id);return C(e)?l.reject(new g(e.error.type,e.error.message)):l.resolve(e.data);case"privy:wallet:set-recovery-password":let f=this.eventCallbacks.dequeue(e.event,e.id);return C(e)?f.reject(new g(e.error.type,e.error.message)):f.resolve(e.data)}}async waitForReady(){if(!this.ready)return new Promise(async(e,t)=>{for(;!this.ready;)this.invoke("privy:iframe:ready",{},r(this,v)).then(()=>{this.ready=!0,e(null)}).catch(t),await yt(150)})}async invoke(e,t,s){let i=ht(e,t);if(e==="privy:wallet:create"){let l=this.cache.get(i);if(l)return l}let p=new Promise((l,f)=>{let ae=ct();this.eventCallbacks.enqueue(ae,{resolve:l,reject:f}),s.postMessage({id:ae,event:e,data:t},"*")}).finally(()=>{this.cache.delete(i)});return this.cache.set(i,p),p}};v=new WeakMap;var d,c,I,B,ce,$=class{constructor(e,t){n(this,B);n(this,d,void 0);n(this,c,void 0);n(this,I,oe.map(e=>e));o(this,d,e),t&&o(this,c,new x(t))}setMessagePoster(e){o(this,c,new x(e))}async create(e){if(!r(this,c))throw new Error("Embedded wallet proxy not initialized");if(!e&&r(this,d).config?.embedded_wallet_config.require_user_password_on_create)throw new Error("Password not provided yet is required by App configuration");let t=await r(this,d).getAccessToken();if(!t)throw new Error("User must be logged in to create an embedded wallet");let{address:s}=await r(this,c).create({accessToken:t,recoveryPassword:e});if(!s)throw new Error("Failed to create wallet");return new k({address:s,privyInternal:r(this,d),chains:r(this,I),walletProxy:r(this,c)})}async getProvider(e){if(!r(this,c))throw new Error("Embedded wallet proxy not initialized");let t=await _(this,B,ce).call(this,e);return new k({address:t,privyInternal:r(this,d),chains:r(this,I),walletProxy:r(this,c)})}async setPassword(e,t){if(!r(this,c))throw new Error("Embedded wallet proxy not initialized");let s=await _(this,B,ce).call(this,t),i=await r(this,d).getAccessToken();if(!i)throw new Error("User must be logged in to create an embedded wallet");return await r(this,c).setPassword({accessToken:i,address:s,recoveryPassword:e}),new k({address:s,privyInternal:r(this,d),chains:r(this,I),walletProxy:r(this,c)})}getURL(){return`${r(this,d).baseUrl}/apps/${r(this,d).appId}/embedded-wallets`}getMessageHandler(){if(!r(this,c))throw new Error("Embedded wallet proxy not initialized");return r(this,c).handleEmbeddedWalletMessages.bind(r(this,c))}};d=new WeakMap,c=new WeakMap,I=new WeakMap,B=new WeakSet,ce=async function(e){if(!r(this,c))throw new Error("Embedded wallet proxy not initialized");let{user:t,token:s}=await r(this,d).refreshSession();if(!s)throw new Error("User must be logged in to interact with embedded wallets");let i=t?.linked_accounts.find(l=>l.type==="wallet"&&l.connector_type==="embedded"&&l.wallet_client_type==="privy");if(!i)throw new Error("User doesn't have an embedded wallet. Create one first.");let p=i.address;try{return await r(this,c).connect({accessToken:s,address:p}),p}catch(l){if(pe(l)&&i.recovery_method==="privy")return await r(this,c).recover({accessToken:s,address:p,recoveryPassword:e}),p;throw pe(l)&&!e?new Error("User recovery password required"):l}};import $e from"fetch-retry";import{v4 as gt}from"uuid";import{getAppConfig as bt,recordAnalyticsEvent as Rt,refreshSession as Tt}from"@privy-io/core-api";var Ne="0.0.1";import J from"js-cookie";import*as je from"jose";var T=class{static parse(e){try{return new T(e)}catch{return null}}constructor(e){this.value=e,this._decoded=je.decodeJwt(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}get issuer(){return this._decoded.iss}get audience(){return this._decoded.aud}isExpired(e=0){let t=Date.now(),s=(this.expiration-e)*1e3;return t>=s}};var de="privy:token",Le="privy-token",he="privy:refresh_token",He="privy-refresh-token",ut="privy-session",Fe="privy:session_transfer_token",vt=30,h,S,Z=class{constructor(e){n(this,h,void 0);n(this,S,!1);o(this,h,e.storage)}set isUsingServerCookies(e){o(this,S,e)}get token(){try{let e=r(this,h).get(de);return typeof e=="string"?new T(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=r(this,h).get(he);return typeof e=="string"?e:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get forkedToken(){try{let e=r(this,h).get(Fe);return typeof e=="string"?e:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get mightHaveServerCookies(){try{let e=J.get(ut);return e!==void 0&&e.length>0}catch(e){console.error(e)}return!1}hasRefreshCredentials(){return this.mightHaveServerCookies||typeof this.token=="string"&&typeof this.refreshToken=="string"}hasRecoveryCredentials(){return typeof this.forkedToken=="string"}hasActiveToken(){let e=T.parse(this.token);return e!==null&&!e.isExpired(vt)}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null),this.clearForkedToken()}storeToken(e){if(typeof e=="string"){if(r(this,h).put(de,e),!r(this,S)){let t=T.parse(e)?.expiration;J.set(Le,e,{sameSite:"Strict",secure:!0,expires:t?new Date(t*1e3):void 0})}}else r(this,h).del(de),J.remove(Le)}storeRefreshToken(e){typeof e=="string"?(r(this,h).put(he,e),r(this,S)||J.set(He,e,{sameSite:"Strict",secure:!0,expires:30})):(r(this,h).del(he),J.remove(He))}clearForkedToken(){r(this,h).del(Fe)}};h=new WeakMap,S=new WeakMap;var ft=a=>{let e=new AbortController;return setTimeout(()=>e.abort(),a),e.signal},Ge=ft;var wt="https://auth.privy.io",K,V,W,D,te,Be,re,Je,se,Ke,ee=class{constructor(e){n(this,te);n(this,re);n(this,se);n(this,K,void 0);n(this,V,void 0);n(this,W,`js-sdk-core:${Ne}`);n(this,D,void 0);this.baseUrl=e.baseUrl??wt,this.appId=e.appId,o(this,K,e.storage),o(this,V,gt()),o(this,W,e.sdkVersion??r(this,W)),this.session=new Z({storage:r(this,K),isUsingServerCookies:!1}),o(this,D,$e(fetch,{retries:3,retryDelay:500}))}async fetch(e,{body:t,params:s=void 0,options:i={onRequest:_(this,se,Ke).bind(this)}}){let p=new Request(`${this.baseUrl}${e.constructPath({params:s})}`,{method:e.method,body:JSON.stringify(t)}),l=await i.onRequest(p),f=await r(this,D).call(this,p,l);if(f.status!==e.expectedStatusCode)throw console.warn(`Privy: Expected status code ${e.expectedStatusCode}, received ${f.status}`),await f.json();return await f.json()}beforeRequestWithoutRefresh(e){let t=this.session.token,s=new Headers(e.headers);return s.set("privy-app-id",this.appId),s.set("privy-client",r(this,W)),s.set("Authorization",`Bearer ${t}`),s.set("Content-Type","application/json"),s.set("Accept","application/json"),{signal:Ge(3e3),headers:s,credentials:"include"}}async getAppConfig(){return this.fetch(bt,{params:{app_id:this.appId},options:{onRequest:this.beforeRequestWithoutRefresh.bind(this)}})}async createAnalyticsEvent(e,t){return this.fetch(Rt,{body:{event_name:e,client_id:r(this,V),payload:t}})}async refreshSession(){let e=await this.fetch(Tt,{body:{refresh_token:this.session.refreshToken??void 0},options:{onRequest:this.beforeRequestWithoutRefresh.bind(this)}});return this.session.storeToken(e.token),this.session.storeRefreshToken(e.refresh_token),e}async getAccessToken(){let e=this.session.token;if(e&&!this.session.hasActiveToken&&this.session.hasRefreshCredentials()){let{token:t}=await this.refreshSession();return t}return e}};K=new WeakMap,V=new WeakMap,W=new WeakMap,D=new WeakMap,te=new WeakSet,Be=function(){return!!this.config},re=new WeakSet,Je=async function(){r(this,te,Be)||(this.config=await this.getAppConfig(),this.config?.custom_api_url&&(this.baseUrl=this.config.custom_api_url,o(this,D,$e(fetch,{retries:3,retryDelay:500})),this.session.isUsingServerCookies=!0),this.createAnalyticsEvent("sdk_initialize",{}))},se=new WeakSet,Ke=async function(e){return await _(this,re,Je).call(this),await this.getAccessToken(),this.beforeRequestWithoutRefresh(e)};var Y,z=class{constructor(e){n(this,Y,void 0);o(this,Y,e)}async get(){return await r(this,Y).refreshSession()}};Y=new WeakMap;var P,Q=class{constructor(e){n(this,P,void 0);o(this,P,new ee(e)),this.user=new z(r(this,P)),this.auth=new O(r(this,P)),this.embeddedWallet=new $(r(this,P),e.embeddedWalletMessagePoster)}setMessagePoster(e){this.embeddedWallet.setMessagePoster(e)}};P=new WeakMap;var ye=class{get(e){let t=localStorage.getItem(e);return t===null?void 0:JSON.parse(t)}put(e,t){t!==void 0?localStorage.setItem(e,JSON.stringify(t)):this.del(e)}del(e){localStorage.removeItem(e)}getKeys(){return Object.entries(localStorage).map(([e])=>e)}};var me=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,t){t!==void 0?this._cache[e]=t:this.del(e)}del(e){delete this._cache[e]}getKeys(){return Object.keys(this._cache)}};globalThis.TextEncoder??=Et;var Ps=Q;export{me as InMemoryCache,ye as LocalStorage,Ps as default};
|
|
1
|
+
import {TextEncoder as $fdlOJ$TextEncoder} from "text-encoding";
|
|
2
|
+
import {logout as $fdlOJ$logout, authenticateCustomJwtAccount as $fdlOJ$authenticateCustomJwtAccount, passwordlessInit as $fdlOJ$passwordlessInit, passwordlessAuthenticate as $fdlOJ$passwordlessAuthenticate, passwordlessLink as $fdlOJ$passwordlessLink, passwordlessUnlink as $fdlOJ$passwordlessUnlink, passwordlessSmsInit as $fdlOJ$passwordlessSmsInit, passwordlessSmsAuthenticate as $fdlOJ$passwordlessSmsAuthenticate, passwordlessSmsLink as $fdlOJ$passwordlessSmsLink, passwordlessSmsUnlink as $fdlOJ$passwordlessSmsUnlink, getAppConfig as $fdlOJ$getAppConfig, recordAnalyticsEvent as $fdlOJ$recordAnalyticsEvent, refreshSession as $fdlOJ$refreshSession} from "@privy-io/public-api";
|
|
3
|
+
import {StaticJsonRpcProvider as $fdlOJ$StaticJsonRpcProvider} from "@ethersproject/providers";
|
|
4
|
+
import $fdlOJ$eventemitter3 from "eventemitter3";
|
|
5
|
+
import $fdlOJ$fetchretry from "fetch-retry";
|
|
6
|
+
import {v4 as $fdlOJ$v4} from "uuid";
|
|
7
|
+
import $fdlOJ$jscookie from "js-cookie";
|
|
8
|
+
import {decodeJwt as $fdlOJ$decodeJwt} from "jose";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class $e682ccb78399239f$export$2e2bcd8739ae039 {
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/ #privyInternal;
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/ constructor(privyInternal){
|
|
20
|
+
this.#privyInternal = privyInternal;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Logs a user in via a custom JWT from another (non-Privy) service
|
|
24
|
+
*
|
|
25
|
+
* @param token The JWT from the non-Privy service
|
|
26
|
+
*/ async syncWithToken(token) {
|
|
27
|
+
const res = await this.#privyInternal.fetch((0, $fdlOJ$authenticateCustomJwtAccount), {
|
|
28
|
+
body: {
|
|
29
|
+
token: token
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
this.#privyInternal.session.storeToken(res.token);
|
|
33
|
+
this.#privyInternal.session.storeRefreshToken(res.refresh_token);
|
|
34
|
+
return res;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class $96a8f034f38c2c62$export$2e2bcd8739ae039 {
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
*/ #privyInternal;
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/ constructor(privyInternal){
|
|
47
|
+
this.#privyInternal = privyInternal;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sends a one time login code to a user's email address
|
|
51
|
+
*
|
|
52
|
+
* @param email The email address to send the one time login code
|
|
53
|
+
* @param token A CAPTCHA token
|
|
54
|
+
*/ async sendCode(email, token) {
|
|
55
|
+
return this.#privyInternal.fetch((0, $fdlOJ$passwordlessInit), {
|
|
56
|
+
body: {
|
|
57
|
+
email: email,
|
|
58
|
+
token: token
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Logs a user in via an email address and one time code
|
|
64
|
+
*
|
|
65
|
+
* @param email The email address that the one time code was sent to
|
|
66
|
+
* @param code The one time code
|
|
67
|
+
*/ async loginWithCode(email, code) {
|
|
68
|
+
const res = await this.#privyInternal.fetch((0, $fdlOJ$passwordlessAuthenticate), {
|
|
69
|
+
body: {
|
|
70
|
+
email: email,
|
|
71
|
+
code: code
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
this.#privyInternal.session.storeToken(res.token);
|
|
75
|
+
this.#privyInternal.session.storeRefreshToken(res.refresh_token);
|
|
76
|
+
return res;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Links an email adress to an existing user
|
|
80
|
+
*
|
|
81
|
+
* @param email The email address that the one time code was sent to
|
|
82
|
+
* @param code The one time code
|
|
83
|
+
*/ async linkWithCode(email, code) {
|
|
84
|
+
return this.#privyInternal.fetch((0, $fdlOJ$passwordlessLink), {
|
|
85
|
+
body: {
|
|
86
|
+
email: email,
|
|
87
|
+
code: code
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async unlink(email) {
|
|
92
|
+
return this.#privyInternal.fetch((0, $fdlOJ$passwordlessUnlink), {
|
|
93
|
+
body: {
|
|
94
|
+
address: email
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class $04e9bebb951e0c7e$export$2e2bcd8739ae039 {
|
|
103
|
+
/**
|
|
104
|
+
* @internal
|
|
105
|
+
*/ #privyInternal;
|
|
106
|
+
/**
|
|
107
|
+
* @internal
|
|
108
|
+
*/ constructor(privyInternal){
|
|
109
|
+
this.#privyInternal = privyInternal;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Sends a one time login code to a user's phone number via sms
|
|
113
|
+
*
|
|
114
|
+
* @param phoneNumber The phone number to send the one time login code
|
|
115
|
+
* @param token A CAPTCHA token
|
|
116
|
+
*/ async sendCode(phoneNumber, token) {
|
|
117
|
+
return this.#privyInternal.fetch((0, $fdlOJ$passwordlessSmsInit), {
|
|
118
|
+
body: {
|
|
119
|
+
phoneNumber: phoneNumber,
|
|
120
|
+
token: token
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Logs a user in via a phone number and one time code
|
|
126
|
+
*
|
|
127
|
+
* @param phoneNumber The phone number that the one time code was sent to
|
|
128
|
+
* @param code The one time code
|
|
129
|
+
*/ async loginWithCode(phoneNumber, code) {
|
|
130
|
+
const res = await this.#privyInternal.fetch((0, $fdlOJ$passwordlessSmsAuthenticate), {
|
|
131
|
+
body: {
|
|
132
|
+
phoneNumber: phoneNumber,
|
|
133
|
+
code: code
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
this.#privyInternal.session.storeToken(res.token);
|
|
137
|
+
this.#privyInternal.session.storeRefreshToken(res.refresh_token);
|
|
138
|
+
return res;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Links a phone number to an existing user
|
|
142
|
+
*
|
|
143
|
+
* @param phoneNumber The phone number that the one time code was sent to
|
|
144
|
+
* @param code The one time code
|
|
145
|
+
*/ async linkWithCode(phoneNumber, code) {
|
|
146
|
+
return this.#privyInternal.fetch((0, $fdlOJ$passwordlessSmsLink), {
|
|
147
|
+
body: {
|
|
148
|
+
phoneNumber: phoneNumber,
|
|
149
|
+
code: code
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async unlink(phoneNumber) {
|
|
154
|
+
return this.#privyInternal.fetch((0, $fdlOJ$passwordlessSmsUnlink), {
|
|
155
|
+
body: {
|
|
156
|
+
phoneNumber: phoneNumber
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class $955bfb5a5edecad4$export$2e2bcd8739ae039 {
|
|
164
|
+
/**
|
|
165
|
+
* @internal
|
|
166
|
+
*/ #privyInternal;
|
|
167
|
+
/**
|
|
168
|
+
* @internal
|
|
169
|
+
*/ constructor(privyInternal){
|
|
170
|
+
this.#privyInternal = privyInternal;
|
|
171
|
+
this.phone = new (0, $04e9bebb951e0c7e$export$2e2bcd8739ae039)(this.#privyInternal);
|
|
172
|
+
this.email = new (0, $96a8f034f38c2c62$export$2e2bcd8739ae039)(this.#privyInternal);
|
|
173
|
+
this.customProvider = new (0, $e682ccb78399239f$export$2e2bcd8739ae039)(this.#privyInternal);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Logs the current user out.
|
|
177
|
+
*/ async logout() {
|
|
178
|
+
try {
|
|
179
|
+
await this.#privyInternal.fetch((0, $fdlOJ$logout), {
|
|
180
|
+
body: {
|
|
181
|
+
refresh_token: this.#privyInternal.session.refreshToken ?? undefined
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
} catch (e) {
|
|
185
|
+
// Fail silently, as API error should not block logging the user out
|
|
186
|
+
console.warn("Error destroying session");
|
|
187
|
+
}
|
|
188
|
+
// Destroy the local auth state
|
|
189
|
+
this.#privyInternal.session.destroyLocalState();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
const $3fea037b39853544$export$625cf84d855940d4 = {
|
|
195
|
+
id: 42161,
|
|
196
|
+
name: "Arbitrum One",
|
|
197
|
+
network: "arbitrum",
|
|
198
|
+
nativeCurrency: {
|
|
199
|
+
name: "Ether",
|
|
200
|
+
symbol: "ETH",
|
|
201
|
+
decimals: 18
|
|
202
|
+
},
|
|
203
|
+
rpcUrls: {
|
|
204
|
+
alchemy: {
|
|
205
|
+
http: [
|
|
206
|
+
"https://arb-mainnet.g.alchemy.com/v2"
|
|
207
|
+
],
|
|
208
|
+
webSocket: [
|
|
209
|
+
"wss://arb-mainnet.g.alchemy.com/v2"
|
|
210
|
+
]
|
|
211
|
+
},
|
|
212
|
+
infura: {
|
|
213
|
+
http: [
|
|
214
|
+
"https://arbitrum-mainnet.infura.io/v3"
|
|
215
|
+
],
|
|
216
|
+
webSocket: [
|
|
217
|
+
"wss://arbitrum-mainnet.infura.io/ws/v3"
|
|
218
|
+
]
|
|
219
|
+
},
|
|
220
|
+
default: {
|
|
221
|
+
http: [
|
|
222
|
+
"https://arb1.arbitrum.io/rpc"
|
|
223
|
+
]
|
|
224
|
+
},
|
|
225
|
+
public: {
|
|
226
|
+
http: [
|
|
227
|
+
"https://arb1.arbitrum.io/rpc"
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
blockExplorers: {
|
|
232
|
+
etherscan: {
|
|
233
|
+
name: "Arbiscan",
|
|
234
|
+
url: "https://arbiscan.io"
|
|
235
|
+
},
|
|
236
|
+
default: {
|
|
237
|
+
name: "Arbiscan",
|
|
238
|
+
url: "https://arbiscan.io"
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
const $5cd11e46a9ac45df$export$857f1b5f596fb425 = {
|
|
245
|
+
id: 421613,
|
|
246
|
+
name: "Arbitrum Goerli",
|
|
247
|
+
network: "arbitrum-goerli",
|
|
248
|
+
nativeCurrency: {
|
|
249
|
+
name: "Goerli Ether",
|
|
250
|
+
symbol: "AGOR",
|
|
251
|
+
decimals: 18
|
|
252
|
+
},
|
|
253
|
+
rpcUrls: {
|
|
254
|
+
alchemy: {
|
|
255
|
+
http: [
|
|
256
|
+
"https://arb-goerli.g.alchemy.com/v2"
|
|
257
|
+
],
|
|
258
|
+
webSocket: [
|
|
259
|
+
"wss://arb-goerli.g.alchemy.com/v2"
|
|
260
|
+
]
|
|
261
|
+
},
|
|
262
|
+
infura: {
|
|
263
|
+
http: [
|
|
264
|
+
"https://arbitrum-goerli.infura.io/v3"
|
|
265
|
+
],
|
|
266
|
+
webSocket: [
|
|
267
|
+
"wss://arbitrum-goerli.infura.io/ws/v3"
|
|
268
|
+
]
|
|
269
|
+
},
|
|
270
|
+
default: {
|
|
271
|
+
http: [
|
|
272
|
+
"https://goerli-rollup.arbitrum.io/rpc"
|
|
273
|
+
]
|
|
274
|
+
},
|
|
275
|
+
public: {
|
|
276
|
+
http: [
|
|
277
|
+
"https://goerli-rollup.arbitrum.io/rpc"
|
|
278
|
+
]
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
blockExplorers: {
|
|
282
|
+
etherscan: {
|
|
283
|
+
name: "Arbiscan",
|
|
284
|
+
url: "https://goerli.arbiscan.io/"
|
|
285
|
+
},
|
|
286
|
+
default: {
|
|
287
|
+
name: "Arbiscan",
|
|
288
|
+
url: "https://goerli.arbiscan.io/"
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
testnet: true
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
const $f2266046a7507579$export$ca1d15c01fde7266 = {
|
|
296
|
+
id: 43114,
|
|
297
|
+
name: "Avalanche",
|
|
298
|
+
network: "avalanche",
|
|
299
|
+
nativeCurrency: {
|
|
300
|
+
decimals: 18,
|
|
301
|
+
name: "Avalanche",
|
|
302
|
+
symbol: "AVAX"
|
|
303
|
+
},
|
|
304
|
+
rpcUrls: {
|
|
305
|
+
default: {
|
|
306
|
+
http: [
|
|
307
|
+
"https://api.avax.network/ext/bc/C/rpc"
|
|
308
|
+
]
|
|
309
|
+
},
|
|
310
|
+
public: {
|
|
311
|
+
http: [
|
|
312
|
+
"https://api.avax.network/ext/bc/C/rpc"
|
|
313
|
+
]
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
blockExplorers: {
|
|
317
|
+
etherscan: {
|
|
318
|
+
name: "SnowTrace",
|
|
319
|
+
url: "https://snowtrace.io"
|
|
320
|
+
},
|
|
321
|
+
default: {
|
|
322
|
+
name: "SnowTrace",
|
|
323
|
+
url: "https://snowtrace.io"
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
const $0bbdff61bcb77830$export$714c92acd9d3100a = {
|
|
330
|
+
id: 43113,
|
|
331
|
+
name: "Avalanche Fuji",
|
|
332
|
+
network: "avalanche-fuji",
|
|
333
|
+
nativeCurrency: {
|
|
334
|
+
decimals: 18,
|
|
335
|
+
name: "Avalanche Fuji",
|
|
336
|
+
symbol: "AVAX"
|
|
337
|
+
},
|
|
338
|
+
rpcUrls: {
|
|
339
|
+
default: {
|
|
340
|
+
http: [
|
|
341
|
+
"https://api.avax-test.network/ext/bc/C/rpc"
|
|
342
|
+
]
|
|
343
|
+
},
|
|
344
|
+
public: {
|
|
345
|
+
http: [
|
|
346
|
+
"https://api.avax-test.network/ext/bc/C/rpc"
|
|
347
|
+
]
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
blockExplorers: {
|
|
351
|
+
etherscan: {
|
|
352
|
+
name: "SnowTrace",
|
|
353
|
+
url: "https://testnet.snowtrace.io"
|
|
354
|
+
},
|
|
355
|
+
default: {
|
|
356
|
+
name: "SnowTrace",
|
|
357
|
+
url: "https://testnet.snowtrace.io"
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
testnet: true
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
const $8e5ed855f7f912d0$export$e2253033e6e1df16 = {
|
|
365
|
+
id: 8453,
|
|
366
|
+
network: "base",
|
|
367
|
+
name: "Base",
|
|
368
|
+
nativeCurrency: {
|
|
369
|
+
name: "Ether",
|
|
370
|
+
symbol: "ETH",
|
|
371
|
+
decimals: 18
|
|
372
|
+
},
|
|
373
|
+
rpcUrls: {
|
|
374
|
+
blast: {
|
|
375
|
+
http: [
|
|
376
|
+
"https://base-mainnet.blastapi.io"
|
|
377
|
+
],
|
|
378
|
+
webSocket: [
|
|
379
|
+
"wss://base-mainnet.blastapi.io"
|
|
380
|
+
]
|
|
381
|
+
},
|
|
382
|
+
default: {
|
|
383
|
+
http: [
|
|
384
|
+
"https://mainnet.base.org"
|
|
385
|
+
]
|
|
386
|
+
},
|
|
387
|
+
public: {
|
|
388
|
+
http: [
|
|
389
|
+
"https://mainnet.base.org"
|
|
390
|
+
]
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
blockExplorers: {
|
|
394
|
+
etherscan: {
|
|
395
|
+
name: "Basescan",
|
|
396
|
+
url: "https://basescan.org"
|
|
397
|
+
},
|
|
398
|
+
default: {
|
|
399
|
+
name: "Basescan",
|
|
400
|
+
url: "https://basescan.org"
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
testnet: true
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
const $f54a2e14e1d8a57d$export$8ae5747389a6ab6b = {
|
|
408
|
+
id: 84531,
|
|
409
|
+
network: "base-goerli",
|
|
410
|
+
name: "Base Goerli Testnet",
|
|
411
|
+
nativeCurrency: {
|
|
412
|
+
name: "Goerli Ether",
|
|
413
|
+
symbol: "ETH",
|
|
414
|
+
decimals: 18
|
|
415
|
+
},
|
|
416
|
+
rpcUrls: {
|
|
417
|
+
blast: {
|
|
418
|
+
http: [
|
|
419
|
+
"https://base-goerli.blastapi.io"
|
|
420
|
+
],
|
|
421
|
+
webSocket: [
|
|
422
|
+
"wss://base-goerli.blastapi.io"
|
|
423
|
+
]
|
|
424
|
+
},
|
|
425
|
+
default: {
|
|
426
|
+
http: [
|
|
427
|
+
"https://goerli.base.org"
|
|
428
|
+
]
|
|
429
|
+
},
|
|
430
|
+
public: {
|
|
431
|
+
http: [
|
|
432
|
+
"https://goerli.base.org"
|
|
433
|
+
]
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
blockExplorers: {
|
|
437
|
+
etherscan: {
|
|
438
|
+
name: "Basescan",
|
|
439
|
+
url: "https://goerli.basescan.org"
|
|
440
|
+
},
|
|
441
|
+
default: {
|
|
442
|
+
name: "Basescan",
|
|
443
|
+
url: "https://goerli.basescan.org"
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
testnet: true
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
const $1fe6d49303d1b309$export$671bdf559232d1e0 = {
|
|
451
|
+
id: 42220,
|
|
452
|
+
name: "Celo Mainnet",
|
|
453
|
+
network: "celo",
|
|
454
|
+
nativeCurrency: {
|
|
455
|
+
decimals: 18,
|
|
456
|
+
name: "CELO",
|
|
457
|
+
symbol: "CELO"
|
|
458
|
+
},
|
|
459
|
+
rpcUrls: {
|
|
460
|
+
default: {
|
|
461
|
+
http: [
|
|
462
|
+
"https://forno.celo.org"
|
|
463
|
+
]
|
|
464
|
+
},
|
|
465
|
+
infura: {
|
|
466
|
+
http: [
|
|
467
|
+
"https://celo-mainnet.infura.io/v3"
|
|
468
|
+
]
|
|
469
|
+
},
|
|
470
|
+
public: {
|
|
471
|
+
http: [
|
|
472
|
+
"https://forno.celo.org"
|
|
473
|
+
]
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
blockExplorers: {
|
|
477
|
+
default: {
|
|
478
|
+
name: "Celo Explorer",
|
|
479
|
+
url: "https://explorer.celo.org/mainnet"
|
|
480
|
+
},
|
|
481
|
+
etherscan: {
|
|
482
|
+
name: "CeloScan",
|
|
483
|
+
url: "https://celoscan.io"
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
testnet: false
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
const $794e5fcc6fbcd8df$export$ea1d1a16df546697 = {
|
|
491
|
+
id: 44787,
|
|
492
|
+
name: "Celo Alfajores Testnet",
|
|
493
|
+
network: "celo-alfajores",
|
|
494
|
+
nativeCurrency: {
|
|
495
|
+
decimals: 18,
|
|
496
|
+
name: "CELO",
|
|
497
|
+
symbol: "CELO"
|
|
498
|
+
},
|
|
499
|
+
rpcUrls: {
|
|
500
|
+
default: {
|
|
501
|
+
http: [
|
|
502
|
+
"https://alfajores-forno.celo-testnet.org"
|
|
503
|
+
]
|
|
504
|
+
},
|
|
505
|
+
infura: {
|
|
506
|
+
http: [
|
|
507
|
+
"https://celo-alfajores.infura.io/v3"
|
|
508
|
+
]
|
|
509
|
+
},
|
|
510
|
+
public: {
|
|
511
|
+
http: [
|
|
512
|
+
"https://alfajores-forno.celo-testnet.org"
|
|
513
|
+
]
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
blockExplorers: {
|
|
517
|
+
default: {
|
|
518
|
+
name: "Celo Explorer",
|
|
519
|
+
url: "https://explorer.celo.org/alfajores"
|
|
520
|
+
},
|
|
521
|
+
etherscan: {
|
|
522
|
+
name: "CeloScan",
|
|
523
|
+
url: "https://alfajores.celoscan.io/"
|
|
524
|
+
}
|
|
525
|
+
},
|
|
526
|
+
testnet: true
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
const $dd9c9d3f892375a3$export$d5a6d2ad15089d83 = {
|
|
531
|
+
id: 314,
|
|
532
|
+
name: "Filecoin - Mainnet",
|
|
533
|
+
network: "filecoin-mainnet",
|
|
534
|
+
nativeCurrency: {
|
|
535
|
+
decimals: 18,
|
|
536
|
+
name: "filecoin",
|
|
537
|
+
symbol: "FIL"
|
|
538
|
+
},
|
|
539
|
+
rpcUrls: {
|
|
540
|
+
default: {
|
|
541
|
+
http: [
|
|
542
|
+
"https://api.node.glif.io/rpc/v1"
|
|
543
|
+
]
|
|
544
|
+
},
|
|
545
|
+
public: {
|
|
546
|
+
http: [
|
|
547
|
+
"https://api.node.glif.io/rpc/v1"
|
|
548
|
+
]
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
blockExplorers: {
|
|
552
|
+
default: {
|
|
553
|
+
name: "Filfox",
|
|
554
|
+
url: "https://filfox.info/en"
|
|
555
|
+
},
|
|
556
|
+
filscan: {
|
|
557
|
+
name: "Filscan",
|
|
558
|
+
url: "https://filscan.io"
|
|
559
|
+
},
|
|
560
|
+
filscout: {
|
|
561
|
+
name: "Filscout",
|
|
562
|
+
url: "https://filscout.io/en"
|
|
563
|
+
},
|
|
564
|
+
glif: {
|
|
565
|
+
name: "Glif",
|
|
566
|
+
url: "https://explorer.glif.io"
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
const $f3a92deaec4182c8$export$de9b05abdae7c2c = {
|
|
573
|
+
id: 314159,
|
|
574
|
+
name: "Filecoin - Calibration testnet",
|
|
575
|
+
network: "filecoin-calibration",
|
|
576
|
+
nativeCurrency: {
|
|
577
|
+
decimals: 18,
|
|
578
|
+
name: "testnet filecoin",
|
|
579
|
+
symbol: "tFIL"
|
|
580
|
+
},
|
|
581
|
+
rpcUrls: {
|
|
582
|
+
default: {
|
|
583
|
+
http: [
|
|
584
|
+
"https://api.calibration.node.glif.io/rpc/v1"
|
|
585
|
+
]
|
|
586
|
+
},
|
|
587
|
+
public: {
|
|
588
|
+
http: [
|
|
589
|
+
"https://api.calibration.node.glif.io/rpc/v1"
|
|
590
|
+
]
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
blockExplorers: {
|
|
594
|
+
default: {
|
|
595
|
+
name: "Filscan",
|
|
596
|
+
url: "https://calibration.filscan.io"
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
const $ef71324da6e93be6$export$50b37201a1017e1e = {
|
|
603
|
+
id: 5,
|
|
604
|
+
network: "goerli",
|
|
605
|
+
name: "Goerli",
|
|
606
|
+
nativeCurrency: {
|
|
607
|
+
name: "Goerli Ether",
|
|
608
|
+
symbol: "ETH",
|
|
609
|
+
decimals: 18
|
|
610
|
+
},
|
|
611
|
+
rpcUrls: {
|
|
612
|
+
alchemy: {
|
|
613
|
+
http: [
|
|
614
|
+
"https://eth-goerli.g.alchemy.com/v2"
|
|
615
|
+
],
|
|
616
|
+
webSocket: [
|
|
617
|
+
"wss://eth-goerli.g.alchemy.com/v2"
|
|
618
|
+
]
|
|
619
|
+
},
|
|
620
|
+
infura: {
|
|
621
|
+
http: [
|
|
622
|
+
"https://goerli.infura.io/v3"
|
|
623
|
+
],
|
|
624
|
+
webSocket: [
|
|
625
|
+
"wss://goerli.infura.io/ws/v3"
|
|
626
|
+
]
|
|
627
|
+
},
|
|
628
|
+
default: {
|
|
629
|
+
http: [
|
|
630
|
+
"https://rpc.ankr.com/eth_goerli"
|
|
631
|
+
]
|
|
632
|
+
},
|
|
633
|
+
public: {
|
|
634
|
+
http: [
|
|
635
|
+
"https://rpc.ankr.com/eth_goerli"
|
|
636
|
+
]
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
blockExplorers: {
|
|
640
|
+
etherscan: {
|
|
641
|
+
name: "Etherscan",
|
|
642
|
+
url: "https://goerli.etherscan.io"
|
|
643
|
+
},
|
|
644
|
+
default: {
|
|
645
|
+
name: "Etherscan",
|
|
646
|
+
url: "https://goerli.etherscan.io"
|
|
647
|
+
}
|
|
648
|
+
},
|
|
649
|
+
testnet: true
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
const $7507f76ddce18ab1$export$7d9a0b32b656284d = {
|
|
654
|
+
id: 59144,
|
|
655
|
+
network: "linea-mainnet",
|
|
656
|
+
name: "Linea Mainnet",
|
|
657
|
+
nativeCurrency: {
|
|
658
|
+
name: "Linea Ether",
|
|
659
|
+
symbol: "ETH",
|
|
660
|
+
decimals: 18
|
|
661
|
+
},
|
|
662
|
+
rpcUrls: {
|
|
663
|
+
infura: {
|
|
664
|
+
http: [
|
|
665
|
+
"https://linea-mainnet.infura.io/v3"
|
|
666
|
+
],
|
|
667
|
+
webSocket: [
|
|
668
|
+
"wss://linea-mainnet.infura.io/ws/v3"
|
|
669
|
+
]
|
|
670
|
+
},
|
|
671
|
+
default: {
|
|
672
|
+
http: [
|
|
673
|
+
"https://rpc.linea.build"
|
|
674
|
+
],
|
|
675
|
+
webSocket: [
|
|
676
|
+
"wss://rpc.linea.build"
|
|
677
|
+
]
|
|
678
|
+
},
|
|
679
|
+
public: {
|
|
680
|
+
http: [
|
|
681
|
+
"https://rpc.linea.build"
|
|
682
|
+
],
|
|
683
|
+
webSocket: [
|
|
684
|
+
"wss://rpc.linea.build"
|
|
685
|
+
]
|
|
686
|
+
}
|
|
687
|
+
},
|
|
688
|
+
blockExplorers: {
|
|
689
|
+
default: {
|
|
690
|
+
name: "Etherscan",
|
|
691
|
+
url: "https://lineascan.build"
|
|
692
|
+
},
|
|
693
|
+
etherscan: {
|
|
694
|
+
name: "Etherscan",
|
|
695
|
+
url: "https://lineascan.build"
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
testnet: false
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
const $db0add24f91165c9$export$9b359a3964075c2b = {
|
|
703
|
+
id: 59140,
|
|
704
|
+
network: "linea-testnet",
|
|
705
|
+
name: "Linea Goerli Testnet",
|
|
706
|
+
nativeCurrency: {
|
|
707
|
+
name: "Linea Ether",
|
|
708
|
+
symbol: "ETH",
|
|
709
|
+
decimals: 18
|
|
710
|
+
},
|
|
711
|
+
rpcUrls: {
|
|
712
|
+
infura: {
|
|
713
|
+
http: [
|
|
714
|
+
"https://linea-goerli.infura.io/v3"
|
|
715
|
+
],
|
|
716
|
+
webSocket: [
|
|
717
|
+
"wss://linea-goerli.infura.io/ws/v3"
|
|
718
|
+
]
|
|
719
|
+
},
|
|
720
|
+
default: {
|
|
721
|
+
http: [
|
|
722
|
+
"https://rpc.goerli.linea.build"
|
|
723
|
+
],
|
|
724
|
+
webSocket: [
|
|
725
|
+
"wss://rpc.goerli.linea.build"
|
|
726
|
+
]
|
|
727
|
+
},
|
|
728
|
+
public: {
|
|
729
|
+
http: [
|
|
730
|
+
"https://rpc.goerli.linea.build"
|
|
731
|
+
],
|
|
732
|
+
webSocket: [
|
|
733
|
+
"wss://rpc.goerli.linea.build"
|
|
734
|
+
]
|
|
735
|
+
}
|
|
736
|
+
},
|
|
737
|
+
blockExplorers: {
|
|
738
|
+
default: {
|
|
739
|
+
name: "Etherscan",
|
|
740
|
+
url: "https://goerli.lineascan.build"
|
|
741
|
+
},
|
|
742
|
+
etherscan: {
|
|
743
|
+
name: "Etherscan",
|
|
744
|
+
url: "https://goerli.lineascan.build"
|
|
745
|
+
}
|
|
746
|
+
},
|
|
747
|
+
testnet: true
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
const $2fd08fe5279c649f$export$536d3e0d2c7baf54 = {
|
|
752
|
+
id: 1,
|
|
753
|
+
network: "homestead",
|
|
754
|
+
name: "Ethereum",
|
|
755
|
+
nativeCurrency: {
|
|
756
|
+
name: "Ether",
|
|
757
|
+
symbol: "ETH",
|
|
758
|
+
decimals: 18
|
|
759
|
+
},
|
|
760
|
+
rpcUrls: {
|
|
761
|
+
alchemy: {
|
|
762
|
+
http: [
|
|
763
|
+
"https://eth-mainnet.g.alchemy.com/v2"
|
|
764
|
+
],
|
|
765
|
+
webSocket: [
|
|
766
|
+
"wss://eth-mainnet.g.alchemy.com/v2"
|
|
767
|
+
]
|
|
768
|
+
},
|
|
769
|
+
infura: {
|
|
770
|
+
http: [
|
|
771
|
+
"https://mainnet.infura.io/v3"
|
|
772
|
+
],
|
|
773
|
+
webSocket: [
|
|
774
|
+
"wss://mainnet.infura.io/ws/v3"
|
|
775
|
+
]
|
|
776
|
+
},
|
|
777
|
+
default: {
|
|
778
|
+
http: [
|
|
779
|
+
"https://cloudflare-eth.com"
|
|
780
|
+
]
|
|
781
|
+
},
|
|
782
|
+
public: {
|
|
783
|
+
http: [
|
|
784
|
+
"https://cloudflare-eth.com"
|
|
785
|
+
]
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
blockExplorers: {
|
|
789
|
+
etherscan: {
|
|
790
|
+
name: "Etherscan",
|
|
791
|
+
url: "https://etherscan.io"
|
|
792
|
+
},
|
|
793
|
+
default: {
|
|
794
|
+
name: "Etherscan",
|
|
795
|
+
url: "https://etherscan.io"
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
const $c0fc898708b5c03c$export$e584d4a579189f9b = {
|
|
802
|
+
id: 10,
|
|
803
|
+
name: "OP Mainnet",
|
|
804
|
+
network: "optimism",
|
|
805
|
+
nativeCurrency: {
|
|
806
|
+
name: "Ether",
|
|
807
|
+
symbol: "ETH",
|
|
808
|
+
decimals: 18
|
|
809
|
+
},
|
|
810
|
+
rpcUrls: {
|
|
811
|
+
alchemy: {
|
|
812
|
+
http: [
|
|
813
|
+
"https://opt-mainnet.g.alchemy.com/v2"
|
|
814
|
+
],
|
|
815
|
+
webSocket: [
|
|
816
|
+
"wss://opt-mainnet.g.alchemy.com/v2"
|
|
817
|
+
]
|
|
818
|
+
},
|
|
819
|
+
infura: {
|
|
820
|
+
http: [
|
|
821
|
+
"https://optimism-mainnet.infura.io/v3"
|
|
822
|
+
],
|
|
823
|
+
webSocket: [
|
|
824
|
+
"wss://optimism-mainnet.infura.io/ws/v3"
|
|
825
|
+
]
|
|
826
|
+
},
|
|
827
|
+
default: {
|
|
828
|
+
http: [
|
|
829
|
+
"https://mainnet.optimism.io"
|
|
830
|
+
]
|
|
831
|
+
},
|
|
832
|
+
public: {
|
|
833
|
+
http: [
|
|
834
|
+
"https://mainnet.optimism.io"
|
|
835
|
+
]
|
|
836
|
+
}
|
|
837
|
+
},
|
|
838
|
+
blockExplorers: {
|
|
839
|
+
etherscan: {
|
|
840
|
+
name: "Etherscan",
|
|
841
|
+
url: "https://optimistic.etherscan.io"
|
|
842
|
+
},
|
|
843
|
+
default: {
|
|
844
|
+
name: "Optimism Explorer",
|
|
845
|
+
url: "https://explorer.optimism.io"
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
const $20cda9ec9bdd69ae$export$50b3e5cabd7d7a60 = {
|
|
852
|
+
id: 420,
|
|
853
|
+
name: "Optimism Goerli Testnet",
|
|
854
|
+
network: "optimism-goerli",
|
|
855
|
+
nativeCurrency: {
|
|
856
|
+
name: "Goerli Ether",
|
|
857
|
+
symbol: "ETH",
|
|
858
|
+
decimals: 18
|
|
859
|
+
},
|
|
860
|
+
rpcUrls: {
|
|
861
|
+
alchemy: {
|
|
862
|
+
http: [
|
|
863
|
+
"https://opt-goerli.g.alchemy.com/v2"
|
|
864
|
+
],
|
|
865
|
+
webSocket: [
|
|
866
|
+
"wss://opt-goerli.g.alchemy.com/v2"
|
|
867
|
+
]
|
|
868
|
+
},
|
|
869
|
+
infura: {
|
|
870
|
+
http: [
|
|
871
|
+
"https://optimism-goerli.infura.io/v3"
|
|
872
|
+
],
|
|
873
|
+
webSocket: [
|
|
874
|
+
"wss://optimism-goerli.infura.io/ws/v3"
|
|
875
|
+
]
|
|
876
|
+
},
|
|
877
|
+
default: {
|
|
878
|
+
http: [
|
|
879
|
+
"https://goerli.optimism.io"
|
|
880
|
+
]
|
|
881
|
+
},
|
|
882
|
+
public: {
|
|
883
|
+
http: [
|
|
884
|
+
"https://goerli.optimism.io"
|
|
885
|
+
]
|
|
886
|
+
}
|
|
887
|
+
},
|
|
888
|
+
blockExplorers: {
|
|
889
|
+
etherscan: {
|
|
890
|
+
name: "Etherscan",
|
|
891
|
+
url: "https://goerli-optimism.etherscan.io"
|
|
892
|
+
},
|
|
893
|
+
default: {
|
|
894
|
+
name: "Etherscan",
|
|
895
|
+
url: "https://goerli-optimism.etherscan.io"
|
|
896
|
+
}
|
|
897
|
+
},
|
|
898
|
+
testnet: true
|
|
899
|
+
};
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
const $dae31d00cceb5ed1$export$b7b19aa0ee06c73 = {
|
|
903
|
+
id: 137,
|
|
904
|
+
name: "Polygon Mainnet",
|
|
905
|
+
network: "matic",
|
|
906
|
+
nativeCurrency: {
|
|
907
|
+
name: "MATIC",
|
|
908
|
+
symbol: "MATIC",
|
|
909
|
+
decimals: 18
|
|
910
|
+
},
|
|
911
|
+
rpcUrls: {
|
|
912
|
+
alchemy: {
|
|
913
|
+
http: [
|
|
914
|
+
"https://polygon-mainnet.g.alchemy.com/v2"
|
|
915
|
+
],
|
|
916
|
+
webSocket: [
|
|
917
|
+
"wss://polygon-mainnet.g.alchemy.com/v2"
|
|
918
|
+
]
|
|
919
|
+
},
|
|
920
|
+
infura: {
|
|
921
|
+
http: [
|
|
922
|
+
"https://polygon-mainnet.infura.io/v3"
|
|
923
|
+
],
|
|
924
|
+
webSocket: [
|
|
925
|
+
"wss://polygon-mainnet.infura.io/ws/v3"
|
|
926
|
+
]
|
|
927
|
+
},
|
|
928
|
+
default: {
|
|
929
|
+
http: [
|
|
930
|
+
"https://polygon-rpc.com"
|
|
931
|
+
]
|
|
932
|
+
},
|
|
933
|
+
public: {
|
|
934
|
+
http: [
|
|
935
|
+
"https://polygon-rpc.com"
|
|
936
|
+
]
|
|
937
|
+
}
|
|
938
|
+
},
|
|
939
|
+
blockExplorers: {
|
|
940
|
+
etherscan: {
|
|
941
|
+
name: "PolygonScan",
|
|
942
|
+
url: "https://polygonscan.com"
|
|
943
|
+
},
|
|
944
|
+
default: {
|
|
945
|
+
name: "PolygonScan",
|
|
946
|
+
url: "https://polygonscan.com"
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
const $4e8fde1a95428707$export$34b6ef3a78067459 = {
|
|
953
|
+
id: 80001,
|
|
954
|
+
name: "Mumbai",
|
|
955
|
+
network: "maticmum",
|
|
956
|
+
nativeCurrency: {
|
|
957
|
+
name: "MATIC",
|
|
958
|
+
symbol: "MATIC",
|
|
959
|
+
decimals: 18
|
|
960
|
+
},
|
|
961
|
+
rpcUrls: {
|
|
962
|
+
alchemy: {
|
|
963
|
+
http: [
|
|
964
|
+
"https://polygon-mumbai.g.alchemy.com/v2"
|
|
965
|
+
],
|
|
966
|
+
webSocket: [
|
|
967
|
+
"wss://polygon-mumbai.g.alchemy.com/v2"
|
|
968
|
+
]
|
|
969
|
+
},
|
|
970
|
+
infura: {
|
|
971
|
+
http: [
|
|
972
|
+
"https://polygon-mumbai.infura.io/v3"
|
|
973
|
+
],
|
|
974
|
+
webSocket: [
|
|
975
|
+
"wss://polygon-mumbai.infura.io/ws/v3"
|
|
976
|
+
]
|
|
977
|
+
},
|
|
978
|
+
default: {
|
|
979
|
+
http: [
|
|
980
|
+
"https://matic-mumbai.chainstacklabs.com"
|
|
981
|
+
]
|
|
982
|
+
},
|
|
983
|
+
public: {
|
|
984
|
+
http: [
|
|
985
|
+
"https://matic-mumbai.chainstacklabs.com"
|
|
986
|
+
]
|
|
987
|
+
}
|
|
988
|
+
},
|
|
989
|
+
blockExplorers: {
|
|
990
|
+
etherscan: {
|
|
991
|
+
name: "PolygonScan",
|
|
992
|
+
url: "https://mumbai.polygonscan.com"
|
|
993
|
+
},
|
|
994
|
+
default: {
|
|
995
|
+
name: "PolygonScan",
|
|
996
|
+
url: "https://mumbai.polygonscan.com"
|
|
997
|
+
}
|
|
998
|
+
},
|
|
999
|
+
testnet: true
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
const $e5636bd4149958a1$export$31254237fd28c61a = {
|
|
1004
|
+
id: 11155111,
|
|
1005
|
+
network: "sepolia",
|
|
1006
|
+
name: "Sepolia",
|
|
1007
|
+
nativeCurrency: {
|
|
1008
|
+
name: "Sepolia Ether",
|
|
1009
|
+
symbol: "SEP",
|
|
1010
|
+
decimals: 18
|
|
1011
|
+
},
|
|
1012
|
+
rpcUrls: {
|
|
1013
|
+
alchemy: {
|
|
1014
|
+
http: [
|
|
1015
|
+
"https://eth-sepolia.g.alchemy.com/v2"
|
|
1016
|
+
],
|
|
1017
|
+
webSocket: [
|
|
1018
|
+
"wss://eth-sepolia.g.alchemy.com/v2"
|
|
1019
|
+
]
|
|
1020
|
+
},
|
|
1021
|
+
infura: {
|
|
1022
|
+
http: [
|
|
1023
|
+
"https://sepolia.infura.io/v3"
|
|
1024
|
+
],
|
|
1025
|
+
webSocket: [
|
|
1026
|
+
"wss://sepolia.infura.io/ws/v3"
|
|
1027
|
+
]
|
|
1028
|
+
},
|
|
1029
|
+
default: {
|
|
1030
|
+
http: [
|
|
1031
|
+
"https://rpc.sepolia.org"
|
|
1032
|
+
]
|
|
1033
|
+
},
|
|
1034
|
+
public: {
|
|
1035
|
+
http: [
|
|
1036
|
+
"https://rpc.sepolia.org"
|
|
1037
|
+
]
|
|
1038
|
+
}
|
|
1039
|
+
},
|
|
1040
|
+
blockExplorers: {
|
|
1041
|
+
etherscan: {
|
|
1042
|
+
name: "Etherscan",
|
|
1043
|
+
url: "https://sepolia.etherscan.io"
|
|
1044
|
+
},
|
|
1045
|
+
default: {
|
|
1046
|
+
name: "Etherscan",
|
|
1047
|
+
url: "https://sepolia.etherscan.io"
|
|
1048
|
+
}
|
|
1049
|
+
},
|
|
1050
|
+
testnet: true
|
|
1051
|
+
};
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
const $909ea10c4deb7831$export$f92d15367ea6b4f7 = [
|
|
1055
|
+
(0, $3fea037b39853544$export$625cf84d855940d4),
|
|
1056
|
+
(0, $5cd11e46a9ac45df$export$857f1b5f596fb425),
|
|
1057
|
+
(0, $ef71324da6e93be6$export$50b37201a1017e1e),
|
|
1058
|
+
(0, $e5636bd4149958a1$export$31254237fd28c61a),
|
|
1059
|
+
(0, $2fd08fe5279c649f$export$536d3e0d2c7baf54),
|
|
1060
|
+
(0, $c0fc898708b5c03c$export$e584d4a579189f9b),
|
|
1061
|
+
(0, $20cda9ec9bdd69ae$export$50b3e5cabd7d7a60),
|
|
1062
|
+
(0, $dae31d00cceb5ed1$export$b7b19aa0ee06c73),
|
|
1063
|
+
(0, $4e8fde1a95428707$export$34b6ef3a78067459),
|
|
1064
|
+
(0, $1fe6d49303d1b309$export$671bdf559232d1e0),
|
|
1065
|
+
(0, $794e5fcc6fbcd8df$export$ea1d1a16df546697),
|
|
1066
|
+
(0, $dd9c9d3f892375a3$export$d5a6d2ad15089d83),
|
|
1067
|
+
(0, $f3a92deaec4182c8$export$de9b05abdae7c2c),
|
|
1068
|
+
(0, $8e5ed855f7f912d0$export$e2253033e6e1df16),
|
|
1069
|
+
(0, $f54a2e14e1d8a57d$export$8ae5747389a6ab6b),
|
|
1070
|
+
(0, $7507f76ddce18ab1$export$7d9a0b32b656284d),
|
|
1071
|
+
(0, $db0add24f91165c9$export$9b359a3964075c2b),
|
|
1072
|
+
(0, $f2266046a7507579$export$ca1d15c01fde7266),
|
|
1073
|
+
(0, $0bbdff61bcb77830$export$714c92acd9d3100a)
|
|
1074
|
+
];
|
|
1075
|
+
const $909ea10c4deb7831$export$3486db705befb001 = new Set($909ea10c4deb7831$export$f92d15367ea6b4f7.map((chain)=>chain.id));
|
|
1076
|
+
|
|
1077
|
+
|
|
1078
|
+
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* We support a subset of the provider methods found here:
|
|
1082
|
+
*
|
|
1083
|
+
* https://ethereum.org/en/developers/docs/apis/json-rpc/#json-rpc-methods
|
|
1084
|
+
*
|
|
1085
|
+
* For now, we're focused on signing-related methods because the iframe (this code)
|
|
1086
|
+
* is the only place that has access to the private key and thus is the only one
|
|
1087
|
+
* who can create signatures. All other methods do not need the private key and
|
|
1088
|
+
* can therefore be implemented by clients of the iframe.
|
|
1089
|
+
*/ const $0e2651eab08b0995$export$c70f8b9e7a68f3d9 = [
|
|
1090
|
+
"eth_sign",
|
|
1091
|
+
"eth_populateTransactionRequest",
|
|
1092
|
+
"eth_signTransaction",
|
|
1093
|
+
"personal_sign",
|
|
1094
|
+
"eth_signTypedData_v4"
|
|
1095
|
+
];
|
|
1096
|
+
const $0e2651eab08b0995$export$ed257f2588d73f92 = (method)=>{
|
|
1097
|
+
return $0e2651eab08b0995$export$c70f8b9e7a68f3d9.includes(method);
|
|
1098
|
+
};
|
|
1099
|
+
const $0e2651eab08b0995$export$beaff6b088e4f134 = [
|
|
1100
|
+
"error",
|
|
1101
|
+
"invalid_request_arguments",
|
|
1102
|
+
"wallet_not_on_device",
|
|
1103
|
+
"invalid_recovery_pin",
|
|
1104
|
+
"insufficient_funds"
|
|
1105
|
+
];
|
|
1106
|
+
|
|
1107
|
+
|
|
1108
|
+
var $7a102e2cbe11da0c$export$bcef4598d6aa064e;
|
|
1109
|
+
(function(PrivyErrorCode) {
|
|
1110
|
+
PrivyErrorCode["MISSING_OR_INVALID_PRIVY_APP_ID"] = "missing_or_invalid_privy_app_id";
|
|
1111
|
+
PrivyErrorCode["MISSING_OR_INVALID_PRIVY_ACCOUNT_ID"] = "missing_or_invalid_privy_account_id";
|
|
1112
|
+
PrivyErrorCode["INVALID_DATA"] = "invalid_data";
|
|
1113
|
+
PrivyErrorCode["LINKED_TO_ANOTHER_USER"] = "linked_to_another_user";
|
|
1114
|
+
PrivyErrorCode["ALLOWLIST_REJECTED"] = "allowlist_rejected";
|
|
1115
|
+
PrivyErrorCode["OAUTH_USER_DENIED"] = "oauth_user_denied";
|
|
1116
|
+
PrivyErrorCode["UNKNOWN_AUTH_ERROR"] = "unknown_auth_error";
|
|
1117
|
+
PrivyErrorCode["USER_EXITED_AUTH_FLOW"] = "exited_auth_flow";
|
|
1118
|
+
PrivyErrorCode["MUST_BE_AUTHENTICATED"] = "must_be_authenticated";
|
|
1119
|
+
PrivyErrorCode["UNKNOWN_CONNECT_WALLET_ERROR"] = "unknown_connect_wallet_error";
|
|
1120
|
+
PrivyErrorCode["GENERIC_CONNECT_WALLET_ERROR"] = "generic_connect_wallet_error";
|
|
1121
|
+
PrivyErrorCode["CLIENT_REQUEST_TIMEOUT"] = "client_request_timeout";
|
|
1122
|
+
PrivyErrorCode["INVALID_CREDENTIALS"] = "invalid_credentials";
|
|
1123
|
+
})($7a102e2cbe11da0c$export$bcef4598d6aa064e || ($7a102e2cbe11da0c$export$bcef4598d6aa064e = {}));
|
|
1124
|
+
class $7a102e2cbe11da0c$export$40842056b5426348 extends Error {
|
|
1125
|
+
/**
|
|
1126
|
+
* @param type Privy error type.
|
|
1127
|
+
* @param message Human-readable message.
|
|
1128
|
+
* @param cause Source of this error.
|
|
1129
|
+
*/ constructor(message, cause, privyErrorCode){
|
|
1130
|
+
super(message);
|
|
1131
|
+
if (cause instanceof Error) this.cause = cause;
|
|
1132
|
+
this.privyErrorCode = privyErrorCode;
|
|
1133
|
+
}
|
|
1134
|
+
toString() {
|
|
1135
|
+
return `${this.type}${this.privyErrorCode ? `-${this.privyErrorCode}` : ""}: ${this.message}${this.cause ? ` [cause: ${this.cause}]` : ""}`;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
class $7a102e2cbe11da0c$export$417589b978208a8f extends $7a102e2cbe11da0c$export$40842056b5426348 {
|
|
1139
|
+
constructor(message, code, data){
|
|
1140
|
+
super(message);
|
|
1141
|
+
this.type = "provider_error";
|
|
1142
|
+
this.code = code;
|
|
1143
|
+
this.data = data;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
class $7a102e2cbe11da0c$export$4ee5e2a38200b61e extends Error {
|
|
1147
|
+
constructor(type, message){
|
|
1148
|
+
super(message);
|
|
1149
|
+
this.type = type;
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
class $7a102e2cbe11da0c$export$75d61f1bcb44b776 extends $7a102e2cbe11da0c$export$40842056b5426348 {
|
|
1153
|
+
constructor(message, cause, privyErrorCode){
|
|
1154
|
+
super(message, cause, privyErrorCode);
|
|
1155
|
+
this.type = "connector_error";
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
class $7a102e2cbe11da0c$export$7c35c76e874bdcb extends Error {
|
|
1159
|
+
constructor(message, code, data){
|
|
1160
|
+
super(message);
|
|
1161
|
+
this.code = code;
|
|
1162
|
+
this.data = data;
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
function $7a102e2cbe11da0c$export$141c9b0218e5efe9(error) {
|
|
1166
|
+
const type = error.type;
|
|
1167
|
+
return typeof type === "string" && (0, $0e2651eab08b0995$export$beaff6b088e4f134).includes(type);
|
|
1168
|
+
}
|
|
1169
|
+
function $7a102e2cbe11da0c$export$8e5517a02da6043(error) {
|
|
1170
|
+
return $7a102e2cbe11da0c$export$141c9b0218e5efe9(error) && error.type === "wallet_not_on_device";
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
const $fe8dd73ef21c3024$var$SUPPORTED_STATIC_METHODS = [
|
|
1175
|
+
"eth_accounts",
|
|
1176
|
+
"eth_requestAccounts",
|
|
1177
|
+
"eth_chainId",
|
|
1178
|
+
"eth_estimateGas",
|
|
1179
|
+
"wallet_switchEthereumChain"
|
|
1180
|
+
];
|
|
1181
|
+
const $fe8dd73ef21c3024$var$SUPPORTED_JSON_RPC_METHODS = [
|
|
1182
|
+
"eth_sign",
|
|
1183
|
+
"eth_populateTransactionRequest",
|
|
1184
|
+
"eth_signTransaction",
|
|
1185
|
+
"personal_sign",
|
|
1186
|
+
"eth_signTypedData_v4"
|
|
1187
|
+
];
|
|
1188
|
+
const $fe8dd73ef21c3024$export$ed257f2588d73f92 = (method)=>{
|
|
1189
|
+
return $fe8dd73ef21c3024$var$SUPPORTED_JSON_RPC_METHODS.includes(method);
|
|
1190
|
+
};
|
|
1191
|
+
const $fe8dd73ef21c3024$export$1994a077b98ee0d5 = (method)=>$fe8dd73ef21c3024$var$SUPPORTED_STATIC_METHODS.includes(method);
|
|
1192
|
+
|
|
1193
|
+
|
|
1194
|
+
|
|
1195
|
+
const $93c0a15e49a033eb$export$e682a3879cb3666e = "4df5e2316331463a9130964bd6078dfa";
|
|
1196
|
+
const $93c0a15e49a033eb$export$5cf1676300c48d00 = "fe9c30fc-3bc5-4064-91e2-6ab5887f8f4d";
|
|
1197
|
+
const $93c0a15e49a033eb$export$45f1e355ab86a109 = (chainId, chains, rpcConfig)=>{
|
|
1198
|
+
const chainIdInt = Number(chainId);
|
|
1199
|
+
const chain = chains.find((chain)=>chain.id === chainIdInt);
|
|
1200
|
+
if (!chain) throw new (0, $7a102e2cbe11da0c$export$75d61f1bcb44b776)(`Unsupported chainId ${chainId}`, 4901);
|
|
1201
|
+
let rpcUrl;
|
|
1202
|
+
// Priority given to bring-your-own RPC -> Infura -> Blast -> Default
|
|
1203
|
+
if (rpcConfig.rpcUrls[chainIdInt]) rpcUrl = rpcConfig.rpcUrls[chainIdInt];
|
|
1204
|
+
else if (chain.rpcUrls["infura"]?.http[0]) rpcUrl = chain.rpcUrls["infura"].http[0] + "/" + $93c0a15e49a033eb$export$e682a3879cb3666e;
|
|
1205
|
+
else if (chain.rpcUrls["blast"]?.http[0]) rpcUrl = chain.rpcUrls["blast"].http[0] + "/" + $93c0a15e49a033eb$export$5cf1676300c48d00;
|
|
1206
|
+
else rpcUrl = chain.rpcUrls["default"]?.http[0];
|
|
1207
|
+
if (!rpcUrl) throw new (0, $7a102e2cbe11da0c$export$75d61f1bcb44b776)(`No RPC url found for ${chainId}`);
|
|
1208
|
+
return rpcUrl;
|
|
1209
|
+
};
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
class $ed667f6fcbd5f0f2$export$26f7ada50d209c97 extends (0, $fdlOJ$eventemitter3) {
|
|
1213
|
+
#walletProxy;
|
|
1214
|
+
#privyInternal;
|
|
1215
|
+
#address;
|
|
1216
|
+
#chainId;
|
|
1217
|
+
#chains;
|
|
1218
|
+
#provider;
|
|
1219
|
+
/**
|
|
1220
|
+
* @internal
|
|
1221
|
+
*/ constructor({ walletProxy: walletProxy, privyInternal: privyInternal, address: address, chains: chains, chainId: chainId = 1 }){
|
|
1222
|
+
super();
|
|
1223
|
+
this.#walletProxy = walletProxy;
|
|
1224
|
+
this.#privyInternal = privyInternal;
|
|
1225
|
+
this.#address = address;
|
|
1226
|
+
this.#chainId = chainId;
|
|
1227
|
+
this.#chains = chains;
|
|
1228
|
+
this.#provider = new (0, $fdlOJ$StaticJsonRpcProvider)((0, $93c0a15e49a033eb$export$45f1e355ab86a109)(chainId, chains, {
|
|
1229
|
+
rpcUrls: []
|
|
1230
|
+
}));
|
|
1231
|
+
}
|
|
1232
|
+
async request(request) {
|
|
1233
|
+
if ((0, $fe8dd73ef21c3024$export$ed257f2588d73f92)(request.method)) return this.handleIFrameRpc(request);
|
|
1234
|
+
else if ((0, $fe8dd73ef21c3024$export$1994a077b98ee0d5)(request.method)) return this.handleStatic(request);
|
|
1235
|
+
else if (request.method === "eth_estimateGas") return this.handleEstimateGas(request);
|
|
1236
|
+
else return this.handleJsonRpc(request);
|
|
1237
|
+
}
|
|
1238
|
+
async handleStatic(request) {
|
|
1239
|
+
switch(request.method){
|
|
1240
|
+
case "eth_accounts":
|
|
1241
|
+
case "eth_requestAccounts":
|
|
1242
|
+
return this.#address ? [
|
|
1243
|
+
this.#address
|
|
1244
|
+
] : [];
|
|
1245
|
+
case "eth_chainId":
|
|
1246
|
+
return `0x${this.#chainId.toString(16)}`;
|
|
1247
|
+
case "wallet_switchEthereumChain":
|
|
1248
|
+
return this.handleSwitchEthereumChain(request);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
async handleEstimateGas(args) {
|
|
1252
|
+
if (!args.params || !Array.isArray(args.params)) throw new Error("Invalid params for eth_estimateGas");
|
|
1253
|
+
// Delete gas parameters to avoid balance checks
|
|
1254
|
+
delete args.params[0].gasPrice;
|
|
1255
|
+
delete args.params[0].maxFeePerGas;
|
|
1256
|
+
delete args.params[0].maxPriorityFeePerGas;
|
|
1257
|
+
// Empirically observed that we need:
|
|
1258
|
+
// 1. The chainId, so we add it.
|
|
1259
|
+
const txRequest = {
|
|
1260
|
+
...args.params[0],
|
|
1261
|
+
chainId: `0x${this.#chainId.toString(16)}`
|
|
1262
|
+
};
|
|
1263
|
+
try {
|
|
1264
|
+
return await this.#provider.send("eth_estimateGas", [
|
|
1265
|
+
txRequest
|
|
1266
|
+
]);
|
|
1267
|
+
} catch (e) {
|
|
1268
|
+
// If the original request fails, it may be because the wallet has insufficient funds.
|
|
1269
|
+
// We want to produce a successful gas estimate even if the wallet does not have funds,
|
|
1270
|
+
// because ethers prevents `eth_sendTransaction` from being called if gas estimation fails.
|
|
1271
|
+
// We only try this if the original request fails, because some transactions include logic
|
|
1272
|
+
// that requires the `from` address in order for gas to be computed.
|
|
1273
|
+
delete txRequest.from;
|
|
1274
|
+
return await this.#provider.send("eth_estimateGas", [
|
|
1275
|
+
txRequest
|
|
1276
|
+
]);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
handleSwitchEthereumChain(args) {
|
|
1280
|
+
if (!args.params || !Array.isArray(args.params)) // 4200 = unsupported method
|
|
1281
|
+
throw new (0, $7a102e2cbe11da0c$export$7c35c76e874bdcb)(`Invalid params for ${args.method}`, 4200);
|
|
1282
|
+
let newChain;
|
|
1283
|
+
// Legacy support for passing in a chainId as a string.
|
|
1284
|
+
// The standard is to pass in an object with a chainId property.
|
|
1285
|
+
// https://eips.ethereum.org/EIPS/eip-3326#parameters
|
|
1286
|
+
if (typeof args.params[0] === "string") newChain = args.params[0];
|
|
1287
|
+
else if ("chainId" in args.params[0] && typeof args.params[0].chainId === "string") newChain = args.params[0].chainId;
|
|
1288
|
+
else // 4200 = unsupported method
|
|
1289
|
+
throw new (0, $7a102e2cbe11da0c$export$7c35c76e874bdcb)(`Invalid params for ${args.method}`, 4200);
|
|
1290
|
+
// It will be passed as a hexString, convert to number.
|
|
1291
|
+
this.#chainId = Number(newChain);
|
|
1292
|
+
this.#provider = new (0, $fdlOJ$StaticJsonRpcProvider)((0, $93c0a15e49a033eb$export$45f1e355ab86a109)(this.#chainId, this.#chains, {
|
|
1293
|
+
rpcUrls: []
|
|
1294
|
+
}));
|
|
1295
|
+
this.emit("chainChanged", newChain);
|
|
1296
|
+
}
|
|
1297
|
+
async handleIFrameRpc(request) {
|
|
1298
|
+
try {
|
|
1299
|
+
const token = await this.#privyInternal.getAccessToken();
|
|
1300
|
+
if (!token) throw new Error("Missing privy token. User must be logged in");
|
|
1301
|
+
const result = await this.#walletProxy.rpc({
|
|
1302
|
+
request: request,
|
|
1303
|
+
address: this.#address,
|
|
1304
|
+
accessToken: token
|
|
1305
|
+
});
|
|
1306
|
+
return result.response.data;
|
|
1307
|
+
} catch (error) {
|
|
1308
|
+
console.error(error);
|
|
1309
|
+
// TODO: Add error
|
|
1310
|
+
throw new Error("Unable to make wallet request");
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
async handleJsonRpc(request) {
|
|
1314
|
+
return this.#provider.send(request.method, request.params ?? []);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
class $c49329927a06d75f$export$4a16012cef0432f7 {
|
|
1320
|
+
enqueue(eventId, callbacks) {
|
|
1321
|
+
this.callbacks[eventId] = callbacks;
|
|
1322
|
+
}
|
|
1323
|
+
dequeue(event, eventId) {
|
|
1324
|
+
const callbacks = this.callbacks[eventId];
|
|
1325
|
+
if (!callbacks) // If this happens, it is a bug with Privy's code.
|
|
1326
|
+
throw new Error(`cannot dequeue ${event} event: no event found for id ${eventId}`);
|
|
1327
|
+
delete this.callbacks[eventId];
|
|
1328
|
+
switch(event){
|
|
1329
|
+
case "privy:iframe:ready":
|
|
1330
|
+
return callbacks;
|
|
1331
|
+
case "privy:wallet:create":
|
|
1332
|
+
return callbacks;
|
|
1333
|
+
case "privy:wallet:connect":
|
|
1334
|
+
return callbacks;
|
|
1335
|
+
case "privy:wallet:recover":
|
|
1336
|
+
return callbacks;
|
|
1337
|
+
case "privy:wallet:rpc":
|
|
1338
|
+
return callbacks;
|
|
1339
|
+
default:
|
|
1340
|
+
throw new Error(`invalid wallet event type ${event}`);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
constructor(){
|
|
1344
|
+
this.callbacks = {};
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
|
|
1349
|
+
|
|
1350
|
+
const $c244c00b386c92f6$export$4702905edceab12f = 15000;
|
|
1351
|
+
function $c244c00b386c92f6$var$isErrorResponseEvent(event) {
|
|
1352
|
+
return event.error !== undefined;
|
|
1353
|
+
}
|
|
1354
|
+
// We'll need unique identifiers to associate with each event.
|
|
1355
|
+
const $c244c00b386c92f6$var$uniqueId = function(id) {
|
|
1356
|
+
return ()=>`id-${id++}`;
|
|
1357
|
+
}(0);
|
|
1358
|
+
// This is a lossy serialization!
|
|
1359
|
+
// i.e. trying to deserialize the output will result in `string`s where there
|
|
1360
|
+
// were originally `BigInt`s
|
|
1361
|
+
const $c244c00b386c92f6$var$replacer = (_key, value)=>typeof value === "bigint" ? value.toString() : value;
|
|
1362
|
+
const $c244c00b386c92f6$var$serialize = (event, data)=>`${event}${JSON.stringify(data, $c244c00b386c92f6$var$replacer)}`;
|
|
1363
|
+
const $c244c00b386c92f6$var$sleep = (ms)=>{
|
|
1364
|
+
return new Promise((resolve)=>{
|
|
1365
|
+
setTimeout(resolve, ms);
|
|
1366
|
+
});
|
|
1367
|
+
};
|
|
1368
|
+
const $c244c00b386c92f6$var$expiringPromise = (promise, ms)=>{
|
|
1369
|
+
return Promise.race([
|
|
1370
|
+
promise,
|
|
1371
|
+
new Promise((_, reject)=>{
|
|
1372
|
+
setTimeout(reject, ms);
|
|
1373
|
+
})
|
|
1374
|
+
]);
|
|
1375
|
+
};
|
|
1376
|
+
class $c244c00b386c92f6$export$574bb90dcdb39533 {
|
|
1377
|
+
#embeddedWalletMessagePoster;
|
|
1378
|
+
constructor(embeddedWalletMessagePoster){
|
|
1379
|
+
this.ready = false;
|
|
1380
|
+
this.cache = new Map();
|
|
1381
|
+
this.eventCallbacks = new (0, $c49329927a06d75f$export$4a16012cef0432f7)();
|
|
1382
|
+
this.#embeddedWalletMessagePoster = embeddedWalletMessagePoster;
|
|
1383
|
+
}
|
|
1384
|
+
async create(data, timeoutMs = $c244c00b386c92f6$export$4702905edceab12f) {
|
|
1385
|
+
await this.waitForReady();
|
|
1386
|
+
return $c244c00b386c92f6$var$expiringPromise(this.invoke("privy:wallet:create", data, this.#embeddedWalletMessagePoster), timeoutMs);
|
|
1387
|
+
}
|
|
1388
|
+
async connect(data, timeoutMs = $c244c00b386c92f6$export$4702905edceab12f) {
|
|
1389
|
+
await this.waitForReady();
|
|
1390
|
+
return $c244c00b386c92f6$var$expiringPromise(this.invoke("privy:wallet:connect", data, this.#embeddedWalletMessagePoster), timeoutMs);
|
|
1391
|
+
}
|
|
1392
|
+
async recover(data, timeoutMs = $c244c00b386c92f6$export$4702905edceab12f) {
|
|
1393
|
+
await this.waitForReady();
|
|
1394
|
+
return $c244c00b386c92f6$var$expiringPromise(this.invoke("privy:wallet:recover", data, this.#embeddedWalletMessagePoster), timeoutMs);
|
|
1395
|
+
}
|
|
1396
|
+
async setPassword(data, timeoutMs = $c244c00b386c92f6$export$4702905edceab12f) {
|
|
1397
|
+
await this.waitForReady();
|
|
1398
|
+
return $c244c00b386c92f6$var$expiringPromise(this.invoke("privy:wallet:set-recovery-password", data, this.#embeddedWalletMessagePoster), timeoutMs);
|
|
1399
|
+
}
|
|
1400
|
+
async rpc(data, timeoutMs = $c244c00b386c92f6$export$4702905edceab12f) {
|
|
1401
|
+
await this.waitForReady();
|
|
1402
|
+
return $c244c00b386c92f6$var$expiringPromise(this.invoke("privy:wallet:rpc", data, this.#embeddedWalletMessagePoster), timeoutMs);
|
|
1403
|
+
}
|
|
1404
|
+
handleEmbeddedWalletMessages(event) {
|
|
1405
|
+
switch(event.event){
|
|
1406
|
+
case "privy:iframe:ready":
|
|
1407
|
+
const readyCallbacks = this.eventCallbacks.dequeue(event.event, event.id);
|
|
1408
|
+
if ($c244c00b386c92f6$var$isErrorResponseEvent(event)) return readyCallbacks.reject(new (0, $7a102e2cbe11da0c$export$4ee5e2a38200b61e)(event.error.type, event.error.message));
|
|
1409
|
+
else return readyCallbacks.resolve(event.data);
|
|
1410
|
+
case "privy:wallet:create":
|
|
1411
|
+
const createCallbacks = this.eventCallbacks.dequeue(event.event, event.id);
|
|
1412
|
+
if ($c244c00b386c92f6$var$isErrorResponseEvent(event)) return createCallbacks.reject(new (0, $7a102e2cbe11da0c$export$4ee5e2a38200b61e)(event.error.type, event.error.message));
|
|
1413
|
+
else return createCallbacks.resolve(event.data);
|
|
1414
|
+
case "privy:wallet:connect":
|
|
1415
|
+
const connectCallbacks = this.eventCallbacks.dequeue(event.event, event.id);
|
|
1416
|
+
if ($c244c00b386c92f6$var$isErrorResponseEvent(event)) return connectCallbacks.reject(new (0, $7a102e2cbe11da0c$export$4ee5e2a38200b61e)(event.error.type, event.error.message));
|
|
1417
|
+
else return connectCallbacks.resolve(event.data);
|
|
1418
|
+
case "privy:wallet:recover":
|
|
1419
|
+
const recoverCallbacks = this.eventCallbacks.dequeue(event.event, event.id);
|
|
1420
|
+
if ($c244c00b386c92f6$var$isErrorResponseEvent(event)) return recoverCallbacks.reject(new (0, $7a102e2cbe11da0c$export$4ee5e2a38200b61e)(event.error.type, event.error.message));
|
|
1421
|
+
else return recoverCallbacks.resolve(event.data);
|
|
1422
|
+
case "privy:wallet:rpc":
|
|
1423
|
+
const rpcCallbacks = this.eventCallbacks.dequeue(event.event, event.id);
|
|
1424
|
+
if ($c244c00b386c92f6$var$isErrorResponseEvent(event)) return rpcCallbacks.reject(new (0, $7a102e2cbe11da0c$export$4ee5e2a38200b61e)(event.error.type, event.error.message));
|
|
1425
|
+
else return rpcCallbacks.resolve(event.data);
|
|
1426
|
+
case "privy:wallet:set-recovery-password":
|
|
1427
|
+
const cb = this.eventCallbacks.dequeue(event.event, event.id);
|
|
1428
|
+
if ($c244c00b386c92f6$var$isErrorResponseEvent(event)) return cb.reject(new (0, $7a102e2cbe11da0c$export$4ee5e2a38200b61e)(event.error.type, event.error.message));
|
|
1429
|
+
else return cb.resolve(event.data);
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
async waitForReady() {
|
|
1433
|
+
if (this.ready) return;
|
|
1434
|
+
return new Promise(async (resolve, reject)=>{
|
|
1435
|
+
while(!this.ready){
|
|
1436
|
+
this.invoke("privy:iframe:ready", {}, this.#embeddedWalletMessagePoster).then(()=>{
|
|
1437
|
+
this.ready = true;
|
|
1438
|
+
resolve(null);
|
|
1439
|
+
}).catch(reject);
|
|
1440
|
+
await $c244c00b386c92f6$var$sleep(150);
|
|
1441
|
+
}
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
async invoke(event, data, embeddedWalletMessagePoster) {
|
|
1445
|
+
const key = $c244c00b386c92f6$var$serialize(event, data);
|
|
1446
|
+
if (event === "privy:wallet:create") {
|
|
1447
|
+
const cached = this.cache.get(key);
|
|
1448
|
+
if (cached) return cached;
|
|
1449
|
+
}
|
|
1450
|
+
// This is the promise that is returned to outside callers so they can use async functions.
|
|
1451
|
+
const res = new Promise((resolve, reject)=>{
|
|
1452
|
+
// Create a unique ID for this event.
|
|
1453
|
+
const eventId = $c244c00b386c92f6$var$uniqueId();
|
|
1454
|
+
// Enqueue callbacks for this event associated with the unique id.
|
|
1455
|
+
this.eventCallbacks.enqueue(eventId, {
|
|
1456
|
+
resolve: resolve,
|
|
1457
|
+
reject: reject
|
|
1458
|
+
});
|
|
1459
|
+
// Send the iframe this event. We pass along the unique event id so that when it
|
|
1460
|
+
// sends us a response back, we are able to pair it back to the originating request.
|
|
1461
|
+
// TODO: Target proper destination: https://github.com/privy-io/react-auth/pull/596
|
|
1462
|
+
embeddedWalletMessagePoster.postMessage({
|
|
1463
|
+
id: eventId,
|
|
1464
|
+
event: event,
|
|
1465
|
+
data: data
|
|
1466
|
+
}, "*");
|
|
1467
|
+
}).finally(()=>{
|
|
1468
|
+
this.cache.delete(key);
|
|
1469
|
+
});
|
|
1470
|
+
this.cache.set(key, res);
|
|
1471
|
+
return res;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
|
|
1476
|
+
|
|
1477
|
+
|
|
1478
|
+
|
|
1479
|
+
class $c838da93fb583f7c$export$2e2bcd8739ae039 {
|
|
1480
|
+
/**
|
|
1481
|
+
* @internal
|
|
1482
|
+
*/ #privyInternal;
|
|
1483
|
+
/**
|
|
1484
|
+
* @internal
|
|
1485
|
+
*/ #proxy;
|
|
1486
|
+
/**
|
|
1487
|
+
* @internal
|
|
1488
|
+
*/ #chains;
|
|
1489
|
+
/**
|
|
1490
|
+
* @internal
|
|
1491
|
+
*/ constructor(privyInternal, embeddedWalletMessagePoster){
|
|
1492
|
+
this.#chains = (0, $909ea10c4deb7831$export$f92d15367ea6b4f7).map((chain)=>chain);
|
|
1493
|
+
this.#privyInternal = privyInternal;
|
|
1494
|
+
if (embeddedWalletMessagePoster) this.#proxy = new (0, $c244c00b386c92f6$export$574bb90dcdb39533)(embeddedWalletMessagePoster);
|
|
1495
|
+
}
|
|
1496
|
+
setMessagePoster(poster) {
|
|
1497
|
+
this.#proxy = new (0, $c244c00b386c92f6$export$574bb90dcdb39533)(poster);
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Creates an embedded wallet
|
|
1501
|
+
*
|
|
1502
|
+
* @param password Recovery password for the embedded wallet
|
|
1503
|
+
* @returns EmbeddedWalletProvider implementing EIP1193Provider
|
|
1504
|
+
*/ async create(password) {
|
|
1505
|
+
if (!this.#proxy) throw new Error("Embedded wallet proxy not initialized");
|
|
1506
|
+
if (!password && this.#privyInternal.config?.embedded_wallet_config.require_user_password_on_create) throw new Error("Password not provided yet is required by App configuration");
|
|
1507
|
+
const accessToken = await this.#privyInternal.getAccessToken();
|
|
1508
|
+
if (!accessToken) throw new Error("User must be logged in to create an embedded wallet");
|
|
1509
|
+
const { address: address } = await this.#proxy.create({
|
|
1510
|
+
accessToken: accessToken,
|
|
1511
|
+
recoveryPassword: password
|
|
1512
|
+
});
|
|
1513
|
+
if (!address) throw new Error("Failed to create wallet");
|
|
1514
|
+
return new (0, $ed667f6fcbd5f0f2$export$26f7ada50d209c97)({
|
|
1515
|
+
address: address,
|
|
1516
|
+
privyInternal: this.#privyInternal,
|
|
1517
|
+
chains: this.#chains,
|
|
1518
|
+
walletProxy: this.#proxy
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Retrieve this users embedded wallet.
|
|
1523
|
+
* If the wallet has never been used on this device recover.
|
|
1524
|
+
*
|
|
1525
|
+
* @param password Recovery password for the embedded wallet
|
|
1526
|
+
* @returns EmbeddedWalletProvider implementing EIP1193Provider
|
|
1527
|
+
*/ async getProvider(password) {
|
|
1528
|
+
if (!this.#proxy) throw new Error("Embedded wallet proxy not initialized");
|
|
1529
|
+
const address = await this.#load(password);
|
|
1530
|
+
return new (0, $ed667f6fcbd5f0f2$export$26f7ada50d209c97)({
|
|
1531
|
+
address: address,
|
|
1532
|
+
privyInternal: this.#privyInternal,
|
|
1533
|
+
chains: this.#chains,
|
|
1534
|
+
walletProxy: this.#proxy
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
/**
|
|
1538
|
+
* Add or change the password used to recover an embedded wallet.
|
|
1539
|
+
*
|
|
1540
|
+
* @param password New recovery password
|
|
1541
|
+
* @param currentPassword Current recovery password used to recover the embedded wallet
|
|
1542
|
+
* @returns EmbeddedWalletProvider implementing EIP1193Provider
|
|
1543
|
+
*/ async setPassword(password, currentPassword) {
|
|
1544
|
+
if (!this.#proxy) throw new Error("Embedded wallet proxy not initialized");
|
|
1545
|
+
const address = await this.#load(currentPassword);
|
|
1546
|
+
const accessToken = await this.#privyInternal.getAccessToken();
|
|
1547
|
+
if (!accessToken) throw new Error("User must be logged in to create an embedded wallet");
|
|
1548
|
+
await this.#proxy.setPassword({
|
|
1549
|
+
accessToken: accessToken,
|
|
1550
|
+
address: address,
|
|
1551
|
+
recoveryPassword: password
|
|
1552
|
+
});
|
|
1553
|
+
return new (0, $ed667f6fcbd5f0f2$export$26f7ada50d209c97)({
|
|
1554
|
+
address: address,
|
|
1555
|
+
privyInternal: this.#privyInternal,
|
|
1556
|
+
chains: this.#chains,
|
|
1557
|
+
walletProxy: this.#proxy
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
/**
|
|
1561
|
+
* @returns URL to load in the embedded wallet iframe
|
|
1562
|
+
*/ getURL() {
|
|
1563
|
+
return `${this.#privyInternal.baseUrl}/apps/${this.#privyInternal.appId}/embedded-wallets`;
|
|
1564
|
+
}
|
|
1565
|
+
/**
|
|
1566
|
+
* @returns Allows the user to subscribe
|
|
1567
|
+
* to the response events from the embedded wallet iframe
|
|
1568
|
+
*
|
|
1569
|
+
* @example
|
|
1570
|
+
* const handler = privy.wallet.getMessageHandler()
|
|
1571
|
+
* window.addEventListener('message', handler)
|
|
1572
|
+
*/ getMessageHandler() {
|
|
1573
|
+
if (!this.#proxy) throw new Error("Embedded wallet proxy not initialized");
|
|
1574
|
+
return this.#proxy.handleEmbeddedWalletMessages.bind(this.#proxy);
|
|
1575
|
+
}
|
|
1576
|
+
/**
|
|
1577
|
+
* Attempt to get an embedded wallet with a device share. If no
|
|
1578
|
+
* device share is present then recover the wallet.
|
|
1579
|
+
* @param password the pin used to encrypt the user's recovery share
|
|
1580
|
+
* @returns
|
|
1581
|
+
*/ async #load(password) {
|
|
1582
|
+
if (!this.#proxy) throw new Error("Embedded wallet proxy not initialized");
|
|
1583
|
+
const { user: user, token: token } = await this.#privyInternal.refreshSession();
|
|
1584
|
+
if (!token) throw new Error("User must be logged in to interact with embedded wallets");
|
|
1585
|
+
const embeddedWallet = user?.linked_accounts.find((account)=>account.type === "wallet" && account.connector_type === "embedded" && account.wallet_client_type === "privy");
|
|
1586
|
+
if (!embeddedWallet) throw new Error("User doesn't have an embedded wallet. Create one first.");
|
|
1587
|
+
const address = embeddedWallet.address;
|
|
1588
|
+
try {
|
|
1589
|
+
await this.#proxy.connect({
|
|
1590
|
+
accessToken: token,
|
|
1591
|
+
address: address
|
|
1592
|
+
});
|
|
1593
|
+
return address;
|
|
1594
|
+
} catch (err) {
|
|
1595
|
+
if ((0, $7a102e2cbe11da0c$export$8e5517a02da6043)(err) && embeddedWallet.recovery_method === "privy") {
|
|
1596
|
+
await this.#proxy.recover({
|
|
1597
|
+
accessToken: token,
|
|
1598
|
+
address: address,
|
|
1599
|
+
recoveryPassword: password
|
|
1600
|
+
});
|
|
1601
|
+
return address;
|
|
1602
|
+
} else if ((0, $7a102e2cbe11da0c$export$8e5517a02da6043)(err) && !password) // password is required
|
|
1603
|
+
throw new Error("User recovery password required");
|
|
1604
|
+
else throw err;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
|
|
1610
|
+
|
|
1611
|
+
|
|
1612
|
+
|
|
1613
|
+
var $d019bc61f66dc929$exports = {};
|
|
1614
|
+
$d019bc61f66dc929$exports = JSON.parse('{"name":"@privy-io/js-sdk-core","version":"0.1.1","description":"Vanilla JS client for the Privy Auth API","keywords":["authentication","authorization","identity","privacy","privy","user data","web3"],"license":"Apache-2.0","source":"./src/index.ts","main":"./dist/index.js","module":"./dist/esm/index.js","types":"./dist/index.d.ts","typings":"./dist/index","exports":{".":{"require":"./dist/index.js","import":"./dist/esm/index.js","types":"./dist/index.d.ts"}},"targets":{"main":{"isLibrary":true},"module":{"isLibrary":true}},"files":["dist/**/*","LICENSE","README.md"],"scripts":{"build":"npx parcel build","clean":"rm -rf dist","prepublishOnly":"npm run clean && npm run build","dev":"npx parcel watch","test":"jest --testMatch \\"**/test/unit/**/*.test.ts\\"","test:ci":"npm run test","test-integration":"jest --testMatch \\"**/test/integration/**/*.test.ts\\"","lint":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" && npx tsc --noEmit","format":"eslint \\"src/**/*.{ts,tsx,js,jsx}\\" --fix"},"devDependencies":{"@privy-io/tsconfig":"*","@tsconfig/node16-strictest-esm":"^1.0.3","@types/text-encoding":"^0.0.37","parcel":"^2.9.3"},"dependencies":{"@ethersproject/providers":"^5.7.2","@privy-io/public-api":"*","eventemitter3":"^5.0.1","fetch-retry":"^5.0.6","jose":"^4.11.2","js-cookie":"^3.0.5","text-encoding":"^0.7.0","uuid":">=8 <10"},"author":"privy.io","browserslist":["defaults","node >= 18","not op_mini all"],"publishConfig":{"access":"public"}}');
|
|
1615
|
+
|
|
1616
|
+
|
|
1617
|
+
|
|
1618
|
+
|
|
1619
|
+
class $dafc1d5a5d2c2ddb$export$50792b0e93539fde {
|
|
1620
|
+
static parse(token) {
|
|
1621
|
+
try {
|
|
1622
|
+
return new $dafc1d5a5d2c2ddb$export$50792b0e93539fde(token);
|
|
1623
|
+
} catch (error) {
|
|
1624
|
+
return null;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
constructor(value){
|
|
1628
|
+
this.value = value;
|
|
1629
|
+
this._decoded = $fdlOJ$decodeJwt(value);
|
|
1630
|
+
}
|
|
1631
|
+
/**
|
|
1632
|
+
* The subject is the user id to which this token is assigned.
|
|
1633
|
+
*/ get subject() {
|
|
1634
|
+
return this._decoded.sub;
|
|
1635
|
+
}
|
|
1636
|
+
/**
|
|
1637
|
+
* The date in seconds since Epoch that this token expires.
|
|
1638
|
+
*/ get expiration() {
|
|
1639
|
+
return this._decoded.exp;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* The party that issued the token, which should always be 'privy.io'
|
|
1643
|
+
*/ get issuer() {
|
|
1644
|
+
return this._decoded.iss;
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* The token audience, which will be the app ID for the customer app.'
|
|
1648
|
+
*/ get audience() {
|
|
1649
|
+
return this._decoded.aud;
|
|
1650
|
+
}
|
|
1651
|
+
/**
|
|
1652
|
+
* Whether or not the token is to be considered expired.
|
|
1653
|
+
*
|
|
1654
|
+
* @param {number} seconds A number in seconds to reduce the expiration time by. Defaults to 0
|
|
1655
|
+
*/ isExpired(seconds = 0) {
|
|
1656
|
+
const now = Date.now();
|
|
1657
|
+
const expiration = (this.expiration - seconds) * 1000;
|
|
1658
|
+
return now >= expiration;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
|
|
1663
|
+
const $f7be880219889a89$var$TOKEN_STORAGE_KEY = "privy:token";
|
|
1664
|
+
const $f7be880219889a89$var$TOKEN_COOKIE_KEY = "privy-token";
|
|
1665
|
+
const $f7be880219889a89$var$REFRESH_TOKEN_STORAGE_KEY = "privy:refresh_token";
|
|
1666
|
+
const $f7be880219889a89$var$REFRESH_TOKEN_COOKIE_KEY = "privy-refresh-token";
|
|
1667
|
+
const $f7be880219889a89$var$SESSION_COOKIE_KEY = "privy-session";
|
|
1668
|
+
const $f7be880219889a89$var$FORKED_TOKEN_STORAGE_KEY = "privy:session_transfer_token";
|
|
1669
|
+
// By default, a session will be considered unauthenticated
|
|
1670
|
+
// 30 seconds prior to its token's expiration time. This is
|
|
1671
|
+
// so we can eagerly re-authenticate before the server would
|
|
1672
|
+
// reject requests with a 401.
|
|
1673
|
+
const $f7be880219889a89$var$DEFAULT_EXPIRATION_PADDING_IN_SECONDS = 30;
|
|
1674
|
+
class $f7be880219889a89$export$1fb4852a55678982 {
|
|
1675
|
+
#storage;
|
|
1676
|
+
#isUsingServerCookies;
|
|
1677
|
+
constructor(o){
|
|
1678
|
+
this.#isUsingServerCookies = false;
|
|
1679
|
+
this.#storage = o.storage;
|
|
1680
|
+
}
|
|
1681
|
+
set isUsingServerCookies(isUsingServerCookies) {
|
|
1682
|
+
this.#isUsingServerCookies = isUsingServerCookies;
|
|
1683
|
+
}
|
|
1684
|
+
get token() {
|
|
1685
|
+
try {
|
|
1686
|
+
const token = this.#storage.get($f7be880219889a89$var$TOKEN_STORAGE_KEY);
|
|
1687
|
+
if (typeof token === "string") // This should throw error if the token is not a JWT
|
|
1688
|
+
return new (0, $dafc1d5a5d2c2ddb$export$50792b0e93539fde)(token).value;
|
|
1689
|
+
else return null;
|
|
1690
|
+
} catch (error) {
|
|
1691
|
+
console.error(error);
|
|
1692
|
+
this.destroyLocalState();
|
|
1693
|
+
return null;
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
get refreshToken() {
|
|
1697
|
+
try {
|
|
1698
|
+
const refreshToken = this.#storage.get($f7be880219889a89$var$REFRESH_TOKEN_STORAGE_KEY);
|
|
1699
|
+
return typeof refreshToken === "string" ? refreshToken : null;
|
|
1700
|
+
} catch (error) {
|
|
1701
|
+
console.error(error);
|
|
1702
|
+
this.destroyLocalState();
|
|
1703
|
+
return null;
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
get forkedToken() {
|
|
1707
|
+
try {
|
|
1708
|
+
const forkedToken = this.#storage.get($f7be880219889a89$var$FORKED_TOKEN_STORAGE_KEY);
|
|
1709
|
+
return typeof forkedToken === "string" ? forkedToken : null;
|
|
1710
|
+
} catch (error) {
|
|
1711
|
+
console.error(error);
|
|
1712
|
+
this.destroyLocalState();
|
|
1713
|
+
return null;
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
// Check the non-HTTPOnly server cookie. If present, it's likely that an HTTPOnly server cookie
|
|
1717
|
+
// is present, as it is set with the same lifespan as the refresh token and at the same time.
|
|
1718
|
+
get mightHaveServerCookies() {
|
|
1719
|
+
try {
|
|
1720
|
+
const sessionToken = (0, $fdlOJ$jscookie).get($f7be880219889a89$var$SESSION_COOKIE_KEY);
|
|
1721
|
+
return sessionToken !== undefined && sessionToken.length > 0;
|
|
1722
|
+
} catch (error) {
|
|
1723
|
+
console.error(error);
|
|
1724
|
+
}
|
|
1725
|
+
return false;
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
* Checks to see if locally we have refresh credentials. Refresh
|
|
1729
|
+
* credentials consist of:
|
|
1730
|
+
*
|
|
1731
|
+
* 1. Client access token and refresh token
|
|
1732
|
+
* 2. Server cookies
|
|
1733
|
+
*
|
|
1734
|
+
* @returns true if we have what appear to be valid credentials, false otherwise.
|
|
1735
|
+
*/ hasRefreshCredentials() {
|
|
1736
|
+
return this.mightHaveServerCookies || typeof this.token === "string" && typeof this.refreshToken === "string";
|
|
1737
|
+
}
|
|
1738
|
+
/**
|
|
1739
|
+
* Checks to see if locally we have recovery credentials (forked session token)
|
|
1740
|
+
*
|
|
1741
|
+
* @returns true if we have what appear to be valid credentials, false otherwise.
|
|
1742
|
+
*/ hasRecoveryCredentials() {
|
|
1743
|
+
return typeof this.forkedToken === "string";
|
|
1744
|
+
}
|
|
1745
|
+
/**
|
|
1746
|
+
* Checks if the session contains a valid token that is not
|
|
1747
|
+
* expired or expiring soon.
|
|
1748
|
+
*
|
|
1749
|
+
* @returns true if token is considered active, false otherwise.
|
|
1750
|
+
*/ hasActiveToken() {
|
|
1751
|
+
const token = (0, $dafc1d5a5d2c2ddb$export$50792b0e93539fde).parse(this.token);
|
|
1752
|
+
return token !== null && !token.isExpired($f7be880219889a89$var$DEFAULT_EXPIRATION_PADDING_IN_SECONDS);
|
|
1753
|
+
}
|
|
1754
|
+
destroyLocalState() {
|
|
1755
|
+
this.storeToken(null);
|
|
1756
|
+
this.storeRefreshToken(null);
|
|
1757
|
+
this.clearForkedToken();
|
|
1758
|
+
}
|
|
1759
|
+
storeToken(token) {
|
|
1760
|
+
if (typeof token === "string") {
|
|
1761
|
+
this.#storage.put($f7be880219889a89$var$TOKEN_STORAGE_KEY, token);
|
|
1762
|
+
if (!this.#isUsingServerCookies) {
|
|
1763
|
+
const exp = (0, $dafc1d5a5d2c2ddb$export$50792b0e93539fde).parse(token)?.expiration;
|
|
1764
|
+
(0, $fdlOJ$jscookie).set($f7be880219889a89$var$TOKEN_COOKIE_KEY, token, {
|
|
1765
|
+
sameSite: "Strict",
|
|
1766
|
+
secure: true,
|
|
1767
|
+
expires: exp ? new Date(exp * 1000) : undefined
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
} else {
|
|
1771
|
+
this.#storage.del($f7be880219889a89$var$TOKEN_STORAGE_KEY);
|
|
1772
|
+
(0, $fdlOJ$jscookie).remove($f7be880219889a89$var$TOKEN_COOKIE_KEY);
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
storeRefreshToken(refreshToken) {
|
|
1776
|
+
if (typeof refreshToken === "string") {
|
|
1777
|
+
this.#storage.put($f7be880219889a89$var$REFRESH_TOKEN_STORAGE_KEY, refreshToken);
|
|
1778
|
+
if (!this.#isUsingServerCookies) (0, $fdlOJ$jscookie).set($f7be880219889a89$var$REFRESH_TOKEN_COOKIE_KEY, refreshToken, {
|
|
1779
|
+
sameSite: "Strict",
|
|
1780
|
+
secure: true,
|
|
1781
|
+
// Note! This is capped to 7 days on Safari and Brave:
|
|
1782
|
+
// https://github.com/js-cookie/js-cookie/issues/627#issuecomment-626144237
|
|
1783
|
+
expires: 30
|
|
1784
|
+
});
|
|
1785
|
+
} else {
|
|
1786
|
+
this.#storage.del($f7be880219889a89$var$REFRESH_TOKEN_STORAGE_KEY);
|
|
1787
|
+
(0, $fdlOJ$jscookie).remove($f7be880219889a89$var$REFRESH_TOKEN_COOKIE_KEY);
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
clearForkedToken() {
|
|
1791
|
+
this.#storage.del($f7be880219889a89$var$FORKED_TOKEN_STORAGE_KEY);
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
|
|
1796
|
+
/**
|
|
1797
|
+
* Patch for AbortSignal.timeout since it is not supported in iOS Safari < 16
|
|
1798
|
+
* Adapted from: https://github.com/mo/abortcontroller-polyfill/issues/73#issuecomment-1541180943
|
|
1799
|
+
*/ const $23b60b0520ebfec6$var$toAbortSignalTimeout = (duration)=>{
|
|
1800
|
+
const controller = new AbortController();
|
|
1801
|
+
setTimeout(()=>controller.abort(), duration);
|
|
1802
|
+
return controller.signal;
|
|
1803
|
+
};
|
|
1804
|
+
var $23b60b0520ebfec6$export$2e2bcd8739ae039 = $23b60b0520ebfec6$var$toAbortSignalTimeout;
|
|
1805
|
+
|
|
1806
|
+
|
|
1807
|
+
const $d20bcd05f51689d2$var$DEFAULT_PRIVY_API_URL = "https://auth.privy.io";
|
|
1808
|
+
class $d20bcd05f51689d2$export$9e80c3751b841788 {
|
|
1809
|
+
#storage;
|
|
1810
|
+
#clientId;
|
|
1811
|
+
#sdkVersion;
|
|
1812
|
+
#fetch;
|
|
1813
|
+
/**
|
|
1814
|
+
* Constructor for PrivyInternal class
|
|
1815
|
+
* @param {PrivyInternalOptions} o - options for PrivyInternal
|
|
1816
|
+
* @property {Storage} o.storage - The storage instance to be used
|
|
1817
|
+
* @property {string} o.appId - The application ID
|
|
1818
|
+
* @property {string} o.baseUrl - The base URL for the application
|
|
1819
|
+
*/ constructor(o){
|
|
1820
|
+
this.#sdkVersion = `js-sdk-core:${0, $d019bc61f66dc929$exports.version}`;
|
|
1821
|
+
this.baseUrl = o.baseUrl ?? $d20bcd05f51689d2$var$DEFAULT_PRIVY_API_URL;
|
|
1822
|
+
this.appId = o.appId;
|
|
1823
|
+
this.#storage = o.storage;
|
|
1824
|
+
this.#clientId = (0, $fdlOJ$v4)();
|
|
1825
|
+
this.#sdkVersion = o.sdkVersion ?? this.#sdkVersion;
|
|
1826
|
+
this.session = new (0, $f7be880219889a89$export$1fb4852a55678982)({
|
|
1827
|
+
storage: this.#storage,
|
|
1828
|
+
isUsingServerCookies: false
|
|
1829
|
+
});
|
|
1830
|
+
this.#fetch = (0, $fdlOJ$fetchretry)(fetch, {
|
|
1831
|
+
retries: 3,
|
|
1832
|
+
retryDelay: 500
|
|
1833
|
+
});
|
|
1834
|
+
}
|
|
1835
|
+
/**
|
|
1836
|
+
* Getter for ready state
|
|
1837
|
+
*
|
|
1838
|
+
* Returns true if the configuration is defined, false otherwise
|
|
1839
|
+
*/ get #ready() {
|
|
1840
|
+
return Boolean(this.config);
|
|
1841
|
+
}
|
|
1842
|
+
/**
|
|
1843
|
+
* Initialize the PrivyInternal instance
|
|
1844
|
+
* This method fetches the application configuration and sets up the base URL
|
|
1845
|
+
* It also triggers the creation of an analytics event for SDK initialization
|
|
1846
|
+
*/ async #initialize() {
|
|
1847
|
+
if (this.#ready) return;
|
|
1848
|
+
this.config = await this.getAppConfig();
|
|
1849
|
+
if (this.config?.custom_api_url) {
|
|
1850
|
+
this.baseUrl = this.config.custom_api_url;
|
|
1851
|
+
this.#fetch = (0, $fdlOJ$fetchretry)(fetch, {
|
|
1852
|
+
retries: 3,
|
|
1853
|
+
retryDelay: 500
|
|
1854
|
+
});
|
|
1855
|
+
this.session.isUsingServerCookies = true;
|
|
1856
|
+
}
|
|
1857
|
+
this.createAnalyticsEvent("sdk_initialize", {});
|
|
1858
|
+
}
|
|
1859
|
+
/**
|
|
1860
|
+
* Strongly typed fetch, takes a `Route` and determines body and path parameter types
|
|
1861
|
+
*/ async fetch(r, { body: body, params: params, options: options = {
|
|
1862
|
+
onRequest: this.#beforeRequest.bind(this)
|
|
1863
|
+
} }) {
|
|
1864
|
+
const request = new Request(`${this.baseUrl}${r.constructPath({
|
|
1865
|
+
params: params
|
|
1866
|
+
})}`, {
|
|
1867
|
+
method: r.method,
|
|
1868
|
+
body: JSON.stringify(body)
|
|
1869
|
+
});
|
|
1870
|
+
const requestInit = await options.onRequest(request);
|
|
1871
|
+
const res = await this.#fetch(request, requestInit);
|
|
1872
|
+
if (res.status !== r.expectedStatusCode) {
|
|
1873
|
+
console.warn(`Privy: Expected status code ${r.expectedStatusCode}, received ${res.status}`);
|
|
1874
|
+
throw await res.json();
|
|
1875
|
+
}
|
|
1876
|
+
const parsedResponse = await res.json();
|
|
1877
|
+
return parsedResponse;
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1880
|
+
* Before request without refresh. This must be set manually as needed.
|
|
1881
|
+
* This method sets the headers for the fetch request
|
|
1882
|
+
* It also sets a timeout for the request
|
|
1883
|
+
* @param {Request} request - The request object
|
|
1884
|
+
*/ beforeRequestWithoutRefresh(request) {
|
|
1885
|
+
const token = this.session.token;
|
|
1886
|
+
const headers = new Headers(request.headers);
|
|
1887
|
+
headers.set("privy-app-id", this.appId);
|
|
1888
|
+
headers.set("privy-client", this.#sdkVersion);
|
|
1889
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
1890
|
+
headers.set("Content-Type", "application/json");
|
|
1891
|
+
headers.set("Accept", "application/json");
|
|
1892
|
+
return {
|
|
1893
|
+
signal: (0, $23b60b0520ebfec6$export$2e2bcd8739ae039)(3000),
|
|
1894
|
+
headers: headers,
|
|
1895
|
+
credentials: "include"
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
/**
|
|
1899
|
+
* Before request. This is the default before request method. You should not need to call this method directly.
|
|
1900
|
+
* This method initializes the PrivyInternal instance and refreshes the session if needed
|
|
1901
|
+
* It then calls the beforeRequestWithoutRefresh method to set the headers
|
|
1902
|
+
* @param {Request} request - The request object
|
|
1903
|
+
*/ async #beforeRequest(request) {
|
|
1904
|
+
await this.#initialize();
|
|
1905
|
+
// Ensure we refresh our session token if we need to
|
|
1906
|
+
await this.getAccessToken();
|
|
1907
|
+
return this.beforeRequestWithoutRefresh(request);
|
|
1908
|
+
}
|
|
1909
|
+
/**
|
|
1910
|
+
* Get app config
|
|
1911
|
+
* This method fetches the application configuration from the server
|
|
1912
|
+
*
|
|
1913
|
+
* Returns a promise that resolves to the application configuration
|
|
1914
|
+
*/ async getAppConfig() {
|
|
1915
|
+
return this.fetch((0, $fdlOJ$getAppConfig), {
|
|
1916
|
+
params: {
|
|
1917
|
+
app_id: this.appId
|
|
1918
|
+
},
|
|
1919
|
+
options: {
|
|
1920
|
+
onRequest: this.beforeRequestWithoutRefresh.bind(this)
|
|
1921
|
+
}
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Create analytics event
|
|
1926
|
+
* This method creates an analytics event with the given name and properties
|
|
1927
|
+
* @param {string} name - The name of the event
|
|
1928
|
+
* @param {object} properties - The properties of the event
|
|
1929
|
+
*
|
|
1930
|
+
* Returns a promise that resolves to the response of the analytics event creation
|
|
1931
|
+
*/ async createAnalyticsEvent(name, properties) {
|
|
1932
|
+
return this.fetch((0, $fdlOJ$recordAnalyticsEvent), {
|
|
1933
|
+
body: {
|
|
1934
|
+
event_name: name,
|
|
1935
|
+
client_id: this.#clientId,
|
|
1936
|
+
payload: properties
|
|
1937
|
+
}
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
/**
|
|
1941
|
+
* Refresh the session
|
|
1942
|
+
* This method refreshes the session by sending a request to the server
|
|
1943
|
+
*
|
|
1944
|
+
* Returns a promise that resolves to the response of the session refresh
|
|
1945
|
+
*/ async refreshSession() {
|
|
1946
|
+
const res = await this.fetch((0, $fdlOJ$refreshSession), {
|
|
1947
|
+
body: {
|
|
1948
|
+
refresh_token: this.session.refreshToken ?? undefined
|
|
1949
|
+
},
|
|
1950
|
+
options: {
|
|
1951
|
+
onRequest: this.beforeRequestWithoutRefresh.bind(this)
|
|
1952
|
+
}
|
|
1953
|
+
});
|
|
1954
|
+
this.session.storeToken(res.token);
|
|
1955
|
+
this.session.storeRefreshToken(res.refresh_token);
|
|
1956
|
+
return res;
|
|
1957
|
+
}
|
|
1958
|
+
async getAccessToken() {
|
|
1959
|
+
const existingToken = this.session.token;
|
|
1960
|
+
// If we have a token and we don't have an active token and we have refresh credentials
|
|
1961
|
+
if (existingToken && !this.session.hasActiveToken && this.session.hasRefreshCredentials()) {
|
|
1962
|
+
const { token: token } = await this.refreshSession();
|
|
1963
|
+
return token;
|
|
1964
|
+
}
|
|
1965
|
+
return existingToken;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
|
|
1970
|
+
class $8bd75308be6bba56$export$2e2bcd8739ae039 {
|
|
1971
|
+
/**
|
|
1972
|
+
* @internal
|
|
1973
|
+
*/ #privyInternal;
|
|
1974
|
+
/**
|
|
1975
|
+
* @internal
|
|
1976
|
+
*/ constructor(privyInternal){
|
|
1977
|
+
this.#privyInternal = privyInternal;
|
|
1978
|
+
}
|
|
1979
|
+
/**
|
|
1980
|
+
* Get the logged in user.
|
|
1981
|
+
*/ async get() {
|
|
1982
|
+
return await this.#privyInternal.refreshSession();
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
|
|
1987
|
+
class $774a046612cfe588$export$2e2bcd8739ae039 {
|
|
1988
|
+
#privyInternal;
|
|
1989
|
+
/** Create a new `Privy` Client */ constructor(o){
|
|
1990
|
+
this.#privyInternal = new (0, $d20bcd05f51689d2$export$9e80c3751b841788)(o);
|
|
1991
|
+
this.user = new (0, $8bd75308be6bba56$export$2e2bcd8739ae039)(this.#privyInternal);
|
|
1992
|
+
this.auth = new (0, $955bfb5a5edecad4$export$2e2bcd8739ae039)(this.#privyInternal);
|
|
1993
|
+
this.embeddedWallet = new (0, $c838da93fb583f7c$export$2e2bcd8739ae039)(this.#privyInternal, o.embeddedWalletMessagePoster);
|
|
1994
|
+
}
|
|
1995
|
+
setMessagePoster(poster) {
|
|
1996
|
+
this.embeddedWallet.setMessagePoster(poster);
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
|
|
2001
|
+
class $5619ac446340380b$export$19fffca37ef3e106 {
|
|
2002
|
+
get(key) {
|
|
2003
|
+
const val = localStorage.getItem(key);
|
|
2004
|
+
return val === null ? undefined : JSON.parse(val);
|
|
2005
|
+
}
|
|
2006
|
+
put(key, val) {
|
|
2007
|
+
if (val !== undefined) localStorage.setItem(key, JSON.stringify(val));
|
|
2008
|
+
else this.del(key);
|
|
2009
|
+
}
|
|
2010
|
+
del(key) {
|
|
2011
|
+
localStorage.removeItem(key);
|
|
2012
|
+
}
|
|
2013
|
+
getKeys() {
|
|
2014
|
+
return Object.entries(localStorage).map(([key])=>key);
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
|
|
2019
|
+
class $4ec4af43adcd9806$export$467265324939f47f {
|
|
2020
|
+
get(key) {
|
|
2021
|
+
return this._cache[key];
|
|
2022
|
+
}
|
|
2023
|
+
put(key, val) {
|
|
2024
|
+
if (val !== undefined) this._cache[key] = val;
|
|
2025
|
+
else this.del(key);
|
|
2026
|
+
}
|
|
2027
|
+
del(key) {
|
|
2028
|
+
delete this._cache[key];
|
|
2029
|
+
}
|
|
2030
|
+
getKeys() {
|
|
2031
|
+
return Object.keys(this._cache);
|
|
2032
|
+
}
|
|
2033
|
+
constructor(){
|
|
2034
|
+
this._cache = {};
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
|
|
2039
|
+
var $bd69d25d1a305f68$exports = {};
|
|
2040
|
+
|
|
2041
|
+
|
|
2042
|
+
globalThis.TextEncoder ??= (0, $fdlOJ$TextEncoder);
|
|
2043
|
+
var $a6e1b29c10faf0c5$export$2e2bcd8739ae039 = (0, $774a046612cfe588$export$2e2bcd8739ae039);
|
|
2044
|
+
|
|
2045
|
+
|
|
2046
|
+
export {$a6e1b29c10faf0c5$export$2e2bcd8739ae039 as default, $5619ac446340380b$export$19fffca37ef3e106 as LocalStorage, $4ec4af43adcd9806$export$467265324939f47f as InMemoryCache};
|
|
2047
|
+
//# sourceMappingURL=index.js.map
|