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

feat: CAIP Multichain (New) #27782

Draft
wants to merge 466 commits into
base: caip25-permission-migration
Choose a base branch
from

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Oct 10, 2024

Description

This branch is the feature branch for CAIP-25, CAIP-27, CAIP stream bifurcation. TODO better PR desc.

Open in GitHub Codespaces

Related issues

Related: MetaMask/core#4813
Upstream: #27847

See: https://github.com/MetaMask/MetaMask-planning/issues/2360

Manual testing steps

yarn start:flask

Replace EXTENSION_ID with your local extension ID

// Setup
const EXTENSION_ID = 'nonfpcflonapegmnfeafnddgdniflbnk';
const extensionPort = chrome.runtime.connect(EXTENSION_ID)
extensionPort.onMessage.addListener((msg) => {
    // format wallet_notify events nicely so that we can read them more easily later
    if (msg.data.method === 'wallet_notify') {
        console.log('wallet_notify:', {
            scope: msg.data.params.scope,
            method: msg.data.params.notification.method,
            subscription: msg.data.params.notification.params.subscription,
            number: msg.data.params.notification.params.result.number
        })
        return;
    }
    console.log(msg.data)
})


// Initial Connection
extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_createSession',
        params: {
            requiredScopes: {
            },
            optionalScopes: {
                'eip155:1': {
                    methods: [
                        'eth_blockNumber',
                        'eth_gasPrice',
                        'eth_getTransactionCount'
                    ],
                    notifications: [],
                    accounts: []
                }
            },
        },
    }
})


extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_invokeMethod',
        params: {
            scope: 'eip155:1',
            request: {
                "method": "eth_blockNumber",
                "params": [],
            }
        }
    }
})

extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_invokeMethod',
        params: {
            scope: 'eip155:1',
            request: {
                "method": "eth_gasPrice",
                "params": [],
            }
        }
    }
})

extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_invokeMethod',
        params: {
            scope: 'eip155:1',
            request: {
                "method": "eth_getTransactionCount",
                "params": ["0x5bA08AF1bc30f17272178bDcACA1C74e94955cF4", "latest"],
            }
        }
    }
})

// Not very interesting, let’s do this on Sepolia where I have some tx

extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_invokeMethod',
        params: {
            scope: 'eip155:11155111',
            request: {
                "method": "eth_getTransactionCount",
                "params": ["0x5bA08AF1bc30f17272178bDcACA1C74e94955cF4", "latest"],
            }
        }
    }
})


// Oh no, an error. Let’s fix that
extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_createSession',
        params: {
            requiredScopes: {
            },
            optionalScopes: {
                'eip155:1': {
                    methods: [
                        'eth_blockNumber',
                        'eth_gasPrice',
                        'eth_getTransactionCount'
                    ],
                    notifications: [],
                    accounts: []
                },
                'eip155:11155111': {
                    methods: [
                        'eth_blockNumber',
                        'eth_gasPrice',
                        'eth_getTransactionCount'
                    ],
                    notifications: [],
                    accounts: []
                }
            },
        },
    }
})

// And try again
extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_invokeMethod',
        params: {
            scope: 'eip155:11155111',
            request: {
                "method": "eth_getTransactionCount",
                "params": ["0x5bA08AF1bc30f17272178bDcACA1C74e94955cF4", "latest"],
            }
        }
    }
})

// What if I want even more chains and methods and subscriptions and preselected accounts?
extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_createSession',
        params: {
            requiredScopes: {
            },
            optionalScopes: {
                'eip155:1': {
                    methods: [
                        'eth_blockNumber',
                        'eth_gasPrice',
                        'eth_getTransactionCount',
                        'eth_sendTransaction', 
                        'eth_subscribe'
                    ],
                    notifications: ['eth_subscription'],
                    accounts: []
                },
                'eip155:11155111': {
                    methods: [
                        'eth_blockNumber',
                        'eth_gasPrice',
                        'eth_getTransactionCount',
                        'eth_sendTransaction', 
                        'eth_subscribe'
                    ],
                    notifications: ['eth_subscription'],
                    accounts: ['eip155:11155111:0x5bA08AF1bc30f17272178bDcACA1C74e94955cF4', 'eip155:11155111:0xEe166a3eec4796DeC6A1D314e7485a52bBe68e4d']
                },
                'eip155:59144': {
                    methods: [
                        'eth_estimateGas',
                    ],
                    notifications: [],
                    accounts: []
                },
            },
        },
    }
})










