-
Notifications
You must be signed in to change notification settings - Fork 5.2k
fix: add accounts to caip25 permissions when adding chain permissions to ethereum-provider enabled snaps #33111
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,7 +28,7 @@ describe(`migration #${version}`, () => { | |||||
expect(newStorage.meta).toStrictEqual({ version }); | ||||||
}); | ||||||
|
||||||
it('adds the network endowment to Snaps with the `endowment:ethereum-provider` permission', async () => { | ||||||
it('adds the `endowment:caip25` permission with the current globally selected chainId (and no accounts) permissioned to Snaps with the `endowment:ethereum-provider` permission and which do not already a `endowment:caip25` permission', async () => { | ||||||
const oldStorage = { | ||||||
meta: { version: oldVersion }, | ||||||
data: { | ||||||
|
@@ -122,7 +122,7 @@ describe(`migration #${version}`, () => { | |||||
}); | ||||||
}); | ||||||
|
||||||
it('merges with an existing permission if the Snap already has `endowment:caip25`', async () => { | ||||||
it('merges with an existing permission and adds existing account permissions along with the current globally selected chainId if the Snap already has `endowment:caip25`', async () => { | ||||||
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.
Suggested change
maybe? 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. done here: 9e3276c |
||||||
const oldStorage = { | ||||||
meta: { version: oldVersion }, | ||||||
data: { | ||||||
|
@@ -166,7 +166,7 @@ describe(`migration #${version}`, () => { | |||||
optionalScopes: { | ||||||
'wallet:eip155': { | ||||||
accounts: [ | ||||||
'0x1234567890123456789012345678901234567890', | ||||||
'wallet:eip155:0x1234567890123456789012345678901234567890', | ||||||
], | ||||||
}, | ||||||
}, | ||||||
|
@@ -214,11 +214,13 @@ describe(`migration #${version}`, () => { | |||||
optionalScopes: { | ||||||
'wallet:eip155': { | ||||||
accounts: [ | ||||||
'0x1234567890123456789012345678901234567890', | ||||||
'wallet:eip155:0x1234567890123456789012345678901234567890', | ||||||
], | ||||||
}, | ||||||
'eip155:1': { | ||||||
accounts: [], | ||||||
accounts: [ | ||||||
'eip155:1:0x1234567890123456789012345678901234567890', | ||||||
], | ||||||
}, | ||||||
}, | ||||||
requiredScopes: {}, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
Caip25EndowmentPermissionName, | ||
addPermittedEthChainId, | ||
Caip25CaveatValue, | ||
setEthAccounts, | ||
getEthAccounts, | ||
} from '@metamask/chain-agnostic-permission'; | ||
|
||
type GenericPermissionControllerSubject = | ||
|
@@ -206,6 +208,24 @@ | |
currentChainId, | ||
); | ||
|
||
let caip25PermissionCaveatWithCurrentChainIdAndAccountsSet = | ||
caip25PermissionCaveatWithCurrentChainIdSet; | ||
|
||
if (subject.permissions[Caip25EndowmentPermissionName]) { | ||
const existingCaveat = subject.permissions[ | ||
Caip25EndowmentPermissionName | ||
]?.caveats?.find((caveat) => caveat.type === Caip25CaveatType); | ||
if (existingCaveat && existingCaveat.value) { | ||
const alreadyPermissionedAccounts = getEthAccounts( | ||
existingCaveat.value as Caip25CaveatValue, | ||
); | ||
caip25PermissionCaveatWithCurrentChainIdAndAccountsSet = setEthAccounts( | ||
caip25PermissionCaveatWithCurrentChainIdSet, | ||
alreadyPermissionedAccounts, | ||
); | ||
} | ||
} | ||
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. This can be deduplicated using the 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. done here: 483e2f8 |
||
|
||
const { | ||
date = Date.now(), | ||
id = nanoid(), | ||
|
@@ -221,7 +241,7 @@ | |
caveats: [ | ||
{ | ||
type: Caip25CaveatType, | ||
value: caip25PermissionCaveatWithCurrentChainIdSet, | ||
value: caip25PermissionCaveatWithCurrentChainIdAndAccountsSet, | ||
}, | ||
], | ||
date, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done here: 483e2f8