@metamask-previews/approval-controller 8.0.0-preview-6cb7e4bcf → 8.0.0-preview-25d2d4502

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 CHANGED
@@ -7,24 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Added
11
-
12
- - New `addRequest()` public method ([#8183](https://github.com/MetaMask/core/pull/8183))
13
- - Expose missing public `ApprovalController` methods through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183))
14
- - The following actions are now available:
15
- - `ApprovalController:add`
16
- - `ApprovalController:addAndShowApprovalRequest`
17
- - `ApprovalController:get`
18
- - `ApprovalController:getApprovalCount`
19
- - `ApprovalController:getTotalApprovalCount`
20
- - Corresponding action types (e.g. `ApprovalControllerAddAction`) are available as well.
21
-
22
10
  ### Changed
23
11
 
24
- - **BREAKING:** Standardize names of `ApprovalController` methods ([#8183](https://github.com/MetaMask/core/pull/8183))
25
- - All existing methods for handling requests have been renamed so they include `Request` (e.g. `clear()` -> `clearRequest()`). You will need to update usage appropriately.
26
- - The error handling method `error()` has been renamed to include `show` (`error()` -> `showError()`). You will need to update usage appropriately.
27
- - **BREAKING:** Rename get-state action type: `GetApprovalsState` → `ApprovalControllerGetStateAction` ([#8183](https://github.com/MetaMask/core/pull/8183))
28
12
  - Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511))
29
13
 
30
14
  ## [8.0.0]
@@ -51,25 +51,6 @@ const getDefaultState = () => {
51
51
  approvalFlows: [],
52
52
  };
53
53
  };
54
- // === MESSENGER ===
55
- const MESSENGER_EXPOSED_METHODS = [
56
- 'acceptRequest',
57
- 'add',
58
- 'addAndShowApprovalRequest',
59
- 'addRequest',
60
- 'clearRequests',
61
- 'endFlow',
62
- 'get',
63
- 'getApprovalCount',
64
- 'getTotalApprovalCount',
65
- 'hasRequest',
66
- 'rejectRequest',
67
- 'setFlowLoadingText',
68
- 'showError',
69
- 'showSuccess',
70
- 'startFlow',
71
- 'updateRequestState',
72
- ];
73
54
  /**
74
55
  * Controller for managing requests that require user approval.
75
56
  *
@@ -108,29 +89,29 @@ class ApprovalController extends base_controller_1.BaseController {
108
89
  // eslint-disable-next-line @typescript-eslint/no-misused-promises
109
90
  __classPrivateFieldSet(this, _ApprovalController_showApprovalRequest, showApprovalRequest, "f");
110
91
  __classPrivateFieldSet(this, _ApprovalController_typesExcludedFromRateLimiting, typesExcludedFromRateLimiting, "f");
111
- this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
92
+ this.registerMessageHandlers();
112
93
  }
113
94
  /**
114
- * Adds an approval request per the given arguments, optionally showing
115
- * the approval request to the user.
116
- *
117
- * @param opts - Options bag.
118
- * @param opts.id - The id of the approval request. A random id will be
119
- * generated if none is provided.
120
- * @param opts.origin - The origin of the approval request.
121
- * @param opts.type - The type associated with the approval request.
122
- * @param opts.requestData - Additional data associated with the request,
123
- * if any.
124
- * @param opts.requestState - Additional state associated with the request,
125
- * if any.
126
- * @param shouldShowRequest - Whether to show the approval request to the user.
127
- * @returns The approval promise.
95
+ * Constructor helper for registering this controller's messaging system
96
+ * actions.
128
97
  */
129
- addRequest(opts, shouldShowRequest) {
130
- if (shouldShowRequest) {
131
- return this.addAndShowApprovalRequest(opts);
132
- }
133
- return this.add(opts);
98
+ registerMessageHandlers() {
99
+ this.messenger.registerActionHandler(`${controllerName}:clearRequests`, this.clear.bind(this));
100
+ this.messenger.registerActionHandler(`${controllerName}:addRequest`, (opts, shouldShowRequest) => {
101
+ if (shouldShowRequest) {
102
+ return this.addAndShowApprovalRequest(opts);
103
+ }
104
+ return this.add(opts);
105
+ });
106
+ this.messenger.registerActionHandler(`${controllerName}:hasRequest`, this.has.bind(this));
107
+ this.messenger.registerActionHandler(`${controllerName}:acceptRequest`, this.accept.bind(this));
108
+ this.messenger.registerActionHandler(`${controllerName}:rejectRequest`, this.reject.bind(this));
109
+ this.messenger.registerActionHandler(`${controllerName}:updateRequestState`, this.updateRequestState.bind(this));
110
+ this.messenger.registerActionHandler(`${controllerName}:startFlow`, this.startFlow.bind(this));
111
+ this.messenger.registerActionHandler(`${controllerName}:endFlow`, this.endFlow.bind(this));
112
+ this.messenger.registerActionHandler(`${controllerName}:setFlowLoadingText`, this.setFlowLoadingText.bind(this));
113
+ this.messenger.registerActionHandler(`${controllerName}:showSuccess`, this.success.bind(this));
114
+ this.messenger.registerActionHandler(`${controllerName}:showError`, this.error.bind(this));
134
115
  }
135
116
  addAndShowApprovalRequest(opts) {
136
117
  const promise = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_add).call(this, opts.origin, opts.type, opts.id, opts.requestData, opts.requestState, opts.expectsResult);
@@ -207,7 +188,7 @@ class ApprovalController extends base_controller_1.BaseController {
207
188
  * @param opts.type - The type to check for.
208
189
  * @returns `true` if a matching approval is found, and `false` otherwise.
209
190
  */
210
- hasRequest(opts = {}) {
191
+ has(opts = {}) {
211
192
  const { id, origin, type: _type } = opts;
212
193
  if (id) {
213
194
  if (typeof id !== 'string') {
@@ -249,7 +230,7 @@ class ApprovalController extends base_controller_1.BaseController {
249
230
  * the creator of the approval request, or immediately if `options.waitForResult`
250
231
  * is `false` or `undefined`.
251
232
  */
252
- acceptRequest(id, value, options) {
233
+ accept(id, value, options) {
253
234
  // Safe to cast as the delete method below will throw if the ID is not found
254
235
  const approval = this.get(id);
255
236
  const requestPromise = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_getCallbacks).call(this, id);
@@ -288,7 +269,7 @@ class ApprovalController extends base_controller_1.BaseController {
288
269
  * @param id - The id of the approval request.
289
270
  * @param error - The error to reject the approval promise with.
290
271
  */
291
- rejectRequest(id, error) {
272
+ reject(id, error) {
292
273
  const callbacks = __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_getCallbacks).call(this, id);
293
274
  __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_delete).call(this, id);
294
275
  callbacks.reject(error);
@@ -299,9 +280,9 @@ class ApprovalController extends base_controller_1.BaseController {
299
280
  * @param rejectionError - The JsonRpcError to reject the approval
300
281
  * requests with.
301
282
  */
302
- clearRequests(rejectionError) {
283
+ clear(rejectionError) {
303
284
  for (const id of __classPrivateFieldGet(this, _ApprovalController_approvals, "f").keys()) {
304
- this.rejectRequest(id, rejectionError);
285
+ this.reject(id, rejectionError);
305
286
  }
306
287
  __classPrivateFieldGet(this, _ApprovalController_origins, "f").clear();
307
288
  this.update((draftState) => {
@@ -391,7 +372,7 @@ class ApprovalController extends base_controller_1.BaseController {
391
372
  * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.
392
373
  * @returns Empty object to support future additions.
393
374
  */
394
- async showSuccess(opts = {}) {
375
+ async success(opts = {}) {
395
376
  await __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_result).call(this, exports.APPROVAL_TYPE_RESULT_SUCCESS, opts, {
396
377
  message: opts.message,
397
378
  header: opts.header,
@@ -411,7 +392,7 @@ class ApprovalController extends base_controller_1.BaseController {
411
392
  * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.
412
393
  * @returns Empty object to support future additions.
413
394
  */
414
- async showError(opts = {}) {
395
+ async error(opts = {}) {
415
396
  await __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_result).call(this, exports.APPROVAL_TYPE_RESULT_ERROR, opts, {
416
397
  error: opts.error,
417
398
  header: opts.header,
@@ -425,7 +406,7 @@ exports.ApprovalController = ApprovalController;
425
406
  _ApprovalController_approvals = new WeakMap(), _ApprovalController_origins = new WeakMap(), _ApprovalController_showApprovalRequest = new WeakMap(), _ApprovalController_typesExcludedFromRateLimiting = new WeakMap(), _ApprovalController_instances = new WeakSet(), _ApprovalController_add = function _ApprovalController_add(origin, type, id = (0, nanoid_1.nanoid)(), requestData, requestState, expectsResult) {
426
407
  __classPrivateFieldGet(this, _ApprovalController_instances, "m", _ApprovalController_validateAddParams).call(this, id, origin, type, requestData, requestState);
427
408
  if (!__classPrivateFieldGet(this, _ApprovalController_typesExcludedFromRateLimiting, "f").includes(type) &&
428
- this.hasRequest({ origin, type })) {
409
+ this.has({ origin, type })) {
429
410
  throw rpc_errors_1.rpcErrors.resourceUnavailable(getAlreadyPendingMessage(origin, type));
430
411
  }
431
412
  // add pending approval
@@ -1 +1 @@
1
- {"version":3,"file":"ApprovalController.cjs","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAA2D;AAQ3D,qDAAiD;AAEjD,mCAAgC;AAGhC,yCAMkB;AAElB,YAAY;AAEZ,0CAA0C;AAC7B,QAAA,eAAe,GAAG,UAAU,CAAC;AAC7B,QAAA,0BAA0B,GAAG,cAAc,CAAC;AAC5C,QAAA,4BAA4B,GAAG,gBAAgB,CAAC;AAE7D,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAE5C,MAAM,aAAa,GAA2C;IAC5D,gBAAgB,EAAE;QAChB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,oBAAoB,EAAE;QACpB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,aAAa,EAAE;QACb,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAM,wBAAwB,GAAG,CAAC,MAAc,EAAE,IAAY,EAAE,EAAE,CAChE,oBAAoB,IAAI,gCAAgC,MAAM,gBAAgB,CAAC;AAEjF,MAAM,eAAe,GAAG,GAA4B,EAAE;IACpD,OAAO;QACL,gBAAgB,EAAE,EAAE;QACp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IAAI,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC;YAAS,CAAC;QACT,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,IAAI,CAAC;gBACH,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;YACvC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;YACpE,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAGH,kBAAe,kBAAkB,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n StateMetadata,\n} from '@metamask/base-controller';\nimport type { ControllerStateChangeEvent } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { JsonRpcError, DataWithOptionalCause } from '@metamask/rpc-errors';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json, OptionalField } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport type { ApprovalControllerMethodActions } from './ApprovalController-method-action-types';\nimport {\n ApprovalRequestNotFoundError,\n ApprovalRequestNoResultSupportError,\n EndInvalidFlowError,\n NoApprovalFlowsError,\n MissingApprovalFlowError,\n} from './errors';\n\n// Constants\n\n// Avoiding dependency on controller-utils\nexport const ORIGIN_METAMASK = 'metamask';\nexport const APPROVAL_TYPE_RESULT_ERROR = 'result_error';\nexport const APPROVAL_TYPE_RESULT_SUCCESS = 'result_success';\n\nconst controllerName = 'ApprovalController';\n\nconst stateMetadata: StateMetadata<ApprovalControllerState> = {\n pendingApprovals: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n pendingApprovalCount: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n approvalFlows: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getAlreadyPendingMessage = (origin: string, type: string) =>\n `Request of type '${type}' already pending for origin ${origin}. Please wait.`;\n\nconst getDefaultState = (): ApprovalControllerState => {\n return {\n pendingApprovals: {},\n pendingApprovalCount: 0,\n approvalFlows: [],\n };\n};\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'acceptRequest',\n 'add',\n 'addAndShowApprovalRequest',\n 'addRequest',\n 'clearRequests',\n 'endFlow',\n 'get',\n 'getApprovalCount',\n 'getTotalApprovalCount',\n 'hasRequest',\n 'rejectRequest',\n 'setFlowLoadingText',\n 'showError',\n 'showSuccess',\n 'startFlow',\n 'updateRequestState',\n] as const;\n\n// Internal Types\n\ntype ApprovalPromiseResolve = (value?: unknown | AddResult) => void;\n\ntype ApprovalPromiseReject = (error?: unknown) => void;\n\ntype ApprovalRequestData = Record<string, Json> | null;\n\ntype ApprovalRequestState = Record<string, Json> | null;\n\ntype ApprovalCallbacks = {\n resolve: ApprovalPromiseResolve;\n reject: ApprovalPromiseReject;\n};\n\ntype ApprovalFlow = {\n id: string;\n loadingText: string | null;\n};\n\ntype ResultOptions = {\n flowToEnd?: string;\n header?: (string | ResultComponent)[];\n icon?: string | null;\n title?: string | null;\n};\n\n// Miscellaneous Types\n\nexport type ApprovalRequest<RequestData extends ApprovalRequestData> = {\n /**\n * The ID of the approval request.\n */\n id: string;\n\n /**\n * The origin of the approval request.\n */\n origin: string;\n\n /**\n * The time that the request was received, per Date.now().\n */\n time: number;\n\n /**\n * The type of the approval request.\n * Unfortunately, not all values will match the `ApprovalType` enum, so we are using `string` here.\n * TODO: Replace `string` with `ApprovalType` when all `type` values used by the clients can be encompassed by the `ApprovalType` enum.\n */\n type: string;\n\n /**\n * Additional data associated with the request.\n */\n requestData: RequestData;\n\n /**\n * Additional mutable state associated with the request\n */\n requestState: ApprovalRequestState;\n\n /**\n * Whether the request expects a result object to be returned instead of just the approval value.\n */\n expectsResult: boolean;\n};\n\nexport type ApprovalFlowState = ApprovalFlow;\n\nexport type ApprovalControllerState = {\n pendingApprovals: Record<string, ApprovalRequest<Record<string, Json>>>;\n pendingApprovalCount: number;\n approvalFlows: ApprovalFlowState[];\n};\n\nexport type ApprovalControllerMessenger = Messenger<\n typeof controllerName,\n ApprovalControllerActions,\n ApprovalControllerEvents\n>;\n\n// Option Types\n\nexport type ShowApprovalRequest = () => void | Promise<void>;\n\nexport type ResultComponent = {\n /**\n * A unique identifier for this instance of the component.\n */\n key: string;\n\n /**\n * The name of the component to render.\n */\n name: string;\n\n /**\n * Any properties required by the component.\n */\n properties?: Record<string, unknown>;\n\n /**\n * Any child components to render inside the component.\n */\n children?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ApprovalControllerOptions = {\n messenger: ApprovalControllerMessenger;\n showApprovalRequest: ShowApprovalRequest;\n state?: Partial<ApprovalControllerState>;\n typesExcludedFromRateLimiting?: string[];\n};\n\nexport type AddApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record<string, Json>;\n requestState?: Record<string, Json>;\n expectsResult?: boolean;\n};\n\nexport type UpdateRequestStateOptions = {\n id: string;\n requestState: Record<string, Json>;\n};\n\nexport type AcceptOptions = {\n /**\n * Whether to resolve the returned promise only when the request creator indicates the success of the\n * post-approval logic using the result callbacks.\n * If false or unspecified, the promise will resolve immediately.\n */\n waitForResult?: boolean;\n\n /**\n * Whether to delete the approval request after a result callback is called.\n * If false or unspecified, the approval request will be deleted immediately.\n * Ignored if `waitForResult` is false or unspecified.\n */\n deleteAfterResult?: boolean;\n};\n\nexport type StartFlowOptions = OptionalField<\n ApprovalFlow,\n 'id' | 'loadingText'\n> & { show?: boolean };\n\nexport type EndFlowOptions = Pick<ApprovalFlow, 'id'>;\n\nexport type SetFlowLoadingTextOptions = ApprovalFlow;\n\nexport type SuccessOptions = ResultOptions & {\n message?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ErrorOptions = ResultOptions & {\n error?: string | ResultComponent | (string | ResultComponent)[];\n};\n\n// Result Types\n\nexport type AcceptResultCallbacks = {\n /**\n * Inform the request acceptor that the post-approval logic was successful.\n *\n * @param value - An optional value generated by the post-approval logic.\n */\n success: (value?: unknown) => void;\n\n /**\n * Inform the request acceptor that the post-approval logic failed.\n *\n * @param error - The reason for the failure.\n */\n error: (error: Error) => void;\n};\n\nexport type AddResult = {\n /**\n * An optional value provided by the request acceptor.\n */\n value?: unknown;\n\n /**\n * Callback functions that must be used to indicate to the request acceptor whether the post-approval logic was successful or not.\n * Will be undefined if the request acceptor did not specify that they want to wait for a result.\n */\n resultCallbacks?: AcceptResultCallbacks;\n};\n\nexport type AcceptResult = {\n /**\n * An optional value provided by the request creator when indicating a successful result.\n */\n value?: unknown;\n};\n\nexport type ApprovalFlowStartResult = ApprovalFlow;\n\nexport type SuccessResult = Record<string, never>;\n\nexport type ErrorResult = Record<string, never>;\n\n// Event Types\n\nexport type ApprovalStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n ApprovalControllerState\n>;\n\nexport type ApprovalControllerEvents = ApprovalStateChange;\n\n// Action Types\n\nexport type ApprovalControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ApprovalControllerState\n>;\n\nexport type ApprovalControllerActions =\n | ApprovalControllerGetStateAction\n | ApprovalControllerMethodActions;\n\n/**\n * Controller for managing requests that require user approval.\n *\n * Enables limiting the number of pending requests by origin and type, counting\n * pending requests, and more.\n *\n * Adding a request returns a promise that resolves or rejects when the request\n * is approved or denied, respectively.\n */\nexport class ApprovalController extends BaseController<\n typeof controllerName,\n ApprovalControllerState,\n ApprovalControllerMessenger\n> {\n readonly #approvals: Map<string, ApprovalCallbacks>;\n\n readonly #origins: Map<string, Map<string, number>>;\n\n readonly #showApprovalRequest: () => void;\n\n readonly #typesExcludedFromRateLimiting: string[];\n\n /**\n * Construct an Approval controller.\n *\n * @param options - The controller options.\n * @param options.showApprovalRequest - Function for opening the UI such that\n * the request can be displayed to the user.\n * @param options.messenger - The restricted messenger for the Approval controller.\n * @param options.state - The initial controller state.\n * @param options.typesExcludedFromRateLimiting - Array of approval types which allow multiple pending approval requests from the same origin.\n */\n constructor({\n messenger,\n showApprovalRequest,\n state = {},\n typesExcludedFromRateLimiting = [],\n }: ApprovalControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#approvals = new Map();\n this.#origins = new Map();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#showApprovalRequest = showApprovalRequest;\n this.#typesExcludedFromRateLimiting = typesExcludedFromRateLimiting;\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Adds an approval request per the given arguments, optionally showing\n * the approval request to the user.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @param shouldShowRequest - Whether to show the approval request to the user.\n * @returns The approval promise.\n */\n addRequest(\n opts: AddApprovalOptions,\n shouldShowRequest: boolean,\n ): Promise<unknown> {\n if (shouldShowRequest) {\n return this.addAndShowApprovalRequest(opts);\n }\n return this.add(opts);\n }\n\n /**\n * Adds an approval request per the given arguments, calls the show approval\n * request function, and returns the associated approval promise resolving to\n * an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\n addAndShowApprovalRequest(\n opts: AddApprovalOptions & { expectsResult: true },\n ): Promise<AddResult>;\n\n /**\n * Adds an approval request per the given arguments, calls the show approval\n * request function, and returns the associated approval promise resolving\n * to a value provided during acceptance.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @returns The approval promise resolving to a value provided during acceptance.\n */\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise<unknown>;\n\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise<unknown> {\n const promise = this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n this.#showApprovalRequest();\n return promise;\n }\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\n add(opts: AddApprovalOptions & { expectsResult: true }): Promise<AddResult>;\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to a value provided during acceptance.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @returns The approval promise resolving to a value provided during acceptance.\n */\n add(opts: AddApprovalOptions): Promise<unknown>;\n\n add(opts: AddApprovalOptions): Promise<unknown | AddResult> {\n return this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n }\n\n /**\n * Gets the info for the approval request with the given id.\n *\n * @param id - The id of the approval request.\n * @returns The approval request data associated with the id.\n */\n get(id: string): ApprovalRequest<ApprovalRequestData> | undefined {\n return this.state.pendingApprovals[id];\n }\n\n /**\n * Gets the number of pending approvals, by origin and/or type.\n *\n * If only `origin` is specified, all approvals for that origin will be\n * counted, regardless of type.\n * If only `type` is specified, all approvals for that type will be counted,\n * regardless of origin.\n * If both `origin` and `type` are specified, 0 or 1 will be returned.\n *\n * @param opts - The approval count options.\n * @param opts.origin - An approval origin.\n * @param opts.type - The type of the approval request.\n * @returns The current approval request count for the given origin and/or\n * type.\n */\n getApprovalCount(opts: { origin?: string; type?: string } = {}): number {\n if (!opts.origin && !opts.type) {\n throw new Error('Must specify origin, type, or both.');\n }\n const { origin, type: _type } = opts;\n\n if (origin && _type) {\n return this.#origins.get(origin)?.get(_type) || 0;\n }\n\n if (origin) {\n return Array.from(\n (this.#origins.get(origin) || new Map()).values(),\n ).reduce((total, value) => total + value, 0);\n }\n\n // Only \"type\" was specified\n let count = 0;\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n count += 1;\n }\n }\n return count;\n }\n\n /**\n * Get the total count of all pending approval requests for all origins.\n *\n * @returns The total pending approval request count.\n */\n getTotalApprovalCount(): number {\n return this.state.pendingApprovalCount;\n }\n\n /**\n * Checks if there's a pending approval request per the given parameters.\n * At least one parameter must be specified. An error will be thrown if the\n * parameters are invalid.\n *\n * If `id` is specified, all other parameters will be ignored.\n * If `id` is not specified, the method will check for requests that match\n * all of the specified parameters.\n *\n * @param opts - Options bag.\n * @param opts.id - The ID to check for.\n * @param opts.origin - The origin to check for.\n * @param opts.type - The type to check for.\n * @returns `true` if a matching approval is found, and `false` otherwise.\n */\n hasRequest(\n opts: { id?: string; origin?: string; type?: string } = {},\n ): boolean {\n const { id, origin, type: _type } = opts;\n\n if (id) {\n if (typeof id !== 'string') {\n throw new Error('May not specify non-string id.');\n }\n return this.#approvals.has(id);\n }\n\n if (_type && typeof _type !== 'string') {\n throw new Error('May not specify non-string type.');\n }\n\n if (origin) {\n if (typeof origin !== 'string') {\n throw new Error('May not specify non-string origin.');\n }\n\n // Check origin and type pair if type also specified\n if (_type) {\n return Boolean(this.#origins.get(origin)?.get(_type));\n }\n return this.#origins.has(origin);\n }\n\n if (_type) {\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n return true;\n }\n }\n return false;\n }\n throw new Error(\n 'Must specify a valid combination of id, origin, and type.',\n );\n }\n\n /**\n * Resolves the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param value - The value to resolve the approval promise with.\n * @param options - Options bag.\n * @returns A promise that either resolves once a result is provided by\n * the creator of the approval request, or immediately if `options.waitForResult`\n * is `false` or `undefined`.\n */\n acceptRequest(\n id: string,\n value?: unknown,\n options?: AcceptOptions,\n ): Promise<AcceptResult> {\n // Safe to cast as the delete method below will throw if the ID is not found\n const approval = this.get(id) as ApprovalRequest<ApprovalRequestData>;\n const requestPromise = this.#getCallbacks(id);\n let requestDeleted = false;\n\n if (!options?.deleteAfterResult || !options.waitForResult) {\n this.#delete(id);\n requestDeleted = true;\n }\n\n return new Promise<AcceptResult>((resolve, reject) => {\n const resultCallbacks: AcceptResultCallbacks = {\n success: (acceptValue?: unknown) => resolve({ value: acceptValue }),\n error: reject,\n };\n\n if (options?.waitForResult && !approval.expectsResult) {\n reject(new ApprovalRequestNoResultSupportError(id));\n return;\n }\n\n const resultValue = options?.waitForResult ? resultCallbacks : undefined;\n\n const resolveValue = approval.expectsResult\n ? { value, resultCallbacks: resultValue }\n : value;\n\n requestPromise.resolve(resolveValue);\n\n if (!options?.waitForResult) {\n resolve({ value: undefined });\n }\n }).finally(() => {\n if (!requestDeleted) {\n this.#delete(id);\n }\n });\n }\n\n /**\n * Rejects the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param error - The error to reject the approval promise with.\n */\n rejectRequest(id: string, error: unknown): void {\n const callbacks = this.#getCallbacks(id);\n this.#delete(id);\n callbacks.reject(error);\n }\n\n /**\n * Rejects and deletes all approval requests.\n *\n * @param rejectionError - The JsonRpcError to reject the approval\n * requests with.\n */\n clearRequests(rejectionError: JsonRpcError<DataWithOptionalCause>): void {\n for (const id of this.#approvals.keys()) {\n this.rejectRequest(id, rejectionError);\n }\n this.#origins.clear();\n this.update((draftState) => {\n draftState.pendingApprovals = {};\n draftState.pendingApprovalCount = 0;\n });\n }\n\n /**\n * Updates the request state of the approval with the given id.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request.\n * @param opts.requestState - Additional data associated with the request\n */\n updateRequestState(opts: UpdateRequestStateOptions): void {\n if (!this.state.pendingApprovals[opts.id]) {\n throw new ApprovalRequestNotFoundError(opts.id);\n }\n\n this.update((draftState) => {\n draftState.pendingApprovals[opts.id].requestState =\n opts.requestState as never;\n });\n }\n\n /**\n * Starts a new approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n * @param opts.show - A flag to determine whether the approval should show to the user.\n * @returns The object containing the approval flow id.\n */\n startFlow(opts: StartFlowOptions = {}): ApprovalFlowStartResult {\n const id = opts.id ?? nanoid();\n const loadingText = opts.loadingText ?? null;\n\n this.update((draftState) => {\n draftState.approvalFlows.push({ id, loadingText });\n });\n\n // By default, if nothing else is specified, we always show the approval.\n if (opts.show !== false) {\n this.#showApprovalRequest();\n }\n\n return { id, loadingText };\n }\n\n /**\n * Ends the current approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow that will be finished.\n */\n endFlow({ id }: EndFlowOptions) {\n if (!this.state.approvalFlows.length) {\n throw new NoApprovalFlowsError();\n }\n\n const currentFlow = this.state.approvalFlows.slice(-1)[0];\n\n if (id !== currentFlow.id) {\n throw new EndInvalidFlowError(\n id,\n this.state.approvalFlows.map((flow) => flow.id),\n );\n }\n\n this.update((draftState) => {\n draftState.approvalFlows.pop();\n });\n }\n\n /**\n * Sets the loading text for the approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The approval flow loading text that will be displayed.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n */\n setFlowLoadingText({ id, loadingText }: SetFlowLoadingTextOptions) {\n const flowIndex = this.state.approvalFlows.findIndex(\n (flow) => flow.id === id,\n );\n\n if (flowIndex === -1) {\n throw new MissingApprovalFlowError(id);\n }\n\n this.update((draftState) => {\n draftState.approvalFlows[flowIndex].loadingText = loadingText;\n });\n }\n\n /**\n * Show a success page.\n *\n * @param opts - Options bag.\n * @param opts.message - The message text or components to display in the page.\n * @param opts.header - The text or components to display in the header of the page.\n * @param opts.flowToEnd - The ID of the approval flow to end once the success page is approved.\n * @param opts.title - The title to display above the message. Shown by default but can be hidden with `null`.\n * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.\n * @returns Empty object to support future additions.\n */\n async showSuccess(opts: SuccessOptions = {}): Promise<SuccessResult> {\n await this.#result(APPROVAL_TYPE_RESULT_SUCCESS, opts, {\n message: opts.message,\n header: opts.header,\n title: opts.title,\n icon: opts.icon,\n } as Record<string, Json>);\n\n return {};\n }\n\n /**\n * Show an error page.\n *\n * @param opts - Options bag.\n * @param opts.message - The message text or components to display in the page.\n * @param opts.header - The text or components to display in the header of the page.\n * @param opts.flowToEnd - The ID of the approval flow to end once the error page is approved.\n * @param opts.title - The title to display above the message. Shown by default but can be hidden with `null`.\n * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.\n * @returns Empty object to support future additions.\n */\n async showError(opts: ErrorOptions = {}): Promise<ErrorResult> {\n await this.#result(APPROVAL_TYPE_RESULT_ERROR, opts, {\n error: opts.error,\n header: opts.header,\n title: opts.title,\n icon: opts.icon,\n } as Record<string, Json>);\n\n return {};\n }\n\n /**\n * Implementation of add operation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param id - The id of the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the approval request expects a result object to be returned.\n * @returns The approval promise.\n */\n #add(\n origin: string,\n type: string,\n id: string = nanoid(),\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n expectsResult?: boolean,\n ): Promise<unknown | AddResult> {\n this.#validateAddParams(id, origin, type, requestData, requestState);\n\n if (\n !this.#typesExcludedFromRateLimiting.includes(type) &&\n this.hasRequest({ origin, type })\n ) {\n throw rpcErrors.resourceUnavailable(\n getAlreadyPendingMessage(origin, type),\n );\n }\n\n // add pending approval\n return new Promise((resolve, reject) => {\n this.#approvals.set(id, { resolve, reject });\n this.#addPendingApprovalOrigin(origin, type);\n\n this.#addToStore(\n id,\n origin,\n type,\n requestData,\n requestState,\n expectsResult,\n );\n });\n }\n\n /**\n * Validates parameters to the add method.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n */\n #validateAddParams(\n id: string,\n origin: string,\n type: string,\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n ): void {\n let errorMessage = null;\n if (!id || typeof id !== 'string') {\n errorMessage = 'Must specify non-empty string id.';\n } else if (this.#approvals.has(id)) {\n errorMessage = `Approval request with id '${id}' already exists.`;\n } else if (!origin || typeof origin !== 'string') {\n errorMessage = 'Must specify non-empty string origin.';\n } else if (!type || typeof type !== 'string') {\n errorMessage = 'Must specify non-empty string type.';\n } else if (\n requestData &&\n (typeof requestData !== 'object' || Array.isArray(requestData))\n ) {\n errorMessage = 'Request data must be a plain object if specified.';\n } else if (\n requestState &&\n (typeof requestState !== 'object' || Array.isArray(requestState))\n ) {\n errorMessage = 'Request state must be a plain object if specified.';\n }\n\n if (errorMessage) {\n throw rpcErrors.internal(errorMessage);\n }\n }\n\n /**\n * Adds an entry to _origins.\n * Performs no validation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n */\n #addPendingApprovalOrigin(origin: string, type: string): void {\n let originMap = this.#origins.get(origin);\n\n if (!originMap) {\n originMap = new Map();\n this.#origins.set(origin, originMap);\n }\n\n const currentValue = originMap.get(type) || 0;\n originMap.set(type, currentValue + 1);\n }\n\n /**\n * Adds an entry to the store.\n * Performs no validation.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the request expects a result object to be returned.\n */\n #addToStore(\n id: string,\n origin: string,\n type: string,\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n expectsResult?: boolean,\n ): void {\n const approval = {\n id,\n origin,\n type,\n time: Date.now(),\n requestData: requestData || null,\n requestState: requestState || null,\n expectsResult: expectsResult || false,\n };\n\n this.update((draftState) => {\n draftState.pendingApprovals[id] = approval as never;\n\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Deletes the approval with the given id.\n *\n * Deletion is an internal operation because approval state is solely\n * managed by this controller.\n *\n * @param id - The id of the approval request to be deleted.\n */\n #delete(id: string): void {\n if (!this.#approvals.has(id)) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n this.#approvals.delete(id);\n\n const { origin, type } = this.state.pendingApprovals[id];\n\n const originMap = this.#origins.get(origin) as Map<string, number>;\n const originTotalCount = this.getApprovalCount({ origin });\n const originTypeCount = originMap.get(type) as number;\n\n if (originTotalCount === 1) {\n this.#origins.delete(origin);\n } else {\n originMap.set(type, originTypeCount - 1);\n }\n\n this.update((draftState) => {\n delete draftState.pendingApprovals[id];\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n #getCallbacks(id: string): ApprovalCallbacks {\n const callbacks = this.#approvals.get(id);\n\n if (!callbacks) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n return callbacks;\n }\n\n async #result(\n type: string,\n opts: ResultOptions,\n requestData: Record<string, Json>,\n ) {\n try {\n await this.addAndShowApprovalRequest({\n origin: ORIGIN_METAMASK,\n type,\n requestData,\n });\n } catch (error) {\n console.info('Failed to display result page', error);\n } finally {\n if (opts.flowToEnd) {\n try {\n this.endFlow({ id: opts.flowToEnd });\n } catch (error) {\n console.info('Failed to end flow', { id: opts.flowToEnd, error });\n }\n }\n }\n }\n}\n\nexport default ApprovalController;\n"]}
1
+ {"version":3,"file":"ApprovalController.cjs","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAA2D;AAQ3D,qDAAiD;AAEjD,mCAAgC;AAEhC,yCAMkB;AAElB,YAAY;AAEZ,0CAA0C;AAC7B,QAAA,eAAe,GAAG,UAAU,CAAC;AAC7B,QAAA,0BAA0B,GAAG,cAAc,CAAC;AAC5C,QAAA,4BAA4B,GAAG,gBAAgB,CAAC;AAE7D,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAE5C,MAAM,aAAa,GAA2C;IAC5D,gBAAgB,EAAE;QAChB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,oBAAoB,EAAE;QACpB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,aAAa,EAAE;QACb,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAM,wBAAwB,GAAG,CAAC,MAAc,EAAE,IAAY,EAAE,E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,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC;YAAS,CAAC;QACT,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,IAAI,CAAC;gBACH,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;YACvC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;YACpE,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAGH,kBAAe,kBAAkB,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n StateMetadata,\n} from '@metamask/base-controller';\nimport type { ControllerStateChangeEvent } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { JsonRpcError, DataWithOptionalCause } from '@metamask/rpc-errors';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json, OptionalField } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport {\n ApprovalRequestNotFoundError,\n ApprovalRequestNoResultSupportError,\n EndInvalidFlowError,\n NoApprovalFlowsError,\n MissingApprovalFlowError,\n} from './errors';\n\n// Constants\n\n// Avoiding dependency on controller-utils\nexport const ORIGIN_METAMASK = 'metamask';\nexport const APPROVAL_TYPE_RESULT_ERROR = 'result_error';\nexport const APPROVAL_TYPE_RESULT_SUCCESS = 'result_success';\n\nconst controllerName = 'ApprovalController';\n\nconst stateMetadata: StateMetadata<ApprovalControllerState> = {\n pendingApprovals: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n pendingApprovalCount: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n approvalFlows: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getAlreadyPendingMessage = (origin: string, type: string) =>\n `Request of type '${type}' already pending for origin ${origin}. Please wait.`;\n\nconst getDefaultState = (): ApprovalControllerState => {\n return {\n pendingApprovals: {},\n pendingApprovalCount: 0,\n approvalFlows: [],\n };\n};\n\n// Internal Types\n\ntype ApprovalPromiseResolve = (value?: unknown | AddResult) => void;\n\ntype ApprovalPromiseReject = (error?: unknown) => void;\n\ntype ApprovalRequestData = Record<string, Json> | null;\n\ntype ApprovalRequestState = Record<string, Json> | null;\n\ntype ApprovalCallbacks = {\n resolve: ApprovalPromiseResolve;\n reject: ApprovalPromiseReject;\n};\n\ntype ApprovalFlow = {\n id: string;\n loadingText: string | null;\n};\n\ntype ResultOptions = {\n flowToEnd?: string;\n header?: (string | ResultComponent)[];\n icon?: string | null;\n title?: string | null;\n};\n\n// Miscellaneous Types\n\nexport type ApprovalRequest<RequestData extends ApprovalRequestData> = {\n /**\n * The ID of the approval request.\n */\n id: string;\n\n /**\n * The origin of the approval request.\n */\n origin: string;\n\n /**\n * The time that the request was received, per Date.now().\n */\n time: number;\n\n /**\n * The type of the approval request.\n * Unfortunately, not all values will match the `ApprovalType` enum, so we are using `string` here.\n * TODO: Replace `string` with `ApprovalType` when all `type` values used by the clients can be encompassed by the `ApprovalType` enum.\n */\n type: string;\n\n /**\n * Additional data associated with the request.\n */\n requestData: RequestData;\n\n /**\n * Additional mutable state associated with the request\n */\n requestState: ApprovalRequestState;\n\n /**\n * Whether the request expects a result object to be returned instead of just the approval value.\n */\n expectsResult: boolean;\n};\n\nexport type ApprovalFlowState = ApprovalFlow;\n\nexport type ApprovalControllerState = {\n pendingApprovals: Record<string, ApprovalRequest<Record<string, Json>>>;\n pendingApprovalCount: number;\n approvalFlows: ApprovalFlowState[];\n};\n\nexport type ApprovalControllerMessenger = Messenger<\n typeof controllerName,\n ApprovalControllerActions,\n ApprovalControllerEvents\n>;\n\n// Option Types\n\nexport type ShowApprovalRequest = () => void | Promise<void>;\n\nexport type ResultComponent = {\n /**\n * A unique identifier for this instance of the component.\n */\n key: string;\n\n /**\n * The name of the component to render.\n */\n name: string;\n\n /**\n * Any properties required by the component.\n */\n properties?: Record<string, unknown>;\n\n /**\n * Any child components to render inside the component.\n */\n children?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ApprovalControllerOptions = {\n messenger: ApprovalControllerMessenger;\n showApprovalRequest: ShowApprovalRequest;\n state?: Partial<ApprovalControllerState>;\n typesExcludedFromRateLimiting?: string[];\n};\n\nexport type AddApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record<string, Json>;\n requestState?: Record<string, Json>;\n expectsResult?: boolean;\n};\n\nexport type UpdateRequestStateOptions = {\n id: string;\n requestState: Record<string, Json>;\n};\n\nexport type AcceptOptions = {\n /**\n * Whether to resolve the returned promise only when the request creator indicates the success of the\n * post-approval logic using the result callbacks.\n * If false or unspecified, the promise will resolve immediately.\n */\n waitForResult?: boolean;\n\n /**\n * Whether to delete the approval request after a result callback is called.\n * If false or unspecified, the approval request will be deleted immediately.\n * Ignored if `waitForResult` is false or unspecified.\n */\n deleteAfterResult?: boolean;\n};\n\nexport type StartFlowOptions = OptionalField<\n ApprovalFlow,\n 'id' | 'loadingText'\n> & { show?: boolean };\n\nexport type EndFlowOptions = Pick<ApprovalFlow, 'id'>;\n\nexport type SetFlowLoadingTextOptions = ApprovalFlow;\n\nexport type SuccessOptions = ResultOptions & {\n message?: string | ResultComponent | (string | ResultComponent)[];\n};\n\nexport type ErrorOptions = ResultOptions & {\n error?: string | ResultComponent | (string | ResultComponent)[];\n};\n\n// Result Types\n\nexport type AcceptResultCallbacks = {\n /**\n * Inform the request acceptor that the post-approval logic was successful.\n *\n * @param value - An optional value generated by the post-approval logic.\n */\n success: (value?: unknown) => void;\n\n /**\n * Inform the request acceptor that the post-approval logic failed.\n *\n * @param error - The reason for the failure.\n */\n error: (error: Error) => void;\n};\n\nexport type AddResult = {\n /**\n * An optional value provided by the request acceptor.\n */\n value?: unknown;\n\n /**\n * Callback functions that must be used to indicate to the request acceptor whether the post-approval logic was successful or not.\n * Will be undefined if the request acceptor did not specify that they want to wait for a result.\n */\n resultCallbacks?: AcceptResultCallbacks;\n};\n\nexport type AcceptResult = {\n /**\n * An optional value provided by the request creator when indicating a successful result.\n */\n value?: unknown;\n};\n\nexport type ApprovalFlowStartResult = ApprovalFlow;\n\nexport type SuccessResult = Record<string, never>;\n\nexport type ErrorResult = Record<string, never>;\n\n// Event Types\n\nexport type ApprovalStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n ApprovalControllerState\n>;\n\nexport type ApprovalControllerEvents = ApprovalStateChange;\n\n// Action Types\n\nexport type GetApprovalsState = ControllerGetStateAction<\n typeof controllerName,\n ApprovalControllerState\n>;\n\nexport type ClearApprovalRequests = {\n type: `${typeof controllerName}:clearRequests`;\n handler: (error: JsonRpcError<DataWithOptionalCause>) => void;\n};\n\nexport type AddApprovalRequest = {\n type: `${typeof controllerName}:addRequest`;\n handler: (\n opts: AddApprovalOptions,\n shouldShowRequest: boolean,\n ) => ReturnType<ApprovalController['add']>;\n};\n\nexport type HasApprovalRequest = {\n type: `${typeof controllerName}:hasRequest`;\n handler: ApprovalController['has'];\n};\n\nexport type AcceptRequest = {\n type: `${typeof controllerName}:acceptRequest`;\n handler: ApprovalController['accept'];\n};\n\nexport type RejectRequest = {\n type: `${typeof controllerName}:rejectRequest`;\n handler: ApprovalController['reject'];\n};\n\nexport type UpdateRequestState = {\n type: `${typeof controllerName}:updateRequestState`;\n handler: ApprovalController['updateRequestState'];\n};\n\nexport type StartFlow = {\n type: `${typeof controllerName}:startFlow`;\n handler: ApprovalController['startFlow'];\n};\n\nexport type EndFlow = {\n type: `${typeof controllerName}:endFlow`;\n handler: ApprovalController['endFlow'];\n};\n\nexport type SetFlowLoadingText = {\n type: `${typeof controllerName}:setFlowLoadingText`;\n handler: ApprovalController['setFlowLoadingText'];\n};\n\nexport type ShowSuccess = {\n type: `${typeof controllerName}:showSuccess`;\n handler: ApprovalController['success'];\n};\n\nexport type ShowError = {\n type: `${typeof controllerName}:showError`;\n handler: ApprovalController['error'];\n};\n\nexport type ApprovalControllerActions =\n | GetApprovalsState\n | ClearApprovalRequests\n | AddApprovalRequest\n | HasApprovalRequest\n | AcceptRequest\n | RejectRequest\n | UpdateRequestState\n | StartFlow\n | EndFlow\n | SetFlowLoadingText\n | ShowSuccess\n | ShowError;\n\n/**\n * Controller for managing requests that require user approval.\n *\n * Enables limiting the number of pending requests by origin and type, counting\n * pending requests, and more.\n *\n * Adding a request returns a promise that resolves or rejects when the request\n * is approved or denied, respectively.\n */\nexport class ApprovalController extends BaseController<\n typeof controllerName,\n ApprovalControllerState,\n ApprovalControllerMessenger\n> {\n readonly #approvals: Map<string, ApprovalCallbacks>;\n\n readonly #origins: Map<string, Map<string, number>>;\n\n readonly #showApprovalRequest: () => void;\n\n readonly #typesExcludedFromRateLimiting: string[];\n\n /**\n * Construct an Approval controller.\n *\n * @param options - The controller options.\n * @param options.showApprovalRequest - Function for opening the UI such that\n * the request can be displayed to the user.\n * @param options.messenger - The restricted messenger for the Approval controller.\n * @param options.state - The initial controller state.\n * @param options.typesExcludedFromRateLimiting - Array of approval types which allow multiple pending approval requests from the same origin.\n */\n constructor({\n messenger,\n showApprovalRequest,\n state = {},\n typesExcludedFromRateLimiting = [],\n }: ApprovalControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#approvals = new Map();\n this.#origins = new Map();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.#showApprovalRequest = showApprovalRequest;\n this.#typesExcludedFromRateLimiting = typesExcludedFromRateLimiting;\n this.registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n private registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:clearRequests` as const,\n this.clear.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:addRequest` as const,\n (opts: AddApprovalOptions, shouldShowRequest: boolean) => {\n if (shouldShowRequest) {\n return this.addAndShowApprovalRequest(opts);\n }\n return this.add(opts);\n },\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:hasRequest` as const,\n this.has.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:acceptRequest` as const,\n this.accept.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:rejectRequest` as const,\n this.reject.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:updateRequestState` as const,\n this.updateRequestState.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:startFlow` as const,\n this.startFlow.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:endFlow` as const,\n this.endFlow.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:setFlowLoadingText` as const,\n this.setFlowLoadingText.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:showSuccess` as const,\n this.success.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:showError` as const,\n this.error.bind(this),\n );\n }\n\n /**\n * Adds an approval request per the given arguments, calls the show approval\n * request function, and returns the associated approval promise resolving to\n * an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\n addAndShowApprovalRequest(\n opts: AddApprovalOptions & { expectsResult: true },\n ): Promise<AddResult>;\n\n /**\n * Adds an approval request per the given arguments, calls the show approval\n * request function, and returns the associated approval promise resolving\n * to a value provided during acceptance.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * @param opts.requestState - Additional state associated with the request,\n * if any.\n * @returns The approval promise resolving to a value provided during acceptance.\n */\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise<unknown>;\n\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise<unknown> {\n const promise = this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n this.#showApprovalRequest();\n return promise;\n }\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to an AddResult object.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @returns The approval promise resolving to an AddResult object.\n */\n add(opts: AddApprovalOptions & { expectsResult: true }): Promise<AddResult>;\n\n /**\n * Adds an approval request per the given arguments and returns the approval\n * promise resolving to a value provided during acceptance.\n *\n * There can only be one approval per origin and type. An error is thrown if\n * attempting to add an invalid or duplicate request.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request. A random id will be\n * generated if none is provided.\n * @param opts.origin - The origin of the approval request.\n * @param opts.type - The type associated with the approval request.\n * @param opts.requestData - Additional data associated with the request,\n * if any.\n * @returns The approval promise resolving to a value provided during acceptance.\n */\n add(opts: AddApprovalOptions): Promise<unknown>;\n\n add(opts: AddApprovalOptions): Promise<unknown | AddResult> {\n return this.#add(\n opts.origin,\n opts.type,\n opts.id,\n opts.requestData,\n opts.requestState,\n opts.expectsResult,\n );\n }\n\n /**\n * Gets the info for the approval request with the given id.\n *\n * @param id - The id of the approval request.\n * @returns The approval request data associated with the id.\n */\n get(id: string): ApprovalRequest<ApprovalRequestData> | undefined {\n return this.state.pendingApprovals[id];\n }\n\n /**\n * Gets the number of pending approvals, by origin and/or type.\n *\n * If only `origin` is specified, all approvals for that origin will be\n * counted, regardless of type.\n * If only `type` is specified, all approvals for that type will be counted,\n * regardless of origin.\n * If both `origin` and `type` are specified, 0 or 1 will be returned.\n *\n * @param opts - The approval count options.\n * @param opts.origin - An approval origin.\n * @param opts.type - The type of the approval request.\n * @returns The current approval request count for the given origin and/or\n * type.\n */\n getApprovalCount(opts: { origin?: string; type?: string } = {}): number {\n if (!opts.origin && !opts.type) {\n throw new Error('Must specify origin, type, or both.');\n }\n const { origin, type: _type } = opts;\n\n if (origin && _type) {\n return this.#origins.get(origin)?.get(_type) || 0;\n }\n\n if (origin) {\n return Array.from(\n (this.#origins.get(origin) || new Map()).values(),\n ).reduce((total, value) => total + value, 0);\n }\n\n // Only \"type\" was specified\n let count = 0;\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n count += 1;\n }\n }\n return count;\n }\n\n /**\n * Get the total count of all pending approval requests for all origins.\n *\n * @returns The total pending approval request count.\n */\n getTotalApprovalCount(): number {\n return this.state.pendingApprovalCount;\n }\n\n /**\n * Checks if there's a pending approval request per the given parameters.\n * At least one parameter must be specified. An error will be thrown if the\n * parameters are invalid.\n *\n * If `id` is specified, all other parameters will be ignored.\n * If `id` is not specified, the method will check for requests that match\n * all of the specified parameters.\n *\n * @param opts - Options bag.\n * @param opts.id - The ID to check for.\n * @param opts.origin - The origin to check for.\n * @param opts.type - The type to check for.\n * @returns `true` if a matching approval is found, and `false` otherwise.\n */\n has(opts: { id?: string; origin?: string; type?: string } = {}): boolean {\n const { id, origin, type: _type } = opts;\n\n if (id) {\n if (typeof id !== 'string') {\n throw new Error('May not specify non-string id.');\n }\n return this.#approvals.has(id);\n }\n\n if (_type && typeof _type !== 'string') {\n throw new Error('May not specify non-string type.');\n }\n\n if (origin) {\n if (typeof origin !== 'string') {\n throw new Error('May not specify non-string origin.');\n }\n\n // Check origin and type pair if type also specified\n if (_type) {\n return Boolean(this.#origins.get(origin)?.get(_type));\n }\n return this.#origins.has(origin);\n }\n\n if (_type) {\n for (const approval of Object.values(this.state.pendingApprovals)) {\n if (approval.type === _type) {\n return true;\n }\n }\n return false;\n }\n throw new Error(\n 'Must specify a valid combination of id, origin, and type.',\n );\n }\n\n /**\n * Resolves the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param value - The value to resolve the approval promise with.\n * @param options - Options bag.\n * @returns A promise that either resolves once a result is provided by\n * the creator of the approval request, or immediately if `options.waitForResult`\n * is `false` or `undefined`.\n */\n accept(\n id: string,\n value?: unknown,\n options?: AcceptOptions,\n ): Promise<AcceptResult> {\n // Safe to cast as the delete method below will throw if the ID is not found\n const approval = this.get(id) as ApprovalRequest<ApprovalRequestData>;\n const requestPromise = this.#getCallbacks(id);\n let requestDeleted = false;\n\n if (!options?.deleteAfterResult || !options.waitForResult) {\n this.#delete(id);\n requestDeleted = true;\n }\n\n return new Promise<AcceptResult>((resolve, reject) => {\n const resultCallbacks: AcceptResultCallbacks = {\n success: (acceptValue?: unknown) => resolve({ value: acceptValue }),\n error: reject,\n };\n\n if (options?.waitForResult && !approval.expectsResult) {\n reject(new ApprovalRequestNoResultSupportError(id));\n return;\n }\n\n const resultValue = options?.waitForResult ? resultCallbacks : undefined;\n\n const resolveValue = approval.expectsResult\n ? { value, resultCallbacks: resultValue }\n : value;\n\n requestPromise.resolve(resolveValue);\n\n if (!options?.waitForResult) {\n resolve({ value: undefined });\n }\n }).finally(() => {\n if (!requestDeleted) {\n this.#delete(id);\n }\n });\n }\n\n /**\n * Rejects the promise of the approval with the given id, and deletes the\n * approval. Throws an error if no such approval exists.\n *\n * @param id - The id of the approval request.\n * @param error - The error to reject the approval promise with.\n */\n reject(id: string, error: unknown): void {\n const callbacks = this.#getCallbacks(id);\n this.#delete(id);\n callbacks.reject(error);\n }\n\n /**\n * Rejects and deletes all approval requests.\n *\n * @param rejectionError - The JsonRpcError to reject the approval\n * requests with.\n */\n clear(rejectionError: JsonRpcError<DataWithOptionalCause>): void {\n for (const id of this.#approvals.keys()) {\n this.reject(id, rejectionError);\n }\n this.#origins.clear();\n this.update((draftState) => {\n draftState.pendingApprovals = {};\n draftState.pendingApprovalCount = 0;\n });\n }\n\n /**\n * Updates the request state of the approval with the given id.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval request.\n * @param opts.requestState - Additional data associated with the request\n */\n updateRequestState(opts: UpdateRequestStateOptions): void {\n if (!this.state.pendingApprovals[opts.id]) {\n throw new ApprovalRequestNotFoundError(opts.id);\n }\n\n this.update((draftState) => {\n draftState.pendingApprovals[opts.id].requestState =\n opts.requestState as never;\n });\n }\n\n /**\n * Starts a new approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n * @param opts.show - A flag to determine whether the approval should show to the user.\n * @returns The object containing the approval flow id.\n */\n startFlow(opts: StartFlowOptions = {}): ApprovalFlowStartResult {\n const id = opts.id ?? nanoid();\n const loadingText = opts.loadingText ?? null;\n\n this.update((draftState) => {\n draftState.approvalFlows.push({ id, loadingText });\n });\n\n // By default, if nothing else is specified, we always show the approval.\n if (opts.show !== false) {\n this.#showApprovalRequest();\n }\n\n return { id, loadingText };\n }\n\n /**\n * Ends the current approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The id of the approval flow that will be finished.\n */\n endFlow({ id }: EndFlowOptions) {\n if (!this.state.approvalFlows.length) {\n throw new NoApprovalFlowsError();\n }\n\n const currentFlow = this.state.approvalFlows.slice(-1)[0];\n\n if (id !== currentFlow.id) {\n throw new EndInvalidFlowError(\n id,\n this.state.approvalFlows.map((flow) => flow.id),\n );\n }\n\n this.update((draftState) => {\n draftState.approvalFlows.pop();\n });\n }\n\n /**\n * Sets the loading text for the approval flow.\n *\n * @param opts - Options bag.\n * @param opts.id - The approval flow loading text that will be displayed.\n * @param opts.loadingText - The loading text that will be associated to the approval flow.\n */\n setFlowLoadingText({ id, loadingText }: SetFlowLoadingTextOptions) {\n const flowIndex = this.state.approvalFlows.findIndex(\n (flow) => flow.id === id,\n );\n\n if (flowIndex === -1) {\n throw new MissingApprovalFlowError(id);\n }\n\n this.update((draftState) => {\n draftState.approvalFlows[flowIndex].loadingText = loadingText;\n });\n }\n\n /**\n * Show a success page.\n *\n * @param opts - Options bag.\n * @param opts.message - The message text or components to display in the page.\n * @param opts.header - The text or components to display in the header of the page.\n * @param opts.flowToEnd - The ID of the approval flow to end once the success page is approved.\n * @param opts.title - The title to display above the message. Shown by default but can be hidden with `null`.\n * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.\n * @returns Empty object to support future additions.\n */\n async success(opts: SuccessOptions = {}): Promise<SuccessResult> {\n await this.#result(APPROVAL_TYPE_RESULT_SUCCESS, opts, {\n message: opts.message,\n header: opts.header,\n title: opts.title,\n icon: opts.icon,\n } as Record<string, Json>);\n\n return {};\n }\n\n /**\n * Show an error page.\n *\n * @param opts - Options bag.\n * @param opts.message - The message text or components to display in the page.\n * @param opts.header - The text or components to display in the header of the page.\n * @param opts.flowToEnd - The ID of the approval flow to end once the error page is approved.\n * @param opts.title - The title to display above the message. Shown by default but can be hidden with `null`.\n * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.\n * @returns Empty object to support future additions.\n */\n async error(opts: ErrorOptions = {}): Promise<ErrorResult> {\n await this.#result(APPROVAL_TYPE_RESULT_ERROR, opts, {\n error: opts.error,\n header: opts.header,\n title: opts.title,\n icon: opts.icon,\n } as Record<string, Json>);\n\n return {};\n }\n\n /**\n * Implementation of add operation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param id - The id of the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the approval request expects a result object to be returned.\n * @returns The approval promise.\n */\n #add(\n origin: string,\n type: string,\n id: string = nanoid(),\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n expectsResult?: boolean,\n ): Promise<unknown | AddResult> {\n this.#validateAddParams(id, origin, type, requestData, requestState);\n\n if (\n !this.#typesExcludedFromRateLimiting.includes(type) &&\n this.has({ origin, type })\n ) {\n throw rpcErrors.resourceUnavailable(\n getAlreadyPendingMessage(origin, type),\n );\n }\n\n // add pending approval\n return new Promise((resolve, reject) => {\n this.#approvals.set(id, { resolve, reject });\n this.#addPendingApprovalOrigin(origin, type);\n\n this.#addToStore(\n id,\n origin,\n type,\n requestData,\n requestState,\n expectsResult,\n );\n });\n }\n\n /**\n * Validates parameters to the add method.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n */\n #validateAddParams(\n id: string,\n origin: string,\n type: string,\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n ): void {\n let errorMessage = null;\n if (!id || typeof id !== 'string') {\n errorMessage = 'Must specify non-empty string id.';\n } else if (this.#approvals.has(id)) {\n errorMessage = `Approval request with id '${id}' already exists.`;\n } else if (!origin || typeof origin !== 'string') {\n errorMessage = 'Must specify non-empty string origin.';\n } else if (!type || typeof type !== 'string') {\n errorMessage = 'Must specify non-empty string type.';\n } else if (\n requestData &&\n (typeof requestData !== 'object' || Array.isArray(requestData))\n ) {\n errorMessage = 'Request data must be a plain object if specified.';\n } else if (\n requestState &&\n (typeof requestState !== 'object' || Array.isArray(requestState))\n ) {\n errorMessage = 'Request state must be a plain object if specified.';\n }\n\n if (errorMessage) {\n throw rpcErrors.internal(errorMessage);\n }\n }\n\n /**\n * Adds an entry to _origins.\n * Performs no validation.\n *\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n */\n #addPendingApprovalOrigin(origin: string, type: string): void {\n let originMap = this.#origins.get(origin);\n\n if (!originMap) {\n originMap = new Map();\n this.#origins.set(origin, originMap);\n }\n\n const currentValue = originMap.get(type) || 0;\n originMap.set(type, currentValue + 1);\n }\n\n /**\n * Adds an entry to the store.\n * Performs no validation.\n *\n * @param id - The id of the approval request.\n * @param origin - The origin of the approval request.\n * @param type - The type associated with the approval request.\n * @param requestData - The request data associated with the approval request.\n * @param requestState - The request state associated with the approval request.\n * @param expectsResult - Whether the request expects a result object to be returned.\n */\n #addToStore(\n id: string,\n origin: string,\n type: string,\n requestData?: Record<string, Json>,\n requestState?: Record<string, Json>,\n expectsResult?: boolean,\n ): void {\n const approval = {\n id,\n origin,\n type,\n time: Date.now(),\n requestData: requestData || null,\n requestState: requestState || null,\n expectsResult: expectsResult || false,\n };\n\n this.update((draftState) => {\n draftState.pendingApprovals[id] = approval as never;\n\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n /**\n * Deletes the approval with the given id.\n *\n * Deletion is an internal operation because approval state is solely\n * managed by this controller.\n *\n * @param id - The id of the approval request to be deleted.\n */\n #delete(id: string): void {\n if (!this.#approvals.has(id)) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n this.#approvals.delete(id);\n\n const { origin, type } = this.state.pendingApprovals[id];\n\n const originMap = this.#origins.get(origin) as Map<string, number>;\n const originTotalCount = this.getApprovalCount({ origin });\n const originTypeCount = originMap.get(type) as number;\n\n if (originTotalCount === 1) {\n this.#origins.delete(origin);\n } else {\n originMap.set(type, originTypeCount - 1);\n }\n\n this.update((draftState) => {\n delete draftState.pendingApprovals[id];\n draftState.pendingApprovalCount = Object.keys(\n draftState.pendingApprovals,\n ).length;\n });\n }\n\n #getCallbacks(id: string): ApprovalCallbacks {\n const callbacks = this.#approvals.get(id);\n\n if (!callbacks) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n return callbacks;\n }\n\n async #result(\n type: string,\n opts: ResultOptions,\n requestData: Record<string, Json>,\n ) {\n try {\n await this.addAndShowApprovalRequest({\n origin: ORIGIN_METAMASK,\n type,\n requestData,\n });\n } catch (error) {\n console.info('Failed to display result page', error);\n } finally {\n if (opts.flowToEnd) {\n try {\n this.endFlow({ id: opts.flowToEnd });\n } catch (error) {\n console.info('Failed to end flow', { id: opts.flowToEnd, error });\n }\n }\n }\n }\n}\n\nexport default ApprovalController;\n"]}
@@ -4,7 +4,6 @@ import type { ControllerStateChangeEvent } from "@metamask/base-controller";
4
4
  import type { Messenger } from "@metamask/messenger";
5
5
  import type { JsonRpcError, DataWithOptionalCause } from "@metamask/rpc-errors";
6
6
  import type { Json, OptionalField } from "@metamask/utils";
7
- import type { ApprovalControllerMethodActions } from "./ApprovalController-method-action-types.cjs";
8
7
  export declare const ORIGIN_METAMASK = "metamask";
9
8
  export declare const APPROVAL_TYPE_RESULT_ERROR = "result_error";
10
9
  export declare const APPROVAL_TYPE_RESULT_SUCCESS = "result_success";
@@ -158,8 +157,52 @@ export type SuccessResult = Record<string, never>;
158
157
  export type ErrorResult = Record<string, never>;
159
158
  export type ApprovalStateChange = ControllerStateChangeEvent<typeof controllerName, ApprovalControllerState>;
160
159
  export type ApprovalControllerEvents = ApprovalStateChange;
161
- export type ApprovalControllerGetStateAction = ControllerGetStateAction<typeof controllerName, ApprovalControllerState>;
162
- export type ApprovalControllerActions = ApprovalControllerGetStateAction | ApprovalControllerMethodActions;
160
+ export type GetApprovalsState = ControllerGetStateAction<typeof controllerName, ApprovalControllerState>;
161
+ export type ClearApprovalRequests = {
162
+ type: `${typeof controllerName}:clearRequests`;
163
+ handler: (error: JsonRpcError<DataWithOptionalCause>) => void;
164
+ };
165
+ export type AddApprovalRequest = {
166
+ type: `${typeof controllerName}:addRequest`;
167
+ handler: (opts: AddApprovalOptions, shouldShowRequest: boolean) => ReturnType<ApprovalController['add']>;
168
+ };
169
+ export type HasApprovalRequest = {
170
+ type: `${typeof controllerName}:hasRequest`;
171
+ handler: ApprovalController['has'];
172
+ };
173
+ export type AcceptRequest = {
174
+ type: `${typeof controllerName}:acceptRequest`;
175
+ handler: ApprovalController['accept'];
176
+ };
177
+ export type RejectRequest = {
178
+ type: `${typeof controllerName}:rejectRequest`;
179
+ handler: ApprovalController['reject'];
180
+ };
181
+ export type UpdateRequestState = {
182
+ type: `${typeof controllerName}:updateRequestState`;
183
+ handler: ApprovalController['updateRequestState'];
184
+ };
185
+ export type StartFlow = {
186
+ type: `${typeof controllerName}:startFlow`;
187
+ handler: ApprovalController['startFlow'];
188
+ };
189
+ export type EndFlow = {
190
+ type: `${typeof controllerName}:endFlow`;
191
+ handler: ApprovalController['endFlow'];
192
+ };
193
+ export type SetFlowLoadingText = {
194
+ type: `${typeof controllerName}:setFlowLoadingText`;
195
+ handler: ApprovalController['setFlowLoadingText'];
196
+ };
197
+ export type ShowSuccess = {
198
+ type: `${typeof controllerName}:showSuccess`;
199
+ handler: ApprovalController['success'];
200
+ };
201
+ export type ShowError = {
202
+ type: `${typeof controllerName}:showError`;
203
+ handler: ApprovalController['error'];
204
+ };
205
+ export type ApprovalControllerActions = GetApprovalsState | ClearApprovalRequests | AddApprovalRequest | HasApprovalRequest | AcceptRequest | RejectRequest | UpdateRequestState | StartFlow | EndFlow | SetFlowLoadingText | ShowSuccess | ShowError;
163
206
  /**
164
207
  * Controller for managing requests that require user approval.
165
208
  *
@@ -183,22 +226,10 @@ export declare class ApprovalController extends BaseController<typeof controller
183
226
  */
184
227
  constructor({ messenger, showApprovalRequest, state, typesExcludedFromRateLimiting, }: ApprovalControllerOptions);
185
228
  /**
186
- * Adds an approval request per the given arguments, optionally showing
187
- * the approval request to the user.
188
- *
189
- * @param opts - Options bag.
190
- * @param opts.id - The id of the approval request. A random id will be
191
- * generated if none is provided.
192
- * @param opts.origin - The origin of the approval request.
193
- * @param opts.type - The type associated with the approval request.
194
- * @param opts.requestData - Additional data associated with the request,
195
- * if any.
196
- * @param opts.requestState - Additional state associated with the request,
197
- * if any.
198
- * @param shouldShowRequest - Whether to show the approval request to the user.
199
- * @returns The approval promise.
229
+ * Constructor helper for registering this controller's messaging system
230
+ * actions.
200
231
  */
201
- addRequest(opts: AddApprovalOptions, shouldShowRequest: boolean): Promise<unknown>;
232
+ private registerMessageHandlers;
202
233
  /**
203
234
  * Adds an approval request per the given arguments, calls the show approval
204
235
  * request function, and returns the associated approval promise resolving to
@@ -322,7 +353,7 @@ export declare class ApprovalController extends BaseController<typeof controller
322
353
  * @param opts.type - The type to check for.
323
354
  * @returns `true` if a matching approval is found, and `false` otherwise.
324
355
  */
325
- hasRequest(opts?: {
356
+ has(opts?: {
326
357
  id?: string;
327
358
  origin?: string;
328
359
  type?: string;
@@ -338,7 +369,7 @@ export declare class ApprovalController extends BaseController<typeof controller
338
369
  * the creator of the approval request, or immediately if `options.waitForResult`
339
370
  * is `false` or `undefined`.
340
371
  */
341
- acceptRequest(id: string, value?: unknown, options?: AcceptOptions): Promise<AcceptResult>;
372
+ accept(id: string, value?: unknown, options?: AcceptOptions): Promise<AcceptResult>;
342
373
  /**
343
374
  * Rejects the promise of the approval with the given id, and deletes the
344
375
  * approval. Throws an error if no such approval exists.
@@ -346,14 +377,14 @@ export declare class ApprovalController extends BaseController<typeof controller
346
377
  * @param id - The id of the approval request.
347
378
  * @param error - The error to reject the approval promise with.
348
379
  */
349
- rejectRequest(id: string, error: unknown): void;
380
+ reject(id: string, error: unknown): void;
350
381
  /**
351
382
  * Rejects and deletes all approval requests.
352
383
  *
353
384
  * @param rejectionError - The JsonRpcError to reject the approval
354
385
  * requests with.
355
386
  */
356
- clearRequests(rejectionError: JsonRpcError<DataWithOptionalCause>): void;
387
+ clear(rejectionError: JsonRpcError<DataWithOptionalCause>): void;
357
388
  /**
358
389
  * Updates the request state of the approval with the given id.
359
390
  *
@@ -398,7 +429,7 @@ export declare class ApprovalController extends BaseController<typeof controller
398
429
  * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.
399
430
  * @returns Empty object to support future additions.
400
431
  */
401
- showSuccess(opts?: SuccessOptions): Promise<SuccessResult>;
432
+ success(opts?: SuccessOptions): Promise<SuccessResult>;
402
433
  /**
403
434
  * Show an error page.
404
435
  *
@@ -410,7 +441,7 @@ export declare class ApprovalController extends BaseController<typeof controller
410
441
  * @param opts.icon - The icon to display in the page. Shown by default but can be hidden with `null`.
411
442
  * @returns Empty object to support future additions.
412
443
  */
413
- showError(opts?: ErrorOptions): Promise<ErrorResult>;
444
+ error(opts?: ErrorOptions): Promise<ErrorResult>;
414
445
  }
415
446
  export default ApprovalController;
416
447
  //# sourceMappingURL=ApprovalController.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ApprovalController.d.cts","sourceRoot":"","sources":["../src/ApprovalController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,0BAA0B,EAAE,kCAAkC;AAC5E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,6BAA6B;AAEhF,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAG3D,OAAO,KAAK,EAAE,+BAA+B,EAAE,qDAAiD;AAYhG,eAAO,MAAM,eAAe,aAAa,CAAC;AAC1C,eAAO,MAAM,0BAA0B,iBAAiB,CAAC;AACzD,eAAO,MAAM,4BAA4B,mBAAmB,CAAC;AAE7D,QAAA,MAAM,cAAc,uBAAuB,CAAC;AA6D5C,KAAK,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;AAEvD,KAAK,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;AAOxD,KAAK,YAAY,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,KAAK,aA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