// What if I want to deny some requested chains and add extras?
// Rerun above, Remove Linea, add Linea Sepolia. Show how the added chains get the full permission set


// My dapp that just loaded / I forgot what my permissions look like / I want to check what my permissions currently look like.
extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_getSession',
        params:{}
    }
})

// What if the user modifies the permission outside of my dapp? How will I know without checking wallet_getSession frequently?
// Modify permission in page. Check for wallet_sessionChanged event


// What if I want to disconnect from the session entirely?
extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_revokeSession',
        params:{}
    }
})


// Let’s send some transactions! On sepolia and linea sepolia

extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_createSession',
        params: {
            requiredScopes: {
            },
            optionalScopes: {
                'eip155:1': {
                    methods: [
                        'eth_sendTransaction', 
                        'eth_subscribe'
                    ],
                    notifications: ['eth_subscription'],
                    accounts: []
                },
                'eip155:11155111': {
                    methods: [
                        'eth_sendTransaction', 
                        'eth_subscribe'
                    ],
                    notifications: ['eth_subscription'],
                    accounts: ['eip155:11155111:0x5bA08AF1bc30f17272178bDcACA1C74e94955cF4', 'eip155:11155111:0xEe166a3eec4796DeC6A1D314e7485a52bBe68e4d']
                },
                'eip155:59141': {
                    methods: [
                        'eth_sendTransaction',
                    ],
                    notifications: [],
                    accounts: []
                },
            },
        },
    }
})


extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_invokeMethod',
        params: {
            scope: 'eip155:11155111',
            request: {
                "method": "eth_sendTransaction",
                 "params": [
                  {
                    from: "0x5bA08AF1bc30f17272178bDcACA1C74e94955cF4",
                    to: "0x0000000000000000000000000000000000000000",
                    gas: "0x76c0",
                    value: "0x2bdbb64bc09000",
                    data: "0x",
                  }
                ],
            }
        }
    }
})


extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_invokeMethod',
        params: {
            scope: 'eip155:59141',
            request: {
                "method": "eth_sendTransaction",
                 "params": [
                  {
                    from: "0x5bA08AF1bc30f17272178bDcACA1C74e94955cF4",
                    to: "0x0000000000000000000000000000000000000000",
                    gas: "0x76c0",
                    value: "0x2bdbb64bc09000",
                    data: "0x",
                  }
                ],
            }
        }
    }
})

// You can even be receive eth subscriptions events on multiple chains at the same time, previously impossible.
extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_invokeMethod',
        params: {
            scope: 'eip155:1',
            request: {
                "method": "eth_subscribe",
                 "params": [
                     "newHeads"
                ],
            }
        }
    }
})



extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        method: 'wallet_invokeMethod',
        params: {
            scope: 'eip155:11155111',
            request: {
                "method": "eth_subscribe",
                 "params": [
                     "newHeads"
                ],
            }
        }
    }
})

Locked Wallet Behavior

  • wallet_getSession returns full session with all accounts
  • wallet_revokeSession works as usual
  • wallet_createSession prompts for unlock
  • wallet_invokeMethod on signature methods fails with method or accounts not authorized
  • wallet_invokeMethod on non-signature methods work as usual
  • wallet_sessionChanged not being fired when locked and revokeSession is called (TODO need to fix this). Is being fired when unlocked and revokeSession is called.

Wallet Onboarding Behavior (fresh install, not setup yet)

  • wallet_createSession causes wallet setup screen to be shown instead
  • all other methods work as expected
    • wallet_getSession returns no session since there is none
    • wallet_invokeMethod fails for everything since there is no active session

Screenshots/Recordings

