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

Research if we're able to detect legacy dapps #6384

Closed
bdresser opened this issue Apr 1, 2019 · 3 comments
Closed

Research if we're able to detect legacy dapps #6384

bdresser opened this issue Apr 1, 2019 · 3 comments
Assignees

Comments

@bdresser
Copy link
Contributor

bdresser commented Apr 1, 2019

Can we know if a site hasn't updated to support 1102? This will inform #6352

@bdresser bdresser added this to the Sprint: 4.1 - 4.12 milestone Apr 1, 2019
@whymarrh
Copy link
Contributor

whymarrh commented Apr 8, 2019

Can we know if a site hasn't updated to support 1102?

Yes, I believe that we can detect if a dapp is using the old initialization process. 1102 outlined a dapp initialization process that supersedes the "legacy dapp initialization" that used a global web3 object.[1] After looking at a small sample of "legacy" dapps and how they use web3, I believe that we detect property access and use that to display custom messaging about 1102 and the larger privacy mode option.

danfinlay/js-eth-personal-sign-examples [2]

Here a dapp is using an address from web3.eth.accounts[0] over "connect":

var from = web3.eth.accounts[0]
if (!from) return connect()

idleKings/Turtle [3]

Here a dapp is using web3.currentProvider:

var web3;
if (typeof window.web3 !== "undefined" && typeof window.web3.currentProvider !== "undefined") {
    web3 = new Web3(window.web3.currentProvider);
} else {
    web3 = new Web3();		
    web3.setProvider(new web3.providers.HttpProvider('https://mainnet.infura.io/uwEccFsRIgwJGznPQLDN'));		
}

We should be able to wrap our injected web3 instance with a Proxy that detect property access and checks whether or not the dapp has already called request provider access. If the dapp has not yet requested provider access, we can display messaging about privacy mode and its implications.

global.web3 = new Proxy(web3, {
  get (_web3, key) {
    switch (key) {
      case 'eth':
        return new Proxy(_web3[key], {
          get (_eth, key) {
            switch (key) {
              case 'accounts':
                console.log('web3.eth.accounts property access')
              default:
                return _eth[key]
            }
          },
          set (_eth, key, value) {
            _eth[key] = value
          },
        })
      case 'currentProvider':
        console.log('web3.currentProvider property access')
      default:
        return _web3[key]
    }
  },
  set (_web3, key, value) {
    _web3[key] = value
  },
})

@bdresser bdresser closed this as completed Apr 8, 2019
@danfinlay
Copy link
Contributor

We should be able to wrap our injected web3 instance with a Proxy that detect property access and checks whether or not the dapp has already called request provider access. If the dapp has not yet requested provider access, we can display messaging about privacy mode and its implications.

For this to be a valid solution, it would have to differentiate these legacy dapps from current dapp patterns.

This solution assumes that modern dapps never attempt to access web3 before calling enable(), but I'm not sure that's the case. I think it's actually very common to check web3.eth.accounts to see if a user is logged in, which would trigger legacy dapp detection in this case.

@bdresser bdresser reopened this Apr 8, 2019
@whymarrh
Copy link
Contributor

whymarrh commented Apr 10, 2019

Yup, my comment here about us being able to detect property access on web3 was more that it's possible, less that it's a full solution. We can coordinate with the background script to determine whether or not the site is already approved/connected and/or whether or not the user has privacy mode enabled. Some combination of those checks can be run when a dapp accesses properties off web3 to determine whether or not we show messaging around privacy mode.

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

No branches or pull requests

4 participants
@danfinlay @bdresser @whymarrh and others