@metamask/permission-controller 10.0.1 → 11.0.1
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 +23 -1
- package/dist/Caveat.js +3 -3
- package/dist/Caveat.mjs +2 -2
- package/dist/PermissionController.js +6 -6
- package/dist/PermissionController.mjs +5 -5
- package/dist/SubjectMetadataController.js +2 -2
- package/dist/SubjectMetadataController.mjs +1 -1
- package/dist/{chunk-6V5UTS24.mjs → chunk-3WWJKO7P.mjs} +2 -2
- package/dist/{chunk-D7PWCWCC.js → chunk-3YOPLPVY.js} +4 -4
- package/dist/{chunk-SPOFDHOW.mjs → chunk-42QSJHWO.mjs} +3 -3
- package/dist/chunk-42QSJHWO.mjs.map +1 -0
- package/dist/{chunk-NOB77ENO.mjs → chunk-4FMYQC3Y.mjs} +4 -4
- package/dist/{chunk-ZTBBRCDR.mjs → chunk-4NAVRO44.mjs} +4 -4
- package/dist/chunk-4NAVRO44.mjs.map +1 -0
- package/dist/{chunk-73M67Z5X.mjs → chunk-5RFW5THA.mjs} +2 -2
- package/dist/{chunk-73M67Z5X.mjs.map → chunk-5RFW5THA.mjs.map} +1 -1
- package/dist/{chunk-AQ46ICF5.js → chunk-6PXDVUYM.js} +7 -7
- package/dist/{chunk-FVYYHAVF.mjs → chunk-74H4CVH7.mjs} +3 -3
- package/dist/{chunk-FVYYHAVF.mjs.map → chunk-74H4CVH7.mjs.map} +1 -1
- package/dist/{chunk-HZPWUOQB.js → chunk-7A3VYLCK.js} +4 -4
- package/dist/{chunk-HZPWUOQB.js.map → chunk-7A3VYLCK.js.map} +1 -1
- package/dist/{chunk-R56CBYD3.js → chunk-B6PDRQ7N.js} +73 -75
- package/dist/{chunk-7WEYLBME.mjs.map → chunk-B6PDRQ7N.js.map} +1 -1
- package/dist/{chunk-7WEYLBME.mjs → chunk-COGJLF22.mjs} +19 -21
- package/dist/chunk-COGJLF22.mjs.map +1 -0
- package/dist/{chunk-M5GM7UFU.js → chunk-F5TBMVWC.js} +3 -3
- package/dist/{chunk-4YXP3WEE.js → chunk-FYADAA2G.js} +4 -2
- package/dist/chunk-FYADAA2G.js.map +1 -0
- package/dist/{chunk-VHHS2FJX.mjs → chunk-G4BWJ7EA.mjs} +4 -2
- package/dist/chunk-G4BWJ7EA.mjs.map +1 -0
- package/dist/{chunk-5NYMBY4A.mjs → chunk-I62TTXZ6.mjs} +2 -2
- package/dist/{chunk-SKKQZ5E6.mjs → chunk-OCLNDUYO.mjs} +3 -3
- package/dist/{chunk-SKKQZ5E6.mjs.map → chunk-OCLNDUYO.mjs.map} +1 -1
- package/dist/{chunk-HRDKMOYS.js → chunk-VBIZGGQL.js} +2 -2
- package/dist/{chunk-HRDKMOYS.js.map → chunk-VBIZGGQL.js.map} +1 -1
- package/dist/{chunk-TAK6LXU6.js → chunk-VQPP5PWS.js} +4 -4
- package/dist/chunk-VQPP5PWS.js.map +1 -0
- package/dist/{chunk-IPKS33XA.js → chunk-VSDHL2GQ.js} +3 -3
- package/dist/{chunk-IPKS33XA.js.map → chunk-VSDHL2GQ.js.map} +1 -1
- package/dist/{chunk-6UCIDD5V.js → chunk-X4ZAW4QR.js} +5 -5
- package/dist/{chunk-6UCIDD5V.js.map → chunk-X4ZAW4QR.js.map} +1 -1
- package/dist/errors.js +2 -2
- package/dist/errors.mjs +1 -1
- package/dist/index.js +11 -11
- package/dist/index.mjs +10 -10
- package/dist/permission-middleware.js +3 -3
- package/dist/permission-middleware.mjs +2 -2
- package/dist/rpc-methods/getPermissions.js +3 -3
- 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 +4 -4
- package/dist/rpc-methods/requestPermissions.mjs +3 -3
- package/dist/rpc-methods/revokePermissions.js +4 -4
- package/dist/rpc-methods/revokePermissions.mjs +3 -3
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/PermissionController.d.ts +10 -10
- package/dist/types/PermissionController.d.ts.map +1 -1
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/utils.d.ts +9 -9
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -2
- package/dist/utils.mjs +1 -1
- package/package.json +12 -11
- package/dist/chunk-4YXP3WEE.js.map +0 -1
- package/dist/chunk-R56CBYD3.js.map +0 -1
- package/dist/chunk-SPOFDHOW.mjs.map +0 -1
- package/dist/chunk-TAK6LXU6.js.map +0 -1
- package/dist/chunk-VHHS2FJX.mjs.map +0 -1
- package/dist/chunk-ZTBBRCDR.mjs.map +0 -1
- /package/dist/{chunk-6V5UTS24.mjs.map → chunk-3WWJKO7P.mjs.map} +0 -0
- /package/dist/{chunk-D7PWCWCC.js.map → chunk-3YOPLPVY.js.map} +0 -0
- /package/dist/{chunk-NOB77ENO.mjs.map → chunk-4FMYQC3Y.mjs.map} +0 -0
- /package/dist/{chunk-AQ46ICF5.js.map → chunk-6PXDVUYM.js.map} +0 -0
- /package/dist/{chunk-M5GM7UFU.js.map → chunk-F5TBMVWC.js.map} +0 -0
- /package/dist/{chunk-5NYMBY4A.mjs.map → chunk-I62TTXZ6.mjs.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 _chunk3YOPLPVYjs = require('./chunk-3YOPLPVY.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ var _chunkD7PWCWCCjs = require('./chunk-D7PWCWCC.js');
|
|
|
10
10
|
var _chunkZH4MLSXXjs = require('./chunk-ZH4MLSXX.js');
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkF5TBMVWCjs = require('./chunk-F5TBMVWC.js');
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
@@ -38,10 +38,10 @@ var _chunkM5GM7UFUjs = require('./chunk-M5GM7UFU.js');
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
var
|
|
41
|
+
var _chunkFYADAA2Gjs = require('./chunk-FYADAA2G.js');
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
var
|
|
44
|
+
var _chunkVQPP5PWSjs = require('./chunk-VQPP5PWS.js');
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
|
|
@@ -67,10 +67,10 @@ function getDefaultState() {
|
|
|
67
67
|
return { subjects: {} };
|
|
68
68
|
}
|
|
69
69
|
var CaveatMutatorOperation = /* @__PURE__ */ ((CaveatMutatorOperation2) => {
|
|
70
|
-
CaveatMutatorOperation2[CaveatMutatorOperation2["
|
|
71
|
-
CaveatMutatorOperation2[CaveatMutatorOperation2["
|
|
72
|
-
CaveatMutatorOperation2[CaveatMutatorOperation2["
|
|
73
|
-
CaveatMutatorOperation2[CaveatMutatorOperation2["
|
|
70
|
+
CaveatMutatorOperation2[CaveatMutatorOperation2["Noop"] = 0] = "Noop";
|
|
71
|
+
CaveatMutatorOperation2[CaveatMutatorOperation2["UpdateValue"] = 1] = "UpdateValue";
|
|
72
|
+
CaveatMutatorOperation2[CaveatMutatorOperation2["DeleteCaveat"] = 2] = "DeleteCaveat";
|
|
73
|
+
CaveatMutatorOperation2[CaveatMutatorOperation2["RevokePermission"] = 3] = "RevokePermission";
|
|
74
74
|
return CaveatMutatorOperation2;
|
|
75
75
|
})(CaveatMutatorOperation || {});
|
|
76
76
|
var _expectGetCaveatMerger, expectGetCaveatMerger_fn, _applyGrantedPermissions, applyGrantedPermissions_fn, _mergeIncrementalPermissions, mergeIncrementalPermissions_fn, _mergePermission, mergePermission_fn, _mergeCaveat, mergeCaveat_fn, _handleApprovedPermissions, handleApprovedPermissions_fn;
|
|
@@ -150,8 +150,6 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
150
150
|
* @param rightCaveat - The right-hand caveat to merge.
|
|
151
151
|
* @returns The merged caveat and the diff between the two caveats.
|
|
152
152
|
*/
|
|
153
|
-
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
154
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
155
153
|
_chunkZ2XKIXLSjs.__privateAdd.call(void 0, this, _mergeCaveat);
|
|
156
154
|
/**
|
|
157
155
|
* Accepts a permissions request that has been approved by the user. This
|
|
@@ -177,7 +175,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
177
175
|
...permissionSpecifications
|
|
178
176
|
});
|
|
179
177
|
this.registerMessageHandlers();
|
|
180
|
-
this.createPermissionMiddleware =
|
|
178
|
+
this.createPermissionMiddleware = _chunkF5TBMVWCjs.getPermissionMiddlewareFactory.call(void 0, {
|
|
181
179
|
executeRestrictedMethod: this._executeRestrictedMethod.bind(this),
|
|
182
180
|
getRestrictedMethod: this.getRestrictedMethod.bind(this),
|
|
183
181
|
isUnrestrictedMethod: this.unrestrictedMethods.has.bind(
|
|
@@ -243,12 +241,12 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
243
241
|
if (allowedCaveats) {
|
|
244
242
|
allowedCaveats.forEach((caveatType) => {
|
|
245
243
|
if (!_utils.hasProperty.call(void 0, caveatSpecifications, caveatType)) {
|
|
246
|
-
throw new (0,
|
|
244
|
+
throw new (0, _chunkFYADAA2Gjs.UnrecognizedCaveatTypeError)(caveatType);
|
|
247
245
|
}
|
|
248
246
|
const specification = caveatSpecifications[caveatType];
|
|
249
|
-
const isRestrictedMethodCaveat =
|
|
247
|
+
const isRestrictedMethodCaveat = _chunk3YOPLPVYjs.isRestrictedMethodCaveatSpecification.call(void 0, specification);
|
|
250
248
|
if (permissionType === "RestrictedMethod" /* RestrictedMethod */ && !isRestrictedMethodCaveat || permissionType === "Endowment" /* Endowment */ && isRestrictedMethodCaveat) {
|
|
251
|
-
throw new (0,
|
|
249
|
+
throw new (0, _chunkFYADAA2Gjs.CaveatSpecificationMismatchError)(
|
|
252
250
|
specification,
|
|
253
251
|
permissionType
|
|
254
252
|
);
|
|
@@ -352,10 +350,10 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
352
350
|
* target name.
|
|
353
351
|
*/
|
|
354
352
|
getTypedPermissionSpecification(permissionType, targetName, requestingOrigin) {
|
|
355
|
-
const failureError = permissionType === "RestrictedMethod" /* RestrictedMethod */ ?
|
|
353
|
+
const failureError = permissionType === "RestrictedMethod" /* RestrictedMethod */ ? _chunkFYADAA2Gjs.methodNotFound.call(void 0,
|
|
356
354
|
targetName,
|
|
357
355
|
requestingOrigin ? { origin: requestingOrigin } : void 0
|
|
358
|
-
) : new (0,
|
|
356
|
+
) : new (0, _chunkFYADAA2Gjs.EndowmentPermissionDoesNotExistError)(
|
|
359
357
|
targetName,
|
|
360
358
|
requestingOrigin
|
|
361
359
|
);
|
|
@@ -447,7 +445,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
447
445
|
revokeAllPermissions(origin) {
|
|
448
446
|
this.update((draftState) => {
|
|
449
447
|
if (!draftState.subjects[origin]) {
|
|
450
|
-
throw new (0,
|
|
448
|
+
throw new (0, _chunkFYADAA2Gjs.UnrecognizedSubjectError)(origin);
|
|
451
449
|
}
|
|
452
450
|
delete draftState.subjects[origin];
|
|
453
451
|
});
|
|
@@ -476,12 +474,12 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
476
474
|
this.update((draftState) => {
|
|
477
475
|
Object.keys(subjectsAndPermissions).forEach((origin) => {
|
|
478
476
|
if (!_utils.hasProperty.call(void 0, draftState.subjects, origin)) {
|
|
479
|
-
throw new (0,
|
|
477
|
+
throw new (0, _chunkFYADAA2Gjs.UnrecognizedSubjectError)(origin);
|
|
480
478
|
}
|
|
481
479
|
subjectsAndPermissions[origin].forEach((target) => {
|
|
482
480
|
const { permissions } = draftState.subjects[origin];
|
|
483
481
|
if (!_utils.hasProperty.call(void 0, permissions, target)) {
|
|
484
|
-
throw new (0,
|
|
482
|
+
throw new (0, _chunkFYADAA2Gjs.PermissionDoesNotExistError)(origin, target);
|
|
485
483
|
}
|
|
486
484
|
this.deletePermission(draftState.subjects, origin, target);
|
|
487
485
|
});
|
|
@@ -561,7 +559,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
561
559
|
getCaveat(origin, target, caveatType) {
|
|
562
560
|
const permission = this.getPermission(origin, target);
|
|
563
561
|
if (!permission) {
|
|
564
|
-
throw new (0,
|
|
562
|
+
throw new (0, _chunkFYADAA2Gjs.PermissionDoesNotExistError)(origin, target);
|
|
565
563
|
}
|
|
566
564
|
return _chunkZH4MLSXXjs.findCaveat.call(void 0, permission, caveatType);
|
|
567
565
|
}
|
|
@@ -586,7 +584,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
586
584
|
*/
|
|
587
585
|
addCaveat(origin, target, caveatType, caveatValue) {
|
|
588
586
|
if (this.hasCaveat(origin, target, caveatType)) {
|
|
589
|
-
throw new (0,
|
|
587
|
+
throw new (0, _chunkFYADAA2Gjs.CaveatAlreadyExistsError)(origin, target, caveatType);
|
|
590
588
|
}
|
|
591
589
|
this.setCaveat(origin, target, caveatType, caveatValue);
|
|
592
590
|
}
|
|
@@ -610,7 +608,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
610
608
|
*/
|
|
611
609
|
updateCaveat(origin, target, caveatType, caveatValue) {
|
|
612
610
|
if (!this.hasCaveat(origin, target, caveatType)) {
|
|
613
|
-
throw new (0,
|
|
611
|
+
throw new (0, _chunkFYADAA2Gjs.CaveatDoesNotExistError)(origin, target, caveatType);
|
|
614
612
|
}
|
|
615
613
|
this.setCaveat(origin, target, caveatType, caveatValue);
|
|
616
614
|
}
|
|
@@ -636,11 +634,11 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
636
634
|
this.update((draftState) => {
|
|
637
635
|
const subject = draftState.subjects[origin];
|
|
638
636
|
if (!subject) {
|
|
639
|
-
throw new (0,
|
|
637
|
+
throw new (0, _chunkFYADAA2Gjs.UnrecognizedSubjectError)(origin);
|
|
640
638
|
}
|
|
641
639
|
const permission = subject.permissions[target];
|
|
642
640
|
if (!permission) {
|
|
643
|
-
throw new (0,
|
|
641
|
+
throw new (0, _chunkFYADAA2Gjs.PermissionDoesNotExistError)(origin, target);
|
|
644
642
|
}
|
|
645
643
|
const caveat = {
|
|
646
644
|
type: caveatType,
|
|
@@ -674,10 +672,10 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
674
672
|
* value to update the existing caveat with.
|
|
675
673
|
*
|
|
676
674
|
* For each caveat, depending on the mutator result, this method will:
|
|
677
|
-
* - Do nothing ({@link CaveatMutatorOperation.
|
|
678
|
-
* - Update the value of the caveat ({@link CaveatMutatorOperation.
|
|
679
|
-
* - Delete the caveat ({@link CaveatMutatorOperation.
|
|
680
|
-
* - Revoke the parent permission ({@link CaveatMutatorOperation.
|
|
675
|
+
* - Do nothing ({@link CaveatMutatorOperation.Noop})
|
|
676
|
+
* - Update the value of the caveat ({@link CaveatMutatorOperation.UpdateValue}). The caveat specification validator, if any, will be called after updating the value.
|
|
677
|
+
* - Delete the caveat ({@link CaveatMutatorOperation.DeleteCaveat}). The permission specification validator, if any, will be called after deleting the caveat.
|
|
678
|
+
* - Revoke the parent permission ({@link CaveatMutatorOperation.RevokePermission})
|
|
681
679
|
*
|
|
682
680
|
* This method throws if the validation of any caveat or permission fails.
|
|
683
681
|
*
|
|
@@ -702,9 +700,9 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
702
700
|
const mutatorResult = mutator(targetCaveat.value);
|
|
703
701
|
const { operation } = mutatorResult;
|
|
704
702
|
switch (operation) {
|
|
705
|
-
case 0 /*
|
|
703
|
+
case 0 /* Noop */:
|
|
706
704
|
break;
|
|
707
|
-
case 1 /*
|
|
705
|
+
case 1 /* UpdateValue */:
|
|
708
706
|
targetCaveat.value = mutatorResult.value;
|
|
709
707
|
this.validateCaveat(
|
|
710
708
|
targetCaveat,
|
|
@@ -712,10 +710,10 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
712
710
|
permission.parentCapability
|
|
713
711
|
);
|
|
714
712
|
break;
|
|
715
|
-
case 2 /*
|
|
713
|
+
case 2 /* DeleteCaveat */:
|
|
716
714
|
this.deleteCaveat(permission, targetCaveatType, subject.origin);
|
|
717
715
|
break;
|
|
718
|
-
case 3 /*
|
|
716
|
+
case 3 /* RevokePermission */:
|
|
719
717
|
this.deletePermission(
|
|
720
718
|
draftState.subjects,
|
|
721
719
|
subject.origin,
|
|
@@ -747,10 +745,10 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
747
745
|
this.update((draftState) => {
|
|
748
746
|
const permission = draftState.subjects[origin]?.permissions[target];
|
|
749
747
|
if (!permission) {
|
|
750
|
-
throw new (0,
|
|
748
|
+
throw new (0, _chunkFYADAA2Gjs.PermissionDoesNotExistError)(origin, target);
|
|
751
749
|
}
|
|
752
750
|
if (!permission.caveats) {
|
|
753
|
-
throw new (0,
|
|
751
|
+
throw new (0, _chunkFYADAA2Gjs.CaveatDoesNotExistError)(origin, target, caveatType);
|
|
754
752
|
}
|
|
755
753
|
this.deleteCaveat(permission, caveatType, origin);
|
|
756
754
|
});
|
|
@@ -769,7 +767,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
769
767
|
*/
|
|
770
768
|
deleteCaveat(permission, caveatType, origin) {
|
|
771
769
|
if (!permission.caveats) {
|
|
772
|
-
throw new (0,
|
|
770
|
+
throw new (0, _chunkFYADAA2Gjs.CaveatDoesNotExistError)(
|
|
773
771
|
origin,
|
|
774
772
|
permission.parentCapability,
|
|
775
773
|
caveatType
|
|
@@ -779,7 +777,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
779
777
|
(existingCaveat) => existingCaveat.type === caveatType
|
|
780
778
|
);
|
|
781
779
|
if (caveatIndex === -1) {
|
|
782
|
-
throw new (0,
|
|
780
|
+
throw new (0, _chunkFYADAA2Gjs.CaveatDoesNotExistError)(
|
|
783
781
|
origin,
|
|
784
782
|
permission.parentCapability,
|
|
785
783
|
caveatType
|
|
@@ -922,13 +920,13 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
922
920
|
origin
|
|
923
921
|
);
|
|
924
922
|
if (!metadata || metadata.subjectType === null || !specification.subjectTypes.includes(metadata.subjectType)) {
|
|
925
|
-
throw specification.permissionType === "RestrictedMethod" /* RestrictedMethod */ ?
|
|
923
|
+
throw specification.permissionType === "RestrictedMethod" /* RestrictedMethod */ ? _chunkFYADAA2Gjs.methodNotFound.call(void 0, targetName, { origin }) : new (0, _chunkFYADAA2Gjs.EndowmentPermissionDoesNotExistError)(targetName, origin);
|
|
926
924
|
}
|
|
927
925
|
}
|
|
928
926
|
if (_utils.hasProperty.call(void 0, permission, "caveats")) {
|
|
929
927
|
const { caveats } = permission;
|
|
930
928
|
if (caveats !== null && !(Array.isArray(caveats) && caveats.length > 0)) {
|
|
931
|
-
throw new (0,
|
|
929
|
+
throw new (0, _chunkFYADAA2Gjs.InvalidCaveatsPropertyError)(origin, targetName, caveats);
|
|
932
930
|
}
|
|
933
931
|
const seenCaveatTypes = /* @__PURE__ */ new Set();
|
|
934
932
|
caveats?.forEach((caveat) => {
|
|
@@ -936,10 +934,10 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
936
934
|
this.validateCaveat(caveat, origin, targetName);
|
|
937
935
|
}
|
|
938
936
|
if (!allowedCaveats?.includes(caveat.type)) {
|
|
939
|
-
throw new (0,
|
|
937
|
+
throw new (0, _chunkFYADAA2Gjs.ForbiddenCaveatError)(caveat.type, origin, targetName);
|
|
940
938
|
}
|
|
941
939
|
if (seenCaveatTypes.has(caveat.type)) {
|
|
942
|
-
throw new (0,
|
|
940
|
+
throw new (0, _chunkFYADAA2Gjs.DuplicateCaveatError)(caveat.type, origin, targetName);
|
|
943
941
|
}
|
|
944
942
|
seenCaveatTypes.add(caveat.type);
|
|
945
943
|
});
|
|
@@ -1000,23 +998,23 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1000
998
|
*/
|
|
1001
999
|
validateCaveat(caveat, origin, target) {
|
|
1002
1000
|
if (!_controllerutils.isPlainObject.call(void 0, caveat)) {
|
|
1003
|
-
throw new (0,
|
|
1001
|
+
throw new (0, _chunkFYADAA2Gjs.InvalidCaveatError)(caveat, origin, target);
|
|
1004
1002
|
}
|
|
1005
1003
|
if (Object.keys(caveat).length !== 2) {
|
|
1006
|
-
throw new (0,
|
|
1004
|
+
throw new (0, _chunkFYADAA2Gjs.InvalidCaveatFieldsError)(caveat, origin, target);
|
|
1007
1005
|
}
|
|
1008
1006
|
if (typeof caveat.type !== "string") {
|
|
1009
|
-
throw new (0,
|
|
1007
|
+
throw new (0, _chunkFYADAA2Gjs.InvalidCaveatTypeError)(caveat, origin, target);
|
|
1010
1008
|
}
|
|
1011
1009
|
const specification = this.getCaveatSpecification(caveat.type);
|
|
1012
1010
|
if (!specification) {
|
|
1013
|
-
throw new (0,
|
|
1011
|
+
throw new (0, _chunkFYADAA2Gjs.UnrecognizedCaveatTypeError)(caveat.type, origin, target);
|
|
1014
1012
|
}
|
|
1015
1013
|
if (!_utils.hasProperty.call(void 0, caveat, "value") || caveat.value === void 0) {
|
|
1016
|
-
throw new (0,
|
|
1014
|
+
throw new (0, _chunkFYADAA2Gjs.CaveatMissingValueError)(caveat, origin, target);
|
|
1017
1015
|
}
|
|
1018
1016
|
if (!_controllerutils.isValidJson.call(void 0, caveat.value)) {
|
|
1019
|
-
throw new (0,
|
|
1017
|
+
throw new (0, _chunkFYADAA2Gjs.CaveatInvalidJsonError)(caveat, origin, target);
|
|
1020
1018
|
}
|
|
1021
1019
|
specification.validator?.(caveat, origin, target);
|
|
1022
1020
|
}
|
|
@@ -1110,13 +1108,13 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1110
1108
|
this.validateRequestedPermissions(origin, newPermissions);
|
|
1111
1109
|
} catch (error) {
|
|
1112
1110
|
if (error instanceof Error) {
|
|
1113
|
-
throw new (0,
|
|
1111
|
+
throw new (0, _chunkFYADAA2Gjs.InvalidMergedPermissionsError)(
|
|
1114
1112
|
origin,
|
|
1115
1113
|
error,
|
|
1116
1114
|
permissionDiffMap
|
|
1117
1115
|
);
|
|
1118
1116
|
}
|
|
1119
|
-
throw
|
|
1117
|
+
throw _chunkFYADAA2Gjs.internalError.call(void 0, "Unrecognized error type", { error });
|
|
1120
1118
|
}
|
|
1121
1119
|
const metadata = {
|
|
1122
1120
|
...options.metadata,
|
|
@@ -1156,13 +1154,13 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1156
1154
|
*/
|
|
1157
1155
|
validateRequestedPermissions(origin, requestedPermissions) {
|
|
1158
1156
|
if (!_controllerutils.isPlainObject.call(void 0, requestedPermissions)) {
|
|
1159
|
-
throw
|
|
1157
|
+
throw _chunkFYADAA2Gjs.invalidParams.call(void 0, {
|
|
1160
1158
|
message: `Requested permissions for origin "${origin}" is not a plain object.`,
|
|
1161
1159
|
data: { origin, requestedPermissions }
|
|
1162
1160
|
});
|
|
1163
1161
|
}
|
|
1164
1162
|
if (Object.keys(requestedPermissions).length === 0) {
|
|
1165
|
-
throw
|
|
1163
|
+
throw _chunkFYADAA2Gjs.invalidParams.call(void 0, {
|
|
1166
1164
|
message: `Permissions request for origin "${origin}" contains no permissions.`,
|
|
1167
1165
|
data: { requestedPermissions }
|
|
1168
1166
|
});
|
|
@@ -1170,10 +1168,10 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1170
1168
|
for (const targetName of Object.keys(requestedPermissions)) {
|
|
1171
1169
|
const permission = requestedPermissions[targetName];
|
|
1172
1170
|
if (!this.targetExists(targetName)) {
|
|
1173
|
-
throw
|
|
1171
|
+
throw _chunkFYADAA2Gjs.methodNotFound.call(void 0, targetName, { origin, requestedPermissions });
|
|
1174
1172
|
}
|
|
1175
1173
|
if (!_controllerutils.isPlainObject.call(void 0, permission) || permission.parentCapability !== void 0 && targetName !== permission.parentCapability) {
|
|
1176
|
-
throw
|
|
1174
|
+
throw _chunkFYADAA2Gjs.invalidParams.call(void 0, {
|
|
1177
1175
|
message: `Permissions request for origin "${origin}" contains invalid requested permission(s).`,
|
|
1178
1176
|
data: { origin, requestedPermissions }
|
|
1179
1177
|
});
|
|
@@ -1203,7 +1201,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1203
1201
|
id,
|
|
1204
1202
|
origin,
|
|
1205
1203
|
requestData: permissionsRequest,
|
|
1206
|
-
type: "wallet_requestPermissions" /*
|
|
1204
|
+
type: "wallet_requestPermissions" /* RequestPermissions */
|
|
1207
1205
|
},
|
|
1208
1206
|
true
|
|
1209
1207
|
);
|
|
@@ -1263,14 +1261,14 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1263
1261
|
failureHandlersList.map((failureHandler) => failureHandler(params))
|
|
1264
1262
|
);
|
|
1265
1263
|
} catch (error) {
|
|
1266
|
-
throw
|
|
1264
|
+
throw _chunkFYADAA2Gjs.internalError.call(void 0, "Unexpected error in side-effects", { error });
|
|
1267
1265
|
}
|
|
1268
1266
|
}
|
|
1269
1267
|
const reasons = rejectedHandlers.map((handler) => handler.reason);
|
|
1270
1268
|
reasons.forEach((reason) => {
|
|
1271
1269
|
console.error(reason);
|
|
1272
1270
|
});
|
|
1273
|
-
throw reasons.length > 1 ?
|
|
1271
|
+
throw reasons.length > 1 ? _chunkFYADAA2Gjs.internalError.call(void 0,
|
|
1274
1272
|
"Multiple errors occurred during side-effects execution",
|
|
1275
1273
|
{ errors: reasons }
|
|
1276
1274
|
) : reasons[0];
|
|
@@ -1295,7 +1293,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1295
1293
|
validateApprovedPermissions(approvedRequest, originalMetadata) {
|
|
1296
1294
|
const { id, origin } = originalMetadata;
|
|
1297
1295
|
if (!_controllerutils.isPlainObject.call(void 0, approvedRequest) || !_controllerutils.isPlainObject.call(void 0, approvedRequest.metadata)) {
|
|
1298
|
-
throw
|
|
1296
|
+
throw _chunkFYADAA2Gjs.internalError.call(void 0,
|
|
1299
1297
|
`Approved permissions request for subject "${origin}" is invalid.`,
|
|
1300
1298
|
{ data: { approvedRequest } }
|
|
1301
1299
|
);
|
|
@@ -1305,13 +1303,13 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1305
1303
|
permissions
|
|
1306
1304
|
} = approvedRequest;
|
|
1307
1305
|
if (newId !== id) {
|
|
1308
|
-
throw
|
|
1306
|
+
throw _chunkFYADAA2Gjs.internalError.call(void 0,
|
|
1309
1307
|
`Approved permissions request for subject "${origin}" mutated its id.`,
|
|
1310
1308
|
{ originalId: id, mutatedId: newId }
|
|
1311
1309
|
);
|
|
1312
1310
|
}
|
|
1313
1311
|
if (newOrigin !== origin) {
|
|
1314
|
-
throw
|
|
1312
|
+
throw _chunkFYADAA2Gjs.internalError.call(void 0,
|
|
1315
1313
|
`Approved permissions request for subject "${origin}" mutated its origin.`,
|
|
1316
1314
|
{ originalOrigin: origin, mutatedOrigin: newOrigin }
|
|
1317
1315
|
);
|
|
@@ -1320,12 +1318,12 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1320
1318
|
this.validateRequestedPermissions(origin, permissions);
|
|
1321
1319
|
} catch (error) {
|
|
1322
1320
|
if (error instanceof Error) {
|
|
1323
|
-
throw
|
|
1321
|
+
throw _chunkFYADAA2Gjs.internalError.call(void 0,
|
|
1324
1322
|
`Invalid approved permissions request: ${error.message}`,
|
|
1325
1323
|
error instanceof _rpcerrors.JsonRpcError ? error.data : void 0
|
|
1326
1324
|
);
|
|
1327
1325
|
}
|
|
1328
|
-
throw
|
|
1326
|
+
throw _chunkFYADAA2Gjs.internalError.call(void 0, "Unrecognized error type", { error });
|
|
1329
1327
|
}
|
|
1330
1328
|
}
|
|
1331
1329
|
/**
|
|
@@ -1337,19 +1335,19 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1337
1335
|
async acceptPermissionsRequest(request) {
|
|
1338
1336
|
const { id } = request.metadata;
|
|
1339
1337
|
if (!this.hasApprovalRequest({ id })) {
|
|
1340
|
-
throw new (0,
|
|
1338
|
+
throw new (0, _chunkFYADAA2Gjs.PermissionsRequestNotFoundError)(id);
|
|
1341
1339
|
}
|
|
1342
1340
|
if (Object.keys(request.permissions).length === 0) {
|
|
1343
1341
|
this._rejectPermissionsRequest(
|
|
1344
1342
|
id,
|
|
1345
|
-
|
|
1343
|
+
_chunkFYADAA2Gjs.invalidParams.call(void 0, {
|
|
1346
1344
|
message: "Must request at least one permission."
|
|
1347
1345
|
})
|
|
1348
1346
|
);
|
|
1349
1347
|
return;
|
|
1350
1348
|
}
|
|
1351
1349
|
try {
|
|
1352
|
-
this.messagingSystem.call(
|
|
1350
|
+
await this.messagingSystem.call(
|
|
1353
1351
|
"ApprovalController:acceptRequest",
|
|
1354
1352
|
id,
|
|
1355
1353
|
request
|
|
@@ -1367,9 +1365,9 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1367
1365
|
*/
|
|
1368
1366
|
async rejectPermissionsRequest(id) {
|
|
1369
1367
|
if (!this.hasApprovalRequest({ id })) {
|
|
1370
|
-
throw new (0,
|
|
1368
|
+
throw new (0, _chunkFYADAA2Gjs.PermissionsRequestNotFoundError)(id);
|
|
1371
1369
|
}
|
|
1372
|
-
this._rejectPermissionsRequest(id,
|
|
1370
|
+
this._rejectPermissionsRequest(id, _chunkFYADAA2Gjs.userRejectedRequest.call(void 0, ));
|
|
1373
1371
|
}
|
|
1374
1372
|
/**
|
|
1375
1373
|
* Checks whether the {@link ApprovalController} has a particular permissions
|
|
@@ -1416,7 +1414,7 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1416
1414
|
*/
|
|
1417
1415
|
async getEndowments(origin, targetName, requestData) {
|
|
1418
1416
|
if (!this.hasPermission(origin, targetName)) {
|
|
1419
|
-
throw
|
|
1417
|
+
throw _chunkFYADAA2Gjs.unauthorized.call(void 0, { data: { origin, targetName } });
|
|
1420
1418
|
}
|
|
1421
1419
|
return this.getTypedPermissionSpecification(
|
|
1422
1420
|
"Endowment" /* Endowment */,
|
|
@@ -1486,9 +1484,9 @@ var PermissionController = class extends _basecontroller.BaseController {
|
|
|
1486
1484
|
const { origin } = subject;
|
|
1487
1485
|
const permission = this.getPermission(origin, method);
|
|
1488
1486
|
if (!permission) {
|
|
1489
|
-
throw
|
|
1487
|
+
throw _chunkFYADAA2Gjs.unauthorized.call(void 0, { data: { origin, method } });
|
|
1490
1488
|
}
|
|
1491
|
-
return
|
|
1489
|
+
return _chunk3YOPLPVYjs.decorateWithCaveats.call(void 0,
|
|
1492
1490
|
methodImplementation,
|
|
1493
1491
|
permission,
|
|
1494
1492
|
this._caveatSpecifications
|
|
@@ -1499,7 +1497,7 @@ _expectGetCaveatMerger = new WeakSet();
|
|
|
1499
1497
|
expectGetCaveatMerger_fn = function(caveatType) {
|
|
1500
1498
|
const { merger } = this.getCaveatSpecification(caveatType);
|
|
1501
1499
|
if (merger === void 0) {
|
|
1502
|
-
throw new (0,
|
|
1500
|
+
throw new (0, _chunkFYADAA2Gjs.CaveatMergerDoesNotExistError)(caveatType);
|
|
1503
1501
|
}
|
|
1504
1502
|
return merger;
|
|
1505
1503
|
};
|
|
@@ -1513,7 +1511,7 @@ applyGrantedPermissions_fn = function({
|
|
|
1513
1511
|
}) {
|
|
1514
1512
|
const { origin } = subject;
|
|
1515
1513
|
if (!origin || typeof origin !== "string") {
|
|
1516
|
-
throw new (0,
|
|
1514
|
+
throw new (0, _chunkFYADAA2Gjs.InvalidSubjectIdentifierError)(origin);
|
|
1517
1515
|
}
|
|
1518
1516
|
const permissions = preserveExistingPermissions ? {
|
|
1519
1517
|
...this.getPermissions(origin)
|
|
@@ -1522,10 +1520,10 @@ applyGrantedPermissions_fn = function({
|
|
|
1522
1520
|
approvedPermissions
|
|
1523
1521
|
)) {
|
|
1524
1522
|
if (!this.targetExists(requestedTarget)) {
|
|
1525
|
-
throw
|
|
1523
|
+
throw _chunkFYADAA2Gjs.methodNotFound.call(void 0, requestedTarget);
|
|
1526
1524
|
}
|
|
1527
1525
|
if (approvedPermission.parentCapability !== void 0 && requestedTarget !== approvedPermission.parentCapability) {
|
|
1528
|
-
throw new (0,
|
|
1526
|
+
throw new (0, _chunkFYADAA2Gjs.InvalidApprovedPermissionError)(
|
|
1529
1527
|
origin,
|
|
1530
1528
|
requestedTarget,
|
|
1531
1529
|
approvedPermission
|
|
@@ -1589,7 +1587,7 @@ mergeIncrementalPermissions_fn = function(existingPermissions, incrementalReques
|
|
|
1589
1587
|
};
|
|
1590
1588
|
_mergePermission = new WeakSet();
|
|
1591
1589
|
mergePermission_fn = function(leftPermission, rightPermission) {
|
|
1592
|
-
const { caveatPairs, leftUniqueCaveats, rightUniqueCaveats } =
|
|
1590
|
+
const { caveatPairs, leftUniqueCaveats, rightUniqueCaveats } = _chunkVQPP5PWSjs.collectUniqueAndPairedCaveats.call(void 0, leftPermission, rightPermission);
|
|
1593
1591
|
const [mergedCaveats, caveatDiffMap] = caveatPairs.reduce(
|
|
1594
1592
|
([caveats, diffMap], [leftCaveat, rightCaveat]) => {
|
|
1595
1593
|
const [newCaveat, diff] = _chunkZ2XKIXLSjs.__privateMethod.call(void 0, this, _mergeCaveat, mergeCaveat_fn).call(this, leftCaveat, rightCaveat);
|
|
@@ -1623,7 +1621,7 @@ mergePermission_fn = function(leftPermission, rightPermission) {
|
|
|
1623
1621
|
_mergeCaveat = new WeakSet();
|
|
1624
1622
|
mergeCaveat_fn = function(leftCaveat, rightCaveat) {
|
|
1625
1623
|
if (leftCaveat !== void 0 && leftCaveat.type !== rightCaveat.type) {
|
|
1626
|
-
throw new (0,
|
|
1624
|
+
throw new (0, _chunkFYADAA2Gjs.CaveatMergeTypeMismatchError)(leftCaveat.type, rightCaveat.type);
|
|
1627
1625
|
}
|
|
1628
1626
|
const merger = _chunkZ2XKIXLSjs.__privateMethod.call(void 0, this, _expectGetCaveatMerger, expectGetCaveatMerger_fn).call(this, rightCaveat.type);
|
|
1629
1627
|
if (leftCaveat === void 0) {
|
|
@@ -1678,4 +1676,4 @@ handleApprovedPermissions_fn = async function({
|
|
|
1678
1676
|
|
|
1679
1677
|
|
|
1680
1678
|
exports.CaveatMutatorOperation = CaveatMutatorOperation; exports.PermissionController = PermissionController;
|
|
1681
|
-
//# sourceMappingURL=chunk-
|
|
1679
|
+
//# sourceMappingURL=chunk-B6PDRQ7N.js.map
|