From d6c52feae00cfc40023025a26e9ed2f6d7627a10 Mon Sep 17 00:00:00 2001 From: Matthew Walsh Date: Wed, 23 Oct 2024 12:33:17 +0100 Subject: [PATCH] chore: upgrade signature controller to remove message managers (#11911) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** Upgrade `@metamask/signature-controller` to version `20.1.0` to remove all usage of `metamask/message-managers`. Upgrade `@metamask/approval-controller` to version `7.1.0` and remove the unnecessary patch. Upgrade Node version from `20.12.2` to `20.14.0`. ## **Related issues** ## **Manual testing steps** Full regression of all signature functionality. ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- .nvmrc | 2 +- app/core/Engine.ts | 1 - app/util/test/initial-background-state.json | 1 + bitrise.yml | 2 +- package.json | 6 +- .../@metamask+approval-controller+7.0.2.patch | 404 ------------------ scripts/generate-attributions/package.json | 2 +- yarn.lock | 34 +- 8 files changed, 31 insertions(+), 421 deletions(-) delete mode 100644 patches/@metamask+approval-controller+7.0.2.patch diff --git a/.nvmrc b/.nvmrc index 87834047a6f..48b14e6b2b5 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -20.12.2 +20.14.0 diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 89ede70f472..a5969f5edf3 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -506,7 +506,6 @@ class Engine { }; const approvalController = new ApprovalController({ - // @ts-expect-error TODO: Resolve mismatch between base-controller versions. messenger: this.controllerMessenger.getRestricted({ name: 'ApprovalController', allowedEvents: [], diff --git a/app/util/test/initial-background-state.json b/app/util/test/initial-background-state.json index 201cdd78024..87e02448df0 100644 --- a/app/util/test/initial-background-state.json +++ b/app/util/test/initial-background-state.json @@ -320,6 +320,7 @@ "domains": {} }, "SignatureController": { + "signatureRequests": {}, "unapprovedPersonalMsgs": {}, "unapprovedTypedMessages": {}, "unapprovedPersonalMsgCount": 0, diff --git a/bitrise.yml b/bitrise.yml index 1fc61f98351..070b13b5846 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -1553,7 +1553,7 @@ app: NVM_SHA256SUM: '8e45fa547f428e9196a5613efad3bfa4d4608b74ca870f930090598f5af5f643' - opts: is_expand: false - NODE_VERSION: 20.12.2 + NODE_VERSION: 20.14.0 - opts: is_expand: false YARN_VERSION: 1.22.22 diff --git a/package.json b/package.json index c474cba0370..ac835169e01 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,7 @@ "@ledgerhq/react-native-hw-transport-ble": "^6.33.2", "@metamask/accounts-controller": "^18.2.1", "@metamask/address-book-controller": "^6.0.1", - "@metamask/approval-controller": "^7.0.1", + "@metamask/approval-controller": "^7.1.0", "@metamask/assets-controllers": "^35.0.0", "@metamask/base-controller": "^7.0.1", "@metamask/composable-controller": "^3.0.0", @@ -179,7 +179,7 @@ "@metamask/scure-bip39": "^2.1.0", "@metamask/sdk-communication-layer": "0.29.0-wallet", "@metamask/selected-network-controller": "^15.0.2", - "@metamask/signature-controller": "^19.1.0", + "@metamask/signature-controller": "^20.1.0", "@metamask/slip44": "3.1.0", "@metamask/smart-transactions-controller": "^13.0.0", "@metamask/snaps-controllers": "^9.8.0", @@ -532,7 +532,7 @@ "fs": "react-native-level-fs" }, "engines": { - "node": "^20.12.2", + "node": "^20.14.0", "yarn": "^1.22.22" }, "lavamoat": { diff --git a/patches/@metamask+approval-controller+7.0.2.patch b/patches/@metamask+approval-controller+7.0.2.patch deleted file mode 100644 index dd655204a82..00000000000 --- a/patches/@metamask+approval-controller+7.0.2.patch +++ /dev/null @@ -1,404 +0,0 @@ -diff --git a/node_modules/@metamask/approval-controller/dist/.patch.txt b/node_modules/@metamask/approval-controller/dist/.patch.txt -new file mode 100644 -index 0000000..1c8ef8f ---- /dev/null -+++ b/node_modules/@metamask/approval-controller/dist/.patch.txt -@@ -0,0 +1,7 @@ -+PATCH GENERATED FROM MetaMask/core branch: patch/mobile-approval-controller-7-0-1 -+This patch backports various transaction controller features from the main branch of MetaMask/core -+Steps to update patch: -+* Create a new core branch from: patch/mobile-approval-controller-7-0-1 -+* Run "yarn build" in the core monorepo -+* Run "yarn patch:approval " in the mobile repo -+* Once the new patch is merged, add your changes to: patch/mobile-approval-controller-7-0-1 -diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.js b/node_modules/@metamask/approval-controller/dist/ApprovalController.js -index 21178e9..db8fdcf 100644 ---- a/node_modules/@metamask/approval-controller/dist/ApprovalController.js -+++ b/node_modules/@metamask/approval-controller/dist/ApprovalController.js -@@ -4,7 +4,7 @@ - - - --var _chunkPMXPCCKSjs = require('./chunk-PMXPCCKS.js'); -+var _chunkNONDXCHJjs = require('./chunk-NONDXCHJ.js'); - require('./chunk-LKCXZAKD.js'); - - -@@ -12,5 +12,5 @@ require('./chunk-LKCXZAKD.js'); - - - --exports.APPROVAL_TYPE_RESULT_ERROR = _chunkPMXPCCKSjs.APPROVAL_TYPE_RESULT_ERROR; exports.APPROVAL_TYPE_RESULT_SUCCESS = _chunkPMXPCCKSjs.APPROVAL_TYPE_RESULT_SUCCESS; exports.ApprovalController = _chunkPMXPCCKSjs.ApprovalController; exports.ORIGIN_METAMASK = _chunkPMXPCCKSjs.ORIGIN_METAMASK; exports.default = _chunkPMXPCCKSjs.ApprovalController_default; -+exports.APPROVAL_TYPE_RESULT_ERROR = _chunkNONDXCHJjs.APPROVAL_TYPE_RESULT_ERROR; exports.APPROVAL_TYPE_RESULT_SUCCESS = _chunkNONDXCHJjs.APPROVAL_TYPE_RESULT_SUCCESS; exports.ApprovalController = _chunkNONDXCHJjs.ApprovalController; exports.ORIGIN_METAMASK = _chunkNONDXCHJjs.ORIGIN_METAMASK; exports.default = _chunkNONDXCHJjs.ApprovalController_default; - //# sourceMappingURL=ApprovalController.js.map -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.js.map b/node_modules/@metamask/approval-controller/dist/ApprovalController.js.map -deleted file mode 100644 -index a464c67..0000000 ---- a/node_modules/@metamask/approval-controller/dist/ApprovalController.js.map -+++ /dev/null -@@ -1 +0,0 @@ --{"version":3,"sources":[],"names":[],"mappings":""} -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.mjs b/node_modules/@metamask/approval-controller/dist/ApprovalController.mjs -index a6f0950..664ec6b 100644 ---- a/node_modules/@metamask/approval-controller/dist/ApprovalController.mjs -+++ b/node_modules/@metamask/approval-controller/dist/ApprovalController.mjs -@@ -4,7 +4,7 @@ import { - ApprovalController, - ApprovalController_default, - ORIGIN_METAMASK --} from "./chunk-PIJZDVKC.mjs"; -+} from "./chunk-CZANKQ6E.mjs"; - import "./chunk-C4VZRQ2J.mjs"; - export { - APPROVAL_TYPE_RESULT_ERROR, -diff --git a/node_modules/@metamask/approval-controller/dist/ApprovalController.mjs.map b/node_modules/@metamask/approval-controller/dist/ApprovalController.mjs.map -deleted file mode 100644 -index 84c51b2..0000000 ---- a/node_modules/@metamask/approval-controller/dist/ApprovalController.mjs.map -+++ /dev/null -@@ -1 +0,0 @@ --{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]} -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/chunk-C4VZRQ2J.mjs.map b/node_modules/@metamask/approval-controller/dist/chunk-C4VZRQ2J.mjs.map -deleted file mode 100644 -index 0df9138..0000000 ---- a/node_modules/@metamask/approval-controller/dist/chunk-C4VZRQ2J.mjs.map -+++ /dev/null -@@ -1 +0,0 @@ --{"version":3,"sources":["../src/errors.ts"],"sourcesContent":["export class ApprovalRequestNotFoundError extends Error {\n constructor(id: string) {\n super(`Approval request with id '${id}' not found.`);\n }\n}\n\nexport class ApprovalRequestNoResultSupportError extends Error {\n constructor(id: string) {\n super(\n `Approval acceptance requested result but request with id '${id}' does not support it.`,\n );\n }\n}\n\nexport class NoApprovalFlowsError extends Error {\n constructor() {\n super(`No approval flows found.`);\n }\n}\n\nexport class EndInvalidFlowError extends Error {\n constructor(id: string, flowIds: string[]) {\n super(\n `Attempted to end flow with id '${id}' which does not match current flow with id '${\n flowIds.slice(-1)[0]\n }'. All Flows: ${flowIds.join(', ')}`,\n );\n }\n}\n\nexport class MissingApprovalFlowError extends Error {\n constructor(id: string) {\n super(`No approval flows found with id '${id}'.`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAO,IAAM,+BAAN,cAA2C,MAAM;AAAA,EACtD,YAAY,IAAY;AACtB,UAAM,6BAA6B,EAAE,cAAc;AAAA,EACrD;AACF;AAEO,IAAM,sCAAN,cAAkD,MAAM;AAAA,EAC7D,YAAY,IAAY;AACtB;AAAA,MACE,6DAA6D,EAAE;AAAA,IACjE;AAAA,EACF;AACF;AAEO,IAAM,uBAAN,cAAmC,MAAM;AAAA,EAC9C,cAAc;AACZ,UAAM,0BAA0B;AAAA,EAClC;AACF;AAEO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7C,YAAY,IAAY,SAAmB;AACzC;AAAA,MACE,kCAAkC,EAAE,gDAClC,QAAQ,MAAM,EAAE,EAAE,CAAC,CACrB,iBAAiB,QAAQ,KAAK,IAAI,CAAC;AAAA,IACrC;AAAA,EACF;AACF;AAEO,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAClD,YAAY,IAAY;AACtB,UAAM,oCAAoC,EAAE,IAAI;AAAA,EAClD;AACF;","names":[]} -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/chunk-PIJZDVKC.mjs b/node_modules/@metamask/approval-controller/dist/chunk-CZANKQ6E.mjs -similarity index 94% -rename from node_modules/@metamask/approval-controller/dist/chunk-PIJZDVKC.mjs -rename to node_modules/@metamask/approval-controller/dist/chunk-CZANKQ6E.mjs -index 57f7b7b..573794d 100644 ---- a/node_modules/@metamask/approval-controller/dist/chunk-PIJZDVKC.mjs -+++ b/node_modules/@metamask/approval-controller/dist/chunk-CZANKQ6E.mjs -@@ -33,7 +33,7 @@ var getDefaultState = () => { - approvalFlows: [] - }; - }; --var _approvals, _origins, _showApprovalRequest, _typesExcludedFromRateLimiting, _add, add_fn, _validateAddParams, validateAddParams_fn, _addPendingApprovalOrigin, addPendingApprovalOrigin_fn, _addToStore, addToStore_fn, _delete, delete_fn, _deleteApprovalAndGetCallbacks, deleteApprovalAndGetCallbacks_fn, _result, result_fn; -+var _approvals, _origins, _showApprovalRequest, _typesExcludedFromRateLimiting, _add, add_fn, _validateAddParams, validateAddParams_fn, _addPendingApprovalOrigin, addPendingApprovalOrigin_fn, _addToStore, addToStore_fn, _delete, delete_fn, _getCallbacks, getCallbacks_fn, _result, result_fn; - var ApprovalController = class extends BaseController { - /** - * Construct an Approval controller. -@@ -100,23 +100,15 @@ var ApprovalController = class extends BaseController { - */ - __privateAdd(this, _addToStore); - /** -- * Deletes the approval with the given id. The approval promise must be -- * resolved or reject before this method is called. -+ * Deletes the approval with the given id. -+ * - * Deletion is an internal operation because approval state is solely - * managed by this controller. - * - * @param id - The id of the approval request to be deleted. - */ - __privateAdd(this, _delete); -- /** -- * Gets the approval callbacks for the given id, deletes the entry, and then -- * returns the callbacks for promise resolution. -- * Throws an error if no approval is found for the given id. -- * -- * @param id - The id of the approval request. -- * @returns The promise callbacks associated with the approval request. -- */ -- __privateAdd(this, _deleteApprovalAndGetCallbacks); -+ __privateAdd(this, _getCallbacks); - __privateAdd(this, _result); - __privateAdd(this, _approvals, void 0); - __privateAdd(this, _origins, void 0); -@@ -306,7 +298,12 @@ var ApprovalController = class extends BaseController { - */ - accept(id, value, options) { - const approval = this.get(id); -- const requestPromise = __privateMethod(this, _deleteApprovalAndGetCallbacks, deleteApprovalAndGetCallbacks_fn).call(this, id); -+ const requestPromise = __privateMethod(this, _getCallbacks, getCallbacks_fn).call(this, id); -+ let requestDeleted = false; -+ if (!options?.deleteAfterResult || !options.waitForResult) { -+ __privateMethod(this, _delete, delete_fn).call(this, id); -+ requestDeleted = true; -+ } - return new Promise((resolve, reject) => { - const resultCallbacks = { - success: (acceptValue) => resolve({ value: acceptValue }), -@@ -322,6 +319,10 @@ var ApprovalController = class extends BaseController { - if (!options?.waitForResult) { - resolve({ value: void 0 }); - } -+ }).finally(() => { -+ if (!requestDeleted) { -+ __privateMethod(this, _delete, delete_fn).call(this, id); -+ } - }); - } - /** -@@ -332,7 +333,9 @@ var ApprovalController = class extends BaseController { - * @param error - The error to reject the approval promise with. - */ - reject(id, error) { -- __privateMethod(this, _deleteApprovalAndGetCallbacks, deleteApprovalAndGetCallbacks_fn).call(this, id).reject(error); -+ const callbacks = __privateMethod(this, _getCallbacks, getCallbacks_fn).call(this, id); -+ __privateMethod(this, _delete, delete_fn).call(this, id); -+ callbacks.reject(error); - } - /** - * Rejects and deletes all approval requests. -@@ -533,6 +536,9 @@ addToStore_fn = function(id, origin, type, requestData, requestState, expectsRes - }; - _delete = new WeakSet(); - delete_fn = function(id) { -+ if (!__privateGet(this, _approvals).has(id)) { -+ throw new ApprovalRequestNotFoundError(id); -+ } - __privateGet(this, _approvals).delete(id); - const { origin, type } = this.state.pendingApprovals[id]; - const originMap = __privateGet(this, _origins).get(origin); -@@ -550,13 +556,12 @@ delete_fn = function(id) { - ).length; - }); - }; --_deleteApprovalAndGetCallbacks = new WeakSet(); --deleteApprovalAndGetCallbacks_fn = function(id) { -+_getCallbacks = new WeakSet(); -+getCallbacks_fn = function(id) { - const callbacks = __privateGet(this, _approvals).get(id); - if (!callbacks) { - throw new ApprovalRequestNotFoundError(id); - } -- __privateMethod(this, _delete, delete_fn).call(this, id); - return callbacks; - }; - _result = new WeakSet(); -@@ -588,4 +593,4 @@ export { - ApprovalController, - ApprovalController_default - }; --//# sourceMappingURL=chunk-PIJZDVKC.mjs.map -\ No newline at end of file -+//# sourceMappingURL=chunk-CZANKQ6E.mjs.map -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/chunk-LKCXZAKD.js.map b/node_modules/@metamask/approval-controller/dist/chunk-LKCXZAKD.js.map -deleted file mode 100644 -index 4834941..0000000 ---- a/node_modules/@metamask/approval-controller/dist/chunk-LKCXZAKD.js.map -+++ /dev/null -@@ -1 +0,0 @@ --{"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAO,IAAM,+BAAN,cAA2C,MAAM;AAAA,EACtD,YAAY,IAAY;AACtB,UAAM,6BAA6B,EAAE,cAAc;AAAA,EACrD;AACF;AAEO,IAAM,sCAAN,cAAkD,MAAM;AAAA,EAC7D,YAAY,IAAY;AACtB;AAAA,MACE,6DAA6D,EAAE;AAAA,IACjE;AAAA,EACF;AACF;AAEO,IAAM,uBAAN,cAAmC,MAAM;AAAA,EAC9C,cAAc;AACZ,UAAM,0BAA0B;AAAA,EAClC;AACF;AAEO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7C,YAAY,IAAY,SAAmB;AACzC;AAAA,MACE,kCAAkC,EAAE,gDAClC,QAAQ,MAAM,EAAE,EAAE,CAAC,CACrB,iBAAiB,QAAQ,KAAK,IAAI,CAAC;AAAA,IACrC;AAAA,EACF;AACF;AAEO,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAClD,YAAY,IAAY;AACtB,UAAM,oCAAoC,EAAE,IAAI;AAAA,EAClD;AACF","sourcesContent":["export class ApprovalRequestNotFoundError extends Error {\n constructor(id: string) {\n super(`Approval request with id '${id}' not found.`);\n }\n}\n\nexport class ApprovalRequestNoResultSupportError extends Error {\n constructor(id: string) {\n super(\n `Approval acceptance requested result but request with id '${id}' does not support it.`,\n );\n }\n}\n\nexport class NoApprovalFlowsError extends Error {\n constructor() {\n super(`No approval flows found.`);\n }\n}\n\nexport class EndInvalidFlowError extends Error {\n constructor(id: string, flowIds: string[]) {\n super(\n `Attempted to end flow with id '${id}' which does not match current flow with id '${\n flowIds.slice(-1)[0]\n }'. All Flows: ${flowIds.join(', ')}`,\n );\n }\n}\n\nexport class MissingApprovalFlowError extends Error {\n constructor(id: string) {\n super(`No approval flows found with id '${id}'.`);\n }\n}\n"]} -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/chunk-PMXPCCKS.js b/node_modules/@metamask/approval-controller/dist/chunk-NONDXCHJ.js -similarity index 94% -rename from node_modules/@metamask/approval-controller/dist/chunk-PMXPCCKS.js -rename to node_modules/@metamask/approval-controller/dist/chunk-NONDXCHJ.js -index d840c27..42b4765 100644 ---- a/node_modules/@metamask/approval-controller/dist/chunk-PMXPCCKS.js -+++ b/node_modules/@metamask/approval-controller/dist/chunk-NONDXCHJ.js -@@ -33,7 +33,7 @@ var getDefaultState = () => { - approvalFlows: [] - }; - }; --var _approvals, _origins, _showApprovalRequest, _typesExcludedFromRateLimiting, _add, add_fn, _validateAddParams, validateAddParams_fn, _addPendingApprovalOrigin, addPendingApprovalOrigin_fn, _addToStore, addToStore_fn, _delete, delete_fn, _deleteApprovalAndGetCallbacks, deleteApprovalAndGetCallbacks_fn, _result, result_fn; -+var _approvals, _origins, _showApprovalRequest, _typesExcludedFromRateLimiting, _add, add_fn, _validateAddParams, validateAddParams_fn, _addPendingApprovalOrigin, addPendingApprovalOrigin_fn, _addToStore, addToStore_fn, _delete, delete_fn, _getCallbacks, getCallbacks_fn, _result, result_fn; - var ApprovalController = class extends _basecontroller.BaseController { - /** - * Construct an Approval controller. -@@ -100,23 +100,15 @@ var ApprovalController = class extends _basecontroller.BaseController { - */ - _chunkLKCXZAKDjs.__privateAdd.call(void 0, this, _addToStore); - /** -- * Deletes the approval with the given id. The approval promise must be -- * resolved or reject before this method is called. -+ * Deletes the approval with the given id. -+ * - * Deletion is an internal operation because approval state is solely - * managed by this controller. - * - * @param id - The id of the approval request to be deleted. - */ - _chunkLKCXZAKDjs.__privateAdd.call(void 0, this, _delete); -- /** -- * Gets the approval callbacks for the given id, deletes the entry, and then -- * returns the callbacks for promise resolution. -- * Throws an error if no approval is found for the given id. -- * -- * @param id - The id of the approval request. -- * @returns The promise callbacks associated with the approval request. -- */ -- _chunkLKCXZAKDjs.__privateAdd.call(void 0, this, _deleteApprovalAndGetCallbacks); -+ _chunkLKCXZAKDjs.__privateAdd.call(void 0, this, _getCallbacks); - _chunkLKCXZAKDjs.__privateAdd.call(void 0, this, _result); - _chunkLKCXZAKDjs.__privateAdd.call(void 0, this, _approvals, void 0); - _chunkLKCXZAKDjs.__privateAdd.call(void 0, this, _origins, void 0); -@@ -306,7 +298,12 @@ var ApprovalController = class extends _basecontroller.BaseController { - */ - accept(id, value, options) { - const approval = this.get(id); -- const requestPromise = _chunkLKCXZAKDjs.__privateMethod.call(void 0, this, _deleteApprovalAndGetCallbacks, deleteApprovalAndGetCallbacks_fn).call(this, id); -+ const requestPromise = _chunkLKCXZAKDjs.__privateMethod.call(void 0, this, _getCallbacks, getCallbacks_fn).call(this, id); -+ let requestDeleted = false; -+ if (!options?.deleteAfterResult || !options.waitForResult) { -+ _chunkLKCXZAKDjs.__privateMethod.call(void 0, this, _delete, delete_fn).call(this, id); -+ requestDeleted = true; -+ } - return new Promise((resolve, reject) => { - const resultCallbacks = { - success: (acceptValue) => resolve({ value: acceptValue }), -@@ -322,6 +319,10 @@ var ApprovalController = class extends _basecontroller.BaseController { - if (!options?.waitForResult) { - resolve({ value: void 0 }); - } -+ }).finally(() => { -+ if (!requestDeleted) { -+ _chunkLKCXZAKDjs.__privateMethod.call(void 0, this, _delete, delete_fn).call(this, id); -+ } - }); - } - /** -@@ -332,7 +333,9 @@ var ApprovalController = class extends _basecontroller.BaseController { - * @param error - The error to reject the approval promise with. - */ - reject(id, error) { -- _chunkLKCXZAKDjs.__privateMethod.call(void 0, this, _deleteApprovalAndGetCallbacks, deleteApprovalAndGetCallbacks_fn).call(this, id).reject(error); -+ const callbacks = _chunkLKCXZAKDjs.__privateMethod.call(void 0, this, _getCallbacks, getCallbacks_fn).call(this, id); -+ _chunkLKCXZAKDjs.__privateMethod.call(void 0, this, _delete, delete_fn).call(this, id); -+ callbacks.reject(error); - } - /** - * Rejects and deletes all approval requests. -@@ -533,6 +536,9 @@ addToStore_fn = function(id, origin, type, requestData, requestState, expectsRes - }; - _delete = new WeakSet(); - delete_fn = function(id) { -+ if (!_chunkLKCXZAKDjs.__privateGet.call(void 0, this, _approvals).has(id)) { -+ throw new (0, _chunkLKCXZAKDjs.ApprovalRequestNotFoundError)(id); -+ } - _chunkLKCXZAKDjs.__privateGet.call(void 0, this, _approvals).delete(id); - const { origin, type } = this.state.pendingApprovals[id]; - const originMap = _chunkLKCXZAKDjs.__privateGet.call(void 0, this, _origins).get(origin); -@@ -550,13 +556,12 @@ delete_fn = function(id) { - ).length; - }); - }; --_deleteApprovalAndGetCallbacks = new WeakSet(); --deleteApprovalAndGetCallbacks_fn = function(id) { -+_getCallbacks = new WeakSet(); -+getCallbacks_fn = function(id) { - const callbacks = _chunkLKCXZAKDjs.__privateGet.call(void 0, this, _approvals).get(id); - if (!callbacks) { - throw new (0, _chunkLKCXZAKDjs.ApprovalRequestNotFoundError)(id); - } -- _chunkLKCXZAKDjs.__privateMethod.call(void 0, this, _delete, delete_fn).call(this, id); - return callbacks; - }; - _result = new WeakSet(); -@@ -588,4 +593,4 @@ var ApprovalController_default = ApprovalController; - - - exports.ORIGIN_METAMASK = ORIGIN_METAMASK; exports.APPROVAL_TYPE_RESULT_ERROR = APPROVAL_TYPE_RESULT_ERROR; exports.APPROVAL_TYPE_RESULT_SUCCESS = APPROVAL_TYPE_RESULT_SUCCESS; exports.ApprovalController = ApprovalController; exports.ApprovalController_default = ApprovalController_default; --//# sourceMappingURL=chunk-PMXPCCKS.js.map -\ No newline at end of file -+//# sourceMappingURL=chunk-NONDXCHJ.js.map -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/chunk-PIJZDVKC.mjs.map b/node_modules/@metamask/approval-controller/dist/chunk-PIJZDVKC.mjs.map -deleted file mode 100644 -index 11b7edd..0000000 ---- a/node_modules/@metamask/approval-controller/dist/chunk-PIJZDVKC.mjs.map -+++ /dev/null -@@ -1 +0,0 @@ --{"version":3,"sources":["../src/ApprovalController.ts"],"sourcesContent":["import type { ControllerGetStateAction } from '@metamask/base-controller';\nimport {\n BaseController,\n type ControllerStateChangeEvent,\n type RestrictedControllerMessenger,\n} from '@metamask/base-controller';\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 = {\n pendingApprovals: { persist: false, anonymous: true },\n pendingApprovalCount: { persist: false, anonymous: false },\n approvalFlows: { persist: false, anonymous: false },\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 | null;\n\ntype ApprovalRequestState = Record | 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 = {\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>>;\n pendingApprovalCount: number;\n approvalFlows: ApprovalFlowState[];\n};\n\nexport type ApprovalControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n ApprovalControllerActions,\n ApprovalControllerEvents,\n never,\n never\n>;\n\n// Option Types\n\nexport type ShowApprovalRequest = () => void | Promise;\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;\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;\n typesExcludedFromRateLimiting?: string[];\n};\n\nexport type AddApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record;\n requestState?: Record;\n expectsResult?: boolean;\n};\n\nexport type UpdateRequestStateOptions = {\n id: string;\n requestState: Record;\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\nexport type StartFlowOptions = OptionalField<\n ApprovalFlow,\n 'id' | 'loadingText'\n> & { show?: boolean };\n\nexport type EndFlowOptions = Pick;\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;\n\nexport type ErrorResult = Record;\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) => void;\n};\n\nexport type AddApprovalRequest = {\n type: `${typeof controllerName}:addRequest`;\n handler: (\n opts: AddApprovalOptions,\n shouldShowRequest: boolean,\n ) => ReturnType;\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 #approvals: Map;\n\n #origins: Map>;\n\n #showApprovalRequest: () => void;\n\n #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 controller 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.messagingSystem.registerActionHandler(\n `${controllerName}:clearRequests` as const,\n this.clear.bind(this),\n );\n\n this.messagingSystem.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.messagingSystem.registerActionHandler(\n `${controllerName}:hasRequest` as const,\n this.has.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:acceptRequest` as const,\n this.accept.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:rejectRequest` as const,\n this.reject.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateRequestState` as const,\n this.updateRequestState.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:startFlow` as const,\n this.startFlow.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:endFlow` as const,\n this.endFlow.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setFlowLoadingText` as const,\n this.setFlowLoadingText.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:showSuccess` as const,\n this.success.bind(this),\n );\n\n this.messagingSystem.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;\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;\n\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise {\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;\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;\n\n add(opts: AddApprovalOptions): Promise {\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 | 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 // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\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 {\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;\n const requestPromise = this.#deleteApprovalAndGetCallbacks(id);\n\n return new Promise((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 });\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 this.#deleteApprovalAndGetCallbacks(id).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): 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 {\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);\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 {\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);\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,\n requestState?: Record,\n expectsResult?: boolean,\n ): Promise {\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,\n requestState?: Record,\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,\n requestState?: Record,\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. The approval promise must be\n * resolved or reject before this method is called.\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 this.#approvals.delete(id);\n\n // This method is only called after verifying that the approval with the\n // specified id exists.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { origin, type } = this.state.pendingApprovals[id]!;\n\n const originMap = this.#origins.get(origin) as Map;\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 /**\n * Gets the approval callbacks for the given id, deletes the entry, and then\n * returns the callbacks for promise resolution.\n * Throws an error if no approval is found for the given id.\n *\n * @param id - The id of the approval request.\n * @returns The promise callbacks associated with the approval request.\n */\n #deleteApprovalAndGetCallbacks(id: string): ApprovalCallbacks {\n const callbacks = this.#approvals.get(id);\n if (!callbacks) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n this.#delete(id);\n return callbacks;\n }\n\n async #result(\n type: string,\n opts: ResultOptions,\n requestData: Record,\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"],"mappings":";;;;;;;;;;;;;AACA;AAAA,EACE;AAAA,OAGK;AAEP,SAAS,iBAAiB;AAE1B,SAAS,cAAc;AAahB,IAAM,kBAAkB;AACxB,IAAM,6BAA6B;AACnC,IAAM,+BAA+B;AAE5C,IAAM,iBAAiB;AAEvB,IAAM,gBAAgB;AAAA,EACpB,kBAAkB,EAAE,SAAS,OAAO,WAAW,KAAK;AAAA,EACpD,sBAAsB,EAAE,SAAS,OAAO,WAAW,MAAM;AAAA,EACzD,eAAe,EAAE,SAAS,OAAO,WAAW,MAAM;AACpD;AAEA,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AM,IAAI,6BAA6B,EAAE;AAAA,EAC3C;AAEA,wBAAK,oBAAL,WAAa;AACb,SAAO;AACT;AAEM;AAAA,YAAO,eACX,MACA,MACA,aACA;AACA,MAAI;AACF,UAAM,KAAK,0BAA0B;AAAA,MACnC,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,SAAS,OAAO;AACd,YAAQ,KAAK,iCAAiC,KAAK;AAAA,EACrD,UAAE;AACA,QAAI,KAAK,WAAW;AAClB,UAAI;AACF,aAAK,QAAQ,EAAE,IAAI,KAAK,UAAU,CAAC;AAAA,MACrC,SAAS,OAAO;AACd,gBAAQ,KAAK,sBAAsB,EAAE,IAAI,KAAK,WAAW,MAAM,CAAC;AAAA,MAClE;AAAA,IACF;AAAA,EACF;AACF;AAGF,IAAO,6BAAQ;","names":[]} -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/chunk-PMXPCCKS.js.map b/node_modules/@metamask/approval-controller/dist/chunk-PMXPCCKS.js.map -deleted file mode 100644 -index 3bf157a..0000000 ---- a/node_modules/@metamask/approval-controller/dist/chunk-PMXPCCKS.js.map -+++ /dev/null -@@ -1 +0,0 @@ --{"version":3,"sources":["../src/ApprovalController.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA;AAAA,EACE;AAAA,OAGK;AAEP,SAAS,iBAAiB;AAE1B,SAAS,cAAc;AAahB,IAAM,kBAAkB;AACxB,IAAM,6BAA6B;AACnC,IAAM,+BAA+B;AAE5C,IAAM,iBAAiB;AAEvB,IAAM,gBAAgB;AAAA,EACpB,kBAAkB,EAAE,SAAS,OAAO,WAAW,KAAK;AAAA,EACpD,sBAAsB,EAAE,SAAS,OAAO,WAAW,MAAM;AAAA,EACzD,eAAe,EAAE,SAAS,OAAO,WAAW,MAAM;AACpD;AAEA,IAAM,2BAA2B,CAAC,QAAgB,SAChD,oBAAoB,IAAI,gCAAgC,MAAM;AAEhE,IAAM,kBAAkB,MAA+B;AACrD,SAAO;AA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,MACA,aACA;AACA,MAAI;AACF,UAAM,KAAK,0BAA0B;AAAA,MACnC,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,SAAS,OAAO;AACd,YAAQ,KAAK,iCAAiC,KAAK;AAAA,EACrD,UAAE;AACA,QAAI,KAAK,WAAW;AAClB,UAAI;AACF,aAAK,QAAQ,EAAE,IAAI,KAAK,UAAU,CAAC;AAAA,MACrC,SAAS,OAAO;AACd,gBAAQ,KAAK,sBAAsB,EAAE,IAAI,KAAK,WAAW,MAAM,CAAC;AAAA,MAClE;AAAA,IACF;AAAA,EACF;AACF;AAGF,IAAO,6BAAQ","sourcesContent":["import type { ControllerGetStateAction } from '@metamask/base-controller';\nimport {\n BaseController,\n type ControllerStateChangeEvent,\n type RestrictedControllerMessenger,\n} from '@metamask/base-controller';\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 = {\n pendingApprovals: { persist: false, anonymous: true },\n pendingApprovalCount: { persist: false, anonymous: false },\n approvalFlows: { persist: false, anonymous: false },\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 | null;\n\ntype ApprovalRequestState = Record | 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 = {\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>>;\n pendingApprovalCount: number;\n approvalFlows: ApprovalFlowState[];\n};\n\nexport type ApprovalControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n ApprovalControllerActions,\n ApprovalControllerEvents,\n never,\n never\n>;\n\n// Option Types\n\nexport type ShowApprovalRequest = () => void | Promise;\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;\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;\n typesExcludedFromRateLimiting?: string[];\n};\n\nexport type AddApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record;\n requestState?: Record;\n expectsResult?: boolean;\n};\n\nexport type UpdateRequestStateOptions = {\n id: string;\n requestState: Record;\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\nexport type StartFlowOptions = OptionalField<\n ApprovalFlow,\n 'id' | 'loadingText'\n> & { show?: boolean };\n\nexport type EndFlowOptions = Pick;\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;\n\nexport type ErrorResult = Record;\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) => void;\n};\n\nexport type AddApprovalRequest = {\n type: `${typeof controllerName}:addRequest`;\n handler: (\n opts: AddApprovalOptions,\n shouldShowRequest: boolean,\n ) => ReturnType;\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 #approvals: Map;\n\n #origins: Map>;\n\n #showApprovalRequest: () => void;\n\n #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 controller 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.messagingSystem.registerActionHandler(\n `${controllerName}:clearRequests` as const,\n this.clear.bind(this),\n );\n\n this.messagingSystem.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.messagingSystem.registerActionHandler(\n `${controllerName}:hasRequest` as const,\n this.has.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:acceptRequest` as const,\n this.accept.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:rejectRequest` as const,\n this.reject.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateRequestState` as const,\n this.updateRequestState.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:startFlow` as const,\n this.startFlow.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:endFlow` as const,\n this.endFlow.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setFlowLoadingText` as const,\n this.setFlowLoadingText.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:showSuccess` as const,\n this.success.bind(this),\n );\n\n this.messagingSystem.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;\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;\n\n addAndShowApprovalRequest(opts: AddApprovalOptions): Promise {\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;\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;\n\n add(opts: AddApprovalOptions): Promise {\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 | 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 // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\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 {\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;\n const requestPromise = this.#deleteApprovalAndGetCallbacks(id);\n\n return new Promise((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 });\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 this.#deleteApprovalAndGetCallbacks(id).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): 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 {\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);\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 {\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);\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,\n requestState?: Record,\n expectsResult?: boolean,\n ): Promise {\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,\n requestState?: Record,\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,\n requestState?: Record,\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. The approval promise must be\n * resolved or reject before this method is called.\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 this.#approvals.delete(id);\n\n // This method is only called after verifying that the approval with the\n // specified id exists.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { origin, type } = this.state.pendingApprovals[id]!;\n\n const originMap = this.#origins.get(origin) as Map;\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 /**\n * Gets the approval callbacks for the given id, deletes the entry, and then\n * returns the callbacks for promise resolution.\n * Throws an error if no approval is found for the given id.\n *\n * @param id - The id of the approval request.\n * @returns The promise callbacks associated with the approval request.\n */\n #deleteApprovalAndGetCallbacks(id: string): ApprovalCallbacks {\n const callbacks = this.#approvals.get(id);\n if (!callbacks) {\n throw new ApprovalRequestNotFoundError(id);\n }\n\n this.#delete(id);\n return callbacks;\n }\n\n async #result(\n type: string,\n opts: ResultOptions,\n requestData: Record,\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"]} -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/errors.js.map b/node_modules/@metamask/approval-controller/dist/errors.js.map -deleted file mode 100644 -index a464c67..0000000 ---- a/node_modules/@metamask/approval-controller/dist/errors.js.map -+++ /dev/null -@@ -1 +0,0 @@ --{"version":3,"sources":[],"names":[],"mappings":""} -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/errors.mjs.map b/node_modules/@metamask/approval-controller/dist/errors.mjs.map -deleted file mode 100644 -index 84c51b2..0000000 ---- a/node_modules/@metamask/approval-controller/dist/errors.mjs.map -+++ /dev/null -@@ -1 +0,0 @@ --{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]} -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/index.js b/node_modules/@metamask/approval-controller/dist/index.js -index 59a39d3..e1c5c4d 100644 ---- a/node_modules/@metamask/approval-controller/dist/index.js -+++ b/node_modules/@metamask/approval-controller/dist/index.js -@@ -3,7 +3,7 @@ - - - --var _chunkPMXPCCKSjs = require('./chunk-PMXPCCKS.js'); -+var _chunkNONDXCHJjs = require('./chunk-NONDXCHJ.js'); - - - -@@ -21,5 +21,5 @@ var _chunkLKCXZAKDjs = require('./chunk-LKCXZAKD.js'); - - - --exports.APPROVAL_TYPE_RESULT_ERROR = _chunkPMXPCCKSjs.APPROVAL_TYPE_RESULT_ERROR; exports.APPROVAL_TYPE_RESULT_SUCCESS = _chunkPMXPCCKSjs.APPROVAL_TYPE_RESULT_SUCCESS; exports.ApprovalController = _chunkPMXPCCKSjs.ApprovalController; exports.ApprovalRequestNoResultSupportError = _chunkLKCXZAKDjs.ApprovalRequestNoResultSupportError; exports.ApprovalRequestNotFoundError = _chunkLKCXZAKDjs.ApprovalRequestNotFoundError; exports.EndInvalidFlowError = _chunkLKCXZAKDjs.EndInvalidFlowError; exports.MissingApprovalFlowError = _chunkLKCXZAKDjs.MissingApprovalFlowError; exports.NoApprovalFlowsError = _chunkLKCXZAKDjs.NoApprovalFlowsError; exports.ORIGIN_METAMASK = _chunkPMXPCCKSjs.ORIGIN_METAMASK; -+exports.APPROVAL_TYPE_RESULT_ERROR = _chunkNONDXCHJjs.APPROVAL_TYPE_RESULT_ERROR; exports.APPROVAL_TYPE_RESULT_SUCCESS = _chunkNONDXCHJjs.APPROVAL_TYPE_RESULT_SUCCESS; exports.ApprovalController = _chunkNONDXCHJjs.ApprovalController; exports.ApprovalRequestNoResultSupportError = _chunkLKCXZAKDjs.ApprovalRequestNoResultSupportError; exports.ApprovalRequestNotFoundError = _chunkLKCXZAKDjs.ApprovalRequestNotFoundError; exports.EndInvalidFlowError = _chunkLKCXZAKDjs.EndInvalidFlowError; exports.MissingApprovalFlowError = _chunkLKCXZAKDjs.MissingApprovalFlowError; exports.NoApprovalFlowsError = _chunkLKCXZAKDjs.NoApprovalFlowsError; exports.ORIGIN_METAMASK = _chunkNONDXCHJjs.ORIGIN_METAMASK; - //# sourceMappingURL=index.js.map -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/index.js.map b/node_modules/@metamask/approval-controller/dist/index.js.map -deleted file mode 100644 -index a464c67..0000000 ---- a/node_modules/@metamask/approval-controller/dist/index.js.map -+++ /dev/null -@@ -1 +0,0 @@ --{"version":3,"sources":[],"names":[],"mappings":""} -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/index.mjs b/node_modules/@metamask/approval-controller/dist/index.mjs -index c1c5b95..c482411 100644 ---- a/node_modules/@metamask/approval-controller/dist/index.mjs -+++ b/node_modules/@metamask/approval-controller/dist/index.mjs -@@ -3,7 +3,7 @@ import { - APPROVAL_TYPE_RESULT_SUCCESS, - ApprovalController, - ORIGIN_METAMASK --} from "./chunk-PIJZDVKC.mjs"; -+} from "./chunk-CZANKQ6E.mjs"; - import { - ApprovalRequestNoResultSupportError, - ApprovalRequestNotFoundError, -diff --git a/node_modules/@metamask/approval-controller/dist/index.mjs.map b/node_modules/@metamask/approval-controller/dist/index.mjs.map -deleted file mode 100644 -index 84c51b2..0000000 ---- a/node_modules/@metamask/approval-controller/dist/index.mjs.map -+++ /dev/null -@@ -1 +0,0 @@ --{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]} -\ No newline at end of file -diff --git a/node_modules/@metamask/approval-controller/dist/types/ApprovalController.d.ts b/node_modules/@metamask/approval-controller/dist/types/ApprovalController.d.ts -index 2b9ad4d..26efec3 100644 ---- a/node_modules/@metamask/approval-controller/dist/types/ApprovalController.d.ts -+++ b/node_modules/@metamask/approval-controller/dist/types/ApprovalController.d.ts -@@ -101,6 +101,12 @@ export type AcceptOptions = { - * If false or unspecified, the promise will resolve immediately. - */ - waitForResult?: boolean; -+ /** -+ * Patch for #10758 -+ * provide the AcceptOptions with extra options which have been used in `engine.acceptPendingApproval()` function in mobile. -+ * the metamask mobile already patch the AprrovalControll.accept() function to accept the extra options. -+ */ -+ deleteAfterResult?: boolean; - }; - export type StartFlowOptions = OptionalField & { - show?: boolean; diff --git a/scripts/generate-attributions/package.json b/scripts/generate-attributions/package.json index e260d5a2f83..ae90d1c2b5e 100644 --- a/scripts/generate-attributions/package.json +++ b/scripts/generate-attributions/package.json @@ -12,7 +12,7 @@ "@metamask/oss-attribution-generator": "^2.0.2" }, "engines": { - "node": "^20.12.2", + "node": "^20.14.0", "yarn": "^1.22.0" }, "lavamoat": { diff --git a/yarn.lock b/yarn.lock index cfc7baf393b..ddd7f1392d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4320,12 +4320,12 @@ "@metamask/controller-utils" "^11.3.0" "@metamask/utils" "^9.1.0" -"@metamask/approval-controller@^7.0.0", "@metamask/approval-controller@^7.0.1", "@metamask/approval-controller@^7.0.2": - version "7.0.2" - resolved "https://registry.yarnpkg.com/@metamask/approval-controller/-/approval-controller-7.0.2.tgz#bf46090fb900a5687b93978fb93eb3cf61d39a56" - integrity sha512-cjCXpdxQ1IzmNrfTtw0MpYcBDklzvWcyRz5AutvlBaLafrWh2FDQZFvofd/rO49DdrvAxEQHUt6GXE9aFjCFTQ== +"@metamask/approval-controller@^7.0.0", "@metamask/approval-controller@^7.0.2", "@metamask/approval-controller@^7.1.0": + version "7.1.0" + resolved "https://registry.yarnpkg.com/@metamask/approval-controller/-/approval-controller-7.1.0.tgz#34b07bc4eaf6938b15f9d915c6885d4a5c0a5205" + integrity sha512-dhqUeX8wMzW88U+Vgr7oKf0Vouol10ncB3lxmvWyC1VZJhSOdO3VUkn0tH1lzt3ybxYVMOkPaB3gfdksfnNRyA== dependencies: - "@metamask/base-controller" "^6.0.2" + "@metamask/base-controller" "^7.0.1" "@metamask/rpc-errors" "^6.3.1" "@metamask/utils" "^9.1.0" nanoid "^3.1.31" @@ -4642,6 +4642,18 @@ ethereum-cryptography "^2.1.2" tweetnacl "^1.0.3" +"@metamask/eth-sig-util@^8.0.0": + version "8.0.0" + resolved "https://registry.yarnpkg.com/@metamask/eth-sig-util/-/eth-sig-util-8.0.0.tgz#6310d93cd1101cab3cc6bc2a1ff526290ed2695b" + integrity sha512-IwE6aoxUL39IhmsAgE4nk+OZbNo+ThFZRNsUjE1pjdEa4MFpWzm1Rue4zJ5DMy1oUyZBi/aiCLMhdMnjl2bh2Q== + dependencies: + "@ethereumjs/util" "^8.1.0" + "@metamask/abi-utils" "^2.0.4" + "@metamask/utils" "^9.0.0" + "@scure/base" "~1.1.3" + ethereum-cryptography "^2.1.2" + tweetnacl "^1.0.3" + "@metamask/eth-simple-keyring@^6.0.5": version "6.0.5" resolved "https://registry.yarnpkg.com/@metamask/eth-simple-keyring/-/eth-simple-keyring-6.0.5.tgz#3e2f783092f9d873740e43852880216192802290" @@ -5336,16 +5348,18 @@ "@metamask/swappable-obj-proxy" "^2.2.0" "@metamask/utils" "^8.3.0" -"@metamask/signature-controller@^19.1.0": - version "19.1.0" - resolved "https://registry.yarnpkg.com/@metamask/signature-controller/-/signature-controller-19.1.0.tgz#47c7435f51d3273fb5a0373f4ebdcfccb6d490a9" - integrity sha512-1rDKxV7HYoKZjBbqkeWLk3TLJJcl8cRgAkPTG8jMRIp7eYW2vUxo5nsiaJlBBHDV/fbjR12SbiawMjj93zD2DA== +"@metamask/signature-controller@^20.1.0": + version "20.1.0" + resolved "https://registry.yarnpkg.com/@metamask/signature-controller/-/signature-controller-20.1.0.tgz#b2ab41ec6eb191f9b21a74bf636d2b8e34d590e0" + integrity sha512-29pYdr9Q5YB5tGrYLEkpCh3l41W5Otg87cQ+cRf7Je0xGo34VdrIHNv6MJQcEgng5qTmR0tG3Hq23nPyZo8rSw== dependencies: "@metamask/base-controller" "^7.0.1" "@metamask/controller-utils" "^11.3.0" - "@metamask/message-manager" "^10.1.1" + "@metamask/eth-sig-util" "^8.0.0" "@metamask/utils" "^9.1.0" + jsonschema "^1.2.4" lodash "^4.17.21" + uuid "^8.3.2" "@metamask/slip44@3.1.0", "@metamask/slip44@^3.1.0": version "3.1.0"