mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
d054175b2e
* Fix an issue with installing snaps with 0 permissions * Fix some issues * Fix lint * Fix code fencing * UI improvements for no permission use-case * Fix redirect * Delay BIP44 test slightly * Add more delay * Fix update UI
63 lines
3.1 KiB
Diff
63 lines
3.1 KiB
Diff
diff --git a/node_modules/@metamask/snap-controllers/dist/snaps/SnapController.js b/node_modules/@metamask/snap-controllers/dist/snaps/SnapController.js
|
|
index ad84417..158e8e6 100644
|
|
--- a/node_modules/@metamask/snap-controllers/dist/snaps/SnapController.js
|
|
+++ b/node_modules/@metamask/snap-controllers/dist/snaps/SnapController.js
|
|
@@ -30,6 +30,7 @@ const RequestQueue_1 = require("./RequestQueue");
|
|
const utils_3 = require("./utils");
|
|
const Timer_1 = require("./Timer");
|
|
exports.controllerName = 'SnapController';
|
|
+exports.SNAP_APPROVAL_INSTALL = 'wallet_installSnap';
|
|
exports.SNAP_APPROVAL_UPDATE = 'wallet_updateSnap';
|
|
const TRUNCATED_SNAP_PROPERTIES = new Set([
|
|
'initialPermissions',
|
|
@@ -738,7 +739,7 @@ class SnapController extends controllers_1.BaseControllerV2 {
|
|
id: snapId,
|
|
versionRange,
|
|
});
|
|
- await this.authorize(snapId);
|
|
+ await this.authorize(origin, snapId);
|
|
await this._startSnap({
|
|
snapId,
|
|
sourceCode,
|
|
@@ -1073,18 +1074,34 @@ class SnapController extends controllers_1.BaseControllerV2 {
|
|
* @param snapId - The id of the Snap.
|
|
* @returns The snap's approvedPermissions.
|
|
*/
|
|
- async authorize(snapId) {
|
|
+ async authorize(origin, snapId) {
|
|
console.info(`Authorizing snap: ${snapId}`);
|
|
const snapsState = this.state.snaps;
|
|
const snap = snapsState[snapId];
|
|
const { initialPermissions } = snap;
|
|
try {
|
|
- if ((0, utils_1.isNonEmptyArray)(Object.keys(initialPermissions))) {
|
|
- const processedPermissions = this.processSnapPermissions(initialPermissions);
|
|
- const [approvedPermissions] = await this.messagingSystem.call('PermissionController:requestPermissions', { origin: snapId }, processedPermissions);
|
|
- return Object.values(approvedPermissions).map((perm) => perm.parentCapability);
|
|
+ const processedPermissions = this.processSnapPermissions(initialPermissions);
|
|
+ const id = (0, nanoid_1.nanoid)();
|
|
+ const isApproved = await this.messagingSystem.call('ApprovalController:addRequest', {
|
|
+ origin,
|
|
+ id,
|
|
+ type: exports.SNAP_APPROVAL_INSTALL,
|
|
+ requestData: {
|
|
+ // Mirror previous installation metadata
|
|
+ metadata: { id, origin: snapId, dappOrigin: origin },
|
|
+ permissions: processedPermissions,
|
|
+ snapId,
|
|
+ },
|
|
+ }, true);
|
|
+ if (!isApproved) {
|
|
+ throw eth_rpc_errors_1.ethErrors.provider.userRejectedRequest();
|
|
+ }
|
|
+ if ((0, utils_1.isNonEmptyArray)(Object.keys(processedPermissions))) {
|
|
+ await this.messagingSystem.call('PermissionController:grantPermissions', {
|
|
+ approvedPermissions: processedPermissions,
|
|
+ subject: { origin: snapId },
|
|
+ });
|
|
}
|
|
- return [];
|
|
}
|
|
finally {
|
|
const runtime = this.getRuntimeExpect(snapId);
|