Before

After

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

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.

jiexi and others added 30 commits September 4, 2024 11:48
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Error cleanup

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26825?quickstart=1)

## **Related issues**

See: MetaMask/MetaMask-planning#3048

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Whelp, my bad.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26926?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

* Rename `provider_authorize` -> `wallet_createSession`
* Rename `provider_requests` -> `wallet_invokeMethod`
* Format `eth_subscription` responses with `wallet_notify`

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26928?quickstart=1)

## **Related issues**

See: MetaMask/MetaMask-planning#3037

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

As discussed in the CASA meeting, we're using the 5301 error wrong. We
wouldn't want to fire it in our implementation either way so just
removing it now

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26915?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

* remove wallet_watchAsset from wallet:eip155
  * (which makes it a `eip155:x` scoped method)

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26954?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

An effort to cleanup some lazy permission types and differentiate the
potentially unflattened/malformed ScopeObjects from a CAIP-25 request
and the internal flattened ScopeObjects that get persisted into the
PermissionController state.

I don't love the current Internal/External prefixing. Perhaps making the
external type `unknown` and keeping the unprefixed as the internal type
would be better. Thoughts?

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26690?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.

---------

Co-authored-by: Alex Donesky <[email protected]>
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26828?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. `CHAIN_PERMISSIONS=1 BARAD_DUR=1 yarn build:test`
2. `yarn test:api-specs-multichain`

## **Screenshots/Recordings**
<img width="1609" alt="image"
src="https://github.com/user-attachments/assets/7db111ad-e194-4799-83a3-783d5e943e65">

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.

---------

Co-authored-by: MetaMask Bot <[email protected]>
# Conflicts:
#	lavamoat/browserify/beta/policy.json
#	lavamoat/browserify/flask/policy.json
#	lavamoat/browserify/main/policy.json
#	lavamoat/browserify/mmi/policy.json
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

* Fix `wallet:eip155` not being considered a valid scopeString
* Fix EIP-1193 permission adapter not checking `wallet` and
`wallet:eip155` scopes for methods

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27223?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
# Conflicts:
#	.gitignore
#	app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.js
#	app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.test.js
#	app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.js
#	app/scripts/lib/rpc-method-middleware/handlers/ethereum-chain-utils.js
#	app/scripts/lib/rpc-method-middleware/handlers/switch-ethereum-chain.test.js
#	app/scripts/metamask-controller.js
#	app/scripts/migrations/127.test.ts
#	app/scripts/migrations/127.ts
#	package.json
#	test/e2e/fixture-builder.js
#	yarn.lock
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Replaces `scopes` with `references` on `ScopeObject`

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27403?quickstart=1)

## **Related issues**

Fixes: MetaMask/MetaMask-planning#3301

## **Manual testing steps**

```
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', '59144'],
                    methods: [
                        'eth_sendTransaction',
                        'eth_getBalance',
                        'eth_subscribe'
                    ],
                    notifications: ['eth_subscription'],
                }
            },
            optionalScopes: {
            },
            sessionProperties: {
                'caip154-mandatory': 'true',
            },
        },
    }
})
```

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**
This adds api spec tests that utilize `externally_connectable` as well
as `caip-27` requests to wrap the "legacy" api-spec tests.

It refactors a lot into `transform.ts` to help reduce duplication since
we want to test it the same way as our current api-spec tests.

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27229?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. `CHAIN_PERMISSIONS=1 BARAD_DUR=1 yarn build:test`
2. `yarn test:api-spec-multichain`
3. see multiple html reporters pop up with all passing.

## **Screenshots/Recordings**
<img width="1309" alt="image"
src="https://github.com/user-attachments/assets/035a1725-b215-4d7c-982c-9867814113b4">

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.

---------

Co-authored-by: MetaMask Bot <[email protected]>
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27317?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.

---------

