Skip to content

WIP: CAIP-25, CAIP-27, CAIP stream bifurcation, permissions#24181

Closed
jiexi wants to merge 101 commits intodevelopfrom
jl/mmp-2360/caip-25-poc
Closed

WIP: CAIP-25, CAIP-27, CAIP stream bifurcation, permissions#24181
jiexi wants to merge 101 commits intodevelopfrom
jl/mmp-2360/caip-25-poc

Conversation

@jiexi
Copy link
Copy Markdown
Member

@jiexi jiexi commented Apr 22, 2024

Description

Initial draft of provider_authorize with basic validation and support check
This branch is becoming the feature branch for CAIP-25, CAIP-27, CAIP stream bifurcation, and CAIP-25 Permissions

Open in GitHub Codespaces

Related issues

See: https://github.com/MetaMask/MetaMask-planning/issues/2360
See: MetaMask/test-dapp#324

Manual testing steps

  1. Go to this page...
BARAD_DUR=1 yarn start

Replace EXTENSION_ID with your local extension ID

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: 'provider_authorize',
        params: {
            requiredScopes: {
                'eip155': {
                    scopes: ['eip155:1', 'eip155:59144'],
                    methods: [
                        'eth_sendTransaction',
                        'eth_accounts',
                        'eth_blockNumber',
                        'eth_getBalance',
                        'personal_sign',
                    ],
                    notifications: ['accountsChanged', 'chainChanged'],
                },
                'eip155:11155111': {
                    methods: ['eth_blockNumber'],
                    notifications: ['accountsChanged', 'chainChanged'],
                },
                'wallet': {
                    methods: [
                        'wallet_getPermissions',
                    ],
                    notifications: [],
                },
            },
            optionalScopes: {
                'eip155:64': {
                    methods: [
                        'eth_blockNumber',
                        'eth_getBalance',
                        'eth_getBlockByHash',
                        'eth_getBlockByNumber',
                    ],
                    notifications: ['accountsChanged', 'chainChanged'],
                },
            },
            sessionProperties: {
                expiry: 1,
                'caip154-mandatory': 'true',
            },
        },
    }
})
extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        "method": "provider_request",
        "params": {
            "sessionId": "0xdeadbeef",
            "scope": "eip155:1",
            "request": {
                "method": "eth_chainId",
            }
        }
    }
})
extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "jsonrpc": "2.0",
        "method": "provider_request",
        "params": {
            "sessionId": "0xdeadbeef",
            "scope": "eip155:11155111",
            "request": {
                "method": "eth_chainId",
            }
        }
    }
})

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.

@github-actions
Copy link
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

not sure where this should live. Definitely not in this folder at the minimum. Maybe @metamask/utils? Feels like it's not quite stable enough for that yet

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good question 🤔 I think here is fine for now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh whoops didn't realize this is a handler, yeah probably in a lib folder til stable enough to pull into @metamask/utils

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ideally we go with a new package in core to encapsulate the shared code for mobile/extension around caip-25 and caip-27

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But i dont think this file should be in handlers, it doesnt have a handler in it, its just utils for provider_authorize which is added here as a handler.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed. These definitely do not belong in handlers. I still feel that these belong in @metamask/utils because of the existing caip types that live there, but I can also see it going in core since they're a slight departure from a "primitive" CAIP type

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [85592db]
Page Load Metrics (1221 ± 668 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint683991489244
domContentLoaded11109322311
load55338412211391668
domInteractive11109322311
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 2.62 KiB (0.07%)
  • ui: 0 Bytes (0.00%)
  • common: 40 Bytes (0.00%)

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 22, 2024

Codecov Report

Attention: Patch coverage is 16.53543% with 106 lines in your changes missing coverage. Please review.

Project coverage is 67.18%. Comparing base (03b5d5e) to head (a0dee99).
Report is 14 commits behind head on develop.

Current head a0dee99 differs from pull request most recent head 7971eac

Please upload reports for the commit 7971eac to get more accurate results.

Files Patch % Lines
...c-method-middleware/handlers/provider-authorize.js 15.00% 68 Missing ⚠️
...ipts/lib/rpc-method-middleware/handlers/caip-25.ts 17.39% 38 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #24181      +/-   ##
===========================================
- Coverage    69.60%   67.18%   -2.41%     
===========================================
  Files         1364     1278      -86     
  Lines        48172    49866    +1694     
  Branches     13291    12962     -329     
===========================================
- Hits         33526    33502      -24     
- Misses       14646    16364    +1718     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [ff801b5]
Page Load Metrics (833 ± 559 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint641631012612
domContentLoaded11352173
load5528468331165559
domInteractive10352173
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 3.72 KiB (0.11%)
  • ui: 0 Bytes (0.00%)
  • common: 40 Bytes (0.00%)

@jiexi jiexi added the team-wallet-api-platform-deprecated DEPRECATED: please use "team-wallet-integrations" instead label Apr 23, 2024
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [c90efeb]
Page Load Metrics (920 ± 550 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint621541042713
domContentLoaded95824126
load5326339201145550
domInteractive95824126
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 3.61 KiB (0.10%)
  • ui: 0 Bytes (0.00%)
  • common: 40 Bytes (0.00%)

...restScopeObject
} = scopeObject;

// These assume that the namespace has a notion of chainIds
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

seems fine til we integrate chains that don't have chainIds

);
}

