polkadot-js / extension

Simple browser extension for managing Polkadot and Substrate network accounts in a browser. Allows the signing of extrinsics using these accounts. Also provides a simple interface for compliant extensions for dapps.
Apache License 2.0
968 stars 405 forks source link

Uncaught Error: Expected a valid key to convert, with length 1, 2, 4, 8, 32, 33 #1250

Closed ltfschoen closed 5 months ago

ltfschoen commented 1 year ago

If I go to https://app.zeitgeist.pm/, using the latest Polkadot.js Extension version 0.44.1, and using the latest Brave browser version 1.50.119 Chromium: 112.0.5615.121 (Official Build) (x86_64).

It displays the following error in the DevTools console:

Screen Shot 2023-04-16 at 9 54 59 am

Clicking the error messages shows that it's related to the Polkadot.js Extension

Screen Shot 2023-04-16 at 10 01 49 am Screen Shot 2023-04-16 at 10 02 01 am

So if i try clicking "Connect" and selecting "Polkadot.js Extension" to connect my wallet it doesn't work. In the past I have been able to connect my wallet this way without any issues.

Note that I have authorised the website to connect to Polkadot.js Extension already:

Screen Shot 2023-04-16 at 10 16 12 am

Additionally, if i go to https://singular.app/, using the same version of Polkadot.js Extension and Brave version.

It displays the following error in the DevTools console:

Screen Shot 2023-04-16 at 9 48 25 am

Clicking the error messages shows that it's related to the Polkadot.js Extension

Screen Shot 2023-04-16 at 10 03 28 am Screen Shot 2023-04-16 at 10 03 17 am

Then when I click to "Connect" and choose "Select account" to choose a wallet using the Polkadot.js Extension, it then shows a modal indicating that I don't have any accounts, even though I do. In the past I have been able to connect my wallet this way without any issues.

Screen Shot 2023-04-16 at 9 48 39 am

I'm an end-user of these Substrate-based chains. Seeing a similar error across more than one of them made report it here incase its a bug report or support request that could help more than one chain.

jacogr commented 1 year ago

Does it inject and display the accounts on the apps UI? (There are additional filters that dapps need to apply for Ethereum-like accounts - the extension only supplies the accounts, the dapp needs to filter based on chain type)

jacogr commented 1 year ago

Verified - it is related to the actual dapps, not the extension. Can re-create the issue on the specified dapps with Ethereum accounts.

I would suggest raising the issue there - there is nothing the extension can do, it supplies all accounts to the apps (unless there is a genesis specified by the dapp, in that case it would filter to the accounts for the specific genesisHash). So it sits purely in the account handling code for the dapps.

ltfschoen commented 1 year ago

Does it inject and display the accounts on the apps UI? (There are additional filters that dapps need to apply for Ethereum-like accounts - the extension only supplies the accounts, the dapp needs to filter based on chain type)

yes for example with Zeitgeist it already shows all my balances successfully in the apps UI. however i did notice that i hadn't updated my metadata

Screen Shot 2023-04-16 at 5 33 17 pm

so i did that as shown below, but it still showed the same error in the Zeitgeist and RMRK dapps

Screen Shot 2023-04-16 at 5 33 53 pm
jacogr commented 1 year ago

Like I said above - it is in the account handling for the specific dapps. You need to log the issue there. (Ethereum-accounts are non-32-bytes in length, so when injected by the extension it cannot be handled by them)

ltfschoen commented 5 months ago

So I just checked and https://singular.app have fixed the error. I still get the error with Zeitgeist, and I published this issue on Polkaverse here https://polkaverse.com/@luke/polkadot-d-app-errors-when-handling-accounts-supplied-by-the-47114 and Dynatle solved the same error message Error: Expected a valid key to convert, with length 1, 2, 4, 8, 32, 33 in Polkaverse dApp here https://github.com/dappforce/polkaverse/pull/210/files#diff-ca62a13994aae3c545ad2d796d272f3ee8c0ab33b83bb3d5c023dc553b55f984R14, where they said the main issue was that before they convert the address directly, they were parsing it using formatBalance from polkadot js, which throws an error if the address is not valid. It can be invalid if the user connects using maybe talisman, and connect all of his accounts, including their EVM wallets. So the solution was to wrap it in try/catch.

Tbaut commented 5 months ago

Note that the pjs exension also allows EVM accounts when imported through json afair. The solution is indeed on the dapp side, and is actually not related to the extension, but rather the functions such as encodeAddress or decodeAddress from @polkadot/util-crypto that must be wrapped into a try/catch.

polkadot-js-bot commented 5 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.