@metamask/permission-controller 13.1.1 → 14.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/CHANGELOG.md +37 -1
  2. package/LICENSE +1 -0
  3. package/dist/{Caveat.d.mts → Caveat.d.ts} +3 -3
  4. package/dist/Caveat.d.ts.map +1 -0
  5. package/dist/{Caveat.mjs → Caveat.js} +4 -4
  6. package/dist/Caveat.js.map +1 -0
  7. package/dist/{Permission.d.mts → Permission.d.ts} +7 -7
  8. package/dist/Permission.d.ts.map +1 -0
  9. package/dist/{Permission.mjs → Permission.js} +2 -2
  10. package/dist/Permission.js.map +1 -0
  11. package/dist/{PermissionController-method-action-types.d.cts → PermissionController-method-action-types.d.ts} +2 -2
  12. package/dist/PermissionController-method-action-types.d.ts.map +1 -0
  13. package/dist/{PermissionController-method-action-types.mjs → PermissionController-method-action-types.js} +1 -1
  14. package/dist/PermissionController-method-action-types.js.map +1 -0
  15. package/dist/{PermissionController.d.cts → PermissionController.d.ts} +11 -11
  16. package/dist/PermissionController.d.ts.map +1 -0
  17. package/dist/PermissionController.js +1535 -0
  18. package/dist/PermissionController.js.map +1 -0
  19. package/dist/{SubjectMetadataController-method-action-types.d.cts → SubjectMetadataController-method-action-types.d.ts} +2 -2
  20. package/dist/SubjectMetadataController-method-action-types.d.ts.map +1 -0
  21. package/dist/{SubjectMetadataController-method-action-types.mjs → SubjectMetadataController-method-action-types.js} +1 -1
  22. package/dist/SubjectMetadataController-method-action-types.js.map +1 -0
  23. package/dist/{SubjectMetadataController.d.cts → SubjectMetadataController.d.ts} +8 -8
  24. package/dist/SubjectMetadataController.d.ts.map +1 -0
  25. package/dist/SubjectMetadataController.js +161 -0
  26. package/dist/SubjectMetadataController.js.map +1 -0
  27. package/dist/{createRestrictedMethodMessenger.d.cts → createRestrictedMethodMessenger.d.ts} +3 -3
  28. package/dist/createRestrictedMethodMessenger.d.ts.map +1 -0
  29. package/dist/{createRestrictedMethodMessenger.mjs → createRestrictedMethodMessenger.js} +2 -2
  30. package/dist/createRestrictedMethodMessenger.js.map +1 -0
  31. package/dist/{errors.d.mts → errors.d.ts} +6 -6
  32. package/dist/errors.d.ts.map +1 -0
  33. package/dist/{errors.mjs → errors.js} +17 -3
  34. package/dist/errors.js.map +1 -0
  35. package/dist/{index.d.cts → index.d.ts} +12 -12
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +9 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/{permission-middleware.d.cts → permission-middleware.d.ts} +7 -7
  40. package/dist/permission-middleware.d.ts.map +1 -0
  41. package/dist/{permission-middleware.mjs → permission-middleware.js} +3 -3
  42. package/dist/permission-middleware.js.map +1 -0
  43. package/dist/{utils.d.cts → utils.d.ts} +3 -3
  44. package/dist/utils.d.ts.map +1 -0
  45. package/dist/{utils.mjs → utils.js} +1 -1
  46. package/dist/utils.js.map +1 -0
  47. package/package.json +34 -39
  48. package/dist/Caveat.cjs +0 -48
  49. package/dist/Caveat.cjs.map +0 -1
  50. package/dist/Caveat.d.cts +0 -211
  51. package/dist/Caveat.d.cts.map +0 -1
  52. package/dist/Caveat.d.mts.map +0 -1
  53. package/dist/Caveat.mjs.map +0 -1
  54. package/dist/Permission.cjs +0 -65
  55. package/dist/Permission.cjs.map +0 -1
  56. package/dist/Permission.d.cts +0 -415
  57. package/dist/Permission.d.cts.map +0 -1
  58. package/dist/Permission.d.mts.map +0 -1
  59. package/dist/Permission.mjs.map +0 -1
  60. package/dist/PermissionController-method-action-types.cjs +0 -7
  61. package/dist/PermissionController-method-action-types.cjs.map +0 -1
  62. package/dist/PermissionController-method-action-types.d.cts.map +0 -1
  63. package/dist/PermissionController-method-action-types.d.mts +0 -374
  64. package/dist/PermissionController-method-action-types.d.mts.map +0 -1
  65. package/dist/PermissionController-method-action-types.mjs.map +0 -1
  66. package/dist/PermissionController.cjs +0 -1257
  67. package/dist/PermissionController.cjs.map +0 -1
  68. package/dist/PermissionController.d.cts.map +0 -1
  69. package/dist/PermissionController.d.mts +0 -753
  70. package/dist/PermissionController.d.mts.map +0 -1
  71. package/dist/PermissionController.mjs +0 -1257
  72. package/dist/PermissionController.mjs.map +0 -1
  73. package/dist/SubjectMetadataController-method-action-types.cjs +0 -7
  74. package/dist/SubjectMetadataController-method-action-types.cjs.map +0 -1
  75. package/dist/SubjectMetadataController-method-action-types.d.cts.map +0 -1
  76. package/dist/SubjectMetadataController-method-action-types.d.mts +0 -51
  77. package/dist/SubjectMetadataController-method-action-types.d.mts.map +0 -1
  78. package/dist/SubjectMetadataController-method-action-types.mjs.map +0 -1
  79. package/dist/SubjectMetadataController.cjs +0 -158
  80. package/dist/SubjectMetadataController.cjs.map +0 -1
  81. package/dist/SubjectMetadataController.d.cts.map +0 -1
  82. package/dist/SubjectMetadataController.d.mts +0 -104
  83. package/dist/SubjectMetadataController.d.mts.map +0 -1
  84. package/dist/SubjectMetadataController.mjs +0 -154
  85. package/dist/SubjectMetadataController.mjs.map +0 -1
  86. package/dist/createRestrictedMethodMessenger.cjs +0 -20
  87. package/dist/createRestrictedMethodMessenger.cjs.map +0 -1
  88. package/dist/createRestrictedMethodMessenger.d.cts.map +0 -1
  89. package/dist/createRestrictedMethodMessenger.d.mts +0 -42
  90. package/dist/createRestrictedMethodMessenger.d.mts.map +0 -1
  91. package/dist/createRestrictedMethodMessenger.mjs.map +0 -1
  92. package/dist/errors.cjs +0 -226
  93. package/dist/errors.cjs.map +0 -1
  94. package/dist/errors.d.cts +0 -183
  95. package/dist/errors.d.cts.map +0 -1
  96. package/dist/errors.d.mts.map +0 -1
  97. package/dist/errors.mjs.map +0 -1
  98. package/dist/index.cjs +0 -30
  99. package/dist/index.cjs.map +0 -1
  100. package/dist/index.d.cts.map +0 -1
  101. package/dist/index.d.mts +0 -12
  102. package/dist/index.d.mts.map +0 -1
  103. package/dist/index.mjs +0 -9
  104. package/dist/index.mjs.map +0 -1
  105. package/dist/permission-middleware.cjs +0 -59
  106. package/dist/permission-middleware.cjs.map +0 -1
  107. package/dist/permission-middleware.d.cts.map +0 -1
  108. package/dist/permission-middleware.d.mts +0 -49
  109. package/dist/permission-middleware.d.mts.map +0 -1
  110. package/dist/permission-middleware.mjs.map +0 -1
  111. package/dist/utils.cjs +0 -44
  112. package/dist/utils.cjs.map +0 -1
  113. package/dist/utils.d.cts.map +0 -1
  114. package/dist/utils.d.mts +0 -34
  115. package/dist/utils.d.mts.map +0 -1
  116. package/dist/utils.mjs.map +0 -1
