@rango-dev/provider-walletconnect-2 0.54.0 → 0.54.1-next.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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # [0.54.0](https://github.com/rango-exchange/rango-client/compare/provider-walletconnect-2@0.53.1...provider-walletconnect-2@0.54.0) (2026-05-31)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * eliminate long dependency ([4da6a92](https://github.com/rango-exchange/rango-client/commit/4da6a926c68bdf3cdb68e9e8a6549a0138c7452f))
7
+ * fix build ([f83d9c9](https://github.com/rango-exchange/rango-client/commit/f83d9c9c8d23aba3c428e971939992ae7e4b15d9))
8
+
9
+
10
+
1
11
  ## [0.53.1](https://github.com/rango-exchange/rango-client/compare/provider-walletconnect-2@0.53.0...provider-walletconnect-2@0.53.1) (2026-05-02)
2
12
 
3
13
 
@@ -0,0 +1,2 @@
1
+ import{Networks as n}from"@rango-dev/wallets-shared";var T=n.ETHEREUM,A=1e4;var e="wc@2:client//namespaces";var t=["chainChanged","accountsChanged"],N=["personal_sign","eth_sendTransaction","eth_signTransaction","wallet_switchEthereumChain","wallet_addEthereumChain","eth_chainId"];var a="4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ",o={name:"Rango Exchange",description:"The Ultimate Cross-Chain Solution",url:"https://app.rango.exchange/",icons:["https://app.rango.exchange/logo-rounded.png"]},s="wss://relay.walletconnect.com";export{T as a,A as b,e as c,t as d,N as e,a as f,o as g,s as h};
2
+ //# sourceMappingURL=chunk-6V3WUFOU.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/constants.ts"],
4
- "sourcesContent": ["import { Networks } from '@rango-dev/wallets-shared';\n\nexport const DEFAULT_NETWORK = Networks.ETHEREUM;\nexport const PING_TIMEOUT = 10_000;\n\nexport enum NAMESPACES {\n ETHEREUM = 'eip155',\n SOLANA = 'solana',\n COSMOS = 'cosmos',\n POLKADOT = 'polkadot',\n CARDANO = 'cip34',\n ERLOND = 'elrond',\n MULTIVERSX = 'multiversx',\n}\n\nexport const CHAIN_ID_STORAGE = 'wc@2:client//namespaces';\n\n// Refrence: https://docs.walletconnect.com/2.0/advanced/rpc-reference/solana-rpc\nexport enum SolanaRPCMethods {\n GET_ACCOUNTS = 'solana_getAccounts',\n REQUEST_ACCOUNTS = 'solana_requestAccounts',\n SIGN_TRANSACTION = 'solana_signTransaction',\n SIGN_MESSAGE = 'solana_signMessage',\n}\n\n// Refrence: https://docs.walletconnect.com/2.0/advanced/rpc-reference/cosmos-rpc\nexport enum CosmosRPCMethods {\n GET_ACCOUNTS = 'cosmos_getAccounts',\n SIGN_DIRECT = 'cosmos_signDirect',\n SIGN_AMINO = 'cosmos_signAmino',\n}\n\n// Refrence: https://docs.walletconnect.com/2.0/advanced/rpc-reference/ethereum-rpc\nexport enum EthereumRPCMethods {\n PERSONAL_SIGN = 'personal_sign',\n SIGN = 'eth_sign',\n SIGN_TYPED_DATA = 'eth_signTypedData',\n SIGN_TRANSACTION = 'eth_signTransaction',\n SEND_TRANSACTION = 'eth_sendTransaction',\n SEND_RAW_TRANSACTION = 'eth_sendRawTransaction',\n SWITCH_CHAIN = 'wallet_switchEthereumChain',\n ADD_CHAIN = 'wallet_addEthereumChain',\n GET_CHAIN = 'eth_chainId',\n}\n\nexport enum StarknetRPCMethods {\n REQUEST_ADD_INVOKE_TRANSACTION = 'starknet_requestAddInvokeTransaction',\n SIGN_TYPED_DATA = 'starknet_signTypedData',\n}\n\nexport enum EthereumEvents {\n CHAIN_CHANGED = 'chainChanged',\n ACCOUNTS_CHANGED = 'accountsChanged',\n}\n\nexport const DEFAULT_ETHEREUM_EVENTS: EthereumEvents[] = [\n EthereumEvents.CHAIN_CHANGED,\n EthereumEvents.ACCOUNTS_CHANGED,\n];\n\nexport const DEFAULT_ETHEREUM_METHODS = [\n EthereumRPCMethods.PERSONAL_SIGN,\n EthereumRPCMethods.SEND_TRANSACTION,\n EthereumRPCMethods.SIGN_TRANSACTION,\n EthereumRPCMethods.SWITCH_CHAIN,\n EthereumRPCMethods.ADD_CHAIN,\n EthereumRPCMethods.GET_CHAIN,\n];\n\nexport const DEFAULT_SOLANA_METHODS = [\n SolanaRPCMethods.SIGN_TRANSACTION,\n SolanaRPCMethods.SIGN_MESSAGE,\n];\n\nexport const DEFAULT_COSMOS_METHODS = [\n CosmosRPCMethods.GET_ACCOUNTS,\n CosmosRPCMethods.SIGN_AMINO,\n CosmosRPCMethods.SIGN_DIRECT,\n];\n\n// refrence: https://github.com/ChainAgnostic/namespaces/blob/main/solana/caip2.md\nexport const DEFAULT_SOLANA_CHAIN_ID = '4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ';\n\nexport const DEFAULT_APP_METADATA = {\n name: 'Rango Exchange',\n description: 'The Ultimate Cross-Chain Solution',\n url: 'https://app.rango.exchange/',\n icons: ['https://app.rango.exchange/logo-rounded.png'],\n};\n\nexport const RELAY_URL = 'wss://relay.walletconnect.com';\n"],
5
- "mappings": "AAAA,OAAS,YAAAA,MAAgB,4BAElB,IAAMC,EAAkBD,EAAS,SAC3BE,EAAe,IAYrB,IAAMC,EAAmB,0BAwCzB,IAAMC,EAA4C,CACvD,eACA,iBACF,EAEaC,EAA2B,CACtC,gBACA,sBACA,sBACA,6BACA,0BACA,aACF,EAcO,IAAMC,EAA0B,mCAE1BC,EAAuB,CAClC,KAAM,iBACN,YAAa,oCACb,IAAK,8BACL,MAAO,CAAC,6CAA6C,CACvD,EAEaC,EAAY",
4
+ "sourcesContent": ["import { Networks } from '@rango-dev/wallets-shared';\n\nexport const DEFAULT_NETWORK = Networks.ETHEREUM;\nexport const PING_TIMEOUT = 10_000;\n\nexport enum NAMESPACES {\n ETHEREUM = 'eip155',\n SOLANA = 'solana',\n POLKADOT = 'polkadot',\n CARDANO = 'cip34',\n ERLOND = 'elrond',\n MULTIVERSX = 'multiversx',\n}\n\nexport const CHAIN_ID_STORAGE = 'wc@2:client//namespaces';\n\n// Refrence: https://docs.walletconnect.com/2.0/advanced/rpc-reference/solana-rpc\nexport enum SolanaRPCMethods {\n GET_ACCOUNTS = 'solana_getAccounts',\n REQUEST_ACCOUNTS = 'solana_requestAccounts',\n SIGN_TRANSACTION = 'solana_signTransaction',\n SIGN_MESSAGE = 'solana_signMessage',\n}\n\n// Refrence: https://docs.walletconnect.com/2.0/advanced/rpc-reference/ethereum-rpc\nexport enum EthereumRPCMethods {\n PERSONAL_SIGN = 'personal_sign',\n SIGN = 'eth_sign',\n SIGN_TYPED_DATA = 'eth_signTypedData',\n SIGN_TRANSACTION = 'eth_signTransaction',\n SEND_TRANSACTION = 'eth_sendTransaction',\n SEND_RAW_TRANSACTION = 'eth_sendRawTransaction',\n SWITCH_CHAIN = 'wallet_switchEthereumChain',\n ADD_CHAIN = 'wallet_addEthereumChain',\n GET_CHAIN = 'eth_chainId',\n}\n\nexport enum StarknetRPCMethods {\n REQUEST_ADD_INVOKE_TRANSACTION = 'starknet_requestAddInvokeTransaction',\n SIGN_TYPED_DATA = 'starknet_signTypedData',\n}\n\nexport enum EthereumEvents {\n CHAIN_CHANGED = 'chainChanged',\n ACCOUNTS_CHANGED = 'accountsChanged',\n}\n\nexport const DEFAULT_ETHEREUM_EVENTS: EthereumEvents[] = [\n EthereumEvents.CHAIN_CHANGED,\n EthereumEvents.ACCOUNTS_CHANGED,\n];\n\nexport const DEFAULT_ETHEREUM_METHODS = [\n EthereumRPCMethods.PERSONAL_SIGN,\n EthereumRPCMethods.SEND_TRANSACTION,\n EthereumRPCMethods.SIGN_TRANSACTION,\n EthereumRPCMethods.SWITCH_CHAIN,\n EthereumRPCMethods.ADD_CHAIN,\n EthereumRPCMethods.GET_CHAIN,\n];\n\nexport const DEFAULT_SOLANA_METHODS = [\n SolanaRPCMethods.SIGN_TRANSACTION,\n SolanaRPCMethods.SIGN_MESSAGE,\n];\n\n// refrence: https://github.com/ChainAgnostic/namespaces/blob/main/solana/caip2.md\nexport const DEFAULT_SOLANA_CHAIN_ID = '4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ';\n\nexport const DEFAULT_APP_METADATA = {\n name: 'Rango Exchange',\n description: 'The Ultimate Cross-Chain Solution',\n url: 'https://app.rango.exchange/',\n icons: ['https://app.rango.exchange/logo-rounded.png'],\n};\n\nexport const RELAY_URL = 'wss://relay.walletconnect.com';\n"],
5
+ "mappings": "AAAA,OAAS,YAAAA,MAAgB,4BAElB,IAAMC,EAAkBD,EAAS,SAC3BE,EAAe,IAWrB,IAAMC,EAAmB,0BAiCzB,IAAMC,EAA4C,CACvD,eACA,iBACF,EAEaC,EAA2B,CACtC,gBACA,sBACA,sBACA,6BACA,0BACA,aACF,EAQO,IAAMC,EAA0B,mCAE1BC,EAAuB,CAClC,KAAM,iBACN,YAAa,oCACb,IAAK,8BACL,MAAO,CAAC,6CAA6C,CACvD,EAEaC,EAAY",
6
6
  "names": ["Networks", "DEFAULT_NETWORK", "PING_TIMEOUT", "CHAIN_ID_STORAGE", "DEFAULT_ETHEREUM_EVENTS", "DEFAULT_ETHEREUM_METHODS", "DEFAULT_SOLANA_CHAIN_ID", "DEFAULT_APP_METADATA", "RELAY_URL"]
7
7
  }
@@ -4,7 +4,6 @@ export declare const PING_TIMEOUT = 10000;
4
4
  export declare enum NAMESPACES {
5
5
  ETHEREUM = "eip155",
6
6
  SOLANA = "solana",
7
- COSMOS = "cosmos",
8
7
  POLKADOT = "polkadot",
9
8
  CARDANO = "cip34",
10
9
  ERLOND = "elrond",
@@ -17,11 +16,6 @@ export declare enum SolanaRPCMethods {
17
16
  SIGN_TRANSACTION = "solana_signTransaction",
18
17
  SIGN_MESSAGE = "solana_signMessage"
19
18
  }
20
- export declare enum CosmosRPCMethods {
21
- GET_ACCOUNTS = "cosmos_getAccounts",
22
- SIGN_DIRECT = "cosmos_signDirect",
23
- SIGN_AMINO = "cosmos_signAmino"
24
- }
25
19
  export declare enum EthereumRPCMethods {
26
20
  PERSONAL_SIGN = "personal_sign",
27
21
  SIGN = "eth_sign",
@@ -44,7 +38,6 @@ export declare enum EthereumEvents {
44
38
  export declare const DEFAULT_ETHEREUM_EVENTS: EthereumEvents[];
45
39
  export declare const DEFAULT_ETHEREUM_METHODS: EthereumRPCMethods[];
46
40
  export declare const DEFAULT_SOLANA_METHODS: SolanaRPCMethods[];
47
- export declare const DEFAULT_COSMOS_METHODS: CosmosRPCMethods[];
48
41
  export declare const DEFAULT_SOLANA_CHAIN_ID = "4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ";
49
42
  export declare const DEFAULT_APP_METADATA: {
50
43
  name: string;
@@ -1,2 +1,2 @@
1
- import"./chunk-RPL2NMJC.js";import{a as h}from"./chunk-DXVBX5XQ.js";import{cleanEvmError as p,DefaultEvmSigner as u}from"@rango-dev/signer-evm";import*as l from"@walletconnect/encoding";import{AccountId as S,ChainId as m}from"caip";import"rango-types";var a="eip155",d=class{static{h(this,"EVMSigner")}client;session;constructor(r,n){this.client=r,this.session=n}async signMessage(r,n,t){let s=this.isNetworkAndAccountExistInSession({address:n,chainId:t}),i=new m({namespace:a,reference:s.chainId}),o=[l.utf8ToHex(r,!0),n],c;try{c=await this.client.request({topic:this.session.topic,chainId:i.toString(),request:{method:"personal_sign",params:o}})}catch(g){throw p(g)}return c}async signAndSendTx(r,n,t){try{let s=this.isNetworkAndAccountExistInSession({address:n,chainId:t}),i=u.buildTx(r),e=await this.client.request({topic:this.session.topic,chainId:s.caipChainId,request:{method:"eth_sendTransaction",params:[i]}});if(!e?.startsWith("0x"))throw new Error(`Received an invalid hash on signing the transaction. (hash=${e})`);return{hash:e}}catch(s){let i=p(s),e=this.session,o={namspaces:e?.namespaces,peering:e?.peer?.metadata,code:s?.code};throw i.context=o,i}}isNetworkAndAccountExistInSession(r){let{address:n,chainId:t}=r;if(!t)throw console.log("isNetworkAndAccountExistInSession",r),new Error("You need to set your chain for signing message/transaction.");let s=t.startsWith("0x")?String(parseInt(t)):t,i=new S({chainId:{namespace:a,reference:s},address:n}),e=this.session.namespaces[a]?.accounts.map(c=>c.toLowerCase());if(!e||!e.includes(i.toString()))throw console.warn("Available adresses and requested address:",e,i.toString(),t,n),new Error("Your requested address doesn't exist on your wallect connect session. Please reconnect your wallet.");let o=new m({namespace:a,reference:s});return{chainId:s,address:n,caipChainId:o.toString()}}},C=d;export{C as default};
2
- //# sourceMappingURL=evm-MYSQOTV5.js.map
1
+ import"./chunk-6V3WUFOU.js";import{a as h}from"./chunk-DXVBX5XQ.js";import{cleanEvmError as p,DefaultEvmSigner as u}from"@rango-dev/signer-evm";import*as l from"@walletconnect/encoding";import{AccountId as S,ChainId as m}from"caip";import"rango-types";var a="eip155",d=class{static{h(this,"EVMSigner")}client;session;constructor(r,n){this.client=r,this.session=n}async signMessage(r,n,t){let s=this.isNetworkAndAccountExistInSession({address:n,chainId:t}),i=new m({namespace:a,reference:s.chainId}),o=[l.utf8ToHex(r,!0),n],c;try{c=await this.client.request({topic:this.session.topic,chainId:i.toString(),request:{method:"personal_sign",params:o}})}catch(g){throw p(g)}return c}async signAndSendTx(r,n,t){try{let s=this.isNetworkAndAccountExistInSession({address:n,chainId:t}),i=u.buildTx(r),e=await this.client.request({topic:this.session.topic,chainId:s.caipChainId,request:{method:"eth_sendTransaction",params:[i]}});if(!e?.startsWith("0x"))throw new Error(`Received an invalid hash on signing the transaction. (hash=${e})`);return{hash:e}}catch(s){let i=p(s),e=this.session,o={namspaces:e?.namespaces,peering:e?.peer?.metadata,code:s?.code};throw i.context=o,i}}isNetworkAndAccountExistInSession(r){let{address:n,chainId:t}=r;if(!t)throw console.log("isNetworkAndAccountExistInSession",r),new Error("You need to set your chain for signing message/transaction.");let s=t.startsWith("0x")?String(parseInt(t)):t,i=new S({chainId:{namespace:a,reference:s},address:n}),e=this.session.namespaces[a]?.accounts.map(c=>c.toLowerCase());if(!e||!e.includes(i.toString()))throw console.warn("Available adresses and requested address:",e,i.toString(),t,n),new Error("Your requested address doesn't exist on your wallect connect session. Please reconnect your wallet.");let o=new m({namespace:a,reference:s});return{chainId:s,address:n,caipChainId:o.toString()}}},C=d;export{C as default};
2
+ //# sourceMappingURL=evm-7WN7BITC.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/signers/evm.ts"],
4
- "sourcesContent": ["import type { SignClient } from '@walletconnect/sign-client/dist/types/client';\nimport type { SessionTypes } from '@walletconnect/types';\nimport type { EvmTransaction } from 'rango-types/mainApi';\n\nimport { cleanEvmError, DefaultEvmSigner } from '@rango-dev/signer-evm';\nimport * as encoding from '@walletconnect/encoding';\nimport { AccountId, ChainId } from 'caip';\nimport { type GenericSigner } from 'rango-types';\n\nimport { EthereumRPCMethods, NAMESPACES } from '../constants.js';\n\nconst NAMESPACE_NAME = NAMESPACES.ETHEREUM;\n\nclass EVMSigner implements GenericSigner<EvmTransaction> {\n private client: SignClient;\n private session: SessionTypes.Struct;\n\n constructor(client: SignClient, session: SessionTypes.Struct) {\n this.client = client;\n this.session = session;\n }\n\n public async signMessage(\n msg: string,\n address: string,\n chainId: string | null\n ): Promise<string> {\n const requestedFor = this.isNetworkAndAccountExistInSession({\n address,\n chainId,\n });\n\n const caipChainId = new ChainId({\n namespace: NAMESPACE_NAME,\n reference: requestedFor.chainId,\n });\n const hexMsg = encoding.utf8ToHex(msg, true);\n\n const params = [hexMsg, address];\n\n let signature: string;\n try {\n // Send message to wallet (using relayer)\n signature = await this.client.request({\n topic: this.session.topic,\n chainId: caipChainId.toString(),\n request: {\n method: EthereumRPCMethods.PERSONAL_SIGN,\n params,\n },\n });\n } catch (error) {\n throw cleanEvmError(error);\n }\n\n /*\n * TODO: We can also verify the signature here\n * Check web-examples: dapps/react-dapp-v2/src/contexts/JsonRpcContext.tsx\n */\n\n return signature;\n }\n\n async signAndSendTx(\n tx: EvmTransaction,\n address: string,\n chainId: string | null\n ): Promise<{ hash: string }> {\n try {\n const requestedFor = this.isNetworkAndAccountExistInSession({\n address,\n chainId,\n });\n const transaction = DefaultEvmSigner.buildTx(tx);\n const hash: string = await this.client.request({\n topic: this.session.topic,\n chainId: requestedFor.caipChainId,\n request: {\n method: EthereumRPCMethods.SEND_TRANSACTION,\n params: [transaction],\n },\n });\n // Some wallets e.g. Rainbow wallet are returning invalid hash (e.g. 'null') in case of the rejection\n if (!hash?.startsWith('0x')) {\n throw new Error(\n `Received an invalid hash on signing the transaction. (hash=${hash})`\n );\n }\n return {\n hash,\n };\n } catch (error: any) {\n const modifiedError = cleanEvmError(error);\n const session = this.session;\n const context = {\n namspaces: session?.namespaces,\n peering: session?.peer?.metadata,\n code: error?.code,\n };\n modifiedError.context = context;\n throw modifiedError;\n }\n }\n\n private isNetworkAndAccountExistInSession(requestedFor: {\n address: string;\n chainId: string | null;\n }) {\n const { address, chainId } = requestedFor;\n\n if (!chainId) {\n console.log('isNetworkAndAccountExistInSession', requestedFor);\n throw new Error(\n 'You need to set your chain for signing message/transaction.'\n );\n }\n\n /*\n * TODO: We need to make sure we are using a single format for chain ids, it should be hex or number.\n * This is a quick fix for evm.\n */\n const chainIdNumber = chainId.startsWith('0x')\n ? String(parseInt(chainId))\n : chainId;\n\n const caipAddress = new AccountId({\n chainId: {\n namespace: NAMESPACE_NAME,\n reference: chainIdNumber,\n },\n address,\n });\n const addresses = this.session.namespaces[NAMESPACE_NAME]?.accounts.map(\n (address) => address.toLowerCase()\n );\n\n if (!addresses || !addresses.includes(caipAddress.toString())) {\n console.warn(\n 'Available adresses and requested address:',\n addresses,\n caipAddress.toString(),\n chainId,\n address\n );\n throw new Error(\n `Your requested address doesn't exist on your wallect connect session. Please reconnect your wallet.`\n );\n }\n\n const caipChainId = new ChainId({\n namespace: NAMESPACE_NAME,\n reference: chainIdNumber,\n });\n\n return {\n chainId: chainIdNumber,\n address,\n caipChainId: caipChainId.toString(),\n };\n }\n}\n\nexport default EVMSigner;\n"],
5
- "mappings": "oEAIA,OAAS,iBAAAA,EAAe,oBAAAC,MAAwB,wBAChD,UAAYC,MAAc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QAAUC,EAClBD,CACR,CACF,CAEQ,kCAAkCX,EAGvC,CACD,GAAM,CAAE,QAAAF,EAAS,QAAAC,CAAQ,EAAIC,EAE7B,GAAI,CAACD,EACH,cAAQ,IAAI,oCAAqCC,CAAY,EACvD,IAAI,MACR,6DACF,EAOF,IAAMa,EAAgBd,EAAQ,WAAW,IAAI,EACzC,OAAO,SAASA,CAAO,CAAC,EACxBA,EAEEe,EAAc,IAAIC,EAAU,CAChC,QAAS,CACP,UAAWvB,EACX,UAAWqB,CACb,EACA,QAAAf,CACF,CAAC,EACKkB,EAAY,KAAK,QAAQ,WAAWxB,CAAc,GAAG,SAAS,IACjEM,GAAYA,EAAQ,YAAY,CACnC,EAEA,GAAI,CAACkB,GAAa,CAACA,EAAU,SAASF,EAAY,SAAS,CAAC,EAC1D,cAAQ,KACN,4CACAE,EACAF,EAAY,SAAS,EACrBf,EACAD,CACF,EACM,IAAI,MACR,qGACF,EAGF,IAAMG,EAAc,IAAIC,EAAQ,CAC9B,UAAWV,EACX,UAAWqB,CACb,CAAC,EAED,MAAO,CACL,QAASA,EACT,QAAAf,EACA,YAAaG,EAAY,SAAS,CACpC,CACF,CACF,EAEOgB,EAAQxB",
4
+ "sourcesContent": ["import type { SignClient } from '@walletconnect/sign-client/dist/types/client';\nimport type { SessionTypes } from '@walletconnect/types';\nimport type { EvmTransaction } from 'rango-types/mainApi';\n\nimport { cleanEvmError, DefaultEvmSigner } from '@rango-dev/signer-evm';\nimport * as encoding from '@walletconnect/encoding';\nimport { AccountId, ChainId } from 'caip';\nimport { type GenericSigner } from 'rango-types';\n\nimport { EthereumRPCMethods, NAMESPACES } from '../constants.js';\n\nconst NAMESPACE_NAME = NAMESPACES.ETHEREUM;\n\nclass EVMSigner implements GenericSigner<EvmTransaction> {\n private client: SignClient;\n private session: SessionTypes.Struct;\n\n constructor(client: SignClient, session: SessionTypes.Struct) {\n this.client = client;\n this.session = session;\n }\n\n public async signMessage(\n msg: string,\n address: string,\n chainId: string | null\n ): Promise<string> {\n const requestedFor = this.isNetworkAndAccountExistInSession({\n address,\n chainId,\n });\n\n const caipChainId = new ChainId({\n namespace: NAMESPACE_NAME,\n reference: requestedFor.chainId,\n });\n const hexMsg = encoding.utf8ToHex(msg, true);\n\n const params = [hexMsg, address];\n\n let signature: string;\n try {\n // Send message to wallet (using relayer)\n signature = await this.client.request({\n topic: this.session.topic,\n chainId: caipChainId.toString(),\n request: {\n method: EthereumRPCMethods.PERSONAL_SIGN,\n params,\n },\n });\n } catch (error) {\n throw cleanEvmError(error);\n }\n\n /*\n * TODO: We can also verify the signature here\n * Check web-examples: dapps/react-dapp-v2/src/contexts/JsonRpcContext.tsx\n */\n\n return signature;\n }\n\n async signAndSendTx(\n tx: EvmTransaction,\n address: string,\n chainId: string | null\n ): Promise<{ hash: string }> {\n try {\n const requestedFor = this.isNetworkAndAccountExistInSession({\n address,\n chainId,\n });\n const transaction = DefaultEvmSigner.buildTx(tx);\n const hash: string = await this.client.request({\n topic: this.session.topic,\n chainId: requestedFor.caipChainId,\n request: {\n method: EthereumRPCMethods.SEND_TRANSACTION,\n params: [transaction],\n },\n });\n // Some wallets e.g. Rainbow wallet are returning invalid hash (e.g. 'null') in case of the rejection\n if (!hash?.startsWith('0x')) {\n throw new Error(\n `Received an invalid hash on signing the transaction. (hash=${hash})`\n );\n }\n return {\n hash,\n };\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n const modifiedError = cleanEvmError(error);\n const session = this.session;\n const context = {\n namspaces: session?.namespaces,\n peering: session?.peer?.metadata,\n code: error?.code,\n };\n modifiedError.context = context;\n throw modifiedError;\n }\n }\n\n private isNetworkAndAccountExistInSession(requestedFor: {\n address: string;\n chainId: string | null;\n }) {\n const { address, chainId } = requestedFor;\n\n if (!chainId) {\n console.log('isNetworkAndAccountExistInSession', requestedFor);\n throw new Error(\n 'You need to set your chain for signing message/transaction.'\n );\n }\n\n /*\n * TODO: We need to make sure we are using a single format for chain ids, it should be hex or number.\n * This is a quick fix for evm.\n */\n const chainIdNumber = chainId.startsWith('0x')\n ? String(parseInt(chainId))\n : chainId;\n\n const caipAddress = new AccountId({\n chainId: {\n namespace: NAMESPACE_NAME,\n reference: chainIdNumber,\n },\n address,\n });\n const addresses = this.session.namespaces[NAMESPACE_NAME]?.accounts.map(\n (address) => address.toLowerCase()\n );\n\n if (!addresses || !addresses.includes(caipAddress.toString())) {\n console.warn(\n 'Available adresses and requested address:',\n addresses,\n caipAddress.toString(),\n chainId,\n address\n );\n throw new Error(\n `Your requested address doesn't exist on your wallect connect session. Please reconnect your wallet.`\n );\n }\n\n const caipChainId = new ChainId({\n namespace: NAMESPACE_NAME,\n reference: chainIdNumber,\n });\n\n return {\n chainId: chainIdNumber,\n address,\n caipChainId: caipChainId.toString(),\n };\n }\n}\n\nexport default EVMSigner;\n"],
5
+ "mappings": "oEAIA,OAAS,iBAAAA,EAAe,oBAAAC,MAAwB,wBAChD,UAAYC,MAAc,0BAC1B,OAAS,aAAAC,EAAW,WAAAC,MAAe,OACnC,MAAmC,cAInC,IAAMC,WAEAC,EAAN,KAAyD,CAbzD,MAayD,CAAAC,EAAA,kBAC/C,OACA,QAER,YAAYC,EAAoBC,EAA8B,CAC5D,KAAK,OAASD,EACd,KAAK,QAAUC,CACjB,CAEA,MAAa,YACXC,EACAC,EACAC,EACiB,CACjB,IAAMC,EAAe,KAAK,kCAAkC,CAC1D,QAAAF,EACA,QAAAC,CACF,CAAC,EAEKE,EAAc,IAAIC,EAAQ,CAC9B,UAAWV,EACX,UAAWQ,EAAa,OAC1B,CAAC,EAGKG,EAAS,CAFS,YAAUN,EAAK,EAAI,EAEnBC,CAAO,EAE3BM,EACJ,GAAI,CAEFA,EAAY,MAAM,KAAK,OAAO,QAAQ,CACpC,MAAO,KAAK,QAAQ,MACpB,QAASH,EAAY,SAAS,EAC9B,QAAS,CACP,uBACA,OAAAE,CACF,CACF,CAAC,CACH,OAASE,EAAO,CACd,MAAMC,EAAcD,CAAK,CAC3B,CA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CACb,CAAC,EAED,MAAO,CACL,QAASA,EACT,QAAAf,EACA,YAAaG,EAAY,SAAS,CACpC,CACF,CACF,EAEOgB,EAAQxB",
6
6
  "names": ["cleanEvmError", "DefaultEvmSigner", "encoding", "AccountId", "ChainId", "NAMESPACE_NAME", "EVMSigner", "__name", "client", "session", "msg", "address", "chainId", "requestedFor", "caipChainId", "ChainId", "params", "signature", "error", "cleanEvmError", "tx", "transaction", "DefaultEvmSigner", "hash", "modifiedError", "context", "chainIdNumber", "caipAddress", "AccountId", "addresses", "evm_default"]
7
7
  }
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{d as R,e as B,g as h,h as S}from"./chunk-BPSEZJUF.js";import{a as x,b as P,c as E,d as W,e as D,f as O,g as L,h as b}from"./chunk-RPL2NMJC.js";import{a as r}from"./chunk-DXVBX5XQ.js";import{debug as we,error as re}from"@rango-dev/logging-core";import{Networks as Ae,WalletTypes as Te}from"@rango-dev/wallets-shared";import ve from"@walletconnect/sign-client";import{AccountId as Ne,ChainId as ie}from"caip";import{evmBlockchains as ae}from"rango-types";import{convertEvmBlockchainMetaToEvmChainInfo as Ce,isEvmAddress as Q,Networks as Ee}from"@rango-dev/wallets-shared";var g=class{static{r(this,"d")}constructor(n){this.openModal=h.open,this.closeModal=h.close,this.subscribeModal=h.subscribe,this.setTheme=S.setThemeConfig,S.setThemeConfig(n),B.setConfig(n),this.initUi()}async initUi(){if(typeof window<"u"){await import("./dist-6GI3ECE5.js");let n=document.createElement("wcm-modal");document.body.insertAdjacentElement("beforeend",n),R.setIsUiLoaded(!0)}}};import{AccountId as X,ChainId as N}from"caip";import{evmBlockchains as Se,isEvmBlockchain as ye}from"rango-types";import{Networks as le,timeout as me}from"@rango-dev/wallets-shared";import{getSdkError as U}from"@walletconnect/utils";import{AccountId as H}from"caip";function w(e){return e.session.values[e.session.values.length-1]}r(w,"getLastSession");async function de(e,n){return await me(e.ping({topic:n}),P),w(e)}r(de,"restoreSession");async function ue(e,n,s){let{requiredNamespaces:o,optionalNamespaces:t,pairingTopic:i}=n;try{let{uri:a,approval:c}=await e.connect({requiredNamespaces:o,optionalNamespaces:t,pairingTopic:i}),l;if(a){let d=s.envs.DISABLE_MODAL_AND_OPEN_LINK;if(d){let u=`${d}/wc?uri=${encodeURIComponent(a)}`;window.open(u,"_blank","noreferrer noopener")}else{let u={...o||{},...t||{}},p=Object.values(u).map(k=>k.chains).flat(),C=y();C.openModal({uri:a,chains:p}),l=new Promise((k,ce)=>{C.subscribeModal(pe=>{pe.open||ce(new Error("Modal has been closed."))})})}}let m=c();return l?await Promise.race([m,l]):await m}finally{y().closeModal()}}r(ue,"createSession");function fe(e){let n=e.pairing.getAll({active:!0});return n.length>0?n[n.length-1]:void 0}r(fe,"tryGetPairing");async function F(e,n){let{meta:s}=n,o=$(s),t,i=fe(e);if(i)try{t=await de(e,i.topic)}catch{await A(e)}return t||(t=await ue(e,{requiredNamespaces:{},optionalNamespaces:o},{envs:n.envs})),t}r(F,"tryConnect");async function q(e,n){let s=e.session.getAll(),o=e.pairing.getAll();s.forEach(t=>{if(t.topic===n||t.pairingTopic===n){let i=t.pairingTopic===n?t.pairingTopic:t.topic;e.core.expirer.set(i,0)}}),o.forEach(t=>{t.topic===n&&e.core.expirer.set(n,0)})}r(q,"cleanupSingleSession");async function A(e){let n=[],s=e.session.getAll();for(let t of s)n.push(e.disconnect({topic:t.topic,reason:U("USER_DISCONNECTED")}));let o=e.pairing.getAll();for(let t of o)n.push(e.disconnect({topic:t.topic,reason:U("USER_DISCONNECTED")}));return T(e,void 0),await Promise.all(n)}r(A,"disconnectSessions");function j(e){return Object.values(e.namespaces).map(s=>s.accounts).flat().map(s=>{let{address:o,chainId:t}=new H(s),i=K(t.reference);return{address:o,chainId:i}})}r(j,"getAccountsFromSession");function G(e){return Object.values(e.params.namespaces).map(s=>s.accounts).flat().map(s=>{let{address:o,chainId:t}=new H(s);return{accounts:[o],chainId:t.namespace==="solana"?le.SOLANA:t.reference}})}r(G,"getAccountsFromEvent");async function J(e,n,s,o){let t=e.session,i=t.namespaces,a=!1,c=i.eip155.accounts,l=Y(e),m=I(n,l,o);c.includes(m)||(c.push(m),a=!0);let d=I(s,l,o);if(c.includes(d)||(c.push(d),a=!0),a){let u={...i,eip155:{...i.eip155,accounts:c}};await e.client.session.update({topic:t.topic,namespaces:u}).catch(p=>{console.log(p)})}}r(J,"updateSessionAccounts");function z(e){let n=["trust","1inch"],s=e?.session?.peer?.metadata?.name;return n.some(o=>s?.toLowerCase()?.includes(o))}r(z,"ignoreNamespaceMethods");async function T(e,n){return e.core.storage.setItem(E,{defaultChainId:n?parseInt(n):""})}r(T,"persistCurrentChainId");async function V(e){try{let n=(await e.core.storage.getItem(E))?.defaultChainId;return n?String(n):void 0}catch{return}}r(V,"getPersistedChainId");var v;function Z(e){v||(v=new g({projectId:e,themeMode:"light",themeVariables:{"--wcm-z-index":"999999999"}}))}r(Z,"createModalInstance");function y(){return v}r(y,"getModal");function $(e){let s=Se(e).map(t=>new N({namespace:"eip155",reference:String(parseInt(t.chainId))}).toString());return{eip155:{methods:D,events:W,chains:s}}}r($,"generateOptionalNamespace");function K(e){return e===O?Ee.SOLANA:e}r(K,"solanaChainIdToNetworkName");async function ee(e,n,s,o){if(e.method==="eth_chainId"){let t=w(n),i=Object.values(t.namespaces).map(c=>c.chains).flat(),a=o().network;if(i.length>0){let c=a?M(a,s):void 0;if(c)return c;let m=i[0];return new N(m).reference}throw new Error("Couldn't find any chain on namespace")}throw new Error("Dissallowed method:",e)}r(ee,"simulateRequest");function M(e,n){let o=n.find(i=>i.name===e)?.chainId;return o?String(parseInt(o)):void 0}r(M,"getChainIdByNetworkName");async function ne(e,n,s,o){let t=e.filter(ye),a=Ce(t)[n],l=e.find(p=>p.name===n)?.chainId,m=M(s,e),d=N.format({namespace:"eip155",reference:String(m)}),u=o.session;try{await o.client.request({topic:u.topic,request:{method:"wallet_switchEthereumChain",params:[{chainId:l}]},chainId:d})}catch(p){if(p?.code===4902||p?.message?.includes(String(4902)))await o.client.request({topic:u.topic,request:{method:"wallet_addEthereumChain",params:[a]},chainId:d});else throw p}}r(ne,"switchOrAddEvmChain");function Y(e){return e.session.namespaces.eip155.accounts?.map(n=>new X(n).address)?.filter(n=>Q(n))?.[0]}r(Y,"getCurrentEvmAccountAddress");function I(e,n,s){let o=M(e,s);return X.format({chainId:{namespace:"eip155",reference:String(o)},address:n})}r(I,"getEvmAccount");function te(e,n){let s=!1;return e.filter(({address:o,chainId:t})=>{if(Q(o)){if(n&&t!==n)return!1;if(!n){if(s)return!1;s=!0}}return!0}).map(({address:o,chainId:t})=>({accounts:[o],chainId:t}))}r(te,"filterEvmAccounts");import{dynamicImportWithRefinedError as se}from"@rango-dev/wallets-shared";import{DefaultSignerFactory as Ie,TransactionType as oe}from"rango-types";async function _(e){if(!e.session)throw new Error("Session is required for wallet connect signers.");let n=new Ie,s=(await se(async()=>await import("./evm-MYSQOTV5.js"))).default,o=(await se(async()=>await import("./solana-35I33VLX.js"))).default;return n.registerSigner(oe.EVM,new s(e.client,e.session)),n.registerSigner(oe.SOLANA,new o(e.client,e.session)),n}r(_,"getSigners");var Me=Te.WALLET_CONNECT_2,f={WC_PROJECT_ID:"",DISABLE_MODAL_AND_OPEN_LINK:void 0},an=r(e=>{f=e,Z(f.WC_PROJECT_ID)},"init"),cn={type:Me,checkInstallation:!1,isAsyncInstance:!0,defaultNetwork:x,isAsyncSwitchNetwork:!0},pn=r(async e=>{let{currentProvider:n,getState:s,meta:o}=e,t;if(n)t=n;else{if(!f.WC_PROJECT_ID)throw new Error("You need to set `WC_PROJECT_ID` in Wallet Connect provider.");t=await ve.init({relayUrl:b,projectId:f.WC_PROJECT_ID,metadata:L})}return{client:t,session:null,request:async i=>ee(i,t,o,s)}},"getInstance"),ln=r(async({instance:e,meta:n})=>{let{client:s}=e,o=await F(s,{meta:n,envs:f});e.session=o;let t=await V(s),i=j(o);return te(i,t)},"connect"),mn=r(({instance:e,updateChainId:n,updateAccounts:s,disconnect:o})=>{let{client:t}=e;t.on("session_update",i=>{G(i).forEach(c=>{s(c.accounts,c.chainId)})}),t.on("session_event",i=>{if(i.params.event.name==="accountsChanged"){let a=i.params.event.data.map(l=>new Ne(l).address),c=ie.parse(i.params.chainId).reference;s(a),n(c)}else if(i.params.event.name==="chainChanged"){let a=i.params.event.data;n(a),T(e.client,a)}else console.log("[WC2] session_event not supported",i.params.event)}),t.on("session_delete",async i=>{console.log("[WC2] your wallet has requested to delete session.",i),q(t,i.topic),o()})},"subscribe"),dn=r(async({network:e,instance:n,meta:s,getState:o,updateChainId:t})=>{let a=ae(s).find(p=>p.name===e)?.chainId;if(!a){let p=new Error(`There is no match for ${a}`);throw re(p),p}let c=new ie({namespace:"eip155",reference:String(parseInt(a))}).toString(),m=n.session.namespaces.eip155,d=m?.chains||[];if((m?.methods||[]).includes("wallet_switchEthereumChain")&&!z(n)){let p=o?.().network||Ae.ETHEREUM;await J(n,e,p,s),await ne(s,e,p,n)}else if(d.includes(c)){t(a);return}else{let p=new Error(`Chain ${a} is not configured.`);throw re(p),p}},"switchNetwork"),un=r(()=>!0,"canSwitchNetworkTo"),fn=r(async({instance:e})=>{let{client:n}=e;n&&A(n).catch(s=>we(s))},"disconnect"),hn=_,gn=r(e=>({name:"WalletConnect",img:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/walletconnect/icon.svg",installLink:"",color:"#b2dbff",supportedChains:ae(e),showOnMobile:!0,mobileWallet:!0}),"getWalletInfo");export{un as canSwitchNetworkTo,cn as config,ln as connect,fn as disconnect,pn as getInstance,hn as getSigners,gn as getWalletInfo,an as init,mn as subscribe,dn as switchNetwork};
1
+ import{d as R,e as B,g as h,h as S}from"./chunk-BPSEZJUF.js";import{a as x,b as P,c as E,d as W,e as D,f as O,g as L,h as b}from"./chunk-6V3WUFOU.js";import{a as r}from"./chunk-DXVBX5XQ.js";import{debug as we,error as re}from"@rango-dev/logging-core";import{Networks as Ae,WalletTypes as Te}from"@rango-dev/wallets-shared";import ve from"@walletconnect/sign-client";import{AccountId as Ne,ChainId as ie}from"caip";import{evmBlockchains as ae}from"rango-types";import{convertEvmBlockchainMetaToEvmChainInfo as Ce,isEvmAddress as Q,Networks as Ee}from"@rango-dev/wallets-shared";var g=class{static{r(this,"d")}constructor(n){this.openModal=h.open,this.closeModal=h.close,this.subscribeModal=h.subscribe,this.setTheme=S.setThemeConfig,S.setThemeConfig(n),B.setConfig(n),this.initUi()}async initUi(){if(typeof window<"u"){await import("./dist-6GI3ECE5.js");let n=document.createElement("wcm-modal");document.body.insertAdjacentElement("beforeend",n),R.setIsUiLoaded(!0)}}};import{AccountId as X,ChainId as N}from"caip";import{evmBlockchains as Se,isEvmBlockchain as ye}from"rango-types";import{Networks as le,timeout as me}from"@rango-dev/wallets-shared";import{getSdkError as U}from"@walletconnect/utils";import{AccountId as H}from"caip";function w(e){return e.session.values[e.session.values.length-1]}r(w,"getLastSession");async function de(e,n){return await me(e.ping({topic:n}),P),w(e)}r(de,"restoreSession");async function ue(e,n,s){let{requiredNamespaces:o,optionalNamespaces:t,pairingTopic:i}=n;try{let{uri:a,approval:c}=await e.connect({requiredNamespaces:o,optionalNamespaces:t,pairingTopic:i}),l;if(a){let d=s.envs.DISABLE_MODAL_AND_OPEN_LINK;if(d){let u=`${d}/wc?uri=${encodeURIComponent(a)}`;window.open(u,"_blank","noreferrer noopener")}else{let u={...o||{},...t||{}},p=Object.values(u).map(k=>k.chains).flat(),C=y();C.openModal({uri:a,chains:p}),l=new Promise((k,ce)=>{C.subscribeModal(pe=>{pe.open||ce(new Error("Modal has been closed."))})})}}let m=c();return l?await Promise.race([m,l]):await m}finally{y().closeModal()}}r(ue,"createSession");function fe(e){let n=e.pairing.getAll({active:!0});return n.length>0?n[n.length-1]:void 0}r(fe,"tryGetPairing");async function F(e,n){let{meta:s}=n,o=$(s),t,i=fe(e);if(i)try{t=await de(e,i.topic)}catch{await A(e)}return t||(t=await ue(e,{requiredNamespaces:{},optionalNamespaces:o},{envs:n.envs})),t}r(F,"tryConnect");async function q(e,n){let s=e.session.getAll(),o=e.pairing.getAll();s.forEach(t=>{if(t.topic===n||t.pairingTopic===n){let i=t.pairingTopic===n?t.pairingTopic:t.topic;e.core.expirer.set(i,0)}}),o.forEach(t=>{t.topic===n&&e.core.expirer.set(n,0)})}r(q,"cleanupSingleSession");async function A(e){let n=[],s=e.session.getAll();for(let t of s)n.push(e.disconnect({topic:t.topic,reason:U("USER_DISCONNECTED")}));let o=e.pairing.getAll();for(let t of o)n.push(e.disconnect({topic:t.topic,reason:U("USER_DISCONNECTED")}));return T(e,void 0),await Promise.all(n)}r(A,"disconnectSessions");function j(e){return Object.values(e.namespaces).map(s=>s.accounts).flat().map(s=>{let{address:o,chainId:t}=new H(s),i=K(t.reference);return{address:o,chainId:i}})}r(j,"getAccountsFromSession");function G(e){return Object.values(e.params.namespaces).map(s=>s.accounts).flat().map(s=>{let{address:o,chainId:t}=new H(s);return{accounts:[o],chainId:t.namespace==="solana"?le.SOLANA:t.reference}})}r(G,"getAccountsFromEvent");async function J(e,n,s,o){let t=e.session,i=t.namespaces,a=!1,c=i.eip155.accounts,l=Y(e),m=I(n,l,o);c.includes(m)||(c.push(m),a=!0);let d=I(s,l,o);if(c.includes(d)||(c.push(d),a=!0),a){let u={...i,eip155:{...i.eip155,accounts:c}};await e.client.session.update({topic:t.topic,namespaces:u}).catch(p=>{console.log(p)})}}r(J,"updateSessionAccounts");function z(e){let n=["trust","1inch"],s=e?.session?.peer?.metadata?.name;return n.some(o=>s?.toLowerCase()?.includes(o))}r(z,"ignoreNamespaceMethods");async function T(e,n){return e.core.storage.setItem(E,{defaultChainId:n?parseInt(n):""})}r(T,"persistCurrentChainId");async function V(e){try{let n=(await e.core.storage.getItem(E))?.defaultChainId;return n?String(n):void 0}catch{return}}r(V,"getPersistedChainId");var v;function Z(e){v||(v=new g({projectId:e,themeMode:"light",themeVariables:{"--wcm-z-index":"999999999"}}))}r(Z,"createModalInstance");function y(){return v}r(y,"getModal");function $(e){let s=Se(e).map(t=>new N({namespace:"eip155",reference:String(parseInt(t.chainId))}).toString());return{eip155:{methods:D,events:W,chains:s}}}r($,"generateOptionalNamespace");function K(e){return e===O?Ee.SOLANA:e}r(K,"solanaChainIdToNetworkName");async function ee(e,n,s,o){if(e.method==="eth_chainId"){let t=w(n),i=Object.values(t.namespaces).map(c=>c.chains).flat(),a=o().network;if(i.length>0){let c=a?M(a,s):void 0;if(c)return c;let m=i[0];return new N(m).reference}throw new Error("Couldn't find any chain on namespace")}throw new Error("Dissallowed method:",e)}r(ee,"simulateRequest");function M(e,n){let o=n.find(i=>i.name===e)?.chainId;return o?String(parseInt(o)):void 0}r(M,"getChainIdByNetworkName");async function ne(e,n,s,o){let t=e.filter(ye),a=Ce(t)[n],l=e.find(p=>p.name===n)?.chainId,m=M(s,e),d=N.format({namespace:"eip155",reference:String(m)}),u=o.session;try{await o.client.request({topic:u.topic,request:{method:"wallet_switchEthereumChain",params:[{chainId:l}]},chainId:d})}catch(p){if(p?.code===4902||p?.message?.includes(String(4902)))await o.client.request({topic:u.topic,request:{method:"wallet_addEthereumChain",params:[a]},chainId:d});else throw p}}r(ne,"switchOrAddEvmChain");function Y(e){return e.session.namespaces.eip155.accounts?.map(n=>new X(n).address)?.filter(n=>Q(n))?.[0]}r(Y,"getCurrentEvmAccountAddress");function I(e,n,s){let o=M(e,s);return X.format({chainId:{namespace:"eip155",reference:String(o)},address:n})}r(I,"getEvmAccount");function te(e,n){let s=!1;return e.filter(({address:o,chainId:t})=>{if(Q(o)){if(n&&t!==n)return!1;if(!n){if(s)return!1;s=!0}}return!0}).map(({address:o,chainId:t})=>({accounts:[o],chainId:t}))}r(te,"filterEvmAccounts");import{dynamicImportWithRefinedError as se}from"@rango-dev/wallets-shared";import{DefaultSignerFactory as Ie,TransactionType as oe}from"rango-types";async function _(e){if(!e.session)throw new Error("Session is required for wallet connect signers.");let n=new Ie,s=(await se(async()=>await import("./evm-7WN7BITC.js"))).default,o=(await se(async()=>await import("./solana-MFA7C5XI.js"))).default;return n.registerSigner(oe.EVM,new s(e.client,e.session)),n.registerSigner(oe.SOLANA,new o(e.client,e.session)),n}r(_,"getSigners");var Me=Te.WALLET_CONNECT_2,f={WC_PROJECT_ID:"",DISABLE_MODAL_AND_OPEN_LINK:void 0},an=r(e=>{f=e,Z(f.WC_PROJECT_ID)},"init"),cn={type:Me,checkInstallation:!1,isAsyncInstance:!0,defaultNetwork:x,isAsyncSwitchNetwork:!0},pn=r(async e=>{let{currentProvider:n,getState:s,meta:o}=e,t;if(n)t=n;else{if(!f.WC_PROJECT_ID)throw new Error("You need to set `WC_PROJECT_ID` in Wallet Connect provider.");t=await ve.init({relayUrl:b,projectId:f.WC_PROJECT_ID,metadata:L})}return{client:t,session:null,request:async i=>ee(i,t,o,s)}},"getInstance"),ln=r(async({instance:e,meta:n})=>{let{client:s}=e,o=await F(s,{meta:n,envs:f});e.session=o;let t=await V(s),i=j(o);return te(i,t)},"connect"),mn=r(({instance:e,updateChainId:n,updateAccounts:s,disconnect:o})=>{let{client:t}=e;t.on("session_update",i=>{G(i).forEach(c=>{s(c.accounts,c.chainId)})}),t.on("session_event",i=>{if(i.params.event.name==="accountsChanged"){let a=i.params.event.data.map(l=>new Ne(l).address),c=ie.parse(i.params.chainId).reference;s(a),n(c)}else if(i.params.event.name==="chainChanged"){let a=i.params.event.data;n(a),T(e.client,a)}else console.log("[WC2] session_event not supported",i.params.event)}),t.on("session_delete",async i=>{console.log("[WC2] your wallet has requested to delete session.",i),q(t,i.topic),o()})},"subscribe"),dn=r(async({network:e,instance:n,meta:s,getState:o,updateChainId:t})=>{let a=ae(s).find(p=>p.name===e)?.chainId;if(!a){let p=new Error(`There is no match for ${a}`);throw re(p),p}let c=new ie({namespace:"eip155",reference:String(parseInt(a))}).toString(),m=n.session.namespaces.eip155,d=m?.chains||[];if((m?.methods||[]).includes("wallet_switchEthereumChain")&&!z(n)){let p=o?.().network||Ae.ETHEREUM;await J(n,e,p,s),await ne(s,e,p,n)}else if(d.includes(c)){t(a);return}else{let p=new Error(`Chain ${a} is not configured.`);throw re(p),p}},"switchNetwork"),un=r(()=>!0,"canSwitchNetworkTo"),fn=r(async({instance:e})=>{let{client:n}=e;n&&A(n).catch(s=>we(s))},"disconnect"),hn=_,gn=r(e=>({name:"WalletConnect",img:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/walletconnect/icon.svg",installLink:"",color:"#b2dbff",supportedChains:ae(e),showOnMobile:!0,mobileWallet:!0}),"getWalletInfo");export{un as canSwitchNetworkTo,cn as config,ln as connect,fn as disconnect,pn as getInstance,hn as getSigners,gn as getWalletInfo,an as init,mn as subscribe,dn as switchNetwork};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../src/helpers.ts", "../../../node_modules/@walletconnect/modal/src/client.ts", "../src/session.ts", "../src/signer.ts"],
4
- "sourcesContent": ["import type { Environments, WCInstance } from './types.js';\nimport type {\n CanSwitchNetwork,\n Connect,\n Disconnect,\n GetInstance,\n Subscribe,\n SwitchNetwork,\n WalletConfig,\n WalletInfo,\n} from '@rango-dev/wallets-shared';\nimport type { ISignClient } from '@walletconnect/types';\nimport type { BlockchainMeta, SignerFactory } from 'rango-types';\n\nimport { debug, error as logError } from '@rango-dev/logging-core';\nimport { Networks, WalletTypes } from '@rango-dev/wallets-shared';\nimport Client from '@walletconnect/sign-client';\nimport { AccountId, ChainId } from 'caip';\nimport { evmBlockchains } from 'rango-types';\n\nimport {\n DEFAULT_APP_METADATA,\n DEFAULT_NETWORK,\n EthereumEvents,\n EthereumRPCMethods,\n NAMESPACES,\n RELAY_URL,\n} from './constants.js';\nimport {\n createModalInstance,\n filterEvmAccounts,\n simulateRequest,\n switchOrAddEvmChain,\n} from './helpers.js';\nimport {\n cleanupSingleSession,\n disconnectSessions,\n getAccountsFromEvent,\n getAccountsFromSession,\n getPersistedChainId,\n ignoreNamespaceMethods,\n persistCurrentChainId,\n tryConnect,\n updateSessionAccounts,\n} from './session.js';\nimport signer from './signer.js';\n\nconst WALLET = WalletTypes.WALLET_CONNECT_2;\n\nlet envs: Environments = {\n WC_PROJECT_ID: '',\n DISABLE_MODAL_AND_OPEN_LINK: undefined,\n};\n\nexport type { Environments };\n\nexport const init = (environments: Environments) => {\n envs = environments;\n\n createModalInstance(envs.WC_PROJECT_ID);\n};\n\nexport const config: WalletConfig = {\n type: WALLET,\n checkInstallation: false,\n isAsyncInstance: true,\n defaultNetwork: DEFAULT_NETWORK,\n isAsyncSwitchNetwork: true,\n};\n\nexport const getInstance: GetInstance = async (options) => {\n const { currentProvider, getState, meta } = options;\n\n /*\n * Create a new pair, if exists use the pair,\n * Or use the already created one.\n */\n let provider: ISignClient;\n if (!currentProvider) {\n if (!envs.WC_PROJECT_ID) {\n throw new Error(\n 'You need to set `WC_PROJECT_ID` in Wallet Connect provider.'\n );\n }\n provider = await Client.init({\n relayUrl: RELAY_URL,\n projectId: envs.WC_PROJECT_ID,\n metadata: DEFAULT_APP_METADATA,\n });\n } else {\n provider = currentProvider;\n }\n\n return {\n client: provider,\n session: null,\n request: async (params: any) =>\n simulateRequest(params, provider, meta, getState),\n };\n};\n\nexport const connect: Connect = async ({ instance, meta }) => {\n const { client } = instance as WCInstance;\n // Try to restore the session first, if couldn't, create a new session by showing a modal.\n const session = await tryConnect(client, { meta, envs });\n // Override the value (session).\n instance.session = session;\n const currentChainId = await getPersistedChainId(client);\n const accounts = getAccountsFromSession(session);\n return filterEvmAccounts(accounts, currentChainId);\n};\n\nexport const subscribe: Subscribe = ({\n instance,\n updateChainId,\n updateAccounts,\n disconnect,\n}) => {\n const { client } = instance as WCInstance;\n\n /**\n * Session events refrence:\n * https://docs.walletconnect.com/2.0/specs/clients/sign/session-events\n */\n\n // Listen to updating the session by adding a new chain, method, or event\n client.on('session_update', (args) => {\n const allAccounts = getAccountsFromEvent(args);\n allAccounts.forEach((accountsWithChain) => {\n updateAccounts(accountsWithChain.accounts, accountsWithChain.chainId);\n });\n });\n\n // Listen to events triggred by wallet. (e.g. accountsChanged and chainChanged)\n client.on('session_event', (args) => {\n if (args.params.event.name === EthereumEvents.ACCOUNTS_CHANGED) {\n const accounts = args.params.event.data.map((account: string) => {\n return new AccountId(account).address;\n });\n const chainId = ChainId.parse(args.params.chainId).reference;\n updateAccounts(accounts);\n updateChainId(chainId);\n } else if (args.params.event.name === EthereumEvents.CHAIN_CHANGED) {\n const chainId = args.params.event.data;\n updateChainId(chainId);\n void persistCurrentChainId(instance.client, chainId);\n } else {\n console.log('[WC2] session_event not supported', args.params.event);\n }\n });\n\n client.on('session_delete', async (event) => {\n console.log('[WC2] your wallet has requested to delete session.', event);\n void cleanupSingleSession(client, event.topic);\n disconnect();\n });\n};\n\nexport const switchNetwork: SwitchNetwork = async ({\n network,\n instance,\n meta,\n getState,\n updateChainId,\n}) => {\n const evm = evmBlockchains(meta);\n const chainId = evm.find((chain) => chain.name === network)?.chainId;\n if (!chainId) {\n const error = new Error(`There is no match for ${chainId}`);\n logError(error);\n throw error;\n }\n const chaindIdStr = new ChainId({\n namespace: NAMESPACES.ETHEREUM,\n reference: String(parseInt(chainId)),\n }).toString();\n\n const session = instance.session;\n const evmNamespace = session.namespaces[NAMESPACES.ETHEREUM];\n const authorizedChains = evmNamespace?.chains || [];\n const authorizedMethods = evmNamespace?.methods || [];\n\n if (\n authorizedMethods.includes(EthereumRPCMethods.SWITCH_CHAIN) &&\n !ignoreNamespaceMethods(instance)\n ) {\n const currentNetwork = getState?.().network || Networks.ETHEREUM;\n await updateSessionAccounts(instance, network, currentNetwork, meta);\n await switchOrAddEvmChain(meta, network, currentNetwork, instance);\n } else if (authorizedChains.includes(chaindIdStr)) {\n updateChainId(chainId);\n return;\n } else {\n const error = new Error(`Chain ${chainId} is not configured.`);\n logError(error);\n throw error;\n }\n};\n\n/**\n *\n * Note:\n * There is no straight-forward way to detect the wallet supports which blockchain,\n * So we send request to wallet and expect to be rejected on the wallet if it's not supported.\n *\n */\nexport const canSwitchNetworkTo: CanSwitchNetwork = () => true;\n\nexport const disconnect: Disconnect = async ({ instance }) => {\n const { client } = instance as WCInstance;\n\n if (client) {\n void disconnectSessions(client).catch((error) => debug(error));\n }\n};\n\nexport const getSigners: (provider: WCInstance) => Promise<SignerFactory> =\n signer;\n\nexport const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (\n allBlockChains\n) => {\n const evms = evmBlockchains(allBlockChains);\n return {\n name: 'WalletConnect',\n img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/walletconnect/icon.svg',\n installLink: '',\n color: '#b2dbff',\n supportedChains: evms,\n showOnMobile: true,\n mobileWallet: true,\n };\n};\n", "import type { WalletConnectModal as WalletConnectModalType } from './wc-types.js';\nimport type { WalletState } from '@rango-dev/wallets-shared';\nimport type { ProposalTypes } from '@walletconnect/types';\nimport type { BlockchainMeta } from 'rango-types';\n\nimport {\n convertEvmBlockchainMetaToEvmChainInfo,\n isEvmAddress,\n Networks,\n} from '@rango-dev/wallets-shared';\nimport { WalletConnectModal } from '@walletconnect/modal';\nimport { AccountId, ChainId } from 'caip';\nimport { evmBlockchains, isEvmBlockchain } from 'rango-types';\n\nimport {\n DEFAULT_ETHEREUM_EVENTS,\n DEFAULT_ETHEREUM_METHODS,\n DEFAULT_SOLANA_CHAIN_ID,\n EthereumRPCMethods,\n NAMESPACES,\n} from './constants.js';\nimport { getLastSession } from './session.js';\n\nlet web3Modal: WalletConnectModalType;\nexport function createModalInstance(projectId: string) {\n if (!web3Modal) {\n web3Modal = new WalletConnectModal({\n projectId,\n themeMode: 'light',\n themeVariables: {\n '--wcm-z-index': '999999999',\n },\n }) as unknown as WalletConnectModalType;\n }\n}\n\nexport function getModal(): WalletConnectModalType {\n return web3Modal;\n}\n\ntype FinalNamespaces = {\n [key in NAMESPACES]?: ProposalTypes.BaseRequiredNamespace;\n};\n\n/*\n * Some wallets like 1inch (android) has problem when we pass cosmos chains in optional namespace\n * Also some wallets like keplr mobile doesn't work when we don't pass cosmos chains in required namespace\n * It seems to be a bug in their current implementation.\n */\nexport function generateOptionalNamespace(\n meta: BlockchainMeta[]\n): FinalNamespaces | undefined {\n const evm = evmBlockchains(meta);\n const evmChains = evm.map((chain) => {\n return new ChainId({\n namespace: NAMESPACES.ETHEREUM,\n reference: String(parseInt(chain.chainId)),\n }).toString();\n });\n\n const namespaces: FinalNamespaces = {\n [NAMESPACES.ETHEREUM]: {\n methods: DEFAULT_ETHEREUM_METHODS,\n events: DEFAULT_ETHEREUM_EVENTS,\n chains: evmChains,\n },\n };\n return namespaces;\n}\n\nexport function solanaChainIdToNetworkName(chainId: string): string {\n return chainId === DEFAULT_SOLANA_CHAIN_ID ? Networks.SOLANA : chainId;\n}\n\n/**\n *\n * In `rango-preset` we are working with `window.ethereum.request()`,\n * this is an interceptor for some RPC methods (e.g. eth_chainId).\n *\n */\nexport async function simulateRequest(\n params: any,\n provider: any,\n meta: BlockchainMeta[],\n getState: () => WalletState\n) {\n if (params.method === 'eth_chainId') {\n const currentSession = getLastSession(provider);\n const standaloneChains = Object.values(currentSession.namespaces)\n .map((namespace) => namespace.chains)\n .flat() as string[];\n\n const network = getState().network;\n\n if (standaloneChains.length > 0) {\n const chainId = network\n ? getChainIdByNetworkName(network, meta)\n : undefined;\n\n if (chainId) {\n return chainId;\n }\n\n const firstIndex = 0;\n const firstChain = standaloneChains[firstIndex];\n const firstChainId = new ChainId(firstChain);\n return firstChainId.reference;\n }\n\n throw new Error(`Couldn't find any chain on namespace`);\n }\n throw new Error('Dissallowed method:', params);\n}\n\nexport function getChainIdByNetworkName(\n network: string,\n meta: BlockchainMeta[]\n): string | undefined {\n const targetBlockchain = meta.find(\n (blockchain) => blockchain.name === network\n );\n const chainIdInHex = targetBlockchain?.chainId;\n if (!chainIdInHex) {\n return undefined;\n }\n\n const chainId = String(parseInt(chainIdInHex));\n\n return chainId;\n}\n\nexport async function switchOrAddEvmChain(\n meta: BlockchainMeta[],\n requestedNetwork: string,\n currentNetwork: string,\n instance: any\n) {\n const evmBlockchains = meta.filter(isEvmBlockchain);\n const evmNetworksChainInfo =\n convertEvmBlockchainMetaToEvmChainInfo(evmBlockchains);\n const targetChain = evmNetworksChainInfo[requestedNetwork];\n const targetBlockchain = meta.find(\n (blockchain: BlockchainMeta) => blockchain.name === requestedNetwork\n );\n const chainIdInHex = targetBlockchain?.chainId;\n\n const currentChainId = getChainIdByNetworkName(currentNetwork, meta);\n const currentChainEip = ChainId.format({\n namespace: NAMESPACES.ETHEREUM,\n reference: String(currentChainId),\n });\n\n const session = instance.session;\n\n try {\n await instance.client.request({\n topic: session.topic,\n request: {\n method: EthereumRPCMethods.SWITCH_CHAIN,\n params: [\n {\n chainId: chainIdInHex,\n },\n ],\n },\n // It's required to pass current chain, otherwise it won't work\n chainId: currentChainEip,\n });\n } catch (err: any) {\n const addChainError = 4902;\n if (\n err?.code === addChainError ||\n err?.message?.includes(String(addChainError))\n ) {\n await instance.client.request({\n topic: session.topic,\n request: {\n method: EthereumRPCMethods.ADD_CHAIN,\n params: [targetChain],\n },\n // It's required to pass current chain, otherwise it won't work\n chainId: currentChainEip,\n });\n } else {\n throw err;\n }\n }\n}\n\nexport function getCurrentEvmAccountAddress(instance: any) {\n return instance.session.namespaces.eip155.accounts\n ?.map((account: string) => {\n return new AccountId(account).address;\n })\n ?.filter((address: string) => isEvmAddress(address))?.[0];\n}\n\nexport function getEvmAccount(\n network: string,\n address: string,\n meta: BlockchainMeta[]\n) {\n const currentChainId = getChainIdByNetworkName(network, meta);\n return AccountId.format({\n chainId: {\n namespace: NAMESPACES.ETHEREUM,\n reference: String(currentChainId),\n },\n address,\n });\n}\n\n// It's enough to return only connected network for the EVM networks and ignore others\nexport function filterEvmAccounts(\n accounts: {\n address: string;\n chainId: string;\n }[],\n currentChainId?: string\n) {\n let firstEvmAddress = false;\n return accounts\n .filter(({ address, chainId }) => {\n const isEvm = isEvmAddress(address);\n if (isEvm) {\n if (currentChainId && chainId !== currentChainId) {\n return false;\n }\n if (!currentChainId) {\n if (firstEvmAddress) {\n return false;\n }\n firstEvmAddress = true;\n }\n }\n return true;\n })\n .map(({ address, chainId }) => ({\n accounts: [address],\n chainId: chainId,\n }));\n}\n", "import type { ConfigCtrlState, ThemeCtrlState } from '@walletconnect/modal-core'\nimport { ConfigCtrl, ModalCtrl, OptionsCtrl, ThemeCtrl } from '@walletconnect/modal-core'\n\n/**\n * Types\n */\nexport type WalletConnectModalConfig = ConfigCtrlState & ThemeCtrlState\n\n/**\n * Client\n */\nexport class WalletConnectModal {\n public constructor(config: WalletConnectModalConfig) {\n ThemeCtrl.setThemeConfig(config)\n ConfigCtrl.setConfig(config)\n this.initUi()\n }\n\n private async initUi() {\n if (typeof window !== 'undefined') {\n await import('@walletconnect/modal-ui')\n const modal = document.createElement('wcm-modal')\n document.body.insertAdjacentElement('beforeend', modal)\n OptionsCtrl.setIsUiLoaded(true)\n }\n }\n\n public openModal = ModalCtrl.open\n\n public closeModal = ModalCtrl.close\n\n public subscribeModal = ModalCtrl.subscribe\n\n public setTheme = ThemeCtrl.setThemeConfig\n}\n", "import type {\n ConnectParams,\n CreateSessionParams,\n Environments,\n} from './types.js';\nimport type { SignClient } from '@walletconnect/sign-client/dist/types/client';\nimport type {\n PairingTypes,\n SessionTypes,\n SignClientTypes,\n} from '@walletconnect/types';\nimport type { BlockchainMeta } from 'rango-types';\n\nimport { Networks, timeout } from '@rango-dev/wallets-shared';\nimport { getSdkError } from '@walletconnect/utils';\nimport { AccountId } from 'caip';\n\nimport { CHAIN_ID_STORAGE, PING_TIMEOUT } from './constants.js';\nimport {\n generateOptionalNamespace,\n getCurrentEvmAccountAddress,\n getEvmAccount,\n getModal,\n solanaChainIdToNetworkName,\n} from './helpers.js';\n\nexport function getLastSession(client: SignClient) {\n return client.session.values[client.session.values.length - 1];\n}\n\n/**\n *\n * Try to ping the wallet, if wallet responded with `pong`, session is a valid and we will use the session.\n * If the wallet didn't respond during 10 seconds (PING_TIME), we assume the wallet isn't available and we need to create a new session.\n *\n */\nexport async function restoreSession(\n client: SignClient,\n pairingTopic: PairingTypes.Struct['topic']\n): Promise<SessionTypes.Struct | undefined> {\n await timeout(\n client.ping({\n topic: pairingTopic,\n }),\n PING_TIMEOUT\n );\n\n // We assume last session is the correct session, beacuse we are doing clean up and keeps only one pairing/session.\n const session = getLastSession(client);\n return session;\n}\n\n/**\n *\n * Getting a pair of required and optional namespaces then tries to show a modal and connect (pair)\n * To the wallet.\n * @param client\n * @param options\n * @returns\n */\nexport async function createSession(\n client: SignClient,\n options: CreateSessionParams,\n configs: {\n envs: Environments;\n }\n): Promise<SessionTypes.Struct> {\n const { requiredNamespaces, optionalNamespaces, pairingTopic } = options;\n\n try {\n const { uri, approval } = await client.connect({\n requiredNamespaces,\n optionalNamespaces,\n pairingTopic,\n });\n\n // Open QRCode modal if a URI was returned (i.e. we're not connecting an existing pairing).\n let onCloseModal;\n if (uri) {\n /*\n * There are some wallets have been listed in WC itself (https://docs.walletconnect.com/cloud/explorer-submission),\n * Using `DISABLE_MODAL_AND_OPEN_LINK` option, we can directly open a specific desktop wallet.\n */\n const redirectLink = configs.envs.DISABLE_MODAL_AND_OPEN_LINK;\n if (redirectLink) {\n const url = `${redirectLink}/wc?uri=${encodeURIComponent(uri)}`;\n window.open(url, '_blank', 'noreferrer noopener');\n } else {\n // Create a flat array of all requested chains across namespaces.\n const allNamespaces = {\n ...(requiredNamespaces || {}),\n ...(optionalNamespaces || {}),\n };\n\n const standaloneChains = Object.values(allNamespaces)\n .map((namespace) => namespace.chains)\n .flat() as string[];\n\n const modal = getModal();\n void modal.openModal({ uri, chains: standaloneChains });\n\n onCloseModal = new Promise((_, reject) => {\n modal.subscribeModal((state) => {\n // the modal was closed so reject the promise\n if (!state.open) {\n reject(new Error('Modal has been closed.'));\n }\n });\n });\n }\n }\n\n const session = approval();\n\n if (onCloseModal) {\n const result = await Promise.race([session, onCloseModal]);\n // We know onClose only reject a modal and never returns a value.\n return result as SessionTypes.Struct;\n }\n return await session;\n } finally {\n getModal().closeModal();\n }\n}\n\n/**\n *\n * A user (client) can have multiple pairings (to different wallets), we are assuming\n * the last pairing is the active pairing for now. A better UX can be showing a list of pairings\n * and let the user to choose the right pairing manually. Because we don't have that yet, we will pick up the last one.\n *\n */\nexport function tryGetPairing(\n client: SignClient\n): PairingTypes.Struct | undefined {\n const pairings = client.pairing.getAll({ active: true });\n const lastPairing =\n pairings.length > 0 ? pairings[pairings.length - 1] : undefined;\n\n return lastPairing;\n}\n\n/**\n *\n * Try to restore the session first, if couldn't, create a new session by showing a modal.\n *\n */\nexport async function tryConnect(\n client: SignClient,\n params: ConnectParams\n): Promise<SessionTypes.Struct> {\n const { meta } = params;\n\n // We try to get all of our supported chains as optional.\n const optionalNamespaces = generateOptionalNamespace(meta);\n\n // Check if the user has a session, if yes, restore the session and use it.\n let session: SessionTypes.Struct | undefined;\n const pairing = tryGetPairing(client);\n if (pairing) {\n try {\n session = await restoreSession(client, pairing.topic);\n } catch (e) {\n await disconnectSessions(client);\n }\n }\n\n // In case of connecting for the first time or session couldn't be restored, we will create a new session.\n if (!session) {\n session = await createSession(\n client,\n {\n requiredNamespaces: {},\n optionalNamespaces,\n },\n {\n envs: params.envs,\n }\n );\n }\n\n return session;\n}\n\n/**\n *\n * Try to find sessions with a topic id and expire them.\n *\n */\nexport async function cleanupSingleSession(client: SignClient, topic: string) {\n const sessions = client.session.getAll();\n const pairings = client.pairing.getAll();\n\n sessions.forEach((session) => {\n if (session.topic === topic || session.pairingTopic === topic) {\n const requestForDeleteTopic =\n session.pairingTopic === topic ? session.pairingTopic : session.topic;\n client.core.expirer.set(requestForDeleteTopic, 0);\n }\n });\n\n pairings.forEach((pairing) => {\n if (pairing.topic === topic) {\n client.core.expirer.set(topic, 0);\n }\n });\n}\n\n/**\n *\n * Disconnect means to delete the session on both parties (dApp & wallet) at the same time.\n *\n */\nexport async function disconnectSessions(client: SignClient) {\n const allPromises = [];\n\n const sessions = client.session.getAll();\n for (const session of sessions) {\n allPromises.push(\n client.disconnect({\n topic: session.topic,\n reason: getSdkError('USER_DISCONNECTED'),\n })\n );\n }\n\n const pairings = client.pairing.getAll();\n for (const pairing of pairings) {\n allPromises.push(\n client.disconnect({\n topic: pairing.topic,\n reason: getSdkError('USER_DISCONNECTED'),\n })\n );\n }\n\n // reset the current chain id\n void persistCurrentChainId(client, undefined);\n\n return await Promise.all(allPromises);\n}\n\nexport function getAccountsFromSession(session: SessionTypes.Struct) {\n const accounts = Object.values(session.namespaces)\n .map((namespace) => namespace.accounts)\n .flat()\n .map((account) => {\n const { address, chainId } = new AccountId(account);\n /*\n * Note: Solana has a specific ID, we need to convert it back to network name.\n * It will return the chain id itslef if it's not that specific ID.\n */\n const chain = solanaChainIdToNetworkName(chainId.reference);\n return {\n address,\n chainId: chain,\n };\n });\n return accounts;\n}\n\nexport function getAccountsFromEvent(\n event: SignClientTypes.BaseEventArgs<{\n namespaces: SessionTypes.Namespaces;\n }>\n) {\n const accounts = Object.values(event.params.namespaces)\n .map((namespace) => namespace.accounts)\n .flat()\n .map((account) => {\n const { address, chainId } = new AccountId(account);\n return {\n accounts: [address],\n chainId:\n chainId.namespace === 'solana' ? Networks.SOLANA : chainId.reference,\n };\n });\n\n return accounts;\n}\n\n/*\n * Before switch network, we need to update session namespace accounts\n * to contain both current chain and target chain accoutns.\n */\nexport async function updateSessionAccounts(\n instance: any,\n requestedNetwork: string,\n currentNetwork: string,\n meta: BlockchainMeta[]\n) {\n const session = instance.session;\n\n const namespaces = session.namespaces;\n let needUpdateNamepspace = false;\n const accounts = namespaces.eip155.accounts;\n\n const currentAccountAddress = getCurrentEvmAccountAddress(instance);\n const requestedAccount = getEvmAccount(\n requestedNetwork,\n currentAccountAddress,\n meta\n );\n if (!accounts.includes(requestedAccount)) {\n accounts.push(requestedAccount);\n needUpdateNamepspace = true;\n }\n\n const currentAccount = getEvmAccount(\n currentNetwork,\n currentAccountAddress,\n meta\n );\n if (!accounts.includes(currentAccount)) {\n accounts.push(currentAccount);\n needUpdateNamepspace = true;\n }\n\n if (needUpdateNamepspace) {\n const updatedNamespaces = {\n ...namespaces,\n eip155: {\n ...namespaces.eip155,\n accounts,\n },\n };\n await instance.client.session\n .update({\n topic: session.topic,\n namespaces: updatedNamespaces,\n })\n .catch((err: unknown) => {\n console.log(err);\n });\n }\n}\n\n/*\n * Certain wallets, such as Trust Wallet and 1inch, are providing incorrect methods in\n * response to session proposal requests. These wallets do not support certain optional\n * RPC methods like \"wallet_xyz,\" but they include them in the response under the session namespace.\n * For the time being, we should avoid their session namespace response.\n * see also: https://github.com/trustwallet/wallet-core/issues/3588\n */\nexport function ignoreNamespaceMethods(instance: any): boolean {\n const WALLETS_WITH_WRONG_NAMESPACE_METHODS = ['trust', '1inch'];\n const peerName = instance?.session?.peer?.metadata?.name;\n return WALLETS_WITH_WRONG_NAMESPACE_METHODS.some((name) =>\n peerName?.toLowerCase()?.includes(name)\n );\n}\n\nexport async function persistCurrentChainId(\n client: SignClient,\n chainId?: string\n) {\n return client.core.storage.setItem(CHAIN_ID_STORAGE, {\n defaultChainId: chainId ? parseInt(chainId) : '',\n });\n}\n\n/*\n * get the latest chain id from the storage,\n * used for setting current chain id in session reconnect.\n */\nexport async function getPersistedChainId(client: SignClient) {\n try {\n const chainId = (await client.core.storage.getItem(CHAIN_ID_STORAGE))\n ?.defaultChainId;\n return !!chainId ? String(chainId) : undefined;\n } catch {\n return undefined;\n }\n}\n", "import type { WCInstance } from './types.js';\nimport type { SignerFactory } from 'rango-types';\n\nimport { dynamicImportWithRefinedError } from '@rango-dev/wallets-shared';\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nexport default async function getSigners(\n instance: WCInstance\n): Promise<SignerFactory> {\n if (!instance.session) {\n throw new Error('Session is required for wallet connect signers.');\n }\n\n const signers = new DefaultSignerFactory();\n const EVMSigner = (\n await dynamicImportWithRefinedError(\n async () => await import('./signers/evm.js')\n )\n ).default;\n const SOLANASigner = (\n await dynamicImportWithRefinedError(\n async () => await import('./signers/solana.js')\n )\n ).default;\n\n signers.registerSigner(\n TxType.EVM,\n new EVMSigner(instance.client, instance.session)\n );\n signers.registerSigner(\n TxType.SOLANA,\n new SOLANASigner(instance.client, instance.session)\n );\n\n return signers;\n}\n"],
5
- "mappings": "8LAcA,OAAS,SAAAA,GAAO,SAASC,OAAgB,0BACzC,OAAS,YAAAC,GAAU,eAAAC,OAAmB,4BACtC,OAAOC,OAAY,6BACnB,OAAS,aAAAC,GAAW,WAAAC,OAAe,OACnC,OAAS,kBAAAC,OAAsB,cCb/B,OACE,0CAAAC,GACA,gBAAAC,EACA,YAAAC,OACK,4BCEM,IAAAC,EAAA,KAAmB,OAAA,CAAAC,EAAA,UACvB,YAAYC,EAAkC,CAerD,KAAO,UAAYC,EAAU,KAE7B,KAAO,WAAaA,EAAU,MAE9B,KAAO,eAAiBA,EAAU,UAElC,KAAO,SAAWC,EAAU,eApB1BA,EAAU,eAAeF,CAAM,EAC/BG,EAAW,UAAUH,CAAM,EAC3B,KAAK,OAAA,CACP,CAEA,MAAc,QAAS,CACrB,GAAI,OAAO,OAAW,IAAa,CACjC,KAAa,QAAA,oBAAyB,EACtC,IAAMI,EAAQ,SAAS,cAAc,WAAW,EAChD,SAAS,KAAK,sBAAsB,YAAaA,CAAK,EACtDC,EAAY,cAAc,EAAI,CAAA,CAElC,CASF,EDvBA,OAAS,aAAAC,EAAW,WAAAC,MAAe,OACnC,OAAS,kBAAAC,GAAgB,mBAAAC,OAAuB,cEChD,OAAS,YAAAC,GAAU,WAAAC,OAAe,4BAClC,OAAS,eAAAC,MAAmB,uBAC5B,OAAS,aAAAC,MAAiB,OAWnB,SAASC,EAAeC,EAAoB,CACjD,OAAOA,EAAO,QAAQ,OAAOA,EAAO,QAAQ,OAAO,OAAS,CAAC,CAC/D,CAFgBC,EAAAF,EAAA,kBAUhB,eAAsBG,GACpBF,EACAG,EAC0C,CAC1C,aAAMC,GACJJ,EAAO,KAAK,CACV,MAAOG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a,GACb,MAAO,UACP,gBANWjB,GAAeiB,CAAc,EAOxC,aAAc,GACd,aAAc,EAChB,GAZ6E",
4
+ "sourcesContent": ["import type { Environments, WCInstance } from './types.js';\nimport type {\n CanSwitchNetwork,\n Connect,\n Disconnect,\n GetInstance,\n Subscribe,\n SwitchNetwork,\n WalletConfig,\n WalletInfo,\n} from '@rango-dev/wallets-shared';\nimport type { ISignClient } from '@walletconnect/types';\nimport type { BlockchainMeta, SignerFactory } from 'rango-types';\n\nimport { debug, error as logError } from '@rango-dev/logging-core';\nimport { Networks, WalletTypes } from '@rango-dev/wallets-shared';\nimport Client from '@walletconnect/sign-client';\nimport { AccountId, ChainId } from 'caip';\nimport { evmBlockchains } from 'rango-types';\n\nimport {\n DEFAULT_APP_METADATA,\n DEFAULT_NETWORK,\n EthereumEvents,\n EthereumRPCMethods,\n NAMESPACES,\n RELAY_URL,\n} from './constants.js';\nimport {\n createModalInstance,\n filterEvmAccounts,\n simulateRequest,\n switchOrAddEvmChain,\n} from './helpers.js';\nimport {\n cleanupSingleSession,\n disconnectSessions,\n getAccountsFromEvent,\n getAccountsFromSession,\n getPersistedChainId,\n ignoreNamespaceMethods,\n persistCurrentChainId,\n tryConnect,\n updateSessionAccounts,\n} from './session.js';\nimport signer from './signer.js';\n\nconst WALLET = WalletTypes.WALLET_CONNECT_2;\n\nlet envs: Environments = {\n WC_PROJECT_ID: '',\n DISABLE_MODAL_AND_OPEN_LINK: undefined,\n};\n\nexport type { Environments };\n\nexport const init = (environments: Environments) => {\n envs = environments;\n\n createModalInstance(envs.WC_PROJECT_ID);\n};\n\nexport const config: WalletConfig = {\n type: WALLET,\n checkInstallation: false,\n isAsyncInstance: true,\n defaultNetwork: DEFAULT_NETWORK,\n isAsyncSwitchNetwork: true,\n};\n\nexport const getInstance: GetInstance = async (options) => {\n const { currentProvider, getState, meta } = options;\n\n /*\n * Create a new pair, if exists use the pair,\n * Or use the already created one.\n */\n let provider: ISignClient;\n if (!currentProvider) {\n if (!envs.WC_PROJECT_ID) {\n throw new Error(\n 'You need to set `WC_PROJECT_ID` in Wallet Connect provider.'\n );\n }\n provider = await Client.init({\n relayUrl: RELAY_URL,\n projectId: envs.WC_PROJECT_ID,\n metadata: DEFAULT_APP_METADATA,\n });\n } else {\n provider = currentProvider;\n }\n\n return {\n client: provider,\n session: null,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n request: async (params: any) =>\n simulateRequest(params, provider, meta, getState),\n };\n};\n\nexport const connect: Connect = async ({ instance, meta }) => {\n const { client } = instance as WCInstance;\n // Try to restore the session first, if couldn't, create a new session by showing a modal.\n const session = await tryConnect(client, { meta, envs });\n // Override the value (session).\n instance.session = session;\n const currentChainId = await getPersistedChainId(client);\n const accounts = getAccountsFromSession(session);\n return filterEvmAccounts(accounts, currentChainId);\n};\n\nexport const subscribe: Subscribe = ({\n instance,\n updateChainId,\n updateAccounts,\n disconnect,\n}) => {\n const { client } = instance as WCInstance;\n\n /**\n * Session events refrence:\n * https://docs.walletconnect.com/2.0/specs/clients/sign/session-events\n */\n\n // Listen to updating the session by adding a new chain, method, or event\n client.on('session_update', (args) => {\n const allAccounts = getAccountsFromEvent(args);\n allAccounts.forEach((accountsWithChain) => {\n updateAccounts(accountsWithChain.accounts, accountsWithChain.chainId);\n });\n });\n\n // Listen to events triggred by wallet. (e.g. accountsChanged and chainChanged)\n client.on('session_event', (args) => {\n if (args.params.event.name === EthereumEvents.ACCOUNTS_CHANGED) {\n const accounts = args.params.event.data.map((account: string) => {\n return new AccountId(account).address;\n });\n const chainId = ChainId.parse(args.params.chainId).reference;\n updateAccounts(accounts);\n updateChainId(chainId);\n } else if (args.params.event.name === EthereumEvents.CHAIN_CHANGED) {\n const chainId = args.params.event.data;\n updateChainId(chainId);\n void persistCurrentChainId(instance.client, chainId);\n } else {\n console.log('[WC2] session_event not supported', args.params.event);\n }\n });\n\n client.on('session_delete', async (event) => {\n console.log('[WC2] your wallet has requested to delete session.', event);\n void cleanupSingleSession(client, event.topic);\n disconnect();\n });\n};\n\nexport const switchNetwork: SwitchNetwork = async ({\n network,\n instance,\n meta,\n getState,\n updateChainId,\n}) => {\n const evm = evmBlockchains(meta);\n const chainId = evm.find((chain) => chain.name === network)?.chainId;\n if (!chainId) {\n const error = new Error(`There is no match for ${chainId}`);\n logError(error);\n throw error;\n }\n const chaindIdStr = new ChainId({\n namespace: NAMESPACES.ETHEREUM,\n reference: String(parseInt(chainId)),\n }).toString();\n\n const session = instance.session;\n const evmNamespace = session.namespaces[NAMESPACES.ETHEREUM];\n const authorizedChains = evmNamespace?.chains || [];\n const authorizedMethods = evmNamespace?.methods || [];\n\n if (\n authorizedMethods.includes(EthereumRPCMethods.SWITCH_CHAIN) &&\n !ignoreNamespaceMethods(instance)\n ) {\n const currentNetwork = getState?.().network || Networks.ETHEREUM;\n await updateSessionAccounts(instance, network, currentNetwork, meta);\n await switchOrAddEvmChain(meta, network, currentNetwork, instance);\n } else if (authorizedChains.includes(chaindIdStr)) {\n updateChainId(chainId);\n return;\n } else {\n const error = new Error(`Chain ${chainId} is not configured.`);\n logError(error);\n throw error;\n }\n};\n\n/**\n *\n * Note:\n * There is no straight-forward way to detect the wallet supports which blockchain,\n * So we send request to wallet and expect to be rejected on the wallet if it's not supported.\n *\n */\nexport const canSwitchNetworkTo: CanSwitchNetwork = () => true;\n\nexport const disconnect: Disconnect = async ({ instance }) => {\n const { client } = instance as WCInstance;\n\n if (client) {\n void disconnectSessions(client).catch((error) => debug(error));\n }\n};\n\nexport const getSigners: (provider: WCInstance) => Promise<SignerFactory> =\n signer;\n\nexport const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (\n allBlockChains\n) => {\n const evms = evmBlockchains(allBlockChains);\n return {\n name: 'WalletConnect',\n img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/walletconnect/icon.svg',\n installLink: '',\n color: '#b2dbff',\n supportedChains: evms,\n showOnMobile: true,\n mobileWallet: true,\n };\n};\n", "/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { WalletConnectModal as WalletConnectModalType } from './wc-types.js';\nimport type { WalletState } from '@rango-dev/wallets-shared';\nimport type { ProposalTypes } from '@walletconnect/types';\nimport type { BlockchainMeta } from 'rango-types';\n\nimport {\n convertEvmBlockchainMetaToEvmChainInfo,\n isEvmAddress,\n Networks,\n} from '@rango-dev/wallets-shared';\nimport { WalletConnectModal } from '@walletconnect/modal';\nimport { AccountId, ChainId } from 'caip';\nimport { evmBlockchains, isEvmBlockchain } from 'rango-types';\n\nimport {\n DEFAULT_ETHEREUM_EVENTS,\n DEFAULT_ETHEREUM_METHODS,\n DEFAULT_SOLANA_CHAIN_ID,\n EthereumRPCMethods,\n NAMESPACES,\n} from './constants.js';\nimport { getLastSession } from './session.js';\n\nlet web3Modal: WalletConnectModalType;\nexport function createModalInstance(projectId: string) {\n if (!web3Modal) {\n web3Modal = new WalletConnectModal({\n projectId,\n themeMode: 'light',\n themeVariables: {\n '--wcm-z-index': '999999999',\n },\n }) as unknown as WalletConnectModalType;\n }\n}\n\nexport function getModal(): WalletConnectModalType {\n return web3Modal;\n}\n\ntype FinalNamespaces = {\n [key in NAMESPACES]?: ProposalTypes.BaseRequiredNamespace;\n};\n\nexport function generateOptionalNamespace(\n meta: BlockchainMeta[]\n): FinalNamespaces | undefined {\n const evm = evmBlockchains(meta);\n const evmChains = evm.map((chain) => {\n return new ChainId({\n namespace: NAMESPACES.ETHEREUM,\n reference: String(parseInt(chain.chainId)),\n }).toString();\n });\n\n const namespaces: FinalNamespaces = {\n [NAMESPACES.ETHEREUM]: {\n methods: DEFAULT_ETHEREUM_METHODS,\n events: DEFAULT_ETHEREUM_EVENTS,\n chains: evmChains,\n },\n };\n return namespaces;\n}\n\nexport function solanaChainIdToNetworkName(chainId: string): string {\n return chainId === DEFAULT_SOLANA_CHAIN_ID ? Networks.SOLANA : chainId;\n}\n\n/**\n *\n * In `rango-preset` we are working with `window.ethereum.request()`,\n * this is an interceptor for some RPC methods (e.g. eth_chainId).\n *\n */\nexport async function simulateRequest(\n params: any,\n provider: any,\n meta: BlockchainMeta[],\n getState: () => WalletState\n) {\n if (params.method === 'eth_chainId') {\n const currentSession = getLastSession(provider);\n const standaloneChains = Object.values(currentSession.namespaces)\n .map((namespace) => namespace.chains)\n .flat() as string[];\n\n const network = getState().network;\n\n if (standaloneChains.length > 0) {\n const chainId = network\n ? getChainIdByNetworkName(network, meta)\n : undefined;\n\n if (chainId) {\n return chainId;\n }\n\n const firstIndex = 0;\n const firstChain = standaloneChains[firstIndex];\n const firstChainId = new ChainId(firstChain);\n return firstChainId.reference;\n }\n\n throw new Error(`Couldn't find any chain on namespace`);\n }\n throw new Error('Dissallowed method:', params);\n}\n\nexport function getChainIdByNetworkName(\n network: string,\n meta: BlockchainMeta[]\n): string | undefined {\n const targetBlockchain = meta.find(\n (blockchain) => blockchain.name === network\n );\n const chainIdInHex = targetBlockchain?.chainId;\n if (!chainIdInHex) {\n return undefined;\n }\n\n const chainId = String(parseInt(chainIdInHex));\n\n return chainId;\n}\n\nexport async function switchOrAddEvmChain(\n meta: BlockchainMeta[],\n requestedNetwork: string,\n currentNetwork: string,\n instance: any\n) {\n const evmBlockchains = meta.filter(isEvmBlockchain);\n const evmNetworksChainInfo =\n convertEvmBlockchainMetaToEvmChainInfo(evmBlockchains);\n const targetChain = evmNetworksChainInfo[requestedNetwork];\n const targetBlockchain = meta.find(\n (blockchain: BlockchainMeta) => blockchain.name === requestedNetwork\n );\n const chainIdInHex = targetBlockchain?.chainId;\n\n const currentChainId = getChainIdByNetworkName(currentNetwork, meta);\n const currentChainEip = ChainId.format({\n namespace: NAMESPACES.ETHEREUM,\n reference: String(currentChainId),\n });\n\n const session = instance.session;\n\n try {\n await instance.client.request({\n topic: session.topic,\n request: {\n method: EthereumRPCMethods.SWITCH_CHAIN,\n params: [\n {\n chainId: chainIdInHex,\n },\n ],\n },\n // It's required to pass current chain, otherwise it won't work\n chainId: currentChainEip,\n });\n } catch (err: any) {\n const addChainError = 4902;\n if (\n err?.code === addChainError ||\n err?.message?.includes(String(addChainError))\n ) {\n await instance.client.request({\n topic: session.topic,\n request: {\n method: EthereumRPCMethods.ADD_CHAIN,\n params: [targetChain],\n },\n // It's required to pass current chain, otherwise it won't work\n chainId: currentChainEip,\n });\n } else {\n throw err;\n }\n }\n}\n\nexport function getCurrentEvmAccountAddress(instance: any) {\n return instance.session.namespaces.eip155.accounts\n ?.map((account: string) => {\n return new AccountId(account).address;\n })\n ?.filter((address: string) => isEvmAddress(address))?.[0];\n}\n\nexport function getEvmAccount(\n network: string,\n address: string,\n meta: BlockchainMeta[]\n) {\n const currentChainId = getChainIdByNetworkName(network, meta);\n return AccountId.format({\n chainId: {\n namespace: NAMESPACES.ETHEREUM,\n reference: String(currentChainId),\n },\n address,\n });\n}\n\n// It's enough to return only connected network for the EVM networks and ignore others\nexport function filterEvmAccounts(\n accounts: {\n address: string;\n chainId: string;\n }[],\n currentChainId?: string\n) {\n let firstEvmAddress = false;\n return accounts\n .filter(({ address, chainId }) => {\n const isEvm = isEvmAddress(address);\n if (isEvm) {\n if (currentChainId && chainId !== currentChainId) {\n return false;\n }\n if (!currentChainId) {\n if (firstEvmAddress) {\n return false;\n }\n firstEvmAddress = true;\n }\n }\n return true;\n })\n .map(({ address, chainId }) => ({\n accounts: [address],\n chainId: chainId,\n }));\n}\n", "import type { ConfigCtrlState, ThemeCtrlState } from '@walletconnect/modal-core'\nimport { ConfigCtrl, ModalCtrl, OptionsCtrl, ThemeCtrl } from '@walletconnect/modal-core'\n\n/**\n * Types\n */\nexport type WalletConnectModalConfig = ConfigCtrlState & ThemeCtrlState\n\n/**\n * Client\n */\nexport class WalletConnectModal {\n public constructor(config: WalletConnectModalConfig) {\n ThemeCtrl.setThemeConfig(config)\n ConfigCtrl.setConfig(config)\n this.initUi()\n }\n\n private async initUi() {\n if (typeof window !== 'undefined') {\n await import('@walletconnect/modal-ui')\n const modal = document.createElement('wcm-modal')\n document.body.insertAdjacentElement('beforeend', modal)\n OptionsCtrl.setIsUiLoaded(true)\n }\n }\n\n public openModal = ModalCtrl.open\n\n public closeModal = ModalCtrl.close\n\n public subscribeModal = ModalCtrl.subscribe\n\n public setTheme = ThemeCtrl.setThemeConfig\n}\n", "import type {\n ConnectParams,\n CreateSessionParams,\n Environments,\n} from './types.js';\nimport type { SignClient } from '@walletconnect/sign-client/dist/types/client';\nimport type {\n PairingTypes,\n SessionTypes,\n SignClientTypes,\n} from '@walletconnect/types';\nimport type { BlockchainMeta } from 'rango-types';\n\nimport { Networks, timeout } from '@rango-dev/wallets-shared';\nimport { getSdkError } from '@walletconnect/utils';\nimport { AccountId } from 'caip';\n\nimport { CHAIN_ID_STORAGE, PING_TIMEOUT } from './constants.js';\nimport {\n generateOptionalNamespace,\n getCurrentEvmAccountAddress,\n getEvmAccount,\n getModal,\n solanaChainIdToNetworkName,\n} from './helpers.js';\n\nexport function getLastSession(client: SignClient) {\n return client.session.values[client.session.values.length - 1];\n}\n\n/**\n *\n * Try to ping the wallet, if wallet responded with `pong`, session is a valid and we will use the session.\n * If the wallet didn't respond during 10 seconds (PING_TIME), we assume the wallet isn't available and we need to create a new session.\n *\n */\nexport async function restoreSession(\n client: SignClient,\n pairingTopic: PairingTypes.Struct['topic']\n): Promise<SessionTypes.Struct | undefined> {\n await timeout(\n client.ping({\n topic: pairingTopic,\n }),\n PING_TIMEOUT\n );\n\n // We assume last session is the correct session, beacuse we are doing clean up and keeps only one pairing/session.\n const session = getLastSession(client);\n return session;\n}\n\n/**\n *\n * Getting a pair of required and optional namespaces then tries to show a modal and connect (pair)\n * To the wallet.\n * @param client\n * @param options\n * @returns\n */\nexport async function createSession(\n client: SignClient,\n options: CreateSessionParams,\n configs: {\n envs: Environments;\n }\n): Promise<SessionTypes.Struct> {\n const { requiredNamespaces, optionalNamespaces, pairingTopic } = options;\n\n try {\n const { uri, approval } = await client.connect({\n requiredNamespaces,\n optionalNamespaces,\n pairingTopic,\n });\n\n // Open QRCode modal if a URI was returned (i.e. we're not connecting an existing pairing).\n let onCloseModal;\n if (uri) {\n /*\n * There are some wallets have been listed in WC itself (https://docs.walletconnect.com/cloud/explorer-submission),\n * Using `DISABLE_MODAL_AND_OPEN_LINK` option, we can directly open a specific desktop wallet.\n */\n const redirectLink = configs.envs.DISABLE_MODAL_AND_OPEN_LINK;\n if (redirectLink) {\n const url = `${redirectLink}/wc?uri=${encodeURIComponent(uri)}`;\n window.open(url, '_blank', 'noreferrer noopener');\n } else {\n // Create a flat array of all requested chains across namespaces.\n const allNamespaces = {\n ...(requiredNamespaces || {}),\n ...(optionalNamespaces || {}),\n };\n\n const standaloneChains = Object.values(allNamespaces)\n .map((namespace) => namespace.chains)\n .flat() as string[];\n\n const modal = getModal();\n void modal.openModal({ uri, chains: standaloneChains });\n\n onCloseModal = new Promise((_, reject) => {\n modal.subscribeModal((state) => {\n // the modal was closed so reject the promise\n if (!state.open) {\n reject(new Error('Modal has been closed.'));\n }\n });\n });\n }\n }\n\n const session = approval();\n\n if (onCloseModal) {\n const result = await Promise.race([session, onCloseModal]);\n // We know onClose only reject a modal and never returns a value.\n return result as SessionTypes.Struct;\n }\n return await session;\n } finally {\n getModal().closeModal();\n }\n}\n\n/**\n *\n * A user (client) can have multiple pairings (to different wallets), we are assuming\n * the last pairing is the active pairing for now. A better UX can be showing a list of pairings\n * and let the user to choose the right pairing manually. Because we don't have that yet, we will pick up the last one.\n *\n */\nexport function tryGetPairing(\n client: SignClient\n): PairingTypes.Struct | undefined {\n const pairings = client.pairing.getAll({ active: true });\n const lastPairing =\n pairings.length > 0 ? pairings[pairings.length - 1] : undefined;\n\n return lastPairing;\n}\n\n/**\n *\n * Try to restore the session first, if couldn't, create a new session by showing a modal.\n *\n */\nexport async function tryConnect(\n client: SignClient,\n params: ConnectParams\n): Promise<SessionTypes.Struct> {\n const { meta } = params;\n\n // We try to get all of our supported chains as optional.\n const optionalNamespaces = generateOptionalNamespace(meta);\n\n // Check if the user has a session, if yes, restore the session and use it.\n let session: SessionTypes.Struct | undefined;\n const pairing = tryGetPairing(client);\n if (pairing) {\n try {\n session = await restoreSession(client, pairing.topic);\n } catch {\n await disconnectSessions(client);\n }\n }\n\n // In case of connecting for the first time or session couldn't be restored, we will create a new session.\n if (!session) {\n session = await createSession(\n client,\n {\n requiredNamespaces: {},\n optionalNamespaces,\n },\n {\n envs: params.envs,\n }\n );\n }\n\n return session;\n}\n\n/**\n *\n * Try to find sessions with a topic id and expire them.\n *\n */\nexport async function cleanupSingleSession(client: SignClient, topic: string) {\n const sessions = client.session.getAll();\n const pairings = client.pairing.getAll();\n\n sessions.forEach((session) => {\n if (session.topic === topic || session.pairingTopic === topic) {\n const requestForDeleteTopic =\n session.pairingTopic === topic ? session.pairingTopic : session.topic;\n client.core.expirer.set(requestForDeleteTopic, 0);\n }\n });\n\n pairings.forEach((pairing) => {\n if (pairing.topic === topic) {\n client.core.expirer.set(topic, 0);\n }\n });\n}\n\n/**\n *\n * Disconnect means to delete the session on both parties (dApp & wallet) at the same time.\n *\n */\nexport async function disconnectSessions(client: SignClient) {\n const allPromises = [];\n\n const sessions = client.session.getAll();\n for (const session of sessions) {\n allPromises.push(\n client.disconnect({\n topic: session.topic,\n reason: getSdkError('USER_DISCONNECTED'),\n })\n );\n }\n\n const pairings = client.pairing.getAll();\n for (const pairing of pairings) {\n allPromises.push(\n client.disconnect({\n topic: pairing.topic,\n reason: getSdkError('USER_DISCONNECTED'),\n })\n );\n }\n\n // reset the current chain id\n void persistCurrentChainId(client, undefined);\n\n return await Promise.all(allPromises);\n}\n\nexport function getAccountsFromSession(session: SessionTypes.Struct) {\n const accounts = Object.values(session.namespaces)\n .map((namespace) => namespace.accounts)\n .flat()\n .map((account) => {\n const { address, chainId } = new AccountId(account);\n /*\n * Note: Solana has a specific ID, we need to convert it back to network name.\n * It will return the chain id itslef if it's not that specific ID.\n */\n const chain = solanaChainIdToNetworkName(chainId.reference);\n return {\n address,\n chainId: chain,\n };\n });\n return accounts;\n}\n\nexport function getAccountsFromEvent(\n event: SignClientTypes.BaseEventArgs<{\n namespaces: SessionTypes.Namespaces;\n }>\n) {\n const accounts = Object.values(event.params.namespaces)\n .map((namespace) => namespace.accounts)\n .flat()\n .map((account) => {\n const { address, chainId } = new AccountId(account);\n return {\n accounts: [address],\n chainId:\n chainId.namespace === 'solana' ? Networks.SOLANA : chainId.reference,\n };\n });\n\n return accounts;\n}\n\n/*\n * Before switch network, we need to update session namespace accounts\n * to contain both current chain and target chain accoutns.\n */\nexport async function updateSessionAccounts(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n instance: any,\n requestedNetwork: string,\n currentNetwork: string,\n meta: BlockchainMeta[]\n) {\n const session = instance.session;\n\n const namespaces = session.namespaces;\n let needUpdateNamepspace = false;\n const accounts = namespaces.eip155.accounts;\n\n const currentAccountAddress = getCurrentEvmAccountAddress(instance);\n const requestedAccount = getEvmAccount(\n requestedNetwork,\n currentAccountAddress,\n meta\n );\n if (!accounts.includes(requestedAccount)) {\n accounts.push(requestedAccount);\n needUpdateNamepspace = true;\n }\n\n const currentAccount = getEvmAccount(\n currentNetwork,\n currentAccountAddress,\n meta\n );\n if (!accounts.includes(currentAccount)) {\n accounts.push(currentAccount);\n needUpdateNamepspace = true;\n }\n\n if (needUpdateNamepspace) {\n const updatedNamespaces = {\n ...namespaces,\n eip155: {\n ...namespaces.eip155,\n accounts,\n },\n };\n await instance.client.session\n .update({\n topic: session.topic,\n namespaces: updatedNamespaces,\n })\n .catch((err: unknown) => {\n console.log(err);\n });\n }\n}\n\n/*\n * Certain wallets, such as Trust Wallet and 1inch, are providing incorrect methods in\n * response to session proposal requests. These wallets do not support certain optional\n * RPC methods like \"wallet_xyz,\" but they include them in the response under the session namespace.\n * For the time being, we should avoid their session namespace response.\n * see also: https://github.com/trustwallet/wallet-core/issues/3588\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function ignoreNamespaceMethods(instance: any): boolean {\n const WALLETS_WITH_WRONG_NAMESPACE_METHODS = ['trust', '1inch'];\n const peerName = instance?.session?.peer?.metadata?.name;\n return WALLETS_WITH_WRONG_NAMESPACE_METHODS.some((name) =>\n peerName?.toLowerCase()?.includes(name)\n );\n}\n\nexport async function persistCurrentChainId(\n client: SignClient,\n chainId?: string\n) {\n return client.core.storage.setItem(CHAIN_ID_STORAGE, {\n defaultChainId: chainId ? parseInt(chainId) : '',\n });\n}\n\n/*\n * get the latest chain id from the storage,\n * used for setting current chain id in session reconnect.\n */\nexport async function getPersistedChainId(client: SignClient) {\n try {\n const chainId = (await client.core.storage.getItem(CHAIN_ID_STORAGE))\n ?.defaultChainId;\n return !!chainId ? String(chainId) : undefined;\n } catch {\n return undefined;\n }\n}\n", "import type { WCInstance } from './types.js';\nimport type { SignerFactory } from 'rango-types';\n\nimport { dynamicImportWithRefinedError } from '@rango-dev/wallets-shared';\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nexport default async function getSigners(\n instance: WCInstance\n): Promise<SignerFactory> {\n if (!instance.session) {\n throw new Error('Session is required for wallet connect signers.');\n }\n\n const signers = new DefaultSignerFactory();\n const EVMSigner = (\n await dynamicImportWithRefinedError(\n async () => await import('./signers/evm.js')\n )\n ).default;\n const SOLANASigner = (\n await dynamicImportWithRefinedError(\n async () => await import('./signers/solana.js')\n )\n ).default;\n\n signers.registerSigner(\n TxType.EVM,\n new EVMSigner(instance.client, instance.session)\n );\n signers.registerSigner(\n TxType.SOLANA,\n new SOLANASigner(instance.client, instance.session)\n );\n\n return signers;\n}\n"],
5
+ "mappings": "8LAcA,OAAS,SAAAA,GAAO,SAASC,OAAgB,0BACzC,OAAS,YAAAC,GAAU,eAAAC,OAAmB,4BACtC,OAAOC,OAAY,6BACnB,OAAS,aAAAC,GAAW,WAAAC,OAAe,OACnC,OAAS,kBAAAC,OAAsB,cCZ/B,OACE,0CAAAC,GACA,gBAAAC,EACA,YAAAC,OACK,4BCCM,IAAAC,EAAA,KAAmB,OAAA,CAAAC,EAAA,UACvB,YAAYC,EAAkC,CAerD,KAAO,UAAYC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D,GAAc,QAAU,CAAC,EAGlD,IAF0BA,GAAc,SAAW,CAAC,GAGhC,qCAAwC,GAC1D,CAACE,EAAuBhC,CAAQ,EAChC,CACA,IAAMiC,EAAiB1C,IAAW,EAAE,SAAW2C,GAAS,SACxD,MAAMC,EAAsBnC,EAAUwB,EAASS,EAAgBzC,CAAI,EACnE,MAAM4C,GAAoB5C,EAAMgC,EAASS,EAAgBjC,CAAQ,CACnE,SAAW+B,EAAiB,SAASF,CAAW,EAAG,CACjDnB,EAAcQ,CAAO,EACrB,MACF,KAAO,CACL,IAAMS,EAAQ,IAAI,MAAM,SAAST,CAAO,qBAAqB,EAC7D,MAAAU,GAASD,CAAK,EACRA,CACR,CACF,EAvC4C,iBAgD/BU,GAAuCtD,EAAA,IAAM,GAAN,sBAEvC6B,GAAyB7B,EAAA,MAAO,CAAE,SAAAiB,CAAS,IAAM,CAC5D,GAAM,CAAE,OAAAC,CAAO,EAAID,EAEfC,GACGqC,EAAmBrC,CAAM,EAAE,MAAO0B,GAAUY,GAAMZ,CAAK,CAAC,CAEjE,EANsC,cAQzBa,GACXA,EAEWC,GAAkE1D,EAC7E2D,IAGO,CACL,KAAM,gBACN,IAAK,8FACL,YAAa,GACb,MAAO,UACP,gBANWjB,GAAeiB,CAAc,EAOxC,aAAc,GACd,aAAc,EAChB,GAZ6E",
6
6
  "names": ["debug", "logError", "Networks", "WalletTypes", "Client", "AccountId", "ChainId", "evmBlockchains", "convertEvmBlockchainMetaToEvmChainInfo", "isEvmAddress", "Networks", "WalletConnectModal", "__name", "config", "ModalCtrl", "ThemeCtrl", "ConfigCtrl", "modal", "OptionsCtrl", "AccountId", "ChainId", "evmBlockchains", "isEvmBlockchain", "Networks", "timeout", "getSdkError", "AccountId", "getLastSession", "client", "__name", "restoreSession", "pairingTopic", "timeout", "PING_TIMEOUT", "createSession", "options", "configs", "requiredNamespaces", "optionalNamespaces", "uri", "approval", "onCloseModal", "redirectLink", "url", "allNamespaces", "standaloneChains", "namespace", "modal", "getModal", "_", "reject", "state", "session", "tryGetPairing", "pairings", "tryConnect", "params", "meta", "generateOptionalNamespace", "pairing", "disconnectSessions", "cleanupSingleSession", "topic", "sessions", "requestForDeleteTopic", "allPromises", "getSdkError", "persistCurrentChainId", "getAccountsFromSession", "account", "address", "chainId", "AccountId", "chain", "solanaChainIdToNetworkName", "getAccountsFromEvent", "event", "Networks", "updateSessionAccounts", "instance", "requestedNetwork", "currentNetwork", "namespaces", "needUpdateNamepspace", "accounts", "currentAccountAddress", "getCurrentEvmAccountAddress", "requestedAccount", "getEvmAccount", "currentAccount", "updatedNamespaces", "err", "ignoreNamespaceMethods", "WALLETS_WITH_WRONG_NAMESPACE_METHODS", "peerName", "name", "CHAIN_ID_STORAGE", "getPersistedChainId", "web3Modal", "createModalInstance", "projectId", "d", "__name", "getModal", "generateOptionalNamespace", "meta", "evmChains", "evmBlockchains", "chain", "ChainId", "DEFAULT_ETHEREUM_METHODS", "DEFAULT_ETHEREUM_EVENTS", "solanaChainIdToNetworkName", "chainId", "DEFAULT_SOLANA_CHAIN_ID", "Networks", "simulateRequest", "params", "provider", "getState", "currentSession", "getLastSession", "standaloneChains", "namespace", "network", "getChainIdByNetworkName", "firstChain", "chainIdInHex", "blockchain", "switchOrAddEvmChain", "requestedNetwork", "currentNetwork", "instance", "isEvmBlockchain", "targetChain", "convertEvmBlockchainMetaToEvmChainInfo", "currentChainId", "currentChainEip", "session", "err", "getCurrentEvmAccountAddress", "account", "AccountId", "address", "isEvmAddress", "getEvmAccount", "filterEvmAccounts", "accounts", "firstEvmAddress", "dynamicImportWithRefinedError", "DefaultSignerFactory", "TxType", "getSigners", "instance", "signers", "DefaultSignerFactory", "EVMSigner", "dynamicImportWithRefinedError", "SOLANASigner", "TxType", "__name", "WALLET", "WalletTypes", "envs", "init", "__name", "environments", "createModalInstance", "config", "DEFAULT_NETWORK", "getInstance", "options", "currentProvider", "getState", "meta", "provider", "Client", "RELAY_URL", "DEFAULT_APP_METADATA", "params", "simulateRequest", "connect", "instance", "client", "session", "tryConnect", "currentChainId", "getPersistedChainId", "accounts", "getAccountsFromSession", "filterEvmAccounts", "subscribe", "updateChainId", "updateAccounts", "disconnect", "args", "getAccountsFromEvent", "accountsWithChain", "account", "AccountId", "chainId", "ChainId", "persistCurrentChainId", "event", "cleanupSingleSession", "switchNetwork", "network", "evmBlockchains", "chain", "error", "logError", "chaindIdStr", "evmNamespace", "authorizedChains", "ignoreNamespaceMethods", "currentNetwork", "Networks", "updateSessionAccounts", "switchOrAddEvmChain", "canSwitchNetworkTo", "disconnectSessions", "debug", "getSigners", "getWalletInfo", "allBlockChains"]
7
7
  }