const sessionId = '0xdeadbeef';
Copy link
Copy Markdown
Contributor

@adonesky1 adonesky1 Apr 26, 2024

Choose a reason for hiding this comment

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

we should keep this as a hardcoded sessionId forever

return end(
new EthereumRpcError(
5301,
'Session Properties can only be optional and global',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤔 are you saying here that any other top level keys should live in sessionProperties?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I believe that's the implication of the spec

Session Properties requested outside of Session Properties Object
code = 5301
message = "Session Properties can only be optional and global"

jiexi added 6 commits June 27, 2024 14:56
<!--
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/25516?quickstart=1)

## **Related issues**

Fixes:

## **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: {
        "id": 1,
        "jsonrpc": "2.0",
        "method": "provider_request",
        "params": {
            "sessionId": "0xdeadbeef",
            "scope": "eip155:1",
            "request": {
                "method": "eth_chainId",
            }
        }
    }
})
extensionPort.postMessage({
    type: 'caip-x',
    data: {
        "id": 2,
        "jsonrpc": "2.0",
        "method": "provider_request",
        "params": {
            "sessionId": "0xdeadbeef",
            "scope": "eip155:11155111",
            "request": {
                "method": "eth_chainId",
            }
        }
    }
})
```

## **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.
…RPC pipeline. Naive hasPermission check in provider_request
@jiexi jiexi changed the title WIP: CAIP-25 POC WIP: CAIP-25, CAIP-27, CAIP stream bifurcation, and CAIP25 Permissions Jun 27, 2024
@jiexi jiexi changed the title WIP: CAIP-25, CAIP-27, CAIP stream bifurcation, and CAIP25 Permissions WIP: CAIP-25, CAIP-27, CAIP stream bifurcation, permissions Jun 27, 2024
jiexi and others added 11 commits June 27, 2024 16:22
…caip-27 handler (#25582)

<!--
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 uses the findNetworkClientIdByChainId hook to get the
networkClientId for caip-27 handler
<!--
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/25582?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**

<!--
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/25589?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**

<!--
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/25617?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: Shane <jonas.shane@gmail.com>
@socket-security
Copy link
Copy Markdown

socket-security bot commented Jul 2, 2024

jiexi and others added 4 commits July 2, 2024 15:43
<!--
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/25643?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.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Jul 3, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
12.1% Duplication on New Code (required ≤ 7%)

See analysis details on SonarCloud

<!--
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/25647?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.
@jiexi jiexi closed this Jul 3, 2024
@jiexi jiexi deleted the jl/mmp-2360/caip-25-poc branch July 3, 2024 18:34
@github-actions github-actions bot locked and limited conversation to collaborators Jul 3, 2024
@jiexi
Copy link
Copy Markdown
Member Author

jiexi commented Jul 3, 2024

Moved to #25665

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

barad-dur team-wallet-api-platform-deprecated DEPRECATED: please use "team-wallet-integrations" instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants