-
Notifications
You must be signed in to change notification settings - Fork 542
/
index.ts
66 lines (60 loc) · 2.3 KB
/
index.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
65
66
import { PermissionConstraint } from '@metamask/permission-controller';
import { HandlerType } from '@metamask/snaps-utils';
import { Json } from '@metamask/utils';
import {
cronjobCaveatSpecifications,
cronjobEndowmentBuilder,
getCronjobCaveatMapper,
} from './cronjob';
import { ethereumProviderEndowmentBuilder } from './ethereum-provider';
import {
keyringEndowmentBuilder,
keyringCaveatSpecifications,
getKeyringCaveatMapper,
} from './keyring';
import { longRunningEndowmentBuilder } from './long-running';
import { networkAccessEndowmentBuilder } from './network-access';
import {
getRpcCaveatMapper,
rpcCaveatSpecifications,
rpcEndowmentBuilder,
} from './rpc';
import {
getTransactionInsightCaveatMapper,
transactionInsightCaveatSpecifications,
transactionInsightEndowmentBuilder,
} from './transaction-insight';
export const endowmentPermissionBuilders = {
[networkAccessEndowmentBuilder.targetKey]: networkAccessEndowmentBuilder,
[longRunningEndowmentBuilder.targetKey]: longRunningEndowmentBuilder,
[transactionInsightEndowmentBuilder.targetKey]:
transactionInsightEndowmentBuilder,
[keyringEndowmentBuilder.targetKey]: keyringEndowmentBuilder,
[cronjobEndowmentBuilder.targetKey]: cronjobEndowmentBuilder,
[ethereumProviderEndowmentBuilder.targetKey]:
ethereumProviderEndowmentBuilder,
[rpcEndowmentBuilder.targetKey]: rpcEndowmentBuilder,
} as const;
export const endowmentCaveatSpecifications = {
...keyringCaveatSpecifications,
...cronjobCaveatSpecifications,
...transactionInsightCaveatSpecifications,
...rpcCaveatSpecifications,
};
export const endowmentCaveatMappers: Record<
string,
(value: Json) => Pick<PermissionConstraint, 'caveats'>
> = {
[keyringEndowmentBuilder.targetKey]: getKeyringCaveatMapper,
[cronjobEndowmentBuilder.targetKey]: getCronjobCaveatMapper,
[transactionInsightEndowmentBuilder.targetKey]:
getTransactionInsightCaveatMapper,
[rpcEndowmentBuilder.targetKey]: getRpcCaveatMapper,
};
export const handlerEndowments: Record<HandlerType, string> = {
[HandlerType.OnRpcRequest]: rpcEndowmentBuilder.targetKey,
[HandlerType.SnapKeyring]: keyringEndowmentBuilder.targetKey,
[HandlerType.OnTransaction]: transactionInsightEndowmentBuilder.targetKey,
[HandlerType.OnCronjob]: cronjobEndowmentBuilder.targetKey,
};
export * from './enum';