Co-authored-by: MetaMask Bot <[email protected]>
# Conflicts:
#	app/scripts/controllers/permissions/background-api.js
#	app/scripts/controllers/permissions/background-api.test.js
#	app/scripts/controllers/permissions/selectors.js
#	app/scripts/controllers/permissions/selectors.test.js
#	app/scripts/controllers/permissions/specifications.js
#	app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.js
#	app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.test.js
#	app/scripts/lib/rpc-method-middleware/handlers/ethereum-chain-utils.js
#	app/scripts/metamask-controller.js
#	ui/components/app/permission-page-container/permission-page-container.component.js
#	ui/selectors/permissions.js
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27510?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

* Add api-specs-multichain examples for wallet_createSession

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29592?quickstart=1)

## **Related issues**

See: MetaMask/MetaMask-planning#3823
See: MetaMask/MetaMask-planning#3824

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.

/**
* Creates a middleware that rejects explicitly unsupported RPC methods with the
* appropriate error.
*
* @param methods
Copy link
Member

Choose a reason for hiding this comment

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

Document please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done here 6d861f1

>;

/**
* Handler for the `wallet_createSession` RPC method.
Copy link
Member

Choose a reason for hiding this comment

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

This warrants a proper docstring IMO.

Also I know you've said that you didn't think this RPC method could be platform-agnostic or generic enough. I'm curious to know what is the cause of that?

Copy link
Contributor Author

@jiexi jiexi Jan 10, 2025

Choose a reason for hiding this comment

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

  1. sending metrics, although that isn't really that big on an issue if abstracted into a hook
  2. processScopedProperties used in this handler has a dependency on validateAddEthereumChainParams from app/scripts/lib/rpc-method-middleware/handlers/ethereum-chain-utils.js. DRYing this would also involve moving the add/switchEthereumChain handler logic into a shared package as well.

Technically I should delete the chunk of logic that uses that uses validateAddEthereumChainParams since that's only there for supporting the suggestion of networks to add via eip3085 shaped params in the scopedProperties of the wallet_createSession request. I'll make that change now, but still hesitant to move this into the core package given the issue i outlined in (2) will just become a problem again when we re-add eip3085 support to this handler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

jsdoc here 9d7a8a4

removal of unneeded scopedProperties validation (so, the entire helpers.ts file) here f2e64be

payload: MetaMetricsEventPayload,
options?: MetaMetricsEventOptions,
) => void;
metamaskState: {
Copy link
Member

Choose a reason for hiding this comment

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

I realize that this already exists, but I am confused as to why this was ever added as a hook. Being obviously not a hook

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤷


const sessionScopes = getSessionScopes(caip25CaveatValue);

await Promise.all(
Copy link
Member

Choose a reason for hiding this comment

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

IIRC we don't actually support these properties yet, so it seems worth it to simplify the PR by removing it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed here c7f9adc

@@ -19,7 +19,7 @@ const Preloader = ({ className, size }) => (
/>
<mask
id="mask0"
mask-type="alpha"
style={{ maskType: 'alpha' }}
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

linter was complaining about this. Unsure what changed about the linter or packages to cause this though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there are other places in code where style={{ maskType: 'alpha' }} is used instead of mask-type="alpha", so i figured this change was fine

);

engine.push(
this.multichainMiddlewareManager.generateMultichainMiddlewareForOriginAndTabId(
Copy link
Member

Choose a reason for hiding this comment

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

Is my understanding correct that this only is the middleware for subscriptions and that everything else is handled in the multichain middleware above?

If so, I think we should document that and maybe even change the names here, we have multiple "multichain middlewares" right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This middleware is a wrapper that routes requests to the correct underlying Subscription middleware for the scope in the request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's the MultichainMiddlewareManager and the MultichainSubscriptionManager. There's only one "multichain" middleware, unless you could the subscription middleware created for each scope to count as well

jiexi and others added 5 commits January 10, 2025 09:21
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29491?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.
@adonesky1
Copy link
Contributor

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

ffmcgee725 and others added 12 commits January 10, 2025 12:15
…pp across three different connected chains#3836 (#29522)

-- test: add wallet_invokeMethod end to end test cases

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29522?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **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.

---------

Co-authored-by: Alex Donesky <[email protected]>
-- test: multichain test dapp e2e test for wallet_notify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants