-
Notifications
You must be signed in to change notification settings - Fork 647
Expand file tree
/
Copy pathindex.ts
More file actions
149 lines (143 loc) · 6.16 KB
/
index.ts
File metadata and controls
149 lines (143 loc) · 6.16 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import type { PermissionConstraint } from '@metamask/permission-controller';
import { HandlerType } from '@metamask/snaps-utils';
import type { Json } from '@metamask/utils';
import { assetsEndowmentBuilder, getAssetsCaveatMapper } from './assets';
import {
createMaxRequestTimeMapper,
getMaxRequestTimeCaveatMapper,
maxRequestTimeCaveatSpecifications,
} from './caveats';
import {
cronjobCaveatSpecifications,
cronjobEndowmentBuilder,
getCronjobCaveatMapper,
} from './cronjob';
import { ethereumProviderEndowmentBuilder } from './ethereum-provider';
import { homePageEndowmentBuilder } from './home-page';
import {
getKeyringCaveatMapper,
keyringCaveatSpecifications,
keyringEndowmentBuilder,
} from './keyring';
import { lifecycleHooksEndowmentBuilder } from './lifecycle-hooks';
import {
getNameLookupCaveatMapper,
nameLookupCaveatSpecifications,
nameLookupEndowmentBuilder,
} from './name-lookup';
import { networkAccessEndowmentBuilder } from './network-access';
import {
getProtocolCaveatMapper,
protocolCaveatSpecifications,
protocolEndowmentBuilder,
} from './protocol';
import {
getRpcCaveatMapper,
rpcCaveatSpecifications,
rpcEndowmentBuilder,
} from './rpc';
import { settingsPageEndowmentBuilder } from './settings-page';
import {
getSignatureInsightCaveatMapper,
signatureInsightCaveatSpecifications,
signatureInsightEndowmentBuilder,
} from './signature-insight';
import {
getTransactionInsightCaveatMapper,
transactionInsightCaveatSpecifications,
transactionInsightEndowmentBuilder,
} from './transaction-insight';
import { webAssemblyEndowmentBuilder } from './web-assembly';
export const endowmentPermissionBuilders = {
[networkAccessEndowmentBuilder.targetName]: networkAccessEndowmentBuilder,
[transactionInsightEndowmentBuilder.targetName]:
transactionInsightEndowmentBuilder,
[cronjobEndowmentBuilder.targetName]: cronjobEndowmentBuilder,
[ethereumProviderEndowmentBuilder.targetName]:
ethereumProviderEndowmentBuilder,
[rpcEndowmentBuilder.targetName]: rpcEndowmentBuilder,
[webAssemblyEndowmentBuilder.targetName]: webAssemblyEndowmentBuilder,
[nameLookupEndowmentBuilder.targetName]: nameLookupEndowmentBuilder,
[lifecycleHooksEndowmentBuilder.targetName]: lifecycleHooksEndowmentBuilder,
[keyringEndowmentBuilder.targetName]: keyringEndowmentBuilder,
[settingsPageEndowmentBuilder.targetName]: settingsPageEndowmentBuilder,
[protocolEndowmentBuilder.targetName]: protocolEndowmentBuilder,
[homePageEndowmentBuilder.targetName]: homePageEndowmentBuilder,
[signatureInsightEndowmentBuilder.targetName]:
signatureInsightEndowmentBuilder,
[assetsEndowmentBuilder.targetName]: assetsEndowmentBuilder,
} as const;
export const endowmentCaveatSpecifications = {
...cronjobCaveatSpecifications,
...transactionInsightCaveatSpecifications,
...rpcCaveatSpecifications,
...nameLookupCaveatSpecifications,
...keyringCaveatSpecifications,
...signatureInsightCaveatSpecifications,
...maxRequestTimeCaveatSpecifications,
...protocolCaveatSpecifications,
};
export const endowmentCaveatMappers: Record<
string,
(value: Json) => Pick<PermissionConstraint, 'caveats'>
> = {
[cronjobEndowmentBuilder.targetName]: createMaxRequestTimeMapper(
getCronjobCaveatMapper,
),
[transactionInsightEndowmentBuilder.targetName]: createMaxRequestTimeMapper(
getTransactionInsightCaveatMapper,
),
[rpcEndowmentBuilder.targetName]:
createMaxRequestTimeMapper(getRpcCaveatMapper),
[nameLookupEndowmentBuilder.targetName]: createMaxRequestTimeMapper(
getNameLookupCaveatMapper,
),
[keyringEndowmentBuilder.targetName]: createMaxRequestTimeMapper(
getKeyringCaveatMapper,
),
[protocolEndowmentBuilder.targetName]: createMaxRequestTimeMapper(
getProtocolCaveatMapper,
),
[signatureInsightEndowmentBuilder.targetName]: createMaxRequestTimeMapper(
getSignatureInsightCaveatMapper,
),
[lifecycleHooksEndowmentBuilder.targetName]: getMaxRequestTimeCaveatMapper,
[homePageEndowmentBuilder.targetName]: getMaxRequestTimeCaveatMapper,
[settingsPageEndowmentBuilder.targetName]: getMaxRequestTimeCaveatMapper,
[assetsEndowmentBuilder.targetName]: createMaxRequestTimeMapper(
getAssetsCaveatMapper,
),
};
// We allow null because a permitted handler does not have an endowment
export const handlerEndowments: Record<HandlerType, string | null> = {
[HandlerType.OnRpcRequest]: rpcEndowmentBuilder.targetName,
[HandlerType.OnTransaction]: transactionInsightEndowmentBuilder.targetName,
[HandlerType.OnCronjob]: cronjobEndowmentBuilder.targetName,
[HandlerType.OnNameLookup]: nameLookupEndowmentBuilder.targetName,
[HandlerType.OnInstall]: lifecycleHooksEndowmentBuilder.targetName,
[HandlerType.OnUpdate]: lifecycleHooksEndowmentBuilder.targetName,
[HandlerType.OnStart]: lifecycleHooksEndowmentBuilder.targetName,
[HandlerType.OnActive]: lifecycleHooksEndowmentBuilder.targetName,
[HandlerType.OnInactive]: lifecycleHooksEndowmentBuilder.targetName,
[HandlerType.OnKeyringRequest]: keyringEndowmentBuilder.targetName,
[HandlerType.OnHomePage]: homePageEndowmentBuilder.targetName,
[HandlerType.OnSettingsPage]: settingsPageEndowmentBuilder.targetName,
[HandlerType.OnSignature]: signatureInsightEndowmentBuilder.targetName,
[HandlerType.OnUserInput]: null,
[HandlerType.OnAssetHistoricalPrice]: assetsEndowmentBuilder.targetName,
[HandlerType.OnAssetsLookup]: assetsEndowmentBuilder.targetName,
[HandlerType.OnAssetsConversion]: assetsEndowmentBuilder.targetName,
[HandlerType.OnAssetsMarketData]: assetsEndowmentBuilder.targetName,
[HandlerType.OnProtocolRequest]: protocolEndowmentBuilder.targetName,
[HandlerType.OnClientRequest]: null,
[HandlerType.OnWebSocketEvent]: networkAccessEndowmentBuilder.targetName,
};
export * from './enum';
export { getRpcCaveatOrigins } from './rpc';
export { getSignatureOriginCaveat } from './signature-insight';
export { getTransactionOriginCaveat } from './transaction-insight';
export { getChainIdsCaveat, getLookupMatchersCaveat } from './name-lookup';
export { getKeyringCaveatOrigins } from './keyring';
export { getMaxRequestTimeCaveat } from './caveats';
export { getCronjobCaveatJobs } from './cronjob';
export { getProtocolCaveatScopes } from './protocol';