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

[FLASK] Fix eth_accounts permission for Snaps #16158

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions patches/@metamask+snap-controllers+0.22.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
diff --git a/node_modules/@metamask/snap-controllers/dist/snaps/SnapController.js b/node_modules/@metamask/snap-controllers/dist/snaps/SnapController.js
index aef2a42..b752ac4 100644
--- a/node_modules/@metamask/snap-controllers/dist/snaps/SnapController.js
+++ b/node_modules/@metamask/snap-controllers/dist/snaps/SnapController.js
@@ -822,7 +822,7 @@ class SnapController extends controllers_1.BaseControllerV2 {
* @param newVersionRange - A semver version range in which the maximum version will be chosen.
* @returns The snap metadata if updated, `null` otherwise.
*/
- async updateSnap(origin, snapId, newVersionRange = snap_utils_1.DEFAULT_REQUESTED_SNAP_VERSION) {
+ async updateSnap(origin, snapId, newVersionRange = snap_utils_1.DEFAULT_REQUESTED_SNAP_VERSION) {
const snap = this.getExpect(snapId);
if (!(0, snap_utils_1.isValidSnapVersionRange)(newVersionRange)) {
throw new Error(`Received invalid snap version range: "${newVersionRange}".`);
@@ -830,7 +830,7 @@ class SnapController extends controllers_1.BaseControllerV2 {
const newSnap = await this._fetchSnap(snapId, newVersionRange);
const newVersion = newSnap.manifest.version;
if (!(0, snap_utils_1.gtVersion)(newVersion, snap.version)) {
- console.warn(`Tried updating snap "${snapId}" within "${newVersionRange}" version range, but newer version "${newVersion}" is already installed`);
+ console.warn(`Tried updating snap "${snapId}" within "${newVersionRange}" version range, but newer version "${snap.version}" is already installed`);
return null;
}
await this._assertIsUnblocked(snapId, {
@@ -840,7 +840,7 @@ class SnapController extends controllers_1.BaseControllerV2 {
const processedPermissions = this.processSnapPermissions(newSnap.manifest.initialPermissions);
const { newPermissions, unusedPermissions, approvedPermissions } = await this.calculatePermissionsChange(snapId, processedPermissions);
const id = (0, nanoid_1.nanoid)();
- const isApproved = await this.messagingSystem.call('ApprovalController:addRequest', {
+ const _a = (await this.messagingSystem.call('ApprovalController:addRequest', {
origin,
id,
type: exports.SNAP_APPROVAL_UPDATE,
@@ -854,10 +854,7 @@ class SnapController extends controllers_1.BaseControllerV2 {
approvedPermissions,
unusedPermissions,
},
- }, true);
- if (!isApproved) {
- return null;
- }
+ }, true)), { permissions: approvedNewPermissions } = _a, requestData = __rest(_a, ["permissions"]);
if (this.isRunning(snapId)) {
await this.stopSnap(snapId, snap_utils_1.SnapStatusEvents.Stop);
}
@@ -875,10 +872,11 @@ class SnapController extends controllers_1.BaseControllerV2 {
[snapId]: unusedPermissionsKeys,
});
}
- if ((0, utils_1.isNonEmptyArray)(Object.keys(newPermissions))) {
+ if ((0, utils_1.isNonEmptyArray)(Object.keys(approvedNewPermissions))) {
await this.messagingSystem.call('PermissionController:grantPermissions', {
- approvedPermissions: newPermissions,
+ approvedPermissions: approvedNewPermissions,
subject: { origin: snapId },
+ requestData,
});
}
await this._startSnap({ snapId, sourceCode: newSnap.sourceCode });
@@ -1137,7 +1135,7 @@ class SnapController extends controllers_1.BaseControllerV2 {
* @param snapId - The id of the Snap.
* @returns The snap's approvedPermissions.
*/
- async authorize(origin, snapId) {
+ async authorize(origin, snapId) {
console.info(`Authorizing snap: ${snapId}`);
const snapsState = this.state.snaps;
const snap = snapsState[snapId];
@@ -1145,7 +1143,7 @@ class SnapController extends controllers_1.BaseControllerV2 {
try {
const processedPermissions = this.processSnapPermissions(initialPermissions);
const id = (0, nanoid_1.nanoid)();
- const isApproved = await this.messagingSystem.call('ApprovalController:addRequest', {
+ const _a = (await this.messagingSystem.call('ApprovalController:addRequest', {
origin,
id,
type: exports.SNAP_APPROVAL_INSTALL,
@@ -1155,14 +1153,12 @@ class SnapController extends controllers_1.BaseControllerV2 {
permissions: processedPermissions,
snapId,
},
- }, true);
- if (!isApproved) {
- throw eth_rpc_errors_1.ethErrors.provider.userRejectedRequest();
- }
- if ((0, utils_1.isNonEmptyArray)(Object.keys(processedPermissions))) {
+ }, true)), { permissions: approvedPermissions } = _a, requestData = __rest(_a, ["permissions"]);
+ if ((0, utils_1.isNonEmptyArray)(Object.keys(approvedPermissions))) {
await this.messagingSystem.call('PermissionController:grantPermissions', {
- approvedPermissions: processedPermissions,
+ approvedPermissions,
subject: { origin: snapId },
+ requestData,
});
}
}
10 changes: 8 additions & 2 deletions ui/pages/permissions-connect/permissions-connect.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ export default class PermissionConnect extends Component {
<SnapInstall
request={permissionsRequest || {}}
approveSnapInstall={(requestId) => {
approvePendingApproval(requestId, true);
approvePendingApproval(requestId, {
...permissionsRequest,
approvedAccounts: selectedAccountAddresses,
});
this.redirect(true);
}}
rejectSnapInstall={(requestId) => {
Expand All @@ -340,7 +343,10 @@ export default class PermissionConnect extends Component {
<SnapUpdate
request={permissionsRequest || {}}
approveSnapUpdate={(requestId) => {
approvePendingApproval(requestId, true);
approvePendingApproval(requestId, {
...permissionsRequest,
approvedAccounts: selectedAccountAddresses,
});
this.redirect(true);
}}
rejectSnapUpdate={(requestId) => {
Expand Down