@metamask-previews/permission-controller 9.0.2-preview-73f66baf → 9.0.2-preview-4e7f493
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/dist/Caveat.js +4 -4
- package/dist/Caveat.mjs +3 -3
- package/dist/Permission.js +1 -1
- package/dist/Permission.mjs +1 -1
- package/dist/PermissionController.js +7 -7
- package/dist/PermissionController.mjs +6 -6
- package/dist/SubjectMetadataController.js +1 -1
- package/dist/SubjectMetadataController.mjs +1 -1
- package/dist/chunk-2L4QPE5A.mjs +25 -0
- package/dist/chunk-3R56AY2L.mjs +35 -0
- package/dist/chunk-3R56AY2L.mjs.map +1 -0
- package/dist/{chunk-U5LTEXSU.js → chunk-3X6WO7UG.js} +28 -2
- package/dist/chunk-3X6WO7UG.js.map +1 -0
- package/dist/{chunk-MCDOYEJY.mjs → chunk-4B6NOD2D.mjs} +392 -96
- package/dist/chunk-4B6NOD2D.mjs.map +1 -0
- package/dist/{chunk-FEXS6SJF.mjs → chunk-AZUM6CBY.mjs} +27 -1
- package/dist/chunk-AZUM6CBY.mjs.map +1 -0
- package/dist/{chunk-YVXIWLBE.mjs → chunk-DUZPZORW.mjs} +2 -2
- package/dist/{chunk-6Z4WR2GC.js → chunk-DV74ZDGD.js} +7 -7
- package/dist/{chunk-5O77G5L6.js → chunk-GHOOCGN3.js} +4 -4
- package/dist/{chunk-R66I7AKM.js → chunk-I3DJ23QH.js} +437 -141
- package/dist/chunk-I3DJ23QH.js.map +1 -0
- package/dist/chunk-PTE4672I.js +35 -0
- package/dist/chunk-PTE4672I.js.map +1 -0
- package/dist/{chunk-DRXP4C4H.mjs → chunk-RJKSCKTD.mjs} +2 -2
- package/dist/chunk-RJKSCKTD.mjs.map +1 -0
- package/dist/{chunk-JG74NEYV.js → chunk-RKDXFKNN.js} +4 -4
- package/dist/chunk-RKDXFKNN.js.map +1 -0
- package/dist/{chunk-N4KQ2BHF.mjs → chunk-RXC2KFRK.mjs} +2 -2
- package/dist/{chunk-2ISIACR4.mjs → chunk-TBOKQ5NP.mjs} +4 -4
- package/dist/{chunk-AQ35E2HU.js → chunk-VM4LI55W.js} +3 -3
- package/dist/{chunk-YRNH4R3G.js → chunk-XM622CMP.js} +3 -3
- package/dist/{chunk-VFXNNVQY.mjs → chunk-Y6GRGXOL.mjs} +2 -2
- package/dist/chunk-Z2XKIXLS.js +25 -0
- package/dist/errors.js +9 -3
- package/dist/errors.mjs +8 -2
- package/dist/index.js +16 -10
- package/dist/index.mjs +15 -9
- package/dist/permission-middleware.js +4 -4
- package/dist/permission-middleware.mjs +3 -3
- package/dist/rpc-methods/getPermissions.js +2 -2
- package/dist/rpc-methods/getPermissions.mjs +2 -2
- package/dist/rpc-methods/index.js +7 -7
- package/dist/rpc-methods/index.mjs +6 -6
- package/dist/rpc-methods/requestPermissions.js +5 -5
- package/dist/rpc-methods/requestPermissions.mjs +4 -4
- package/dist/rpc-methods/revokePermissions.js +5 -5
- package/dist/rpc-methods/revokePermissions.mjs +4 -4
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/Caveat.d.ts +27 -0
- package/dist/types/Caveat.d.ts.map +1 -1
- package/dist/types/PermissionController.d.ts +113 -20
- package/dist/types/PermissionController.d.ts.map +1 -1
- package/dist/types/errors.d.ts +19 -0
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils.d.ts +19 -2
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/utils.js +5 -3
- package/dist/utils.mjs +6 -4
- package/package.json +1 -1
- package/dist/chunk-CSAU5B4Q.js +0 -10
- package/dist/chunk-DRXP4C4H.mjs.map +0 -1
- package/dist/chunk-FEXS6SJF.mjs.map +0 -1
- package/dist/chunk-JG74NEYV.js.map +0 -1
- package/dist/chunk-K5R57Y57.js +0 -12
- package/dist/chunk-K5R57Y57.js.map +0 -1
- package/dist/chunk-KVKKNDYV.mjs +0 -12
- package/dist/chunk-KVKKNDYV.mjs.map +0 -1
- package/dist/chunk-MCDOYEJY.mjs.map +0 -1
- package/dist/chunk-R66I7AKM.js.map +0 -1
- package/dist/chunk-U5LTEXSU.js.map +0 -1
- package/dist/chunk-ZSTKOCBT.mjs +0 -10
- /package/dist/{chunk-ZSTKOCBT.mjs.map → chunk-2L4QPE5A.mjs.map} +0 -0
- /package/dist/{chunk-YVXIWLBE.mjs.map → chunk-DUZPZORW.mjs.map} +0 -0
- /package/dist/{chunk-6Z4WR2GC.js.map → chunk-DV74ZDGD.js.map} +0 -0
- /package/dist/{chunk-5O77G5L6.js.map → chunk-GHOOCGN3.js.map} +0 -0
- /package/dist/{chunk-N4KQ2BHF.mjs.map → chunk-RXC2KFRK.mjs.map} +0 -0
- /package/dist/{chunk-2ISIACR4.mjs.map → chunk-TBOKQ5NP.mjs.map} +0 -0
- /package/dist/{chunk-AQ35E2HU.js.map → chunk-VM4LI55W.js.map} +0 -0
- /package/dist/{chunk-YRNH4R3G.js.map → chunk-XM622CMP.js.map} +0 -0
- /package/dist/{chunk-VFXNNVQY.mjs.map → chunk-Y6GRGXOL.mjs.map} +0 -0
- /package/dist/{chunk-CSAU5B4Q.js.map → chunk-Z2XKIXLS.js.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkRKDXFKNNjs = require('./chunk-RKDXFKNN.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ var _chunkJG74NEYVjs = require('./chunk-JG74NEYV.js');
|
|
|
10
10
|
var _chunkZH4MLSXXjs = require('./chunk-ZH4MLSXX.js');
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkVM4LI55Wjs = require('./chunk-VM4LI55W.js');
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
@@ -35,7 +35,17 @@ var _chunkAQ35E2HUjs = require('./chunk-AQ35E2HU.js');
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
var _chunk3X6WO7UGjs = require('./chunk-3X6WO7UG.js');
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
var _chunkPTE4672Ijs = require('./chunk-PTE4672I.js');
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
var _chunkZ2XKIXLSjs = require('./chunk-Z2XKIXLS.js');
|
|
39
49
|
|
|
40
50
|
// src/PermissionController.ts
|
|
41
51
|
var _basecontroller = require('@metamask/base-controller');
|
|
@@ -63,15 +73,8 @@ var CaveatMutatorOperation = /* @__PURE__ */ ((CaveatMutatorOperation2) => {
|
|
|
63
73
|
CaveatMutatorOperation2[CaveatMutatorOperation2["revokePermission"] = 3] = "revokePermission";
|
|
64
74
|
return CaveatMutatorOperation2;
|
|
65
75
|
})(CaveatMutatorOperation || {});
|
|
76
|
+
var _expectGetCaveatMerger, expectGetCaveatMerger_fn, _applyGrantedPermissions, applyGrantedPermissions_fn, _mergeIncrementalPermissions, mergeIncrementalPermissions_fn, _mergePermission, mergePermission_fn, _mergeCaveat, mergeCaveat_fn, _handleApprovedPermissions, handleApprovedPermissions_fn;
|
|
66
77
|
var PermissionController = class extends _basecontroller.BaseController {
|
|
67
|
-
/**
|
|
68
|
-
* The names of all JSON-RPC methods that will be ignored by the controller.
|
|
69
|
-
*
|
|
70
|
-
* @returns The names of all unrestricted JSON-RPC methods
|
|
71
|
-
*/
|
|
72
|
-
get unrestrictedMethods() {
|
|
73
|
-
return this._unrestrictedMethods;
|
|
74
|
-
}
|
|
75
78
|
/**
|
|
76
79
|
* Constructs the PermissionController.
|
|
77
80
|
*
|
|
@@ -106,6 +109,62 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
106
109
|
...state
|
|
107
110
|
}
|
|
108
111
|
});
|
|
112
|
+
/**
|
|
113
|
+
* Gets the merger function for the specified caveat. Throws if no
|
|
114
|
+
* merger exists.
|
|
115
|
+
*
|
|
116
|
+
* @param caveatType - The type of the caveat whose merger to get.
|
|
117
|
+
* @returns The caveat value merger function for the specified caveat type.
|
|
118
|
+
*/
|
|
119
|
+
_chunkZ2XKIXLSjs.__privateAdd.call(void 0, this, _expectGetCaveatMerger);
|
|
120
|
+
_chunkZ2XKIXLSjs.__privateAdd.call(void 0, this, _applyGrantedPermissions);
|
|
121
|
+
/**
|
|
122
|
+
* Merges a set of incrementally requested permissions into the existing permissions of
|
|
123
|
+
* the requesting subject. The merge is a right-biased union, where the existing
|
|
124
|
+
* permissions are the left-hand side, and the incrementally requested permissions are
|
|
125
|
+
* the right-hand side.
|
|
126
|
+
*
|
|
127
|
+
* @param existingPermissions - The subject's existing permissions.
|
|
128
|
+
* @param incrementalRequestedPermissions - The requested permissions to merge.
|
|
129
|
+
* @returns The merged permissions and the resulting diff.
|
|
130
|
+
*/
|
|
131
|
+
_chunkZ2XKIXLSjs.__privateAdd.call(void 0, this, _mergeIncrementalPermissions);
|
|
132
|
+
/**
|
|
133
|
+
* Performs a right-biased union between two permissions. The task of merging caveats
|
|
134
|
+
* of the same type between the two permissions is delegated to the corresponding
|
|
135
|
+
* caveat type's merger implementation.
|
|
136
|
+
*
|
|
137
|
+
* Throws if the left-hand and right-hand permissions both have a caveat whose
|
|
138
|
+
* specification does not provide a caveat value merger function.
|
|
139
|
+
*
|
|
140
|
+
* @param leftPermission - The left-hand permission to merge.
|
|
141
|
+
* @param rightPermission - The right-hand permission to merge.
|
|
142
|
+
* @returns The merged permission.
|
|
143
|
+
*/
|
|
144
|
+
_chunkZ2XKIXLSjs.__privateAdd.call(void 0, this, _mergePermission);
|
|
145
|
+
/**
|
|
146
|
+
* Merges two caveats of the same type. The task of merging the values of the
|
|
147
|
+
* two caveats is delegated to the corresponding caveat type's merger implementation.
|
|
148
|
+
*
|
|
149
|
+
* @param leftCaveat - The left-hand caveat to merge.
|
|
150
|
+
* @param rightCaveat - The right-hand caveat to merge.
|
|
151
|
+
* @returns The merged caveat and the diff between the two caveats.
|
|
152
|
+
*/
|
|
153
|
+
_chunkZ2XKIXLSjs.__privateAdd.call(void 0, this, _mergeCaveat);
|
|
154
|
+
/**
|
|
155
|
+
* Accepts a permissions request that has been approved by the user. This
|
|
156
|
+
* method should be called after the user has approved the request and the
|
|
157
|
+
* {@link ApprovalController} has resolved the user approval promise.
|
|
158
|
+
*
|
|
159
|
+
* @param options - Options bag.
|
|
160
|
+
* @param options.subject - The subject to grant permissions to.
|
|
161
|
+
* @param options.metadata - The metadata of the approved permissions request.
|
|
162
|
+
* @param options.preserveExistingPermissions - Whether to preserve the
|
|
163
|
+
* subject's existing permissions.
|
|
164
|
+
* @param options.approvedRequest - The approved permissions request to handle.
|
|
165
|
+
* @returns The granted permissions and request metadata.
|
|
166
|
+
*/
|
|
167
|
+
_chunkZ2XKIXLSjs.__privateAdd.call(void 0, this, _handleApprovedPermissions);
|
|
109
168
|
this._unrestrictedMethods = new Set(unrestrictedMethods);
|
|
110
169
|
this._caveatSpecifications = _deepfreezestrict2.default.call(void 0, { ...caveatSpecifications });
|
|
111
170
|
this.validatePermissionSpecifications(
|
|
@@ -116,7 +175,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
116
175
|
...permissionSpecifications
|
|
117
176
|
});
|
|
118
177
|
this.registerMessageHandlers();
|
|
119
|
-
this.createPermissionMiddleware =
|
|
178
|
+
this.createPermissionMiddleware = _chunkVM4LI55Wjs.getPermissionMiddlewareFactory.call(void 0, {
|
|
120
179
|
executeRestrictedMethod: this._executeRestrictedMethod.bind(this),
|
|
121
180
|
getRestrictedMethod: this.getRestrictedMethod.bind(this),
|
|
122
181
|
isUnrestrictedMethod: this.unrestrictedMethods.has.bind(
|
|
@@ -124,6 +183,14 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
124
183
|
)
|
|
125
184
|
});
|
|
126
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* The names of all JSON-RPC methods that will be ignored by the controller.
|
|
188
|
+
*
|
|
189
|
+
* @returns The names of all unrestricted JSON-RPC methods
|
|
190
|
+
*/
|
|
191
|
+
get unrestrictedMethods() {
|
|
192
|
+
return this._unrestrictedMethods;
|
|
193
|
+
}
|
|
127
194
|
/**
|
|
128
195
|
* Gets a permission specification.
|
|
129
196
|
*
|
|
@@ -174,12 +241,12 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
174
241
|
if (allowedCaveats) {
|
|
175
242
|
allowedCaveats.forEach((caveatType) => {
|
|
176
243
|
if (!_utils.hasProperty.call(void 0, caveatSpecifications, caveatType)) {
|
|
177
|
-
throw new (0,
|
|
244
|
+
throw new (0, _chunk3X6WO7UGjs.UnrecognizedCaveatTypeError)(caveatType);
|
|
178
245
|
}
|
|
179
246
|
const specification = caveatSpecifications[caveatType];
|
|
180
|
-
const isRestrictedMethodCaveat =
|
|
247
|
+
const isRestrictedMethodCaveat = _chunkRKDXFKNNjs.isRestrictedMethodCaveatSpecification.call(void 0, specification);
|
|
181
248
|
if (permissionType === "RestrictedMethod" /* RestrictedMethod */ && !isRestrictedMethodCaveat || permissionType === "Endowment" /* Endowment */ && isRestrictedMethodCaveat) {
|
|
182
|
-
throw new (0,
|
|
249
|
+
throw new (0, _chunk3X6WO7UGjs.CaveatSpecificationMismatchError)(
|
|
183
250
|
specification,
|
|
184
251
|
permissionType
|
|
185
252
|
);
|
|
@@ -222,10 +289,18 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
222
289
|
`${controllerName}:grantPermissions`,
|
|
223
290
|
this.grantPermissions.bind(this)
|
|
224
291
|
);
|
|
292
|
+
this.messagingSystem.registerActionHandler(
|
|
293
|
+
`${controllerName}:grantPermissionsIncremental`,
|
|
294
|
+
this.grantPermissionsIncremental.bind(this)
|
|
295
|
+
);
|
|
225
296
|
this.messagingSystem.registerActionHandler(
|
|
226
297
|
`${controllerName}:requestPermissions`,
|
|
227
298
|
(subject, permissions) => this.requestPermissions(subject, permissions)
|
|
228
299
|
);
|
|
300
|
+
this.messagingSystem.registerActionHandler(
|
|
301
|
+
`${controllerName}:requestPermissionsIncremental`,
|
|
302
|
+
(subject, permissions) => this.requestPermissionsIncremental(subject, permissions)
|
|
303
|
+
);
|
|
229
304
|
this.messagingSystem.registerActionHandler(
|
|
230
305
|
`${controllerName}:revokeAllPermissions`,
|
|
231
306
|
(origin) => this.revokeAllPermissions(origin)
|
|
@@ -275,10 +350,10 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
275
350
|
* target name.
|
|
276
351
|
*/
|
|
277
352
|
getTypedPermissionSpecification(permissionType, targetName, requestingOrigin) {
|
|
278
|
-
const failureError = permissionType === "RestrictedMethod" /* RestrictedMethod */ ?
|
|
353
|
+
const failureError = permissionType === "RestrictedMethod" /* RestrictedMethod */ ? _chunk3X6WO7UGjs.methodNotFound.call(void 0,
|
|
279
354
|
targetName,
|
|
280
355
|
requestingOrigin ? { origin: requestingOrigin } : void 0
|
|
281
|
-
) : new (0,
|
|
356
|
+
) : new (0, _chunk3X6WO7UGjs.EndowmentPermissionDoesNotExistError)(
|
|
282
357
|
targetName,
|
|
283
358
|
requestingOrigin
|
|
284
359
|
);
|
|
@@ -370,7 +445,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
370
445
|
revokeAllPermissions(origin) {
|
|
371
446
|
this.update((draftState) => {
|
|
372
447
|
if (!draftState.subjects[origin]) {
|
|
373
|
-
throw new (0,
|
|
448
|
+
throw new (0, _chunk3X6WO7UGjs.UnrecognizedSubjectError)(origin);
|
|
374
449
|
}
|
|
375
450
|
delete draftState.subjects[origin];
|
|
376
451
|
});
|
|
@@ -399,12 +474,12 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
399
474
|
this.update((draftState) => {
|
|
400
475
|
Object.keys(subjectsAndPermissions).forEach((origin) => {
|
|
401
476
|
if (!_utils.hasProperty.call(void 0, draftState.subjects, origin)) {
|
|
402
|
-
throw new (0,
|
|
477
|
+
throw new (0, _chunk3X6WO7UGjs.UnrecognizedSubjectError)(origin);
|
|
403
478
|
}
|
|
404
479
|
subjectsAndPermissions[origin].forEach((target) => {
|
|
405
480
|
const { permissions } = draftState.subjects[origin];
|
|
406
481
|
if (!_utils.hasProperty.call(void 0, permissions, target)) {
|
|
407
|
-
throw new (0,
|
|
482
|
+
throw new (0, _chunk3X6WO7UGjs.PermissionDoesNotExistError)(origin, target);
|
|
408
483
|
}
|
|
409
484
|
this.deletePermission(draftState.subjects, origin, target);
|
|
410
485
|
});
|
|
@@ -484,7 +559,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
484
559
|
getCaveat(origin, target, caveatType) {
|
|
485
560
|
const permission = this.getPermission(origin, target);
|
|
486
561
|
if (!permission) {
|
|
487
|
-
throw new (0,
|
|
562
|
+
throw new (0, _chunk3X6WO7UGjs.PermissionDoesNotExistError)(origin, target);
|
|
488
563
|
}
|
|
489
564
|
return _chunkZH4MLSXXjs.findCaveat.call(void 0, permission, caveatType);
|
|
490
565
|
}
|
|
@@ -509,7 +584,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
509
584
|
*/
|
|
510
585
|
addCaveat(origin, target, caveatType, caveatValue) {
|
|
511
586
|
if (this.hasCaveat(origin, target, caveatType)) {
|
|
512
|
-
throw new (0,
|
|
587
|
+
throw new (0, _chunk3X6WO7UGjs.CaveatAlreadyExistsError)(origin, target, caveatType);
|
|
513
588
|
}
|
|
514
589
|
this.setCaveat(origin, target, caveatType, caveatValue);
|
|
515
590
|
}
|
|
@@ -533,7 +608,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
533
608
|
*/
|
|
534
609
|
updateCaveat(origin, target, caveatType, caveatValue) {
|
|
535
610
|
if (!this.hasCaveat(origin, target, caveatType)) {
|
|
536
|
-
throw new (0,
|
|
611
|
+
throw new (0, _chunk3X6WO7UGjs.CaveatDoesNotExistError)(origin, target, caveatType);
|
|
537
612
|
}
|
|
538
613
|
this.setCaveat(origin, target, caveatType, caveatValue);
|
|
539
614
|
}
|
|
@@ -559,11 +634,11 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
559
634
|
this.update((draftState) => {
|
|
560
635
|
const subject = draftState.subjects[origin];
|
|
561
636
|
if (!subject) {
|
|
562
|
-
throw new (0,
|
|
637
|
+
throw new (0, _chunk3X6WO7UGjs.UnrecognizedSubjectError)(origin);
|
|
563
638
|
}
|
|
564
639
|
const permission = subject.permissions[target];
|
|
565
640
|
if (!permission) {
|
|
566
|
-
throw new (0,
|
|
641
|
+
throw new (0, _chunk3X6WO7UGjs.PermissionDoesNotExistError)(origin, target);
|
|
567
642
|
}
|
|
568
643
|
const caveat = {
|
|
569
644
|
type: caveatType,
|
|
@@ -670,10 +745,10 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
670
745
|
this.update((draftState) => {
|
|
671
746
|
const permission = draftState.subjects[origin]?.permissions[target];
|
|
672
747
|
if (!permission) {
|
|
673
|
-
throw new (0,
|
|
748
|
+
throw new (0, _chunk3X6WO7UGjs.PermissionDoesNotExistError)(origin, target);
|
|
674
749
|
}
|
|
675
750
|
if (!permission.caveats) {
|
|
676
|
-
throw new (0,
|
|
751
|
+
throw new (0, _chunk3X6WO7UGjs.CaveatDoesNotExistError)(origin, target, caveatType);
|
|
677
752
|
}
|
|
678
753
|
this.deleteCaveat(permission, caveatType, origin);
|
|
679
754
|
});
|
|
@@ -692,7 +767,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
692
767
|
*/
|
|
693
768
|
deleteCaveat(permission, caveatType, origin) {
|
|
694
769
|
if (!permission.caveats) {
|
|
695
|
-
throw new (0,
|
|
770
|
+
throw new (0, _chunk3X6WO7UGjs.CaveatDoesNotExistError)(
|
|
696
771
|
origin,
|
|
697
772
|
permission.parentCapability,
|
|
698
773
|
caveatType
|
|
@@ -702,7 +777,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
702
777
|
(existingCaveat) => existingCaveat.type === caveatType
|
|
703
778
|
);
|
|
704
779
|
if (caveatIndex === -1) {
|
|
705
|
-
throw new (0,
|
|
780
|
+
throw new (0, _chunk3X6WO7UGjs.CaveatDoesNotExistError)(
|
|
706
781
|
origin,
|
|
707
782
|
permission.parentCapability,
|
|
708
783
|
caveatType
|
|
@@ -750,10 +825,11 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
750
825
|
}
|
|
751
826
|
/**
|
|
752
827
|
* Grants _approved_ permissions to the specified subject. Every permission and
|
|
753
|
-
* caveat is stringently validated
|
|
754
|
-
*
|
|
828
|
+
* caveat is stringently validated—including by calling their specification
|
|
829
|
+
* validators—and an error is thrown if validation fails.
|
|
755
830
|
*
|
|
756
|
-
* ATTN: This method does **not** prompt the user for approval.
|
|
831
|
+
* ATTN: This method does **not** prompt the user for approval. User consent must
|
|
832
|
+
* first be obtained through some other means.
|
|
757
833
|
*
|
|
758
834
|
* @see {@link PermissionController.requestPermissions} For initiating a
|
|
759
835
|
* permissions request requiring user approval.
|
|
@@ -765,7 +841,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
765
841
|
* @param options.preserveExistingPermissions - Whether to preserve the
|
|
766
842
|
* subject's existing permissions.
|
|
767
843
|
* @param options.subject - The subject to grant permissions to.
|
|
768
|
-
* @returns The
|
|
844
|
+
* @returns The subject's new permission state. It may or may not have changed.
|
|
769
845
|
*/
|
|
770
846
|
grantPermissions({
|
|
771
847
|
approvedPermissions,
|
|
@@ -773,53 +849,44 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
773
849
|
preserveExistingPermissions = true,
|
|
774
850
|
subject
|
|
775
851
|
}) {
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
this.validatePermission(specification, permission, origin, {
|
|
815
|
-
invokePermissionValidator: true,
|
|
816
|
-
performCaveatValidation: false
|
|
817
|
-
});
|
|
818
|
-
}
|
|
819
|
-
permissions[targetName] = permission;
|
|
820
|
-
}
|
|
821
|
-
this.setValidatedPermissions(origin, permissions);
|
|
822
|
-
return permissions;
|
|
852
|
+
return _chunkZ2XKIXLSjs.__privateMethod.call(void 0, this, _applyGrantedPermissions, applyGrantedPermissions_fn).call(this, {
|
|
853
|
+
approvedPermissions,
|
|
854
|
+
subject,
|
|
855
|
+
mergePermissions: false,
|
|
856
|
+
preserveExistingPermissions,
|
|
857
|
+
requestData
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Incrementally grants _approved_ permissions to the specified subject. Every
|
|
862
|
+
* permission and caveat is stringently validated—including by calling their
|
|
863
|
+
* specification validators—and an error is thrown if validation fails.
|
|
864
|
+
*
|
|
865
|
+
* ATTN: This method does **not** prompt the user for approval. User consent must
|
|
866
|
+
* first be obtained through some other means.
|
|
867
|
+
*
|
|
868
|
+
* @see {@link PermissionController.requestPermissionsIncremental} For initiating
|
|
869
|
+
* an incremental permissions request requiring user approval.
|
|
870
|
+
* @param options - Options bag.
|
|
871
|
+
* @param options.approvedPermissions - The requested permissions approved by
|
|
872
|
+
* the user.
|
|
873
|
+
* @param options.requestData - Permission request data. Passed to permission
|
|
874
|
+
* factory functions.
|
|
875
|
+
* @param options.subject - The subject to grant permissions to.
|
|
876
|
+
* @returns The subject's new permission state. It may or may not have changed.
|
|
877
|
+
*/
|
|
878
|
+
grantPermissionsIncremental({
|
|
879
|
+
approvedPermissions,
|
|
880
|
+
requestData,
|
|
881
|
+
subject
|
|
882
|
+
}) {
|
|
883
|
+
return _chunkZ2XKIXLSjs.__privateMethod.call(void 0, this, _applyGrantedPermissions, applyGrantedPermissions_fn).call(this, {
|
|
884
|
+
approvedPermissions,
|
|
885
|
+
subject,
|
|
886
|
+
mergePermissions: true,
|
|
887
|
+
preserveExistingPermissions: true,
|
|
888
|
+
requestData
|
|
889
|
+
});
|
|
823
890
|
}
|
|
824
891
|
/**
|
|
825
892
|
* Validates the specified permission by:
|
|
@@ -853,13 +920,13 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
853
920
|
origin
|
|
854
921
|
);
|
|
855
922
|
if (!metadata || metadata.subjectType === null || !specification.subjectTypes.includes(metadata.subjectType)) {
|
|
856
|
-
throw specification.permissionType === "RestrictedMethod" /* RestrictedMethod */ ?
|
|
923
|
+
throw specification.permissionType === "RestrictedMethod" /* RestrictedMethod */ ? _chunk3X6WO7UGjs.methodNotFound.call(void 0, targetName, { origin }) : new (0, _chunk3X6WO7UGjs.EndowmentPermissionDoesNotExistError)(targetName, origin);
|
|
857
924
|
}
|
|
858
925
|
}
|
|
859
926
|
if (_utils.hasProperty.call(void 0, permission, "caveats")) {
|
|
860
927
|
const { caveats } = permission;
|
|
861
928
|
if (caveats !== null && !(Array.isArray(caveats) && caveats.length > 0)) {
|
|
862
|
-
throw new (0,
|
|
929
|
+
throw new (0, _chunk3X6WO7UGjs.InvalidCaveatsPropertyError)(origin, targetName, caveats);
|
|
863
930
|
}
|
|
864
931
|
const seenCaveatTypes = /* @__PURE__ */ new Set();
|
|
865
932
|
caveats?.forEach((caveat) => {
|
|
@@ -867,10 +934,10 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
867
934
|
this.validateCaveat(caveat, origin, targetName);
|
|
868
935
|
}
|
|
869
936
|
if (!allowedCaveats?.includes(caveat.type)) {
|
|
870
|
-
throw new (0,
|
|
937
|
+
throw new (0, _chunk3X6WO7UGjs.ForbiddenCaveatError)(caveat.type, origin, targetName);
|
|
871
938
|
}
|
|
872
939
|
if (seenCaveatTypes.has(caveat.type)) {
|
|
873
|
-
throw new (0,
|
|
940
|
+
throw new (0, _chunk3X6WO7UGjs.DuplicateCaveatError)(caveat.type, origin, targetName);
|
|
874
941
|
}
|
|
875
942
|
seenCaveatTypes.add(caveat.type);
|
|
876
943
|
});
|
|
@@ -931,30 +998,32 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
931
998
|
*/
|
|
932
999
|
validateCaveat(caveat, origin, target) {
|
|
933
1000
|
if (!_controllerutils.isPlainObject.call(void 0, caveat)) {
|
|
934
|
-
throw new (0,
|
|
1001
|
+
throw new (0, _chunk3X6WO7UGjs.InvalidCaveatError)(caveat, origin, target);
|
|
935
1002
|
}
|
|
936
1003
|
if (Object.keys(caveat).length !== 2) {
|
|
937
|
-
throw new (0,
|
|
1004
|
+
throw new (0, _chunk3X6WO7UGjs.InvalidCaveatFieldsError)(caveat, origin, target);
|
|
938
1005
|
}
|
|
939
1006
|
if (typeof caveat.type !== "string") {
|
|
940
|
-
throw new (0,
|
|
1007
|
+
throw new (0, _chunk3X6WO7UGjs.InvalidCaveatTypeError)(caveat, origin, target);
|
|
941
1008
|
}
|
|
942
1009
|
const specification = this.getCaveatSpecification(caveat.type);
|
|
943
1010
|
if (!specification) {
|
|
944
|
-
throw new (0,
|
|
1011
|
+
throw new (0, _chunk3X6WO7UGjs.UnrecognizedCaveatTypeError)(caveat.type, origin, target);
|
|
945
1012
|
}
|
|
946
1013
|
if (!_utils.hasProperty.call(void 0, caveat, "value") || caveat.value === void 0) {
|
|
947
|
-
throw new (0,
|
|
1014
|
+
throw new (0, _chunk3X6WO7UGjs.CaveatMissingValueError)(caveat, origin, target);
|
|
948
1015
|
}
|
|
949
1016
|
if (!_controllerutils.isValidJson.call(void 0, caveat.value)) {
|
|
950
|
-
throw new (0,
|
|
1017
|
+
throw new (0, _chunk3X6WO7UGjs.CaveatInvalidJsonError)(caveat, origin, target);
|
|
951
1018
|
}
|
|
952
1019
|
specification.validator?.(caveat, origin, target);
|
|
953
1020
|
}
|
|
954
1021
|
/**
|
|
955
|
-
* Initiates a permission request that requires user approval.
|
|
956
|
-
*
|
|
957
|
-
*
|
|
1022
|
+
* Initiates a permission request that requires user approval.
|
|
1023
|
+
*
|
|
1024
|
+
* Either this or {@link PermissionController.requestPermissionsIncremental}
|
|
1025
|
+
* should always be used to grant additional permissions to a subject,
|
|
1026
|
+
* unless user approval has been obtained through some other means.
|
|
958
1027
|
*
|
|
959
1028
|
* Permissions are validated at every step of the approval process, and this
|
|
960
1029
|
* method will reject if validation fails.
|
|
@@ -988,36 +1057,85 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
988
1057
|
permissions: requestedPermissions
|
|
989
1058
|
};
|
|
990
1059
|
const approvedRequest = await this.requestUserApproval(permissionsRequest);
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1060
|
+
return await _chunkZ2XKIXLSjs.__privateMethod.call(void 0, this, _handleApprovedPermissions, handleApprovedPermissions_fn).call(this, {
|
|
1061
|
+
subject,
|
|
1062
|
+
metadata,
|
|
1063
|
+
preserveExistingPermissions,
|
|
1064
|
+
approvedRequest
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* Initiates an incremental permission request that prompts for user approval.
|
|
1069
|
+
* Incremental permission requests allow the caller to replace existing and/or
|
|
1070
|
+
* add brand new permissions and caveats for the specified subject.
|
|
1071
|
+
*
|
|
1072
|
+
* Incremental permission request are merged with the subject's existing permissions
|
|
1073
|
+
* through a right-biased union, where the incremental permission are the right-hand
|
|
1074
|
+
* side of the merger. If both sides of the merger specify the same caveats for a
|
|
1075
|
+
* given permission, the caveats are merged using their specification's caveat value
|
|
1076
|
+
* merger property.
|
|
1077
|
+
*
|
|
1078
|
+
* Either this or {@link PermissionController.requestPermissions} should
|
|
1079
|
+
* always be used to grant additional permissions to a subject, unless user
|
|
1080
|
+
* approval has been obtained through some other means.
|
|
1081
|
+
*
|
|
1082
|
+
* Permissions are validated at every step of the approval process, and this
|
|
1083
|
+
* method will reject if validation fails.
|
|
1084
|
+
*
|
|
1085
|
+
* @see {@link ApprovalController} For the user approval logic.
|
|
1086
|
+
* @see {@link PermissionController.acceptPermissionsRequest} For the method
|
|
1087
|
+
* that _accepts_ the request and resolves the user approval promise.
|
|
1088
|
+
* @see {@link PermissionController.rejectPermissionsRequest} For the method
|
|
1089
|
+
* that _rejects_ the request and the user approval promise.
|
|
1090
|
+
* @param subject - The grantee subject.
|
|
1091
|
+
* @param requestedPermissions - The requested permissions.
|
|
1092
|
+
* @param options - Additional options.
|
|
1093
|
+
* @param options.id - The id of the permissions request. Defaults to a unique
|
|
1094
|
+
* id.
|
|
1095
|
+
* @param options.metadata - Additional metadata about the permission request.
|
|
1096
|
+
* @returns The granted permissions and request metadata.
|
|
1097
|
+
*/
|
|
1098
|
+
async requestPermissionsIncremental(subject, requestedPermissions, options = {}) {
|
|
1099
|
+
const { origin } = subject;
|
|
1100
|
+
const { id = _nanoid.nanoid.call(void 0, ) } = options;
|
|
1101
|
+
this.validateRequestedPermissions(origin, requestedPermissions);
|
|
1102
|
+
const currentPermissions = this.getPermissions(origin) ?? {};
|
|
1103
|
+
const [newPermissions, permissionDiffMap] = _chunkZ2XKIXLSjs.__privateMethod.call(void 0, this, _mergeIncrementalPermissions, mergeIncrementalPermissions_fn).call(this, currentPermissions, requestedPermissions);
|
|
1104
|
+
if (newPermissions === void 0 || permissionDiffMap === void 0) {
|
|
1105
|
+
return [];
|
|
1011
1106
|
}
|
|
1012
|
-
|
|
1013
|
-
this.
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1107
|
+
try {
|
|
1108
|
+
this.validateRequestedPermissions(origin, newPermissions);
|
|
1109
|
+
} catch (error) {
|
|
1110
|
+
if (error instanceof Error) {
|
|
1111
|
+
throw new (0, _chunk3X6WO7UGjs.InvalidMergedPermissionsError)(
|
|
1112
|
+
origin,
|
|
1113
|
+
error,
|
|
1114
|
+
permissionDiffMap
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
throw _chunk3X6WO7UGjs.internalError.call(void 0, "Unrecognized error type", { error });
|
|
1118
|
+
}
|
|
1119
|
+
const metadata = {
|
|
1120
|
+
...options.metadata,
|
|
1121
|
+
id,
|
|
1122
|
+
origin
|
|
1123
|
+
};
|
|
1124
|
+
const permissionsRequest = {
|
|
1125
|
+
metadata,
|
|
1126
|
+
permissions: newPermissions,
|
|
1127
|
+
diff: {
|
|
1128
|
+
currentPermissions,
|
|
1129
|
+
permissionDiffMap
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
const approvedRequest = await this.requestUserApproval(permissionsRequest);
|
|
1133
|
+
return await _chunkZ2XKIXLSjs.__privateMethod.call(void 0, this, _handleApprovedPermissions, handleApprovedPermissions_fn).call(this, {
|
|
1134
|
+
subject,
|
|
1135
|
+
metadata,
|
|
1136
|
+
preserveExistingPermissions: false,
|
|
1137
|
+
approvedRequest
|
|
1138
|
+
});
|
|
1021
1139
|
}
|
|
1022
1140
|
/**
|
|
1023
1141
|
* Validates requested permissions. Throws if validation fails.
|
|
@@ -1036,13 +1154,13 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1036
1154
|
*/
|
|
1037
1155
|
validateRequestedPermissions(origin, requestedPermissions) {
|
|
1038
1156
|
if (!_controllerutils.isPlainObject.call(void 0, requestedPermissions)) {
|
|
1039
|
-
throw
|
|
1157
|
+
throw _chunk3X6WO7UGjs.invalidParams.call(void 0, {
|
|
1040
1158
|
message: `Requested permissions for origin "${origin}" is not a plain object.`,
|
|
1041
1159
|
data: { origin, requestedPermissions }
|
|
1042
1160
|
});
|
|
1043
1161
|
}
|
|
1044
1162
|
if (Object.keys(requestedPermissions).length === 0) {
|
|
1045
|
-
throw
|
|
1163
|
+
throw _chunk3X6WO7UGjs.invalidParams.call(void 0, {
|
|
1046
1164
|
message: `Permissions request for origin "${origin}" contains no permissions.`,
|
|
1047
1165
|
data: { requestedPermissions }
|
|
1048
1166
|
});
|
|
@@ -1050,10 +1168,10 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1050
1168
|
for (const targetName of Object.keys(requestedPermissions)) {
|
|
1051
1169
|
const permission = requestedPermissions[targetName];
|
|
1052
1170
|
if (!this.targetExists(targetName)) {
|
|
1053
|
-
throw
|
|
1171
|
+
throw _chunk3X6WO7UGjs.methodNotFound.call(void 0, targetName, { origin, requestedPermissions });
|
|
1054
1172
|
}
|
|
1055
1173
|
if (!_controllerutils.isPlainObject.call(void 0, permission) || permission.parentCapability !== void 0 && targetName !== permission.parentCapability) {
|
|
1056
|
-
throw
|
|
1174
|
+
throw _chunk3X6WO7UGjs.invalidParams.call(void 0, {
|
|
1057
1175
|
message: `Permissions request for origin "${origin}" contains invalid requested permission(s).`,
|
|
1058
1176
|
data: { origin, requestedPermissions }
|
|
1059
1177
|
});
|
|
@@ -1143,14 +1261,14 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1143
1261
|
failureHandlersList.map((failureHandler) => failureHandler(params))
|
|
1144
1262
|
);
|
|
1145
1263
|
} catch (error) {
|
|
1146
|
-
throw
|
|
1264
|
+
throw _chunk3X6WO7UGjs.internalError.call(void 0, "Unexpected error in side-effects", { error });
|
|
1147
1265
|
}
|
|
1148
1266
|
}
|
|
1149
1267
|
const reasons = rejectedHandlers.map((handler) => handler.reason);
|
|
1150
1268
|
reasons.forEach((reason) => {
|
|
1151
1269
|
console.error(reason);
|
|
1152
1270
|
});
|
|
1153
|
-
throw reasons.length > 1 ?
|
|
1271
|
+
throw reasons.length > 1 ? _chunk3X6WO7UGjs.internalError.call(void 0,
|
|
1154
1272
|
"Multiple errors occurred during side-effects execution",
|
|
1155
1273
|
{ errors: reasons }
|
|
1156
1274
|
) : reasons[0];
|
|
@@ -1175,7 +1293,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1175
1293
|
validateApprovedPermissions(approvedRequest, originalMetadata) {
|
|
1176
1294
|
const { id, origin } = originalMetadata;
|
|
1177
1295
|
if (!_controllerutils.isPlainObject.call(void 0, approvedRequest) || !_controllerutils.isPlainObject.call(void 0, approvedRequest.metadata)) {
|
|
1178
|
-
throw
|
|
1296
|
+
throw _chunk3X6WO7UGjs.internalError.call(void 0,
|
|
1179
1297
|
`Approved permissions request for subject "${origin}" is invalid.`,
|
|
1180
1298
|
{ data: { approvedRequest } }
|
|
1181
1299
|
);
|
|
@@ -1185,13 +1303,13 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1185
1303
|
permissions
|
|
1186
1304
|
} = approvedRequest;
|
|
1187
1305
|
if (newId !== id) {
|
|
1188
|
-
throw
|
|
1306
|
+
throw _chunk3X6WO7UGjs.internalError.call(void 0,
|
|
1189
1307
|
`Approved permissions request for subject "${origin}" mutated its id.`,
|
|
1190
1308
|
{ originalId: id, mutatedId: newId }
|
|
1191
1309
|
);
|
|
1192
1310
|
}
|
|
1193
1311
|
if (newOrigin !== origin) {
|
|
1194
|
-
throw
|
|
1312
|
+
throw _chunk3X6WO7UGjs.internalError.call(void 0,
|
|
1195
1313
|
`Approved permissions request for subject "${origin}" mutated its origin.`,
|
|
1196
1314
|
{ originalOrigin: origin, mutatedOrigin: newOrigin }
|
|
1197
1315
|
);
|
|
@@ -1200,12 +1318,12 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1200
1318
|
this.validateRequestedPermissions(origin, permissions);
|
|
1201
1319
|
} catch (error) {
|
|
1202
1320
|
if (error instanceof Error) {
|
|
1203
|
-
throw
|
|
1321
|
+
throw _chunk3X6WO7UGjs.internalError.call(void 0,
|
|
1204
1322
|
`Invalid approved permissions request: ${error.message}`,
|
|
1205
1323
|
error instanceof _rpcerrors.JsonRpcError ? error.data : void 0
|
|
1206
1324
|
);
|
|
1207
1325
|
}
|
|
1208
|
-
throw
|
|
1326
|
+
throw _chunk3X6WO7UGjs.internalError.call(void 0, "Unrecognized error type", { error });
|
|
1209
1327
|
}
|
|
1210
1328
|
}
|
|
1211
1329
|
/**
|
|
@@ -1217,12 +1335,12 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1217
1335
|
async acceptPermissionsRequest(request) {
|
|
1218
1336
|
const { id } = request.metadata;
|
|
1219
1337
|
if (!this.hasApprovalRequest({ id })) {
|
|
1220
|
-
throw new (0,
|
|
1338
|
+
throw new (0, _chunk3X6WO7UGjs.PermissionsRequestNotFoundError)(id);
|
|
1221
1339
|
}
|
|
1222
1340
|
if (Object.keys(request.permissions).length === 0) {
|
|
1223
1341
|
this._rejectPermissionsRequest(
|
|
1224
1342
|
id,
|
|
1225
|
-
|
|
1343
|
+
_chunk3X6WO7UGjs.invalidParams.call(void 0, {
|
|
1226
1344
|
message: "Must request at least one permission."
|
|
1227
1345
|
})
|
|
1228
1346
|
);
|
|
@@ -1247,9 +1365,9 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1247
1365
|
*/
|
|
1248
1366
|
async rejectPermissionsRequest(id) {
|
|
1249
1367
|
if (!this.hasApprovalRequest({ id })) {
|
|
1250
|
-
throw new (0,
|
|
1368
|
+
throw new (0, _chunk3X6WO7UGjs.PermissionsRequestNotFoundError)(id);
|
|
1251
1369
|
}
|
|
1252
|
-
this._rejectPermissionsRequest(id,
|
|
1370
|
+
this._rejectPermissionsRequest(id, _chunk3X6WO7UGjs.userRejectedRequest.call(void 0, ));
|
|
1253
1371
|
}
|
|
1254
1372
|
/**
|
|
1255
1373
|
* Checks whether the {@link ApprovalController} has a particular permissions
|
|
@@ -1296,7 +1414,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1296
1414
|
*/
|
|
1297
1415
|
async getEndowments(origin, targetName, requestData) {
|
|
1298
1416
|
if (!this.hasPermission(origin, targetName)) {
|
|
1299
|
-
throw
|
|
1417
|
+
throw _chunk3X6WO7UGjs.unauthorized.call(void 0, { data: { origin, targetName } });
|
|
1300
1418
|
}
|
|
1301
1419
|
return this.getTypedPermissionSpecification(
|
|
1302
1420
|
"Endowment" /* Endowment */,
|
|
@@ -1366,18 +1484,196 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1366
1484
|
const { origin } = subject;
|
|
1367
1485
|
const permission = this.getPermission(origin, method);
|
|
1368
1486
|
if (!permission) {
|
|
1369
|
-
throw
|
|
1487
|
+
throw _chunk3X6WO7UGjs.unauthorized.call(void 0, { data: { origin, method } });
|
|
1370
1488
|
}
|
|
1371
|
-
return
|
|
1489
|
+
return _chunkRKDXFKNNjs.decorateWithCaveats.call(void 0,
|
|
1372
1490
|
methodImplementation,
|
|
1373
1491
|
permission,
|
|
1374
1492
|
this._caveatSpecifications
|
|
1375
1493
|
)({ method, params, context: { origin } });
|
|
1376
1494
|
}
|
|
1377
1495
|
};
|
|
1496
|
+
_expectGetCaveatMerger = new WeakSet();
|
|
1497
|
+
expectGetCaveatMerger_fn = function(caveatType) {
|
|
1498
|
+
const { merger } = this.getCaveatSpecification(caveatType);
|
|
1499
|
+
if (merger === void 0) {
|
|
1500
|
+
throw new (0, _chunk3X6WO7UGjs.CaveatMergerDoesNotExistError)(caveatType);
|
|
1501
|
+
}
|
|
1502
|
+
return merger;
|
|
1503
|
+
};
|
|
1504
|
+
_applyGrantedPermissions = new WeakSet();
|
|
1505
|
+
applyGrantedPermissions_fn = function({
|
|
1506
|
+
approvedPermissions,
|
|
1507
|
+
subject,
|
|
1508
|
+
mergePermissions,
|
|
1509
|
+
preserveExistingPermissions,
|
|
1510
|
+
requestData
|
|
1511
|
+
}) {
|
|
1512
|
+
const { origin } = subject;
|
|
1513
|
+
if (!origin || typeof origin !== "string") {
|
|
1514
|
+
throw new (0, _chunk3X6WO7UGjs.InvalidSubjectIdentifierError)(origin);
|
|
1515
|
+
}
|
|
1516
|
+
const permissions = preserveExistingPermissions ? {
|
|
1517
|
+
...this.getPermissions(origin)
|
|
1518
|
+
} : {};
|
|
1519
|
+
for (const [requestedTarget, approvedPermission] of Object.entries(
|
|
1520
|
+
approvedPermissions
|
|
1521
|
+
)) {
|
|
1522
|
+
if (!this.targetExists(requestedTarget)) {
|
|
1523
|
+
throw _chunk3X6WO7UGjs.methodNotFound.call(void 0, requestedTarget);
|
|
1524
|
+
}
|
|
1525
|
+
if (approvedPermission.parentCapability !== void 0 && requestedTarget !== approvedPermission.parentCapability) {
|
|
1526
|
+
throw new (0, _chunk3X6WO7UGjs.InvalidApprovedPermissionError)(
|
|
1527
|
+
origin,
|
|
1528
|
+
requestedTarget,
|
|
1529
|
+
approvedPermission
|
|
1530
|
+
);
|
|
1531
|
+
}
|
|
1532
|
+
const targetName = requestedTarget;
|
|
1533
|
+
const specification = this.getPermissionSpecification(targetName);
|
|
1534
|
+
const caveats = this.constructCaveats(
|
|
1535
|
+
origin,
|
|
1536
|
+
targetName,
|
|
1537
|
+
approvedPermission.caveats
|
|
1538
|
+
);
|
|
1539
|
+
const permissionOptions = {
|
|
1540
|
+
caveats,
|
|
1541
|
+
invoker: origin,
|
|
1542
|
+
target: targetName
|
|
1543
|
+
};
|
|
1544
|
+
let permission;
|
|
1545
|
+
let performCaveatValidation = true;
|
|
1546
|
+
if (specification.factory) {
|
|
1547
|
+
permission = specification.factory(permissionOptions, requestData);
|
|
1548
|
+
} else {
|
|
1549
|
+
permission = _chunkZH4MLSXXjs.constructPermission.call(void 0, permissionOptions);
|
|
1550
|
+
performCaveatValidation = false;
|
|
1551
|
+
}
|
|
1552
|
+
if (mergePermissions) {
|
|
1553
|
+
permission = _chunkZ2XKIXLSjs.__privateMethod.call(void 0, this, _mergePermission, mergePermission_fn).call(this, permissions[targetName], permission)[0];
|
|
1554
|
+
}
|
|
1555
|
+
this.validatePermission(specification, permission, origin, {
|
|
1556
|
+
invokePermissionValidator: true,
|
|
1557
|
+
performCaveatValidation
|
|
1558
|
+
});
|
|
1559
|
+
permissions[targetName] = permission;
|
|
1560
|
+
}
|
|
1561
|
+
this.setValidatedPermissions(origin, permissions);
|
|
1562
|
+
return permissions;
|
|
1563
|
+
};
|
|
1564
|
+
_mergeIncrementalPermissions = new WeakSet();
|
|
1565
|
+
mergeIncrementalPermissions_fn = function(existingPermissions, incrementalRequestedPermissions) {
|
|
1566
|
+
const permissionDiffMap = {};
|
|
1567
|
+
const newPermissions = _immer.produce.call(void 0,
|
|
1568
|
+
existingPermissions,
|
|
1569
|
+
(draftExistingPermissions) => {
|
|
1570
|
+
const leftPermissions = draftExistingPermissions;
|
|
1571
|
+
Object.entries(incrementalRequestedPermissions).forEach(
|
|
1572
|
+
([targetName, rightPermission]) => {
|
|
1573
|
+
const leftPermission = leftPermissions[targetName];
|
|
1574
|
+
const [newPermission, caveatsDiff] = _chunkZ2XKIXLSjs.__privateMethod.call(void 0, this, _mergePermission, mergePermission_fn).call(this, leftPermission ?? {}, rightPermission);
|
|
1575
|
+
if (leftPermission === void 0 || Object.keys(caveatsDiff).length > 0) {
|
|
1576
|
+
leftPermissions[targetName] = newPermission;
|
|
1577
|
+
permissionDiffMap[targetName] = caveatsDiff;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
);
|
|
1581
|
+
}
|
|
1582
|
+
);
|
|
1583
|
+
if (Object.keys(permissionDiffMap).length === 0) {
|
|
1584
|
+
return [];
|
|
1585
|
+
}
|
|
1586
|
+
return [newPermissions, permissionDiffMap];
|
|
1587
|
+
};
|
|
1588
|
+
_mergePermission = new WeakSet();
|
|
1589
|
+
mergePermission_fn = function(leftPermission, rightPermission) {
|
|
1590
|
+
const { caveatPairs, leftUniqueCaveats, rightUniqueCaveats } = _chunkPTE4672Ijs.collectUniqueAndPairedCaveats.call(void 0, leftPermission, rightPermission);
|
|
1591
|
+
const [mergedCaveats, caveatDiffMap] = caveatPairs.reduce(
|
|
1592
|
+
([caveats, diffMap], [leftCaveat, rightCaveat]) => {
|
|
1593
|
+
const [newCaveat, diff] = _chunkZ2XKIXLSjs.__privateMethod.call(void 0, this, _mergeCaveat, mergeCaveat_fn).call(this, leftCaveat, rightCaveat);
|
|
1594
|
+
if (newCaveat !== void 0 && diff !== void 0) {
|
|
1595
|
+
caveats.push(newCaveat);
|
|
1596
|
+
diffMap[newCaveat.type] = diff;
|
|
1597
|
+
} else {
|
|
1598
|
+
caveats.push(leftCaveat);
|
|
1599
|
+
}
|
|
1600
|
+
return [caveats, diffMap];
|
|
1601
|
+
},
|
|
1602
|
+
[[], {}]
|
|
1603
|
+
);
|
|
1604
|
+
const mergedRightUniqueCaveats = rightUniqueCaveats.map((caveat) => {
|
|
1605
|
+
const [newCaveat, diff] = _chunkZ2XKIXLSjs.__privateMethod.call(void 0, this, _mergeCaveat, mergeCaveat_fn).call(this, void 0, caveat);
|
|
1606
|
+
caveatDiffMap[newCaveat.type] = diff;
|
|
1607
|
+
return newCaveat;
|
|
1608
|
+
});
|
|
1609
|
+
const allCaveats = [
|
|
1610
|
+
...mergedCaveats,
|
|
1611
|
+
...leftUniqueCaveats,
|
|
1612
|
+
...mergedRightUniqueCaveats
|
|
1613
|
+
];
|
|
1614
|
+
const newPermission = {
|
|
1615
|
+
...leftPermission,
|
|
1616
|
+
...rightPermission,
|
|
1617
|
+
...allCaveats.length > 0 ? { caveats: allCaveats } : {}
|
|
1618
|
+
};
|
|
1619
|
+
return [newPermission, caveatDiffMap];
|
|
1620
|
+
};
|
|
1621
|
+
_mergeCaveat = new WeakSet();
|
|
1622
|
+
mergeCaveat_fn = function(leftCaveat, rightCaveat) {
|
|
1623
|
+
if (leftCaveat !== void 0 && leftCaveat.type !== rightCaveat.type) {
|
|
1624
|
+
throw new (0, _chunk3X6WO7UGjs.CaveatMergeTypeMismatchError)(leftCaveat.type, rightCaveat.type);
|
|
1625
|
+
}
|
|
1626
|
+
const merger = _chunkZ2XKIXLSjs.__privateMethod.call(void 0, this, _expectGetCaveatMerger, expectGetCaveatMerger_fn).call(this, rightCaveat.type);
|
|
1627
|
+
if (leftCaveat === void 0) {
|
|
1628
|
+
return [
|
|
1629
|
+
{
|
|
1630
|
+
...rightCaveat
|
|
1631
|
+
},
|
|
1632
|
+
rightCaveat.value
|
|
1633
|
+
];
|
|
1634
|
+
}
|
|
1635
|
+
const [newValue, diff] = merger(leftCaveat.value, rightCaveat.value);
|
|
1636
|
+
return newValue !== void 0 && diff !== void 0 ? [
|
|
1637
|
+
{
|
|
1638
|
+
type: rightCaveat.type,
|
|
1639
|
+
value: newValue
|
|
1640
|
+
},
|
|
1641
|
+
diff
|
|
1642
|
+
] : [];
|
|
1643
|
+
};
|
|
1644
|
+
_handleApprovedPermissions = new WeakSet();
|
|
1645
|
+
handleApprovedPermissions_fn = async function({
|
|
1646
|
+
subject,
|
|
1647
|
+
metadata,
|
|
1648
|
+
preserveExistingPermissions,
|
|
1649
|
+
approvedRequest
|
|
1650
|
+
}) {
|
|
1651
|
+
const { permissions: approvedPermissions, ...requestData } = approvedRequest;
|
|
1652
|
+
const approvedMetadata = { ...metadata };
|
|
1653
|
+
const sideEffects = this.getSideEffects(approvedPermissions);
|
|
1654
|
+
if (Object.values(sideEffects.permittedHandlers).length > 0) {
|
|
1655
|
+
const sideEffectsData = await this.executeSideEffects(
|
|
1656
|
+
sideEffects,
|
|
1657
|
+
approvedRequest
|
|
1658
|
+
);
|
|
1659
|
+
approvedMetadata.data = Object.keys(sideEffects.permittedHandlers).reduce(
|
|
1660
|
+
(acc, permission, i) => ({ [permission]: sideEffectsData[i], ...acc }),
|
|
1661
|
+
{}
|
|
1662
|
+
);
|
|
1663
|
+
}
|
|
1664
|
+
return [
|
|
1665
|
+
this.grantPermissions({
|
|
1666
|
+
subject,
|
|
1667
|
+
approvedPermissions,
|
|
1668
|
+
preserveExistingPermissions,
|
|
1669
|
+
requestData
|
|
1670
|
+
}),
|
|
1671
|
+
approvedMetadata
|
|
1672
|
+
];
|
|
1673
|
+
};
|
|
1378
1674
|
|
|
1379
1675
|
|
|
1380
1676
|
|
|
1381
1677
|
|
|
1382
1678
|
exports.CaveatMutatorOperation = CaveatMutatorOperation; exports.PermissionController = PermissionController;
|
|
1383
|
-
//# sourceMappingURL=chunk-
|
|
1679
|
+
//# sourceMappingURL=chunk-I3DJ23QH.js.map
|