Skip to content

Commit c0ae284

Browse files
Fix lint
1 parent d02653f commit c0ae284

File tree

2 files changed

+50
-31
lines changed

2 files changed

+50
-31
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './middleware';
1+
export * from './middleware';

packages/snaps-rpc-methods/src/preinstalled/middleware.ts

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,81 @@
11
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';
2-
import { PermissionConstraint, RequestedPermissions } from '@metamask/permission-controller';
2+
import type {
3+
PermissionConstraint,
4+
RequestedPermissions,
5+
} from '@metamask/permission-controller';
6+
import { isEqual } from '@metamask/snaps-utils';
37
import { hasProperty, type Json, type JsonRpcParams } from '@metamask/utils';
8+
49
import { SnapEndowments } from '../endowments';
5-
import { isEqual } from '@metamask/snaps-utils';
610

7-
export interface PreinstalledSnapsMiddlewareHooks {
8-
getPermittedEvmAccounts: () => string[];
9-
getAllEvmAccounts: () => string[];
10-
getPermissions: () => Record<string, PermissionConstraint> | undefined;
11-
grantPermissions: (permissions: RequestedPermissions) => void;
12-
}
11+
export type PreinstalledSnapsMiddlewareHooks = {
12+
getPermittedEvmAccounts: () => string[];
13+
getAllEvmAccounts: () => string[];
14+
getPermissions: () => Record<string, PermissionConstraint> | undefined;
15+
grantPermissions: (permissions: RequestedPermissions) => void;
16+
};
1317

1418
/**
1519
* Creates a middleware that automatically grants permissions to preinstalled Snaps
1620
* that want to use the Ethereum provider endowment.
1721
*
1822
* @param hooks - The hooks used by the middleware.
23+
* @param hooks.getPermittedEvmAccounts
24+
* @param hooks.getAllEvmAccounts
25+
* @param hooks.getPermissions
26+
* @param hooks.grantPermissions
1927
* @returns The middleware.
2028
*/
21-
export function createPreinstalledSnapsMiddleware(
22-
{ getPermittedEvmAccounts, getAllEvmAccounts, getPermissions, grantPermissions }: PreinstalledSnapsMiddlewareHooks,
23-
): JsonRpcMiddleware<JsonRpcParams, Json> {
29+
export function createPreinstalledSnapsMiddleware({
30+
getPermittedEvmAccounts,
31+
getAllEvmAccounts,
32+
getPermissions,
33+
grantPermissions,
34+
}: PreinstalledSnapsMiddlewareHooks): JsonRpcMiddleware<JsonRpcParams, Json> {
2435
return function methodMiddleware(request, _response, next, _end) {
25-
if (!request.method.startsWith("wallet") && !request.method.startsWith("eth")) {
26-
return next();
36+
if (
37+
!request.method.startsWith('wallet') &&
38+
!request.method.startsWith('eth')
39+
) {
40+
return next();
2741
}
2842

2943
const permissions = getPermissions();
3044

31-
if (!permissions || !hasProperty(permissions, SnapEndowments.EthereumProvider)) {
32-
return next();
45+
if (
46+
!permissions ||
47+
!hasProperty(permissions, SnapEndowments.EthereumProvider)
48+
) {
49+
return next();
3350
}
3451

3552
const evmAccounts = getAllEvmAccounts();
3653
const existingEvmAccounts = getPermittedEvmAccounts();
3754

3855
if (isEqual(evmAccounts, existingEvmAccounts)) {
39-
return next();
56+
return next();
4057
}
4158

4259
grantPermissions({
43-
'endowment:caip25': {
44-
caveats: [
45-
{
46-
type: 'authorizedScopes',
47-
value: {
48-
requiredScopes: {},
49-
optionalScopes: {
50-
'wallet:eip155': {
51-
accounts: evmAccounts.map(account => `wallet:eip155:${account}`),
52-
},
53-
},
54-
sessionProperties: {},
55-
isMultichainOrigin: false,
60+
'endowment:caip25': {
61+
caveats: [
62+
{
63+
type: 'authorizedScopes',
64+
value: {
65+
requiredScopes: {},
66+
optionalScopes: {
67+
'wallet:eip155': {
68+
accounts: evmAccounts.map(
69+
(account) => `wallet:eip155:${account}`,
70+
),
5671
},
5772
},
58-
],
73+
sessionProperties: {},
74+
isMultichainOrigin: false,
75+
},
5976
},
77+
],
78+
},
6079
});
6180

6281
return next();

0 commit comments

Comments
 (0)