@@ -1,8 +1,8 @@
1
- import { DataWithOptionalCause, EthereumProviderError, OptionalDataWithOptionalCause } from "@metamask/rpc-errors";
2
- import { JsonRpcError } from "@metamask/rpc-errors";
3
- import type { CaveatConstraint } from "./Caveat.mjs";
4
- import type { PermissionType } from "./Permission.mjs";
5
- import type { PermissionDiffMap } from "./PermissionController.mjs";
1
+ import { DataWithOptionalCause, EthereumProviderError, OptionalDataWithOptionalCause } from '@metamask/rpc-errors';
2
+ import { JsonRpcError } from '@metamask/rpc-errors';
3
+ import type { CaveatConstraint } from './Caveat.js';
4
+ import type { PermissionType } from './Permission.js';
5
+ import type { PermissionDiffMap } from './PermissionController.js';
6
6
  type UnauthorizedArg = {
7
7
  data?: Record<string, unknown>;
8
8
  message?: string;
@@ -180,4 +180,4 @@ export declare class PermissionsRequestNotFoundError extends CustomError {
180
180
  constructor(id: string);
181
181
  }
182
182
  export {};
183
- //# sourceMappingURL=errors.d.mts.map
183
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,6BAA6B,EAC9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAIL,YAAY,EACb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,E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BAA6B,SAAQ,WAAW;IACpD,IAAI,EAAE;QACX,cAAc,EAAE,MAAM,CAAC;QACvB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IAEF,YAAY,cAAc,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAK1D;CACF;AAED,qBAAa,gCAAiC,SAAQ,WAAW;IACxD,IAAI,EAAE;QACX,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACpC,cAAc,EAAE,cAAc,CAAC;KAChC,CAAC;IAEF,YACE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,cAAc,EAAE,cAAc,EAM/B;CACF;AAED,qBAAa,+BAAgC,SAAQ,WAAW;IAC9D,YAAY,EAAE,EAAE,MAAM,EAErB;CACF"}
@@ -1,5 +1,4 @@
1
- import { EthereumProviderError } from "@metamask/rpc-errors";
2
- import { errorCodes, providerErrors, rpcErrors, JsonRpcError } from "@metamask/rpc-errors";
1
+ import { errorCodes, providerErrors, rpcErrors, JsonRpcError, } from '@metamask/rpc-errors';
3
2
  /**
4
3
  * Utility function for building an "unauthorized" error.
5
4
  *
@@ -82,6 +81,8 @@ export class CaveatMergerDoesNotExistError extends CustomError {
82
81
  }
83
82
  }
84
83
  export class InvalidMergedPermissionsError extends Error {
84
+ cause;
85
+ data;
85
86
  constructor(origin, cause, diff) {
86
87
  super(`Invalid merged permissions for subject "${origin}":\n${cause.message}`);
87
88
  this.cause = cause;
@@ -89,6 +90,7 @@ export class InvalidMergedPermissionsError extends Error {
89
90
  }
90
91
  }
91
92
  export class InvalidApprovedPermissionError extends CustomError {
93
+ data;
92
94
  constructor(origin, target, approvedPermission) {
93
95
  super(`Invalid approved permission for origin "${origin}" and target "${target}".`);
94
96
  this.data = { origin, target, approvedPermission };
@@ -100,6 +102,7 @@ export class PermissionDoesNotExistError extends CustomError {
100
102
  }
101
103
  }
102
104
  export class EndowmentPermissionDoesNotExistError extends CustomError {
105
+ data;
103
106
  constructor(target, origin) {
104
107
  super(`${origin ? `Subject "${origin}"` : 'Unknown subject'} has no permission for "${target}".`);
105
108
  if (origin) {
@@ -108,6 +111,7 @@ export class EndowmentPermissionDoesNotExistError extends CustomError {
108
111
  }
109
112
  }
110
113
  export class UnrecognizedCaveatTypeError extends CustomError {
114
+ data;
111
115
  constructor(caveatType, origin, target) {
112
116
  super(`Unrecognized caveat type: "${caveatType}"`);
113
117
  this.data = { caveatType };
@@ -120,6 +124,7 @@ export class UnrecognizedCaveatTypeError extends CustomError {
120
124
  }
121
125
  }
122
126
  export class InvalidCaveatsPropertyError extends CustomError {
127
+ data;
123
128
  constructor(origin, target, caveatsProperty) {
124
129
  super(`The "caveats" property of permission for "${target}" of subject "${origin}" is invalid. It must be a non-empty array if specified.`);
125
130
  this.data = { origin, target, caveatsProperty };
@@ -136,54 +141,63 @@ export class CaveatAlreadyExistsError extends CustomError {
136
141
  }
137
142
  }
138
143
  export class InvalidCaveatError extends JsonRpcError {
144
+ data;
139
145
  constructor(receivedCaveat, origin, target) {
140
146
  super(errorCodes.rpc.invalidParams, `Invalid caveat. Caveats must be plain objects.`, { receivedCaveat });
141
147
  this.data = { origin, target };
142
148
  }
143
149
  }
144
150
  export class InvalidCaveatTypeError extends CustomError {
151
+ data;
145
152
  constructor(caveat, origin, target) {
146
153
  super(`Caveat types must be strings. Received: "${typeof caveat.type}"`);
147
154
  this.data = { caveat, origin, target };
148
155
  }
149
156
  }
150
157
  export class CaveatMissingValueError extends CustomError {
158
+ data;
151
159
  constructor(caveat, origin, target) {
152
160
  super(`Caveat is missing "value" field.`);
153
161
  this.data = { caveat, origin, target };
154
162
  }
155
163
  }
156
164
  export class CaveatInvalidJsonError extends CustomError {
165
+ data;
157
166
  constructor(caveat, origin, target) {
158
167
  super(`Caveat "value" is invalid JSON.`);
159
168
  this.data = { caveat, origin, target };
160
169
  }
161
170
  }
162
171
  export class InvalidCaveatFieldsError extends CustomError {
172
+ data;
163
173
  constructor(caveat, origin, target) {
164
174
  super(`Caveat has unexpected number of fields: "${Object.keys(caveat).length}"`);
165
175
  this.data = { caveat, origin, target };
166
176
  }
167
177
  }
168
178
  export class ForbiddenCaveatError extends CustomError {
179
+ data;
169
180
  constructor(caveatType, origin, targetName) {
170
181
  super(`Permissions for target "${targetName}" may not have caveats of type "${caveatType}".`);
171
182
  this.data = { caveatType, origin, target: targetName };
172
183
  }
173
184
  }
174
185
  export class DuplicateCaveatError extends CustomError {
186
+ data;
175
187
  constructor(caveatType, origin, targetName) {
176
188
  super(`Permissions for target "${targetName}" contains multiple caveats of type "${caveatType}".`);
177
189
  this.data = { caveatType, origin, target: targetName };
178
190
  }
179
191
  }
180
192
  export class CaveatMergeTypeMismatchError extends CustomError {
193
+ data;
181
194
  constructor(leftCaveatType, rightCaveatType) {
182
195
  super(`Cannot merge caveats of different types: "${leftCaveatType}" and "${rightCaveatType}".`);
183
196
  this.data = { leftCaveatType, rightCaveatType };
184
197
  }
185
198
  }
186
199
  export class CaveatSpecificationMismatchError extends CustomError {
200
+ data;
187
201
  constructor(caveatSpec, permissionType) {
188
202
  super(`Caveat specification uses a mismatched type. Expected caveats for ${permissionType}`);
189
203
  this.data = { caveatSpec, permissionType };
@@ -194,4 +208,4 @@ export class PermissionsRequestNotFoundError extends CustomError {
194
208
  super(`Permissions request with id "${id}" not found.`);
195
209
  }
196
210
  }
197
- //# sourceMappingURL=errors.mjs.map
211
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,UAAU,EACV,cAAc,EACd,SAAS,EACT,YAAY,GACb,MAAM,sBAAsB,CAAC;AAW9B;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAqB;IAErB,OAAO,cAAc,CAAC,YAAY,CAAC;QACjC,OAAO,EACL,qKAAqK;QACvK,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC,CAAC;AACL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'@metamask/rpc-errors';\nimport {\n errorCodes,\n providerErrors,\n rpcErrors,\n JsonRpcError,\n} from '@metamask/rpc-errors';\n\nimport type { CaveatConstraint } from './Caveat.js';\nimport type { PermissionType } from './Permission.js';\nimport type { PermissionDiffMap } from './PermissionController.js';\n\ntype UnauthorizedArg = {\n data?: Record<string, unknown>;\n message?: string;\n};\n\n/**\n * Utility function for building an \"unauthorized\" error.\n *\n * @param opts - Optional arguments that add extra context\n * @returns The built error\n */\nexport function unauthorized(\n opts: UnauthorizedArg,\n): EthereumProviderError<UnauthorizedArg> {\n return providerErrors.unauthorized({\n message:\n 'Unauthorized to perform action. Try requesting the required permission(s) first. For more information, see: https://docs.metamask.io/guide/rpc-api.html#permissions',\n data: opts.data,\n });\n}\n\n/**\n * Utility function for building a \"method not found\" error.\n *\n * @param method - The method in question.\n * @param data - Optional data for context.\n * @returns The built error\n */\nexport function methodNotFound(\n method: string,\n data?: DataWithOptionalCause,\n): JsonRpcError<OptionalDataWithOptionalCause> {\n const message = `The method \"${method}\" does not exist / is not available.`;\n\n const opts: Parameters<typeof rpcErrors.methodNotFound>[0] = { message };\n if (data !== undefined) {\n opts.data = data;\n }\n return rpcErrors.methodNotFound(opts);\n}\n\ntype InvalidParamsArg = {\n message?: string;\n data?: DataWithOptionalCause;\n};\n\n/**\n * Utility function for building an \"invalid params\" error.\n *\n * @param opts - Optional arguments that add extra context\n * @returns The built error\n */\nexport function invalidParams(\n opts: InvalidParamsArg,\n): JsonRpcError<DataWithOptionalCause> {\n return rpcErrors.invalidParams({\n data: opts.data,\n message: opts.message,\n });\n}\n\n/**\n * Utility function for building an \"user rejected request\" error.\n *\n * @param data - Optional data to add extra context\n * @returns The built error\n */\nexport function userRejectedRequest<Data extends Record<string, unknown>>(\n data?: Data,\n): JsonRpcError<Data> {\n return providerErrors.userRejectedRequest({ data });\n}\n\n/**\n * Utility function for building an internal error.\n *\n * @param message - The error message\n * @param data - Optional data to add extra context\n * @returns The built error\n */\nexport function internalError<Data extends Record<string, unknown>>(\n message: string,\n data?: Data,\n): JsonRpcError<Data> {\n return rpcErrors.internal({ message, data });\n}\n\nclass CustomError extends Error {\n constructor(message?: string) {\n super(message);\n this.name = this.constructor.name;\n }\n}\n\nexport class InvalidSubjectIdentifierError extends CustomError {\n constructor(origin: unknown) {\n super(\n `Invalid subject identifier: \"${\n typeof origin === 'string' ? origin : typeof origin\n }\"`,\n );\n this.name = this.constructor.name;\n }\n}\n\nexport class UnrecognizedSubjectError extends CustomError {\n constructor(origin: string) {\n super(`Unrecognized subject: \"${origin}\" has no permissions.`);\n this.name = this.constructor.name;\n }\n}\n\nexport class CaveatMergerDoesNotExistError extends CustomError {\n constructor(caveatType: string) {\n super(`Caveat value merger does not exist for type: \"${caveatType}\"`);\n }\n}\n\nexport class InvalidMergedPermissionsError extends Error {\n public cause: Error;\n\n public data: {\n diff: PermissionDiffMap<string, CaveatConstraint>;\n };\n\n constructor(\n origin: string,\n cause: Error,\n diff: PermissionDiffMap<string, CaveatConstraint>,\n ) {\n super(\n `Invalid merged permissions for subject \"${origin}\":\\n${cause.message}`,\n );\n this.cause = cause;\n this.data = { diff };\n }\n}\n\nexport class InvalidApprovedPermissionError extends CustomError {\n public data: {\n origin: string;\n target: string;\n approvedPermission: Record<string, unknown>;\n };\n\n constructor(\n origin: string,\n target: string,\n approvedPermission: Record<string, unknown>,\n ) {\n super(\n `Invalid approved permission for origin \"${origin}\" and target \"${target}\".`,\n );\n this.data = { origin, target, approvedPermission };\n }\n}\nexport class PermissionDoesNotExistError extends CustomError {\n constructor(origin: string, target: string) {\n super(`Subject \"${origin}\" has no permission for \"${target}\".`);\n }\n}\n\nexport class EndowmentPermissionDoesNotExistError extends CustomError {\n public data?: { origin: string };\n\n constructor(target: string, origin?: string) {\n super(\n `${\n origin ? `Subject \"${origin}\"` : 'Unknown subject'\n } has no permission for \"${target}\".`,\n );\n if (origin) {\n this.data = { origin };\n }\n }\n}\n\nexport class UnrecognizedCaveatTypeError extends CustomError {\n public data: {\n caveatType: string;\n origin?: string;\n target?: string;\n };\n\n constructor(caveatType: string);\n\n constructor(caveatType: string, origin: string, target: string);\n\n constructor(caveatType: string, origin?: string, target?: string) {\n super(`Unrecognized caveat type: \"${caveatType}\"`);\n this.data = { caveatType };\n if (origin !== undefined) {\n this.data.origin = origin;\n }\n\n if (target !== undefined) {\n this.data.target = target;\n }\n }\n}\n\nexport class InvalidCaveatsPropertyError extends CustomError {\n public data: { origin: string; target: string; caveatsProperty: unknown };\n\n constructor(origin: string, target: string, caveatsProperty: unknown) {\n super(\n `The \"caveats\" property of permission for \"${target}\" of subject \"${origin}\" is invalid. It must be a non-empty array if specified.`,\n );\n this.data = { origin, target, caveatsProperty };\n }\n}\n\nexport class CaveatDoesNotExistError extends CustomError {\n constructor(origin: string, target: string, caveatType: string) {\n super(\n `Permission for \"${target}\" of subject \"${origin}\" has no caveat of type \"${caveatType}\".`,\n );\n }\n}\n\nexport class CaveatAlreadyExistsError extends CustomError {\n constructor(origin: string, target: string, caveatType: string) {\n super(\n `Permission for \"${target}\" of subject \"${origin}\" already has a caveat of type \"${caveatType}\".`,\n );\n }\n}\n\nexport class InvalidCaveatError extends JsonRpcError<\n DataWithOptionalCause | undefined\n> {\n public override data: { origin: string; target: string };\n\n constructor(receivedCaveat: unknown, origin: string, target: string) {\n super(\n errorCodes.rpc.invalidParams,\n `Invalid caveat. Caveats must be plain objects.`,\n { receivedCaveat },\n );\n this.data = { origin, target };\n }\n}\n\nexport class InvalidCaveatTypeError extends CustomError {\n public data: {\n caveat: Record<string, unknown>;\n origin: string;\n target: string;\n };\n\n constructor(caveat: Record<string, unknown>, origin: string, target: string) {\n super(`Caveat types must be strings. Received: \"${typeof caveat.type}\"`);\n this.data = { caveat, origin, target };\n }\n}\n\nexport class CaveatMissingValueError extends CustomError {\n public data: {\n caveat: Record<string, unknown>;\n origin: string;\n target: string;\n };\n\n constructor(caveat: Record<string, unknown>, origin: string, target: string) {\n super(`Caveat is missing \"value\" field.`);\n this.data = { caveat, origin, target };\n }\n}\n\nexport class CaveatInvalidJsonError extends CustomError {\n public data: {\n caveat: Record<string, unknown>;\n origin: string;\n target: string;\n };\n\n constructor(caveat: Record<string, unknown>, origin: string, target: string) {\n super(`Caveat \"value\" is invalid JSON.`);\n this.data = { caveat, origin, target };\n }\n}\n\nexport class InvalidCaveatFieldsError extends CustomError {\n public data: {\n caveat: Record<string, unknown>;\n origin: string;\n target: string;\n };\n\n constructor(caveat: Record<string, unknown>, origin: string, target: string) {\n super(\n `Caveat has unexpected number of fields: \"${Object.keys(caveat).length}\"`,\n );\n this.data = { caveat, origin, target };\n }\n}\n\nexport class ForbiddenCaveatError extends CustomError {\n public data: {\n caveatType: string;\n origin: string;\n target: string;\n };\n\n constructor(caveatType: string, origin: string, targetName: string) {\n super(\n `Permissions for target \"${targetName}\" may not have caveats of type \"${caveatType}\".`,\n );\n this.data = { caveatType, origin, target: targetName };\n }\n}\n\nexport class DuplicateCaveatError extends CustomError {\n public data: {\n caveatType: string;\n origin: string;\n target: string;\n };\n\n constructor(caveatType: string, origin: string, targetName: string) {\n super(\n `Permissions for target \"${targetName}\" contains multiple caveats of type \"${caveatType}\".`,\n );\n this.data = { caveatType, origin, target: targetName };\n }\n}\n\nexport class CaveatMergeTypeMismatchError extends CustomError {\n public data: {\n leftCaveatType: string;\n rightCaveatType: string;\n };\n\n constructor(leftCaveatType: string, rightCaveatType: string) {\n super(\n `Cannot merge caveats of different types: \"${leftCaveatType}\" and \"${rightCaveatType}\".`,\n );\n this.data = { leftCaveatType, rightCaveatType };\n }\n}\n\nexport class CaveatSpecificationMismatchError extends CustomError {\n public data: {\n caveatSpec: Record<string, unknown>;\n permissionType: PermissionType;\n };\n\n constructor(\n caveatSpec: Record<string, unknown>,\n permissionType: PermissionType,\n ) {\n super(\n `Caveat specification uses a mismatched type. Expected caveats for ${permissionType}`,\n );\n this.data = { caveatSpec, permissionType };\n }\n}\n\nexport class PermissionsRequestNotFoundError extends CustomError {\n constructor(id: string) {\n super(`Permissions request with id \"${id}\" not found.`);\n }\n}\n"]}
@@ -1,12 +1,12 @@
1
- export * from "./Caveat.cjs";
2
- export { createRestrictedMethodMessenger } from "./createRestrictedMethodMessenger.cjs";
3
- export * from "./errors.cjs";
4
- export * from "./Permission.cjs";
5
- export * from "./PermissionController.cjs";
6
- export type { PermissionControllerClearStateAction, PermissionControllerExecuteRestrictedMethodAction, PermissionControllerGetCaveatAction, PermissionControllerGetEndowmentsAction, PermissionControllerGetPermissionsAction, PermissionControllerGetSubjectNamesAction, PermissionControllerGrantPermissionsAction, PermissionControllerGrantPermissionsIncrementalAction, PermissionControllerHasPermissionAction, PermissionControllerHasPermissionsAction, PermissionControllerHasUnrestrictedMethodAction, PermissionControllerRequestPermissionsAction, PermissionControllerRequestPermissionsIncrementalAction, PermissionControllerRevokeAllPermissionsAction, PermissionControllerRevokePermissionForAllSubjectsAction, PermissionControllerRevokePermissionsAction, PermissionControllerUpdateCaveatAction, PermissionControllerGetPermissionAction, PermissionControllerRevokePermissionAction, PermissionControllerUpdatePermissionsByCaveatAction, PermissionControllerAcceptPermissionsRequestAction, PermissionControllerRejectPermissionsRequestAction, } from "./PermissionController-method-action-types.cjs";
7
- export { createPermissionMiddleware, createPermissionMiddlewareV2, type PermissionMiddlewareActions, } from "./permission-middleware.cjs";
8
- export type { ExtractSpecifications } from "./utils.cjs";
9
- export { MethodNames } from "./utils.cjs";
10
- export * from "./SubjectMetadataController.cjs";
11
- export type { SubjectMetadataControllerClearStateAction, SubjectMetadataControllerAddSubjectMetadataAction, SubjectMetadataControllerGetSubjectMetadataAction, SubjectMetadataControllerTrimMetadataStateAction, } from "./SubjectMetadataController-method-action-types.cjs";
12
- //# sourceMappingURL=index.d.cts.map
1
+ export * from './Caveat.js';
2
+ export { createRestrictedMethodMessenger } from './createRestrictedMethodMessenger.js';
3
+ export * from './errors.js';
4
+ export * from './Permission.js';
5
+ export * from './PermissionController.js';
6
+ export type { PermissionControllerClearStateAction, PermissionControllerExecuteRestrictedMethodAction, PermissionControllerGetCaveatAction, PermissionControllerGetEndowmentsAction, PermissionControllerGetPermissionsAction, PermissionControllerGetSubjectNamesAction, PermissionControllerGrantPermissionsAction, PermissionControllerGrantPermissionsIncrementalAction, PermissionControllerHasPermissionAction, PermissionControllerHasPermissionsAction, PermissionControllerHasUnrestrictedMethodAction, PermissionControllerRequestPermissionsAction, PermissionControllerRequestPermissionsIncrementalAction, PermissionControllerRevokeAllPermissionsAction, PermissionControllerRevokePermissionForAllSubjectsAction, PermissionControllerRevokePermissionsAction, PermissionControllerUpdateCaveatAction, PermissionControllerGetPermissionAction, PermissionControllerRevokePermissionAction, PermissionControllerUpdatePermissionsByCaveatAction, PermissionControllerAcceptPermissionsRequestAction, PermissionControllerRejectPermissionsRequestAction, } from './PermissionController-method-action-types.js';
7
+ export { createPermissionMiddleware, createPermissionMiddlewareV2, type PermissionMiddlewareActions, } from './permission-middleware.js';
8
+ export type { ExtractSpecifications } from './utils.js';
9
+ export { MethodNames } from './utils.js';
10
+ export * from './SubjectMetadataController.js';
11
+ export type { SubjectMetadataControllerClearStateAction, SubjectMetadataControllerAddSubjectMetadataAction, SubjectMetadataControllerGetSubjectMetadataAction, SubjectMetadataControllerTrimMetadataStateAction, } from './SubjectMetadataController-method-action-types.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,YAAY,EACV,oCAAoC,EACpC,iDAAiD,EACjD,mCAAmC,EACnC,uCAAuC,EACvC,wCAAwC,EACxC,yCAAyC,EACzC,0CAA0C,EAC1C,qDAAqD,EACrD,uCAAuC,EACvC,wCAAwC,EACxC,+CAA+C,EAC/C,4CAA4C,EAC5C,uDAAuD,EACvD,8CAA8C,EAC9C,wDAAwD,EACxD,2CAA2C,EAC3C,sCAAsC,EACtC,uCAAuC,EACvC,0CAA0C,EAC1C,mDAAmD,EACnD,kDAAkD,EAClD,kDAAkD,GACnD,MAAM,+CAA+C,CAAC;AACvD,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,KAAK,2BAA2B,GACjC,MAAM,4BAA4B,CAAC;AACpC,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,YAAY,EACV,yCAAyC,EACzC,iDAAiD,EACjD,iDAAiD,EACjD,gDAAgD,GACjD,MAAM,oDAAoD,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export * from './Caveat.js';
2
+ export { createRestrictedMethodMessenger } from './createRestrictedMethodMessenger.js';
3
+ export * from './errors.js';
4
+ export * from './Permission.js';
5
+ export * from './PermissionController.js';
6
+ export { createPermissionMiddleware, createPermissionMiddlewareV2, } from './permission-middleware.js';
7
+ export { MethodNames } from './utils.js';
8
+ export * from './SubjectMetadataController.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAyB1C,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,GAE7B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,cAAc,gCAAgC,CAAC","sourcesContent":["export * from './Caveat.js';\nexport { createRestrictedMethodMessenger } from './createRestrictedMethodMessenger.js';\nexport * from './errors.js';\nexport * from './Permission.js';\nexport * from './PermissionController.js';\nexport type {\n PermissionControllerClearStateAction,\n PermissionControllerExecuteRestrictedMethodAction,\n PermissionControllerGetCaveatAction,\n PermissionControllerGetEndowmentsAction,\n PermissionControllerGetPermissionsAction,\n PermissionControllerGetSubjectNamesAction,\n PermissionControllerGrantPermissionsAction,\n PermissionControllerGrantPermissionsIncrementalAction,\n PermissionControllerHasPermissionAction,\n PermissionControllerHasPermissionsAction,\n PermissionControllerHasUnrestrictedMethodAction,\n PermissionControllerRequestPermissionsAction,\n PermissionControllerRequestPermissionsIncrementalAction,\n PermissionControllerRevokeAllPermissionsAction,\n PermissionControllerRevokePermissionForAllSubjectsAction,\n PermissionControllerRevokePermissionsAction,\n PermissionControllerUpdateCaveatAction,\n PermissionControllerGetPermissionAction,\n PermissionControllerRevokePermissionAction,\n PermissionControllerUpdatePermissionsByCaveatAction,\n PermissionControllerAcceptPermissionsRequestAction,\n PermissionControllerRejectPermissionsRequestAction,\n} from './PermissionController-method-action-types.js';\nexport {\n createPermissionMiddleware,\n createPermissionMiddlewareV2,\n type PermissionMiddlewareActions,\n} from './permission-middleware.js';\nexport type { ExtractSpecifications } from './utils.js';\nexport { MethodNames } from './utils.js';\nexport * from './SubjectMetadataController.js';\nexport type {\n SubjectMetadataControllerClearStateAction,\n SubjectMetadataControllerAddSubjectMetadataAction,\n SubjectMetadataControllerGetSubjectMetadataAction,\n SubjectMetadataControllerTrimMetadataStateAction,\n} from './SubjectMetadataController-method-action-types.js';\n"]}
@@ -1,9 +1,9 @@
1
- import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
2
- import type { JsonRpcMiddleware as JsonRpcMiddlewareV2 } from "@metamask/json-rpc-engine/v2";
3
- import type { Messenger } from "@metamask/messenger";
4
- import type { Json } from "@metamask/utils";
5
- import type { RestrictedMethodParameters } from "./Permission.cjs";
6
- import type { PermissionControllerExecuteRestrictedMethodAction, PermissionControllerHasUnrestrictedMethodAction } from "./PermissionController-method-action-types.cjs";
1
+ import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';
2
+ import type { JsonRpcMiddleware as JsonRpcMiddlewareV2 } from '@metamask/json-rpc-engine/v2';
3
+ import type { Messenger } from '@metamask/messenger';
4
+ import type { Json } from '@metamask/utils';
5
+ import type { RestrictedMethodParameters } from './Permission.js';
6
+ import type { PermissionControllerExecuteRestrictedMethodAction, PermissionControllerHasUnrestrictedMethodAction } from './PermissionController-method-action-types.js';
7
7
  /**
8
8
  * The set of messenger actions required by the permission middleware.
9
9
  */
@@ -46,4 +46,4 @@ export declare function createPermissionMiddleware({ messenger, origin, }: Creat
46
46
  * @returns A `JsonRpcEngineV2` middleware.
47
47
  */
48
48
  export declare function createPermissionMiddlewareV2({ messenger, origin, }: CreatePermissionMiddlewareOptions): JsonRpcMiddlewareV2;
49
- //# sourceMappingURL=permission-middleware.d.cts.map
49
+ //# sourceMappingURL=permission-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-middleware.d.ts","sourceRoot":"","sources":["../src/permission-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,iBAAiB,IAAI,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAC7F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EACV,iDAAiD,EACjD,+CAA+C,EAChD,MAAM,+CAA+C,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,2BAA2B,GACnC,iDAAiD,GACjD,+CAA+C,CAAC;AAEpD,MAAM,MAAM,iCAAiC,GAAG;IAC9C,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;IAC1D,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,SAAS,EACT,MAAM,GACP,EAAE,iCAAiC,GAAG,iBAAiB,CACtD,0BAA0B,EAC1B,IAAI,CACL,CAuBA;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,SAAS,EACT,MAAM,GACP,EAAE,iCAAiC,GAAG,mBAAmB,CAezD"}
@@ -1,4 +1,4 @@
1
- import { createAsyncMiddleware } from "@metamask/json-rpc-engine";
1
+ import { createAsyncMiddleware } from '@metamask/json-rpc-engine';
2
2
  /**
3
3
  * Creates a JSON-RPC middleware that enforces permissions for a single subject.
4
4
  *
@@ -22,7 +22,7 @@ export function createPermissionMiddleware({ messenger, origin, }) {
22
22
  return next();
23
23
  }
24
24
  response.result = await messenger.call('PermissionController:executeRestrictedMethod', origin, method, params);
25
- return undefined;
25
+ return;
26
26
  };
27
27
  return createAsyncMiddleware(permissionsMiddleware);
28
28
  }
@@ -51,4 +51,4 @@ export function createPermissionMiddlewareV2({ messenger, origin, }) {
51
51
  return messenger.call('PermissionController:executeRestrictedMethod', origin, method, params);
52
52
  };
53
53
  }
54
- //# sourceMappingURL=permission-middleware.mjs.map
54
+ //# sourceMappingURL=permission-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-middleware.js","sourceRoot":"","sources":["../src/permission-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AA2BlE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,0BAA0B,CAAC,EACzC,SAAS,EACT,MAAM,GAC4B;IAIlC,MAAM,qBAAqB,GAGvB,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;QACpC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAEnC,IAAI,SAAS,CAAC,IAAI,CAAC,4CAA4C,EAAE,MAAM,CAAC,EAAE,CAAC;YACzE,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,QAAQ,CAAC,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,CACpC,8CAA8C,EAC9C,MAAM,EACN,MAAM,EACN,MAAM,CACP,CAAC;QACF,OAAO;IACT,CAAC,CAAC;IAEF,OAAO,qBAAqB,CAC1B,qBAAqB,CACtB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,4BAA4B,CAAC,EAC3C,SAAS,EACT,MAAM,GAC4B;IAClC,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;QACjC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAEnC,IAAI,SAAS,CAAC,IAAI,CAAC,4CAA4C,EAAE,MAAM,CAAC,EAAE,CAAC;YACzE,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,OAAO,SAAS,CAAC,IAAI,CACnB,8CAA8C,EAC9C,MAAM,EACN,MAAM,EACN,MAAM,CACP,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { createAsyncMiddleware } from '@metamask/json-rpc-engine';\nimport type {\n AsyncJsonrpcMiddleware,\n JsonRpcMiddleware,\n} from '@metamask/json-rpc-engine';\nimport type { JsonRpcMiddleware as JsonRpcMiddlewareV2 } from '@metamask/json-rpc-engine/v2';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n\nimport type { RestrictedMethodParameters } from './Permission.js';\nimport type {\n PermissionControllerExecuteRestrictedMethodAction,\n PermissionControllerHasUnrestrictedMethodAction,\n} from './PermissionController-method-action-types.js';\n\n/**\n * The set of messenger actions required by the permission middleware.\n */\nexport type PermissionMiddlewareActions =\n | PermissionControllerExecuteRestrictedMethodAction\n | PermissionControllerHasUnrestrictedMethodAction;\n\nexport type CreatePermissionMiddlewareOptions = {\n messenger: Messenger<string, PermissionMiddlewareActions>;\n origin: string;\n};\n\n/**\n * Creates a JSON-RPC middleware that enforces permissions for a single subject.\n *\n * The middleware passes through unrestricted methods, and otherwise dispatches\n * restricted methods to the `PermissionController` via messenger actions. If\n * the subject lacks the required permission, or if the method does not exist,\n * the corresponding error is propagated to the JSON-RPC response.\n *\n * @deprecated Use {@link createPermissionMiddlewareV2} with `JsonRpcEngineV2`.\n * @param options - Options bag.\n * @param options.messenger - A messenger with the\n * `PermissionController:executeRestrictedMethod` and\n * `PermissionController:hasUnrestrictedMethod` actions.\n * @param options.origin - The origin of the subject for which to create the middleware.\n * @returns A `json-rpc-engine` middleware.\n */\nexport function createPermissionMiddleware({\n messenger,\n origin,\n}: CreatePermissionMiddlewareOptions): JsonRpcMiddleware<\n RestrictedMethodParameters,\n Json\n> {\n const permissionsMiddleware: AsyncJsonrpcMiddleware<\n RestrictedMethodParameters,\n Json\n > = async (request, response, next) => {\n const { method, params } = request;\n\n if (messenger.call('PermissionController:hasUnrestrictedMethod', method)) {\n return next();\n }\n\n response.result = await messenger.call(\n 'PermissionController:executeRestrictedMethod',\n origin,\n method,\n params,\n );\n return;\n };\n\n return createAsyncMiddleware<RestrictedMethodParameters, Json>(\n permissionsMiddleware,\n );\n}\n\n/**\n * Creates a `JsonRpcEngineV2` middleware that enforces permissions for a\n * single subject.\n *\n * The middleware passes through unrestricted methods, and otherwise dispatches\n * restricted methods to the `PermissionController` via messenger actions. If\n * the subject lacks the required permission, or if the method does not exist,\n * the corresponding error is thrown.\n *\n * @param options - Options bag.\n * @param options.messenger - A messenger with the\n * `PermissionController:executeRestrictedMethod` and\n * `PermissionController:hasUnrestrictedMethod` actions.\n * @param options.origin - The origin of the subject for which to create the middleware.\n * @returns A `JsonRpcEngineV2` middleware.\n */\nexport function createPermissionMiddlewareV2({\n messenger,\n origin,\n}: CreatePermissionMiddlewareOptions): JsonRpcMiddlewareV2 {\n return async ({ request, next }) => {\n const { method, params } = request;\n\n if (messenger.call('PermissionController:hasUnrestrictedMethod', method)) {\n return next();\n }\n\n return messenger.call(\n 'PermissionController:executeRestrictedMethod',\n origin,\n method,\n params,\n );\n };\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { CaveatConstraint, CaveatSpecificationConstraint, CaveatSpecificationMap } from "./Caveat.cjs";
2
- import type { PermissionConstraint, PermissionSpecificationConstraint, PermissionSpecificationMap } from "./Permission.cjs";
1
+ import type { CaveatConstraint, CaveatSpecificationConstraint, CaveatSpecificationMap } from './Caveat.js';
2
+ import type { PermissionConstraint, PermissionSpecificationConstraint, PermissionSpecificationMap } from './Permission.js';
3
3
  export declare enum MethodNames {
4
4
  RequestPermissions = "wallet_requestPermissions",
5
5
  GetPermissions = "wallet_getPermissions",
@@ -31,4 +31,4 @@ export declare function collectUniqueAndPairedCaveats(leftPermission: Partial<Pe
31
31
  leftUniqueCaveats: CaveatConstraint[];
32
32
  rightUniqueCaveats: CaveatConstraint[];
33
33
  };
34
- //# sourceMappingURL=utils.d.cts.map
34
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,6BAA6B,EAC7B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACV,oBAAoB,EACpB,iCAAiC,EACjC,0BAA0B,EAC3B,MAAM,iBAAiB,CAAC;AAEzB,oBAAY,WAAW;IACrB,kBAAkB,8BAA8B;IAChD,cAAc,0BAA0B;IACxC,iBAAiB,6BAA6B;CAC/C;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,qBAAqB,CAC/B,iBAAiB,SACb,sBAAsB,CAAC,6BAA6B,CAAC,GACrD,0BAA0B,CAAC,iCAAiC,CAAC,IAC/D,iBAAiB,CAAC,MAAM,iBAAiB,CAAC,CAAC;AAE/C;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAC3C,cAAc,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,SAAS,EACzD,eAAe,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAC7C;IACD,WAAW,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,EAAE,CAAC;IACpD,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,kBAAkB,EAAE,gBAAgB,EAAE,CAAC;CACxC,CAwBA"}
@@ -37,4 +37,4 @@ export function collectUniqueAndPairedCaveats(leftPermission, rightPermission) {
37
37
  rightUniqueCaveats: [...rightCaveats],
38
38
  };
39
39
  }
40
- //# sourceMappingURL=utils.mjs.map
40
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAWA,MAAM,CAAN,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,+DAAgD,CAAA;IAChD,uDAAwC,CAAA;IACxC,6DAA8C,CAAA;AAChD,CAAC,EAJW,WAAW,KAAX,WAAW,QAItB;AAgBD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,6BAA6B,CAC3C,cAAyD,EACzD,eAA8C;IAM9C,MAAM,WAAW,GAAG,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC3D,MAAM,YAAY,GAAG,eAAe,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC5D,MAAM,iBAAiB,GAAuB,EAAE,CAAC;IACjD,MAAM,WAAW,GAA2C,EAAE,CAAC;IAE/D,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QACjC,MAAM,gBAAgB,GAAG,YAAY,CAAC,SAAS,CAC7C,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,KAAK,UAAU,CAAC,IAAI,CACtD,CAAC;QAEF,IAAI,gBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC;YAC5B,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACrC,CAAC;aAAM,CAAC;YACN,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;YAC/D,YAAY,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,WAAW;QACX,iBAAiB;QACjB,kBAAkB,EAAE,CAAC,GAAG,YAAY,CAAC;KACtC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n CaveatConstraint,\n CaveatSpecificationConstraint,\n CaveatSpecificationMap,\n} from './Caveat.js';\nimport type {\n PermissionConstraint,\n PermissionSpecificationConstraint,\n PermissionSpecificationMap,\n} from './Permission.js';\n\nexport enum MethodNames {\n RequestPermissions = 'wallet_requestPermissions',\n GetPermissions = 'wallet_getPermissions',\n RevokePermissions = 'wallet_revokePermissions',\n}\n\n/**\n * Utility type for extracting a union of all individual caveat or permission\n * specification types from a {@link CaveatSpecificationMap} or\n * {@link PermissionSpecificationMap}.\n *\n * @template SpecificationsMap - The caveat or permission specifications map\n * whose specification type union to extract.\n */\nexport type ExtractSpecifications<\n SpecificationsMap extends\n | CaveatSpecificationMap<CaveatSpecificationConstraint>\n | PermissionSpecificationMap<PermissionSpecificationConstraint>,\n> = SpecificationsMap[keyof SpecificationsMap];\n\n/**\n * Given two permission objects, computes 3 sets:\n * - The set of caveat pairs that are common to both permissions.\n * - The set of caveats that are unique to the existing permission.\n * - The set of caveats that are unique to the requested permission.\n *\n * Assumes that the caveat arrays of both permissions are valid.\n *\n * @param leftPermission - The left-hand permission.\n * @param rightPermission - The right-hand permission.\n * @returns The sets of caveat pairs and unique caveats.\n */\nexport function collectUniqueAndPairedCaveats(\n leftPermission: Partial<PermissionConstraint> | undefined,\n rightPermission: Partial<PermissionConstraint>,\n): {\n caveatPairs: [CaveatConstraint, CaveatConstraint][];\n leftUniqueCaveats: CaveatConstraint[];\n rightUniqueCaveats: CaveatConstraint[];\n} {\n const leftCaveats = leftPermission?.caveats?.slice() ?? [];\n const rightCaveats = rightPermission.caveats?.slice() ?? [];\n const leftUniqueCaveats: CaveatConstraint[] = [];\n const caveatPairs: [CaveatConstraint, CaveatConstraint][] = [];\n\n leftCaveats.forEach((leftCaveat) => {\n const rightCaveatIndex = rightCaveats.findIndex(\n (rightCaveat) => rightCaveat.type === leftCaveat.type,\n );\n\n if (rightCaveatIndex === -1) {\n leftUniqueCaveats.push(leftCaveat);\n } else {\n caveatPairs.push([leftCaveat, rightCaveats[rightCaveatIndex]]);\n rightCaveats.splice(rightCaveatIndex, 1);\n }\n });\n\n return {\n caveatPairs,\n leftUniqueCaveats,\n rightUniqueCaveats: [...rightCaveats],\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/permission-controller",
3
- "version": "13.1.1",
3
+ "version": "14.1.0",
4
4
  "description": "Mediates access to JSON-RPC methods, used to interact with pieces of the MetaMask stack, via middleware for json-rpc-engine",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -18,19 +18,12 @@
18
18
  "files": [
19
19
  "dist/"
20
20
  ],
21
+ "type": "module",
21
22
  "sideEffects": false,
22
- "main": "./dist/index.cjs",
23
- "types": "./dist/index.d.cts",
24
23
  "exports": {
25
24
  ".": {
26
- "import": {
27
- "types": "./dist/index.d.mts",
28
- "default": "./dist/index.mjs"
29
- },
30
- "require": {
31
- "types": "./dist/index.d.cts",
32
- "default": "./dist/index.cjs"
33
- }
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
34
27
  },
35
28
  "./package.json": "./package.json"
36
29
  },
@@ -39,45 +32,47 @@
39
32
  "registry": "https://registry.npmjs.org/"
40
33
  },
41
34
  "scripts": {
42
- "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
43
- "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
35
+ "build": "tsc --project tsconfig.build.json",
36
+ "build:all": "tsc --build tsconfig.build.json --verbose",
37
+ "build:clean": "yarn build:only-clean && yarn build",
44
38
  "build:docs": "typedoc",
39
+ "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
45
40
  "changelog:update": "../../scripts/update-changelog.sh @metamask/permission-controller",
46
41
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/permission-controller",
47
- "messenger-action-types:check": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --check",
48
- "messenger-action-types:generate": "tsx ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --generate",
42
+ "lint:tsconfigs": "node --import ../../scripts/resolver/register.ts ../../scripts/lint-tsconfigs/lint-tsconfigs.ts",
43
+ "lint:tsconfigs:fix": "node --import ../../scripts/resolver/register.ts ../../scripts/lint-tsconfigs/lint-tsconfigs.ts --fix",
44
+ "messenger-action-types:check": "node --import ../../scripts/resolver/register.ts ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --check",
45
+ "messenger-action-types:generate": "node --import ../../scripts/resolver/register.ts ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --generate",
49
46
  "since-latest-release": "../../scripts/since-latest-release.sh",
50
- "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
51
- "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
52
- "test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
53
- "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
47
+ "test": "vitest",
48
+ "test:clean": "vitest --clearCache",
49
+ "test:verbose": "vitest --reporter=verbose",
50
+ "test:watch": "vitest --watch"
54
51
  },
55
52
  "dependencies": {
56
- "@metamask/approval-controller": "^9.0.1",
57
- "@metamask/base-controller": "^9.1.0",
58
- "@metamask/controller-utils": "^12.0.0",
59
- "@metamask/json-rpc-engine": "^10.5.0",
60
- "@metamask/messenger": "^1.2.0",
61
- "@metamask/rpc-errors": "^7.0.2",
62
- "@metamask/utils": "^11.9.0",
53
+ "@metamask/approval-controller": "^10.0.0",
54
+ "@metamask/base-controller": "^10.1.0",
55
+ "@metamask/controller-utils": "^13.0.0",
56
+ "@metamask/json-rpc-engine": "^11.0.0",
57
+ "@metamask/messenger": "^3.0.0",
58
+ "@metamask/rpc-errors": "^7.0.3",
59
+ "@metamask/utils": "^12.0.1",
63
60
  "@types/deep-freeze-strict": "^1.1.0",
64
61
  "deep-freeze-strict": "^1.1.1",
65
- "immer": "^9.0.6",
66
- "nanoid": "^3.3.8"
62
+ "fast-deep-equal": "^3.1.3",
63
+ "immer": "^11.1.18",
64
+ "nanoid": "^3.3.19"
67
65
  },
68
66
  "devDependencies": {
69
- "@metamask/auto-changelog": "^6.1.0",
70
- "@ts-bridge/cli": "^0.6.4",
71
- "@types/jest": "^29.5.14",
72
- "deepmerge": "^4.2.2",
73
- "jest": "^29.7.0",
74
- "ts-jest": "^29.2.5",
75
- "tsx": "^4.20.5",
76
- "typedoc": "^0.25.13",
77
- "typedoc-plugin-missing-exports": "^2.0.0",
78
- "typescript": "~5.3.3"
67
+ "@metamask/auto-changelog": "^6.2.1",
68
+ "@typescript/native": "npm:typescript@^7.0.2",
69
+ "rimraf": "^6.1.3",
70
+ "typedoc": "^0.28.20",
71
+ "typedoc-plugin-missing-exports": "^4.1.4",
72
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
73
+ "vitest": "^5.0.0"
79
74
  },
80
75
  "engines": {
81
- "node": "^18.18 || >=20"
76
+ "node": "^22.14.0 || ^24 || ^26"
82
77
  }
83
78
  }
package/dist/Caveat.cjs DELETED
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decorateWithCaveats = exports.isRestrictedMethodCaveatSpecification = void 0;
4
- const utils_1 = require("@metamask/utils");
5
- const errors_1 = require("./errors.cjs");
6
- const Permission_1 = require("./Permission.cjs");
7
- /**
8
- * Determines whether a caveat specification is a restricted method caveat specification.
9
- *
10
- * @param specification - The caveat specification.
11
- * @returns True if the caveat specification is a restricted method caveat specification, otherwise false.
12
- */
13
- function isRestrictedMethodCaveatSpecification(specification) {
14
- return (0, utils_1.hasProperty)(specification, 'decorator');
15
- }
16
- exports.isRestrictedMethodCaveatSpecification = isRestrictedMethodCaveatSpecification;
17
- /**
18
- * Decorate a restricted method implementation with its caveats.
19
- *
20
- * Note that all caveat functions (i.e. the argument and return value of the
21
- * decorator) must be awaited.
22
- *
23
- * @param methodImplementation - The restricted method implementation
24
- * @param permission - The origin's potential permission
25
- * @param caveatSpecifications - All caveat implementations
26
- * @returns The decorated method implementation
27
- */
28
- function decorateWithCaveats(methodImplementation, permission, // bound to the requesting origin
29
- caveatSpecifications) {
30
- const { caveats } = permission;
31
- if (!caveats) {
32
- return methodImplementation;
33
- }
34
- let decorated = async (args) => methodImplementation(args);
35
- for (const caveat of caveats) {
36
- const specification = caveatSpecifications[caveat.type];
37
- if (!specification) {
38
- throw new errors_1.UnrecognizedCaveatTypeError(caveat.type);
39
- }
40
- if (!isRestrictedMethodCaveatSpecification(specification)) {
41
- throw new errors_1.CaveatSpecificationMismatchError(specification, Permission_1.PermissionType.RestrictedMethod);
42
- }
43
- decorated = specification.decorator(decorated, caveat);
44
- }
45
- return decorated;
46
- }
47
- exports.decorateWithCaveats = decorateWithCaveats;
48
- //# sourceMappingURL=Caveat.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Caveat.cjs","sourceRoot":"","sources":["../src/Caveat.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAE9C,yCAGkB;AAOlB,iDAA8C;AA+Q9C;;;;;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,CAAC;QACb,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAED,IAAI,SAAS,GAAG,KAAK,EACnB,IAAuE,EACxD,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;IAE/C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,aAAa,GACjB,oBAAoB,CAAC,MAAM,CAAC,IAAoC,CAAC,CAAC;QACpE,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,oCAA2B,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC;QAED,IAAI,CAAC,qCAAqC,CAAC,aAAa,CAAC,EAAE,CAAC;YAC1D,MAAM,IAAI,yCAAgC,CACxC,aAAa,EACb,2BAAc,CAAC,gBAAgB,CAChC,CAAC;QACJ,CAAC;QACD,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;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 /**\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 /**\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 */\ntype ExtractCaveatValueFromDecorator<\n Decorator extends CaveatDecorator<CaveatConstraint>,\n> = Decorator extends (\n decorated: AsyncRestrictedMethod<RestrictedMethodParameters, Json>,\n caveat: infer ParentCaveat,\n) => AsyncRestrictedMethod<RestrictedMethodParameters, Json>\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 * @see `validator` in {@link CaveatSpecificationBase} for more details.\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\n/**\n * A map of caveat type strings to {@link CaveatDiff} values.\n */\nexport type CaveatDiffMap<ParentCaveat extends CaveatConstraint> = {\n [CaveatType in ParentCaveat['type']]: ParentCaveat['value'];\n};\n\n/**\n * A function that merges two caveat values of the same type. The values must be\n * merged in the fashion of a right-biased union.\n *\n * @see `ARCHITECTURE.md` for more details.\n * @template Value - The type of the values to merge.\n * @param leftValue - The left-hand value.\n * @param rightValue - The right-hand value.\n * @returns `[newValue, diff]`, i.e. the merged value and the diff between the left value\n * and the new value. The diff must be expressed in the same type as the value itself.\n */\nexport type CaveatValueMerger<Value extends Json> = (\n leftValue: Value,\n rightValue: Value,\n) => [Value, Value] | [];\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 constructed 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. In instances where caveats are mutated but a permission's caveat\n * array has not changed, any corresponding permission validator will not be\n * called. For this reason, permission validators **must not** be relied upon\n * to validate caveats.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n validator?: CaveatValidator<any>;\n\n /**\n * The merger function used to merge a pair of values of the associated caveat type\n * during incremental permission requests. The values must be merged in the fashion\n * of a right-biased union.\n *\n * @see `ARCHITECTURE.md` for more details.\n */\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n merger?: CaveatValueMerger<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 decorator: CaveatDecorator<CaveatConstraint>;\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 Options extends CaveatSpecificationBuilderOptions<\n Record<string, unknown>,\n Record<string, unknown>\n >,\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 CaveatSpecificationBuilderOptions<\n Record<string, unknown>,\n Record<string, unknown>\n >,\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> = CaveatSpecification extends RestrictedMethodCaveatSpecificationConstraint\n ? Caveat<\n CaveatSpecification['type'],\n ExtractCaveatValueFromDecorator<\n RestrictedMethodCaveatSpecificationConstraint['decorator']\n >\n >\n : Caveat<CaveatSpecification['type'], Json>;\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 ): Promise<Json> => 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"]}