Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MetaMask does not show signature request if open when 'eth_signTypedData' request is sent #4821

Closed
alex-ppg opened this issue Jul 18, 2018 · 9 comments

Comments

@alex-ppg
Copy link

alex-ppg commented Jul 18, 2018

This is quite a crucial issue with user interaction as we cannot reasonably expect a user, after unlocking his account, to close and re-open the MetaMask plugin screen.

  • Expected Behavior: Whilst the MetaMask plugin screen is open, either the page itself transitions to the signature request or the signature request pop-up shows.
  • Actual Behavior: If MetaMask is open when the request is sent, the request does not show unless I close and re-open the MetaMask screen.
  • Browser Used: Google Chrome although I believe this is irrelevant.
  • Operating System Used: Windows 10 but likewise irrelevant.

Code Example (Ensure your account is locked):

const msgParams = [
    {
        type: 'string',
        name: 'Authorization Request',
        value: 'test'
    }
];
if (typeof window.web3 !== 'undefined' && typeof window.web3.currentProvider !== 'undefined') {
    let localWeb3 = new Web3(window.web3.currentProvider);
    window.web3.eth.getAccounts((err, accounts) => {
        if (!accounts[0]) {
            watchAccountUnlock();
        } else {
            localWeb3.eth.defaultAccount = accounts[0];
            requestSignature();
        }
    });
}

function watchAccountUnlock() {
    const toClear = setInterval(() => {
       window.web3.eth.getAccounts((err, accounts) => {
            if (accounts[0] !== localWeb3.eth.defaultAccount) {
                localWeb3.eth.defaultAccount = accounts[0];
                requestSignature();
                clearInterval(toClear);
            }
        });
    },500);
}

function requestSignature() {
    localWeb3.currentProvider.sendAsync({
      method: 'eth_signTypedData',
      params: [msgParams, localWeb3.eth.defaultAccount],
      from: localWeb3.eth.defaultAccount,
    }, (err, result) => {
      if (err) return console.error(err)
      if (result.error) {
        // User denied signature
      }
      const signature = result.result;
      alert(signature);
    });
}
@bdresser
Copy link
Contributor

@alex-ppg a simple workaround might be to have the user click a UI element to prompt the signing request, rather than trying to fire it automatically on login.

curious what your usecase is – if you're trying to create a sort of log-in behavior, make sure you've checked out this web3 opt-in feature that we'll be rolling out shortly.

@danfinlay @bitpshr any other thoughts?

@alex-ppg
Copy link
Author

@bdresser While what I am trying to do is create a sort of log-in behavior, it doesn't exactly work in the same way most DApps do.

We are creating a multi-currency front-end wallet that derives the various keys from a seed and in order to support MetaMask, we want the user to sign a randomly generated (once) and server-side stored string, using the resulting signature as the seed for the various currencies.

We are going to allow the user to use their Ethereum based wallet directly via MetaMask obviously but we need the signature for the rest of the currencies.

@danfinlay
Copy link
Contributor

This does sound like a bug that we should fix.

Please be aware @alex-ppg that our current signTypedData implementation is not the final one, and we may need to break the current method definition (or add a new method name for the actual spec version) soon: #4803

@bdresser bdresser added the area-UI Relating to the user interface. label Jul 23, 2018
@bdresser bdresser added this to the Sprint 08 [7.23 - 8.3] milestone Jul 23, 2018
@bdresser
Copy link
Contributor

@bitpshr might have to do with the logic around the popup ID #4592

@joenhon
Copy link

joenhon commented Aug 2, 2018

Excuse me, how do you call MetaMask, is it convenient to call the code to give me a copy?

@alex-ppg
Copy link
Author

alex-ppg commented Aug 5, 2018

Hey @joenhon, sorry for the late response I've been abroad. I recreated the problem in the following Gist: https://gist.github.com/alex-ppg/86ddf1bd997e016aef95f46b8497d7b7

I am developing the application using Angular but the problem seems to be related to the MetaMask plugin API rather than any of the technology stacks as showcased by the Gist which is a simple HTML webpage.

I have also tried delaying the signature request for a while but the issue is that the MetaMask pop-up is kept open after unlocking. If I close the MetaMask plugin page before the signature request occurs, the pop-up will show just fine.

@bdresser bdresser modified the milestones: Sprint 08 [7.23 - 8.3], Sprint 09 [8.6 - 8.17] Aug 6, 2018
@bdresser bdresser modified the milestones: Sprint 09 [8.6 - 8.17], Sprint 10 [8.20 - 8.31] Aug 20, 2018
@bdresser bdresser removed this from the Sprint 10 [8.20 - 8.31] milestone Apr 1, 2019
@Gudahtt
Copy link
Member

Gudahtt commented Jul 28, 2020

Thanks for the report @alex-ppg ! Are you still experiencing this problem with the latest version of MetaMask? I suspect that this has been fixed.

@tmashuang
Copy link
Contributor

Closing this, the issue was the result of the first iteration of the login-per-site and the notification windows. This has since been changed and reworked as well as fix.

@JithinKS97
Copy link

@alex-ppg Could you please let me know how you resolved the issue? I ran into the exact use case and I'm observing the same behaviour. If the wallet is already open, signature screen is not shown unless we explicitly close and open the metamask widget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants