@metamask/gator-permissions-controller 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/LICENSE +20 -0
- package/README.md +38 -0
- package/dist/GatorPermissionsController.cjs +240 -0
- package/dist/GatorPermissionsController.cjs.map +1 -0
- package/dist/GatorPermissionsController.d.cts +139 -0
- package/dist/GatorPermissionsController.d.cts.map +1 -0
- package/dist/GatorPermissionsController.d.mts +139 -0
- package/dist/GatorPermissionsController.d.mts.map +1 -0
- package/dist/GatorPermissionsController.mjs +236 -0
- package/dist/GatorPermissionsController.mjs.map +1 -0
- package/dist/errors.cjs +54 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +40 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +40 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +46 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +12 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.cjs +10 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +7 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +7 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs +7 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/test/mocks.cjs +209 -0
- package/dist/test/mocks.cjs.map +1 -0
- package/dist/test/mocks.d.cts +34 -0
- package/dist/test/mocks.d.cts.map +1 -0
- package/dist/test/mocks.d.mts +34 -0
- package/dist/test/mocks.d.mts.map +1 -0
- package/dist/test/mocks.mjs +200 -0
- package/dist/test/mocks.mjs.map +1 -0
- package/dist/types.cjs +24 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +149 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +149 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +21 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.cjs +46 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +16 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +16 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +41 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +85 -0
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { PermissionTypes, Signer, BasePermission, NativeTokenStreamPermission, NativeTokenPeriodicPermission, Erc20TokenStreamPermission, Erc20TokenPeriodicPermission, Rule, MetaMaskBasePermissionData } from "@metamask/7715-permission-types";
|
|
2
|
+
import type { Hex } from "@metamask/utils";
|
|
3
|
+
/**
|
|
4
|
+
* Enum for the error codes of the gator permissions controller.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum GatorPermissionsControllerErrorCode {
|
|
7
|
+
GatorPermissionsFetchError = "gator-permissions-fetch-error",
|
|
8
|
+
GatorPermissionsNotEnabled = "gator-permissions-not-enabled",
|
|
9
|
+
GatorPermissionsProviderError = "gator-permissions-provider-error",
|
|
10
|
+
GatorPermissionsMapSerializationError = "gator-permissions-map-serialization-error"
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Enum for the RPC methods of the gator permissions provider snap.
|
|
14
|
+
*/
|
|
15
|
+
export declare enum GatorPermissionsSnapRpcMethod {
|
|
16
|
+
/**
|
|
17
|
+
* This method is used by the metamask to request a permissions provider to get granted permissions for all sites.
|
|
18
|
+
*/
|
|
19
|
+
PermissionProviderGetGrantedPermissions = "permissionsProvider_getGrantedPermissions"
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Represents a custom permission that are not of the standard ERC-7715 permission types.
|
|
23
|
+
*/
|
|
24
|
+
export type CustomPermission = BasePermission & {
|
|
25
|
+
type: 'custom';
|
|
26
|
+
data: MetaMaskBasePermissionData & Record<string, unknown>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Represents the type of the ERC-7715 permissions that can be granted including custom permissions.
|
|
30
|
+
*/
|
|
31
|
+
export type PermissionTypesWithCustom = PermissionTypes | CustomPermission;
|
|
32
|
+
/**
|
|
33
|
+
* Represents a ERC-7715 permission request.
|
|
34
|
+
*
|
|
35
|
+
* @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.
|
|
36
|
+
* @template Permission - The type of the permission provided.
|
|
37
|
+
*/
|
|
38
|
+
export type PermissionRequest<TSigner extends Signer, TPermission extends PermissionTypesWithCustom> = {
|
|
39
|
+
/**
|
|
40
|
+
* hex-encoding of uint256 defined the chain with EIP-155
|
|
41
|
+
*/
|
|
42
|
+
chainId: Hex;
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* The account being targeted for this permission request.
|
|
46
|
+
* It is optional to let the user choose which account to grant permission from.
|
|
47
|
+
*/
|
|
48
|
+
address?: Hex;
|
|
49
|
+
/**
|
|
50
|
+
* An account that is associated with the recipient of the granted 7715 permission or alternatively the wallet will manage the session.
|
|
51
|
+
*/
|
|
52
|
+
signer: TSigner;
|
|
53
|
+
/**
|
|
54
|
+
* Defines the allowed behavior the signer can do on behalf of the account.
|
|
55
|
+
*/
|
|
56
|
+
permission: TPermission;
|
|
57
|
+
rules?: Rule[] | null;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Represents a ERC-7715 permission response.
|
|
61
|
+
*
|
|
62
|
+
* @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.
|
|
63
|
+
* @template Permission - The type of the permission provided.
|
|
64
|
+
*/
|
|
65
|
+
export type PermissionResponse<TSigner extends Signer, TPermission extends PermissionTypesWithCustom> = PermissionRequest<TSigner, TPermission> & {
|
|
66
|
+
/**
|
|
67
|
+
* Is a catch-all to identify a permission for revoking permissions or submitting
|
|
68
|
+
* Defined in ERC-7710.
|
|
69
|
+
*/
|
|
70
|
+
context: Hex;
|
|
71
|
+
/**
|
|
72
|
+
* The dependencyInfo field is required and contains information needed to deploy accounts.
|
|
73
|
+
* Each entry specifies a factory contract and its associated deployment data.
|
|
74
|
+
* If no account deployment is needed when redeeming the permission, this array must be empty.
|
|
75
|
+
* When non-empty, DApps MUST deploy the accounts by calling the factory contract with factoryData as the calldata.
|
|
76
|
+
* Defined in ERC-4337.
|
|
77
|
+
*/
|
|
78
|
+
dependencyInfo: {
|
|
79
|
+
factory: Hex;
|
|
80
|
+
factoryData: Hex;
|
|
81
|
+
}[];
|
|
82
|
+
/**
|
|
83
|
+
* If the signer type is account then delegationManager is required as defined in ERC-7710.
|
|
84
|
+
*/
|
|
85
|
+
signerMeta: {
|
|
86
|
+
delegationManager: Hex;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Represents a sanitized version of the PermissionResponse type.
|
|
91
|
+
* Some fields have been removed but the fields are still present in profile sync.
|
|
92
|
+
*
|
|
93
|
+
* @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.
|
|
94
|
+
* @template Permission - The type of the permission provided.
|
|
95
|
+
*/
|
|
96
|
+
export type PermissionResponseSanitized<TSigner extends Signer, TPermission extends PermissionTypesWithCustom> = Omit<PermissionResponse<TSigner, TPermission>, 'dependencyInfo' | 'signer' | 'rules'>;
|
|
97
|
+
/**
|
|
98
|
+
* Represents a gator ERC-7715 granted(ie. signed by an user account) permission entry that is stored in profile sync.
|
|
99
|
+
*
|
|
100
|
+
* @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.
|
|
101
|
+
* @template Permission - The type of the permission provided
|
|
102
|
+
*/
|
|
103
|
+
export type StoredGatorPermission<TSigner extends Signer, TPermission extends PermissionTypesWithCustom> = {
|
|
104
|
+
permissionResponse: PermissionResponse<TSigner, TPermission>;
|
|
105
|
+
siteOrigin: string;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Represents a sanitized version of the StoredGatorPermission type. Some fields have been removed but the fields are still present in profile sync.
|
|
109
|
+
*
|
|
110
|
+
* @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.
|
|
111
|
+
* @template Permission - The type of the permission provided.
|
|
112
|
+
*/
|
|
113
|
+
export type StoredGatorPermissionSanitized<TSigner extends Signer, TPermission extends PermissionTypesWithCustom> = {
|
|
114
|
+
permissionResponse: PermissionResponseSanitized<TSigner, TPermission>;
|
|
115
|
+
siteOrigin: string;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Represents a map of gator permissions by chainId and permission type.
|
|
119
|
+
*/
|
|
120
|
+
export type GatorPermissionsMap = {
|
|
121
|
+
'native-token-stream': {
|
|
122
|
+
[chainId: Hex]: StoredGatorPermissionSanitized<Signer, NativeTokenStreamPermission>[];
|
|
123
|
+
};
|
|
124
|
+
'native-token-periodic': {
|
|
125
|
+
[chainId: Hex]: StoredGatorPermissionSanitized<Signer, NativeTokenPeriodicPermission>[];
|
|
126
|
+
};
|
|
127
|
+
'erc20-token-stream': {
|
|
128
|
+
[chainId: Hex]: StoredGatorPermissionSanitized<Signer, Erc20TokenStreamPermission>[];
|
|
129
|
+
};
|
|
130
|
+
'erc20-token-periodic': {
|
|
131
|
+
[chainId: Hex]: StoredGatorPermissionSanitized<Signer, Erc20TokenPeriodicPermission>[];
|
|
132
|
+
};
|
|
133
|
+
other: {
|
|
134
|
+
[chainId: Hex]: StoredGatorPermissionSanitized<Signer, CustomPermission>[];
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Represents the supported permission type(e.g. 'native-token-stream', 'native-token-periodic', 'erc20-token-stream', 'erc20-token-periodic') of the gator permissions map.
|
|
139
|
+
*/
|
|
140
|
+
export type SupportedGatorPermissionType = keyof GatorPermissionsMap;
|
|
141
|
+
/**
|
|
142
|
+
* Represents a map of gator permissions for a given permission type with key of chainId. The value being an array of gator permissions for that chainId.
|
|
143
|
+
*/
|
|
144
|
+
export type GatorPermissionsMapByPermissionType<TPermissionType extends SupportedGatorPermissionType> = GatorPermissionsMap[TPermissionType];
|
|
145
|
+
/**
|
|
146
|
+
* Represents an array of gator permissions for a given permission type and chainId.
|
|
147
|
+
*/
|
|
148
|
+
export type GatorPermissionsListByPermissionTypeAndChainId<TPermissionType extends SupportedGatorPermissionType> = GatorPermissionsMap[TPermissionType][Hex];
|
|
149
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,MAAM,EACN,cAAc,EACd,2BAA2B,EAC3B,6BAA6B,EAC7B,0BAA0B,EAC1B,4BAA4B,EAC5B,IAAI,EACJ,0BAA0B,EAC3B,wCAAwC;AACzC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C;;GAEG;AACH,oBAAY,mCAAmC;IAC7C,0BAA0B,kCAAkC;IAC5D,0BAA0B,kCAAkC;IAC5D,6BAA6B,qCAAqC;IAClE,qCAAqC,8CAA8C;CACpF;AAED;;GAEG;AACH,oBAAY,6BAA6B;IACvC;;OAEG;IACH,uCAAuC,8CAA8C;CACtF;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG;IAC9C,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,0BAA0B,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,eAAe,GAAG,gBAAgB,CAAC;AAE3E;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,CAC3B,OAAO,SAAS,MAAM,EACtB,WAAW,SAAS,yBAAyB,IAC3C;IACF;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC;IAEb;;;;OAIG;IACH,OAAO,CA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B,EAAE;QACrB,CAAC,OAAO,EAAE,GAAG,GAAG,8BAA8B,CAC5C,MAAM,EACN,2BAA2B,CAC5B,EAAE,CAAC;KACL,CAAC;IACF,uBAAuB,EAAE;QACvB,CAAC,OAAO,EAAE,GAAG,GAAG,8BAA8B,CAC5C,MAAM,EACN,6BAA6B,CAC9B,EAAE,CAAC;KACL,CAAC;IACF,oBAAoB,EAAE;QACpB,CAAC,OAAO,EAAE,GAAG,GAAG,8BAA8B,CAC5C,MAAM,EACN,0BAA0B,CAC3B,EAAE,CAAC;KACL,CAAC;IACF,sBAAsB,EAAE;QACtB,CAAC,OAAO,EAAE,GAAG,GAAG,8BAA8B,CAC5C,MAAM,EACN,4BAA4B,CAC7B,EAAE,CAAC;KACL,CAAC;IACF,KAAK,EAAE;QACL,CAAC,OAAO,EAAE,GAAG,GAAG,8BAA8B,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAAE,CAAC;KAC5E,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,MAAM,mBAAmB,CAAC;AAErE;;GAEG;AACH,MAAM,MAAM,mCAAmC,CAC7C,eAAe,SAAS,4BAA4B,IAClD,mBAAmB,CAAC,eAAe,CAAC,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,8CAA8C,CACxD,eAAe,SAAS,4BAA4B,IAClD,mBAAmB,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { PermissionTypes, Signer, BasePermission, NativeTokenStreamPermission, NativeTokenPeriodicPermission, Erc20TokenStreamPermission, Erc20TokenPeriodicPermission, Rule, MetaMaskBasePermissionData } from "@metamask/7715-permission-types";
|
|
2
|
+
import type { Hex } from "@metamask/utils";
|
|
3
|
+
/**
|
|
4
|
+
* Enum for the error codes of the gator permissions controller.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum GatorPermissionsControllerErrorCode {
|
|
7
|
+
GatorPermissionsFetchError = "gator-permissions-fetch-error",
|
|
8
|
+
GatorPermissionsNotEnabled = "gator-permissions-not-enabled",
|
|
9
|
+
GatorPermissionsProviderError = "gator-permissions-provider-error",
|
|
10
|
+
GatorPermissionsMapSerializationError = "gator-permissions-map-serialization-error"
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Enum for the RPC methods of the gator permissions provider snap.
|
|
14
|
+
*/
|
|
15
|
+
export declare enum GatorPermissionsSnapRpcMethod {
|
|
16
|
+
/**
|
|
17
|
+
* This method is used by the metamask to request a permissions provider to get granted permissions for all sites.
|
|
18
|
+
*/
|
|
19
|
+
PermissionProviderGetGrantedPermissions = "permissionsProvider_getGrantedPermissions"
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Represents a custom permission that are not of the standard ERC-7715 permission types.
|
|
23
|
+
*/
|
|
24
|
+
export type CustomPermission = BasePermission & {
|
|
25
|
+
type: 'custom';
|
|
26
|
+
data: MetaMaskBasePermissionData & Record<string, unknown>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Represents the type of the ERC-7715 permissions that can be granted including custom permissions.
|
|
30
|
+
*/
|
|
31
|
+
export type PermissionTypesWithCustom = PermissionTypes | CustomPermission;
|
|
32
|
+
/**
|
|
33
|
+
* Represents a ERC-7715 permission request.
|
|
34
|
+
*
|
|
35
|
+
* @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.
|
|
36
|
+
* @template Permission - The type of the permission provided.
|
|
37
|
+
*/
|
|
38
|
+
export type PermissionRequest<TSigner extends Signer, TPermission extends PermissionTypesWithCustom> = {
|
|
39
|
+
/**
|
|
40
|
+
* hex-encoding of uint256 defined the chain with EIP-155
|
|
41
|
+
*/
|
|
42
|
+
chainId: Hex;
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* The account being targeted for this permission request.
|
|
46
|
+
* It is optional to let the user choose which account to grant permission from.
|
|
47
|
+
*/
|
|
48
|
+
address?: Hex;
|
|
49
|
+
/**
|
|
50
|
+
* An account that is associated with the recipient of the granted 7715 permission or alternatively the wallet will manage the session.
|
|
51
|
+
*/
|
|
52
|
+
signer: TSigner;
|
|
53
|
+
/**
|
|
54
|
+
* Defines the allowed behavior the signer can do on behalf of the account.
|
|
55
|
+
*/
|
|
56
|
+
permission: TPermission;
|
|
57
|
+
rules?: Rule[] | null;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Represents a ERC-7715 permission response.
|
|
61
|
+
*
|
|
62
|
+
* @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.
|
|
63
|
+
* @template Permission - The type of the permission provided.
|
|
64
|
+
*/
|
|
65
|
+
export type PermissionResponse<TSigner extends Signer, TPermission extends PermissionTypesWithCustom> = PermissionRequest<TSigner, TPermission> & {
|
|
66
|
+
/**
|
|
67
|
+
* Is a catch-all to identify a permission for revoking permissions or submitting
|
|
68
|
+
* Defined in ERC-7710.
|
|
69
|
+
*/
|
|
70
|
+
context: Hex;
|
|
71
|
+
/**
|
|
72
|
+
* The dependencyInfo field is required and contains information needed to deploy accounts.
|
|
73
|
+
* Each entry specifies a factory contract and its associated deployment data.
|
|
74
|
+
* If no account deployment is needed when redeeming the permission, this array must be empty.
|
|
75
|
+
* When non-empty, DApps MUST deploy the accounts by calling the factory contract with factoryData as the calldata.
|
|
76
|
+
* Defined in ERC-4337.
|
|
77
|
+
*/
|
|
78
|
+
dependencyInfo: {
|
|
79
|
+
factory: Hex;
|
|
80
|
+
factoryData: Hex;
|
|
81
|
+
}[];
|
|
82
|
+
/**
|
|
83
|
+
* If the signer type is account then delegationManager is required as defined in ERC-7710.
|
|
84
|
+
*/
|
|
85
|
+
signerMeta: {
|
|
86
|
+
delegationManager: Hex;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Represents a sanitized version of the PermissionResponse type.
|
|
91
|
+
* Some fields have been removed but the fields are still present in profile sync.
|
|
92
|
+
*
|
|
93
|
+
* @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.
|
|
94
|
+
* @template Permission - The type of the permission provided.
|
|
95
|
+
*/
|
|
96
|
+
export type PermissionResponseSanitized<TSigner extends Signer, TPermission extends PermissionTypesWithCustom> = Omit<PermissionResponse<TSigner, TPermission>, 'dependencyInfo' | 'signer' | 'rules'>;
|
|
97
|
+
/**
|
|
98
|
+
* Represents a gator ERC-7715 granted(ie. signed by an user account) permission entry that is stored in profile sync.
|
|
99
|
+
*
|
|
100
|
+
* @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.
|
|
101
|
+
* @template Permission - The type of the permission provided
|
|
102
|
+
*/
|
|
103
|
+
export type StoredGatorPermission<TSigner extends Signer, TPermission extends PermissionTypesWithCustom> = {
|
|
104
|
+
permissionResponse: PermissionResponse<TSigner, TPermission>;
|
|
105
|
+
siteOrigin: string;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Represents a sanitized version of the StoredGatorPermission type. Some fields have been removed but the fields are still present in profile sync.
|
|
109
|
+
*
|
|
110
|
+
* @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.
|
|
111
|
+
* @template Permission - The type of the permission provided.
|
|
112
|
+
*/
|
|
113
|
+
export type StoredGatorPermissionSanitized<TSigner extends Signer, TPermission extends PermissionTypesWithCustom> = {
|
|
114
|
+
permissionResponse: PermissionResponseSanitized<TSigner, TPermission>;
|
|
115
|
+
siteOrigin: string;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Represents a map of gator permissions by chainId and permission type.
|
|
119
|
+
*/
|
|
120
|
+
export type GatorPermissionsMap = {
|
|
121
|
+
'native-token-stream': {
|
|
122
|
+
[chainId: Hex]: StoredGatorPermissionSanitized<Signer, NativeTokenStreamPermission>[];
|
|
123
|
+
};
|
|
124
|
+
'native-token-periodic': {
|
|
125
|
+
[chainId: Hex]: StoredGatorPermissionSanitized<Signer, NativeTokenPeriodicPermission>[];
|
|
126
|
+
};
|
|
127
|
+
'erc20-token-stream': {
|
|
128
|
+
[chainId: Hex]: StoredGatorPermissionSanitized<Signer, Erc20TokenStreamPermission>[];
|
|
129
|
+
};
|
|
130
|
+
'erc20-token-periodic': {
|
|
131
|
+
[chainId: Hex]: StoredGatorPermissionSanitized<Signer, Erc20TokenPeriodicPermission>[];
|
|
132
|
+
};
|
|
133
|
+
other: {
|
|
134
|
+
[chainId: Hex]: StoredGatorPermissionSanitized<Signer, CustomPermission>[];
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Represents the supported permission type(e.g. 'native-token-stream', 'native-token-periodic', 'erc20-token-stream', 'erc20-token-periodic') of the gator permissions map.
|
|
139
|
+
*/
|
|
140
|
+
export type SupportedGatorPermissionType = keyof GatorPermissionsMap;
|
|
141
|
+
/**
|
|
142
|
+
* Represents a map of gator permissions for a given permission type with key of chainId. The value being an array of gator permissions for that chainId.
|
|
143
|
+
*/
|
|
144
|
+
export type GatorPermissionsMapByPermissionType<TPermissionType extends SupportedGatorPermissionType> = GatorPermissionsMap[TPermissionType];
|
|
145
|
+
/**
|
|
146
|
+
* Represents an array of gator permissions for a given permission type and chainId.
|
|
147
|
+
*/
|
|
148
|
+
export type GatorPermissionsListByPermissionTypeAndChainId<TPermissionType extends SupportedGatorPermissionType> = GatorPermissionsMap[TPermissionType][Hex];
|
|
149
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,MAAM,EACN,cAAc,EACd,2BAA2B,EAC3B,6BAA6B,EAC7B,0BAA0B,EAC1B,4BAA4B,EAC5B,IAAI,EACJ,0BAA0B,EAC3B,wCAAwC;AACzC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C;;GAEG;AACH,oBAAY,mCAAmC;IAC7C,0BAA0B,kCAAkC;IAC5D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;GAEG;AACH,MAAM,MAAM,mCAAmC,CAC7C,eAAe,SAAS,4BAA4B,IAClD,mBAAmB,CAAC,eAAe,CAAC,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,8CAA8C,CACxD,eAAe,SAAS,4BAA4B,IAClD,mBAAmB,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC"}
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum for the error codes of the gator permissions controller.
|
|
3
|
+
*/
|
|
4
|
+
export var GatorPermissionsControllerErrorCode;
|
|
5
|
+
(function (GatorPermissionsControllerErrorCode) {
|
|
6
|
+
GatorPermissionsControllerErrorCode["GatorPermissionsFetchError"] = "gator-permissions-fetch-error";
|
|
7
|
+
GatorPermissionsControllerErrorCode["GatorPermissionsNotEnabled"] = "gator-permissions-not-enabled";
|
|
8
|
+
GatorPermissionsControllerErrorCode["GatorPermissionsProviderError"] = "gator-permissions-provider-error";
|
|
9
|
+
GatorPermissionsControllerErrorCode["GatorPermissionsMapSerializationError"] = "gator-permissions-map-serialization-error";
|
|
10
|
+
})(GatorPermissionsControllerErrorCode || (GatorPermissionsControllerErrorCode = {}));
|
|
11
|
+
/**
|
|
12
|
+
* Enum for the RPC methods of the gator permissions provider snap.
|
|
13
|
+
*/
|
|
14
|
+
export var GatorPermissionsSnapRpcMethod;
|
|
15
|
+
(function (GatorPermissionsSnapRpcMethod) {
|
|
16
|
+
/**
|
|
17
|
+
* This method is used by the metamask to request a permissions provider to get granted permissions for all sites.
|
|
18
|
+
*/
|
|
19
|
+
GatorPermissionsSnapRpcMethod["PermissionProviderGetGrantedPermissions"] = "permissionsProvider_getGrantedPermissions";
|
|
20
|
+
})(GatorPermissionsSnapRpcMethod || (GatorPermissionsSnapRpcMethod = {}));
|
|
21
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,MAAM,CAAN,IAAY,mCAKX;AALD,WAAY,mCAAmC;IAC7C,mGAA4D,CAAA;IAC5D,mGAA4D,CAAA;IAC5D,yGAAkE,CAAA;IAClE,0HAAmF,CAAA;AACrF,CAAC,EALW,mCAAmC,KAAnC,mCAAmC,QAK9C;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,6BAKX;AALD,WAAY,6BAA6B;IACvC;;OAEG;IACH,sHAAqF,CAAA;AACvF,CAAC,EALW,6BAA6B,KAA7B,6BAA6B,QAKxC","sourcesContent":["import type {\n PermissionTypes,\n Signer,\n BasePermission,\n NativeTokenStreamPermission,\n NativeTokenPeriodicPermission,\n Erc20TokenStreamPermission,\n Erc20TokenPeriodicPermission,\n Rule,\n MetaMaskBasePermissionData,\n} from '@metamask/7715-permission-types';\nimport type { Hex } from '@metamask/utils';\n\n/**\n * Enum for the error codes of the gator permissions controller.\n */\nexport enum GatorPermissionsControllerErrorCode {\n GatorPermissionsFetchError = 'gator-permissions-fetch-error',\n GatorPermissionsNotEnabled = 'gator-permissions-not-enabled',\n GatorPermissionsProviderError = 'gator-permissions-provider-error',\n GatorPermissionsMapSerializationError = 'gator-permissions-map-serialization-error',\n}\n\n/**\n * Enum for the RPC methods of the gator permissions provider snap.\n */\nexport enum GatorPermissionsSnapRpcMethod {\n /**\n * This method is used by the metamask to request a permissions provider to get granted permissions for all sites.\n */\n PermissionProviderGetGrantedPermissions = 'permissionsProvider_getGrantedPermissions',\n}\n\n/**\n * Represents a custom permission that are not of the standard ERC-7715 permission types.\n */\nexport type CustomPermission = BasePermission & {\n type: 'custom';\n data: MetaMaskBasePermissionData & Record<string, unknown>;\n};\n\n/**\n * Represents the type of the ERC-7715 permissions that can be granted including custom permissions.\n */\nexport type PermissionTypesWithCustom = PermissionTypes | CustomPermission;\n\n/**\n * Represents a ERC-7715 permission request.\n *\n * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.\n * @template Permission - The type of the permission provided.\n */\nexport type PermissionRequest<\n TSigner extends Signer,\n TPermission extends PermissionTypesWithCustom,\n> = {\n /**\n * hex-encoding of uint256 defined the chain with EIP-155\n */\n chainId: Hex;\n\n /**\n *\n * The account being targeted for this permission request.\n * It is optional to let the user choose which account to grant permission from.\n */\n address?: Hex;\n\n /**\n * An account that is associated with the recipient of the granted 7715 permission or alternatively the wallet will manage the session.\n */\n signer: TSigner;\n\n /**\n * Defines the allowed behavior the signer can do on behalf of the account.\n */\n permission: TPermission;\n\n rules?: Rule[] | null;\n};\n\n/**\n * Represents a ERC-7715 permission response.\n *\n * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.\n * @template Permission - The type of the permission provided.\n */\nexport type PermissionResponse<\n TSigner extends Signer,\n TPermission extends PermissionTypesWithCustom,\n> = PermissionRequest<TSigner, TPermission> & {\n /**\n * Is a catch-all to identify a permission for revoking permissions or submitting\n * Defined in ERC-7710.\n */\n context: Hex;\n\n /**\n * The dependencyInfo field is required and contains information needed to deploy accounts.\n * Each entry specifies a factory contract and its associated deployment data.\n * If no account deployment is needed when redeeming the permission, this array must be empty.\n * When non-empty, DApps MUST deploy the accounts by calling the factory contract with factoryData as the calldata.\n * Defined in ERC-4337.\n */\n dependencyInfo: {\n factory: Hex;\n factoryData: Hex;\n }[];\n\n /**\n * If the signer type is account then delegationManager is required as defined in ERC-7710.\n */\n signerMeta: {\n delegationManager: Hex;\n };\n};\n\n/**\n * Represents a sanitized version of the PermissionResponse type.\n * Some fields have been removed but the fields are still present in profile sync.\n *\n * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.\n * @template Permission - The type of the permission provided.\n */\nexport type PermissionResponseSanitized<\n TSigner extends Signer,\n TPermission extends PermissionTypesWithCustom,\n> = Omit<\n PermissionResponse<TSigner, TPermission>,\n 'dependencyInfo' | 'signer' | 'rules'\n>;\n\n/**\n * Represents a gator ERC-7715 granted(ie. signed by an user account) permission entry that is stored in profile sync.\n *\n * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.\n * @template Permission - The type of the permission provided\n */\nexport type StoredGatorPermission<\n TSigner extends Signer,\n TPermission extends PermissionTypesWithCustom,\n> = {\n permissionResponse: PermissionResponse<TSigner, TPermission>;\n siteOrigin: string;\n};\n\n/**\n * Represents a sanitized version of the StoredGatorPermission type. Some fields have been removed but the fields are still present in profile sync.\n *\n * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.\n * @template Permission - The type of the permission provided.\n */\nexport type StoredGatorPermissionSanitized<\n TSigner extends Signer,\n TPermission extends PermissionTypesWithCustom,\n> = {\n permissionResponse: PermissionResponseSanitized<TSigner, TPermission>;\n siteOrigin: string;\n};\n\n/**\n * Represents a map of gator permissions by chainId and permission type.\n */\nexport type GatorPermissionsMap = {\n 'native-token-stream': {\n [chainId: Hex]: StoredGatorPermissionSanitized<\n Signer,\n NativeTokenStreamPermission\n >[];\n };\n 'native-token-periodic': {\n [chainId: Hex]: StoredGatorPermissionSanitized<\n Signer,\n NativeTokenPeriodicPermission\n >[];\n };\n 'erc20-token-stream': {\n [chainId: Hex]: StoredGatorPermissionSanitized<\n Signer,\n Erc20TokenStreamPermission\n >[];\n };\n 'erc20-token-periodic': {\n [chainId: Hex]: StoredGatorPermissionSanitized<\n Signer,\n Erc20TokenPeriodicPermission\n >[];\n };\n other: {\n [chainId: Hex]: StoredGatorPermissionSanitized<Signer, CustomPermission>[];\n };\n};\n\n/**\n * Represents the supported permission type(e.g. 'native-token-stream', 'native-token-periodic', 'erc20-token-stream', 'erc20-token-periodic') of the gator permissions map.\n */\nexport type SupportedGatorPermissionType = keyof GatorPermissionsMap;\n\n/**\n * Represents a map of gator permissions for a given permission type with key of chainId. The value being an array of gator permissions for that chainId.\n */\nexport type GatorPermissionsMapByPermissionType<\n TPermissionType extends SupportedGatorPermissionType,\n> = GatorPermissionsMap[TPermissionType];\n\n/**\n * Represents an array of gator permissions for a given permission type and chainId.\n */\nexport type GatorPermissionsListByPermissionTypeAndChainId<\n TPermissionType extends SupportedGatorPermissionType,\n> = GatorPermissionsMap[TPermissionType][Hex];\n"]}
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeGatorPermissionsMap = exports.serializeGatorPermissionsMap = void 0;
|
|
4
|
+
const errors_1 = require("./errors.cjs");
|
|
5
|
+
const logger_1 = require("./logger.cjs");
|
|
6
|
+
/**
|
|
7
|
+
* Serializes a gator permissions map to a string.
|
|
8
|
+
*
|
|
9
|
+
* @param gatorPermissionsMap - The gator permissions map to serialize.
|
|
10
|
+
* @returns The serialized gator permissions map.
|
|
11
|
+
*/
|
|
12
|
+
function serializeGatorPermissionsMap(gatorPermissionsMap) {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.stringify(gatorPermissionsMap);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
(0, logger_1.utilsLog)('Failed to serialize gator permissions map', error);
|
|
18
|
+
throw new errors_1.GatorPermissionsMapSerializationError({
|
|
19
|
+
cause: error,
|
|
20
|
+
message: 'Failed to serialize gator permissions map',
|
|
21
|
+
data: gatorPermissionsMap,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.serializeGatorPermissionsMap = serializeGatorPermissionsMap;
|
|
26
|
+
/**
|
|
27
|
+
* Deserializes a gator permissions map from a string.
|
|
28
|
+
*
|
|
29
|
+
* @param gatorPermissionsMap - The gator permissions map to deserialize.
|
|
30
|
+
* @returns The deserialized gator permissions map.
|
|
31
|
+
*/
|
|
32
|
+
function deserializeGatorPermissionsMap(gatorPermissionsMap) {
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(gatorPermissionsMap);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
(0, logger_1.utilsLog)('Failed to deserialize gator permissions map', error);
|
|
38
|
+
throw new errors_1.GatorPermissionsMapSerializationError({
|
|
39
|
+
cause: error,
|
|
40
|
+
message: 'Failed to deserialize gator permissions map',
|
|
41
|
+
data: gatorPermissionsMap,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.deserializeGatorPermissionsMap = deserializeGatorPermissionsMap;
|
|
46
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,yCAAiE;AACjE,yCAAoC;AAGpC;;;;;GAKG;AACH,SAAgB,4BAA4B,CAC1C,mBAAwC;IAExC,IAAI;QACF,OAAO,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;KAC5C;IAAC,OAAO,KAAK,EAAE;QACd,IAAA,iBAAQ,EAAC,2CAA2C,EAAE,KAAK,CAAC,CAAC;QAC7D,MAAM,IAAI,8CAAqC,CAAC;YAC9C,KAAK,EAAE,KAAc;YACrB,OAAO,EAAE,2CAA2C;YACpD,IAAI,EAAE,mBAAmB;SAC1B,CAAC,CAAC;KACJ;AACH,CAAC;AAbD,oEAaC;AAED;;;;;GAKG;AACH,SAAgB,8BAA8B,CAC5C,mBAA2B;IAE3B,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;KACxC;IAAC,OAAO,KAAK,EAAE;QACd,IAAA,iBAAQ,EAAC,6CAA6C,EAAE,KAAK,CAAC,CAAC;QAC/D,MAAM,IAAI,8CAAqC,CAAC;YAC9C,KAAK,EAAE,KAAc;YACrB,OAAO,EAAE,6CAA6C;YACtD,IAAI,EAAE,mBAAmB;SAC1B,CAAC,CAAC;KACJ;AACH,CAAC;AAbD,wEAaC","sourcesContent":["import { GatorPermissionsMapSerializationError } from './errors';\nimport { utilsLog } from './logger';\nimport type { GatorPermissionsMap } from './types';\n\n/**\n * Serializes a gator permissions map to a string.\n *\n * @param gatorPermissionsMap - The gator permissions map to serialize.\n * @returns The serialized gator permissions map.\n */\nexport function serializeGatorPermissionsMap(\n gatorPermissionsMap: GatorPermissionsMap,\n): string {\n try {\n return JSON.stringify(gatorPermissionsMap);\n } catch (error) {\n utilsLog('Failed to serialize gator permissions map', error);\n throw new GatorPermissionsMapSerializationError({\n cause: error as Error,\n message: 'Failed to serialize gator permissions map',\n data: gatorPermissionsMap,\n });\n }\n}\n\n/**\n * Deserializes a gator permissions map from a string.\n *\n * @param gatorPermissionsMap - The gator permissions map to deserialize.\n * @returns The deserialized gator permissions map.\n */\nexport function deserializeGatorPermissionsMap(\n gatorPermissionsMap: string,\n): GatorPermissionsMap {\n try {\n return JSON.parse(gatorPermissionsMap);\n } catch (error) {\n utilsLog('Failed to deserialize gator permissions map', error);\n throw new GatorPermissionsMapSerializationError({\n cause: error as Error,\n message: 'Failed to deserialize gator permissions map',\n data: gatorPermissionsMap,\n });\n }\n}\n"]}
|
package/dist/utils.d.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { GatorPermissionsMap } from "./types.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* Serializes a gator permissions map to a string.
|
|
4
|
+
*
|
|
5
|
+
* @param gatorPermissionsMap - The gator permissions map to serialize.
|
|
6
|
+
* @returns The serialized gator permissions map.
|
|
7
|
+
*/
|
|
8
|
+
export declare function serializeGatorPermissionsMap(gatorPermissionsMap: GatorPermissionsMap): string;
|
|
9
|
+
/**
|
|
10
|
+
* Deserializes a gator permissions map from a string.
|
|
11
|
+
*
|
|
12
|
+
* @param gatorPermissionsMap - The gator permissions map to deserialize.
|
|
13
|
+
* @returns The deserialized gator permissions map.
|
|
14
|
+
*/
|
|
15
|
+
export declare function deserializeGatorPermissionsMap(gatorPermissionsMap: string): GatorPermissionsMap;
|
|
16
|
+
//# sourceMappingURL=utils.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAgB;AAEnD;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,mBAAmB,EAAE,mBAAmB,GACvC,MAAM,CAWR;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,mBAAmB,EAAE,MAAM,GAC1B,mBAAmB,CAWrB"}
|
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { GatorPermissionsMap } from "./types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Serializes a gator permissions map to a string.
|
|
4
|
+
*
|
|
5
|
+
* @param gatorPermissionsMap - The gator permissions map to serialize.
|
|
6
|
+
* @returns The serialized gator permissions map.
|
|
7
|
+
*/
|
|
8
|
+
export declare function serializeGatorPermissionsMap(gatorPermissionsMap: GatorPermissionsMap): string;
|
|
9
|
+
/**
|
|
10
|
+
* Deserializes a gator permissions map from a string.
|
|
11
|
+
*
|
|
12
|
+
* @param gatorPermissionsMap - The gator permissions map to deserialize.
|
|
13
|
+
* @returns The deserialized gator permissions map.
|
|
14
|
+
*/
|
|
15
|
+
export declare function deserializeGatorPermissionsMap(gatorPermissionsMap: string): GatorPermissionsMap;
|
|
16
|
+
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAgB;AAEnD;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,mBAAmB,EAAE,mBAAmB,GACvC,MAAM,CAWR;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,mBAAmB,EAAE,MAAM,GAC1B,mBAAmB,CAWrB"}
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { GatorPermissionsMapSerializationError } from "./errors.mjs";
|
|
2
|
+
import { utilsLog } from "./logger.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Serializes a gator permissions map to a string.
|
|
5
|
+
*
|
|
6
|
+
* @param gatorPermissionsMap - The gator permissions map to serialize.
|
|
7
|
+
* @returns The serialized gator permissions map.
|
|
8
|
+
*/
|
|
9
|
+
export function serializeGatorPermissionsMap(gatorPermissionsMap) {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.stringify(gatorPermissionsMap);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
utilsLog('Failed to serialize gator permissions map', error);
|
|
15
|
+
throw new GatorPermissionsMapSerializationError({
|
|
16
|
+
cause: error,
|
|
17
|
+
message: 'Failed to serialize gator permissions map',
|
|
18
|
+
data: gatorPermissionsMap,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Deserializes a gator permissions map from a string.
|
|
24
|
+
*
|
|
25
|
+
* @param gatorPermissionsMap - The gator permissions map to deserialize.
|
|
26
|
+
* @returns The deserialized gator permissions map.
|
|
27
|
+
*/
|
|
28
|
+
export function deserializeGatorPermissionsMap(gatorPermissionsMap) {
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(gatorPermissionsMap);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
utilsLog('Failed to deserialize gator permissions map', error);
|
|
34
|
+
throw new GatorPermissionsMapSerializationError({
|
|
35
|
+
cause: error,
|
|
36
|
+
message: 'Failed to deserialize gator permissions map',
|
|
37
|
+
data: gatorPermissionsMap,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qCAAqC,EAAE,qBAAiB;AACjE,OAAO,EAAE,QAAQ,EAAE,qBAAiB;AAGpC;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAC1C,mBAAwC;IAExC,IAAI;QACF,OAAO,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;KAC5C;IAAC,OAAO,KAAK,EAAE;QACd,QAAQ,CAAC,2CAA2C,EAAE,KAAK,CAAC,CAAC;QAC7D,MAAM,IAAI,qCAAqC,CAAC;YAC9C,KAAK,EAAE,KAAc;YACrB,OAAO,EAAE,2CAA2C;YACpD,IAAI,EAAE,mBAAmB;SAC1B,CAAC,CAAC;KACJ;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B,CAC5C,mBAA2B;IAE3B,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;KACxC;IAAC,OAAO,KAAK,EAAE;QACd,QAAQ,CAAC,6CAA6C,EAAE,KAAK,CAAC,CAAC;QAC/D,MAAM,IAAI,qCAAqC,CAAC;YAC9C,KAAK,EAAE,KAAc;YACrB,OAAO,EAAE,6CAA6C;YACtD,IAAI,EAAE,mBAAmB;SAC1B,CAAC,CAAC;KACJ;AACH,CAAC","sourcesContent":["import { GatorPermissionsMapSerializationError } from './errors';\nimport { utilsLog } from './logger';\nimport type { GatorPermissionsMap } from './types';\n\n/**\n * Serializes a gator permissions map to a string.\n *\n * @param gatorPermissionsMap - The gator permissions map to serialize.\n * @returns The serialized gator permissions map.\n */\nexport function serializeGatorPermissionsMap(\n gatorPermissionsMap: GatorPermissionsMap,\n): string {\n try {\n return JSON.stringify(gatorPermissionsMap);\n } catch (error) {\n utilsLog('Failed to serialize gator permissions map', error);\n throw new GatorPermissionsMapSerializationError({\n cause: error as Error,\n message: 'Failed to serialize gator permissions map',\n data: gatorPermissionsMap,\n });\n }\n}\n\n/**\n * Deserializes a gator permissions map from a string.\n *\n * @param gatorPermissionsMap - The gator permissions map to deserialize.\n * @returns The deserialized gator permissions map.\n */\nexport function deserializeGatorPermissionsMap(\n gatorPermissionsMap: string,\n): GatorPermissionsMap {\n try {\n return JSON.parse(gatorPermissionsMap);\n } catch (error) {\n utilsLog('Failed to deserialize gator permissions map', error);\n throw new GatorPermissionsMapSerializationError({\n cause: error as Error,\n message: 'Failed to deserialize gator permissions map',\n data: gatorPermissionsMap,\n });\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metamask/gator-permissions-controller",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Controller for managing gator permissions with profile sync integration",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"MetaMask",
|
|
7
|
+
"Ethereum"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/MetaMask/core/tree/main/packages/gator-permissions-controller#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/MetaMask/core/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/MetaMask/core.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/index.d.mts",
|
|
23
|
+
"default": "./dist/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/index.d.cts",
|
|
27
|
+
"default": "./dist/index.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"main": "./dist/index.cjs",
|
|
33
|
+
"types": "./dist/index.d.cts",
|
|
34
|
+
"files": [
|
|
35
|
+
"dist/"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
39
|
+
"build:docs": "typedoc",
|
|
40
|
+
"changelog:update": "../../scripts/update-changelog.sh @metamask/gator-permissions-controller",
|
|
41
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/gator-permissions-controller",
|
|
42
|
+
"publish:preview": "yarn npm publish --tag preview",
|
|
43
|
+
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
44
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
45
|
+
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
46
|
+
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
|
47
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@metamask/7715-permission-types": "^0.3.0",
|
|
51
|
+
"@metamask/base-controller": "^8.3.0",
|
|
52
|
+
"@metamask/snaps-sdk": "^9.0.0",
|
|
53
|
+
"@metamask/snaps-utils": "^11.0.0",
|
|
54
|
+
"@metamask/utils": "^11.4.2"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@lavamoat/allow-scripts": "^3.0.4",
|
|
58
|
+
"@lavamoat/preinstall-always-fail": "^2.1.0",
|
|
59
|
+
"@metamask/auto-changelog": "^3.4.4",
|
|
60
|
+
"@metamask/snaps-controllers": "^14.0.1",
|
|
61
|
+
"@ts-bridge/cli": "^0.6.1",
|
|
62
|
+
"@types/jest": "^27.4.1",
|
|
63
|
+
"deepmerge": "^4.2.2",
|
|
64
|
+
"jest": "^27.5.1",
|
|
65
|
+
"ts-jest": "^27.1.4",
|
|
66
|
+
"typedoc": "^0.24.8",
|
|
67
|
+
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
68
|
+
"typescript": "~5.2.2"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@metamask/snaps-controllers": "^14.0.1"
|
|
72
|
+
},
|
|
73
|
+
"engines": {
|
|
74
|
+
"node": "^18.18 || >=20"
|
|
75
|
+
},
|
|
76
|
+
"publishConfig": {
|
|
77
|
+
"access": "public",
|
|
78
|
+
"registry": "https://registry.npmjs.org/"
|
|
79
|
+
},
|
|
80
|
+
"lavamoat": {
|
|
81
|
+
"allowScripts": {
|
|
82
|
+
"@lavamoat/preinstall-always-fail": false
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|