WalletConnect / walletconnect-monorepo

WalletConnect Monorepo
Apache License 2.0
1.46k stars 714 forks source link

Specifying required chainIds doesn't seem to work properly #3427

Open glitch-txs opened 1 year ago

glitch-txs commented 1 year ago

Discussed in https://github.com/orgs/WalletConnect/discussions/3426

Originally posted by **gonzamontiel** August 10, 2023 **Context** We followed [this guidelines](https://docs.walletconnect.com/2.0/web3modal/polkadot/dapp-integration-guide) to integrate to our Polkadot Dapp. We are trying to filter the wallet connection only to wallets that support polkadot. For this reason we are specifying the following inside the connection params: ``` requiredNamespaces: { polkadot: { methods: ['polkadot_signTransaction', 'polkadot_signMessage'], events: ['chainChanged', 'accountsChanged'], chains: [polkadot: 'polkadot:91b171bb158e2d3848fa23a9f1c25182'], }, }, ``` **Problem** When testing this setup, I tried a connection with LOBSTR wallet (stellar network), expecting to catch some kind of error. To my surprise, no exception was thrown, but some errors were being logged in console.error. The problem is that SignClient.connect(), which returns an approval() function, is not failing, and it is returning an actual session with a 'valid' account. I put quotes because the account received has this shape: `"polkadot:91b171bb158e2d3848fa23a9f1c25182:GDDRSQK7ZITHZJZQJMTP4BHSJRZRO6GMMG6HUOOUICO7ZXX764LRQATY"` Which makes no sense to me, since GD...ATY is not a valid polkadot address, but stellar's. As I said, an error is thrown making evident that this is indeed an invalid connection request and should be rejected. The error is as follows: ![Screenshot from 2023-08-10 14 44 20](https://github.com/WalletConnect/walletconnect-monorepo/assets/4713407/5a6acd23-4994-4076-821b-0676b37485da) I would expect that that the approval() function returned by SignClient.connect() ([this one](https://github.com/WalletConnect/walletconnect-monorepo/blob/fa8a19afe62ae0cd167792b2bd1e7075f19a7d30/packages/sign-client/src/controllers/engine.ts#L116) ?) fails or returns an invalid session, but I couldn't find indicators that the session is not valid. What I'm missing? Session object loos as follows: ``` { "topic": "13828738d345999e488f43843b8604eb6204c00ed45acc3361052f42d68f030e", "relay": { "protocol": "irn" }, "expiry": 1692263927, "namespaces": { "polkadot": { "chains": [ "polkadot:91b171bb158e2d3848fa23a9f1c25182" ], "accounts": [ "polkadot:91b171bb158e2d3848fa23a9f1c25182:GDDRSQK7ZITHZJZQJMTP4BHSJRZRO6GMMG6HUOOUICO7ZXX764LRQATY" ], "methods": [ "polkadot_signTransaction", "polkadot_signMessage" ], "events": [ "chainChanged", "accountsChanged" ] } }, "acknowledged": true, "controller": "8c71c003883e2655ae3a37ddc36a8cee6c7d400c637f5270221ed6658f521a65", "self": { "publicKey": "44b61423bbf32150db522d1c515acacb9c232528b0006018a272a923b1b7dc6f", "metadata": { "description": "", "url": "http://localhost:5173", "icons": [ "http://localhost:5173/favicon.png" ], "name": "Pendulum Chain Portal" } }, "peer": { "publicKey": "8c71c003883e2655ae3a37ddc36a8cee6c7d400c637f5270221ed6658f521a65", "metadata": { "name": "LOBSTR", "description": "OPPO CPH2197, Android 13", "url": "https://lobstr.co", "icons": [ "https://static.lobstr.co/media/lobstr-icon.svg" ], "redirect": { "native": "kotlin-wallet-wc:/request" } } } } ``` **Note** This topic is a followup of [this discussion](https://github.com/orgs/WalletConnect/discussions/3282#discussioncomment-6561740).
VadimSaveljev commented 1 year ago

Not sure if this will help, but part of what you specify for connection params chains: [polkadot: 'polkadot:91b171bb158e2d3848fa23a9f1c25182'], should look like this chains: ['polkadot:91b171bb158e2d3848fa23a9f1c25182'],

gonzamontiel commented 1 year ago

Not sure if this will help, but part of what you specify for connection params chains: [polkadot: 'polkadot:91b171bb158e2d3848fa23a9f1c25182'], should look like this chains: ['polkadot:91b171bb158e2d3848fa23a9f1c25182'],

Oops sorry, my bad, I manually changed the parameters in the example for illustrating the post, bc we are building the object programmatically. But we are passing the right value, thanks.

gonzamontiel commented 1 year ago

Hi, any news on this ? Could you guys take a look @glitch-txs ?

glitch-txs commented 1 year ago

Hi could you share a MRE?

gonzamontiel commented 1 year ago

Hi, sorry my late response. While not exactly an MRE, our current code is not that hard to follow. The configuration that we use is here. We instantiate the client here and we grab the addresses from the response here.

This code can be tested here, if you click in "Connect Wallet", and then the Wallet Connect option. You'll need a way to connect to a non-polkadot wallet (I used LOBSTR to try it out). I specifically added a log with the session information returned.

Thanks in advance!