-
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?
Conversation
…thereum-provider enabled snaps
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. |
Builds ready [88c7859]
UI Startup Metrics (1194 ± 63 ms)
Benchmark value 24 exceeds gate value 18 for chrome browserify home p95 backgroundConnect Benchmark value 2247 exceeds gate value 2192 for chrome webpack home mean uiStartup Benchmark value 1741 exceeds gate value 1711 for chrome webpack home mean load Benchmark value 1734 exceeds gate value 1704 for chrome webpack home mean domContentLoaded Benchmark value 1730 exceeds gate value 1699 for chrome webpack home mean loadScripts Benchmark value 45 exceeds gate value 32 for chrome webpack home mean setupStore Benchmark value 2640 exceeds gate value 2454 for chrome webpack home p95 uiStartup Benchmark value 2032 exceeds gate value 2030 for chrome webpack home p95 load Benchmark value 2022 exceeds gate value 2005 for chrome webpack home p95 domContentLoaded Benchmark value 2010 exceeds gate value 1970 for chrome webpack home p95 loadScripts Benchmark value 309 exceeds gate value 65 for chrome webpack home p95 setupStore Benchmark value 1681 exceeds gate value 1660 for firefox browserify home p95 uiStartup Benchmark value 1497 exceeds gate value 1495 for firefox browserify home p95 load Benchmark value 1497 exceeds gate value 1495 for firefox browserify home p95 domContentLoaded Benchmark value 1483 exceeds gate value 1475 for firefox browserify home p95 loadScripts Benchmark value 33 exceeds gate value 27 for firefox browserify home p95 setupStore Benchmark value 39 exceeds gate value 38 for firefox webpack home mean firstReactRender Sum of mean exceeds: 160ms | Sum of p95 exceeds: 534ms Sum of all benchmark exceeds: 694ms |
app/scripts/migrations/160.test.ts
Outdated
@@ -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 () => { |
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.
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 () => { | |
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 have a `endowment:caip25` permission', async () => { |
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
app/scripts/migrations/160.ts
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This can be deduplicated using the getExistingCaip25PermissionCaveat(subject)
above.
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
feb0add
to
483e2f8
Compare
Builds ready [483e2f8]
UI Startup Metrics (1243 ± 68 ms)
Benchmark value 1243 exceeds gate value 1234 for chrome browserify home mean uiStartup Benchmark value 1062 exceeds gate value 1061 for chrome browserify home mean domContentLoaded Benchmark value 861 exceeds gate value 800 for chrome browserify home mean firstPaint Benchmark value 25 exceeds gate value 18 for chrome browserify home p95 backgroundConnect Benchmark value 2470 exceeds gate value 2454 for chrome webpack home p95 uiStartup Benchmark value 296 exceeds gate value 65 for chrome webpack home p95 setupStore Benchmark value 12 exceeds gate value 11 for firefox browserify home mean getState Benchmark value 1384 exceeds gate value 1380 for firefox webpack home mean load Benchmark value 1384 exceeds gate value 1380 for firefox webpack home mean domContentLoaded Benchmark value 42 exceeds gate value 38 for firefox webpack home mean firstReactRender Benchmark value 1364 exceeds gate value 1360 for firefox webpack home mean loadScripts Benchmark value 2011 exceeds gate value 1935 for firefox webpack home p95 uiStartup Benchmark value 1785 exceeds gate value 1660 for firefox webpack home p95 load Benchmark value 1784 exceeds gate value 1660 for firefox webpack home p95 domContentLoaded Benchmark value 1763 exceeds gate value 1630 for firefox webpack home p95 loadScripts Sum of mean exceeds: 88ms | Sum of p95 exceeds: 712ms Sum of all benchmark exceeds: 800ms |
app/scripts/migrations/160.ts
Outdated
caip25PermissionCaveatWithCurrentChainIdSet; | ||
|
||
if (existingCaip25Caveat) { | ||
const alreadyPermissionedAccounts = getEthAccounts(existingCaip25Caveat); |
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.
existingPermittedAccounts
? or just plain old permittedAccounts
? idk. nit.
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.
switched to existingPermittedAccounts
here: 9e3276c
app/scripts/migrations/160.ts
Outdated
|
||
if (existingCaip25Caveat) { | ||
const alreadyPermissionedAccounts = getEthAccounts(existingCaip25Caveat); | ||
if (alreadyPermissionedAccounts) { |
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.
empty array is always truthy
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.
should we leave a comment what this block is trying to achieve? or nah because specs help clarify?
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.
fixed here + added a comment: 9e3276c
app/scripts/migrations/160.test.ts
Outdated
@@ -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 have a `endowment:caip25` permission', async () => { |
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.
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 have a `endowment:caip25` 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 but do not already have a `endowment:caip25` permission', async () => { |
?
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.
idk
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: 9e3276c
app/scripts/migrations/160.test.ts
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
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 () => { | |
it('adds the current globally selected chainId with the existing permitted eth accounts to the existing `endowment:caip25` permission if the Snap already has `endowment:caip25` permission', async () => { |
maybe?
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: 9e3276c
Builds ready [9e3276c]
UI Startup Metrics (1243 ± 68 ms)
Benchmark value 1076 exceeds gate value 1070 for chrome browserify home mean load Benchmark value 1068 exceeds gate value 1061 for chrome browserify home mean domContentLoaded Benchmark value 1369 exceeds gate value 1365 for chrome browserify home p95 uiStartup Benchmark value 1209 exceeds gate value 1190 for chrome browserify home p95 load Benchmark value 1199 exceeds gate value 1180 for chrome browserify home p95 domContentLoaded Benchmark value 1206 exceeds gate value 1180 for chrome browserify home p95 firstPaint Benchmark value 31 exceeds gate value 18 for chrome browserify home p95 backgroundConnect Benchmark value 954 exceeds gate value 940 for chrome browserify home p95 loadScripts Benchmark value 52 exceeds gate value 32 for chrome webpack home mean setupStore Benchmark value 303 exceeds gate value 65 for chrome webpack home p95 setupStore Sum of mean exceeds: 43ms | Sum of p95 exceeds: 333ms Sum of all benchmark exceeds: 376ms |
Description
This PR updates migration 160 - recently added in #33018 - to add missing account permissions for Snaps with the
endowment:caip25
permission.Previously, when migrating Snaps with an existing
endowment:caip25
permission, the accounts associated with that permission were not explicitly carried over to the newly added chainId scope. This change ensures that:If a Snap already has the
endowment:caip25
permission, any accounts previously permissioned underwallet:eip155
are applied to the new scopes added to the permission. This means these accounts will be permissioned for thecurrentChainId
that is being added by the migration.The corresponding tests in
160.test.ts
have been updated to verify this new behavior, ensuring that existing accounts are correctly merged and applied to the relevant chainId scope in theendowment:caip25
permission caveat.Pre-merge author checklist
Pre-merge reviewer checklist