@metamask/permission-controller 8.0.0 → 9.0.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 +74 -1
- package/dist/Caveat.js +11 -56
- package/dist/Caveat.js.map +1 -1
- package/dist/Caveat.mjs +12 -0
- package/dist/Caveat.mjs.map +1 -0
- package/dist/Permission.js +13 -65
- package/dist/Permission.js.map +1 -1
- package/dist/Permission.mjs +14 -0
- package/dist/Permission.mjs.map +1 -0
- package/dist/PermissionController.js +14 -1294
- package/dist/PermissionController.js.map +1 -1
- package/dist/PermissionController.mjs +15 -0
- package/dist/PermissionController.mjs.map +1 -0
- package/dist/SubjectMetadataController.js +9 -143
- package/dist/SubjectMetadataController.js.map +1 -1
- package/dist/SubjectMetadataController.mjs +10 -0
- package/dist/SubjectMetadataController.mjs.map +1 -0
- package/dist/chunk-4D2RVWNF.mjs +154 -0
- package/dist/chunk-4D2RVWNF.mjs.map +1 -0
- package/dist/chunk-5C5SZO74.mjs +29 -0
- package/dist/chunk-5C5SZO74.mjs.map +1 -0
- package/dist/chunk-5L2IOZE2.js +1393 -0
- package/dist/chunk-5L2IOZE2.js.map +1 -0
- package/dist/chunk-6CID6TBW.js +31 -0
- package/dist/chunk-6CID6TBW.js.map +1 -0
- package/dist/chunk-73M67Z5X.mjs +17 -0
- package/dist/chunk-73M67Z5X.mjs.map +1 -0
- package/dist/chunk-7CTPRFQ3.js +29 -0
- package/dist/chunk-7CTPRFQ3.js.map +1 -0
- package/dist/chunk-AQ35E2HU.js +46 -0
- package/dist/chunk-AQ35E2HU.js.map +1 -0
- package/dist/chunk-BEQEQLRE.mjs +34 -0
- package/dist/chunk-BEQEQLRE.mjs.map +1 -0
- package/dist/chunk-CSAU5B4Q.js +10 -0
- package/dist/chunk-CSAU5B4Q.js.map +1 -0
- package/dist/chunk-CXKOMB77.mjs +1393 -0
- package/dist/chunk-CXKOMB77.mjs.map +1 -0
- package/dist/chunk-EGNDXGRG.js +37 -0
- package/dist/chunk-EGNDXGRG.js.map +1 -0
- package/dist/chunk-FEXS6SJF.mjs +192 -0
- package/dist/chunk-FEXS6SJF.mjs.map +1 -0
- package/dist/chunk-HRDKMOYS.js +17 -0
- package/dist/chunk-HRDKMOYS.js.map +1 -0
- package/dist/chunk-K5R57Y57.js +12 -0
- package/dist/chunk-K5R57Y57.js.map +1 -0
- package/dist/chunk-KVKKNDYV.mjs +12 -0
- package/dist/chunk-KVKKNDYV.mjs.map +1 -0
- package/dist/chunk-N4KQ2BHF.mjs +46 -0
- package/dist/chunk-N4KQ2BHF.mjs.map +1 -0
- package/dist/chunk-ODCVB4BB.mjs +31 -0
- package/dist/chunk-ODCVB4BB.mjs.map +1 -0
- package/dist/chunk-SFKE5HHK.js +154 -0
- package/dist/chunk-SFKE5HHK.js.map +1 -0
- package/dist/chunk-U5LTEXSU.js +192 -0
- package/dist/chunk-U5LTEXSU.js.map +1 -0
- package/dist/chunk-XBFHEZRU.mjs +37 -0
- package/dist/chunk-XBFHEZRU.mjs.map +1 -0
- package/dist/chunk-YRNH4R3G.js +30 -0
- package/dist/chunk-YRNH4R3G.js.map +1 -0
- package/dist/chunk-YVXIWLBE.mjs +30 -0
- package/dist/chunk-YVXIWLBE.mjs.map +1 -0
- package/dist/chunk-ZSTKOCBT.mjs +10 -0
- package/dist/chunk-ZSTKOCBT.mjs.map +1 -0
- package/dist/chunk-ZVO26XPN.js +34 -0
- package/dist/chunk-ZVO26XPN.js.map +1 -0
- package/dist/errors.js +51 -195
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +52 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.js +91 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -0
- package/dist/index.mjs.map +1 -0
- package/dist/permission-middleware.js +8 -63
- package/dist/permission-middleware.js.map +1 -1
- package/dist/permission-middleware.mjs +9 -0
- package/dist/permission-middleware.mjs.map +1 -0
- package/dist/rpc-methods/getPermissions.js +8 -37
- package/dist/rpc-methods/getPermissions.js.map +1 -1
- package/dist/rpc-methods/getPermissions.mjs +9 -0
- package/dist/rpc-methods/getPermissions.mjs.map +1 -0
- package/dist/rpc-methods/index.js +12 -11
- package/dist/rpc-methods/index.js.map +1 -1
- package/dist/rpc-methods/index.mjs +13 -0
- package/dist/rpc-methods/index.mjs.map +1 -0
- package/dist/rpc-methods/requestPermissions.js +9 -54
- package/dist/rpc-methods/requestPermissions.js.map +1 -1
- package/dist/rpc-methods/requestPermissions.mjs +10 -0
- package/dist/rpc-methods/requestPermissions.mjs.map +1 -0
- package/dist/rpc-methods/revokePermissions.js +9 -51
- package/dist/rpc-methods/revokePermissions.js.map +1 -1
- package/dist/rpc-methods/revokePermissions.mjs +10 -0
- package/dist/rpc-methods/revokePermissions.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/Caveat.d.ts.map +1 -0
- package/dist/types/Permission.d.ts.map +1 -0
- package/dist/{PermissionController.d.ts → types/PermissionController.d.ts} +1 -1
- package/dist/types/PermissionController.d.ts.map +1 -0
- package/dist/types/SubjectMetadataController.d.ts.map +1 -0
- package/dist/{errors.d.ts → types/errors.d.ts} +1 -1
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/permission-middleware.d.ts.map +1 -0
- package/dist/types/rpc-methods/getPermissions.d.ts.map +1 -0
- package/dist/types/rpc-methods/index.d.ts.map +1 -0
- package/dist/{rpc-methods → types/rpc-methods}/requestPermissions.d.ts +1 -1
- package/dist/types/rpc-methods/requestPermissions.d.ts.map +1 -0
- package/dist/types/rpc-methods/revokePermissions.d.ts.map +1 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/utils.js +7 -9
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +8 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +17 -7
- package/dist/Caveat.d.ts.map +0 -1
- package/dist/Permission.d.ts.map +0 -1
- package/dist/PermissionController.d.ts.map +0 -1
- package/dist/SubjectMetadataController.d.ts.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/permission-middleware.d.ts.map +0 -1
- package/dist/rpc-methods/getPermissions.d.ts.map +0 -1
- package/dist/rpc-methods/index.d.ts.map +0 -1
- package/dist/rpc-methods/requestPermissions.d.ts.map +0 -1
- package/dist/rpc-methods/revokePermissions.d.ts.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- /package/dist/{Caveat.d.ts → types/Caveat.d.ts} +0 -0
- /package/dist/{Permission.d.ts → types/Permission.d.ts} +0 -0
- /package/dist/{SubjectMetadataController.d.ts → types/SubjectMetadataController.d.ts} +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{permission-middleware.d.ts → types/permission-middleware.d.ts} +0 -0
- /package/dist/{rpc-methods → types/rpc-methods}/getPermissions.d.ts +0 -0
- /package/dist/{rpc-methods → types/rpc-methods}/index.d.ts +0 -0
- /package/dist/{rpc-methods → types/rpc-methods}/revokePermissions.d.ts +0 -0
- /package/dist/{utils.d.ts → types/utils.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
|
|
2
3
|
All notable changes to this project will be documented in this file.
|
|
3
4
|
|
|
4
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
@@ -6,8 +7,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
7
|
|
|
7
8
|
## [Unreleased]
|
|
8
9
|
|
|
10
|
+
## [9.0.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **BREAKING**: Add ESM build ([#3998](https://github.com/MetaMask/core/pull/3998))
|
|
15
|
+
- It's no longer possible to import files from `./dist` directly.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- **BREAKING:** Bump peer dependency on `@metamask/approval-controller` to `^6.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039))
|
|
20
|
+
- **BREAKING:** Bump `@metamask/base-controller` to `^5.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039))
|
|
21
|
+
- This version has a number of breaking changes. See the changelog for more.
|
|
22
|
+
- Bump `@metamask/controller-utils` to `^9.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039))
|
|
23
|
+
- Bump `@metamask/json-rpc-engine` to `^8.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039))
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **BREAKING:** Fix `SideEffectMessenger` so that it's defined with a `RestrictedControllerMessenger` that has access to `PermissionController` allowed actions ([#4031](https://github.com/MetaMask/core/pull/4031))
|
|
28
|
+
- The messenger's `Action` generic parameter is widened to include the `PermissionController` actions allowlist.
|
|
29
|
+
- The messenger's `AllowedAction` generic parameter is narrowed from `string` to the `PermissionController` actions allowlist.
|
|
30
|
+
|
|
31
|
+
## [8.0.1]
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- Bump `@metamask/rpc-errors` to `^6.2.1` ([#3954](https://github.com/MetaMask/core/pull/3954), [#3970](https://github.com/MetaMask/core/pull/3970))
|
|
36
|
+
|
|
9
37
|
## [8.0.0]
|
|
38
|
+
|
|
10
39
|
### Changed
|
|
40
|
+
|
|
11
41
|
- **BREAKING:** Bump `@metamask/approval-controller` peer dependency to `^5.1.2` ([#3821](https://github.com/MetaMask/core/pull/3821))
|
|
12
42
|
- Bump `@metamask/utils` to `^8.3.0` ([#3769](https://github.com/MetaMask/core/pull/3769))
|
|
13
43
|
- Bump `@metamask/base-controller` to `^4.1.1` ([#3760](https://github.com/MetaMask/core/pull/3760), [#3821](https://github.com/MetaMask/core/pull/3821))
|
|
@@ -15,24 +45,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
15
45
|
- Bump `@metamask/json-rpc-engine` to `^7.3.2` ([#3821](https://github.com/MetaMask/core/pull/3821))
|
|
16
46
|
|
|
17
47
|
## [7.1.0]
|
|
48
|
+
|
|
18
49
|
### Added
|
|
50
|
+
|
|
19
51
|
- Add `SubjectMetadataController:addSubjectMetadata` action ([#3733](https://github.com/MetaMask/core/pull/3733))
|
|
20
52
|
|
|
21
53
|
## [7.0.0]
|
|
54
|
+
|
|
22
55
|
### Changed
|
|
56
|
+
|
|
23
57
|
- **BREAKING:** Bump `@metamask/approval-controller` peer dependency from `^5.0.0` to `^5.1.1` ([#3680](https://github.com/MetaMask/core/pull/3680), [#3695](https://github.com/MetaMask/core/pull/3695))
|
|
24
58
|
- Bump `@metamask/base-controller` to `^4.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695))
|
|
25
59
|
- Bump `@metamask/controller-utils` to `^8.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695), [#3678](https://github.com/MetaMask/core/pull/3678), [#3667](https://github.com/MetaMask/core/pull/3667), [#3580](https://github.com/MetaMask/core/pull/3580))
|
|
26
60
|
- Bump `@metamask/json-rpc-engine` to `^7.3.1` ([#3695](https://github.com/MetaMask/core/pull/3695))
|
|
27
61
|
|
|
28
62
|
### Fixed
|
|
63
|
+
|
|
29
64
|
- Remove `@metamask/approval-controller` dependency ([#3607](https://github.com/MetaMask/core/pull/3607))
|
|
30
65
|
|
|
31
66
|
## [6.0.0]
|
|
67
|
+
|
|
32
68
|
### Added
|
|
69
|
+
|
|
33
70
|
- Add new handler to `permissionRpcMethods.handlers` for `wallet_revokePermissions` RPC method ([#1889](https://github.com/MetaMask/core/pull/1889))
|
|
34
71
|
|
|
35
72
|
### Changed
|
|
73
|
+
|
|
36
74
|
- **BREAKING:** Bump `@metamask/base-controller` to ^4.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
|
|
37
75
|
- This is breaking because the type of the `messenger` has backward-incompatible changes. See the changelog for this package for more.
|
|
38
76
|
- **BREAKING:** Update `PermittedRpcMethodHooks` type so it must support signature for `wallet_revokePermission` hook ([#1889](https://github.com/MetaMask/core/pull/1889))
|
|
@@ -40,7 +78,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
40
78
|
- Bump `@metamask/controller-utils` to ^6.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
|
|
41
79
|
|
|
42
80
|
## [5.0.1]
|
|
81
|
+
|
|
43
82
|
### Changed
|
|
83
|
+
|
|
44
84
|
- Bump `@metamask/json-rpc-engine` from `^7.1.0` to `^7.2.0` ([#1895](https://github.com/MetaMask/core/pull/1895))
|
|
45
85
|
- Bump dependency on `@metamask/rpc-errors` to ^6.1.0 ([#1653](https://github.com/MetaMask/core/pull/1653))
|
|
46
86
|
- Bump dependency and peer dependency on `@metamask/approval-controller` to ^4.0.1
|
|
@@ -48,7 +88,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
48
88
|
- Bump `@metamask/auto-changelog` from `^3.2.0` to `^3.4.3` ([#1870](https://github.com/MetaMask/core/pull/1870), [#1905](https://github.com/MetaMask/core/pull/1905), [#1997](https://github.com/MetaMask/core/pull/1997))
|
|
49
89
|
|
|
50
90
|
## [5.0.0]
|
|
91
|
+
|
|
51
92
|
### Changed
|
|
93
|
+
|
|
52
94
|
- **BREAKING:** Remove `undefined` from RestrictedMethodParameters type union and from type parameter for RestrictedMethodOptions ([#1749])(https://github.com/MetaMask/core/pull/1749))
|
|
53
95
|
- **BREAKING:** Update from `json-rpc-engine@^6.1.0` to `@metamask/json-rpc-engine@^7.1.1` ([#1749])(https://github.com/MetaMask/core/pull/1749))
|
|
54
96
|
- Update from `eth-rpc-errors@^4.0.2` to `@metamask/rpc-errors@^6.0.0` ([#1749])(https://github.com/MetaMask/core/pull/1749))
|
|
@@ -58,27 +100,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
58
100
|
- Bump dependency on `@metamask/controller-utils` to ^5.0.2
|
|
59
101
|
|
|
60
102
|
## [4.1.2]
|
|
103
|
+
|
|
61
104
|
### Changed
|
|
105
|
+
|
|
62
106
|
- Update TypeScript to v4.8.x ([#1718](https://github.com/MetaMask/core/pull/1718))
|
|
63
107
|
- Bump dependency on `@metamask/controller-utils` to ^5.0.0
|
|
64
108
|
|
|
65
109
|
## [4.1.1]
|
|
110
|
+
|
|
66
111
|
### Changed
|
|
112
|
+
|
|
67
113
|
- Bump dependency and peer dependency on `@metamask/approval-controller` to ^3.5.1
|
|
68
114
|
- Bump dependency on `@metamask/base-controller` to ^3.2.1
|
|
69
115
|
- Bump dependency on `@metamask/controller-utils` to ^4.3.2
|
|
70
116
|
|
|
71
117
|
## [4.1.0]
|
|
118
|
+
|
|
72
119
|
### Changed
|
|
120
|
+
|
|
73
121
|
- Update `@metamask/utils` to `^6.2.0` ([#1514](https://github.com/MetaMask/core/pull/1514))
|
|
74
122
|
|
|
75
123
|
## [4.0.1]
|
|
124
|
+
|
|
76
125
|
### Fixed
|
|
126
|
+
|
|
77
127
|
- Fix permissions RPC method types ([#1464](https://github.com/MetaMask/core/pull/1464))
|
|
78
128
|
- The RPC method handlers were mistakenly typed as an array rather than a tuple
|
|
79
129
|
|
|
80
130
|
## [4.0.0]
|
|
131
|
+
|
|
81
132
|
### Changed
|
|
133
|
+
|
|
82
134
|
- **BREAKING:** Bump to Node 16 ([#1262](https://github.com/MetaMask/core/pull/1262))
|
|
83
135
|
- **BREAKING:** Update `@metamask/approval-controller` dependency and peer dependency
|
|
84
136
|
- The export `permissionRpcMethods` has a slightly different type; the second generic type variable of the `getPermissions` handler is now `undefined` rather than `void` ([#1372](https://github.com/MetaMask/core/pull/1372))
|
|
@@ -87,6 +139,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
87
139
|
- Change type of constructor parameter `unrestrictedMethods` to be readonly ([#1395](https://github.com/MetaMask/core/pull/1395))
|
|
88
140
|
|
|
89
141
|
### Removed
|
|
142
|
+
|
|
90
143
|
- **BREAKING**: Remove namespaced permissions ([#1337](https://github.com/MetaMask/core/pull/1337))
|
|
91
144
|
- Namespaced permissions are no longer supported. Consumers should replace namespaced permissions with equivalent caveat-based implementations.
|
|
92
145
|
- **BREAKING**: Remove `targetKey` concept ([#1337](https://github.com/MetaMask/core/pull/1337))
|
|
@@ -94,48 +147,68 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
94
147
|
- The `targetKey` property of permission specifications has been renamed to `targetName`.
|
|
95
148
|
|
|
96
149
|
## [3.2.0]
|
|
150
|
+
|
|
97
151
|
### Added
|
|
152
|
+
|
|
98
153
|
- Allow restricting permissions by subject type ([#1233](https://github.com/MetaMask/core/pull/1233))
|
|
99
154
|
|
|
100
155
|
### Changed
|
|
156
|
+
|
|
101
157
|
- Move `SubjectMetadataController` to permission-controller package ([#1234](https://github.com/MetaMask/core/pull/1234))
|
|
102
158
|
- Update minimum `eth-rpc-errors` version from `4.0.0` to `4.0.2` ([#1215](https://github.com/MetaMask/core/pull/1215))
|
|
103
159
|
|
|
104
160
|
## [3.1.0]
|
|
161
|
+
|
|
105
162
|
### Added
|
|
163
|
+
|
|
106
164
|
- Add side-effects to permissions ([#1069](https://github.com/MetaMask/core/pull/1069))
|
|
107
165
|
|
|
108
166
|
## [3.0.0]
|
|
167
|
+
|
|
109
168
|
### Removed
|
|
169
|
+
|
|
110
170
|
- **BREAKING:** Remove `isomorphic-fetch` ([#1106](https://github.com/MetaMask/controllers/pull/1106))
|
|
111
171
|
- Consumers must now import `isomorphic-fetch` or another polyfill themselves if they are running in an environment without `fetch`
|
|
112
172
|
|
|
113
173
|
## [2.0.0]
|
|
174
|
+
|
|
114
175
|
### Added
|
|
176
|
+
|
|
115
177
|
- Add `updateCaveat` action ([#1071](https://github.com/MetaMask/core/pull/1071))
|
|
116
178
|
|
|
117
179
|
### Changed
|
|
180
|
+
|
|
118
181
|
- **BREAKING:** Update `@metamask/network-controller` peer dependency to v3 ([#1041](https://github.com/MetaMask/controllers/pull/1041))
|
|
119
182
|
- Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031))
|
|
120
183
|
- Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
|
|
121
184
|
|
|
122
185
|
## [1.0.2]
|
|
186
|
+
|
|
123
187
|
### Fixed
|
|
188
|
+
|
|
124
189
|
- This package will now warn if a required package is not present ([#1003](https://github.com/MetaMask/core/pull/1003))
|
|
125
190
|
|
|
126
191
|
## [1.0.1]
|
|
192
|
+
|
|
127
193
|
### Changed
|
|
194
|
+
|
|
128
195
|
- Relax dependencies on `@metamask/approval-controller`, `@metamask/base-controller` and `@metamask/controller-utils` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/core/pull/998))
|
|
129
196
|
|
|
130
197
|
## [1.0.0]
|
|
198
|
+
|
|
131
199
|
### Added
|
|
200
|
+
|
|
132
201
|
- Initial release
|
|
202
|
+
|
|
133
203
|
- As a result of converting our shared controllers repo into a monorepo ([#831](https://github.com/MetaMask/core/pull/831)), we've created this package from select parts of [`@metamask/controllers` v33.0.0](https://github.com/MetaMask/core/tree/v33.0.0), namely:
|
|
204
|
+
|
|
134
205
|
- Everything in `src/permissions`
|
|
135
206
|
|
|
136
207
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
137
208
|
|
|
138
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/permission-controller@
|
|
209
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/permission-controller@9.0.0...HEAD
|
|
210
|
+
[9.0.0]: https://github.com/MetaMask/core/compare/@metamask/permission-controller@8.0.1...@metamask/permission-controller@9.0.0
|
|
211
|
+
[8.0.1]: https://github.com/MetaMask/core/compare/@metamask/permission-controller@8.0.0...@metamask/permission-controller@8.0.1
|
|
139
212
|
[8.0.0]: https://github.com/MetaMask/core/compare/@metamask/permission-controller@7.1.0...@metamask/permission-controller@8.0.0
|
|
140
213
|
[7.1.0]: https://github.com/MetaMask/core/compare/@metamask/permission-controller@7.0.0...@metamask/permission-controller@7.1.0
|
|
141
214
|
[7.0.0]: https://github.com/MetaMask/core/compare/@metamask/permission-controller@6.0.0...@metamask/permission-controller@7.0.0
|
package/dist/Caveat.js
CHANGED
|
@@ -1,57 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.decorateWithCaveats = exports.isRestrictedMethodCaveatSpecification = void 0;
|
|
13
|
-
const utils_1 = require("@metamask/utils");
|
|
14
|
-
const errors_1 = require("./errors");
|
|
15
|
-
const Permission_1 = require("./Permission");
|
|
16
|
-
/**
|
|
17
|
-
* Determines whether a caveat specification is a restricted method caveat specification.
|
|
18
|
-
*
|
|
19
|
-
* @param specification - The caveat specification.
|
|
20
|
-
* @returns True if the caveat specification is a restricted method caveat specification, otherwise false.
|
|
21
|
-
*/
|
|
22
|
-
function isRestrictedMethodCaveatSpecification(specification) {
|
|
23
|
-
return (0, utils_1.hasProperty)(specification, 'decorator');
|
|
24
|
-
}
|
|
25
|
-
exports.isRestrictedMethodCaveatSpecification = isRestrictedMethodCaveatSpecification;
|
|
26
|
-
/**
|
|
27
|
-
* Decorate a restricted method implementation with its caveats.
|
|
28
|
-
*
|
|
29
|
-
* Note that all caveat functions (i.e. the argument and return value of the
|
|
30
|
-
* decorator) must be awaited.
|
|
31
|
-
*
|
|
32
|
-
* @param methodImplementation - The restricted method implementation
|
|
33
|
-
* @param permission - The origin's potential permission
|
|
34
|
-
* @param caveatSpecifications - All caveat implementations
|
|
35
|
-
* @returns The decorated method implementation
|
|
36
|
-
*/
|
|
37
|
-
function decorateWithCaveats(methodImplementation, permission, // bound to the requesting origin
|
|
38
|
-
caveatSpecifications) {
|
|
39
|
-
const { caveats } = permission;
|
|
40
|
-
if (!caveats) {
|
|
41
|
-
return methodImplementation;
|
|
42
|
-
}
|
|
43
|
-
let decorated = (args) => __awaiter(this, void 0, void 0, function* () { return methodImplementation(args); });
|
|
44
|
-
for (const caveat of caveats) {
|
|
45
|
-
const specification = caveatSpecifications[caveat.type];
|
|
46
|
-
if (!specification) {
|
|
47
|
-
throw new errors_1.UnrecognizedCaveatTypeError(caveat.type);
|
|
48
|
-
}
|
|
49
|
-
if (!isRestrictedMethodCaveatSpecification(specification)) {
|
|
50
|
-
throw new errors_1.CaveatSpecificationMismatchError(specification, Permission_1.PermissionType.RestrictedMethod);
|
|
51
|
-
}
|
|
52
|
-
decorated = specification.decorator(decorated, caveat);
|
|
53
|
-
}
|
|
54
|
-
return decorated;
|
|
55
|
-
}
|
|
56
|
-
exports.decorateWithCaveats = decorateWithCaveats;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkEGNDXGRGjs = require('./chunk-EGNDXGRG.js');
|
|
5
|
+
require('./chunk-6CID6TBW.js');
|
|
6
|
+
require('./chunk-U5LTEXSU.js');
|
|
7
|
+
require('./chunk-CSAU5B4Q.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.decorateWithCaveats = _chunkEGNDXGRGjs.decorateWithCaveats; exports.isRestrictedMethodCaveatSpecification = _chunkEGNDXGRGjs.isRestrictedMethodCaveatSpecification;
|
|
57
12
|
//# sourceMappingURL=Caveat.js.map
|
package/dist/Caveat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Caveat.js","sourceRoot":"","sources":["../src/Caveat.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2CAA8C;AAE9C,qCAGkB;AAOlB,6CAA8C;AAsP9C;;;;;GAKG;AACH,SAAgB,qCAAqC,CACnD,aAA4C;IAE5C,OAAO,IAAA,mBAAW,EAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AACjD,CAAC;AAJD,sFAIC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CAGjC,oBAAwE,EACxE,UAA0C,EAAE,iCAAiC;AAC7E,oBAAkE;IAElE,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;IAC/B,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,oBAAoB,CAAC;KAC7B;IAED,IAAI,SAAS,GAAG,CACd,IAAuE,EACvE,EAAE,gDAAC,OAAA,oBAAoB,CAAC,IAAI,CAAC,CAAA,GAAA,CAAC;IAEhC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,MAAM,aAAa,GACjB,oBAAoB,CAAC,MAAM,CAAC,IAAoC,CAAC,CAAC;QACpE,IAAI,CAAC,aAAa,EAAE;YAClB,MAAM,IAAI,oCAA2B,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;SACpD;QAED,IAAI,CAAC,qCAAqC,CAAC,aAAa,CAAC,EAAE;YACzD,MAAM,IAAI,yCAAgC,CACxC,aAAa,EACb,2BAAc,CAAC,gBAAgB,CAChC,CAAC;SACH;QACD,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;KACxD;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAjCD,kDAiCC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\n\nimport {\n CaveatSpecificationMismatchError,\n UnrecognizedCaveatTypeError,\n} from './errors';\nimport type {\n AsyncRestrictedMethod,\n RestrictedMethod,\n PermissionConstraint,\n RestrictedMethodParameters,\n} from './Permission';\nimport { PermissionType } from './Permission';\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { PermissionController } from './PermissionController';\n\nexport type CaveatConstraint = {\n /**\n * The type of the caveat. The type is presumed to be meaningful in the\n * context of the capability it is associated with.\n *\n * In MetaMask, every permission can only have one caveat of each type.\n */\n readonly type: string;\n\n // TODO:TS4.4 Make optional\n /**\n * Any additional data necessary to enforce the caveat.\n */\n readonly value: Json;\n};\n\n/**\n * A `ZCAP-LD`-like caveat object. A caveat is associated with a particular\n * permission, and stored in its `caveats` array. Conceptually, a caveat is\n * an arbitrary attenuation of the authority granted by its associated\n * permission. It is the responsibility of the host to interpret and apply\n * the restriction represented by a caveat.\n *\n * @template Type - The type of the caveat.\n * @template Value - The value associated with the caveat.\n */\nexport type Caveat<Type extends string, Value extends Json> = {\n /**\n * The type of the caveat. The type is presumed to be meaningful in the\n * context of the capability it is associated with.\n *\n * In MetaMask, every permission can only have one caveat of each type.\n */\n readonly type: Type;\n\n // TODO:TS4.4 Make optional\n /**\n * Any additional data necessary to enforce the caveat.\n */\n readonly value: Value;\n};\n\n// Next, we define types used for specifying caveats at the consumer layer,\n// and a function for applying caveats to a restricted method request. This is\n// Accomplished by decorating the restricted method implementation with the\n// the corresponding caveat functions.\n\n/**\n * A function for applying caveats to a restricted method request.\n *\n * @template ParentCaveat - The caveat type associated with this decorator.\n * @param decorated - The restricted method implementation to be decorated.\n * The method may have already been decorated with other caveats.\n * @param caveat - The caveat object.\n * @returns The decorated restricted method implementation.\n */\nexport type CaveatDecorator<ParentCaveat extends CaveatConstraint> = (\n decorated: AsyncRestrictedMethod<RestrictedMethodParameters, Json>,\n caveat: ParentCaveat,\n) => AsyncRestrictedMethod<RestrictedMethodParameters, Json>;\n\n/**\n * Extracts a caveat value type from a caveat decorator.\n *\n * @template Decorator - The {@link CaveatDecorator} to extract a caveat value\n * type from.\n */\n// TODO: Replace `any` with type\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ExtractCaveatValueFromDecorator<Decorator extends CaveatDecorator<any>> =\n Decorator extends (\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n decorated: any,\n caveat: infer ParentCaveat,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) => AsyncRestrictedMethod<any, any>\n ? ParentCaveat extends CaveatConstraint\n ? ParentCaveat['value']\n : never\n : never;\n\n/**\n * A function for validating caveats of a particular type.\n *\n * @template ParentCaveat - The caveat type associated with this validator.\n * @param caveat - The caveat object to validate.\n * @param origin - The origin associated with the parent permission.\n * @param target - The target of the parent permission.\n */\nexport type CaveatValidator<ParentCaveat extends CaveatConstraint> = (\n caveat: { type: ParentCaveat['type']; value: unknown },\n origin?: string,\n target?: string,\n) => void;\n\nexport type CaveatSpecificationBase = {\n /**\n * The string type of the caveat.\n */\n type: string;\n\n /**\n * The validator function used to validate caveats of the associated type\n * whenever they are instantiated. Caveat are instantiated whenever they are\n * created or mutated.\n *\n * The validator should throw an appropriate JSON-RPC error if validation fails.\n *\n * If no validator is specified, no validation of caveat values will be\n * performed. Although caveats can also be validated by permission validators,\n * validating caveat values separately is strongly recommended.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n validator?: CaveatValidator<any>;\n};\n\nexport type RestrictedMethodCaveatSpecificationConstraint =\n CaveatSpecificationBase & {\n /**\n * The decorator function used to apply the caveat to restricted method\n * requests.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n decorator: CaveatDecorator<any>;\n };\n\nexport type EndowmentCaveatSpecificationConstraint = CaveatSpecificationBase;\n\n/**\n * The constraint for caveat specification objects. Every {@link Caveat}\n * supported by a {@link PermissionController} must have an associated\n * specification, which is the source of truth for all caveat-related types.\n * In addition, a caveat specification may include a decorator function used\n * to apply the caveat's attenuation to a restricted method. It may also include\n * a validator function specified by the consumer.\n *\n * See the README for more details.\n */\nexport type CaveatSpecificationConstraint =\n | RestrictedMethodCaveatSpecificationConstraint\n | EndowmentCaveatSpecificationConstraint;\n\n/**\n * Options for {@link CaveatSpecificationBuilder} functions.\n */\ntype CaveatSpecificationBuilderOptions<\n DecoratorHooks extends Record<string, unknown>,\n ValidatorHooks extends Record<string, unknown>,\n> = {\n type?: string;\n decoratorHooks?: DecoratorHooks;\n validatorHooks?: ValidatorHooks;\n};\n\n/**\n * A function that builds caveat specifications. Modules that specify caveats\n * for external consumption should make this their primary / default export so\n * that host applications can use them to generate concrete specifications\n * tailored to their requirements.\n */\nexport type CaveatSpecificationBuilder<\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Options extends CaveatSpecificationBuilderOptions<any, any>,\n Specification extends CaveatSpecificationConstraint,\n> = (options: Options) => Specification;\n\n/**\n * A caveat specification export object, containing the\n * {@link CaveatSpecificationBuilder} function and \"hook name\" objects.\n */\nexport type CaveatSpecificationBuilderExportConstraint = {\n specificationBuilder: CaveatSpecificationBuilder<\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n CaveatSpecificationBuilderOptions<any, any>,\n CaveatSpecificationConstraint\n >;\n decoratorHookNames?: Record<string, true>;\n validatorHookNames?: Record<string, true>;\n};\n\n/**\n * The specifications for all caveats supported by a particular\n * {@link PermissionController}.\n *\n * @template Specifications - The union of all {@link CaveatSpecificationConstraint} types.\n */\nexport type CaveatSpecificationMap<\n CaveatSpecification extends CaveatSpecificationConstraint,\n> = Record<CaveatSpecification['type'], CaveatSpecification>;\n\n/**\n * Extracts the union of all caveat types specified by the given\n * {@link CaveatSpecificationConstraint} type.\n *\n * @template CaveatSpecification - The {@link CaveatSpecificationConstraint} to extract a\n * caveat type union from.\n */\nexport type ExtractCaveats<\n CaveatSpecification extends CaveatSpecificationConstraint,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n> = CaveatSpecification extends any\n ? CaveatSpecification extends RestrictedMethodCaveatSpecificationConstraint\n ? Caveat<\n CaveatSpecification['type'],\n ExtractCaveatValueFromDecorator<\n RestrictedMethodCaveatSpecificationConstraint['decorator']\n >\n >\n : Caveat<CaveatSpecification['type'], Json>\n : never;\n\n/**\n * Extracts the type of a specific {@link Caveat} from a union of caveat\n * specifications.\n *\n * @template CaveatSpecifications - The union of all caveat specifications.\n * @template CaveatType - The type of the caveat to extract.\n */\nexport type ExtractCaveat<\n CaveatSpecifications extends CaveatSpecificationConstraint,\n CaveatType extends string,\n> = Extract<ExtractCaveats<CaveatSpecifications>, { type: CaveatType }>;\n\n/**\n * Extracts the value type of a specific {@link Caveat} from a union of caveat\n * specifications.\n *\n * @template CaveatSpecifications - The union of all caveat specifications.\n * @template CaveatType - The type of the caveat whose value to extract.\n */\nexport type ExtractCaveatValue<\n CaveatSpecifications extends CaveatSpecificationConstraint,\n CaveatType extends string,\n> = ExtractCaveat<CaveatSpecifications, CaveatType>['value'];\n\n/**\n * Determines whether a caveat specification is a restricted method caveat specification.\n *\n * @param specification - The caveat specification.\n * @returns True if the caveat specification is a restricted method caveat specification, otherwise false.\n */\nexport function isRestrictedMethodCaveatSpecification(\n specification: CaveatSpecificationConstraint,\n): specification is RestrictedMethodCaveatSpecificationConstraint {\n return hasProperty(specification, 'decorator');\n}\n\n/**\n * Decorate a restricted method implementation with its caveats.\n *\n * Note that all caveat functions (i.e. the argument and return value of the\n * decorator) must be awaited.\n *\n * @param methodImplementation - The restricted method implementation\n * @param permission - The origin's potential permission\n * @param caveatSpecifications - All caveat implementations\n * @returns The decorated method implementation\n */\nexport function decorateWithCaveats<\n CaveatSpecifications extends CaveatSpecificationConstraint,\n>(\n methodImplementation: RestrictedMethod<RestrictedMethodParameters, Json>,\n permission: Readonly<PermissionConstraint>, // bound to the requesting origin\n caveatSpecifications: CaveatSpecificationMap<CaveatSpecifications>, // all caveat implementations\n): RestrictedMethod<RestrictedMethodParameters, Json> {\n const { caveats } = permission;\n if (!caveats) {\n return methodImplementation;\n }\n\n let decorated = async (\n args: Parameters<RestrictedMethod<RestrictedMethodParameters, Json>>[0],\n ) => methodImplementation(args);\n\n for (const caveat of caveats) {\n const specification =\n caveatSpecifications[caveat.type as CaveatSpecifications['type']];\n if (!specification) {\n throw new UnrecognizedCaveatTypeError(caveat.type);\n }\n\n if (!isRestrictedMethodCaveatSpecification(specification)) {\n throw new CaveatSpecificationMismatchError(\n specification,\n PermissionType.RestrictedMethod,\n );\n }\n decorated = specification.decorator(decorated, caveat);\n }\n\n return decorated;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/Caveat.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decorateWithCaveats,
|
|
3
|
+
isRestrictedMethodCaveatSpecification
|
|
4
|
+
} from "./chunk-XBFHEZRU.mjs";
|
|
5
|
+
import "./chunk-ODCVB4BB.mjs";
|
|
6
|
+
import "./chunk-FEXS6SJF.mjs";
|
|
7
|
+
import "./chunk-ZSTKOCBT.mjs";
|
|
8
|
+
export {
|
|
9
|
+
decorateWithCaveats,
|
|
10
|
+
isRestrictedMethodCaveatSpecification
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=Caveat.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/Permission.js
CHANGED
|
@@ -1,66 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function constructPermission(options) {
|
|
15
|
-
const { caveats = null, invoker, target } = options;
|
|
16
|
-
return {
|
|
17
|
-
id: (0, nanoid_1.nanoid)(),
|
|
18
|
-
parentCapability: target,
|
|
19
|
-
invoker,
|
|
20
|
-
caveats,
|
|
21
|
-
date: new Date().getTime(),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
exports.constructPermission = constructPermission;
|
|
25
|
-
/**
|
|
26
|
-
* Gets the caveat of the specified type belonging to the specified permission.
|
|
27
|
-
*
|
|
28
|
-
* @param permission - The permission whose caveat to retrieve.
|
|
29
|
-
* @param caveatType - The type of the caveat to retrieve.
|
|
30
|
-
* @returns The caveat, or undefined if no such caveat exists.
|
|
31
|
-
*/
|
|
32
|
-
function findCaveat(permission, caveatType) {
|
|
33
|
-
var _a;
|
|
34
|
-
return (_a = permission.caveats) === null || _a === void 0 ? void 0 : _a.find((caveat) => caveat.type === caveatType);
|
|
35
|
-
}
|
|
36
|
-
exports.findCaveat = findCaveat;
|
|
37
|
-
/**
|
|
38
|
-
* The different possible types of permissions.
|
|
39
|
-
*/
|
|
40
|
-
var PermissionType;
|
|
41
|
-
(function (PermissionType) {
|
|
42
|
-
/**
|
|
43
|
-
* A restricted JSON-RPC method. A subject must have the requisite permission
|
|
44
|
-
* to call a restricted JSON-RPC method.
|
|
45
|
-
*/
|
|
46
|
-
PermissionType["RestrictedMethod"] = "RestrictedMethod";
|
|
47
|
-
/**
|
|
48
|
-
* An "endowment" granted to subjects that possess the requisite permission,
|
|
49
|
-
* such as a global environment variable exposing a restricted API, etc.
|
|
50
|
-
*/
|
|
51
|
-
PermissionType["Endowment"] = "Endowment";
|
|
52
|
-
})(PermissionType = exports.PermissionType || (exports.PermissionType = {}));
|
|
53
|
-
/**
|
|
54
|
-
* Checks that the specification has the expected permission type.
|
|
55
|
-
*
|
|
56
|
-
* @param specification - The specification to check.
|
|
57
|
-
* @param expectedType - The expected permission type.
|
|
58
|
-
* @template Specification - The specification to check.
|
|
59
|
-
* @template Type - The expected permission type.
|
|
60
|
-
* @returns Whether or not the specification is of the expected type.
|
|
61
|
-
*/
|
|
62
|
-
function hasSpecificationType(specification, expectedType) {
|
|
63
|
-
return specification.permissionType === expectedType;
|
|
64
|
-
}
|
|
65
|
-
exports.hasSpecificationType = hasSpecificationType;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk6CID6TBWjs = require('./chunk-6CID6TBW.js');
|
|
7
|
+
require('./chunk-CSAU5B4Q.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.PermissionType = _chunk6CID6TBWjs.PermissionType; exports.constructPermission = _chunk6CID6TBWjs.constructPermission; exports.findCaveat = _chunk6CID6TBWjs.findCaveat; exports.hasSpecificationType = _chunk6CID6TBWjs.hasSpecificationType;
|
|
66
14
|
//# sourceMappingURL=Permission.js.map
|
package/dist/Permission.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Permission.js","sourceRoot":"","sources":["../src/Permission.ts"],"names":[],"mappings":";;;AAMA,mCAAgC;AAsJhC;;;;;;;;GAQG;AACH,SAAgB,mBAAmB,CAEjC,OAA4C;IAC5C,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAEpD,OAAO;QACL,EAAE,EAAE,IAAA,eAAM,GAAE;QACZ,gBAAgB,EAAE,MAAM;QACxB,OAAO;QACP,OAAO;QACP,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;KACP,CAAC;AACxB,CAAC;AAZD,kDAYC;AAED;;;;;;GAMG;AACH,SAAgB,UAAU,CACxB,UAAgC,EAChC,UAAkB;;IAElB,OAAO,MAAA,UAAU,CAAC,OAAO,0CAAE,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;AAC1E,CAAC;AALD,gCAKC;AAiKD;;GAEG;AACH,IAAY,cAYX;AAZD,WAAY,cAAc;IACxB;;;OAGG;IACH,uDAAqC,CAAA;IAErC;;;OAGG;IACH,yCAAuB,CAAA;AACzB,CAAC,EAZW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAYzB;AAsMD;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAIlC,aAA4B,EAC5B,YAAkB;IAIlB,OAAO,aAAa,CAAC,cAAc,KAAK,YAAY,CAAC;AACvD,CAAC;AAVD,oDAUC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n} from '@metamask/base-controller';\nimport type { NonEmptyArray } from '@metamask/controller-utils';\nimport type { Json } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { CaveatConstraint, Caveat } from './Caveat';\nimport type {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n PermissionController,\n PermissionsRequest,\n SideEffectMessenger,\n} from './PermissionController';\nimport type { SubjectType } from './SubjectMetadataController';\n\n/**\n * The origin of a subject.\n * Effectively the GUID of an entity that can have permissions.\n */\nexport type OriginString = string;\n\n/**\n * The name of a permission target.\n */\ntype TargetName = string;\n\n/**\n * A `ZCAP-LD`-like permission object. A permission is associated with a\n * particular `invoker`, which is the holder of the permission. Possessing the\n * permission grants access to a particular restricted resource, identified by\n * the `parentCapability`. The use of the restricted resource may be further\n * restricted by any `caveats` associated with the permission.\n *\n * See the README for details.\n */\nexport type PermissionConstraint = {\n /**\n * The context(s) in which this capability is meaningful.\n *\n * It is required by the standard, but we make it optional since there is only\n * one context in our usage (i.e. the user's MetaMask instance).\n */\n readonly '@context'?: NonEmptyArray<string>;\n\n // TODO:TS4.4 Make optional\n /**\n * The caveats of the permission.\n *\n * @see {@link Caveat} For more information.\n */\n readonly caveats: null | NonEmptyArray<CaveatConstraint>;\n\n /**\n * The creation date of the permission, in UNIX epoch time.\n */\n readonly date: number;\n\n /**\n * The GUID of the permission object.\n */\n readonly id: string;\n\n /**\n * The origin string of the subject that has the permission.\n */\n readonly invoker: OriginString;\n\n /**\n * A pointer to the resource that possession of the capability grants\n * access to, for example a JSON-RPC method or endowment.\n */\n readonly parentCapability: string;\n};\n\n/**\n * A `ZCAP-LD`-like permission object. A permission is associated with a\n * particular `invoker`, which is the holder of the permission. Possessing the\n * permission grants access to a particular restricted resource, identified by\n * the `parentCapability`. The use of the restricted resource may be further\n * restricted by any `caveats` associated with the permission.\n *\n * See the README for details.\n *\n * @template Name - The name of the permission that the target corresponds to.\n * @template AllowedCaveat - A union of the allowed {@link Caveat} types\n * for the permission.\n */\nexport type ValidPermission<\n Name extends TargetName,\n AllowedCaveat extends CaveatConstraint,\n> = PermissionConstraint & {\n // TODO:TS4.4 Make optional\n /**\n * The caveats of the permission.\n *\n * @see {@link Caveat} For more information.\n */\n readonly caveats: AllowedCaveat extends never\n ? null\n : NonEmptyArray<AllowedCaveat> | null;\n\n /**\n * A pointer to the resource that possession of the capability grants\n * access to, for example a JSON-RPC method or endowment.\n */\n readonly parentCapability: Name;\n};\n\n/**\n * Internal utility for extracting the members types of an array. The type\n * evalutes to `never` if the specified type is the empty tuple or neither\n * an array nor a tuple.\n *\n * @template ArrayType - The array type whose members to extract.\n */\ntype ExtractArrayMembers<ArrayType> = ArrayType extends []\n ? never\n : // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ArrayType extends any[] | readonly any[]\n ? ArrayType[number]\n : never;\n\n/**\n * A utility type for extracting the allowed caveat types for a particular\n * permission from a permission specification type.\n *\n * @template PermissionSpecification - The permission specification type to\n * extract valid caveat types from.\n */\nexport type ExtractAllowedCaveatTypes<\n PermissionSpecification extends PermissionSpecificationConstraint,\n> = ExtractArrayMembers<PermissionSpecification['allowedCaveats']>;\n\n/**\n * The options object of {@link constructPermission}.\n *\n * @template TargetPermission - The {@link Permission} that will be constructed.\n */\nexport type PermissionOptions<TargetPermission extends PermissionConstraint> = {\n target: TargetPermission['parentCapability'];\n /**\n * The origin string of the subject that has the permission.\n */\n invoker: OriginString;\n\n /**\n * The caveats of the permission.\n * See {@link Caveat}.\n */\n caveats?: NonEmptyArray<CaveatConstraint>;\n};\n\n/**\n * The default permission factory function. Naively constructs a permission from\n * the inputs. Sets a default, random `id` if none is provided.\n *\n * @see {@link Permission} For more details.\n * @template TargetPermission- - The {@link Permission} that will be constructed.\n * @param options - The options for the permission.\n * @returns The new permission object.\n */\nexport function constructPermission<\n TargetPermission extends PermissionConstraint,\n>(options: PermissionOptions<TargetPermission>): TargetPermission {\n const { caveats = null, invoker, target } = options;\n\n return {\n id: nanoid(),\n parentCapability: target,\n invoker,\n caveats,\n date: new Date().getTime(),\n } as TargetPermission;\n}\n\n/**\n * Gets the caveat of the specified type belonging to the specified permission.\n *\n * @param permission - The permission whose caveat to retrieve.\n * @param caveatType - The type of the caveat to retrieve.\n * @returns The caveat, or undefined if no such caveat exists.\n */\nexport function findCaveat(\n permission: PermissionConstraint,\n caveatType: string,\n): CaveatConstraint | undefined {\n return permission.caveats?.find((caveat) => caveat.type === caveatType);\n}\n\n/**\n * A requested permission object. Just an object with any of the properties\n * of a {@link PermissionConstraint} object.\n */\ntype RequestedPermission = Partial<PermissionConstraint>;\n\n/**\n * A record of target names and their {@link RequestedPermission} objects.\n */\nexport type RequestedPermissions = Record<TargetName, RequestedPermission>;\n\n/**\n * The restricted method context object. Essentially a way to pass internal\n * arguments to restricted methods and caveat functions, most importantly the\n * requesting origin.\n */\ntype RestrictedMethodContext = Readonly<{\n origin: OriginString;\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key: string]: any;\n}>;\n\nexport type RestrictedMethodParameters = Json[] | Record<string, Json>;\n\n/**\n * The arguments passed to a restricted method implementation.\n *\n * @template Params - The JSON-RPC parameters of the restricted method.\n */\nexport type RestrictedMethodOptions<\n Params extends RestrictedMethodParameters | null,\n> = {\n method: TargetName;\n params?: Params;\n context: RestrictedMethodContext;\n};\n\n/**\n * A synchronous restricted method implementation.\n *\n * @template Params - The JSON-RPC parameters of the restricted method.\n * @template Result - The JSON-RPC result of the restricted method.\n */\nexport type SyncRestrictedMethod<\n Params extends RestrictedMethodParameters,\n Result extends Json,\n> = (args: RestrictedMethodOptions<Params>) => Result;\n\n/**\n * An asynchronous restricted method implementation.\n *\n * @template Params - The JSON-RPC parameters of the restricted method.\n * @template Result - The JSON-RPC result of the restricted method.\n */\nexport type AsyncRestrictedMethod<\n Params extends RestrictedMethodParameters,\n Result extends Json,\n> = (args: RestrictedMethodOptions<Params>) => Promise<Result>;\n\n/**\n * A synchronous or asynchronous restricted method implementation.\n *\n * @template Params - The JSON-RPC parameters of the restricted method.\n * @template Result - The JSON-RPC result of the restricted method.\n */\nexport type RestrictedMethod<\n Params extends RestrictedMethodParameters,\n Result extends Json,\n> =\n | SyncRestrictedMethod<Params, Result>\n | AsyncRestrictedMethod<Params, Result>;\n\nexport type ValidRestrictedMethod<\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n MethodImplementation extends RestrictedMethod<any, any>,\n> = MethodImplementation extends (args: infer Options) => Json | Promise<Json>\n ? Options extends RestrictedMethodOptions<RestrictedMethodParameters>\n ? MethodImplementation\n : never\n : never;\n\n/**\n * {@link EndowmentGetter} parameter object.\n */\nexport type EndowmentGetterParams = {\n /**\n * The origin of the requesting subject.\n */\n origin: string;\n\n /**\n * Any additional data associated with the request.\n */\n requestData?: unknown;\n\n [key: string]: unknown;\n};\n\n/**\n * A synchronous or asynchronous function that gets the endowments for a\n * particular endowment permission. The getter receives the origin of the\n * requesting subject and, optionally, additional request metadata.\n */\nexport type EndowmentGetter<Endowments extends Json> = (\n options: EndowmentGetterParams,\n) => Endowments | Promise<Endowments>;\n\nexport type PermissionFactory<\n TargetPermission extends PermissionConstraint,\n RequestData extends Record<string, unknown>,\n> = (\n options: PermissionOptions<TargetPermission>,\n requestData?: RequestData,\n) => TargetPermission;\n\nexport type PermissionValidatorConstraint = (\n permission: PermissionConstraint,\n origin?: OriginString,\n target?: string,\n) => void;\n\n/**\n * The parameters passed to the side-effect function.\n */\nexport type SideEffectParams<\n Actions extends ActionConstraint,\n Events extends EventConstraint,\n> = {\n requestData: PermissionsRequest;\n messagingSystem: SideEffectMessenger<Actions, Events>;\n};\n\n/**\n * A function that will execute actions as a permission side-effect.\n */\nexport type SideEffectHandler<\n Actions extends ActionConstraint,\n Events extends EventConstraint,\n> = (params: SideEffectParams<Actions, Events>) => Promise<unknown>;\n\n/**\n * The permissions side effects.\n */\nexport type PermissionSideEffect<\n Actions extends ActionConstraint,\n Events extends EventConstraint,\n> = {\n /**\n * A method triggered when the permission is accepted by the user\n */\n onPermitted: SideEffectHandler<Actions, Events>;\n /**\n * A method triggered if a `onPermitted` method rejected.\n */\n onFailure?: SideEffectHandler<Actions, Events>;\n};\n\n/**\n * The different possible types of permissions.\n */\nexport enum PermissionType {\n /**\n * A restricted JSON-RPC method. A subject must have the requisite permission\n * to call a restricted JSON-RPC method.\n */\n RestrictedMethod = 'RestrictedMethod',\n\n /**\n * An \"endowment\" granted to subjects that possess the requisite permission,\n * such as a global environment variable exposing a restricted API, etc.\n */\n Endowment = 'Endowment',\n}\n\n/**\n * The base constraint for permission specification objects. Every\n * {@link Permission} supported by a {@link PermissionController} must have an\n * associated specification, which is the source of truth for all permission-\n * related types. A permission specification includes the list of permitted\n * caveats, and any factory and validation functions specified by the consumer.\n * A concrete permission specification may specify further fields as necessary.\n *\n * See the README for more details.\n */\ntype PermissionSpecificationBase<Type extends PermissionType> = {\n /**\n * The type of the specified permission.\n */\n permissionType: Type;\n\n /**\n * The name of the target resource of the permission.\n */\n targetName: string;\n\n /**\n * An array of the caveat types that may be added to instances of this\n * permission.\n */\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n\n /**\n * The factory function used to get permission objects. Permissions returned\n * by this function are presumed to valid, and they will not be passed to the\n * validator function associated with this specification (if any). In other\n * words, the factory function should validate the permissions it creates.\n *\n * If no factory is specified, the {@link Permission} constructor will be\n * used, and the validator function (if specified) will be called on newly\n * constructed permissions.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n factory?: PermissionFactory<any, Record<string, unknown>>;\n\n /**\n * The validator function used to validate permissions of the associated type\n * whenever they are mutated. The only way a permission can be legally mutated\n * is when its caveats are modified by the permission controller.\n *\n * The validator should throw an appropriate JSON-RPC error if validation fails.\n */\n validator?: PermissionValidatorConstraint;\n\n /**\n * The side-effect triggered by the {@link PermissionController} once the user approved it.\n * The side-effect can only be an action allowed to be called inside the {@link PermissionController}.\n *\n * If the side-effect action fails, the permission that triggered it is revoked.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n sideEffect?: PermissionSideEffect<any, any>;\n\n /**\n * The Permission may be available to only a subset of the subject types. If so, specify the subject types as an array.\n * If a subject with a type not in this array tries to request the permission, the call will fail.\n *\n * Leaving this as undefined uses default behaviour where the permission is available to request for all subject types.\n */\n subjectTypes?: readonly SubjectType[];\n};\n\n/**\n * The constraint for restricted method permission specification objects.\n * Permissions that correspond to JSON-RPC methods are specified using objects\n * that conform to this type.\n *\n * See the README for more details.\n */\nexport type RestrictedMethodSpecificationConstraint =\n PermissionSpecificationBase<PermissionType.RestrictedMethod> & {\n /**\n * The implementation of the restricted method that the permission\n * corresponds to.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n methodImplementation: RestrictedMethod<any, any>;\n };\n\n/**\n * The constraint for endowment permission specification objects. Permissions\n * that endow callers with some restricted resource are specified using objects\n * that conform to this type.\n *\n * See the README for more details.\n */\nexport type EndowmentSpecificationConstraint =\n PermissionSpecificationBase<PermissionType.Endowment> & {\n /**\n * The {@link EndowmentGetter} function for the permission. This function\n * will be called by the {@link PermissionController} whenever the\n * permission is invoked, after which the host can apply the endowments to\n * the requesting subject in the intended manner.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n endowmentGetter: EndowmentGetter<any>;\n };\n\n/**\n * The constraint for permission specification objects. Every {@link Permission}\n * supported by a {@link PermissionController} must have an associated\n * specification, which is the source of truth for all permission-related types.\n * All specifications must adhere to the {@link PermissionSpecificationBase}\n * interface, but specifications may have different fields depending on the\n * {@link PermissionType}.\n *\n * See the README for more details.\n */\nexport type PermissionSpecificationConstraint =\n | EndowmentSpecificationConstraint\n | RestrictedMethodSpecificationConstraint;\n\n/**\n * Options for {@link PermissionSpecificationBuilder} functions.\n */\ntype PermissionSpecificationBuilderOptions<\n FactoryHooks extends Record<string, unknown>,\n MethodHooks extends Record<string, unknown>,\n ValidatorHooks extends Record<string, unknown>,\n> = {\n targetName?: string;\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n factoryHooks?: FactoryHooks;\n methodHooks?: MethodHooks;\n validatorHooks?: ValidatorHooks;\n};\n\n/**\n * A function that builds a permission specification. Modules that specify\n * permissions for external consumption should make this their primary /\n * default export so that host applications can use them to generate concrete\n * specifications tailored to their requirements.\n */\nexport type PermissionSpecificationBuilder<\n Type extends PermissionType,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Options extends PermissionSpecificationBuilderOptions<any, any, any>,\n Specification extends PermissionSpecificationConstraint & {\n permissionType: Type;\n },\n> = (options: Options) => Specification;\n\n/**\n * A restricted method permission export object, containing the\n * {@link PermissionSpecificationBuilder} function and \"hook name\" objects.\n */\nexport type PermissionSpecificationBuilderExportConstraint = {\n targetName: string;\n specificationBuilder: PermissionSpecificationBuilder<\n PermissionType,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PermissionSpecificationBuilderOptions<any, any, any>,\n PermissionSpecificationConstraint\n >;\n factoryHookNames?: Record<string, true>;\n methodHookNames?: Record<string, true>;\n validatorHookNames?: Record<string, true>;\n};\n\ntype ValidRestrictedMethodSpecification<\n Specification extends RestrictedMethodSpecificationConstraint,\n> = Specification['methodImplementation'] extends ValidRestrictedMethod<\n Specification['methodImplementation']\n>\n ? Specification\n : never;\n\n/**\n * Constraint for {@link PermissionSpecificationConstraint} objects that\n * evaluates to `never` if the specification contains any invalid fields.\n *\n * @template Specification - The permission specification to validate.\n */\nexport type ValidPermissionSpecification<\n Specification extends PermissionSpecificationConstraint,\n> = Specification['targetName'] extends TargetName\n ? Specification['permissionType'] extends PermissionType.Endowment\n ? Specification\n : Specification['permissionType'] extends PermissionType.RestrictedMethod\n ? ValidRestrictedMethodSpecification<\n Extract<Specification, RestrictedMethodSpecificationConstraint>\n >\n : never\n : never;\n\n/**\n * Checks that the specification has the expected permission type.\n *\n * @param specification - The specification to check.\n * @param expectedType - The expected permission type.\n * @template Specification - The specification to check.\n * @template Type - The expected permission type.\n * @returns Whether or not the specification is of the expected type.\n */\nexport function hasSpecificationType<\n Specification extends PermissionSpecificationConstraint,\n Type extends PermissionType,\n>(\n specification: Specification,\n expectedType: Type,\n): specification is Specification & {\n permissionType: Type;\n} {\n return specification.permissionType === expectedType;\n}\n\n/**\n * The specifications for all permissions supported by a particular\n * {@link PermissionController}.\n *\n * @template Specifications - The union of all {@link PermissionSpecificationConstraint} types.\n */\nexport type PermissionSpecificationMap<\n Specification extends PermissionSpecificationConstraint,\n> = {\n [Name in Specification['targetName']]: Specification extends {\n targetName: Name;\n }\n ? Specification\n : never;\n};\n\n/**\n * Extracts a specific {@link PermissionSpecificationConstraint} from a union of\n * permission specifications.\n *\n * @template Specification - The specification union type to extract from.\n * @template Name - The `targetName` of the specification to extract.\n */\nexport type ExtractPermissionSpecification<\n Specification extends PermissionSpecificationConstraint,\n Name extends Specification['targetName'],\n> = Specification extends {\n targetName: Name;\n}\n ? Specification\n : never;\n"]}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PermissionType,
|
|
3
|
+
constructPermission,
|
|
4
|
+
findCaveat,
|
|
5
|
+
hasSpecificationType
|
|
6
|
+
} from "./chunk-ODCVB4BB.mjs";
|
|
7
|
+
import "./chunk-ZSTKOCBT.mjs";
|
|
8
|
+
export {
|
|
9
|
+
PermissionType,
|
|
10
|
+
constructPermission,
|
|
11
|
+
findCaveat,
|
|
12
|
+
hasSpecificationType
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=Permission.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|