-
Notifications
You must be signed in to change notification settings - Fork 5.3k
refactor: connection Flow to use CAIP25 Permission format #29824
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
Merged
Merged
Changes from 37 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
0ce5acc
refactor: send transformed caip25 compliant data to ApprovalControlle…
ffmcgee725 4c7d343
fix: fix payload sent to UI after Jiexi sesh
ffmcgee725 9b84b2b
refactor: send transformed caip25 compliant data to ApprovalController
ffmcgee725 8b48878
fix: handle common edge case with empty caveats
ffmcgee725 f3209cd
docs: document utility UI functions for caip25 connection flow
ffmcgee725 f793fee
test: unit test for UI utility functions
ffmcgee725 3c2ea45
Merge branch 'main' into jc/caip25-permission-refactor-main
ffmcgee725 7c919bc
lint
ffmcgee725 c88ffae
test: fix metamask controller caip25 unit tests
ffmcgee725 b244570
fix: address 'undefined' request object in connect-page component whe…
ffmcgee725 49814b8
docs: minor update
ffmcgee725 cea8fa8
refactor: address 'background-api.js' requestAccountsAndChainPermissi…
ffmcgee725 f771a58
Merge branch 'main' into jc/caip25-permission-refactor-main
ffmcgee725 5040491
docs: remove outdated comments
ffmcgee725 d885ecf
fix: fix UI reroute
ffmcgee725 a93dbdb
docs: task for future
ffmcgee725 9e11d21
Merge branch 'main' into jc/caip25-permission-refactor
ffmcgee725 fa015e3
refactor: 'requestApprovalPermittedChainsPermission' refactored to se…
ffmcgee725 981ad1e
test: fix 'requestApprovalPermittedChainsPermission' unit test
ffmcgee725 fe51b63
test: fix connect-page.test.tsx
ffmcgee725 f644d12
docs: remove commented code
ffmcgee725 87ff50d
refactor: remove dependency of PermissionNames.permittedChains from p…
ffmcgee725 1d0b241
docs: remove outdated comment
ffmcgee725 2efe4c0
test: remove outdated response data from test
ffmcgee725 9108e47
Merge branch 'main' into jc/caip25-permission-refactor
ffmcgee725 74fc018
refactor: use util functions from @metamask/multichain for chain / ad…
ffmcgee725 ae8c0f6
refactor: code review improvements
ffmcgee725 e30e051
fix: minor bug fix
ffmcgee725 38b6c7f
test: fix background api tets
ffmcgee725 c0832a4
merge main and fix conflicts
ffmcgee725 26cc31a
docs: add comment to 'requestAccountsAndChainPermissions'
ffmcgee725 b10f5ea
docs: add comment to 'requestAccountsAndChainPermissions'
ffmcgee725 7ca66e9
test: fix unit test as per code review
ffmcgee725 22b8227
test: minor test refactor
ffmcgee725 8d5968e
refactor: all redux state passed to container for permission page con…
ffmcgee725 ecad6ee
refactor: rename 'parseCaip25PermissionsResponse' to 'getCaip25Permis…
ffmcgee725 262d8f7
Merge branch 'main' into jc/caip25-permission-refactor
adonesky1 e49c99f
fix: fix issues raised by e2e tests (wip)
ffmcgee725 6e57d3c
docs: document findings for failing test/e2e/json-rpc/switchEthereumC…
ffmcgee725 1de4c5e
docs: document problem continuation
ffmcgee725 7bb7dad
fix: possible solution for permission.js file (wip)
ffmcgee725 5e3fd1f
fix: fix UI bug for properly rendering chain instead of accounts on w…
ffmcgee725 ae0bdb4
fix: consistently fetch pendingPermissionsFromOrigin to check for pen…
ffmcgee725 a1620d4
Merge branch 'main' into jc/caip25-permission-refactor
ffmcgee725 bfccd6e
refactor: code clean up
ffmcgee725 80611dc
docs: minor adjustment
ffmcgee725 486d7ea
Merge branch 'main' into jc/caip25-permission-refactor
ffmcgee725 e2a406f
Merge branch 'main' into jc/caip25-permission-refactor
ffmcgee725 e8bb435
Merge branch 'main' into jc/caip25-permission-refactor
ffmcgee725 267046e
Merge branch 'main' into jc/caip25-permission-refactor
ffmcgee725 2fb2e49
test: small adjustment for simplicity
ffmcgee725 075129b
Merge branch 'main' into jc/caip25-permission-refactor
ffmcgee725 cad7dfe
refactor: permission page container component simplify approved accounts
ffmcgee725 f3397ef
refactor: code review changes
ffmcgee725 4c11da7
Merge branch 'main' into jc/caip25-permission-refactor
ffmcgee725 0ed65fe
Merge branch 'main' into jc/caip25-permission-refactor
ffmcgee725 1ed1218
refactor: address code review
ffmcgee725 fe4cc4e
Merge branch 'main' into jc/caip25-permission-refactor
ffmcgee725 732b9fa
refactor: address code review
ffmcgee725 a66eac3
Merge branch 'main' into jc/caip25-permission-refactor
adonesky1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5416,6 +5416,15 @@ export default class MetamaskController extends EventEmitter { | |||||
* @param {Hex} chainId - The chainId to add incrementally. | ||||||
*/ | ||||||
async requestApprovalPermittedChainsPermission(origin, chainId) { | ||||||
const caveatValueWithChains = setPermittedEthChainIds( | ||||||
{ | ||||||
requiredScopes: {}, | ||||||
optionalScopes: {}, | ||||||
isMultichainOrigin: false, | ||||||
}, | ||||||
[chainId], | ||||||
); | ||||||
|
||||||
const id = nanoid(); | ||||||
await this.approvalController.addAndShowApprovalRequest({ | ||||||
id, | ||||||
|
@@ -5426,11 +5435,11 @@ export default class MetamaskController extends EventEmitter { | |||||
origin, | ||||||
}, | ||||||
permissions: { | ||||||
[PermissionNames.permittedChains]: { | ||||||
[Caip25EndowmentPermissionName]: { | ||||||
caveats: [ | ||||||
{ | ||||||
type: CaveatTypes.restrictNetworkSwitching, | ||||||
value: [chainId], | ||||||
type: Caip25CaveatType, | ||||||
value: caveatValueWithChains, | ||||||
}, | ||||||
], | ||||||
}, | ||||||
|
@@ -5566,20 +5575,15 @@ export default class MetamaskController extends EventEmitter { | |||||
delete permissions[PermissionNames.permittedChains]; | ||||||
} | ||||||
|
||||||
const id = nanoid(); | ||||||
const legacyApproval = | ||||||
await this.approvalController.addAndShowApprovalRequest({ | ||||||
id, | ||||||
origin, | ||||||
requestData: { | ||||||
metadata: { | ||||||
id, | ||||||
origin, | ||||||
}, | ||||||
permissions, | ||||||
}, | ||||||
type: MethodNames.RequestPermissions, | ||||||
}); | ||||||
const requestedChains = | ||||||
permissions[PermissionNames.permittedChains]?.caveats?.find( | ||||||
(caveat) => caveat.type === CaveatTypes.restrictNetworkSwitching, | ||||||
)?.value ?? []; | ||||||
|
||||||
const requestedAccounts = | ||||||
permissions[PermissionNames.eth_accounts]?.caveats?.find( | ||||||
(caveat) => caveat.type === CaveatTypes.restrictReturnedAccounts, | ||||||
)?.value ?? []; | ||||||
|
||||||
const newCaveatValue = { | ||||||
requiredScopes: {}, | ||||||
|
@@ -5593,26 +5597,41 @@ export default class MetamaskController extends EventEmitter { | |||||
|
||||||
const caveatValueWithChains = setPermittedEthChainIds( | ||||||
newCaveatValue, | ||||||
isSnapId(origin) ? [] : legacyApproval.approvedChainIds, | ||||||
isSnapId(origin) ? [] : requestedChains, | ||||||
); | ||||||
|
||||||
const caveatValueWithAccounts = setEthAccounts( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved in 1ed1218 |
||||||
caveatValueWithChains, | ||||||
legacyApproval.approvedAccounts, | ||||||
requestedAccounts, | ||||||
); | ||||||
|
||||||
return { | ||||||
[Caip25EndowmentPermissionName]: { | ||||||
caveats: [ | ||||||
{ | ||||||
type: Caip25CaveatType, | ||||||
value: caveatValueWithAccounts, | ||||||
const id = nanoid(); | ||||||
|
||||||
const { approvedSessionScopes } = | ||||||
await this.approvalController.addAndShowApprovalRequest({ | ||||||
id, | ||||||
origin, | ||||||
requestData: { | ||||||
metadata: { | ||||||
id, | ||||||
origin, | ||||||
}, | ||||||
], | ||||||
}, | ||||||
}; | ||||||
} | ||||||
permissions: { | ||||||
[Caip25EndowmentPermissionName]: { | ||||||
caveats: [ | ||||||
{ | ||||||
type: Caip25CaveatType, | ||||||
value: caveatValueWithAccounts, | ||||||
}, | ||||||
], | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
type: MethodNames.RequestPermissions, | ||||||
}); | ||||||
|
||||||
return approvedSessionScopes.permissions; | ||||||
} | ||||||
// --------------------------------------------------------------------------- | ||||||
// Identity Management (signature operations) | ||||||
|
||||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.