@walletconnect/ethereum-provider 2.5.1 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -4
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +1 -343
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +26 -26
- package/dist/index.umd.js.map +1 -1
- package/dist/types/EthereumProvider.d.ts +5 -4
- package/dist/types/EthereumProvider.d.ts.map +1 -1
- package/package.json +6 -6
- package/dist/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -16,19 +16,19 @@ import { EthereumProvider } from "@walletconnect/ethereum-provider";
|
|
|
16
16
|
const provider = await EthereumProvider.init({
|
|
17
17
|
projectId, // REQUIRED your projectId
|
|
18
18
|
chains, // REQUIRED chain ids
|
|
19
|
+
showQrModal, // REQUIRED set to "true" to use @web3modal/standalone,
|
|
19
20
|
methods, // OPTIONAL ethereum methods
|
|
20
21
|
events, // OPTIONAL ethereum events
|
|
21
22
|
rpcMap, // OPTIONAL rpc urls for each chain
|
|
22
23
|
metadata, // OPTIONAL metadata of your app
|
|
23
|
-
|
|
24
|
-
qrModalOptions, // OPTIONAL - `undefined` by default, see https://docs.walletconnect.com/2.0/web3modal/theming
|
|
24
|
+
qrModalOptions, // OPTIONAL - `undefined` by default, see https://docs.walletconnect.com/2.0/web3modal/options
|
|
25
25
|
});
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
## Display Web3Modal with QR code / Handle connection URI
|
|
29
29
|
|
|
30
30
|
```typescript
|
|
31
|
-
// Web3Modal is
|
|
31
|
+
// Web3Modal is disabled by default, enable it during init() to display a QR code modal
|
|
32
32
|
await provider.connect({
|
|
33
33
|
chains, // OPTIONAL chain ids
|
|
34
34
|
rpcMap, // OPTIONAL rpc urls
|
|
@@ -39,7 +39,7 @@ await provider.enable();
|
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
```typescript
|
|
42
|
-
// If you
|
|
42
|
+
// If you are not using Web3Modal,
|
|
43
43
|
// you can subscribe to the `display_uri` event and handle the URI yourself.
|
|
44
44
|
provider.on("display_uri", (uri: string) => {
|
|
45
45
|
// ... custom logic
|
|
@@ -76,3 +76,18 @@ provider.on("display_uri", handler);
|
|
|
76
76
|
// session disconnect
|
|
77
77
|
provider.on("disconnect", handler);
|
|
78
78
|
```
|
|
79
|
+
|
|
80
|
+
## Supported Web3Modal options (qrModalOptions)
|
|
81
|
+
|
|
82
|
+
- [themeMode](https://docs.walletconnect.com/2.0/web3modal/options#thememode-optional)
|
|
83
|
+
- [themeVariables](https://docs.walletconnect.com/2.0/web3modal/options#themevariables-optional)
|
|
84
|
+
- [chainImages](https://docs.walletconnect.com/2.0/web3modal/options#chainimages-optional)
|
|
85
|
+
- [tokenImages](https://docs.walletconnect.com/2.0/web3modal/options#tokenimages-optional)
|
|
86
|
+
- [walletImages](https://docs.walletconnect.com/2.0/web3modal/options#walletimages-optional)
|
|
87
|
+
- [desktopWallets](https://docs.walletconnect.com/2.0/web3modal/options#desktopwallets-optional)
|
|
88
|
+
- [mobileWallets](https://docs.walletconnect.com/2.0/web3modal/options#mobilewallets-optional)
|
|
89
|
+
- [enableExplorer](https://docs.walletconnect.com/2.0/web3modal/options#enableexplorer-optional)
|
|
90
|
+
- [explorerAllowList](https://docs.walletconnect.com/2.0/web3modal/options#explorerallowlist-optional)
|
|
91
|
+
- [explorerDenyList](https://docs.walletconnect.com/2.0/web3modal/options#explorerdenylist-optional)
|
|
92
|
+
- [privacyPolicyUrl](https://docs.walletconnect.com/2.0/web3modal/options#privacypolicyurl-optional)
|
|
93
|
+
- [termsOfServiceUrl](https://docs.walletconnect.com/2.0/web3modal/options#privacypolicyurl-optional)
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var P=require("events"),h=require("@walletconnect/utils"),T=require("@walletconnect/universal-provider");function R(i){if(i&&i.__esModule)return i;var t=Object.create(null);return i&&Object.keys(i).forEach(function(e){if(e!=="default"){var s=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:function(){return i[e]}})}}),t.default=i,Object.freeze(t)}const S="wc",j="ethereum_provider",N=`${S}@${2}:${j}:`,q="https://rpc.walletconnect.com/v1/",u=["eth_sendTransaction","personal_sign"],D=["eth_accounts","eth_requestAccounts","eth_call","eth_getBalance","eth_sendRawTransaction","eth_sign","eth_signTransaction","eth_signTypedData","eth_signTypedData_v3","eth_signTypedData_v4","wallet_switchEthereumChain","wallet_addEthereumChain","wallet_getPermissions","wallet_requestPermissions","wallet_registerOnboarding","wallet_watchAsset","wallet_scanQRCode"],m=["chainChanged","accountsChanged"],$=["message","disconnect","connect"];var U=Object.defineProperty,Q=Object.defineProperties,L=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,O=(i,t,e)=>t in i?U(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,I=(i,t)=>{for(var e in t||(t={}))V.call(t,e)&&O(i,e,t[e]);if(_)for(var e of _(t))H.call(t,e)&&O(i,e,t[e]);return i},y=(i,t)=>Q(i,L(t));function C(i){return Number(i[0].split(":")[1])}function E(i){return`0x${i.toString(16)}`}function z(i){const{chains:t,optionalChains:e,methods:s,optionalMethods:n,events:a,optionalEvents:l,rpcMap:c}=i;if(!h.isValidArray(t))throw new Error("Invalid chains");const o=t,r=s||u,f=a||m,b={[C(o)]:c[C(o)]},w={chains:o,methods:r,events:f,rpcMap:b},d=a?.filter(v=>!m.includes(v)),p=s?.filter(v=>!u.includes(v));if(!e&&!l&&!n&&!(d!=null&&d.length)&&!(p!=null&&p.length))return{required:w};const M=d?.length&&p?.length||!e,A={chains:[...new Set(M?o.concat(e||[]):e)],methods:[...new Set(r.concat(n||[]))],events:[...new Set(f.concat(l||[]))],rpcMap:c};return{required:w,optional:A}}class g{constructor(){this.events=new P.EventEmitter,this.namespace="eip155",this.accounts=[],this.chainId=1,this.STORAGE_KEY=N,this.on=(t,e)=>(this.events.on(t,e),this),this.once=(t,e)=>(this.events.once(t,e),this),this.removeListener=(t,e)=>(this.events.removeListener(t,e),this),this.off=(t,e)=>(this.events.off(t,e),this),this.parseAccount=t=>this.isCompatibleChainId(t)?this.parseAccountId(t).address:t,this.signer={},this.rpc={}}static async init(t){const e=new g;return await e.initialize(t),e}async request(t){return await this.signer.request(t,this.formatChainId(this.chainId))}sendAsync(t,e){this.signer.sendAsync(t,e,this.formatChainId(this.chainId))}get connected(){return this.signer.client?this.signer.client.core.relayer.connected:!1}get connecting(){return this.signer.client?this.signer.client.core.relayer.connecting:!1}async enable(){return this.session||await this.connect(),await this.request({method:"eth_requestAccounts"})}async connect(t){if(!this.signer.client)throw new Error("Provider not initialized. Call init() first");this.loadConnectOpts(t);const{required:e,optional:s}=z(this.rpc);try{const n=await new Promise(async(l,c)=>{var o;this.rpc.showQrModal&&((o=this.modal)==null||o.subscribeModal(r=>{!r.open&&!this.signer.session&&(this.signer.abortPairingAttempt(),c(new Error("Connection request reset. Please try again.")))})),await this.signer.connect(y(I({namespaces:{[this.namespace]:e}},s&&{optionalNamespaces:{[this.namespace]:s}}),{pairingTopic:t?.pairingTopic})).then(r=>{l(r)}).catch(r=>{c(new Error(r.message))})});if(!n)return;this.setChainIds(this.rpc.chains);const a=h.getAccountsFromNamespaces(n.namespaces,[this.namespace]);this.setAccounts(a),this.events.emit("connect",{chainId:E(this.chainId)})}catch(n){throw this.signer.logger.error(n),n}finally{this.modal&&this.modal.closeModal()}}async disconnect(){this.session&&await this.signer.disconnect(),this.reset()}get isWalletConnect(){return!0}get session(){return this.signer.session}registerEventListeners(){this.signer.on("session_event",t=>{const{params:e}=t,{event:s}=e;s.name==="accountsChanged"?(this.accounts=this.parseAccounts(s.data),this.events.emit("accountsChanged",this.accounts)):s.name==="chainChanged"?this.setChainId(this.formatChainId(s.data)):this.events.emit(s.name,s.data),this.events.emit("session_event",t)}),this.signer.on("chainChanged",t=>{const e=parseInt(t);this.chainId=e,this.events.emit("chainChanged",E(this.chainId)),this.persist()}),this.signer.on("session_update",t=>{this.events.emit("session_update",t)}),this.signer.on("session_delete",t=>{this.reset(),this.events.emit("session_delete",t),this.events.emit("disconnect",y(I({},h.getSdkError("USER_DISCONNECTED")),{data:t.topic,name:"USER_DISCONNECTED"}))}),this.signer.on("display_uri",t=>{var e,s;this.rpc.showQrModal&&((e=this.modal)==null||e.closeModal(),(s=this.modal)==null||s.openModal({uri:t})),this.events.emit("display_uri",t)})}setHttpProvider(t){this.request({method:"wallet_switchEthereumChain",params:[{chainId:t.toString(16)}]})}isCompatibleChainId(t){return typeof t=="string"?t.startsWith(`${this.namespace}:`):!1}formatChainId(t){return`${this.namespace}:${t}`}parseChainId(t){return Number(t.split(":")[1])}setChainIds(t){const e=t.filter(s=>this.isCompatibleChainId(s)).map(s=>this.parseChainId(s));e.length&&(this.chainId=e[0],this.events.emit("chainChanged",E(this.chainId)),this.persist())}setChainId(t){if(this.isCompatibleChainId(t)){const e=this.parseChainId(t);this.chainId=e,this.setHttpProvider(e)}}parseAccountId(t){const[e,s,n]=t.split(":");return{chainId:`${e}:${s}`,address:n}}setAccounts(t){this.accounts=t.filter(e=>this.parseChainId(this.parseAccountId(e).chainId)===this.chainId).map(e=>this.parseAccountId(e).address),this.events.emit("accountsChanged",this.accounts)}getRpcConfig(t){var e,s;return{chains:((e=t.chains)==null?void 0:e.map(n=>this.formatChainId(n)))||[`${this.namespace}:1`],optionalChains:t.optionalChains?t.optionalChains.map(n=>this.formatChainId(n)):void 0,methods:t?.methods||u,events:t?.events||m,optionalMethods:t?.optionalMethods||[],optionalEvents:t?.optionalEvents||[],rpcMap:t?.rpcMap||this.buildRpcMap(t.chains.concat(t.optionalChains||[]),t.projectId),showQrModal:Boolean(t?.showQrModal),qrModalOptions:(s=t?.qrModalOptions)!=null?s:void 0,projectId:t.projectId,metadata:t.metadata}}buildRpcMap(t,e){const s={};return t.forEach(n=>{s[n]=this.getRpcUrl(n,e)}),s}async initialize(t){if(this.rpc=this.getRpcConfig(t),this.chainId=C(this.rpc.chains),this.signer=await T.UniversalProvider.init({projectId:this.rpc.projectId,metadata:this.rpc.metadata}),this.registerEventListeners(),await this.loadPersistedSession(),this.rpc.showQrModal)try{const{Web3Modal:e}=await Promise.resolve().then(function(){return R(require("@web3modal/standalone"))});this.modal=new e(I({walletConnectVersion:2,projectId:this.rpc.projectId,standaloneChains:this.rpc.chains},this.rpc.qrModalOptions))}catch{throw new Error("To use QR modal, please install @web3modal/standalone package")}}loadConnectOpts(t){if(!t)return;const{chains:e,optionalChains:s,rpcMap:n}=t;e&&h.isValidArray(e)&&(this.rpc.chains=e.map(a=>this.formatChainId(a)),e.forEach(a=>{this.rpc.rpcMap[a]=n?.[a]||this.getRpcUrl(a)})),s&&h.isValidArray(s)&&(this.rpc.optionalChains=[],this.rpc.optionalChains=s?.map(a=>this.formatChainId(a)),s.forEach(a=>{this.rpc.rpcMap[a]=n?.[a]||this.getRpcUrl(a)}))}getRpcUrl(t,e){var s;return((s=this.rpc.rpcMap)==null?void 0:s[t])||`${q}?chainId=eip155:${t}&projectId=${e||this.rpc.projectId}`}async loadPersistedSession(){if(!this.session)return;const t=await this.signer.client.core.storage.getItem(`${this.STORAGE_KEY}/chainId`);this.setChainIds(t?[this.formatChainId(t)]:this.session.namespaces[this.namespace].accounts),this.setAccounts(this.session.namespaces[this.namespace].accounts)}reset(){this.chainId=1,this.accounts=[]}persist(){this.session&&this.signer.client.core.storage.setItem(`${this.STORAGE_KEY}/chainId`,this.chainId)}parseAccounts(t){return typeof t=="string"||t instanceof String?[this.parseAccount(t)]:t.map(e=>this.parseAccount(e))}}const G=g;exports.EthereumProvider=G,exports.OPTIONAL_EVENTS=$,exports.OPTIONAL_METHODS=D,exports.REQUIRED_EVENTS=m,exports.REQUIRED_METHODS=u,exports.default=g;
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/constants/values.ts","../src/constants/rpc.ts","../src/EthereumProvider.ts","../src/index.ts"],"sourcesContent":["export const PROTOCOL = \"wc\";\nexport const WC_VERSION = 2;\nexport const CONTEXT = \"ethereum_provider\";\nexport const STORAGE_KEY = `${PROTOCOL}@${WC_VERSION}:${CONTEXT}:`;\nexport const RPC_URL = \"https://rpc.walletconnect.com/v1/\";\n","export const REQUIRED_METHODS = [\"eth_sendTransaction\", \"personal_sign\"];\nexport const OPTIONAL_METHODS = [\n \"eth_accounts\",\n \"eth_requestAccounts\",\n \"eth_call\",\n \"eth_getBalance\",\n \"eth_sendRawTransaction\",\n \"eth_sign\",\n \"eth_signTransaction\",\n \"eth_signTypedData\",\n \"eth_signTypedData_v3\",\n \"eth_signTypedData_v4\",\n \"wallet_switchEthereumChain\",\n \"wallet_addEthereumChain\",\n \"wallet_getPermissions\",\n \"wallet_requestPermissions\",\n \"wallet_registerOnboarding\",\n \"wallet_watchAsset\",\n \"wallet_scanQRCode\",\n];\nexport const REQUIRED_EVENTS = [\"chainChanged\", \"accountsChanged\"];\nexport const OPTIONAL_EVENTS = [\"message\", \"disconnect\", \"connect\"];\n","import { EventEmitter } from \"events\";\nimport { getAccountsFromNamespaces, getSdkError, isValidArray } from \"@walletconnect/utils\";\nimport {\n IEthereumProvider as IProvider,\n IEthereumProviderEvents,\n ProviderAccounts,\n RequestArguments,\n} from \"./types\";\nimport { Metadata, Namespace, UniversalProvider } from \"@walletconnect/universal-provider\";\nimport type { Web3Modal } from \"@web3modal/standalone\";\nimport { SessionTypes, SignClientTypes } from \"@walletconnect/types\";\nimport { STORAGE_KEY, REQUIRED_METHODS, REQUIRED_EVENTS, RPC_URL } from \"./constants\";\n\nexport type RpcMethod =\n | \"personal_sign\"\n | \"eth_sendTransaction\"\n | \"eth_accounts\"\n | \"eth_requestAccounts\"\n | \"eth_call\"\n | \"eth_getBalance\"\n | \"eth_sendRawTransaction\"\n | \"eth_sign\"\n | \"eth_signTransaction\"\n | \"eth_signTypedData\"\n | \"eth_signTypedData_v3\"\n | \"eth_signTypedData_v4\"\n | \"wallet_switchEthereumChain\"\n | \"wallet_addEthereumChain\"\n | \"wallet_getPermissions\"\n | \"wallet_requestPermissions\"\n | \"wallet_registerOnboarding\"\n | \"wallet_watchAsset\"\n | \"wallet_scanQRCode\";\n\nexport type RpcEvent = \"accountsChanged\" | \"chainChanged\" | \"message\" | \"disconnect\" | \"connect\";\n\nexport interface EthereumRpcMap {\n [chainId: string]: string;\n}\n\nexport interface SessionEvent {\n event: { name: string; data: any };\n chainId: string;\n}\n\nexport interface EthereumRpcConfig {\n chains: string[];\n optionalChains?: string[];\n methods: string[];\n optionalMethods?: string[];\n /**\n * @description Events that the wallet MUST support or the connection will be rejected\n */\n events: string[];\n optionalEvents?: string[];\n rpcMap: EthereumRpcMap;\n projectId: string;\n metadata?: Metadata;\n showQrModal: boolean;\n qrModalOptions?: Parameters<Web3Modal[\"setTheme\"]>[0];\n}\nexport interface ConnectOps {\n chains?: number[];\n optionalChains?: number[];\n rpcMap?: EthereumRpcMap;\n pairingTopic?: string;\n}\n\nexport interface IEthereumProvider extends IProvider {\n connect(opts?: ConnectOps | undefined): Promise<void>;\n}\n\nexport function getRpcUrl(chainId: string, rpc: EthereumRpcConfig): string | undefined {\n let rpcUrl: string | undefined;\n if (rpc.rpcMap) {\n rpcUrl = rpc.rpcMap[getEthereumChainId([chainId])];\n }\n return rpcUrl;\n}\n\nexport function getEthereumChainId(chains: string[]): number {\n return Number(chains[0].split(\":\")[1]);\n}\n\nexport function toHexChainId(chainId: number): string {\n return `0x${chainId.toString(16)}`;\n}\n\nexport type NamespacesParams = {\n chains: EthereumRpcConfig[\"chains\"];\n optionalChains?: EthereumRpcConfig[\"optionalChains\"];\n methods?: EthereumRpcConfig[\"methods\"];\n optionalMethods?: EthereumRpcConfig[\"methods\"];\n events?: EthereumRpcConfig[\"events\"];\n rpcMap: EthereumRpcConfig[\"rpcMap\"];\n optionalEvents?: EthereumRpcConfig[\"events\"];\n};\n\nexport function buildNamespaces(params: NamespacesParams): {\n required: Namespace;\n optional?: Namespace;\n} {\n const { chains, optionalChains, methods, optionalMethods, events, optionalEvents, rpcMap } =\n params;\n if (!isValidArray(chains)) {\n throw new Error(\"Invalid chains\");\n }\n\n const requiredChains = chains;\n const requriedMethods = methods || REQUIRED_METHODS;\n const requiredEvents = events || REQUIRED_EVENTS;\n const requiredRpcMap = {\n [getEthereumChainId(requiredChains)]: rpcMap[getEthereumChainId(requiredChains)],\n };\n\n const required: Namespace = {\n chains: requiredChains,\n methods: requriedMethods,\n events: requiredEvents,\n rpcMap: requiredRpcMap,\n };\n\n // make a list of events and methods that require additional permissions\n // so we know if we should to include the required chains in the optional namespace\n const eventsRequiringPermissions = events?.filter((event) => !REQUIRED_EVENTS.includes(event));\n const methodsRequiringPermissions = methods?.filter((event) => !REQUIRED_METHODS.includes(event));\n\n if (\n !optionalChains &&\n !optionalEvents &&\n !optionalMethods &&\n !eventsRequiringPermissions?.length &&\n !methodsRequiringPermissions?.length\n ) {\n return { required };\n }\n\n /*\n * decides whether or not to include the required chains in the optional namespace\n * use case: if there is a single chain as required but additonal methods/events as optional\n */\n const shouldIncludeRequiredChains =\n (eventsRequiringPermissions?.length && methodsRequiringPermissions?.length) || !optionalChains;\n\n const optional: Namespace = {\n chains: [\n ...new Set(\n shouldIncludeRequiredChains ? requiredChains.concat(optionalChains || []) : optionalChains,\n ),\n ],\n methods: [...new Set(requriedMethods.concat(optionalMethods || []))],\n events: [...new Set(requiredEvents.concat(optionalEvents || []))],\n rpcMap,\n };\n\n return { required, optional };\n}\nexport interface EthereumProviderOptions {\n projectId: string;\n /**\n * @note Chains that your app intents to use and the peer MUST support. If the peer does not support these chains, the connection will be rejected.\n * @default [1]\n * @example [1, 3, 4, 5, 42]\n */\n chains: number[];\n /**\n * @note Optional chains that your app MAY attempt to use and the peer MAY support. If the peer does not support these chains, the connection will still be established.\n * @default [1]\n * @example [1, 3, 4, 5, 42]\n */\n optionalChains?: number[];\n /**\n * @note Methods that your app intents to use and the peer MUST support. If the peer does not support these methods, the connection will be rejected.\n * @default [\"eth_sendTransaction\", \"personal_sign\"]\n */\n methods?: string[];\n /**\n * @note Methods that your app MAY attempt to use and the peer MAY support. If the peer does not support these methods, the connection will still be established.\n */\n optionalMethods?: string[];\n events?: string[];\n optionalEvents?: string[];\n rpcMap?: EthereumRpcMap;\n metadata?: Metadata;\n showQrModal?: boolean;\n qrModalOptions?: Parameters<Web3Modal[\"setTheme\"]>[0];\n}\n\nexport class EthereumProvider implements IEthereumProvider {\n public events = new EventEmitter();\n public namespace = \"eip155\";\n public accounts: string[] = [];\n public signer: InstanceType<typeof UniversalProvider>;\n public chainId = 1;\n public modal?: Web3Modal;\n\n private rpc: EthereumRpcConfig;\n private readonly STORAGE_KEY = STORAGE_KEY;\n\n constructor() {\n // assigned during initialize\n this.signer = {} as InstanceType<typeof UniversalProvider>;\n this.rpc = {} as EthereumRpcConfig;\n }\n\n static async init(opts: EthereumProviderOptions): Promise<EthereumProvider> {\n const provider = new EthereumProvider();\n await provider.initialize(opts);\n return provider;\n }\n\n public async request<T = unknown>(args: RequestArguments): Promise<T> {\n return await this.signer.request(args, this.formatChainId(this.chainId));\n }\n\n public sendAsync(\n args: RequestArguments,\n callback: (error: Error | null, response: any) => void,\n ): void {\n this.signer.sendAsync(args, callback, this.formatChainId(this.chainId));\n }\n\n get connected(): boolean {\n if (!this.signer.client) return false;\n return this.signer.client.core.relayer.connected;\n }\n\n get connecting(): boolean {\n if (!this.signer.client) return false;\n return this.signer.client.core.relayer.connecting;\n }\n\n public async enable(): Promise<ProviderAccounts> {\n if (!this.session) await this.connect();\n const accounts = await this.request({ method: \"eth_requestAccounts\" });\n return accounts as ProviderAccounts;\n }\n\n public async connect(opts?: ConnectOps): Promise<void> {\n if (!this.signer.client) {\n throw new Error(\"Provider not initialized. Call init() first\");\n }\n\n this.loadConnectOpts(opts);\n const { required, optional } = buildNamespaces(this.rpc);\n try {\n const session = await new Promise<SessionTypes.Struct | undefined>(\n async (resolve, reject) => {\n if (this.rpc.showQrModal) {\n this.modal?.subscribeModal((state) => {\n // the modal was closed so reject the promise\n if (!state.open && !this.signer.session) {\n this.signer.abortPairingAttempt();\n reject(new Error(\"Connection request reset. Please try again.\"));\n }\n });\n }\n await this.signer\n .connect({\n namespaces: {\n [this.namespace]: required,\n },\n ...(optional && {\n optionalNamespaces: {\n [this.namespace]: optional,\n },\n }),\n pairingTopic: opts?.pairingTopic,\n })\n .then((session) => {\n resolve(session);\n })\n .catch((error: Error) => {\n reject(new Error(error.message));\n });\n },\n );\n\n if (!session) return;\n this.setChainIds(this.rpc.chains);\n const accounts = getAccountsFromNamespaces(session.namespaces, [this.namespace]);\n this.setAccounts(accounts);\n this.events.emit(\"connect\", { chainId: toHexChainId(this.chainId) });\n } catch (error) {\n this.signer.logger.error(error);\n throw error;\n } finally {\n if (this.modal) this.modal.closeModal();\n }\n }\n\n public async disconnect(): Promise<void> {\n if (this.session) {\n await this.signer.disconnect();\n }\n this.reset();\n }\n\n public on: IEthereumProviderEvents[\"on\"] = (event, listener) => {\n this.events.on(event, listener);\n return this;\n };\n\n public once: IEthereumProviderEvents[\"once\"] = (event, listener) => {\n this.events.once(event, listener);\n return this;\n };\n\n public removeListener: IEthereumProviderEvents[\"removeListener\"] = (event, listener) => {\n this.events.removeListener(event, listener);\n return this;\n };\n\n public off: IEthereumProviderEvents[\"off\"] = (event, listener) => {\n this.events.off(event, listener);\n return this;\n };\n\n get isWalletConnect() {\n return true;\n }\n\n get session() {\n return this.signer.session;\n }\n // ---------- Private ----------------------------------------------- //\n\n private registerEventListeners() {\n this.signer.on(\"session_event\", (payload: SignClientTypes.EventArguments[\"session_event\"]) => {\n const { params } = payload;\n const { event } = params;\n if (event.name === \"accountsChanged\") {\n this.accounts = this.parseAccounts(event.data);\n this.events.emit(\"accountsChanged\", this.accounts);\n } else if (event.name === \"chainChanged\") {\n this.setChainId(this.formatChainId(event.data));\n } else {\n this.events.emit(event.name as any, event.data);\n }\n this.events.emit(\"session_event\", payload);\n });\n\n this.signer.on(\"chainChanged\", (chainId: string) => {\n const chain = parseInt(chainId);\n this.chainId = chain;\n this.events.emit(\"chainChanged\", toHexChainId(this.chainId));\n this.persist();\n });\n\n this.signer.on(\n \"session_update\",\n (payload: SignClientTypes.EventArguments[\"session_update\"]) => {\n this.events.emit(\"session_update\", payload);\n },\n );\n\n this.signer.on(\n \"session_delete\",\n (payload: SignClientTypes.EventArguments[\"session_delete\"]) => {\n this.reset();\n this.events.emit(\"session_delete\", payload);\n this.events.emit(\"disconnect\", {\n ...getSdkError(\"USER_DISCONNECTED\"),\n data: payload.topic,\n name: \"USER_DISCONNECTED\",\n });\n },\n );\n\n this.signer.on(\"display_uri\", (uri: string) => {\n if (this.rpc.showQrModal) {\n // to refresh the QR we have to close the modal and open it again\n // until proper API is provided by web3modal\n this.modal?.closeModal();\n this.modal?.openModal({ uri });\n }\n this.events.emit(\"display_uri\", uri);\n });\n }\n\n private setHttpProvider(chainId: number): void {\n this.request({\n method: \"wallet_switchEthereumChain\",\n params: [{ chainId: chainId.toString(16) }],\n });\n }\n\n private isCompatibleChainId(chainId: string): boolean {\n return typeof chainId === \"string\" ? chainId.startsWith(`${this.namespace}:`) : false;\n }\n\n private formatChainId(chainId: number): string {\n return `${this.namespace}:${chainId}`;\n }\n\n private parseChainId(chainId: string): number {\n return Number(chainId.split(\":\")[1]);\n }\n\n private setChainIds(chains: string[]) {\n const compatible = chains.filter((x) => this.isCompatibleChainId(x));\n const chainIds = compatible.map((c) => this.parseChainId(c));\n if (chainIds.length) {\n this.chainId = chainIds[0];\n this.events.emit(\"chainChanged\", toHexChainId(this.chainId));\n this.persist();\n }\n }\n\n private setChainId(chain: string) {\n if (this.isCompatibleChainId(chain)) {\n const chainId = this.parseChainId(chain);\n this.chainId = chainId;\n this.setHttpProvider(chainId);\n }\n }\n\n private parseAccountId(account: string): { chainId: string; address: string } {\n const [namespace, reference, address] = account.split(\":\");\n const chainId = `${namespace}:${reference}`;\n return { chainId, address };\n }\n\n private setAccounts(accounts: string[]) {\n this.accounts = accounts\n .filter((x) => this.parseChainId(this.parseAccountId(x).chainId) === this.chainId)\n .map((x) => this.parseAccountId(x).address);\n this.events.emit(\"accountsChanged\", this.accounts);\n }\n\n private getRpcConfig(opts: EthereumProviderOptions): EthereumRpcConfig {\n return {\n chains: opts.chains?.map((chain) => this.formatChainId(chain)) || [`${this.namespace}:1`],\n optionalChains: opts.optionalChains\n ? opts.optionalChains.map((chain) => this.formatChainId(chain))\n : undefined,\n methods: opts?.methods || REQUIRED_METHODS,\n events: opts?.events || REQUIRED_EVENTS,\n optionalMethods: opts?.optionalMethods || [],\n optionalEvents: opts?.optionalEvents || [],\n rpcMap:\n opts?.rpcMap ||\n this.buildRpcMap(opts.chains.concat(opts.optionalChains || []), opts.projectId),\n showQrModal: opts?.showQrModal ?? true,\n projectId: opts.projectId,\n metadata: opts.metadata,\n };\n }\n\n private buildRpcMap(chains: number[], projectId: string): EthereumRpcMap {\n const map: EthereumRpcMap = {};\n chains.forEach((chain) => {\n map[chain] = this.getRpcUrl(chain, projectId);\n });\n return map;\n }\n\n private async initialize(opts: EthereumProviderOptions) {\n this.rpc = this.getRpcConfig(opts);\n this.chainId = getEthereumChainId(this.rpc.chains);\n this.signer = await UniversalProvider.init({\n projectId: this.rpc.projectId,\n metadata: this.rpc.metadata,\n });\n this.registerEventListeners();\n await this.loadPersistedSession();\n if (this.rpc.showQrModal) {\n try {\n const { Web3Modal } = await import(\"@web3modal/standalone\");\n this.modal = new Web3Modal({\n walletConnectVersion: 2,\n projectId: this.rpc.projectId,\n standaloneChains: this.rpc.chains,\n themeMode: this.rpc.qrModalOptions?.themeMode,\n themeVariables: this.rpc.qrModalOptions?.themeVariables,\n });\n } catch {\n throw new Error(\"To use QR modal, please install @web3modal/standalone package\");\n }\n }\n }\n\n private loadConnectOpts(opts?: ConnectOps) {\n if (!opts) return;\n const { chains, optionalChains, rpcMap } = opts;\n if (chains && isValidArray(chains)) {\n this.rpc.chains = chains.map((chain) => this.formatChainId(chain));\n chains.forEach((chain) => {\n this.rpc.rpcMap[chain] = rpcMap?.[chain] || this.getRpcUrl(chain);\n });\n }\n if (optionalChains && isValidArray(optionalChains)) {\n this.rpc.optionalChains = [];\n this.rpc.optionalChains = optionalChains?.map((chain) => this.formatChainId(chain));\n optionalChains.forEach((chain) => {\n this.rpc.rpcMap[chain] = rpcMap?.[chain] || this.getRpcUrl(chain);\n });\n }\n }\n\n private getRpcUrl(chainId: number, projectId?: string): string {\n const providedRpc = this.rpc.rpcMap?.[chainId];\n return (\n providedRpc ||\n `${RPC_URL}?chainId=eip155:${chainId}&projectId=${projectId || this.rpc.projectId}`\n );\n }\n\n private async loadPersistedSession() {\n if (!this.session) return;\n const chainId = await this.signer.client.core.storage.getItem(`${this.STORAGE_KEY}/chainId`);\n this.setChainIds(\n chainId ? [this.formatChainId(chainId)] : this.session.namespaces[this.namespace].accounts,\n );\n this.setAccounts(this.session.namespaces[this.namespace].accounts);\n }\n\n private reset() {\n this.chainId = 1;\n this.accounts = [];\n }\n\n private persist() {\n if (!this.session) return;\n this.signer.client.core.storage.setItem(`${this.STORAGE_KEY}/chainId`, this.chainId);\n }\n\n private parseAccounts(payload: string | string[]): string[] {\n if (typeof payload === \"string\" || payload instanceof String) {\n return [this.parseAccount(payload)];\n }\n return payload.map((account: string) => this.parseAccount(account));\n }\n\n private parseAccount = (payload: any): string => {\n return this.isCompatibleChainId(payload) ? this.parseAccountId(payload).address : payload;\n };\n}\n\nexport default EthereumProvider;\n","import { EthereumProvider as Provider } from \"./EthereumProvider\";\nexport const EthereumProvider = Provider;\nexport type { RpcEvent, RpcMethod } from \"./EthereumProvider\";\nexport * from \"./constants/rpc\";\nexport default Provider;\n"],"names":["chains","chainId","params","optionalChains","methods","optionalMethods","events","optionalEvents","rpcMap","isValidArray","requiredChains","requriedMethods","REQUIRED_METHODS","requiredEvents","REQUIRED_EVENTS","requiredRpcMap","required","eventsRequiringPermissions","event","methodsRequiringPermissions","shouldIncludeRequiredChains","optional","EthereumProvider","EventEmitter","STORAGE_KEY","listener","payload","opts","provider","args","callback","session","resolve","reject","_a","state","__spreadProps","__spreadValues","error","accounts","getAccountsFromNamespaces","chain","getSdkError","uri","_b","chainIds","x","c","account","namespace","reference","address","projectId","map","UniversalProvider","Web3Modal","e","RPC_URL","Provider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAa,MAAA,QAAA,CAAW,IACX,CACA,OAAA,CAAU,mBACV,CAAA,WAAA,CAAc,CAAG,EAAA,QAAA,CAAA,CAAA,EAAY,CAAc,CAAA,CAAA,EAAA,OAAA,CAAA,CAAA,CAAA,CAC3C,OAAU,CAAA;;ACJhB,MAAM,gBAAmB,CAAA,CAAC,qBAAuB,CAAA,eAAe,EAC1D,gBAAmB,CAAA,CAC9B,cACA,CAAA,qBAAA,CACA,WACA,gBACA,CAAA,wBAAA,CACA,UACA,CAAA,qBAAA,CACA,oBACA,sBACA,CAAA,sBAAA,CACA,4BACA,CAAA,yBAAA,CACA,uBACA,CAAA,2BAAA,CACA,2BACA,CAAA,mBAAA,CACA,mBACF,CACa,CAAA,eAAA,CAAkB,CAAC,cAAA,CAAgB,iBAAiB,CACpD,CAAA,eAAA,CAAkB,CAAC,SAAA,CAAW,aAAc,SAAS;;ACrBlE,IAAA,CAAA,CAAA,MAAA,CAAA,cAAA,CAAA,CAAA,CAAA,MAAA,CAAA,gBAAA,CAAA,IAAA,CAAA,CAAA,MAAA,CAAA,yBAAA,CAAA,IAAA,CAAA,CAAA,MAAA,CAAA,qBAAA,CAAA,IAAA,CAAA,CAAA,MAAA,CAAA,SAAA,CAAA,cAAA,CAAA,CAA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"sourcesContent":["export const PROTOCOL = \"wc\";\nexport const WC_VERSION = 2;\nexport const CONTEXT = \"ethereum_provider\";\nexport const STORAGE_KEY = `${PROTOCOL}@${WC_VERSION}:${CONTEXT}:`;\nexport const RPC_URL = \"https://rpc.walletconnect.com/v1/\";\n","export const REQUIRED_METHODS = [\"eth_sendTransaction\", \"personal_sign\"];\nexport const OPTIONAL_METHODS = [\n \"eth_accounts\",\n \"eth_requestAccounts\",\n \"eth_call\",\n \"eth_getBalance\",\n \"eth_sendRawTransaction\",\n \"eth_sign\",\n \"eth_signTransaction\",\n \"eth_signTypedData\",\n \"eth_signTypedData_v3\",\n \"eth_signTypedData_v4\",\n \"wallet_switchEthereumChain\",\n \"wallet_addEthereumChain\",\n \"wallet_getPermissions\",\n \"wallet_requestPermissions\",\n \"wallet_registerOnboarding\",\n \"wallet_watchAsset\",\n \"wallet_scanQRCode\",\n];\nexport const REQUIRED_EVENTS = [\"chainChanged\", \"accountsChanged\"];\nexport const OPTIONAL_EVENTS = [\"message\", \"disconnect\", \"connect\"];\n","import { EventEmitter } from \"events\";\nimport { getAccountsFromNamespaces, getSdkError, isValidArray } from \"@walletconnect/utils\";\nimport {\n IEthereumProvider as IProvider,\n IEthereumProviderEvents,\n ProviderAccounts,\n RequestArguments,\n} from \"./types\";\nimport { Metadata, Namespace, UniversalProvider } from \"@walletconnect/universal-provider\";\nimport type { Web3ModalConfig, Web3Modal } from \"@web3modal/standalone\";\nimport { SessionTypes, SignClientTypes } from \"@walletconnect/types\";\nimport { STORAGE_KEY, REQUIRED_METHODS, REQUIRED_EVENTS, RPC_URL } from \"./constants\";\n\nexport type QrModalOptions = Pick<\n Web3ModalConfig,\n | \"themeMode\"\n | \"themeVariables\"\n | \"chainImages\"\n | \"desktopWallets\"\n | \"enableExplorer\"\n | \"explorerAllowList\"\n | \"explorerDenyList\"\n | \"mobileWallets\"\n | \"privacyPolicyUrl\"\n | \"termsOfServiceUrl\"\n | \"tokenImages\"\n | \"walletImages\"\n>;\n\nexport type RpcMethod =\n | \"personal_sign\"\n | \"eth_sendTransaction\"\n | \"eth_accounts\"\n | \"eth_requestAccounts\"\n | \"eth_call\"\n | \"eth_getBalance\"\n | \"eth_sendRawTransaction\"\n | \"eth_sign\"\n | \"eth_signTransaction\"\n | \"eth_signTypedData\"\n | \"eth_signTypedData_v3\"\n | \"eth_signTypedData_v4\"\n | \"wallet_switchEthereumChain\"\n | \"wallet_addEthereumChain\"\n | \"wallet_getPermissions\"\n | \"wallet_requestPermissions\"\n | \"wallet_registerOnboarding\"\n | \"wallet_watchAsset\"\n | \"wallet_scanQRCode\";\n\nexport type RpcEvent = \"accountsChanged\" | \"chainChanged\" | \"message\" | \"disconnect\" | \"connect\";\n\nexport interface EthereumRpcMap {\n [chainId: string]: string;\n}\n\nexport interface SessionEvent {\n event: { name: string; data: any };\n chainId: string;\n}\n\nexport interface EthereumRpcConfig {\n chains: string[];\n optionalChains?: string[];\n methods: string[];\n optionalMethods?: string[];\n /**\n * @description Events that the wallet MUST support or the connection will be rejected\n */\n events: string[];\n optionalEvents?: string[];\n rpcMap: EthereumRpcMap;\n projectId: string;\n metadata?: Metadata;\n showQrModal: boolean;\n qrModalOptions?: QrModalOptions;\n}\nexport interface ConnectOps {\n chains?: number[];\n optionalChains?: number[];\n rpcMap?: EthereumRpcMap;\n pairingTopic?: string;\n}\n\nexport interface IEthereumProvider extends IProvider {\n connect(opts?: ConnectOps | undefined): Promise<void>;\n}\n\nexport function getRpcUrl(chainId: string, rpc: EthereumRpcConfig): string | undefined {\n let rpcUrl: string | undefined;\n if (rpc.rpcMap) {\n rpcUrl = rpc.rpcMap[getEthereumChainId([chainId])];\n }\n return rpcUrl;\n}\n\nexport function getEthereumChainId(chains: string[]): number {\n return Number(chains[0].split(\":\")[1]);\n}\n\nexport function toHexChainId(chainId: number): string {\n return `0x${chainId.toString(16)}`;\n}\n\nexport type NamespacesParams = {\n chains: EthereumRpcConfig[\"chains\"];\n optionalChains?: EthereumRpcConfig[\"optionalChains\"];\n methods?: EthereumRpcConfig[\"methods\"];\n optionalMethods?: EthereumRpcConfig[\"methods\"];\n events?: EthereumRpcConfig[\"events\"];\n rpcMap: EthereumRpcConfig[\"rpcMap\"];\n optionalEvents?: EthereumRpcConfig[\"events\"];\n};\n\nexport function buildNamespaces(params: NamespacesParams): {\n required: Namespace;\n optional?: Namespace;\n} {\n const { chains, optionalChains, methods, optionalMethods, events, optionalEvents, rpcMap } =\n params;\n if (!isValidArray(chains)) {\n throw new Error(\"Invalid chains\");\n }\n\n const requiredChains = chains;\n const requriedMethods = methods || REQUIRED_METHODS;\n const requiredEvents = events || REQUIRED_EVENTS;\n const requiredRpcMap = {\n [getEthereumChainId(requiredChains)]: rpcMap[getEthereumChainId(requiredChains)],\n };\n\n const required: Namespace = {\n chains: requiredChains,\n methods: requriedMethods,\n events: requiredEvents,\n rpcMap: requiredRpcMap,\n };\n\n // make a list of events and methods that require additional permissions\n // so we know if we should to include the required chains in the optional namespace\n const eventsRequiringPermissions = events?.filter((event) => !REQUIRED_EVENTS.includes(event));\n const methodsRequiringPermissions = methods?.filter((event) => !REQUIRED_METHODS.includes(event));\n\n if (\n !optionalChains &&\n !optionalEvents &&\n !optionalMethods &&\n !eventsRequiringPermissions?.length &&\n !methodsRequiringPermissions?.length\n ) {\n return { required };\n }\n\n /*\n * decides whether or not to include the required chains in the optional namespace\n * use case: if there is a single chain as required but additonal methods/events as optional\n */\n const shouldIncludeRequiredChains =\n (eventsRequiringPermissions?.length && methodsRequiringPermissions?.length) || !optionalChains;\n\n const optional: Namespace = {\n chains: [\n ...new Set(\n shouldIncludeRequiredChains ? requiredChains.concat(optionalChains || []) : optionalChains,\n ),\n ],\n methods: [...new Set(requriedMethods.concat(optionalMethods || []))],\n events: [...new Set(requiredEvents.concat(optionalEvents || []))],\n rpcMap,\n };\n\n return { required, optional };\n}\nexport interface EthereumProviderOptions {\n projectId: string;\n /**\n * @note Chains that your app intents to use and the peer MUST support. If the peer does not support these chains, the connection will be rejected.\n * @default [1]\n * @example [1, 3, 4, 5, 42]\n */\n chains: number[];\n /**\n * @note Optional chains that your app MAY attempt to use and the peer MAY support. If the peer does not support these chains, the connection will still be established.\n * @default [1]\n * @example [1, 3, 4, 5, 42]\n */\n optionalChains?: number[];\n /**\n * @note Methods that your app intents to use and the peer MUST support. If the peer does not support these methods, the connection will be rejected.\n * @default [\"eth_sendTransaction\", \"personal_sign\"]\n */\n methods?: string[];\n /**\n * @note Methods that your app MAY attempt to use and the peer MAY support. If the peer does not support these methods, the connection will still be established.\n */\n optionalMethods?: string[];\n events?: string[];\n optionalEvents?: string[];\n rpcMap?: EthereumRpcMap;\n metadata?: Metadata;\n showQrModal: boolean;\n qrModalOptions?: QrModalOptions;\n}\n\nexport class EthereumProvider implements IEthereumProvider {\n public events = new EventEmitter();\n public namespace = \"eip155\";\n public accounts: string[] = [];\n public signer: InstanceType<typeof UniversalProvider>;\n public chainId = 1;\n public modal?: Web3Modal;\n\n private rpc: EthereumRpcConfig;\n private readonly STORAGE_KEY = STORAGE_KEY;\n\n constructor() {\n // assigned during initialize\n this.signer = {} as InstanceType<typeof UniversalProvider>;\n this.rpc = {} as EthereumRpcConfig;\n }\n\n static async init(opts: EthereumProviderOptions): Promise<EthereumProvider> {\n const provider = new EthereumProvider();\n await provider.initialize(opts);\n return provider;\n }\n\n public async request<T = unknown>(args: RequestArguments): Promise<T> {\n return await this.signer.request(args, this.formatChainId(this.chainId));\n }\n\n public sendAsync(\n args: RequestArguments,\n callback: (error: Error | null, response: any) => void,\n ): void {\n this.signer.sendAsync(args, callback, this.formatChainId(this.chainId));\n }\n\n get connected(): boolean {\n if (!this.signer.client) return false;\n return this.signer.client.core.relayer.connected;\n }\n\n get connecting(): boolean {\n if (!this.signer.client) return false;\n return this.signer.client.core.relayer.connecting;\n }\n\n public async enable(): Promise<ProviderAccounts> {\n if (!this.session) await this.connect();\n const accounts = await this.request({ method: \"eth_requestAccounts\" });\n return accounts as ProviderAccounts;\n }\n\n public async connect(opts?: ConnectOps): Promise<void> {\n if (!this.signer.client) {\n throw new Error(\"Provider not initialized. Call init() first\");\n }\n\n this.loadConnectOpts(opts);\n const { required, optional } = buildNamespaces(this.rpc);\n try {\n const session = await new Promise<SessionTypes.Struct | undefined>(\n async (resolve, reject) => {\n if (this.rpc.showQrModal) {\n this.modal?.subscribeModal((state) => {\n // the modal was closed so reject the promise\n if (!state.open && !this.signer.session) {\n this.signer.abortPairingAttempt();\n reject(new Error(\"Connection request reset. Please try again.\"));\n }\n });\n }\n await this.signer\n .connect({\n namespaces: {\n [this.namespace]: required,\n },\n ...(optional && {\n optionalNamespaces: {\n [this.namespace]: optional,\n },\n }),\n pairingTopic: opts?.pairingTopic,\n })\n .then((session) => {\n resolve(session);\n })\n .catch((error: Error) => {\n reject(new Error(error.message));\n });\n },\n );\n\n if (!session) return;\n this.setChainIds(this.rpc.chains);\n const accounts = getAccountsFromNamespaces(session.namespaces, [this.namespace]);\n this.setAccounts(accounts);\n this.events.emit(\"connect\", { chainId: toHexChainId(this.chainId) });\n } catch (error) {\n this.signer.logger.error(error);\n throw error;\n } finally {\n if (this.modal) this.modal.closeModal();\n }\n }\n\n public async disconnect(): Promise<void> {\n if (this.session) {\n await this.signer.disconnect();\n }\n this.reset();\n }\n\n public on: IEthereumProviderEvents[\"on\"] = (event, listener) => {\n this.events.on(event, listener);\n return this;\n };\n\n public once: IEthereumProviderEvents[\"once\"] = (event, listener) => {\n this.events.once(event, listener);\n return this;\n };\n\n public removeListener: IEthereumProviderEvents[\"removeListener\"] = (event, listener) => {\n this.events.removeListener(event, listener);\n return this;\n };\n\n public off: IEthereumProviderEvents[\"off\"] = (event, listener) => {\n this.events.off(event, listener);\n return this;\n };\n\n get isWalletConnect() {\n return true;\n }\n\n get session() {\n return this.signer.session;\n }\n // ---------- Private ----------------------------------------------- //\n\n private registerEventListeners() {\n this.signer.on(\"session_event\", (payload: SignClientTypes.EventArguments[\"session_event\"]) => {\n const { params } = payload;\n const { event } = params;\n if (event.name === \"accountsChanged\") {\n this.accounts = this.parseAccounts(event.data);\n this.events.emit(\"accountsChanged\", this.accounts);\n } else if (event.name === \"chainChanged\") {\n this.setChainId(this.formatChainId(event.data));\n } else {\n this.events.emit(event.name as any, event.data);\n }\n this.events.emit(\"session_event\", payload);\n });\n\n this.signer.on(\"chainChanged\", (chainId: string) => {\n const chain = parseInt(chainId);\n this.chainId = chain;\n this.events.emit(\"chainChanged\", toHexChainId(this.chainId));\n this.persist();\n });\n\n this.signer.on(\n \"session_update\",\n (payload: SignClientTypes.EventArguments[\"session_update\"]) => {\n this.events.emit(\"session_update\", payload);\n },\n );\n\n this.signer.on(\n \"session_delete\",\n (payload: SignClientTypes.EventArguments[\"session_delete\"]) => {\n this.reset();\n this.events.emit(\"session_delete\", payload);\n this.events.emit(\"disconnect\", {\n ...getSdkError(\"USER_DISCONNECTED\"),\n data: payload.topic,\n name: \"USER_DISCONNECTED\",\n });\n },\n );\n\n this.signer.on(\"display_uri\", (uri: string) => {\n if (this.rpc.showQrModal) {\n // to refresh the QR we have to close the modal and open it again\n // until proper API is provided by web3modal\n this.modal?.closeModal();\n this.modal?.openModal({ uri });\n }\n this.events.emit(\"display_uri\", uri);\n });\n }\n\n private setHttpProvider(chainId: number): void {\n this.request({\n method: \"wallet_switchEthereumChain\",\n params: [{ chainId: chainId.toString(16) }],\n });\n }\n\n private isCompatibleChainId(chainId: string): boolean {\n return typeof chainId === \"string\" ? chainId.startsWith(`${this.namespace}:`) : false;\n }\n\n private formatChainId(chainId: number): string {\n return `${this.namespace}:${chainId}`;\n }\n\n private parseChainId(chainId: string): number {\n return Number(chainId.split(\":\")[1]);\n }\n\n private setChainIds(chains: string[]) {\n const compatible = chains.filter((x) => this.isCompatibleChainId(x));\n const chainIds = compatible.map((c) => this.parseChainId(c));\n if (chainIds.length) {\n this.chainId = chainIds[0];\n this.events.emit(\"chainChanged\", toHexChainId(this.chainId));\n this.persist();\n }\n }\n\n private setChainId(chain: string) {\n if (this.isCompatibleChainId(chain)) {\n const chainId = this.parseChainId(chain);\n this.chainId = chainId;\n this.setHttpProvider(chainId);\n }\n }\n\n private parseAccountId(account: string): { chainId: string; address: string } {\n const [namespace, reference, address] = account.split(\":\");\n const chainId = `${namespace}:${reference}`;\n return { chainId, address };\n }\n\n private setAccounts(accounts: string[]) {\n this.accounts = accounts\n .filter((x) => this.parseChainId(this.parseAccountId(x).chainId) === this.chainId)\n .map((x) => this.parseAccountId(x).address);\n this.events.emit(\"accountsChanged\", this.accounts);\n }\n\n private getRpcConfig(opts: EthereumProviderOptions): EthereumRpcConfig {\n return {\n chains: opts.chains?.map((chain) => this.formatChainId(chain)) || [`${this.namespace}:1`],\n optionalChains: opts.optionalChains\n ? opts.optionalChains.map((chain) => this.formatChainId(chain))\n : undefined,\n methods: opts?.methods || REQUIRED_METHODS,\n events: opts?.events || REQUIRED_EVENTS,\n optionalMethods: opts?.optionalMethods || [],\n optionalEvents: opts?.optionalEvents || [],\n rpcMap:\n opts?.rpcMap ||\n this.buildRpcMap(opts.chains.concat(opts.optionalChains || []), opts.projectId),\n showQrModal: Boolean(opts?.showQrModal),\n qrModalOptions: opts?.qrModalOptions ?? undefined,\n projectId: opts.projectId,\n metadata: opts.metadata,\n };\n }\n\n private buildRpcMap(chains: number[], projectId: string): EthereumRpcMap {\n const map: EthereumRpcMap = {};\n chains.forEach((chain) => {\n map[chain] = this.getRpcUrl(chain, projectId);\n });\n return map;\n }\n\n private async initialize(opts: EthereumProviderOptions) {\n this.rpc = this.getRpcConfig(opts);\n this.chainId = getEthereumChainId(this.rpc.chains);\n this.signer = await UniversalProvider.init({\n projectId: this.rpc.projectId,\n metadata: this.rpc.metadata,\n });\n this.registerEventListeners();\n await this.loadPersistedSession();\n if (this.rpc.showQrModal) {\n try {\n const { Web3Modal } = await import(\"@web3modal/standalone\");\n this.modal = new Web3Modal({\n walletConnectVersion: 2,\n projectId: this.rpc.projectId,\n standaloneChains: this.rpc.chains,\n ...this.rpc.qrModalOptions,\n });\n } catch {\n throw new Error(\"To use QR modal, please install @web3modal/standalone package\");\n }\n }\n }\n\n private loadConnectOpts(opts?: ConnectOps) {\n if (!opts) return;\n const { chains, optionalChains, rpcMap } = opts;\n if (chains && isValidArray(chains)) {\n this.rpc.chains = chains.map((chain) => this.formatChainId(chain));\n chains.forEach((chain) => {\n this.rpc.rpcMap[chain] = rpcMap?.[chain] || this.getRpcUrl(chain);\n });\n }\n if (optionalChains && isValidArray(optionalChains)) {\n this.rpc.optionalChains = [];\n this.rpc.optionalChains = optionalChains?.map((chain) => this.formatChainId(chain));\n optionalChains.forEach((chain) => {\n this.rpc.rpcMap[chain] = rpcMap?.[chain] || this.getRpcUrl(chain);\n });\n }\n }\n\n private getRpcUrl(chainId: number, projectId?: string): string {\n const providedRpc = this.rpc.rpcMap?.[chainId];\n return (\n providedRpc ||\n `${RPC_URL}?chainId=eip155:${chainId}&projectId=${projectId || this.rpc.projectId}`\n );\n }\n\n private async loadPersistedSession() {\n if (!this.session) return;\n const chainId = await this.signer.client.core.storage.getItem(`${this.STORAGE_KEY}/chainId`);\n this.setChainIds(\n chainId ? [this.formatChainId(chainId)] : this.session.namespaces[this.namespace].accounts,\n );\n this.setAccounts(this.session.namespaces[this.namespace].accounts);\n }\n\n private reset() {\n this.chainId = 1;\n this.accounts = [];\n }\n\n private persist() {\n if (!this.session) return;\n this.signer.client.core.storage.setItem(`${this.STORAGE_KEY}/chainId`, this.chainId);\n }\n\n private parseAccounts(payload: string | string[]): string[] {\n if (typeof payload === \"string\" || payload instanceof String) {\n return [this.parseAccount(payload)];\n }\n return payload.map((account: string) => this.parseAccount(account));\n }\n\n private parseAccount = (payload: any): string => {\n return this.isCompatibleChainId(payload) ? this.parseAccountId(payload).address : payload;\n };\n}\n\nexport default EthereumProvider;\n","import { EthereumProvider as Provider } from \"./EthereumProvider\";\nexport const EthereumProvider = Provider;\nexport type { RpcEvent, RpcMethod } from \"./EthereumProvider\";\nexport * from \"./constants/rpc\";\nexport default Provider;\n"],"names":["chains","chainId","params","optionalChains","methods","optionalMethods","events","optionalEvents","rpcMap","isValidArray","requiredChains","requriedMethods","REQUIRED_METHODS","requiredEvents","REQUIRED_EVENTS","requiredRpcMap","required","eventsRequiringPermissions","event","methodsRequiringPermissions","shouldIncludeRequiredChains","optional","EthereumProvider","EventEmitter","STORAGE_KEY","listener","payload","opts","provider","args","callback","session","resolve","reject","_a","state","__spreadProps","__spreadValues","error","accounts","getAccountsFromNamespaces","chain","getSdkError","uri","_b","chainIds","x","c","account","namespace","reference","address","projectId","map","UniversalProvider","Web3Modal","e","RPC_URL","Provider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAa,MAAA,QAAA,CAAW,IACX,CACA,OAAA,CAAU,mBACV,CAAA,WAAA,CAAc,CAAG,EAAA,QAAA,CAAA,CAAA,EAAY,CAAc,CAAA,CAAA,EAAA,OAAA,CAAA,CAAA,CAAA,CAC3C,OAAU,CAAA;;ACJhB,MAAM,gBAAmB,CAAA,CAAC,qBAAuB,CAAA,eAAe,EAC1D,gBAAmB,CAAA,CAC9B,cACA,CAAA,qBAAA,CACA,WACA,gBACA,CAAA,wBAAA,CACA,UACA,CAAA,qBAAA,CACA,oBACA,sBACA,CAAA,sBAAA,CACA,4BACA,CAAA,yBAAA,CACA,uBACA,CAAA,2BAAA,CACA,2BACA,CAAA,mBAAA,CACA,mBACF,CACa,CAAA,eAAA,CAAkB,CAAC,cAAA,CAAgB,iBAAiB,CACpD,CAAA,eAAA,CAAkB,CAAC,SAAA,CAAW,aAAc,SAAS;;ACrBlE,IAAA,CAAA,CAAA,MAAA,CAAA,cAAA,CAAA,CAAA,CAAA,MAAA,CAAA,gBAAA,CAAA,IAAA,CAAA,CAAA,MAAA,CAAA,yBAAA,CAAA,IAAA,CAAA,CAAA,MAAA,CAAA,qBAAA,CAAA,IAAA,CAAA,CAAA,MAAA,CAAA,SAAA,CAAA,cAAA,CAAA,CAAA,CAAA,MAAA,CAAA,SAAA,CAAA,oBAAA,CAAA,IA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
|
6
|
-
} from "@walletconnect/utils";
|
|
7
|
-
import { UniversalProvider as S } from "@walletconnect/universal-provider";
|
|
8
|
-
const j = "wc",
|
|
9
|
-
$ = "ethereum_provider",
|
|
10
|
-
N = `${j}@${2}:${$}:`,
|
|
11
|
-
q = "https://rpc.walletconnect.com/v1/",
|
|
12
|
-
p = ["eth_sendTransaction", "personal_sign"],
|
|
13
|
-
D = [
|
|
14
|
-
"eth_accounts",
|
|
15
|
-
"eth_requestAccounts",
|
|
16
|
-
"eth_call",
|
|
17
|
-
"eth_getBalance",
|
|
18
|
-
"eth_sendRawTransaction",
|
|
19
|
-
"eth_sign",
|
|
20
|
-
"eth_signTransaction",
|
|
21
|
-
"eth_signTypedData",
|
|
22
|
-
"eth_signTypedData_v3",
|
|
23
|
-
"eth_signTypedData_v4",
|
|
24
|
-
"wallet_switchEthereumChain",
|
|
25
|
-
"wallet_addEthereumChain",
|
|
26
|
-
"wallet_getPermissions",
|
|
27
|
-
"wallet_requestPermissions",
|
|
28
|
-
"wallet_registerOnboarding",
|
|
29
|
-
"wallet_watchAsset",
|
|
30
|
-
"wallet_scanQRCode",
|
|
31
|
-
],
|
|
32
|
-
u = ["chainChanged", "accountsChanged"],
|
|
33
|
-
U = ["message", "disconnect", "connect"];
|
|
34
|
-
var Q = Object.defineProperty,
|
|
35
|
-
L = Object.defineProperties,
|
|
36
|
-
V = Object.getOwnPropertyDescriptors,
|
|
37
|
-
E = Object.getOwnPropertySymbols,
|
|
38
|
-
H = Object.prototype.hasOwnProperty,
|
|
39
|
-
G = Object.prototype.propertyIsEnumerable,
|
|
40
|
-
_ = (a, t, s) =>
|
|
41
|
-
t in a ? Q(a, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : (a[t] = s),
|
|
42
|
-
y = (a, t) => {
|
|
43
|
-
for (var s in t || (t = {})) H.call(t, s) && _(a, s, t[s]);
|
|
44
|
-
if (E) for (var s of E(t)) G.call(t, s) && _(a, s, t[s]);
|
|
45
|
-
return a;
|
|
46
|
-
},
|
|
47
|
-
M = (a, t) => L(a, V(t));
|
|
48
|
-
function I(a) {
|
|
49
|
-
return Number(a[0].split(":")[1]);
|
|
50
|
-
}
|
|
51
|
-
function C(a) {
|
|
52
|
-
return `0x${a.toString(16)}`;
|
|
53
|
-
}
|
|
54
|
-
function K(a) {
|
|
55
|
-
const {
|
|
56
|
-
chains: t,
|
|
57
|
-
optionalChains: s,
|
|
58
|
-
methods: i,
|
|
59
|
-
optionalMethods: e,
|
|
60
|
-
events: n,
|
|
61
|
-
optionalEvents: c,
|
|
62
|
-
rpcMap: h,
|
|
63
|
-
} = a;
|
|
64
|
-
if (!v(t)) throw new Error("Invalid chains");
|
|
65
|
-
const o = t,
|
|
66
|
-
r = i || p,
|
|
67
|
-
w = n || u,
|
|
68
|
-
b = { [I(o)]: h[I(o)] },
|
|
69
|
-
f = { chains: o, methods: r, events: w, rpcMap: b },
|
|
70
|
-
l = n?.filter((g) => !u.includes(g)),
|
|
71
|
-
d = i?.filter((g) => !p.includes(g));
|
|
72
|
-
if (!s && !c && !e && !(l != null && l.length) && !(d != null && d.length))
|
|
73
|
-
return { required: f };
|
|
74
|
-
const O = (l?.length && d?.length) || !s,
|
|
75
|
-
A = {
|
|
76
|
-
chains: [...new Set(O ? o.concat(s || []) : s)],
|
|
77
|
-
methods: [...new Set(r.concat(e || []))],
|
|
78
|
-
events: [...new Set(w.concat(c || []))],
|
|
79
|
-
rpcMap: h,
|
|
80
|
-
};
|
|
81
|
-
return { required: f, optional: A };
|
|
82
|
-
}
|
|
83
|
-
class m {
|
|
84
|
-
constructor() {
|
|
85
|
-
(this.events = new R()),
|
|
86
|
-
(this.namespace = "eip155"),
|
|
87
|
-
(this.accounts = []),
|
|
88
|
-
(this.chainId = 1),
|
|
89
|
-
(this.STORAGE_KEY = N),
|
|
90
|
-
(this.on = (t, s) => (this.events.on(t, s), this)),
|
|
91
|
-
(this.once = (t, s) => (this.events.once(t, s), this)),
|
|
92
|
-
(this.removeListener = (t, s) => (this.events.removeListener(t, s), this)),
|
|
93
|
-
(this.off = (t, s) => (this.events.off(t, s), this)),
|
|
94
|
-
(this.parseAccount = (t) =>
|
|
95
|
-
this.isCompatibleChainId(t) ? this.parseAccountId(t).address : t),
|
|
96
|
-
(this.signer = {}),
|
|
97
|
-
(this.rpc = {});
|
|
98
|
-
}
|
|
99
|
-
static async init(t) {
|
|
100
|
-
const s = new m();
|
|
101
|
-
return await s.initialize(t), s;
|
|
102
|
-
}
|
|
103
|
-
async request(t) {
|
|
104
|
-
return await this.signer.request(t, this.formatChainId(this.chainId));
|
|
105
|
-
}
|
|
106
|
-
sendAsync(t, s) {
|
|
107
|
-
this.signer.sendAsync(t, s, this.formatChainId(this.chainId));
|
|
108
|
-
}
|
|
109
|
-
get connected() {
|
|
110
|
-
return this.signer.client ? this.signer.client.core.relayer.connected : !1;
|
|
111
|
-
}
|
|
112
|
-
get connecting() {
|
|
113
|
-
return this.signer.client ? this.signer.client.core.relayer.connecting : !1;
|
|
114
|
-
}
|
|
115
|
-
async enable() {
|
|
116
|
-
return (
|
|
117
|
-
this.session || (await this.connect()), await this.request({ method: "eth_requestAccounts" })
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
async connect(t) {
|
|
121
|
-
if (!this.signer.client) throw new Error("Provider not initialized. Call init() first");
|
|
122
|
-
this.loadConnectOpts(t);
|
|
123
|
-
const { required: s, optional: i } = K(this.rpc);
|
|
124
|
-
try {
|
|
125
|
-
const e = await new Promise(async (c, h) => {
|
|
126
|
-
var o;
|
|
127
|
-
this.rpc.showQrModal &&
|
|
128
|
-
((o = this.modal) == null ||
|
|
129
|
-
o.subscribeModal((r) => {
|
|
130
|
-
!r.open &&
|
|
131
|
-
!this.signer.session &&
|
|
132
|
-
(this.signer.abortPairingAttempt(),
|
|
133
|
-
h(new Error("Connection request reset. Please try again.")));
|
|
134
|
-
})),
|
|
135
|
-
await this.signer
|
|
136
|
-
.connect(
|
|
137
|
-
M(
|
|
138
|
-
y(
|
|
139
|
-
{ namespaces: { [this.namespace]: s } },
|
|
140
|
-
i && { optionalNamespaces: { [this.namespace]: i } },
|
|
141
|
-
),
|
|
142
|
-
{ pairingTopic: t?.pairingTopic },
|
|
143
|
-
),
|
|
144
|
-
)
|
|
145
|
-
.then((r) => {
|
|
146
|
-
c(r);
|
|
147
|
-
})
|
|
148
|
-
.catch((r) => {
|
|
149
|
-
h(new Error(r.message));
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
if (!e) return;
|
|
153
|
-
this.setChainIds(this.rpc.chains);
|
|
154
|
-
const n = T(e.namespaces, [this.namespace]);
|
|
155
|
-
this.setAccounts(n), this.events.emit("connect", { chainId: C(this.chainId) });
|
|
156
|
-
} catch (e) {
|
|
157
|
-
throw (this.signer.logger.error(e), e);
|
|
158
|
-
} finally {
|
|
159
|
-
this.modal && this.modal.closeModal();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async disconnect() {
|
|
163
|
-
this.session && (await this.signer.disconnect()), this.reset();
|
|
164
|
-
}
|
|
165
|
-
get isWalletConnect() {
|
|
166
|
-
return !0;
|
|
167
|
-
}
|
|
168
|
-
get session() {
|
|
169
|
-
return this.signer.session;
|
|
170
|
-
}
|
|
171
|
-
registerEventListeners() {
|
|
172
|
-
this.signer.on("session_event", (t) => {
|
|
173
|
-
const { params: s } = t,
|
|
174
|
-
{ event: i } = s;
|
|
175
|
-
i.name === "accountsChanged"
|
|
176
|
-
? ((this.accounts = this.parseAccounts(i.data)),
|
|
177
|
-
this.events.emit("accountsChanged", this.accounts))
|
|
178
|
-
: i.name === "chainChanged"
|
|
179
|
-
? this.setChainId(this.formatChainId(i.data))
|
|
180
|
-
: this.events.emit(i.name, i.data),
|
|
181
|
-
this.events.emit("session_event", t);
|
|
182
|
-
}),
|
|
183
|
-
this.signer.on("chainChanged", (t) => {
|
|
184
|
-
const s = parseInt(t);
|
|
185
|
-
(this.chainId = s), this.events.emit("chainChanged", C(this.chainId)), this.persist();
|
|
186
|
-
}),
|
|
187
|
-
this.signer.on("session_update", (t) => {
|
|
188
|
-
this.events.emit("session_update", t);
|
|
189
|
-
}),
|
|
190
|
-
this.signer.on("session_delete", (t) => {
|
|
191
|
-
this.reset(),
|
|
192
|
-
this.events.emit("session_delete", t),
|
|
193
|
-
this.events.emit(
|
|
194
|
-
"disconnect",
|
|
195
|
-
M(y({}, P("USER_DISCONNECTED")), { data: t.topic, name: "USER_DISCONNECTED" }),
|
|
196
|
-
);
|
|
197
|
-
}),
|
|
198
|
-
this.signer.on("display_uri", (t) => {
|
|
199
|
-
var s, i;
|
|
200
|
-
this.rpc.showQrModal &&
|
|
201
|
-
((s = this.modal) == null || s.closeModal(),
|
|
202
|
-
(i = this.modal) == null || i.openModal({ uri: t })),
|
|
203
|
-
this.events.emit("display_uri", t);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
setHttpProvider(t) {
|
|
207
|
-
this.request({ method: "wallet_switchEthereumChain", params: [{ chainId: t.toString(16) }] });
|
|
208
|
-
}
|
|
209
|
-
isCompatibleChainId(t) {
|
|
210
|
-
return typeof t == "string" ? t.startsWith(`${this.namespace}:`) : !1;
|
|
211
|
-
}
|
|
212
|
-
formatChainId(t) {
|
|
213
|
-
return `${this.namespace}:${t}`;
|
|
214
|
-
}
|
|
215
|
-
parseChainId(t) {
|
|
216
|
-
return Number(t.split(":")[1]);
|
|
217
|
-
}
|
|
218
|
-
setChainIds(t) {
|
|
219
|
-
const s = t.filter((i) => this.isCompatibleChainId(i)).map((i) => this.parseChainId(i));
|
|
220
|
-
s.length &&
|
|
221
|
-
((this.chainId = s[0]), this.events.emit("chainChanged", C(this.chainId)), this.persist());
|
|
222
|
-
}
|
|
223
|
-
setChainId(t) {
|
|
224
|
-
if (this.isCompatibleChainId(t)) {
|
|
225
|
-
const s = this.parseChainId(t);
|
|
226
|
-
(this.chainId = s), this.setHttpProvider(s);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
parseAccountId(t) {
|
|
230
|
-
const [s, i, e] = t.split(":");
|
|
231
|
-
return { chainId: `${s}:${i}`, address: e };
|
|
232
|
-
}
|
|
233
|
-
setAccounts(t) {
|
|
234
|
-
(this.accounts = t
|
|
235
|
-
.filter((s) => this.parseChainId(this.parseAccountId(s).chainId) === this.chainId)
|
|
236
|
-
.map((s) => this.parseAccountId(s).address)),
|
|
237
|
-
this.events.emit("accountsChanged", this.accounts);
|
|
238
|
-
}
|
|
239
|
-
getRpcConfig(t) {
|
|
240
|
-
var s, i;
|
|
241
|
-
return {
|
|
242
|
-
chains: ((s = t.chains) == null ? void 0 : s.map((e) => this.formatChainId(e))) || [
|
|
243
|
-
`${this.namespace}:1`,
|
|
244
|
-
],
|
|
245
|
-
optionalChains: t.optionalChains
|
|
246
|
-
? t.optionalChains.map((e) => this.formatChainId(e))
|
|
247
|
-
: void 0,
|
|
248
|
-
methods: t?.methods || p,
|
|
249
|
-
events: t?.events || u,
|
|
250
|
-
optionalMethods: t?.optionalMethods || [],
|
|
251
|
-
optionalEvents: t?.optionalEvents || [],
|
|
252
|
-
rpcMap: t?.rpcMap || this.buildRpcMap(t.chains.concat(t.optionalChains || []), t.projectId),
|
|
253
|
-
showQrModal: (i = t?.showQrModal) != null ? i : !0,
|
|
254
|
-
projectId: t.projectId,
|
|
255
|
-
metadata: t.metadata,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
buildRpcMap(t, s) {
|
|
259
|
-
const i = {};
|
|
260
|
-
return (
|
|
261
|
-
t.forEach((e) => {
|
|
262
|
-
i[e] = this.getRpcUrl(e, s);
|
|
263
|
-
}),
|
|
264
|
-
i
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
async initialize(t) {
|
|
268
|
-
var s, i;
|
|
269
|
-
if (
|
|
270
|
-
((this.rpc = this.getRpcConfig(t)),
|
|
271
|
-
(this.chainId = I(this.rpc.chains)),
|
|
272
|
-
(this.signer = await S.init({ projectId: this.rpc.projectId, metadata: this.rpc.metadata })),
|
|
273
|
-
this.registerEventListeners(),
|
|
274
|
-
await this.loadPersistedSession(),
|
|
275
|
-
this.rpc.showQrModal)
|
|
276
|
-
)
|
|
277
|
-
try {
|
|
278
|
-
const { Web3Modal: e } = await import("@web3modal/standalone");
|
|
279
|
-
this.modal = new e({
|
|
280
|
-
walletConnectVersion: 2,
|
|
281
|
-
projectId: this.rpc.projectId,
|
|
282
|
-
standaloneChains: this.rpc.chains,
|
|
283
|
-
themeMode: (s = this.rpc.qrModalOptions) == null ? void 0 : s.themeMode,
|
|
284
|
-
themeVariables: (i = this.rpc.qrModalOptions) == null ? void 0 : i.themeVariables,
|
|
285
|
-
});
|
|
286
|
-
} catch {
|
|
287
|
-
throw new Error("To use QR modal, please install @web3modal/standalone package");
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
loadConnectOpts(t) {
|
|
291
|
-
if (!t) return;
|
|
292
|
-
const { chains: s, optionalChains: i, rpcMap: e } = t;
|
|
293
|
-
s &&
|
|
294
|
-
v(s) &&
|
|
295
|
-
((this.rpc.chains = s.map((n) => this.formatChainId(n))),
|
|
296
|
-
s.forEach((n) => {
|
|
297
|
-
this.rpc.rpcMap[n] = e?.[n] || this.getRpcUrl(n);
|
|
298
|
-
})),
|
|
299
|
-
i &&
|
|
300
|
-
v(i) &&
|
|
301
|
-
((this.rpc.optionalChains = []),
|
|
302
|
-
(this.rpc.optionalChains = i?.map((n) => this.formatChainId(n))),
|
|
303
|
-
i.forEach((n) => {
|
|
304
|
-
this.rpc.rpcMap[n] = e?.[n] || this.getRpcUrl(n);
|
|
305
|
-
}));
|
|
306
|
-
}
|
|
307
|
-
getRpcUrl(t, s) {
|
|
308
|
-
var i;
|
|
309
|
-
return (
|
|
310
|
-
((i = this.rpc.rpcMap) == null ? void 0 : i[t]) ||
|
|
311
|
-
`${q}?chainId=eip155:${t}&projectId=${s || this.rpc.projectId}`
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
async loadPersistedSession() {
|
|
315
|
-
if (!this.session) return;
|
|
316
|
-
const t = await this.signer.client.core.storage.getItem(`${this.STORAGE_KEY}/chainId`);
|
|
317
|
-
this.setChainIds(
|
|
318
|
-
t ? [this.formatChainId(t)] : this.session.namespaces[this.namespace].accounts,
|
|
319
|
-
),
|
|
320
|
-
this.setAccounts(this.session.namespaces[this.namespace].accounts);
|
|
321
|
-
}
|
|
322
|
-
reset() {
|
|
323
|
-
(this.chainId = 1), (this.accounts = []);
|
|
324
|
-
}
|
|
325
|
-
persist() {
|
|
326
|
-
this.session &&
|
|
327
|
-
this.signer.client.core.storage.setItem(`${this.STORAGE_KEY}/chainId`, this.chainId);
|
|
328
|
-
}
|
|
329
|
-
parseAccounts(t) {
|
|
330
|
-
return typeof t == "string" || t instanceof String
|
|
331
|
-
? [this.parseAccount(t)]
|
|
332
|
-
: t.map((s) => this.parseAccount(s));
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
const Y = m;
|
|
336
|
-
export {
|
|
337
|
-
Y as EthereumProvider,
|
|
338
|
-
U as OPTIONAL_EVENTS,
|
|
339
|
-
D as OPTIONAL_METHODS,
|
|
340
|
-
u as REQUIRED_EVENTS,
|
|
341
|
-
p as REQUIRED_METHODS,
|
|
342
|
-
m as default,
|
|
343
|
-
};
|
|
1
|
+
import{EventEmitter as R}from"events";import{getAccountsFromNamespaces as T,getSdkError as S,isValidArray as v}from"@walletconnect/utils";import{UniversalProvider as P}from"@walletconnect/universal-provider";const j="wc",$="ethereum_provider",q=`${j}@${2}:${$}:`,N="https://rpc.walletconnect.com/v1/",p=["eth_sendTransaction","personal_sign"],D=["eth_accounts","eth_requestAccounts","eth_call","eth_getBalance","eth_sendRawTransaction","eth_sign","eth_signTransaction","eth_signTypedData","eth_signTypedData_v3","eth_signTypedData_v4","wallet_switchEthereumChain","wallet_addEthereumChain","wallet_getPermissions","wallet_requestPermissions","wallet_registerOnboarding","wallet_watchAsset","wallet_scanQRCode"],u=["chainChanged","accountsChanged"],U=["message","disconnect","connect"];var Q=Object.defineProperty,L=Object.defineProperties,H=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable,y=(a,t,s)=>t in a?Q(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s,I=(a,t)=>{for(var s in t||(t={}))G.call(t,s)&&y(a,s,t[s]);if(_)for(var s of _(t))K.call(t,s)&&y(a,s,t[s]);return a},O=(a,t)=>L(a,H(t));function C(a){return Number(a[0].split(":")[1])}function w(a){return`0x${a.toString(16)}`}function V(a){const{chains:t,optionalChains:s,methods:i,optionalMethods:e,events:n,optionalEvents:c,rpcMap:h}=a;if(!v(t))throw new Error("Invalid chains");const o=t,r=i||p,f=n||u,M={[C(o)]:h[C(o)]},E={chains:o,methods:r,events:f,rpcMap:M},l=n?.filter(g=>!u.includes(g)),d=i?.filter(g=>!p.includes(g));if(!s&&!c&&!e&&!(l!=null&&l.length)&&!(d!=null&&d.length))return{required:E};const b=l?.length&&d?.length||!s,A={chains:[...new Set(b?o.concat(s||[]):s)],methods:[...new Set(r.concat(e||[]))],events:[...new Set(f.concat(c||[]))],rpcMap:h};return{required:E,optional:A}}class m{constructor(){this.events=new R,this.namespace="eip155",this.accounts=[],this.chainId=1,this.STORAGE_KEY=q,this.on=(t,s)=>(this.events.on(t,s),this),this.once=(t,s)=>(this.events.once(t,s),this),this.removeListener=(t,s)=>(this.events.removeListener(t,s),this),this.off=(t,s)=>(this.events.off(t,s),this),this.parseAccount=t=>this.isCompatibleChainId(t)?this.parseAccountId(t).address:t,this.signer={},this.rpc={}}static async init(t){const s=new m;return await s.initialize(t),s}async request(t){return await this.signer.request(t,this.formatChainId(this.chainId))}sendAsync(t,s){this.signer.sendAsync(t,s,this.formatChainId(this.chainId))}get connected(){return this.signer.client?this.signer.client.core.relayer.connected:!1}get connecting(){return this.signer.client?this.signer.client.core.relayer.connecting:!1}async enable(){return this.session||await this.connect(),await this.request({method:"eth_requestAccounts"})}async connect(t){if(!this.signer.client)throw new Error("Provider not initialized. Call init() first");this.loadConnectOpts(t);const{required:s,optional:i}=V(this.rpc);try{const e=await new Promise(async(c,h)=>{var o;this.rpc.showQrModal&&((o=this.modal)==null||o.subscribeModal(r=>{!r.open&&!this.signer.session&&(this.signer.abortPairingAttempt(),h(new Error("Connection request reset. Please try again.")))})),await this.signer.connect(O(I({namespaces:{[this.namespace]:s}},i&&{optionalNamespaces:{[this.namespace]:i}}),{pairingTopic:t?.pairingTopic})).then(r=>{c(r)}).catch(r=>{h(new Error(r.message))})});if(!e)return;this.setChainIds(this.rpc.chains);const n=T(e.namespaces,[this.namespace]);this.setAccounts(n),this.events.emit("connect",{chainId:w(this.chainId)})}catch(e){throw this.signer.logger.error(e),e}finally{this.modal&&this.modal.closeModal()}}async disconnect(){this.session&&await this.signer.disconnect(),this.reset()}get isWalletConnect(){return!0}get session(){return this.signer.session}registerEventListeners(){this.signer.on("session_event",t=>{const{params:s}=t,{event:i}=s;i.name==="accountsChanged"?(this.accounts=this.parseAccounts(i.data),this.events.emit("accountsChanged",this.accounts)):i.name==="chainChanged"?this.setChainId(this.formatChainId(i.data)):this.events.emit(i.name,i.data),this.events.emit("session_event",t)}),this.signer.on("chainChanged",t=>{const s=parseInt(t);this.chainId=s,this.events.emit("chainChanged",w(this.chainId)),this.persist()}),this.signer.on("session_update",t=>{this.events.emit("session_update",t)}),this.signer.on("session_delete",t=>{this.reset(),this.events.emit("session_delete",t),this.events.emit("disconnect",O(I({},S("USER_DISCONNECTED")),{data:t.topic,name:"USER_DISCONNECTED"}))}),this.signer.on("display_uri",t=>{var s,i;this.rpc.showQrModal&&((s=this.modal)==null||s.closeModal(),(i=this.modal)==null||i.openModal({uri:t})),this.events.emit("display_uri",t)})}setHttpProvider(t){this.request({method:"wallet_switchEthereumChain",params:[{chainId:t.toString(16)}]})}isCompatibleChainId(t){return typeof t=="string"?t.startsWith(`${this.namespace}:`):!1}formatChainId(t){return`${this.namespace}:${t}`}parseChainId(t){return Number(t.split(":")[1])}setChainIds(t){const s=t.filter(i=>this.isCompatibleChainId(i)).map(i=>this.parseChainId(i));s.length&&(this.chainId=s[0],this.events.emit("chainChanged",w(this.chainId)),this.persist())}setChainId(t){if(this.isCompatibleChainId(t)){const s=this.parseChainId(t);this.chainId=s,this.setHttpProvider(s)}}parseAccountId(t){const[s,i,e]=t.split(":");return{chainId:`${s}:${i}`,address:e}}setAccounts(t){this.accounts=t.filter(s=>this.parseChainId(this.parseAccountId(s).chainId)===this.chainId).map(s=>this.parseAccountId(s).address),this.events.emit("accountsChanged",this.accounts)}getRpcConfig(t){var s,i;return{chains:((s=t.chains)==null?void 0:s.map(e=>this.formatChainId(e)))||[`${this.namespace}:1`],optionalChains:t.optionalChains?t.optionalChains.map(e=>this.formatChainId(e)):void 0,methods:t?.methods||p,events:t?.events||u,optionalMethods:t?.optionalMethods||[],optionalEvents:t?.optionalEvents||[],rpcMap:t?.rpcMap||this.buildRpcMap(t.chains.concat(t.optionalChains||[]),t.projectId),showQrModal:Boolean(t?.showQrModal),qrModalOptions:(i=t?.qrModalOptions)!=null?i:void 0,projectId:t.projectId,metadata:t.metadata}}buildRpcMap(t,s){const i={};return t.forEach(e=>{i[e]=this.getRpcUrl(e,s)}),i}async initialize(t){if(this.rpc=this.getRpcConfig(t),this.chainId=C(this.rpc.chains),this.signer=await P.init({projectId:this.rpc.projectId,metadata:this.rpc.metadata}),this.registerEventListeners(),await this.loadPersistedSession(),this.rpc.showQrModal)try{const{Web3Modal:s}=await import("@web3modal/standalone");this.modal=new s(I({walletConnectVersion:2,projectId:this.rpc.projectId,standaloneChains:this.rpc.chains},this.rpc.qrModalOptions))}catch{throw new Error("To use QR modal, please install @web3modal/standalone package")}}loadConnectOpts(t){if(!t)return;const{chains:s,optionalChains:i,rpcMap:e}=t;s&&v(s)&&(this.rpc.chains=s.map(n=>this.formatChainId(n)),s.forEach(n=>{this.rpc.rpcMap[n]=e?.[n]||this.getRpcUrl(n)})),i&&v(i)&&(this.rpc.optionalChains=[],this.rpc.optionalChains=i?.map(n=>this.formatChainId(n)),i.forEach(n=>{this.rpc.rpcMap[n]=e?.[n]||this.getRpcUrl(n)}))}getRpcUrl(t,s){var i;return((i=this.rpc.rpcMap)==null?void 0:i[t])||`${N}?chainId=eip155:${t}&projectId=${s||this.rpc.projectId}`}async loadPersistedSession(){if(!this.session)return;const t=await this.signer.client.core.storage.getItem(`${this.STORAGE_KEY}/chainId`);this.setChainIds(t?[this.formatChainId(t)]:this.session.namespaces[this.namespace].accounts),this.setAccounts(this.session.namespaces[this.namespace].accounts)}reset(){this.chainId=1,this.accounts=[]}persist(){this.session&&this.signer.client.core.storage.setItem(`${this.STORAGE_KEY}/chainId`,this.chainId)}parseAccounts(t){return typeof t=="string"||t instanceof String?[this.parseAccount(t)]:t.map(s=>this.parseAccount(s))}}const Y=m;export{Y as EthereumProvider,U as OPTIONAL_EVENTS,D as OPTIONAL_METHODS,u as REQUIRED_EVENTS,p as REQUIRED_METHODS,m as default};
|
|
344
2
|
//# sourceMappingURL=index.es.js.map
|