@metamask-previews/message-manager 13.0.1-preview-ab0ad568 → 13.0.2-preview-ebf01f52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,10 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [13.0.2]
11
+
10
12
  ### Changed
11
13
 
12
- - **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6545](https://github.com/MetaMask/core/pull/6545))
13
- - Previously, `AbstractMessageManager`, `DecryptMessageManager` and `EncryptionPublicKeyManager` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
14
14
  - Bump `@metamask/base-controller` from `^8.4.1` to `^8.4.2` ([#6917](https://github.com/MetaMask/core/pull/6917))
15
15
 
16
16
  ## [13.0.1]
@@ -405,7 +405,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
405
405
 
406
406
  All changes listed after this point were applied to this package following the monorepo conversion.
407
407
 
408
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/message-manager@13.0.1...HEAD
408
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/message-manager@13.0.2...HEAD
409
+ [13.0.2]: https://github.com/MetaMask/core/compare/@metamask/message-manager@13.0.1...@metamask/message-manager@13.0.2
409
410
  [13.0.1]: https://github.com/MetaMask/core/compare/@metamask/message-manager@13.0.0...@metamask/message-manager@13.0.1
410
411
  [13.0.0]: https://github.com/MetaMask/core/compare/@metamask/message-manager@12.0.2...@metamask/message-manager@13.0.0
411
412
  [12.0.2]: https://github.com/MetaMask/core/compare/@metamask/message-manager@12.0.1...@metamask/message-manager@12.0.2
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractMessageManager = void 0;
4
- const next_1 = require("@metamask/base-controller/next");
4
+ const base_controller_1 = require("@metamask/base-controller");
5
5
  // This package purposefully relies on Node's EventEmitter module.
6
6
  // eslint-disable-next-line import-x/no-nodejs-modules
7
7
  const events_1 = require("events");
@@ -10,13 +10,13 @@ const stateMetadata = {
10
10
  unapprovedMessages: {
11
11
  includeInStateLogs: true,
12
12
  persist: false,
13
- includeInDebugSnapshot: false,
13
+ anonymous: false,
14
14
  usedInUi: true,
15
15
  },
16
16
  unapprovedMessagesCount: {
17
17
  includeInStateLogs: true,
18
18
  persist: false,
19
- includeInDebugSnapshot: false,
19
+ anonymous: false,
20
20
  usedInUi: true,
21
21
  },
22
22
  };
@@ -27,7 +27,7 @@ const getDefaultState = () => ({
27
27
  /**
28
28
  * Controller in charge of managing - storing, adding, removing, updating - Messages.
29
29
  */
30
- class AbstractMessageManager extends next_1.BaseController {
30
+ class AbstractMessageManager extends base_controller_1.BaseController {
31
31
  constructor({ additionalFinishStatuses, messenger, name, securityProviderRequest, state = {}, }) {
32
32
  super({
33
33
  messenger,
@@ -44,7 +44,7 @@ class AbstractMessageManager extends next_1.BaseController {
44
44
  this.additionalFinishStatuses = additionalFinishStatuses ?? [];
45
45
  }
46
46
  /**
47
- * Adds request props to the message params and returns a new messageParams object.
47
+ * Adds request props to the messsage params and returns a new messageParams object.
48
48
  * @param messageParams - The messageParams to add the request props to.
49
49
  * @param req - The original request object.
50
50
  * @returns The messageParams with the request props added.
@@ -89,7 +89,7 @@ class AbstractMessageManager extends next_1.BaseController {
89
89
  state.unapprovedMessagesCount = this.getUnapprovedMessagesCount();
90
90
  });
91
91
  if (emitUpdateBadge) {
92
- this.messenger.publish(`${this.name}:updateBadge`);
92
+ this.messagingSystem.publish(`${this.name}:updateBadge`);
93
93
  }
94
94
  }
95
95
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractMessageManager.cjs","sourceRoot":"","sources":["../src/AbstractMessageManager.ts"],"names":[],"mappings":";;;AAAA,yDAIwC;AAQxC,kEAAkE;AAClE,sDAAsD;AACtD,mCAAsC;AAEtC,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E;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CACtB,GAAG,SAAmB,WAAW,EACjC,CAAC,IAAqB,EAAE,EAAE;gBACxB,QAAQ,IAAI,CAAC,MAAM,EAAE;oBACnB,KAAK,QAAQ;wBACX,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;oBACxC,KAAK,UAAU;wBACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,YAAY,WAAW,4CAA4C,CACpE,CACF,CAAC;oBACJ,KAAK,SAAS;wBACZ,OAAO,MAAM,CACX,IAAI,KAAK,CACP,YAAY,WAAW,eAAe,IAAI,CAAC,KAAe,EAAE,CAC7D,CACF,CAAC;oBACJ;wBACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,YAAY,WAAW,gCAAgC,IAAI,CAAC,SAAS,CACnE,aAAa,CACd,EAAE,CACJ,CACF,CAAC;iBACL;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AApaD,wDAoaC;AAED,kBAAe,sBAAsB,CAAC","sourcesContent":["import {\n BaseController,\n type ControllerStateChangeEvent,\n type ControllerGetStateAction,\n} from '@metamask/base-controller/next';\nimport type { ApprovalType } from '@metamask/controller-utils';\nimport type {\n Messenger,\n EventConstraint,\n ActionConstraint,\n} from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport { EventEmitter } from 'events';\nimport type { Draft } from 'immer';\nimport { v1 as random } from 'uuid';\n\nconst stateMetadata = {\n unapprovedMessages: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n unapprovedMessagesCount: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = () => ({\n unapprovedMessages: {},\n unapprovedMessagesCount: 0,\n});\n\n/**\n * @type OriginalRequest\n *\n * Represents the original request object for adding a message.\n * @property origin? - Is it is specified, represents the origin\n */\nexport type OriginalRequest = {\n id?: number;\n origin?: string;\n securityAlertResponse?: Record<string, Json>;\n};\n\n/**\n * @type AbstractMessage\n *\n * Represents and contains data about a signing type signature request.\n * @property id - An id to track and identify the message object\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'Message' which always has a signing type\n * @property rawSig - Raw data of the signature request\n * @property securityProviderResponse - Response from a security provider, whether it is malicious or not\n * @property metadata - Additional data for the message, for example external identifiers\n */\nexport type AbstractMessage = {\n id: string;\n time: number;\n status: string;\n type: string;\n rawSig?: string;\n securityProviderResponse?: Record<string, Json>;\n securityAlertResponse?: Record<string, Json>;\n metadata?: Json;\n error?: string;\n};\n\n/**\n * @type AbstractMessageParams\n *\n * Represents the parameters to pass to the signing method once the signature request is approved.\n * @property from - Address from which the message is processed\n * @property origin? - Added for request origin identification\n * @property requestId? - Original request id\n * @property deferSetAsSigned? - Whether to defer setting the message as signed immediately after the keyring is told to sign it\n */\nexport type AbstractMessageParams = {\n from: string;\n origin?: string;\n requestId?: number;\n deferSetAsSigned?: boolean;\n};\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the signing method once the signature request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property from - Address from which the message is processed\n * @property origin? - Added for request origin identification\n */\nexport type AbstractMessageParamsMetamask = AbstractMessageParams & {\n metamaskId?: string;\n};\n\n/**\n * @type MessageManagerState\n *\n * Message Manager state\n * @property unapprovedMessages - A collection of all Messages in the 'unapproved' state\n * @property unapprovedMessagesCount - The count of all Messages in this.unapprovedMessages\n */\nexport type MessageManagerState<Message extends AbstractMessage> = {\n unapprovedMessages: Record<string, Message>;\n unapprovedMessagesCount: number;\n};\n\nexport type UpdateBadgeEvent<Namespace extends string> = {\n type: `${Namespace}:updateBadge`;\n payload: [];\n};\n\n/**\n * A function for verifying a message, whether it is malicious or not\n */\nexport type SecurityProviderRequest = (\n requestData: AbstractMessage,\n messageType: string,\n) => Promise<Json>;\n\n/**\n * AbstractMessageManager constructor options.\n *\n * @property additionalFinishStatuses - Optional list of statuses that are accepted to emit a finished event.\n * @property messenger - Controller messaging system.\n * @property name - The name of the manager.\n * @property securityProviderRequest - A function for verifying a message, whether it is malicious or not.\n * @property state - Initial state to set on this controller.\n */\nexport type AbstractMessageManagerOptions<\n Name extends string,\n Message extends AbstractMessage,\n MessageManagerMessenger extends Messenger<\n Name,\n | ControllerGetStateAction<Name, MessageManagerState<Message>>\n | ActionConstraint,\n | ControllerStateChangeEvent<Name, MessageManagerState<Message>>\n | UpdateBadgeEvent<Name>\n | EventConstraint\n >,\n> = {\n additionalFinishStatuses?: string[];\n messenger: MessageManagerMessenger;\n name: Name;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<Message>;\n};\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport abstract class AbstractMessageManager<\n Name extends string,\n Message extends AbstractMessage,\n Params extends AbstractMessageParams,\n ParamsMetamask extends AbstractMessageParamsMetamask,\n MessageManagerMessenger extends Messenger<\n Name,\n | ControllerGetStateAction<Name, MessageManagerState<Message>>\n | ActionConstraint,\n | ControllerStateChangeEvent<Name, MessageManagerState<Message>>\n | UpdateBadgeEvent<Name>\n | EventConstraint\n >,\n> extends BaseController<\n Name,\n MessageManagerState<Message>,\n MessageManagerMessenger\n> {\n protected messages: Message[];\n\n private readonly securityProviderRequest: SecurityProviderRequest | undefined;\n\n private readonly additionalFinishStatuses: string[];\n\n internalEvents = new EventEmitter();\n\n constructor({\n additionalFinishStatuses,\n messenger,\n name,\n securityProviderRequest,\n state = {} as MessageManagerState<Message>,\n }: AbstractMessageManagerOptions<Name, Message, MessageManagerMessenger>) {\n super({\n messenger,\n metadata: stateMetadata,\n name,\n state: {\n ...getDefaultState(),\n ...state,\n },\n });\n this.messages = [];\n this.securityProviderRequest = securityProviderRequest;\n this.additionalFinishStatuses = additionalFinishStatuses ?? [];\n }\n\n /**\n * Adds request props to the message params and returns a new messageParams object.\n * @param messageParams - The messageParams to add the request props to.\n * @param req - The original request object.\n * @returns The messageParams with the request props added.\n */\n protected addRequestToMessageParams<\n MessageParams extends AbstractMessageParams,\n >(messageParams: MessageParams, req?: OriginalRequest) {\n const updatedMessageParams = {\n ...messageParams,\n };\n\n if (req) {\n updatedMessageParams.requestId = req.id;\n updatedMessageParams.origin = req.origin;\n }\n\n return updatedMessageParams;\n }\n\n /**\n * Creates a new Message with a random id and an 'unapproved' status.\n * @param messageParams - The messageParams to add the request props to.\n * @param type - The approval type of the message.\n * @param req - The original request object.\n * @returns The new unapproved message for a specified type.\n */\n protected createUnapprovedMessage<\n MessageParams extends AbstractMessageParams,\n >(messageParams: MessageParams, type: ApprovalType, req?: OriginalRequest) {\n const messageId = random();\n\n return {\n id: messageId,\n messageParams,\n securityAlertResponse: req?.securityAlertResponse,\n status: 'unapproved',\n time: Date.now(),\n type,\n };\n }\n\n /**\n * Saves the unapproved messages, and their count to state.\n *\n * @param emitUpdateBadge - Whether to emit the updateBadge event.\n */\n protected saveMessageList(emitUpdateBadge = true) {\n this.update((state) => {\n state.unapprovedMessages =\n this.getUnapprovedMessages() as unknown as Record<\n string,\n Draft<Message>\n >;\n state.unapprovedMessagesCount = this.getUnapprovedMessagesCount();\n });\n if (emitUpdateBadge) {\n this.messenger.publish(`${this.name}:updateBadge` as const);\n }\n }\n\n /**\n * Updates the status of a Message in this.messages.\n *\n * @param messageId - The id of the Message to update.\n * @param status - The new status of the Message.\n */\n protected setMessageStatus(messageId: string, status: string) {\n const message = this.getMessage(messageId);\n if (!message) {\n throw new Error(\n `${this.name as string}: Message not found for id: ${messageId}.`,\n );\n }\n const updatedMessage = {\n ...message,\n status,\n };\n this.updateMessage(updatedMessage);\n this.internalEvents.emit(`${messageId}:${status}`, updatedMessage);\n if (\n status === 'rejected' ||\n status === 'signed' ||\n status === 'errored' ||\n this.additionalFinishStatuses.includes(status)\n ) {\n this.internalEvents.emit(\n `${messageId as string}:finished`,\n updatedMessage,\n );\n }\n }\n\n /**\n * Sets a Message in this.messages to the passed Message if the ids are equal.\n * Then saves the unapprovedMessage list to storage.\n *\n * @param message - A Message that will replace an existing Message (with the id) in this.messages.\n * @param emitUpdateBadge - Whether to emit the updateBadge event.\n */\n protected updateMessage(message: Message, emitUpdateBadge = true) {\n const index = this.messages.findIndex((msg) => message.id === msg.id);\n /* istanbul ignore next */\n if (index !== -1) {\n this.messages[index] = message;\n }\n this.saveMessageList(emitUpdateBadge);\n }\n\n /**\n * Verifies a message is malicious or not by checking it against a security provider.\n *\n * @param message - The message to verify.\n * @returns A promise that resolves to a secured message with additional security provider response data.\n */\n private async securityCheck(message: Message): Promise<Message> {\n if (this.securityProviderRequest) {\n const securityProviderResponse = await this.securityProviderRequest(\n message,\n message.type,\n );\n return {\n ...message,\n securityProviderResponse,\n };\n }\n return message;\n }\n\n clearUnapprovedMessages() {\n this.update((state) => {\n state.unapprovedMessages = {};\n state.unapprovedMessagesCount = 0;\n });\n }\n\n /**\n * A getter for the number of 'unapproved' Messages in this.messages.\n *\n * @returns The number of 'unapproved' Messages in this.messages.\n */\n getUnapprovedMessagesCount() {\n return Object.keys(this.getUnapprovedMessages()).length;\n }\n\n /**\n * A getter for the 'unapproved' Messages in state messages.\n *\n * @returns An index of Message ids to Messages, for all 'unapproved' Messages in this.messages.\n */\n getUnapprovedMessages() {\n return this.messages\n .filter((message) => message.status === 'unapproved')\n .reduce((result: Record<string, Message>, message) => {\n result[message.id] = message;\n return result;\n }, {});\n }\n\n /**\n * Adds a passed Message to this.messages, and calls this.saveMessageList() to save\n * the unapproved Messages from that list to this.messages.\n *\n * @param message - The Message to add to this.messages.\n */\n async addMessage(message: Message) {\n const securedMessage = await this.securityCheck(message);\n this.messages.push(securedMessage);\n this.saveMessageList();\n }\n\n /**\n * Returns a specified Message.\n *\n * @param messageId - The id of the Message to get.\n * @returns The Message with the id that matches the passed messageId, or undefined\n * if no Message has that id.\n */\n getMessage(messageId: string) {\n return this.messages.find((message) => message.id === messageId);\n }\n\n /**\n * Returns all the messages.\n *\n * @returns An array of messages.\n */\n getAllMessages() {\n return this.messages;\n }\n\n /**\n * Approves a Message. Sets the message status via a call to this.setMessageStatusApproved,\n * and returns a promise with any the message params modified for proper signing.\n *\n * @param messageParams - The messageParams to be used when signing method is called,\n * plus data added by MetaMask.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n approveMessage(messageParams: ParamsMetamask): Promise<Params> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.setMessageStatusApproved(messageParams.metamaskId);\n return this.prepMessageForSigning(messageParams);\n }\n\n /**\n * Sets a Message status to 'approved' via a call to this.setMessageStatus.\n *\n * @param messageId - The id of the Message to approve.\n */\n setMessageStatusApproved(messageId: string) {\n this.setMessageStatus(messageId, 'approved');\n }\n\n /**\n * Sets message status to inProgress in order to allow users to use extension\n * while waiting for a custodian signature.\n *\n * @param messageId - The id of the message to set to inProgress\n */\n setMessageStatusInProgress(messageId: string) {\n this.setMessageStatus(messageId, 'inProgress');\n }\n\n /**\n * Sets a Message status to 'signed' via a call to this.setMessageStatus and updates\n * that Message in this.messages by adding the raw signature data of the signature\n * request to the Message.\n *\n * @param messageId - The id of the Message to sign.\n * @param rawSig - The raw data of the signature request.\n */\n setMessageStatusSigned(messageId: string, rawSig: string) {\n this.setMessageStatusAndResult(messageId, rawSig, 'signed');\n }\n\n /**\n * Sets the message via a call to this.setResult and updates status of the message.\n *\n * @param messageId - The id of the Message to sign.\n * @param rawSig - The data to update rawSig in the message.\n * @param status - The new message status.\n */\n setMessageStatusAndResult(messageId: string, rawSig: string, status: string) {\n this.setResult(messageId, rawSig);\n this.setMessageStatus(messageId, status);\n }\n\n /**\n * Sets the message result.\n *\n * @param messageId - The id of the Message to sign.\n * @param result - The data to update result in the message.\n */\n setResult(messageId: string, result: string) {\n const message = this.getMessage(messageId);\n /* istanbul ignore if */\n if (!message) {\n return;\n }\n this.updateMessage(\n {\n ...message,\n rawSig: result,\n },\n false,\n );\n }\n\n /**\n * Sets the messsage metadata\n *\n * @param messageId - The id of the Message to update\n * @param metadata - The data with which to replace the metadata property in the message\n */\n setMetadata(messageId: string, metadata: Json) {\n const message = this.getMessage(messageId);\n if (!message) {\n throw new Error(\n `${this.name as string}: Message not found for id: ${messageId}.`,\n );\n }\n this.updateMessage(\n {\n ...message,\n metadata,\n },\n false,\n );\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams\n *\n * @param messageParams - The messageParams to modify\n * @returns Promise resolving to the messageParams with the metamaskId property removed\n */\n abstract prepMessageForSigning(\n messageParams: ParamsMetamask,\n ): Promise<Params>;\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - Message parameters for the message to add\n * @param req - The original request object possibly containing the origin.\n * @param version? - The version of the JSON RPC protocol the request is using.\n * @returns The id of the newly created message.\n */\n abstract addUnapprovedMessage(\n messageParams: ParamsMetamask,\n request: OriginalRequest,\n version?: string,\n ): Promise<string>;\n\n /**\n * Sets a Message status to 'rejected' via a call to this.setMessageStatus.\n *\n * @param messageId - The id of the Message to reject.\n */\n rejectMessage(messageId: string) {\n this.setMessageStatus(messageId, 'rejected');\n }\n\n /**\n * Creates a promise which will resolve or reject when the message process is finished.\n *\n * @param messageParamsWithId - The params for the personal_sign call to be made after the message is approved.\n * @param messageName - The name of the message\n * @returns Promise resolving to the raw data of the signature request.\n */\n async waitForFinishStatus(\n messageParamsWithId: AbstractMessageParamsMetamask,\n messageName: string,\n ): Promise<string> {\n const { metamaskId: messageId, ...messageParams } = messageParamsWithId;\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId as string}:finished`,\n (data: AbstractMessage) => {\n switch (data.status) {\n case 'signed':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n `MetaMask ${messageName} Signature: User denied message signature.`,\n ),\n );\n case 'errored':\n return reject(\n new Error(\n `MetaMask ${messageName} Signature: ${data.error as string}`,\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask ${messageName} Signature: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n}\n\nexport default AbstractMessageManager;\n"]}
1
+ {"version":3,"file":"AbstractMessageManager.cjs","sourceRoot":"","sources":["../src/AbstractMessageManager.ts"],"names":[],"mappings":";;;AAAA,+DAA2D;AAQ3D,kEAAkE;AAClE,sDAAsD;AACtD,mCAAsC;AAEtC,+BAAoC;AAEpC,MAAM,aAAa,GAAG;IACpB,kBAAkB,EAAE;QAClB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;QAChB,QAAQ,EAAE,IAAI;KACf;IACD,uBAAuB,EAAE;QACvB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;QAChB,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,CAAC;IAC7B,kBAAkB,EAAE,EAAE;IACtB,uBAAuB,EAAE,CAAC;CAC3B,CAAC,CAAC;AAuHH;;GAEG;AACH,MAAsB,sBAOpB,SAAQ,gCAUT;IASC,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,IAAI,EACJ,uBAAuB,EACvB,KAAK,GAAG,EAAkC,GACkB;QAC5D,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,aAAa;YACvB,IAAI;YACJ,KAAK,EAAE;gBACL,GAAG,eAAe,EAAE;gBACpB,GAAG,KAAK;aACT;SACF,CAAC,CAAC;QAjBL,mBAAc,GAAG,IAAI,qBAAY,EAAE,CAAC;QAkBlC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;QACvD,IAAI,CAAC,wBAAw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,CACN,CAAC;IACJ,CAAC;IA6BD;;;;OAIG;IACH,aAAa,CAAC,SAAiB;QAC7B,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,mBAAmB,CACvB,mBAAkD,EAClD,WAAmB;QAEnB,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,aAAa,EAAE,GAAG,mBAAmB,CAAC;QACxE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CACtB,GAAG,SAAmB,WAAW,EACjC,CAAC,IAAqB,EAAE,EAAE;gBACxB,QAAQ,IAAI,CAAC,MAAM,EAAE;oBACnB,KAAK,QAAQ;wBACX,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;oBACxC,KAAK,UAAU;wBACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,YAAY,WAAW,4CAA4C,CACpE,CACF,CAAC;oBACJ,KAAK,SAAS;wBACZ,OAAO,MAAM,CACX,IAAI,KAAK,CACP,YAAY,WAAW,eAAe,IAAI,CAAC,KAAe,EAAE,CAC7D,CACF,CAAC;oBACJ;wBACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,YAAY,WAAW,gCAAgC,IAAI,CAAC,SAAS,CACnE,aAAa,CACd,EAAE,CACJ,CACF,CAAC;iBACL;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AApaD,wDAoaC;AAED,kBAAe,sBAAsB,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ActionConstraint,\n EventConstraint,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { ApprovalType } from '@metamask/controller-utils';\nimport type { Json } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport { EventEmitter } from 'events';\nimport type { Draft } from 'immer';\nimport { v1 as random } from 'uuid';\n\nconst stateMetadata = {\n unapprovedMessages: {\n includeInStateLogs: true,\n persist: false,\n anonymous: false,\n usedInUi: true,\n },\n unapprovedMessagesCount: {\n includeInStateLogs: true,\n persist: false,\n anonymous: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = () => ({\n unapprovedMessages: {},\n unapprovedMessagesCount: 0,\n});\n\n/**\n * @type OriginalRequest\n *\n * Represents the original request object for adding a message.\n * @property origin? - Is it is specified, represents the origin\n */\nexport type OriginalRequest = {\n id?: number;\n origin?: string;\n securityAlertResponse?: Record<string, Json>;\n};\n\n/**\n * @type AbstractMessage\n *\n * Represents and contains data about a signing type signature request.\n * @property id - An id to track and identify the message object\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'Message' which always has a signing type\n * @property rawSig - Raw data of the signature request\n * @property securityProviderResponse - Response from a security provider, whether it is malicious or not\n * @property metadata - Additional data for the message, for example external identifiers\n */\nexport type AbstractMessage = {\n id: string;\n time: number;\n status: string;\n type: string;\n rawSig?: string;\n securityProviderResponse?: Record<string, Json>;\n securityAlertResponse?: Record<string, Json>;\n metadata?: Json;\n error?: string;\n};\n\n/**\n * @type AbstractMessageParams\n *\n * Represents the parameters to pass to the signing method once the signature request is approved.\n * @property from - Address from which the message is processed\n * @property origin? - Added for request origin identification\n * @property requestId? - Original request id\n * @property deferSetAsSigned? - Whether to defer setting the message as signed immediately after the keyring is told to sign it\n */\nexport type AbstractMessageParams = {\n from: string;\n origin?: string;\n requestId?: number;\n deferSetAsSigned?: boolean;\n};\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the signing method once the signature request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property from - Address from which the message is processed\n * @property origin? - Added for request origin identification\n */\nexport type AbstractMessageParamsMetamask = AbstractMessageParams & {\n metamaskId?: string;\n};\n\n/**\n * @type MessageManagerState\n *\n * Message Manager state\n * @property unapprovedMessages - A collection of all Messages in the 'unapproved' state\n * @property unapprovedMessagesCount - The count of all Messages in this.unapprovedMessages\n */\nexport type MessageManagerState<Message extends AbstractMessage> = {\n unapprovedMessages: Record<string, Message>;\n unapprovedMessagesCount: number;\n};\n\nexport type UpdateBadgeEvent<Namespace extends string> = {\n type: `${Namespace}:updateBadge`;\n payload: [];\n};\n\n/**\n * A function for verifying a message, whether it is malicious or not\n */\nexport type SecurityProviderRequest = (\n requestData: AbstractMessage,\n messageType: string,\n) => Promise<Json>;\n\n/**\n * AbstractMessageManager constructor options.\n *\n * @property additionalFinishStatuses - Optional list of statuses that are accepted to emit a finished event.\n * @property messenger - Controller messaging system.\n * @property name - The name of the manager.\n * @property securityProviderRequest - A function for verifying a message, whether it is malicious or not.\n * @property state - Initial state to set on this controller.\n */\nexport type AbstractMessageManagerOptions<\n Name extends string,\n Message extends AbstractMessage,\n Action extends ActionConstraint,\n Event extends EventConstraint,\n> = {\n additionalFinishStatuses?: string[];\n messenger: RestrictedMessenger<\n Name,\n Action,\n Event | UpdateBadgeEvent<Name>,\n string,\n string\n >;\n name: Name;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<Message>;\n};\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport abstract class AbstractMessageManager<\n Name extends string,\n Message extends AbstractMessage,\n Params extends AbstractMessageParams,\n ParamsMetamask extends AbstractMessageParamsMetamask,\n Action extends ActionConstraint,\n Event extends EventConstraint,\n> extends BaseController<\n Name,\n MessageManagerState<Message>,\n RestrictedMessenger<\n Name,\n Action,\n Event | UpdateBadgeEvent<Name>,\n string,\n string\n >\n> {\n protected messages: Message[];\n\n private readonly securityProviderRequest: SecurityProviderRequest | undefined;\n\n private readonly additionalFinishStatuses: string[];\n\n internalEvents = new EventEmitter();\n\n constructor({\n additionalFinishStatuses,\n messenger,\n name,\n securityProviderRequest,\n state = {} as MessageManagerState<Message>,\n }: AbstractMessageManagerOptions<Name, Message, Action, Event>) {\n super({\n messenger,\n metadata: stateMetadata,\n name,\n state: {\n ...getDefaultState(),\n ...state,\n },\n });\n this.messages = [];\n this.securityProviderRequest = securityProviderRequest;\n this.additionalFinishStatuses = additionalFinishStatuses ?? [];\n }\n\n /**\n * Adds request props to the messsage params and returns a new messageParams object.\n * @param messageParams - The messageParams to add the request props to.\n * @param req - The original request object.\n * @returns The messageParams with the request props added.\n */\n protected addRequestToMessageParams<\n MessageParams extends AbstractMessageParams,\n >(messageParams: MessageParams, req?: OriginalRequest) {\n const updatedMessageParams = {\n ...messageParams,\n };\n\n if (req) {\n updatedMessageParams.requestId = req.id;\n updatedMessageParams.origin = req.origin;\n }\n\n return updatedMessageParams;\n }\n\n /**\n * Creates a new Message with a random id and an 'unapproved' status.\n * @param messageParams - The messageParams to add the request props to.\n * @param type - The approval type of the message.\n * @param req - The original request object.\n * @returns The new unapproved message for a specified type.\n */\n protected createUnapprovedMessage<\n MessageParams extends AbstractMessageParams,\n >(messageParams: MessageParams, type: ApprovalType, req?: OriginalRequest) {\n const messageId = random();\n\n return {\n id: messageId,\n messageParams,\n securityAlertResponse: req?.securityAlertResponse,\n status: 'unapproved',\n time: Date.now(),\n type,\n };\n }\n\n /**\n * Saves the unapproved messages, and their count to state.\n *\n * @param emitUpdateBadge - Whether to emit the updateBadge event.\n */\n protected saveMessageList(emitUpdateBadge = true) {\n this.update((state) => {\n state.unapprovedMessages =\n this.getUnapprovedMessages() as unknown as Record<\n string,\n Draft<Message>\n >;\n state.unapprovedMessagesCount = this.getUnapprovedMessagesCount();\n });\n if (emitUpdateBadge) {\n this.messagingSystem.publish(`${this.name}:updateBadge`);\n }\n }\n\n /**\n * Updates the status of a Message in this.messages.\n *\n * @param messageId - The id of the Message to update.\n * @param status - The new status of the Message.\n */\n protected setMessageStatus(messageId: string, status: string) {\n const message = this.getMessage(messageId);\n if (!message) {\n throw new Error(\n `${this.name as string}: Message not found for id: ${messageId}.`,\n );\n }\n const updatedMessage = {\n ...message,\n status,\n };\n this.updateMessage(updatedMessage);\n this.internalEvents.emit(`${messageId}:${status}`, updatedMessage);\n if (\n status === 'rejected' ||\n status === 'signed' ||\n status === 'errored' ||\n this.additionalFinishStatuses.includes(status)\n ) {\n this.internalEvents.emit(\n `${messageId as string}:finished`,\n updatedMessage,\n );\n }\n }\n\n /**\n * Sets a Message in this.messages to the passed Message if the ids are equal.\n * Then saves the unapprovedMessage list to storage.\n *\n * @param message - A Message that will replace an existing Message (with the id) in this.messages.\n * @param emitUpdateBadge - Whether to emit the updateBadge event.\n */\n protected updateMessage(message: Message, emitUpdateBadge = true) {\n const index = this.messages.findIndex((msg) => message.id === msg.id);\n /* istanbul ignore next */\n if (index !== -1) {\n this.messages[index] = message;\n }\n this.saveMessageList(emitUpdateBadge);\n }\n\n /**\n * Verifies a message is malicious or not by checking it against a security provider.\n *\n * @param message - The message to verify.\n * @returns A promise that resolves to a secured message with additional security provider response data.\n */\n private async securityCheck(message: Message): Promise<Message> {\n if (this.securityProviderRequest) {\n const securityProviderResponse = await this.securityProviderRequest(\n message,\n message.type,\n );\n return {\n ...message,\n securityProviderResponse,\n };\n }\n return message;\n }\n\n clearUnapprovedMessages() {\n this.update((state) => {\n state.unapprovedMessages = {};\n state.unapprovedMessagesCount = 0;\n });\n }\n\n /**\n * A getter for the number of 'unapproved' Messages in this.messages.\n *\n * @returns The number of 'unapproved' Messages in this.messages.\n */\n getUnapprovedMessagesCount() {\n return Object.keys(this.getUnapprovedMessages()).length;\n }\n\n /**\n * A getter for the 'unapproved' Messages in state messages.\n *\n * @returns An index of Message ids to Messages, for all 'unapproved' Messages in this.messages.\n */\n getUnapprovedMessages() {\n return this.messages\n .filter((message) => message.status === 'unapproved')\n .reduce((result: Record<string, Message>, message) => {\n result[message.id] = message;\n return result;\n }, {});\n }\n\n /**\n * Adds a passed Message to this.messages, and calls this.saveMessageList() to save\n * the unapproved Messages from that list to this.messages.\n *\n * @param message - The Message to add to this.messages.\n */\n async addMessage(message: Message) {\n const securedMessage = await this.securityCheck(message);\n this.messages.push(securedMessage);\n this.saveMessageList();\n }\n\n /**\n * Returns a specified Message.\n *\n * @param messageId - The id of the Message to get.\n * @returns The Message with the id that matches the passed messageId, or undefined\n * if no Message has that id.\n */\n getMessage(messageId: string) {\n return this.messages.find((message) => message.id === messageId);\n }\n\n /**\n * Returns all the messages.\n *\n * @returns An array of messages.\n */\n getAllMessages() {\n return this.messages;\n }\n\n /**\n * Approves a Message. Sets the message status via a call to this.setMessageStatusApproved,\n * and returns a promise with any the message params modified for proper signing.\n *\n * @param messageParams - The messageParams to be used when signing method is called,\n * plus data added by MetaMask.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n approveMessage(messageParams: ParamsMetamask): Promise<Params> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.setMessageStatusApproved(messageParams.metamaskId);\n return this.prepMessageForSigning(messageParams);\n }\n\n /**\n * Sets a Message status to 'approved' via a call to this.setMessageStatus.\n *\n * @param messageId - The id of the Message to approve.\n */\n setMessageStatusApproved(messageId: string) {\n this.setMessageStatus(messageId, 'approved');\n }\n\n /**\n * Sets message status to inProgress in order to allow users to use extension\n * while waiting for a custodian signature.\n *\n * @param messageId - The id of the message to set to inProgress\n */\n setMessageStatusInProgress(messageId: string) {\n this.setMessageStatus(messageId, 'inProgress');\n }\n\n /**\n * Sets a Message status to 'signed' via a call to this.setMessageStatus and updates\n * that Message in this.messages by adding the raw signature data of the signature\n * request to the Message.\n *\n * @param messageId - The id of the Message to sign.\n * @param rawSig - The raw data of the signature request.\n */\n setMessageStatusSigned(messageId: string, rawSig: string) {\n this.setMessageStatusAndResult(messageId, rawSig, 'signed');\n }\n\n /**\n * Sets the message via a call to this.setResult and updates status of the message.\n *\n * @param messageId - The id of the Message to sign.\n * @param rawSig - The data to update rawSig in the message.\n * @param status - The new message status.\n */\n setMessageStatusAndResult(messageId: string, rawSig: string, status: string) {\n this.setResult(messageId, rawSig);\n this.setMessageStatus(messageId, status);\n }\n\n /**\n * Sets the message result.\n *\n * @param messageId - The id of the Message to sign.\n * @param result - The data to update result in the message.\n */\n setResult(messageId: string, result: string) {\n const message = this.getMessage(messageId);\n /* istanbul ignore if */\n if (!message) {\n return;\n }\n this.updateMessage(\n {\n ...message,\n rawSig: result,\n },\n false,\n );\n }\n\n /**\n * Sets the messsage metadata\n *\n * @param messageId - The id of the Message to update\n * @param metadata - The data with which to replace the metadata property in the message\n */\n setMetadata(messageId: string, metadata: Json) {\n const message = this.getMessage(messageId);\n if (!message) {\n throw new Error(\n `${this.name as string}: Message not found for id: ${messageId}.`,\n );\n }\n this.updateMessage(\n {\n ...message,\n metadata,\n },\n false,\n );\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams\n *\n * @param messageParams - The messageParams to modify\n * @returns Promise resolving to the messageParams with the metamaskId property removed\n */\n abstract prepMessageForSigning(\n messageParams: ParamsMetamask,\n ): Promise<Params>;\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - Message parameters for the message to add\n * @param req - The original request object possibly containing the origin.\n * @param version? - The version of the JSON RPC protocol the request is using.\n * @returns The id of the newly created message.\n */\n abstract addUnapprovedMessage(\n messageParams: ParamsMetamask,\n request: OriginalRequest,\n version?: string,\n ): Promise<string>;\n\n /**\n * Sets a Message status to 'rejected' via a call to this.setMessageStatus.\n *\n * @param messageId - The id of the Message to reject.\n */\n rejectMessage(messageId: string) {\n this.setMessageStatus(messageId, 'rejected');\n }\n\n /**\n * Creates a promise which will resolve or reject when the message process is finished.\n *\n * @param messageParamsWithId - The params for the personal_sign call to be made after the message is approved.\n * @param messageName - The name of the message\n * @returns Promise resolving to the raw data of the signature request.\n */\n async waitForFinishStatus(\n messageParamsWithId: AbstractMessageParamsMetamask,\n messageName: string,\n ): Promise<string> {\n const { metamaskId: messageId, ...messageParams } = messageParamsWithId;\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId as string}:finished`,\n (data: AbstractMessage) => {\n switch (data.status) {\n case 'signed':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n `MetaMask ${messageName} Signature: User denied message signature.`,\n ),\n );\n case 'errored':\n return reject(\n new Error(\n `MetaMask ${messageName} Signature: ${data.error as string}`,\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask ${messageName} Signature: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n}\n\nexport default AbstractMessageManager;\n"]}
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
- import { BaseController, type ControllerStateChangeEvent, type ControllerGetStateAction } from "@metamask/base-controller/next";
2
+ import { BaseController } from "@metamask/base-controller";
3
+ import type { ActionConstraint, EventConstraint, RestrictedMessenger } from "@metamask/base-controller";
3
4
  import type { ApprovalType } from "@metamask/controller-utils";
4
- import type { Messenger, EventConstraint, ActionConstraint } from "@metamask/messenger";
5
5
  import type { Json } from "@metamask/utils";
6
6
  import { EventEmitter } from "events";
7
7
  /**
@@ -92,9 +92,9 @@ export type SecurityProviderRequest = (requestData: AbstractMessage, messageType
92
92
  * @property securityProviderRequest - A function for verifying a message, whether it is malicious or not.
93
93
  * @property state - Initial state to set on this controller.
94
94
  */
95
- export type AbstractMessageManagerOptions<Name extends string, Message extends AbstractMessage, MessageManagerMessenger extends Messenger<Name, ControllerGetStateAction<Name, MessageManagerState<Message>> | ActionConstraint, ControllerStateChangeEvent<Name, MessageManagerState<Message>> | UpdateBadgeEvent<Name> | EventConstraint>> = {
95
+ export type AbstractMessageManagerOptions<Name extends string, Message extends AbstractMessage, Action extends ActionConstraint, Event extends EventConstraint> = {
96
96
  additionalFinishStatuses?: string[];
97
- messenger: MessageManagerMessenger;
97
+ messenger: RestrictedMessenger<Name, Action, Event | UpdateBadgeEvent<Name>, string, string>;
98
98
  name: Name;
99
99
  securityProviderRequest?: SecurityProviderRequest;
100
100
  state?: MessageManagerState<Message>;
@@ -102,14 +102,14 @@ export type AbstractMessageManagerOptions<Name extends string, Message extends A
102
102
  /**
103
103
  * Controller in charge of managing - storing, adding, removing, updating - Messages.
104
104
  */
105
- export declare abstract class AbstractMessageManager<Name extends string, Message extends AbstractMessage, Params extends AbstractMessageParams, ParamsMetamask extends AbstractMessageParamsMetamask, MessageManagerMessenger extends Messenger<Name, ControllerGetStateAction<Name, MessageManagerState<Message>> | ActionConstraint, ControllerStateChangeEvent<Name, MessageManagerState<Message>> | UpdateBadgeEvent<Name> | EventConstraint>> extends BaseController<Name, MessageManagerState<Message>, MessageManagerMessenger> {
105
+ export declare abstract class AbstractMessageManager<Name extends string, Message extends AbstractMessage, Params extends AbstractMessageParams, ParamsMetamask extends AbstractMessageParamsMetamask, Action extends ActionConstraint, Event extends EventConstraint> extends BaseController<Name, MessageManagerState<Message>, RestrictedMessenger<Name, Action, Event | UpdateBadgeEvent<Name>, string, string>> {
106
106
  protected messages: Message[];
107
107
  private readonly securityProviderRequest;
108
108
  private readonly additionalFinishStatuses;
109
109
  internalEvents: EventEmitter<[never]>;
110
- constructor({ additionalFinishStatuses, messenger, name, securityProviderRequest, state, }: AbstractMessageManagerOptions<Name, Message, MessageManagerMessenger>);
110
+ constructor({ additionalFinishStatuses, messenger, name, securityProviderRequest, state, }: AbstractMessageManagerOptions<Name, Message, Action, Event>);
111
111
  /**
112
- * Adds request props to the message params and returns a new messageParams object.
112
+ * Adds request props to the messsage params and returns a new messageParams object.
113
113
  * @param messageParams - The messageParams to add the request props to.
114
114
  * @param req - The original request object.
115
115
  * @returns The messageParams with the request props added.
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractMessageManager.d.cts","sourceRoot":"","sources":["../src/AbstractMessageManager.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,cAAc,EACd,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC9B,uCAAuC;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,mCA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3E;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAe3C;;;;;OAKG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI;IAgB7C;;;;;;OAMG;IACH,QAAQ,CAAC,qBAAqB,CAC5B,aAAa,EAAE,cAAc,GAC5B,OAAO,CAAC,MAAM,CAAC;IAElB;;;;;;;;;OASG;IACH,QAAQ,CAAC,oBAAoB,CAC3B,aAAa,EAAE,cAAc,EAC7B,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC;IAElB;;;;OAIG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM;IAI/B;;;;;;OAMG;IACG,mBAAmB,CACvB,mBAAmB,EAAE,6BAA6B,EAClD,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC;CAkCnB;AAED,eAAe,sBAAsB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
- import { BaseController, type ControllerStateChangeEvent, type ControllerGetStateAction } from "@metamask/base-controller/next";
2
+ import { BaseController } from "@metamask/base-controller";
3
+ import type { ActionConstraint, EventConstraint, RestrictedMessenger } from "@metamask/base-controller";
3
4
  import type { ApprovalType } from "@metamask/controller-utils";
4
- import type { Messenger, EventConstraint, ActionConstraint } from "@metamask/messenger";
5
5
  import type { Json } from "@metamask/utils";
6
6
  import { EventEmitter } from "events";
7
7
  /**
@@ -92,9 +92,9 @@ export type SecurityProviderRequest = (requestData: AbstractMessage, messageType
92
92
  * @property securityProviderRequest - A function for verifying a message, whether it is malicious or not.
93
93
  * @property state - Initial state to set on this controller.
94
94
  */
95
- export type AbstractMessageManagerOptions<Name extends string, Message extends AbstractMessage, MessageManagerMessenger extends Messenger<Name, ControllerGetStateAction<Name, MessageManagerState<Message>> | ActionConstraint, ControllerStateChangeEvent<Name, MessageManagerState<Message>> | UpdateBadgeEvent<Name> | EventConstraint>> = {
95
+ export type AbstractMessageManagerOptions<Name extends string, Message extends AbstractMessage, Action extends ActionConstraint, Event extends EventConstraint> = {
96
96
  additionalFinishStatuses?: string[];
97
- messenger: MessageManagerMessenger;
97
+ messenger: RestrictedMessenger<Name, Action, Event | UpdateBadgeEvent<Name>, string, string>;
98
98
  name: Name;
99
99
  securityProviderRequest?: SecurityProviderRequest;
100
100
  state?: MessageManagerState<Message>;
@@ -102,14 +102,14 @@ export type AbstractMessageManagerOptions<Name extends string, Message extends A
102
102
  /**
103
103
  * Controller in charge of managing - storing, adding, removing, updating - Messages.
104
104
  */
105
- export declare abstract class AbstractMessageManager<Name extends string, Message extends AbstractMessage, Params extends AbstractMessageParams, ParamsMetamask extends AbstractMessageParamsMetamask, MessageManagerMessenger extends Messenger<Name, ControllerGetStateAction<Name, MessageManagerState<Message>> | ActionConstraint, ControllerStateChangeEvent<Name, MessageManagerState<Message>> | UpdateBadgeEvent<Name> | EventConstraint>> extends BaseController<Name, MessageManagerState<Message>, MessageManagerMessenger> {
105
+ export declare abstract class AbstractMessageManager<Name extends string, Message extends AbstractMessage, Params extends AbstractMessageParams, ParamsMetamask extends AbstractMessageParamsMetamask, Action extends ActionConstraint, Event extends EventConstraint> extends BaseController<Name, MessageManagerState<Message>, RestrictedMessenger<Name, Action, Event | UpdateBadgeEvent<Name>, string, string>> {
106
106
  protected messages: Message[];
107
107
  private readonly securityProviderRequest;
108
108
  private readonly additionalFinishStatuses;
109
109
  internalEvents: EventEmitter<[never]>;
110
- constructor({ additionalFinishStatuses, messenger, name, securityProviderRequest, state, }: AbstractMessageManagerOptions<Name, Message, MessageManagerMessenger>);
110
+ constructor({ additionalFinishStatuses, messenger, name, securityProviderRequest, state, }: AbstractMessageManagerOptions<Name, Message, Action, Event>);
111
111
  /**
112
- * Adds request props to the message params and returns a new messageParams object.
112
+ * Adds request props to the messsage params and returns a new messageParams object.
113
113
  * @param messageParams - The messageParams to add the request props to.
114
114
  * @param req - The original request object.
115
115
  * @returns The messageParams with the request props added.
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractMessageManager.d.mts","sourceRoot":"","sources":["../src/AbstractMessageManager.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,cAAc,EACd,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC9B,uCAAuC;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,mCAAmC;AAC/D,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,gBAAgB,EACjB,4BAA4B;AAC7B,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,EAAE,YAAY,EAAE,eAAe;AAwBtC;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wBAAwB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAChD,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC7C,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC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C;;;;;OAKG;IACH,0BAA0B,CAAC,SAAS,EAAE,MAAM;IAI5C;;;;;;;OAOG;IACH,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAIxD;;;;;;OAMG;IACH,yBAAyB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK3E;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAe3C;;;;;OAKG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI;IAgB7C;;;;;;OAMG;IACH,QAAQ,CAAC,qBAAqB,CAC5B,aAAa,EAAE,cAAc,GAC5B,OAAO,CAAC,MAAM,CAAC;IAElB;;;;;;;;;OASG;IACH,QAAQ,CAAC,oBAAoB,CAC3B,aAAa,EAAE,cAAc,EAC7B,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC;IAElB;;;;OAIG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM;IAI/B;;;;;;OAMG;IACG,mBAAmB,CACvB,mBAAmB,EAAE,6BAA6B,EAClD,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC;CAkCnB;AAED,eAAe,sBAAsB,CAAC"}
@@ -1,4 +1,4 @@
1
- import { BaseController } from "@metamask/base-controller/next";
1
+ import { BaseController } from "@metamask/base-controller";
2
2
  // This package purposefully relies on Node's EventEmitter module.
3
3
  // eslint-disable-next-line import-x/no-nodejs-modules
4
4
  import { EventEmitter } from "events";
@@ -7,13 +7,13 @@ const stateMetadata = {
7
7
  unapprovedMessages: {
8
8
  includeInStateLogs: true,
9
9
  persist: false,
10
- includeInDebugSnapshot: false,
10
+ anonymous: false,
11
11
  usedInUi: true,
12
12
  },
13
13
  unapprovedMessagesCount: {
14
14
  includeInStateLogs: true,
15
15
  persist: false,
16
- includeInDebugSnapshot: false,
16
+ anonymous: false,
17
17
  usedInUi: true,
18
18
  },
19
19
  };
@@ -41,7 +41,7 @@ export class AbstractMessageManager extends BaseController {
41
41
  this.additionalFinishStatuses = additionalFinishStatuses ?? [];
42
42
  }
43
43
  /**
44
- * Adds request props to the message params and returns a new messageParams object.
44
+ * Adds request props to the messsage params and returns a new messageParams object.
45
45
  * @param messageParams - The messageParams to add the request props to.
46
46
  * @param req - The original request object.
47
47
  * @returns The messageParams with the request props added.
@@ -86,7 +86,7 @@ export class AbstractMessageManager extends BaseController {
86
86
  state.unapprovedMessagesCount = this.getUnapprovedMessagesCount();
87
87
  });
88
88
  if (emitUpdateBadge) {
89
- this.messenger.publish(`${this.name}:updateBadge`);
89
+ this.messagingSystem.publish(`${this.name}:updateBadge`);
90
90
  }
91
91
  }
92
92
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractMessageManager.mjs","sourceRoot":"","sources":["../src/AbstractMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAGf,uCAAuC;AAQxC,kEAAkE;AAClE,sDAAsD;AACtD,OAAO,EAAE,YAAY,EAAE,eAAe;AAEtC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAEpC,MAAM,aAAa,GAAG;IACpB,kBAAkB,EAAE;QAClB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,uBAAuB,EAAE;QACvB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,CAAC;IAC7B,kBAAkB,EAAE,EAAE;IACtB,uBAAuB,EAAE,CAAC;CAC3B,CAAC,CAAC;AAuHH;;GAEG;AACH,MAAM,OAAgB,sBAapB,SAAQ,cAIT;I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Y,WAAW,gCAAgC,IAAI,CAAC,SAAS,CACnE,aAAa,CACd,EAAE,CACJ,CACF,CAAC;iBACL;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,eAAe,sBAAsB,CAAC","sourcesContent":["import {\n BaseController,\n type ControllerStateChangeEvent,\n type ControllerGetStateAction,\n} from '@metamask/base-controller/next';\nimport type { ApprovalType } from '@metamask/controller-utils';\nimport type {\n Messenger,\n EventConstraint,\n ActionConstraint,\n} from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport { EventEmitter } from 'events';\nimport type { Draft } from 'immer';\nimport { v1 as random } from 'uuid';\n\nconst stateMetadata = {\n unapprovedMessages: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n unapprovedMessagesCount: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = () => ({\n unapprovedMessages: {},\n unapprovedMessagesCount: 0,\n});\n\n/**\n * @type OriginalRequest\n *\n * Represents the original request object for adding a message.\n * @property origin? - Is it is specified, represents the origin\n */\nexport type OriginalRequest = {\n id?: number;\n origin?: string;\n securityAlertResponse?: Record<string, Json>;\n};\n\n/**\n * @type AbstractMessage\n *\n * Represents and contains data about a signing type signature request.\n * @property id - An id to track and identify the message object\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'Message' which always has a signing type\n * @property rawSig - Raw data of the signature request\n * @property securityProviderResponse - Response from a security provider, whether it is malicious or not\n * @property metadata - Additional data for the message, for example external identifiers\n */\nexport type AbstractMessage = {\n id: string;\n time: number;\n status: string;\n type: string;\n rawSig?: string;\n securityProviderResponse?: Record<string, Json>;\n securityAlertResponse?: Record<string, Json>;\n metadata?: Json;\n error?: string;\n};\n\n/**\n * @type AbstractMessageParams\n *\n * Represents the parameters to pass to the signing method once the signature request is approved.\n * @property from - Address from which the message is processed\n * @property origin? - Added for request origin identification\n * @property requestId? - Original request id\n * @property deferSetAsSigned? - Whether to defer setting the message as signed immediately after the keyring is told to sign it\n */\nexport type AbstractMessageParams = {\n from: string;\n origin?: string;\n requestId?: number;\n deferSetAsSigned?: boolean;\n};\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the signing method once the signature request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property from - Address from which the message is processed\n * @property origin? - Added for request origin identification\n */\nexport type AbstractMessageParamsMetamask = AbstractMessageParams & {\n metamaskId?: string;\n};\n\n/**\n * @type MessageManagerState\n *\n * Message Manager state\n * @property unapprovedMessages - A collection of all Messages in the 'unapproved' state\n * @property unapprovedMessagesCount - The count of all Messages in this.unapprovedMessages\n */\nexport type MessageManagerState<Message extends AbstractMessage> = {\n unapprovedMessages: Record<string, Message>;\n unapprovedMessagesCount: number;\n};\n\nexport type UpdateBadgeEvent<Namespace extends string> = {\n type: `${Namespace}:updateBadge`;\n payload: [];\n};\n\n/**\n * A function for verifying a message, whether it is malicious or not\n */\nexport type SecurityProviderRequest = (\n requestData: AbstractMessage,\n messageType: string,\n) => Promise<Json>;\n\n/**\n * AbstractMessageManager constructor options.\n *\n * @property additionalFinishStatuses - Optional list of statuses that are accepted to emit a finished event.\n * @property messenger - Controller messaging system.\n * @property name - The name of the manager.\n * @property securityProviderRequest - A function for verifying a message, whether it is malicious or not.\n * @property state - Initial state to set on this controller.\n */\nexport type AbstractMessageManagerOptions<\n Name extends string,\n Message extends AbstractMessage,\n MessageManagerMessenger extends Messenger<\n Name,\n | ControllerGetStateAction<Name, MessageManagerState<Message>>\n | ActionConstraint,\n | ControllerStateChangeEvent<Name, MessageManagerState<Message>>\n | UpdateBadgeEvent<Name>\n | EventConstraint\n >,\n> = {\n additionalFinishStatuses?: string[];\n messenger: MessageManagerMessenger;\n name: Name;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<Message>;\n};\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport abstract class AbstractMessageManager<\n Name extends string,\n Message extends AbstractMessage,\n Params extends AbstractMessageParams,\n ParamsMetamask extends AbstractMessageParamsMetamask,\n MessageManagerMessenger extends Messenger<\n Name,\n | ControllerGetStateAction<Name, MessageManagerState<Message>>\n | ActionConstraint,\n | ControllerStateChangeEvent<Name, MessageManagerState<Message>>\n | UpdateBadgeEvent<Name>\n | EventConstraint\n >,\n> extends BaseController<\n Name,\n MessageManagerState<Message>,\n MessageManagerMessenger\n> {\n protected messages: Message[];\n\n private readonly securityProviderRequest: SecurityProviderRequest | undefined;\n\n private readonly additionalFinishStatuses: string[];\n\n internalEvents = new EventEmitter();\n\n constructor({\n additionalFinishStatuses,\n messenger,\n name,\n securityProviderRequest,\n state = {} as MessageManagerState<Message>,\n }: AbstractMessageManagerOptions<Name, Message, MessageManagerMessenger>) {\n super({\n messenger,\n metadata: stateMetadata,\n name,\n state: {\n ...getDefaultState(),\n ...state,\n },\n });\n this.messages = [];\n this.securityProviderRequest = securityProviderRequest;\n this.additionalFinishStatuses = additionalFinishStatuses ?? [];\n }\n\n /**\n * Adds request props to the message params and returns a new messageParams object.\n * @param messageParams - The messageParams to add the request props to.\n * @param req - The original request object.\n * @returns The messageParams with the request props added.\n */\n protected addRequestToMessageParams<\n MessageParams extends AbstractMessageParams,\n >(messageParams: MessageParams, req?: OriginalRequest) {\n const updatedMessageParams = {\n ...messageParams,\n };\n\n if (req) {\n updatedMessageParams.requestId = req.id;\n updatedMessageParams.origin = req.origin;\n }\n\n return updatedMessageParams;\n }\n\n /**\n * Creates a new Message with a random id and an 'unapproved' status.\n * @param messageParams - The messageParams to add the request props to.\n * @param type - The approval type of the message.\n * @param req - The original request object.\n * @returns The new unapproved message for a specified type.\n */\n protected createUnapprovedMessage<\n MessageParams extends AbstractMessageParams,\n >(messageParams: MessageParams, type: ApprovalType, req?: OriginalRequest) {\n const messageId = random();\n\n return {\n id: messageId,\n messageParams,\n securityAlertResponse: req?.securityAlertResponse,\n status: 'unapproved',\n time: Date.now(),\n type,\n };\n }\n\n /**\n * Saves the unapproved messages, and their count to state.\n *\n * @param emitUpdateBadge - Whether to emit the updateBadge event.\n */\n protected saveMessageList(emitUpdateBadge = true) {\n this.update((state) => {\n state.unapprovedMessages =\n this.getUnapprovedMessages() as unknown as Record<\n string,\n Draft<Message>\n >;\n state.unapprovedMessagesCount = this.getUnapprovedMessagesCount();\n });\n if (emitUpdateBadge) {\n this.messenger.publish(`${this.name}:updateBadge` as const);\n }\n }\n\n /**\n * Updates the status of a Message in this.messages.\n *\n * @param messageId - The id of the Message to update.\n * @param status - The new status of the Message.\n */\n protected setMessageStatus(messageId: string, status: string) {\n const message = this.getMessage(messageId);\n if (!message) {\n throw new Error(\n `${this.name as string}: Message not found for id: ${messageId}.`,\n );\n }\n const updatedMessage = {\n ...message,\n status,\n };\n this.updateMessage(updatedMessage);\n this.internalEvents.emit(`${messageId}:${status}`, updatedMessage);\n if (\n status === 'rejected' ||\n status === 'signed' ||\n status === 'errored' ||\n this.additionalFinishStatuses.includes(status)\n ) {\n this.internalEvents.emit(\n `${messageId as string}:finished`,\n updatedMessage,\n );\n }\n }\n\n /**\n * Sets a Message in this.messages to the passed Message if the ids are equal.\n * Then saves the unapprovedMessage list to storage.\n *\n * @param message - A Message that will replace an existing Message (with the id) in this.messages.\n * @param emitUpdateBadge - Whether to emit the updateBadge event.\n */\n protected updateMessage(message: Message, emitUpdateBadge = true) {\n const index = this.messages.findIndex((msg) => message.id === msg.id);\n /* istanbul ignore next */\n if (index !== -1) {\n this.messages[index] = message;\n }\n this.saveMessageList(emitUpdateBadge);\n }\n\n /**\n * Verifies a message is malicious or not by checking it against a security provider.\n *\n * @param message - The message to verify.\n * @returns A promise that resolves to a secured message with additional security provider response data.\n */\n private async securityCheck(message: Message): Promise<Message> {\n if (this.securityProviderRequest) {\n const securityProviderResponse = await this.securityProviderRequest(\n message,\n message.type,\n );\n return {\n ...message,\n securityProviderResponse,\n };\n }\n return message;\n }\n\n clearUnapprovedMessages() {\n this.update((state) => {\n state.unapprovedMessages = {};\n state.unapprovedMessagesCount = 0;\n });\n }\n\n /**\n * A getter for the number of 'unapproved' Messages in this.messages.\n *\n * @returns The number of 'unapproved' Messages in this.messages.\n */\n getUnapprovedMessagesCount() {\n return Object.keys(this.getUnapprovedMessages()).length;\n }\n\n /**\n * A getter for the 'unapproved' Messages in state messages.\n *\n * @returns An index of Message ids to Messages, for all 'unapproved' Messages in this.messages.\n */\n getUnapprovedMessages() {\n return this.messages\n .filter((message) => message.status === 'unapproved')\n .reduce((result: Record<string, Message>, message) => {\n result[message.id] = message;\n return result;\n }, {});\n }\n\n /**\n * Adds a passed Message to this.messages, and calls this.saveMessageList() to save\n * the unapproved Messages from that list to this.messages.\n *\n * @param message - The Message to add to this.messages.\n */\n async addMessage(message: Message) {\n const securedMessage = await this.securityCheck(message);\n this.messages.push(securedMessage);\n this.saveMessageList();\n }\n\n /**\n * Returns a specified Message.\n *\n * @param messageId - The id of the Message to get.\n * @returns The Message with the id that matches the passed messageId, or undefined\n * if no Message has that id.\n */\n getMessage(messageId: string) {\n return this.messages.find((message) => message.id === messageId);\n }\n\n /**\n * Returns all the messages.\n *\n * @returns An array of messages.\n */\n getAllMessages() {\n return this.messages;\n }\n\n /**\n * Approves a Message. Sets the message status via a call to this.setMessageStatusApproved,\n * and returns a promise with any the message params modified for proper signing.\n *\n * @param messageParams - The messageParams to be used when signing method is called,\n * plus data added by MetaMask.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n approveMessage(messageParams: ParamsMetamask): Promise<Params> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.setMessageStatusApproved(messageParams.metamaskId);\n return this.prepMessageForSigning(messageParams);\n }\n\n /**\n * Sets a Message status to 'approved' via a call to this.setMessageStatus.\n *\n * @param messageId - The id of the Message to approve.\n */\n setMessageStatusApproved(messageId: string) {\n this.setMessageStatus(messageId, 'approved');\n }\n\n /**\n * Sets message status to inProgress in order to allow users to use extension\n * while waiting for a custodian signature.\n *\n * @param messageId - The id of the message to set to inProgress\n */\n setMessageStatusInProgress(messageId: string) {\n this.setMessageStatus(messageId, 'inProgress');\n }\n\n /**\n * Sets a Message status to 'signed' via a call to this.setMessageStatus and updates\n * that Message in this.messages by adding the raw signature data of the signature\n * request to the Message.\n *\n * @param messageId - The id of the Message to sign.\n * @param rawSig - The raw data of the signature request.\n */\n setMessageStatusSigned(messageId: string, rawSig: string) {\n this.setMessageStatusAndResult(messageId, rawSig, 'signed');\n }\n\n /**\n * Sets the message via a call to this.setResult and updates status of the message.\n *\n * @param messageId - The id of the Message to sign.\n * @param rawSig - The data to update rawSig in the message.\n * @param status - The new message status.\n */\n setMessageStatusAndResult(messageId: string, rawSig: string, status: string) {\n this.setResult(messageId, rawSig);\n this.setMessageStatus(messageId, status);\n }\n\n /**\n * Sets the message result.\n *\n * @param messageId - The id of the Message to sign.\n * @param result - The data to update result in the message.\n */\n setResult(messageId: string, result: string) {\n const message = this.getMessage(messageId);\n /* istanbul ignore if */\n if (!message) {\n return;\n }\n this.updateMessage(\n {\n ...message,\n rawSig: result,\n },\n false,\n );\n }\n\n /**\n * Sets the messsage metadata\n *\n * @param messageId - The id of the Message to update\n * @param metadata - The data with which to replace the metadata property in the message\n */\n setMetadata(messageId: string, metadata: Json) {\n const message = this.getMessage(messageId);\n if (!message) {\n throw new Error(\n `${this.name as string}: Message not found for id: ${messageId}.`,\n );\n }\n this.updateMessage(\n {\n ...message,\n metadata,\n },\n false,\n );\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams\n *\n * @param messageParams - The messageParams to modify\n * @returns Promise resolving to the messageParams with the metamaskId property removed\n */\n abstract prepMessageForSigning(\n messageParams: ParamsMetamask,\n ): Promise<Params>;\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - Message parameters for the message to add\n * @param req - The original request object possibly containing the origin.\n * @param version? - The version of the JSON RPC protocol the request is using.\n * @returns The id of the newly created message.\n */\n abstract addUnapprovedMessage(\n messageParams: ParamsMetamask,\n request: OriginalRequest,\n version?: string,\n ): Promise<string>;\n\n /**\n * Sets a Message status to 'rejected' via a call to this.setMessageStatus.\n *\n * @param messageId - The id of the Message to reject.\n */\n rejectMessage(messageId: string) {\n this.setMessageStatus(messageId, 'rejected');\n }\n\n /**\n * Creates a promise which will resolve or reject when the message process is finished.\n *\n * @param messageParamsWithId - The params for the personal_sign call to be made after the message is approved.\n * @param messageName - The name of the message\n * @returns Promise resolving to the raw data of the signature request.\n */\n async waitForFinishStatus(\n messageParamsWithId: AbstractMessageParamsMetamask,\n messageName: string,\n ): Promise<string> {\n const { metamaskId: messageId, ...messageParams } = messageParamsWithId;\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId as string}:finished`,\n (data: AbstractMessage) => {\n switch (data.status) {\n case 'signed':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n `MetaMask ${messageName} Signature: User denied message signature.`,\n ),\n );\n case 'errored':\n return reject(\n new Error(\n `MetaMask ${messageName} Signature: ${data.error as string}`,\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask ${messageName} Signature: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n}\n\nexport default AbstractMessageManager;\n"]}
1
+ {"version":3,"file":"AbstractMessageManager.mjs","sourceRoot":"","sources":["../src/AbstractMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAQ3D,kEAAkE;AAClE,sDAAsD;AACtD,OAAO,EAAE,YAAY,EAAE,eAAe;AAEtC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAEpC,MAAM,aAAa,GAAG;IACpB,kBAAkB,EA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AW,EACjC,CAAC,IAAqB,EAAE,EAAE;gBACxB,QAAQ,IAAI,CAAC,MAAM,EAAE;oBACnB,KAAK,QAAQ;wBACX,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;oBACxC,KAAK,UAAU;wBACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,YAAY,WAAW,4CAA4C,CACpE,CACF,CAAC;oBACJ,KAAK,SAAS;wBACZ,OAAO,MAAM,CACX,IAAI,KAAK,CACP,YAAY,WAAW,eAAe,IAAI,CAAC,KAAe,EAAE,CAC7D,CACF,CAAC;oBACJ;wBACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,YAAY,WAAW,gCAAgC,IAAI,CAAC,SAAS,CACnE,aAAa,CACd,EAAE,CACJ,CACF,CAAC;iBACL;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,eAAe,sBAAsB,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ActionConstraint,\n EventConstraint,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { ApprovalType } from '@metamask/controller-utils';\nimport type { Json } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport { EventEmitter } from 'events';\nimport type { Draft } from 'immer';\nimport { v1 as random } from 'uuid';\n\nconst stateMetadata = {\n unapprovedMessages: {\n includeInStateLogs: true,\n persist: false,\n anonymous: false,\n usedInUi: true,\n },\n unapprovedMessagesCount: {\n includeInStateLogs: true,\n persist: false,\n anonymous: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = () => ({\n unapprovedMessages: {},\n unapprovedMessagesCount: 0,\n});\n\n/**\n * @type OriginalRequest\n *\n * Represents the original request object for adding a message.\n * @property origin? - Is it is specified, represents the origin\n */\nexport type OriginalRequest = {\n id?: number;\n origin?: string;\n securityAlertResponse?: Record<string, Json>;\n};\n\n/**\n * @type AbstractMessage\n *\n * Represents and contains data about a signing type signature request.\n * @property id - An id to track and identify the message object\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'Message' which always has a signing type\n * @property rawSig - Raw data of the signature request\n * @property securityProviderResponse - Response from a security provider, whether it is malicious or not\n * @property metadata - Additional data for the message, for example external identifiers\n */\nexport type AbstractMessage = {\n id: string;\n time: number;\n status: string;\n type: string;\n rawSig?: string;\n securityProviderResponse?: Record<string, Json>;\n securityAlertResponse?: Record<string, Json>;\n metadata?: Json;\n error?: string;\n};\n\n/**\n * @type AbstractMessageParams\n *\n * Represents the parameters to pass to the signing method once the signature request is approved.\n * @property from - Address from which the message is processed\n * @property origin? - Added for request origin identification\n * @property requestId? - Original request id\n * @property deferSetAsSigned? - Whether to defer setting the message as signed immediately after the keyring is told to sign it\n */\nexport type AbstractMessageParams = {\n from: string;\n origin?: string;\n requestId?: number;\n deferSetAsSigned?: boolean;\n};\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the signing method once the signature request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property from - Address from which the message is processed\n * @property origin? - Added for request origin identification\n */\nexport type AbstractMessageParamsMetamask = AbstractMessageParams & {\n metamaskId?: string;\n};\n\n/**\n * @type MessageManagerState\n *\n * Message Manager state\n * @property unapprovedMessages - A collection of all Messages in the 'unapproved' state\n * @property unapprovedMessagesCount - The count of all Messages in this.unapprovedMessages\n */\nexport type MessageManagerState<Message extends AbstractMessage> = {\n unapprovedMessages: Record<string, Message>;\n unapprovedMessagesCount: number;\n};\n\nexport type UpdateBadgeEvent<Namespace extends string> = {\n type: `${Namespace}:updateBadge`;\n payload: [];\n};\n\n/**\n * A function for verifying a message, whether it is malicious or not\n */\nexport type SecurityProviderRequest = (\n requestData: AbstractMessage,\n messageType: string,\n) => Promise<Json>;\n\n/**\n * AbstractMessageManager constructor options.\n *\n * @property additionalFinishStatuses - Optional list of statuses that are accepted to emit a finished event.\n * @property messenger - Controller messaging system.\n * @property name - The name of the manager.\n * @property securityProviderRequest - A function for verifying a message, whether it is malicious or not.\n * @property state - Initial state to set on this controller.\n */\nexport type AbstractMessageManagerOptions<\n Name extends string,\n Message extends AbstractMessage,\n Action extends ActionConstraint,\n Event extends EventConstraint,\n> = {\n additionalFinishStatuses?: string[];\n messenger: RestrictedMessenger<\n Name,\n Action,\n Event | UpdateBadgeEvent<Name>,\n string,\n string\n >;\n name: Name;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<Message>;\n};\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport abstract class AbstractMessageManager<\n Name extends string,\n Message extends AbstractMessage,\n Params extends AbstractMessageParams,\n ParamsMetamask extends AbstractMessageParamsMetamask,\n Action extends ActionConstraint,\n Event extends EventConstraint,\n> extends BaseController<\n Name,\n MessageManagerState<Message>,\n RestrictedMessenger<\n Name,\n Action,\n Event | UpdateBadgeEvent<Name>,\n string,\n string\n >\n> {\n protected messages: Message[];\n\n private readonly securityProviderRequest: SecurityProviderRequest | undefined;\n\n private readonly additionalFinishStatuses: string[];\n\n internalEvents = new EventEmitter();\n\n constructor({\n additionalFinishStatuses,\n messenger,\n name,\n securityProviderRequest,\n state = {} as MessageManagerState<Message>,\n }: AbstractMessageManagerOptions<Name, Message, Action, Event>) {\n super({\n messenger,\n metadata: stateMetadata,\n name,\n state: {\n ...getDefaultState(),\n ...state,\n },\n });\n this.messages = [];\n this.securityProviderRequest = securityProviderRequest;\n this.additionalFinishStatuses = additionalFinishStatuses ?? [];\n }\n\n /**\n * Adds request props to the messsage params and returns a new messageParams object.\n * @param messageParams - The messageParams to add the request props to.\n * @param req - The original request object.\n * @returns The messageParams with the request props added.\n */\n protected addRequestToMessageParams<\n MessageParams extends AbstractMessageParams,\n >(messageParams: MessageParams, req?: OriginalRequest) {\n const updatedMessageParams = {\n ...messageParams,\n };\n\n if (req) {\n updatedMessageParams.requestId = req.id;\n updatedMessageParams.origin = req.origin;\n }\n\n return updatedMessageParams;\n }\n\n /**\n * Creates a new Message with a random id and an 'unapproved' status.\n * @param messageParams - The messageParams to add the request props to.\n * @param type - The approval type of the message.\n * @param req - The original request object.\n * @returns The new unapproved message for a specified type.\n */\n protected createUnapprovedMessage<\n MessageParams extends AbstractMessageParams,\n >(messageParams: MessageParams, type: ApprovalType, req?: OriginalRequest) {\n const messageId = random();\n\n return {\n id: messageId,\n messageParams,\n securityAlertResponse: req?.securityAlertResponse,\n status: 'unapproved',\n time: Date.now(),\n type,\n };\n }\n\n /**\n * Saves the unapproved messages, and their count to state.\n *\n * @param emitUpdateBadge - Whether to emit the updateBadge event.\n */\n protected saveMessageList(emitUpdateBadge = true) {\n this.update((state) => {\n state.unapprovedMessages =\n this.getUnapprovedMessages() as unknown as Record<\n string,\n Draft<Message>\n >;\n state.unapprovedMessagesCount = this.getUnapprovedMessagesCount();\n });\n if (emitUpdateBadge) {\n this.messagingSystem.publish(`${this.name}:updateBadge`);\n }\n }\n\n /**\n * Updates the status of a Message in this.messages.\n *\n * @param messageId - The id of the Message to update.\n * @param status - The new status of the Message.\n */\n protected setMessageStatus(messageId: string, status: string) {\n const message = this.getMessage(messageId);\n if (!message) {\n throw new Error(\n `${this.name as string}: Message not found for id: ${messageId}.`,\n );\n }\n const updatedMessage = {\n ...message,\n status,\n };\n this.updateMessage(updatedMessage);\n this.internalEvents.emit(`${messageId}:${status}`, updatedMessage);\n if (\n status === 'rejected' ||\n status === 'signed' ||\n status === 'errored' ||\n this.additionalFinishStatuses.includes(status)\n ) {\n this.internalEvents.emit(\n `${messageId as string}:finished`,\n updatedMessage,\n );\n }\n }\n\n /**\n * Sets a Message in this.messages to the passed Message if the ids are equal.\n * Then saves the unapprovedMessage list to storage.\n *\n * @param message - A Message that will replace an existing Message (with the id) in this.messages.\n * @param emitUpdateBadge - Whether to emit the updateBadge event.\n */\n protected updateMessage(message: Message, emitUpdateBadge = true) {\n const index = this.messages.findIndex((msg) => message.id === msg.id);\n /* istanbul ignore next */\n if (index !== -1) {\n this.messages[index] = message;\n }\n this.saveMessageList(emitUpdateBadge);\n }\n\n /**\n * Verifies a message is malicious or not by checking it against a security provider.\n *\n * @param message - The message to verify.\n * @returns A promise that resolves to a secured message with additional security provider response data.\n */\n private async securityCheck(message: Message): Promise<Message> {\n if (this.securityProviderRequest) {\n const securityProviderResponse = await this.securityProviderRequest(\n message,\n message.type,\n );\n return {\n ...message,\n securityProviderResponse,\n };\n }\n return message;\n }\n\n clearUnapprovedMessages() {\n this.update((state) => {\n state.unapprovedMessages = {};\n state.unapprovedMessagesCount = 0;\n });\n }\n\n /**\n * A getter for the number of 'unapproved' Messages in this.messages.\n *\n * @returns The number of 'unapproved' Messages in this.messages.\n */\n getUnapprovedMessagesCount() {\n return Object.keys(this.getUnapprovedMessages()).length;\n }\n\n /**\n * A getter for the 'unapproved' Messages in state messages.\n *\n * @returns An index of Message ids to Messages, for all 'unapproved' Messages in this.messages.\n */\n getUnapprovedMessages() {\n return this.messages\n .filter((message) => message.status === 'unapproved')\n .reduce((result: Record<string, Message>, message) => {\n result[message.id] = message;\n return result;\n }, {});\n }\n\n /**\n * Adds a passed Message to this.messages, and calls this.saveMessageList() to save\n * the unapproved Messages from that list to this.messages.\n *\n * @param message - The Message to add to this.messages.\n */\n async addMessage(message: Message) {\n const securedMessage = await this.securityCheck(message);\n this.messages.push(securedMessage);\n this.saveMessageList();\n }\n\n /**\n * Returns a specified Message.\n *\n * @param messageId - The id of the Message to get.\n * @returns The Message with the id that matches the passed messageId, or undefined\n * if no Message has that id.\n */\n getMessage(messageId: string) {\n return this.messages.find((message) => message.id === messageId);\n }\n\n /**\n * Returns all the messages.\n *\n * @returns An array of messages.\n */\n getAllMessages() {\n return this.messages;\n }\n\n /**\n * Approves a Message. Sets the message status via a call to this.setMessageStatusApproved,\n * and returns a promise with any the message params modified for proper signing.\n *\n * @param messageParams - The messageParams to be used when signing method is called,\n * plus data added by MetaMask.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n approveMessage(messageParams: ParamsMetamask): Promise<Params> {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.setMessageStatusApproved(messageParams.metamaskId);\n return this.prepMessageForSigning(messageParams);\n }\n\n /**\n * Sets a Message status to 'approved' via a call to this.setMessageStatus.\n *\n * @param messageId - The id of the Message to approve.\n */\n setMessageStatusApproved(messageId: string) {\n this.setMessageStatus(messageId, 'approved');\n }\n\n /**\n * Sets message status to inProgress in order to allow users to use extension\n * while waiting for a custodian signature.\n *\n * @param messageId - The id of the message to set to inProgress\n */\n setMessageStatusInProgress(messageId: string) {\n this.setMessageStatus(messageId, 'inProgress');\n }\n\n /**\n * Sets a Message status to 'signed' via a call to this.setMessageStatus and updates\n * that Message in this.messages by adding the raw signature data of the signature\n * request to the Message.\n *\n * @param messageId - The id of the Message to sign.\n * @param rawSig - The raw data of the signature request.\n */\n setMessageStatusSigned(messageId: string, rawSig: string) {\n this.setMessageStatusAndResult(messageId, rawSig, 'signed');\n }\n\n /**\n * Sets the message via a call to this.setResult and updates status of the message.\n *\n * @param messageId - The id of the Message to sign.\n * @param rawSig - The data to update rawSig in the message.\n * @param status - The new message status.\n */\n setMessageStatusAndResult(messageId: string, rawSig: string, status: string) {\n this.setResult(messageId, rawSig);\n this.setMessageStatus(messageId, status);\n }\n\n /**\n * Sets the message result.\n *\n * @param messageId - The id of the Message to sign.\n * @param result - The data to update result in the message.\n */\n setResult(messageId: string, result: string) {\n const message = this.getMessage(messageId);\n /* istanbul ignore if */\n if (!message) {\n return;\n }\n this.updateMessage(\n {\n ...message,\n rawSig: result,\n },\n false,\n );\n }\n\n /**\n * Sets the messsage metadata\n *\n * @param messageId - The id of the Message to update\n * @param metadata - The data with which to replace the metadata property in the message\n */\n setMetadata(messageId: string, metadata: Json) {\n const message = this.getMessage(messageId);\n if (!message) {\n throw new Error(\n `${this.name as string}: Message not found for id: ${messageId}.`,\n );\n }\n this.updateMessage(\n {\n ...message,\n metadata,\n },\n false,\n );\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams\n *\n * @param messageParams - The messageParams to modify\n * @returns Promise resolving to the messageParams with the metamaskId property removed\n */\n abstract prepMessageForSigning(\n messageParams: ParamsMetamask,\n ): Promise<Params>;\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - Message parameters for the message to add\n * @param req - The original request object possibly containing the origin.\n * @param version? - The version of the JSON RPC protocol the request is using.\n * @returns The id of the newly created message.\n */\n abstract addUnapprovedMessage(\n messageParams: ParamsMetamask,\n request: OriginalRequest,\n version?: string,\n ): Promise<string>;\n\n /**\n * Sets a Message status to 'rejected' via a call to this.setMessageStatus.\n *\n * @param messageId - The id of the Message to reject.\n */\n rejectMessage(messageId: string) {\n this.setMessageStatus(messageId, 'rejected');\n }\n\n /**\n * Creates a promise which will resolve or reject when the message process is finished.\n *\n * @param messageParamsWithId - The params for the personal_sign call to be made after the message is approved.\n * @param messageName - The name of the message\n * @returns Promise resolving to the raw data of the signature request.\n */\n async waitForFinishStatus(\n messageParamsWithId: AbstractMessageParamsMetamask,\n messageName: string,\n ): Promise<string> {\n const { metamaskId: messageId, ...messageParams } = messageParamsWithId;\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId as string}:finished`,\n (data: AbstractMessage) => {\n switch (data.status) {\n case 'signed':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n `MetaMask ${messageName} Signature: User denied message signature.`,\n ),\n );\n case 'errored':\n return reject(\n new Error(\n `MetaMask ${messageName} Signature: ${data.error as string}`,\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask ${messageName} Signature: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n}\n\nexport default AbstractMessageManager;\n"]}
@@ -60,7 +60,7 @@ class DecryptMessageManager extends AbstractMessageManager_1.AbstractMessageMana
60
60
  const messageData = this.createUnapprovedMessage(updatedMessageParams, controller_utils_1.ApprovalType.EthDecrypt, req);
61
61
  const messageId = messageData.id;
62
62
  await this.addMessage(messageData);
63
- this.messenger.publish(`${managerName}:unapprovedMessage`, {
63
+ this.messagingSystem.publish(`${managerName}:unapprovedMessage`, {
64
64
  ...updatedMessageParams,
65
65
  metamaskId: messageId,
66
66
  });
@@ -1 +1 @@
1
- {"version":3,"file":"DecryptMessageManager.cjs","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":";;;AAIA,iEAA0D;AAY1D,yEAAkE;AAClE,uCAA6E;AAE7E,MAAM,WAAW,GAAG,uBAAuB,CAAC;AA+E5C;;GAEG;AACH,MAAa,qBAAsB,SAAQ,+CAM1C;IACC,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACwB;QAC7B,KAAK,CAAC;YACJ,wBAAwB;YACxB,SAAS;YACT,IAAI,EAAE,WAAW;YACjB,uBAAuB;YACvB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,yBAAyB,CAC7B,aAAmC,EACnC,GAAqB;QAErB,IAAA,oCAA4B,EAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QAEtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CACtB,GAAG,SAAS,WAAW,EACvB,CAAC,IAAoB,EAAE,EAAE;gBACvB,QAAQ,IAAI,CAAC,MAAM,EAAE;oBACnB,KAAK,WAAW;wBACd,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;oBACxC,KAAK,UAAU;wBACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,0DAA0D,CAC3D,CACF,CAAC;oBACJ,KAAK,SAAS;wBACZ,OAAO,MAAM,CACX,IAAI,KAAK,CACP,4DAA4D,CAC7D,CACF,CAAC;oBACJ;wBACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,6CAA6C,IAAI,CAAC,SAAS,CACzD,aAAa,CACd,EAAE,CACJ,CACF,CAAC;iBACL;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,oBAAoB,CACxB,aAAmC,EACnC,GAAqB;QAErB,MAAM,oBAAoB,GAAG,IAAI,CAAC,yBAAyB,CACzD,aAAa,EACb,GAAG,CAC2B,CAAC;QACjC,aAAa,CAAC,IAAI,GAAG,IAAA,4BAAoB,EAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAE9D,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAC9C,oBAAoB,EACpB,+BAAY,CAAC,UAAU,EACvB,GAAG,CACqB,CAAC;QAE3B,MAAM,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;QAEjC,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACnC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,WAAW,oBAAoB,EAAE;YACzD,GAAG,oBAAoB;YACvB,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAA2C;QAE3C,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;CACF;AAvHD,sDAuHC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller/next';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport {} from '@metamask/messenger';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n OriginalRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { normalizeMessageData, validateDecryptedMessageData } from './utils';\n\nconst managerName = 'DecryptMessageManager';\n\nexport type DecryptMessageManagerState = MessageManagerState<DecryptMessage>;\n\nexport type DecryptMessageManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type DecryptMessageManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\ntype DecryptMessageManagerActions = ControllerGetStateAction<\n typeof managerName,\n DecryptMessageManagerState\n>;\n\ntype DecryptMessageManagerEvents =\n | ControllerStateChangeEvent<typeof managerName, DecryptMessageManagerState>\n | DecryptMessageManagerUnapprovedMessageAddedEvent\n | DecryptMessageManagerUpdateBadgeEvent;\n\nexport type DecryptMessageManagerMessenger = Messenger<\n typeof managerName,\n DecryptMessageManagerActions,\n DecryptMessageManagerEvents\n>;\n\ntype DecryptMessageManagerOptions = {\n messenger: DecryptMessageManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<DecryptMessage>;\n additionalFinishStatuses?: string[];\n};\n\n/**\n * @type DecryptMessage\n *\n * Represents and contains data about a 'eth_decrypt' type signature request.\n * These are created when a signature for an eth_decrypt call is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the eth_decrypt method once the request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'DecryptMessage' which always has a 'eth_decrypt' type\n */\nexport type DecryptMessage = AbstractMessage & {\n messageParams: DecryptMessageParams;\n};\n\n/**\n * @type DecryptMessageParams\n *\n * Represents the parameters to pass to the eth_decrypt method once the request is approved.\n * @property data - A hex string conversion of the raw buffer data of the signature request\n */\nexport type DecryptMessageParams = AbstractMessageParams & {\n data: string;\n};\n\n/**\n * @type DecryptMessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_decrypt method once the request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface DecryptMessageParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.\n */\nexport class DecryptMessageManager extends AbstractMessageManager<\n typeof managerName,\n DecryptMessage,\n DecryptMessageParams,\n DecryptMessageParamsMetamask,\n DecryptMessageManagerMessenger\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: DecryptMessageManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns Promise resolving to the raw data of the signature request.\n */\n async addUnapprovedMessageAsync(\n messageParams: DecryptMessageParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateDecryptedMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (data: DecryptMessage) => {\n switch (data.status) {\n case 'decrypted':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n 'MetaMask DecryptMessage: User denied message decryption.',\n ),\n );\n case 'errored':\n return reject(\n new Error(\n 'MetaMask DecryptMessage: This message cannot be decrypted.',\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask DecryptMessage: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: DecryptMessageParams,\n req?: OriginalRequest,\n ) {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies DecryptMessageParams;\n messageParams.data = normalizeMessageData(messageParams.data);\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthDecrypt,\n req,\n ) satisfies DecryptMessage;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messenger.publish(`${managerName}:unapprovedMessage`, {\n ...updatedMessageParams,\n metamaskId: messageId,\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: DecryptMessageParamsMetamask,\n ): Promise<DecryptMessageParams> {\n delete messageParams.metamaskId;\n return Promise.resolve(messageParams);\n }\n}\n"]}
1
+ {"version":3,"file":"DecryptMessageManager.cjs","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":";;;AAKA,iEAA0D;AAU1D,yEAAkE;AAClE,uCAA6E;AAE7E,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAyE5C;;GAEG;AACH,MAAa,qBAAsB,SAAQ,+CAS1C;IACC,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACwB;QAC7B,KAAK,CAAC;YACJ,wBAAwB;YACxB,SAAS;YACT,IAAI,EAAE,WAAW;YACjB,uBAAuB;YACvB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,yBAAyB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ACnC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,WAAW,oBAAoB,EAAE;YAC/D,GAAG,oBAAoB;YACvB,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAA2C;QAE3C,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;CACF;AA1HD,sDA0HC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n OriginalRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { normalizeMessageData, validateDecryptedMessageData } from './utils';\n\nconst managerName = 'DecryptMessageManager';\n\nexport type DecryptMessageManagerState = MessageManagerState<DecryptMessage>;\n\nexport type DecryptMessageManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type DecryptMessageManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\nexport type DecryptMessageManagerMessenger = RestrictedMessenger<\n typeof managerName,\n ActionConstraint,\n | EventConstraint\n | DecryptMessageManagerUnapprovedMessageAddedEvent\n | DecryptMessageManagerUpdateBadgeEvent,\n string,\n string\n>;\n\ntype DecryptMessageManagerOptions = {\n messenger: DecryptMessageManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<DecryptMessage>;\n additionalFinishStatuses?: string[];\n};\n\n/**\n * @type DecryptMessage\n *\n * Represents and contains data about a 'eth_decrypt' type signature request.\n * These are created when a signature for an eth_decrypt call is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the eth_decrypt method once the request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'DecryptMessage' which always has a 'eth_decrypt' type\n */\nexport type DecryptMessage = AbstractMessage & {\n messageParams: DecryptMessageParams;\n};\n\n/**\n * @type DecryptMessageParams\n *\n * Represents the parameters to pass to the eth_decrypt method once the request is approved.\n * @property data - A hex string conversion of the raw buffer data of the signature request\n */\nexport type DecryptMessageParams = AbstractMessageParams & {\n data: string;\n};\n\n/**\n * @type DecryptMessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_decrypt method once the request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface DecryptMessageParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.\n */\nexport class DecryptMessageManager extends AbstractMessageManager<\n typeof managerName,\n DecryptMessage,\n DecryptMessageParams,\n DecryptMessageParamsMetamask,\n ActionConstraint,\n | EventConstraint\n | DecryptMessageManagerUnapprovedMessageAddedEvent\n | DecryptMessageManagerUpdateBadgeEvent\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: DecryptMessageManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns Promise resolving to the raw data of the signature request.\n */\n async addUnapprovedMessageAsync(\n messageParams: DecryptMessageParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateDecryptedMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (data: DecryptMessage) => {\n switch (data.status) {\n case 'decrypted':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n 'MetaMask DecryptMessage: User denied message decryption.',\n ),\n );\n case 'errored':\n return reject(\n new Error(\n 'MetaMask DecryptMessage: This message cannot be decrypted.',\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask DecryptMessage: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: DecryptMessageParams,\n req?: OriginalRequest,\n ) {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies DecryptMessageParams;\n messageParams.data = normalizeMessageData(messageParams.data);\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthDecrypt,\n req,\n ) satisfies DecryptMessage;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messagingSystem.publish(`${managerName}:unapprovedMessage`, {\n ...updatedMessageParams,\n metamaskId: messageId,\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: DecryptMessageParamsMetamask,\n ): Promise<DecryptMessageParams> {\n delete messageParams.metamaskId;\n return Promise.resolve(messageParams);\n }\n}\n"]}
@@ -1,5 +1,4 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller/next";
2
- import type { Messenger } from "@metamask/messenger";
1
+ import type { ActionConstraint, EventConstraint, RestrictedMessenger } from "@metamask/base-controller";
3
2
  import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, OriginalRequest, SecurityProviderRequest } from "./AbstractMessageManager.cjs";
4
3
  import { AbstractMessageManager } from "./AbstractMessageManager.cjs";
5
4
  declare const managerName = "DecryptMessageManager";
@@ -12,9 +11,7 @@ export type DecryptMessageManagerUpdateBadgeEvent = {
12
11
  type: `${typeof managerName}:updateBadge`;
13
12
  payload: [];
14
13
  };
15
- type DecryptMessageManagerActions = ControllerGetStateAction<typeof managerName, DecryptMessageManagerState>;
16
- type DecryptMessageManagerEvents = ControllerStateChangeEvent<typeof managerName, DecryptMessageManagerState> | DecryptMessageManagerUnapprovedMessageAddedEvent | DecryptMessageManagerUpdateBadgeEvent;
17
- export type DecryptMessageManagerMessenger = Messenger<typeof managerName, DecryptMessageManagerActions, DecryptMessageManagerEvents>;
14
+ export type DecryptMessageManagerMessenger = RestrictedMessenger<typeof managerName, ActionConstraint, EventConstraint | DecryptMessageManagerUnapprovedMessageAddedEvent | DecryptMessageManagerUpdateBadgeEvent, string, string>;
18
15
  type DecryptMessageManagerOptions = {
19
16
  messenger: DecryptMessageManagerMessenger;
20
17
  securityProviderRequest?: SecurityProviderRequest;
@@ -59,7 +56,7 @@ export interface DecryptMessageParamsMetamask extends AbstractMessageParamsMetam
59
56
  /**
60
57
  * Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.
61
58
  */
62
- export declare class DecryptMessageManager extends AbstractMessageManager<typeof managerName, DecryptMessage, DecryptMessageParams, DecryptMessageParamsMetamask, DecryptMessageManagerMessenger> {
59
+ export declare class DecryptMessageManager extends AbstractMessageManager<typeof managerName, DecryptMessage, DecryptMessageParams, DecryptMessageParamsMetamask, ActionConstraint, EventConstraint | DecryptMessageManagerUnapprovedMessageAddedEvent | DecryptMessageManagerUpdateBadgeEvent> {
63
60
  constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }: DecryptMessageManagerOptions);
64
61
  /**
65
62
  * Creates a new Message with an 'unapproved' status using the passed messageParams.
@@ -1 +1 @@
1
- {"version":3,"file":"DecryptMessageManager.d.cts","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,uCAAuC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACxB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE,QAAA,MAAM,WAAW,0BAA0B,CAAC;AAE5C,MAAM,MAAM,0BAA0B,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,GAAG,OAAO,WAAW,oBAAoB,CAAC;IAChD,OAAO,EAAE,CAAC,6BAA6B,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,GAAG,OAAO,WAAW,cAAc,CAAC;IAC1C,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF,KAAK,4BAA4B,GAAG,wBAAwB,CAC1D,OAAO,WAAW,EAClB,0BAA0B,CAC3B,CAAC;AAEF,KAAK,2BAA2B,GAC5B,0BAA0B,CAAC,OAAO,WAAW,EAAE,0BAA0B,CAAC,GAC1E,gDAAgD,GAChD,qCAAqC,CAAC;AAE1C,MAAM,MAAM,8BAA8B,GAAG,SAAS,CACpD,OAAO,WAAW,EAClB,4BAA4B,EAC5B,2BAA2B,CAC5B,CAAC;AAEF,KAAK,4BAA4B,GAAG;IAClC,SAAS,EAAE,8BAA8B,CAAC;IAC1C,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;IAClD,KAAK,CAAC,EAAE,mBAAmB,CAAC,cAAc,CAAC,CAAC;IAC5C,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;CACrC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG;IAC7C,aAAa,EAAE,oBAAoB,CAAC;CACrC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,qBAAqB,GAAG;IACzD,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;;;;;GASG;AAIH,MAAM,WAAW,4BACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,sBAAsB,CAC/D,OAAO,WAAW,EAClB,cAAc,EACd,oBAAoB,EACpB,4BAA4B,EAC5B,8BAA8B,CAC/B;gBACa,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACN,EAAE,4BAA4B;IAU/B;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAqClB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,eAAe;IAwBvB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,4BAA4B,GAC1C,OAAO,CAAC,oBAAoB,CAAC;CAIjC"}
1
+ {"version":3,"file":"DecryptMessageManager.d.cts","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACpB,kCAAkC;AAGnC,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACxB,qC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,GAChD,qCAAqC,CACxC;gBACa,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACN,EAAE,4BAA4B;IAU/B;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAqClB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,eAAe;IAwBvB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,4BAA4B,GAC1C,OAAO,CAAC,oBAAoB,CAAC;CAIjC"}
@@ -1,5 +1,4 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller/next";
2
- import type { Messenger } from "@metamask/messenger";
1
+ import type { ActionConstraint, EventConstraint, RestrictedMessenger } from "@metamask/base-controller";
3
2
  import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, OriginalRequest, SecurityProviderRequest } from "./AbstractMessageManager.mjs";
4
3
  import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
5
4
  declare const managerName = "DecryptMessageManager";
@@ -12,9 +11,7 @@ export type DecryptMessageManagerUpdateBadgeEvent = {
12
11
  type: `${typeof managerName}:updateBadge`;
13
12
  payload: [];
14
13
  };
15
- type DecryptMessageManagerActions = ControllerGetStateAction<typeof managerName, DecryptMessageManagerState>;
16
- type DecryptMessageManagerEvents = ControllerStateChangeEvent<typeof managerName, DecryptMessageManagerState> | DecryptMessageManagerUnapprovedMessageAddedEvent | DecryptMessageManagerUpdateBadgeEvent;
17
- export type DecryptMessageManagerMessenger = Messenger<typeof managerName, DecryptMessageManagerActions, DecryptMessageManagerEvents>;
14
+ export type DecryptMessageManagerMessenger = RestrictedMessenger<typeof managerName, ActionConstraint, EventConstraint | DecryptMessageManagerUnapprovedMessageAddedEvent | DecryptMessageManagerUpdateBadgeEvent, string, string>;
18
15
  type DecryptMessageManagerOptions = {
19
16
  messenger: DecryptMessageManagerMessenger;
20
17
  securityProviderRequest?: SecurityProviderRequest;
@@ -59,7 +56,7 @@ export interface DecryptMessageParamsMetamask extends AbstractMessageParamsMetam
59
56
  /**
60
57
  * Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.
61
58
  */
62
- export declare class DecryptMessageManager extends AbstractMessageManager<typeof managerName, DecryptMessage, DecryptMessageParams, DecryptMessageParamsMetamask, DecryptMessageManagerMessenger> {
59
+ export declare class DecryptMessageManager extends AbstractMessageManager<typeof managerName, DecryptMessage, DecryptMessageParams, DecryptMessageParamsMetamask, ActionConstraint, EventConstraint | DecryptMessageManagerUnapprovedMessageAddedEvent | DecryptMessageManagerUpdateBadgeEvent> {
63
60
  constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }: DecryptMessageManagerOptions);
64
61
  /**
65
62
  * Creates a new Message with an 'unapproved' status using the passed messageParams.
@@ -1 +1 @@
1
- {"version":3,"file":"DecryptMessageManager.d.mts","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,uCAAuC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACxB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE,QAAA,MAAM,WAAW,0BAA0B,CAAC;AAE5C,MAAM,MAAM,0BAA0B,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,GAAG,OAAO,WAAW,oBAAoB,CAAC;IAChD,OAAO,EAAE,CAAC,6BAA6B,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI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;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG;IAC7C,aAAa,EAAE,oBAAoB,CAAC;CACrC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,qBAAqB,GAAG;IACzD,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;;;;;GASG;AAIH,MAAM,WAAW,4BACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,sBAAsB,CAC/D,OAAO,WAAW,EAClB,cAAc,EACd,oBAAoB,EACpB,4BAA4B,EAC5B,gBAAgB,EACd,eAAe,GACf,gDAAgD,GAChD,qCAAqC,CACxC;gBACa,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACN,EAAE,4BAA4B;IAU/B;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAqClB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,eAAe;IAwBvB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,4BAA4B,GAC1C,OAAO,CAAC,oBAAoB,CAAC;CAIjC"}
@@ -57,7 +57,7 @@ export class DecryptMessageManager extends AbstractMessageManager {
57
57
  const messageData = this.createUnapprovedMessage(updatedMessageParams, ApprovalType.EthDecrypt, req);
58
58
  const messageId = messageData.id;
59
59
  await this.addMessage(messageData);
60
- this.messenger.publish(`${managerName}:unapprovedMessage`, {
60
+ this.messagingSystem.publish(`${managerName}:unapprovedMessage`, {
61
61
  ...updatedMessageParams,
62
62
  metamaskId: messageId,
63
63
  });
@@ -1 +1 @@
1
- {"version":3,"file":"DecryptMessageManager.mjs","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings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ACL,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,oBAAoB,CACxB,aAAmC,EACnC,GAAqB;QAErB,MAAM,oBAAoB,GAAG,IAAI,CAAC,yBAAyB,CACzD,aAAa,EACb,GAAG,CAC2B,CAAC;QACjC,aAAa,CAAC,IAAI,GAAG,oBAAoB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAE9D,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAC9C,oBAAoB,EACpB,YAAY,CAAC,UAAU,EACvB,GAAG,CACqB,CAAC;QAE3B,MAAM,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;QAEjC,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACnC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,WAAW,oBAAoB,EAAE;YACzD,GAAG,oBAAoB;YACvB,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAA2C;QAE3C,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller/next';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport {} from '@metamask/messenger';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n OriginalRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { normalizeMessageData, validateDecryptedMessageData } from './utils';\n\nconst managerName = 'DecryptMessageManager';\n\nexport type DecryptMessageManagerState = MessageManagerState<DecryptMessage>;\n\nexport type DecryptMessageManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type DecryptMessageManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\ntype DecryptMessageManagerActions = ControllerGetStateAction<\n typeof managerName,\n DecryptMessageManagerState\n>;\n\ntype DecryptMessageManagerEvents =\n | ControllerStateChangeEvent<typeof managerName, DecryptMessageManagerState>\n | DecryptMessageManagerUnapprovedMessageAddedEvent\n | DecryptMessageManagerUpdateBadgeEvent;\n\nexport type DecryptMessageManagerMessenger = Messenger<\n typeof managerName,\n DecryptMessageManagerActions,\n DecryptMessageManagerEvents\n>;\n\ntype DecryptMessageManagerOptions = {\n messenger: DecryptMessageManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<DecryptMessage>;\n additionalFinishStatuses?: string[];\n};\n\n/**\n * @type DecryptMessage\n *\n * Represents and contains data about a 'eth_decrypt' type signature request.\n * These are created when a signature for an eth_decrypt call is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the eth_decrypt method once the request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'DecryptMessage' which always has a 'eth_decrypt' type\n */\nexport type DecryptMessage = AbstractMessage & {\n messageParams: DecryptMessageParams;\n};\n\n/**\n * @type DecryptMessageParams\n *\n * Represents the parameters to pass to the eth_decrypt method once the request is approved.\n * @property data - A hex string conversion of the raw buffer data of the signature request\n */\nexport type DecryptMessageParams = AbstractMessageParams & {\n data: string;\n};\n\n/**\n * @type DecryptMessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_decrypt method once the request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface DecryptMessageParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.\n */\nexport class DecryptMessageManager extends AbstractMessageManager<\n typeof managerName,\n DecryptMessage,\n DecryptMessageParams,\n DecryptMessageParamsMetamask,\n DecryptMessageManagerMessenger\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: DecryptMessageManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns Promise resolving to the raw data of the signature request.\n */\n async addUnapprovedMessageAsync(\n messageParams: DecryptMessageParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateDecryptedMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (data: DecryptMessage) => {\n switch (data.status) {\n case 'decrypted':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n 'MetaMask DecryptMessage: User denied message decryption.',\n ),\n );\n case 'errored':\n return reject(\n new Error(\n 'MetaMask DecryptMessage: This message cannot be decrypted.',\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask DecryptMessage: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: DecryptMessageParams,\n req?: OriginalRequest,\n ) {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies DecryptMessageParams;\n messageParams.data = normalizeMessageData(messageParams.data);\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthDecrypt,\n req,\n ) satisfies DecryptMessage;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messenger.publish(`${managerName}:unapprovedMessage`, {\n ...updatedMessageParams,\n metamaskId: messageId,\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: DecryptMessageParamsMetamask,\n ): Promise<DecryptMessageParams> {\n delete messageParams.metamaskId;\n return Promise.resolve(messageParams);\n }\n}\n"]}
1
+ {"version":3,"file":"DecryptMessageManager.mjs","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAU1D,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,oBAAgB;AAE7E,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAyE5C;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,sBAS1C;IACC,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACwB;QAC7B,KAAK,CAAC;YACJ,wBAAwB;YACxB,SAAS;YACT,IAAI,EAAE,WAAW;YACjB,uBAAuB;YACvB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,yBAAyB,CAC7B,aAAmC,EACnC,GAAqB;QAErB,4BAA4B,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QAEtE,OAAO,IAA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H,qBAAqB,CACnB,aAA2C;QAE3C,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n OriginalRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { normalizeMessageData, validateDecryptedMessageData } from './utils';\n\nconst managerName = 'DecryptMessageManager';\n\nexport type DecryptMessageManagerState = MessageManagerState<DecryptMessage>;\n\nexport type DecryptMessageManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type DecryptMessageManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\nexport type DecryptMessageManagerMessenger = RestrictedMessenger<\n typeof managerName,\n ActionConstraint,\n | EventConstraint\n | DecryptMessageManagerUnapprovedMessageAddedEvent\n | DecryptMessageManagerUpdateBadgeEvent,\n string,\n string\n>;\n\ntype DecryptMessageManagerOptions = {\n messenger: DecryptMessageManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<DecryptMessage>;\n additionalFinishStatuses?: string[];\n};\n\n/**\n * @type DecryptMessage\n *\n * Represents and contains data about a 'eth_decrypt' type signature request.\n * These are created when a signature for an eth_decrypt call is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the eth_decrypt method once the request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'DecryptMessage' which always has a 'eth_decrypt' type\n */\nexport type DecryptMessage = AbstractMessage & {\n messageParams: DecryptMessageParams;\n};\n\n/**\n * @type DecryptMessageParams\n *\n * Represents the parameters to pass to the eth_decrypt method once the request is approved.\n * @property data - A hex string conversion of the raw buffer data of the signature request\n */\nexport type DecryptMessageParams = AbstractMessageParams & {\n data: string;\n};\n\n/**\n * @type DecryptMessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_decrypt method once the request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface DecryptMessageParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.\n */\nexport class DecryptMessageManager extends AbstractMessageManager<\n typeof managerName,\n DecryptMessage,\n DecryptMessageParams,\n DecryptMessageParamsMetamask,\n ActionConstraint,\n | EventConstraint\n | DecryptMessageManagerUnapprovedMessageAddedEvent\n | DecryptMessageManagerUpdateBadgeEvent\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: DecryptMessageManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns Promise resolving to the raw data of the signature request.\n */\n async addUnapprovedMessageAsync(\n messageParams: DecryptMessageParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateDecryptedMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (data: DecryptMessage) => {\n switch (data.status) {\n case 'decrypted':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n 'MetaMask DecryptMessage: User denied message decryption.',\n ),\n );\n case 'errored':\n return reject(\n new Error(\n 'MetaMask DecryptMessage: This message cannot be decrypted.',\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask DecryptMessage: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: DecryptMessageParams,\n req?: OriginalRequest,\n ) {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies DecryptMessageParams;\n messageParams.data = normalizeMessageData(messageParams.data);\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthDecrypt,\n req,\n ) satisfies DecryptMessage;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messagingSystem.publish(`${managerName}:unapprovedMessage`, {\n ...updatedMessageParams,\n metamaskId: messageId,\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: DecryptMessageParamsMetamask,\n ): Promise<DecryptMessageParams> {\n delete messageParams.metamaskId;\n return Promise.resolve(messageParams);\n }\n}\n"]}
@@ -57,7 +57,7 @@ class EncryptionPublicKeyManager extends AbstractMessageManager_1.AbstractMessag
57
57
  const messageData = this.createUnapprovedMessage(updatedMessageParams, controller_utils_1.ApprovalType.EthGetEncryptionPublicKey, req);
58
58
  const messageId = messageData.id;
59
59
  await this.addMessage(messageData);
60
- this.messenger.publish(`${this.name}:unapprovedMessage`, {
60
+ this.messagingSystem.publish(`${this.name}:unapprovedMessage`, {
61
61
  ...updatedMessageParams,
62
62
  metamaskId: messageId,
63
63
  });
@@ -1 +1 @@
1
- {"version":3,"file":"EncryptionPublicKeyManager.cjs","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":";;;AAIA,iEAA0D;AAW1D,yEAAkE;AAClE,uCAAiE;AAEjE,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAgFjD;;GAEG;AACH,MAAa,0BAA2B,SAAQ,+CAM/C;IACC,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GAC6B;QAClC,KAAK,CAAC;YACJ,wBAAwB;YACxB,SAAS;YACT,IAAI,EAAE,WAAW;YACjB,uBAAuB;YACvB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,yBAAyB,CAC7B,aAAwC,EACxC,GAAqB;QAErB,IAAA,8CAAsC,EAAC,aAAa,CAAC,CAAC;QACtD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QAEtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CACtB,GAAG,SAAS,WAAW,EACvB,CAAC,IAAyB,EAAE,EAAE;gBAC5B,QAAQ,IAAI,CAAC,MAAM,EAAE;oBACnB,KAAK,UAAU;wBACb,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;oBACxC,KAAK,UAAU;wBACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,wEAAwE,CACzE,CACF,CAAC;oBACJ;wBACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,kDAAkD,IAAI,CAAC,SAAS,CAC9D,aAAa,CACd,EAAE,CACJ,CACF,CAAC;iBACL;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,oBAAoB,CACxB,aAAwC,EACxC,GAAqB;QAErB,MAAM,oBAAoB,GAAG,IAAI,CAAC,yBAAyB,CACzD,aAAa,EACb,GAAG,CACgC,CAAC;QAEtC,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAC9C,oBAAoB,EACpB,+BAAY,CAAC,yBAAyB,EACtC,GAAG,CAC0B,CAAC;QAEhC,MAAM,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;QAEjC,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACnC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,oBAA6B,EAAE;YAChE,GAAG,oBAAoB;YACvB,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAgD;QAEhD,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;CACF;AAhHD,gEAgHC;AAED,kBAAe,0BAA0B,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller/next';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n OriginalRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { validateEncryptionPublicKeyMessageData } from './utils';\n\nconst managerName = 'EncryptionPublicKeyManager';\n\nexport type EncryptionPublicKeyManagerState =\n MessageManagerState<EncryptionPublicKey>;\n\nexport type EncryptionPublicKeyManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type EncryptionPublicKeyManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\ntype EncryptionPublicKeyManagerActions = ControllerGetStateAction<\n typeof managerName,\n EncryptionPublicKeyManagerState\n>;\n\ntype EncryptionPublicKeyManagerEvents =\n | ControllerStateChangeEvent<\n typeof managerName,\n EncryptionPublicKeyManagerState\n >\n | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent\n | EncryptionPublicKeyManagerUpdateBadgeEvent;\n\nexport type EncryptionPublicKeyManagerMessenger = Messenger<\n typeof managerName,\n EncryptionPublicKeyManagerActions,\n EncryptionPublicKeyManagerEvents\n>;\n\ntype EncryptionPublicKeyManagerOptions = {\n messenger: EncryptionPublicKeyManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<EncryptionPublicKey>;\n additionalFinishStatuses?: string[];\n};\n\n/**\n * @type EncryptionPublicKey\n *\n * Represents and contains data about a 'eth_getEncryptionPublicKey' type request.\n * These are created when an encryption public key is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * @property type - The json-prc method for which an encryption public key request has been made.\n * A 'Message' which always has a 'eth_getEncryptionPublicKey' type\n * @property rawSig - Encryption public key\n */\nexport type EncryptionPublicKey = AbstractMessage & {\n messageParams: EncryptionPublicKeyParams;\n};\n\n/**\n * @type EncryptionPublicKeyParams\n *\n * Represents the parameters to pass to the method once the request is approved.\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport type EncryptionPublicKeyParams = AbstractMessageParams;\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - Encryption public key\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport type EncryptionPublicKeyParamsMetamask =\n AbstractMessageParamsMetamask & {\n data: string;\n };\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport class EncryptionPublicKeyManager extends AbstractMessageManager<\n typeof managerName,\n EncryptionPublicKey,\n EncryptionPublicKeyParams,\n EncryptionPublicKeyParamsMetamask,\n EncryptionPublicKeyManagerMessenger\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: EncryptionPublicKeyManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns Promise resolving to the raw data of the request.\n */\n async addUnapprovedMessageAsync(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateEncryptionPublicKeyMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (data: EncryptionPublicKey) => {\n switch (data.status) {\n case 'received':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n 'MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.',\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask EncryptionPublicKey: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies EncryptionPublicKeyParams;\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthGetEncryptionPublicKey,\n req,\n ) satisfies EncryptionPublicKey;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messenger.publish(`${this.name}:unapprovedMessage` as const, {\n ...updatedMessageParams,\n metamaskId: messageId,\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: EncryptionPublicKeyParamsMetamask,\n ): Promise<EncryptionPublicKeyParams> {\n delete messageParams.metamaskId;\n return Promise.resolve({ from: messageParams.data });\n }\n}\n\nexport default EncryptionPublicKeyManager;\n"]}
1
+ {"version":3,"file":"EncryptionPublicKeyManager.cjs","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":";;;AAKA,iEAA0D;AAU1D,yEAAkE;AAClE,uCAAiE;AAEjE,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAuEjD;;GAEG;AACH,MAAa,0BAA2B,SAAQ,+CAS/C;IACC,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GAC6B;QAClC,KAAK,CAAC;YACJ,wBAAwB;YACxB,SAAS;YACT,IAAI,EAAE,WAAW;YACjB,uBAAuB;YACvB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,yBAAyB,CAC7B,aAAwC,EACxC,GAAqB;QAErB,IAAA,8CAAsC,EAAC,aAAa,CAAC,CAAC;QACtD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QAEtE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EAAE,CAAC,CAAC;IACvD,CAAC;CACF;AAnHD,gEAmHC;AAED,kBAAe,0BAA0B,CAAC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n OriginalRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { validateEncryptionPublicKeyMessageData } from './utils';\n\nconst managerName = 'EncryptionPublicKeyManager';\n\nexport type EncryptionPublicKeyManagerState =\n MessageManagerState<EncryptionPublicKey>;\n\nexport type EncryptionPublicKeyManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type EncryptionPublicKeyManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\nexport type EncryptionPublicKeyManagerMessenger = RestrictedMessenger<\n typeof managerName,\n ActionConstraint,\n | EventConstraint\n | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent\n | EncryptionPublicKeyManagerUpdateBadgeEvent,\n string,\n string\n>;\n\ntype EncryptionPublicKeyManagerOptions = {\n messenger: EncryptionPublicKeyManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<EncryptionPublicKey>;\n additionalFinishStatuses?: string[];\n};\n\n/**\n * @type EncryptionPublicKey\n *\n * Represents and contains data about a 'eth_getEncryptionPublicKey' type request.\n * These are created when an encryption public key is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * @property type - The json-prc method for which an encryption public key request has been made.\n * A 'Message' which always has a 'eth_getEncryptionPublicKey' type\n * @property rawSig - Encryption public key\n */\nexport type EncryptionPublicKey = AbstractMessage & {\n messageParams: EncryptionPublicKeyParams;\n};\n\n/**\n * @type EncryptionPublicKeyParams\n *\n * Represents the parameters to pass to the method once the request is approved.\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport type EncryptionPublicKeyParams = AbstractMessageParams;\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - Encryption public key\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport type EncryptionPublicKeyParamsMetamask =\n AbstractMessageParamsMetamask & {\n data: string;\n };\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport class EncryptionPublicKeyManager extends AbstractMessageManager<\n typeof managerName,\n EncryptionPublicKey,\n EncryptionPublicKeyParams,\n EncryptionPublicKeyParamsMetamask,\n ActionConstraint,\n | EventConstraint\n | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent\n | EncryptionPublicKeyManagerUpdateBadgeEvent\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: EncryptionPublicKeyManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns Promise resolving to the raw data of the request.\n */\n async addUnapprovedMessageAsync(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateEncryptionPublicKeyMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (data: EncryptionPublicKey) => {\n switch (data.status) {\n case 'received':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n 'MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.',\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask EncryptionPublicKey: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies EncryptionPublicKeyParams;\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthGetEncryptionPublicKey,\n req,\n ) satisfies EncryptionPublicKey;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messagingSystem.publish(`${this.name}:unapprovedMessage`, {\n ...updatedMessageParams,\n metamaskId: messageId,\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: EncryptionPublicKeyParamsMetamask,\n ): Promise<EncryptionPublicKeyParams> {\n delete messageParams.metamaskId;\n return Promise.resolve({ from: messageParams.data });\n }\n}\n\nexport default EncryptionPublicKeyManager;\n"]}
@@ -1,5 +1,4 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller/next";
2
- import type { Messenger } from "@metamask/messenger";
1
+ import type { ActionConstraint, EventConstraint, RestrictedMessenger } from "@metamask/base-controller";
3
2
  import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, OriginalRequest, SecurityProviderRequest } from "./AbstractMessageManager.cjs";
4
3
  import { AbstractMessageManager } from "./AbstractMessageManager.cjs";
5
4
  declare const managerName = "EncryptionPublicKeyManager";
@@ -12,9 +11,7 @@ export type EncryptionPublicKeyManagerUpdateBadgeEvent = {
12
11
  type: `${typeof managerName}:updateBadge`;
13
12
  payload: [];
14
13
  };
15
- type EncryptionPublicKeyManagerActions = ControllerGetStateAction<typeof managerName, EncryptionPublicKeyManagerState>;
16
- type EncryptionPublicKeyManagerEvents = ControllerStateChangeEvent<typeof managerName, EncryptionPublicKeyManagerState> | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent | EncryptionPublicKeyManagerUpdateBadgeEvent;
17
- export type EncryptionPublicKeyManagerMessenger = Messenger<typeof managerName, EncryptionPublicKeyManagerActions, EncryptionPublicKeyManagerEvents>;
14
+ export type EncryptionPublicKeyManagerMessenger = RestrictedMessenger<typeof managerName, ActionConstraint, EventConstraint | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent | EncryptionPublicKeyManagerUpdateBadgeEvent, string, string>;
18
15
  type EncryptionPublicKeyManagerOptions = {
19
16
  messenger: EncryptionPublicKeyManagerMessenger;
20
17
  securityProviderRequest?: SecurityProviderRequest;
@@ -59,7 +56,7 @@ export type EncryptionPublicKeyParamsMetamask = AbstractMessageParamsMetamask &
59
56
  /**
60
57
  * Controller in charge of managing - storing, adding, removing, updating - Messages.
61
58
  */
62
- export declare class EncryptionPublicKeyManager extends AbstractMessageManager<typeof managerName, EncryptionPublicKey, EncryptionPublicKeyParams, EncryptionPublicKeyParamsMetamask, EncryptionPublicKeyManagerMessenger> {
59
+ export declare class EncryptionPublicKeyManager extends AbstractMessageManager<typeof managerName, EncryptionPublicKey, EncryptionPublicKeyParams, EncryptionPublicKeyParamsMetamask, ActionConstraint, EventConstraint | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent | EncryptionPublicKeyManagerUpdateBadgeEvent> {
63
60
  constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }: EncryptionPublicKeyManagerOptions);
64
61
  /**
65
62
  * Creates a new Message with an 'unapproved' status using the passed messageParams.
@@ -1 +1 @@
1
- {"version":3,"file":"EncryptionPublicKeyManager.d.cts","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,uCAAuC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACxB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE,QAAA,MAAM,WAAW,+BAA+B,CAAC;AAEjD,MAAM,MAAM,+BAA+B,GACzC,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;AAE3C,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,GAAG,OAAO,WAAW,oBAAoB,CAAC;IAChD,OAAO,EAAE,CAAC,6BAA6B,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,GAAG,OAAO,WAAW,cAAc,CAAC;IAC1C,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF,KAAK,iCAAiC,GAAG,wBAAwB,CAC/D,OAAO,WAAW,EAClB,+BAA+B,CAChC,CAAC;AAEF,KAAK,gCAAgC,GACjC,0BAA0B,CACxB,OAAO,WAAW,EAClB,+BAA+B,CAChC,GACD,qDAAqD,GACrD,0CAA0C,CAAC;AAE/C,MAAM,MAAM,mCAAmC,GAAG,SAAS,CACzD,OAAO,WAAW,EAClB,iCAAiC,EACjC,gCAAgC,CACjC,CAAC;AAEF,KAAK,iCAAiC,GAAG;IACvC,SAAS,EAAE,mCAAmC,CAAC;IAC/C,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;IAClD,KAAK,CAAC,EAAE,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;IACjD,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG;IAClD,aAAa,EAAE,yBAAyB,CAAC;CAC1C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,GAAG,qBAAqB,CAAC;AAE9D;;;;;;;;;GASG;AACH,MAAM,MAAM,iCAAiC,GAC3C,6BAA6B,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEJ;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,sBAAsB,CACpE,OAAO,WAAW,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,iCAAiC,EACjC,mCAAmC,CACpC;gBACa,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACN,EAAE,iCAAiC;IAUpC;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA+BlB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAsBlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,iCAAiC,GAC/C,OAAO,CAAC,yBAAyB,CAAC;CAItC;AAED,eAAe,0BAA0B,CAAC"}
1
+ {"version":3,"file":"EncryptionPublicKeyManager.d.cts","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACpB,kCAAkC;AAGnC,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACxB,qCAAiC;AAClC,OAAO,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V,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACN,EAAE,iCAAiC;IAUpC;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA+BlB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAsBlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,iCAAiC,GAC/C,OAAO,CAAC,yBAAyB,CAAC;CAItC;AAED,eAAe,0BAA0B,CAAC"}
@@ -1,5 +1,4 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller/next";
2
- import type { Messenger } from "@metamask/messenger";
1
+ import type { ActionConstraint, EventConstraint, RestrictedMessenger } from "@metamask/base-controller";
3
2
  import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, OriginalRequest, SecurityProviderRequest } from "./AbstractMessageManager.mjs";
4
3
  import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
5
4
  declare const managerName = "EncryptionPublicKeyManager";
@@ -12,9 +11,7 @@ export type EncryptionPublicKeyManagerUpdateBadgeEvent = {
12
11
  type: `${typeof managerName}:updateBadge`;
13
12
  payload: [];
14
13
  };
15
- type EncryptionPublicKeyManagerActions = ControllerGetStateAction<typeof managerName, EncryptionPublicKeyManagerState>;
16
- type EncryptionPublicKeyManagerEvents = ControllerStateChangeEvent<typeof managerName, EncryptionPublicKeyManagerState> | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent | EncryptionPublicKeyManagerUpdateBadgeEvent;
17
- export type EncryptionPublicKeyManagerMessenger = Messenger<typeof managerName, EncryptionPublicKeyManagerActions, EncryptionPublicKeyManagerEvents>;
14
+ export type EncryptionPublicKeyManagerMessenger = RestrictedMessenger<typeof managerName, ActionConstraint, EventConstraint | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent | EncryptionPublicKeyManagerUpdateBadgeEvent, string, string>;
18
15
  type EncryptionPublicKeyManagerOptions = {
19
16
  messenger: EncryptionPublicKeyManagerMessenger;
20
17
  securityProviderRequest?: SecurityProviderRequest;
@@ -59,7 +56,7 @@ export type EncryptionPublicKeyParamsMetamask = AbstractMessageParamsMetamask &
59
56
  /**
60
57
  * Controller in charge of managing - storing, adding, removing, updating - Messages.
61
58
  */
62
- export declare class EncryptionPublicKeyManager extends AbstractMessageManager<typeof managerName, EncryptionPublicKey, EncryptionPublicKeyParams, EncryptionPublicKeyParamsMetamask, EncryptionPublicKeyManagerMessenger> {
59
+ export declare class EncryptionPublicKeyManager extends AbstractMessageManager<typeof managerName, EncryptionPublicKey, EncryptionPublicKeyParams, EncryptionPublicKeyParamsMetamask, ActionConstraint, EventConstraint | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent | EncryptionPublicKeyManagerUpdateBadgeEvent> {
63
60
  constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }: EncryptionPublicKeyManagerOptions);
64
61
  /**
65
62
  * Creates a new Message with an 'unapproved' status using the passed messageParams.
@@ -1 +1 @@
1
- {"version":3,"file":"EncryptionPublicKeyManager.d.mts","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,uCAAuC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACxB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE,QAAA,MAAM,WAAW,+BAA+B,CAAC;AAEjD,MAAM,MAAM,+BAA+B,GACzC,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;AAE3C,MAAM,MAAM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AE,iCAAiC;IAUpC;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA+BlB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAsBlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,iCAAiC,GAC/C,OAAO,CAAC,yBAAyB,CAAC;CAItC;AAED,eAAe,0BAA0B,CAAC"}
1
+ {"version":3,"file":"EncryptionPublicKeyManager.d.mts","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACpB,kCAAkC;AAGnC,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACxB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE,QAAA,MAAM,WAAW,+BAA+B,CAAC;AAEjD,MAAM,MAAM,+BAA+B,GACzC,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;AAE3C,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,GAAG,OAAO,WAAW,oBAAoB,CAAC;IAChD,OAAO,EAAE,CAAC,6BAA6B,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,GAAG,OAAO,WAAW,cAAc,CAAC;IAC1C,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG,mBAAmB,CACnE,OAAO,WAAW,EAClB,gBAAgB,EACd,eAAe,GACf,qDAAqD,GACrD,0CAA0C,EAC5C,MAAM,EACN,MAAM,CACP,CAAC;AAEF,KAAK,iCAAiC,GAAG;IACvC,SAAS,EAAE,mCAAmC,CAAC;IAC/C,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;IAClD,KAAK,CAAC,EAAE,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;IACjD,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG;IAClD,aAAa,EAAE,yBAAyB,CAAC;CAC1C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,GAAG,qBAAqB,CAAC;AAE9D;;;;;;;;;GASG;AACH,MAAM,MAAM,iCAAiC,GAC3C,6BAA6B,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEJ;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,sBAAsB,CACpE,OAAO,WAAW,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,iCAAiC,EACjC,gBAAgB,EACd,eAAe,GACf,qDAAqD,GACrD,0CAA0C,CAC7C;gBACa,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACN,EAAE,iCAAiC;IAUpC;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA+BlB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAsBlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,iCAAiC,GAC/C,OAAO,CAAC,yBAAyB,CAAC;CAItC;AAED,eAAe,0BAA0B,CAAC"}
@@ -54,7 +54,7 @@ export class EncryptionPublicKeyManager extends AbstractMessageManager {
54
54
  const messageData = this.createUnapprovedMessage(updatedMessageParams, ApprovalType.EthGetEncryptionPublicKey, req);
55
55
  const messageId = messageData.id;
56
56
  await this.addMessage(messageData);
57
- this.messenger.publish(`${this.name}:unapprovedMessage`, {
57
+ this.messagingSystem.publish(`${this.name}:unapprovedMessage`, {
58
58
  ...updatedMessageParams,
59
59
  metamaskId: messageId,
60
60
  });
@@ -1 +1 @@
1
- {"version":3,"file":"EncryptionPublicKeyManager.mjs","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAW1D,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,sCAAsC,EAAE,oBAAgB;AAEjE,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAgFjD;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,sBAM/C;IACC,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GAC6B;QAClC,KAAK,CAAC;YACJ,wBAAwB;YACxB,SAAS;YACT,IAAI,EAAE,WAAW;YACjB,uBAAuB;YACvB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,yBAAyB,CAC7B,aAAwC,EACxC,GAAqB;QAErB,sCAAsC,CAAC,aAAa,CAAC,CAAC;QACtD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QAEtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CACtB,GAAG,SAAS,WAAW,EACvB,CAAC,IAAyB,EAAE,EAAE;gBAC5B,QAAQ,IAAI,CAAC,MAAM,EAAE;oBACnB,KAAK,UAAU;wBACb,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;oBACxC,KAAK,UAAU;wBACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,wEAAwE,CACzE,CACF,CAAC;oBACJ;wBACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,kDAAkD,IAAI,CAAC,SAAS,CAC9D,aAAa,CACd,EAAE,CACJ,CACF,CAAC;iBACL;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,oBAAoB,CACxB,aAAwC,EACxC,GAAqB;QAErB,MAAM,oBAAoB,GAAG,IAAI,CAAC,yBAAyB,CACzD,aAAa,EACb,GAAG,CACgC,CAAC;QAEtC,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAC9C,oBAAoB,EACpB,YAAY,CAAC,yBAAyB,EACtC,GAAG,CAC0B,CAAC;QAEhC,MAAM,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;QAEjC,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACnC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,oBAA6B,EAAE;YAChE,GAAG,oBAAoB;YACvB,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAgD;QAEhD,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;CACF;AAED,eAAe,0BAA0B,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller/next';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n OriginalRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { validateEncryptionPublicKeyMessageData } from './utils';\n\nconst managerName = 'EncryptionPublicKeyManager';\n\nexport type EncryptionPublicKeyManagerState =\n MessageManagerState<EncryptionPublicKey>;\n\nexport type EncryptionPublicKeyManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type EncryptionPublicKeyManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\ntype EncryptionPublicKeyManagerActions = ControllerGetStateAction<\n typeof managerName,\n EncryptionPublicKeyManagerState\n>;\n\ntype EncryptionPublicKeyManagerEvents =\n | ControllerStateChangeEvent<\n typeof managerName,\n EncryptionPublicKeyManagerState\n >\n | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent\n | EncryptionPublicKeyManagerUpdateBadgeEvent;\n\nexport type EncryptionPublicKeyManagerMessenger = Messenger<\n typeof managerName,\n EncryptionPublicKeyManagerActions,\n EncryptionPublicKeyManagerEvents\n>;\n\ntype EncryptionPublicKeyManagerOptions = {\n messenger: EncryptionPublicKeyManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<EncryptionPublicKey>;\n additionalFinishStatuses?: string[];\n};\n\n/**\n * @type EncryptionPublicKey\n *\n * Represents and contains data about a 'eth_getEncryptionPublicKey' type request.\n * These are created when an encryption public key is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * @property type - The json-prc method for which an encryption public key request has been made.\n * A 'Message' which always has a 'eth_getEncryptionPublicKey' type\n * @property rawSig - Encryption public key\n */\nexport type EncryptionPublicKey = AbstractMessage & {\n messageParams: EncryptionPublicKeyParams;\n};\n\n/**\n * @type EncryptionPublicKeyParams\n *\n * Represents the parameters to pass to the method once the request is approved.\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport type EncryptionPublicKeyParams = AbstractMessageParams;\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - Encryption public key\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport type EncryptionPublicKeyParamsMetamask =\n AbstractMessageParamsMetamask & {\n data: string;\n };\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport class EncryptionPublicKeyManager extends AbstractMessageManager<\n typeof managerName,\n EncryptionPublicKey,\n EncryptionPublicKeyParams,\n EncryptionPublicKeyParamsMetamask,\n EncryptionPublicKeyManagerMessenger\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: EncryptionPublicKeyManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns Promise resolving to the raw data of the request.\n */\n async addUnapprovedMessageAsync(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateEncryptionPublicKeyMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (data: EncryptionPublicKey) => {\n switch (data.status) {\n case 'received':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n 'MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.',\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask EncryptionPublicKey: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies EncryptionPublicKeyParams;\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthGetEncryptionPublicKey,\n req,\n ) satisfies EncryptionPublicKey;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messenger.publish(`${this.name}:unapprovedMessage` as const, {\n ...updatedMessageParams,\n metamaskId: messageId,\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: EncryptionPublicKeyParamsMetamask,\n ): Promise<EncryptionPublicKeyParams> {\n delete messageParams.metamaskId;\n return Promise.resolve({ from: messageParams.data });\n }\n}\n\nexport default EncryptionPublicKeyManager;\n"]}
1
+ {"version":3,"file":"EncryptionPublicKeyManager.mjs","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAU1D,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,sCAAsC,EAAE,oBAAgB;AAEjE,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAuEjD;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,sBAS/C;IACC,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GAC6B;QAClC,KAAK,CAAC;YACJ,wBAAwB;YACxB,SAAS;YACT,IAAI,EAAE,WAAW;YACjB,uBAAuB;YACvB,KAAK;SACN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,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAgD;QAEhD,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;CACF;AAED,eAAe,0BAA0B,CAAC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n OriginalRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { validateEncryptionPublicKeyMessageData } from './utils';\n\nconst managerName = 'EncryptionPublicKeyManager';\n\nexport type EncryptionPublicKeyManagerState =\n MessageManagerState<EncryptionPublicKey>;\n\nexport type EncryptionPublicKeyManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type EncryptionPublicKeyManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\nexport type EncryptionPublicKeyManagerMessenger = RestrictedMessenger<\n typeof managerName,\n ActionConstraint,\n | EventConstraint\n | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent\n | EncryptionPublicKeyManagerUpdateBadgeEvent,\n string,\n string\n>;\n\ntype EncryptionPublicKeyManagerOptions = {\n messenger: EncryptionPublicKeyManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<EncryptionPublicKey>;\n additionalFinishStatuses?: string[];\n};\n\n/**\n * @type EncryptionPublicKey\n *\n * Represents and contains data about a 'eth_getEncryptionPublicKey' type request.\n * These are created when an encryption public key is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * @property type - The json-prc method for which an encryption public key request has been made.\n * A 'Message' which always has a 'eth_getEncryptionPublicKey' type\n * @property rawSig - Encryption public key\n */\nexport type EncryptionPublicKey = AbstractMessage & {\n messageParams: EncryptionPublicKeyParams;\n};\n\n/**\n * @type EncryptionPublicKeyParams\n *\n * Represents the parameters to pass to the method once the request is approved.\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport type EncryptionPublicKeyParams = AbstractMessageParams;\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - Encryption public key\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport type EncryptionPublicKeyParamsMetamask =\n AbstractMessageParamsMetamask & {\n data: string;\n };\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport class EncryptionPublicKeyManager extends AbstractMessageManager<\n typeof managerName,\n EncryptionPublicKey,\n EncryptionPublicKeyParams,\n EncryptionPublicKeyParamsMetamask,\n ActionConstraint,\n | EventConstraint\n | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent\n | EncryptionPublicKeyManagerUpdateBadgeEvent\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: EncryptionPublicKeyManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns Promise resolving to the raw data of the request.\n */\n async addUnapprovedMessageAsync(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateEncryptionPublicKeyMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (data: EncryptionPublicKey) => {\n switch (data.status) {\n case 'received':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n 'MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.',\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask EncryptionPublicKey: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies EncryptionPublicKeyParams;\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthGetEncryptionPublicKey,\n req,\n ) satisfies EncryptionPublicKey;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messagingSystem.publish(`${this.name}:unapprovedMessage`, {\n ...updatedMessageParams,\n metamaskId: messageId,\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: EncryptionPublicKeyParamsMetamask,\n ): Promise<EncryptionPublicKeyParams> {\n delete messageParams.metamaskId;\n return Promise.resolve({ from: messageParams.data });\n }\n}\n\nexport default EncryptionPublicKeyManager;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/message-manager",
3
- "version": "13.0.1-preview-ab0ad568",
3
+ "version": "13.0.2-preview-ebf01f52",
4
4
  "description": "Stores and manages interactions with signing requests",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -50,7 +50,6 @@
50
50
  "@metamask/base-controller": "^8.4.2",
51
51
  "@metamask/controller-utils": "^11.14.1",
52
52
  "@metamask/eth-sig-util": "^8.2.0",
53
- "@metamask/messenger": "^0.3.0",
54
53
  "@metamask/utils": "^11.8.1",
55
54
  "@types/uuid": "^8.3.0",
56
55
  "jsonschema": "^1.4.1",