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

Jl/caip multichain/fix connection flow for permitted chains #27471

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Sep 27, 2024

Description

Connects the new AmonHenV2 Connection Flow to CAIP Multichain:

  • Preserves and syncs eth accounts across eip155 scopes when permitted chains are changed
  • Grants full methods and notifications to scopeObject when a new chain is permitted
  • ConnectPage Approval now uses the caveat values from eth_accounts and endowment:permitted-chains as the default selected account and chains
  • wallet_createSession passes a list of supported eth accounts and eth chainIds based on the supported scopes to be used as the preselected/default values in the ConnectPage Approval
  • wallet_createSession removes supported eip155 scopes that were not approved and adds ones that were not in the original request but were approved

Open in GitHub Codespaces

Related issues

Fixes:

Manual testing steps

Replace the account addresses below with your own addresses to test the preselected accounts. This request should preselect mainnet and sepolia (which is different from the default which preselects all non testnet networks)

const EXTENSION_ID = 'nonfpcflonapegmnfeafnddgdniflbnk';
const extensionPort = chrome.runtime.connect(EXTENSION_ID)
extensionPort.onMessage.addListener((msg) => console.log('extensionPort on message', msg))
extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_createSession',
        params: {
            requiredScopes: {
                'eip155': {
                    references: ['1', '11155111'],
                    methods: [
                        'eth_sendTransaction',
                        'eth_getBalance',
                        'eth_subscribe'
                    ],
                    notifications: ['eth_subscription'],
                    accounts: ['eip155:1:0x5bA08AF1bc30f17272178bDcACA1C74e94955cF4', 'eip155:1:0xdeadbeef', 'eip155:1:0x398fC6Ec25889e7373310dC4c3491b18575d5d6B']
                }
            },
            optionalScopes: {
            },
            sessionProperties: {
                'caip154-mandatory': 'true',
            },
        },
    }
})

replace this with your own address to test preselected accounts.

 "method": "wallet_requestPermissions",
 "params": [
  {
    eth_accounts: {
        caveats: [
            {
              type: 'restrictReturnedAccounts',
                value: ['0x5bA08AF1bc30f17272178bDcACA1C74e94955cF4']
            }
            ]
    }
  }
],
});

This one works for preselecting chains

 "method": "wallet_requestPermissions",
 "params": [
  {
    'endowment:permitted-chains': {
        caveats: [
            {
              type: 'restrictNetworkSwitching',
                value: ['0x1']
            }
            ]
    }
  }
],
});

You can also combine the params of these two wallet_requestPermissions examples

One for eth_requestAccounts

await window.ethereum.request({
 "method": "eth_requestAccounts",
 "params": [],
});

And of course you can connect via the wallet UI directly.

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth making this change against develop?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah makes sense. Even just a bit less code in the feature branch too is good! 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adonesky1
Copy link
Contributor

adonesky1 commented Sep 30, 2024

Video of a bug where requests are failing after permissions are granted through wallet UI:

Screen.Recording.2024-09-30.at.12.18.12.PM.mov
Screenshot 2024-09-30 at 2 42 28 PM

Looks like the permissions are there but probably failing because the permission is marked as isMultichainOrigin = false?

This seems like another reason why having even partial lockout will be very challenging

},
],
},
[PermissionNames.permittedChains]: {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this change may be breaking something about the UI in the wallet_switchEthereumChain permissions flow on the legacy API?

Screen.Recording.2024-09-30.at.3.07.51.PM.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don' think I understand what is broken here. If I am correct, you start without Ethereum mainnet permissioned, and then switch to it. After approving the switch, Ethereum mainnet is checked inside the EditNetworkModal. I assume this dapp has EIP-1193 granted permissions, otherwise the switch chain call would have failed (rather than prompting the user to approve or not)

Copy link
Contributor

@adonesky1 adonesky1 Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry I'm specifically highlighting that that switch chain permission UI no longer shows the ethereum avatar or network name
Screenshot 2024-09-30 at 4 00 11 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh gotcha. missed that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here 60f7518

will pull into PR against dev as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -649,7 +595,7 @@ describe('permission background API methods', () => {
);
});

it('calls updateCaveat with the chain added', () => {
it('calls updateCaveat with the chain added and all eip155 accounts synced', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "all eip155 accounts synced" mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the eip155 scopeObjects, gather the unique list of eip155 accounts, and then assign that list back to each eip155 scopeObject (overwriting any accounts array value that was previous there)

Copy link

sonarcloud bot commented Oct 1, 2024

Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jiexi jiexi marked this pull request as ready for review October 3, 2024 21:40
@jiexi jiexi requested review from a team as code owners October 3, 2024 21:40
@jiexi jiexi merged commit 4126dd3 into caip-multichain Oct 3, 2024
13 of 16 checks passed
@jiexi jiexi deleted the jl/caip-multichain/fix-connection-flow-for-permittedChains branch October 3, 2024 21:41
@github-actions github-actions bot locked and limited conversation to collaborators Oct 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants