2022-03-14 19:26:02 +01:00
|
|
|
import deepFreeze from 'deep-freeze-strict';
|
2022-08-18 17:07:34 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
import React from 'react';
|
2022-11-30 13:19:33 +01:00
|
|
|
import { getRpcCaveatOrigins } from '@metamask/snaps-controllers/dist/snaps/endowments/rpc';
|
2022-08-18 17:07:34 +02:00
|
|
|
///: END:ONLY_INCLUDE_IN
|
2022-03-14 19:26:02 +01:00
|
|
|
import {
|
|
|
|
RestrictedMethods,
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
EndowmentPermissions,
|
|
|
|
PermissionNamespaces,
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
} from '../../../shared/constants/permissions';
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
import { coinTypeToProtocolName } from './util';
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
|
|
|
|
const UNKNOWN_PERMISSION = Symbol('unknown');
|
|
|
|
|
|
|
|
const PERMISSION_DESCRIPTIONS = deepFreeze({
|
|
|
|
[RestrictedMethods.eth_accounts]: {
|
|
|
|
label: (t) => t('permission_ethereumAccounts'),
|
|
|
|
leftIcon: 'fas fa-eye',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
[RestrictedMethods.snap_confirm]: {
|
|
|
|
label: (t) => t('permission_customConfirmation'),
|
|
|
|
leftIcon: 'fas fa-user-check',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
2022-03-17 17:43:18 +01:00
|
|
|
[RestrictedMethods.snap_notify]: {
|
|
|
|
leftIcon: 'fas fa-bell',
|
|
|
|
label: (t) => t('permission_notifications'),
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
2022-09-23 12:39:54 +02:00
|
|
|
[RestrictedMethods.snap_getBip32PublicKey]: {
|
|
|
|
label: (t, _, permissionValue) => {
|
|
|
|
return permissionValue.caveats[0].value.map(({ path, curve }) =>
|
|
|
|
t('permission_viewBip32PublicKeys', [
|
|
|
|
<span className="permission-label-item" key={path.join('/')}>
|
|
|
|
{path.join('/')}
|
|
|
|
</span>,
|
|
|
|
curve,
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
leftIcon: 'fas fa-eye',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
2022-08-18 17:07:34 +02:00
|
|
|
[RestrictedMethods.snap_getBip32Entropy]: {
|
|
|
|
label: (t, _, permissionValue) => {
|
|
|
|
return permissionValue.caveats[0].value.map(({ path, curve }) =>
|
|
|
|
t('permission_manageBip32Keys', [
|
|
|
|
<span className="permission-label-item" key={path.join('/')}>
|
|
|
|
{path.join('/')}
|
|
|
|
</span>,
|
|
|
|
curve,
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
leftIcon: 'fas fa-door-open',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
2022-08-26 13:48:53 +02:00
|
|
|
[RestrictedMethods.snap_getBip44Entropy]: {
|
|
|
|
label: (t, _, permissionValue) => {
|
|
|
|
return permissionValue.caveats[0].value.map(({ coinType }) =>
|
|
|
|
t('permission_manageBip44Keys', [
|
|
|
|
<span className="permission-label-item" key={`coin-type-${coinType}`}>
|
|
|
|
{coinTypeToProtocolName(coinType) ||
|
|
|
|
`${coinType} (Unrecognized protocol)`}
|
|
|
|
</span>,
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
leftIcon: 'fas fa-door-open',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
2022-11-22 13:07:08 +01:00
|
|
|
[RestrictedMethods.snap_getEntropy]: {
|
|
|
|
label: (t) => t('permission_getEntropy'),
|
|
|
|
leftIcon: 'fas fa-key',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
2022-03-14 19:26:02 +01:00
|
|
|
[RestrictedMethods.snap_manageState]: {
|
|
|
|
label: (t) => t('permission_manageState'),
|
|
|
|
leftIcon: 'fas fa-download',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
|
|
|
[RestrictedMethods['wallet_snap_*']]: {
|
|
|
|
label: (t, permissionName) => {
|
|
|
|
const snapId = permissionName.split('_').slice(-1);
|
|
|
|
return t('permission_accessSnap', [snapId]);
|
|
|
|
},
|
|
|
|
leftIcon: 'fas fa-bolt',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
|
|
|
[EndowmentPermissions['endowment:network-access']]: {
|
|
|
|
label: (t) => t('permission_accessNetwork'),
|
|
|
|
leftIcon: 'fas fa-wifi',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
2022-05-18 13:49:26 +02:00
|
|
|
[EndowmentPermissions['endowment:long-running']]: {
|
|
|
|
label: (t) => t('permission_longRunning'),
|
|
|
|
leftIcon: 'fas fa-infinity',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
2022-09-20 19:00:07 +02:00
|
|
|
[EndowmentPermissions['endowment:transaction-insight']]: {
|
|
|
|
label: (t) => t('permission_transactionInsight'),
|
|
|
|
leftIcon: 'fas fa-info',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
2022-11-09 13:18:47 +01:00
|
|
|
[EndowmentPermissions['endowment:cronjob']]: {
|
|
|
|
label: (t) => t('permission_cronjob'),
|
|
|
|
leftIcon: 'fas fa-clock',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
2022-11-22 13:07:08 +01:00
|
|
|
[EndowmentPermissions['endowment:ethereum-provider']]: {
|
|
|
|
label: (t) => t('permission_ethereumProvider'),
|
|
|
|
leftIcon: 'fab fa-ethereum',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
2022-11-30 13:19:33 +01:00
|
|
|
[EndowmentPermissions['endowment:rpc']]: {
|
|
|
|
label: (t, _, permissionValue) => {
|
|
|
|
const { snaps, dapps } = getRpcCaveatOrigins(permissionValue);
|
|
|
|
|
|
|
|
const messages = [];
|
|
|
|
if (snaps) {
|
|
|
|
messages.push(t('permission_rpc', [t('otherSnaps')]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dapps) {
|
|
|
|
messages.push(t('permission_rpc', [t('websites')]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return messages;
|
|
|
|
},
|
|
|
|
leftIcon: 'fas fa-plug',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
2022-03-14 19:26:02 +01:00
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
[UNKNOWN_PERMISSION]: {
|
|
|
|
label: (t, permissionName) =>
|
|
|
|
t('permission_unknown', [permissionName ?? 'undefined']),
|
|
|
|
leftIcon: 'fas fa-times-circle',
|
|
|
|
rightIcon: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2022-07-27 15:28:05 +02:00
|
|
|
* @typedef {object} PermissionLabelObject
|
2022-03-14 19:26:02 +01:00
|
|
|
* @property {string} label - The text label.
|
|
|
|
* @property {string} leftIcon - The left icon.
|
|
|
|
* @property {string} rightIcon - The right icon.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Function} t - The translation function
|
|
|
|
* @param {string} permissionName - The name of the permission to request
|
2022-08-18 17:07:34 +02:00
|
|
|
* @param {object} permissionValue - The value of the permission to request
|
2022-03-14 19:26:02 +01:00
|
|
|
* @returns {(permissionName:string) => PermissionLabelObject}
|
|
|
|
*/
|
2022-08-18 17:07:34 +02:00
|
|
|
export const getPermissionDescription = (
|
|
|
|
t,
|
|
|
|
permissionName,
|
|
|
|
permissionValue,
|
|
|
|
) => {
|
2022-03-14 19:26:02 +01:00
|
|
|
let value = PERMISSION_DESCRIPTIONS[UNKNOWN_PERMISSION];
|
|
|
|
|
|
|
|
if (Object.hasOwnProperty.call(PERMISSION_DESCRIPTIONS, permissionName)) {
|
|
|
|
value = PERMISSION_DESCRIPTIONS[permissionName];
|
|
|
|
}
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
for (const namespace of Object.keys(PermissionNamespaces)) {
|
|
|
|
if (permissionName.startsWith(namespace)) {
|
|
|
|
value = PERMISSION_DESCRIPTIONS[PermissionNamespaces[namespace]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
|
2022-08-18 17:07:34 +02:00
|
|
|
return { ...value, label: value.label(t, permissionName, permissionValue) };
|
2022-03-14 19:26:02 +01:00
|
|
|
};
|