-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermissions.ts
64 lines (53 loc) · 1.77 KB
/
permissions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { KeyringRpcMethod } from '@metamask/keyring-api';
import config from './config';
import { custodianMetadata } from './lib/custodian-types/custodianMetadata';
export enum InternalMethod {
Onboard = 'authentication.onboard',
ClearAllRequests = 'snap.internal.clearAllRequests',
}
const metamaskPermissions = new Set([
KeyringRpcMethod.ListAccounts,
KeyringRpcMethod.GetAccount,
KeyringRpcMethod.FilterAccountChains,
KeyringRpcMethod.DeleteAccount,
KeyringRpcMethod.ListRequests,
KeyringRpcMethod.GetRequest,
KeyringRpcMethod.SubmitRequest,
]);
const metamask = 'metamask';
export const originPermissions = new Map<string, Set<string>>([]);
originPermissions.set(metamask, metamaskPermissions);
custodianMetadata.forEach((custodian) => {
if (custodian.allowedOnboardingDomains) {
// exclude localhost
if (!config.dev && !custodian.production) {
return;
}
custodian.allowedOnboardingDomains.forEach((domain) => {
// Due to a quirk of the snap SDK, we need to allow the onboarding domain as a bare domain
originPermissions.set(domain, new Set([InternalMethod.Onboard]));
originPermissions.set(
`https://${domain}`,
new Set([InternalMethod.Onboard]),
);
});
}
});
// Add localhost to the originPermissions
const localhostPermissions = new Set([
// Keyring methods
KeyringRpcMethod.ListAccounts,
KeyringRpcMethod.GetAccount,
KeyringRpcMethod.CreateAccount,
KeyringRpcMethod.FilterAccountChains,
KeyringRpcMethod.UpdateAccount,
KeyringRpcMethod.DeleteAccount,
KeyringRpcMethod.ListRequests,
KeyringRpcMethod.GetRequest,
// Custom methods
InternalMethod.Onboard,
InternalMethod.ClearAllRequests,
]);
if (config.dev) {
originPermissions.set('http://localhost:8000', localhostPermissions);
}