-
Notifications
You must be signed in to change notification settings - Fork 542
/
ethereum-provider.ts
47 lines (42 loc) · 1.44 KB
/
ethereum-provider.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
import {
EndowmentGetterParams,
PermissionSpecificationBuilder,
PermissionType,
ValidPermissionSpecification,
} from '@metamask/permission-controller';
import { SnapEndowments } from './enum';
const permissionName = SnapEndowments.EthereumProvider;
type EthereumProviderEndowmentSpecification = ValidPermissionSpecification<{
permissionType: PermissionType.Endowment;
targetKey: typeof permissionName;
endowmentGetter: (_options?: any) => ['ethereum'];
allowedCaveats: null;
}>;
/**
* `endowment:ethereum-provider` returns the name of the ethereum global browser API.
* This is intended to populate the endowments of the
* SES Compartment in which a Snap executes.
*
* This populates the global scope with an EIP-1193 provider, which DOES NOT implement all legacy functionality exposed to dapps.
*
* @param _builderOptions - Optional specification builder options.
* @returns The specification for the network endowment.
*/
const specificationBuilder: PermissionSpecificationBuilder<
PermissionType.Endowment,
any,
EthereumProviderEndowmentSpecification
> = (_builderOptions?: any) => {
return {
permissionType: PermissionType.Endowment,
targetKey: permissionName,
allowedCaveats: null,
endowmentGetter: (_getterOptions?: EndowmentGetterParams) => {
return ['ethereum'];
},
};
};
export const ethereumProviderEndowmentBuilder = Object.freeze({
targetKey: permissionName,
specificationBuilder,
} as const);