@metamask-previews/message-manager 7.3.5-preview.e3b05ea → 7.3.5-preview.eb58a59
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/dist/AbstractMessageManager.d.ts.map +1 -1
- package/dist/AbstractMessageManager.js.map +1 -1
- package/dist/DecryptMessageManager.d.ts.map +1 -1
- package/dist/DecryptMessageManager.js.map +1 -1
- package/dist/EncryptionPublicKeyManager.d.ts.map +1 -1
- package/dist/EncryptionPublicKeyManager.js.map +1 -1
- package/dist/MessageManager.d.ts.map +1 -1
- package/dist/MessageManager.js.map +1 -1
- package/dist/PersonalMessageManager.d.ts.map +1 -1
- package/dist/PersonalMessageManager.js.map +1 -1
- package/dist/TypedMessageManager.d.ts.map +1 -1
- package/dist/TypedMessageManager.js.map +1 -1
- package/package.json +5 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractMessageManager.d.ts","sourceRoot":"","sources":["../src/AbstractMessageManager.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"AbstractMessageManager.d.ts","sourceRoot":"","sources":["../src/AbstractMessageManager.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AA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AI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,SAAS,WAAW,EAAE,CAAC,IAAqB,EAAE,EAAE;oBAC/D,QAAQ,IAAI,CAAC,MAAM,EAAE;wBACnB,KAAK,QAAQ;4BACX,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;wBACxC,KAAK,UAAU;4BACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,YAAY,WAAW,4CAA4C,CACpE,CACF,CAAC;wBACJ,KAAK,SAAS;4BACZ,OAAO,MAAM,CACX,IAAI,KAAK,CAAC,YAAY,WAAW,eAAe,IAAI,CAAC,KAAK,EAAE,CAAC,CAC9D,CAAC;wBACJ;4BACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,YAAY,WAAW,gCAAgC,IAAI,CAAC,SAAS,CACnE,aAAa,CACd,EAAE,CACJ,CACF,CAAC;qBACL;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AAvVD,wDAuVC;AAED,kBAAe,sBAAsB,CAAC","sourcesContent":["import type { BaseConfig, BaseState } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Hex, Json } from '@metamask/utils';\nimport { EventEmitter } from 'events';\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 interface OriginalRequest {\n origin?: string;\n securityAlertResponse?: Record<string, Json>;\n}\n\n/**\n * @type Message\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 interface 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 MessageParams\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 deferSetAsSigned? - Whether to defer setting the message as signed immediately after the keyring is told to sign it\n */\nexport interface AbstractMessageParams {\n from: string;\n origin?: string;\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 interface AbstractMessageParamsMetamask extends 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 interface MessageManagerState<M extends AbstractMessage>\n extends BaseState {\n unapprovedMessages: { [key: string]: M };\n unapprovedMessagesCount: number;\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\ntype getCurrentChainId = () => Hex;\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport abstract class AbstractMessageManager<\n M extends AbstractMessage,\n P extends AbstractMessageParams,\n PM extends AbstractMessageParamsMetamask,\n> extends BaseController<BaseConfig, MessageManagerState<M>> {\n protected messages: M[];\n\n protected getCurrentChainId: getCurrentChainId | undefined;\n\n private readonly securityProviderRequest: SecurityProviderRequest | undefined;\n\n private readonly additionalFinishStatuses: string[];\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 const unapprovedMessages = this.getUnapprovedMessages();\n const unapprovedMessagesCount = this.getUnapprovedMessagesCount();\n this.update({ unapprovedMessages, unapprovedMessagesCount });\n if (emitUpdateBadge) {\n this.hub.emit('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(`${this.name}: Message not found for id: ${messageId}.`);\n }\n message.status = status;\n this.updateMessage(message);\n this.hub.emit(`${messageId}:${status}`, message);\n if (\n status === 'rejected' ||\n status === 'signed' ||\n status === 'errored' ||\n this.additionalFinishStatuses.includes(status)\n ) {\n this.hub.emit(`${messageId}:finished`, message);\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: M, 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: M): Promise<M> {\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 /**\n * EventEmitter instance used to listen to specific message events\n */\n hub = new EventEmitter();\n\n /**\n * Name of this controller used during composition\n */\n override name = 'AbstractMessageManager';\n\n /**\n * Creates an AbstractMessageManager instance.\n *\n * @param config - Initial options used to configure this controller.\n * @param state - Initial state to set on this controller.\n * @param securityProviderRequest - A function for verifying a message, whether it is malicious or not.\n * @param additionalFinishStatuses - Optional list of statuses that are accepted to emit a finished event.\n * @param getCurrentChainId - Optional function to get the current chainId.\n */\n constructor(\n config?: Partial<BaseConfig>,\n state?: Partial<MessageManagerState<M>>,\n securityProviderRequest?: SecurityProviderRequest,\n additionalFinishStatuses?: string[],\n getCurrentChainId?: getCurrentChainId,\n ) {\n super(config, state);\n this.defaultState = {\n unapprovedMessages: {},\n unapprovedMessagesCount: 0,\n };\n this.messages = [];\n this.securityProviderRequest = securityProviderRequest;\n this.additionalFinishStatuses = additionalFinishStatuses ?? [];\n this.getCurrentChainId = getCurrentChainId;\n this.initialize();\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: { [key: string]: M }, message: M) => {\n result[message.id] = message;\n return result;\n }, {}) as { [key: string]: M };\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: M) {\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: PM): Promise<P> {\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 message.rawSig = result;\n this.updateMessage(message, false);\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\n setMetadata(messageId: string, metadata: Json) {\n const message = this.getMessage(messageId);\n if (!message) {\n throw new Error(`${this.name}: Message not found for id: ${messageId}.`);\n }\n message.metadata = metadata;\n this.updateMessage(message, false);\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(messageParams: PM): Promise<P>;\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: PM,\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.hub.once(`${messageId}:finished`, (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(`MetaMask ${messageName} Signature: ${data.error}`),\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\nexport default AbstractMessageManager;\n"]}
|
|
1
|
+
{"version":3,"file":"AbstractMessageManager.js","sourceRoot":"","sources":["../src/AbstractMessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA,+DAA2D;AAE3D,mCAAsC;AAqGtC;;GAEG;AACH,MAAsB,sBAIpB,SAAQ,gCAAkD;IA6F1D;;;;;;;;OAQG;IACH,YACE,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AsB,CAAC;YACxE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACrC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,SAAS,WAAW,EAAE,CAAC,IAAqB,EAAE,EAAE;oBAC/D,QAAQ,IAAI,CAAC,MAAM,EAAE;wBACnB,KAAK,QAAQ;4BACX,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;wBACxC,KAAK,UAAU;4BACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,YAAY,WAAW,4CAA4C,CACpE,CACF,CAAC;wBACJ,KAAK,SAAS;4BACZ,OAAO,MAAM,CACX,IAAI,KAAK,CAAC,YAAY,WAAW,eAAe,IAAI,CAAC,KAAK,EAAE,CAAC,CAC9D,CAAC;wBACJ;4BACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,YAAY,WAAW,gCAAgC,IAAI,CAAC,SAAS,CACnE,aAAa,CACd,EAAE,CACJ,CACF,CAAC;qBACL;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AAvVD,wDAuVC;AAED,kBAAe,sBAAsB,CAAC","sourcesContent":["import type { BaseConfig, BaseState } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Hex, Json } from '@metamask/utils';\nimport { EventEmitter } from 'events';\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 */\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 OriginalRequest {\n origin?: string;\n securityAlertResponse?: Record<string, Json>;\n}\n\n/**\n * @type Message\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 */\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 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 MessageParams\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 deferSetAsSigned? - Whether to defer setting the message as signed immediately after the keyring is told to sign it\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 AbstractMessageParams {\n from: string;\n origin?: string;\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 */\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 AbstractMessageParamsMetamask extends 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 */\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 MessageManagerState<M extends AbstractMessage>\n extends BaseState {\n unapprovedMessages: { [key: string]: M };\n unapprovedMessagesCount: number;\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\ntype getCurrentChainId = () => Hex;\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport abstract class AbstractMessageManager<\n M extends AbstractMessage,\n P extends AbstractMessageParams,\n PM extends AbstractMessageParamsMetamask,\n> extends BaseController<BaseConfig, MessageManagerState<M>> {\n protected messages: M[];\n\n protected getCurrentChainId: getCurrentChainId | undefined;\n\n private readonly securityProviderRequest: SecurityProviderRequest | undefined;\n\n private readonly additionalFinishStatuses: string[];\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 const unapprovedMessages = this.getUnapprovedMessages();\n const unapprovedMessagesCount = this.getUnapprovedMessagesCount();\n this.update({ unapprovedMessages, unapprovedMessagesCount });\n if (emitUpdateBadge) {\n this.hub.emit('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(`${this.name}: Message not found for id: ${messageId}.`);\n }\n message.status = status;\n this.updateMessage(message);\n this.hub.emit(`${messageId}:${status}`, message);\n if (\n status === 'rejected' ||\n status === 'signed' ||\n status === 'errored' ||\n this.additionalFinishStatuses.includes(status)\n ) {\n this.hub.emit(`${messageId}:finished`, message);\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: M, 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: M): Promise<M> {\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 /**\n * EventEmitter instance used to listen to specific message events\n */\n hub = new EventEmitter();\n\n /**\n * Name of this controller used during composition\n */\n override name = 'AbstractMessageManager';\n\n /**\n * Creates an AbstractMessageManager instance.\n *\n * @param config - Initial options used to configure this controller.\n * @param state - Initial state to set on this controller.\n * @param securityProviderRequest - A function for verifying a message, whether it is malicious or not.\n * @param additionalFinishStatuses - Optional list of statuses that are accepted to emit a finished event.\n * @param getCurrentChainId - Optional function to get the current chainId.\n */\n constructor(\n config?: Partial<BaseConfig>,\n state?: Partial<MessageManagerState<M>>,\n securityProviderRequest?: SecurityProviderRequest,\n additionalFinishStatuses?: string[],\n getCurrentChainId?: getCurrentChainId,\n ) {\n super(config, state);\n this.defaultState = {\n unapprovedMessages: {},\n unapprovedMessagesCount: 0,\n };\n this.messages = [];\n this.securityProviderRequest = securityProviderRequest;\n this.additionalFinishStatuses = additionalFinishStatuses ?? [];\n this.getCurrentChainId = getCurrentChainId;\n this.initialize();\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: { [key: string]: M }, message: M) => {\n result[message.id] = message;\n return result;\n }, {}) as { [key: string]: M };\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: M) {\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: PM): Promise<P> {\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 message.rawSig = result;\n this.updateMessage(message, false);\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\n setMetadata(messageId: string, metadata: Json) {\n const message = this.getMessage(messageId);\n if (!message) {\n throw new Error(`${this.name}: Message not found for id: ${messageId}.`);\n }\n message.metadata = metadata;\n this.updateMessage(message, false);\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(messageParams: PM): Promise<P>;\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: PM,\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.hub.once(`${messageId}:finished`, (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(`MetaMask ${messageName} Signature: ${data.error}`),\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\nexport default AbstractMessageManager;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecryptMessageManager.d.ts","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"DecryptMessageManager.d.ts","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE;;;;;;;;;GASG;AAIH,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,aAAa,EAAE,oBAAoB,CAAC;CACrC;AAED;;;;;GAKG;AAIH,MAAM,WAAW,oBAAqB,SAAQ,qBAAqB;IACjE,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;GASG;AAIH,MAAM,WAAW,4BACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,sBAAsB,CAC/D,cAAc,EACd,oBAAoB,EACpB,4BAA4B,CAC7B;IACC;;OAEG;IACM,IAAI,SAA2B;IAExC;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAkClB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,eAAe;IAsBvB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,4BAA4B,GAC1C,OAAO,CAAC,oBAAoB,CAAC;CAIjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecryptMessageManager.js","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAoC;AAQpC,qEAAkE;AAClE,mCAA6E;
|
|
1
|
+
{"version":3,"file":"DecryptMessageManager.js","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAoC;AAQpC,qEAAkE;AAClE,mCAA6E;AAkD7E;;GAEG;AACH,MAAa,qBAAsB,SAAQ,+CAI1C;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,uBAAuB,CAAC;IA8F1C,CAAC;IA5FC;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAmC,EACnC,GAAqB;;YAErB,IAAA,oCAA4B,EAAC,aAAa,CAAC,CAAC;YAC5C,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;YAEtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACrC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,SAAS,WAAW,EAAE,CAAC,IAAoB,EAAE,EAAE;oBAC9D,QAAQ,IAAI,CAAC,MAAM,EAAE;wBACnB,KAAK,WAAW;4BACd,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;wBACxC,KAAK,UAAU;4BACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,0DAA0D,CAC3D,CACF,CAAC;wBACJ,KAAK,SAAS;4BACZ,OAAO,MAAM,CACX,IAAI,KAAK,CACP,4DAA4D,CAC7D,CACF,CAAC;wBACJ;4BACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,6CAA6C,IAAI,CAAC,SAAS,CACzD,aAAa,CACd,EAAE,CACJ,CACF,CAAC;qBACL;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;IAED;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAmC,EACnC,GAAqB;;YAErB,IAAI,GAAG,EAAE;gBACP,aAAa,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;aACnC;YACD,aAAa,CAAC,IAAI,GAAG,IAAA,4BAAoB,EAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC9D,MAAM,SAAS,GAAG,IAAA,SAAM,GAAE,CAAC;YAC3B,MAAM,WAAW,GAAmB;gBAClC,EAAE,EAAE,SAAS;gBACb,aAAa;gBACb,MAAM,EAAE,YAAY;gBACpB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;gBAChB,IAAI,EAAE,aAAa;aACpB,CAAC;YACF,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,kCAC5B,aAAa,GACb,EAAE,UAAU,EAAE,SAAS,EAAE,EAC5B,CAAC;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAA2C;QAE3C,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;CACF;AAtGD,sDAsGC","sourcesContent":["import { v1 as random } from 'uuid';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { normalizeMessageData, validateDecryptedMessageData } from './utils';\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 */\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 DecryptMessage extends 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 */\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 DecryptMessageParams extends 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 DecryptMessage,\n DecryptMessageParams,\n DecryptMessageParamsMetamask\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'DecryptMessageManager';\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.hub.once(`${messageId}:finished`, (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 * 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 if (req) {\n messageParams.origin = req.origin;\n }\n messageParams.data = normalizeMessageData(messageParams.data);\n const messageId = random();\n const messageData: DecryptMessage = {\n id: messageId,\n messageParams,\n status: 'unapproved',\n time: Date.now(),\n type: 'eth_decrypt',\n };\n await this.addMessage(messageData);\n this.hub.emit(`unapprovedMessage`, {\n ...messageParams,\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptionPublicKeyManager.d.ts","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"EncryptionPublicKeyManager.d.ts","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE;;;;;;;;;;GAUG;AAIH,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,aAAa,EAAE,yBAAyB,CAAC;CAC1C;AAED;;;;;;GAMG;AACH,oBAAY,yBAAyB,GAAG,qBAAqB,CAAC;AAE9D;;;;;;;;;GASG;AAIH,MAAM,WAAW,iCACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,sBAAsB,CACpE,mBAAmB,EACnB,yBAAyB,EACzB,iCAAiC,CAClC;IACC;;OAEG;IACM,IAAI,SAAgC;IAE7C;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA4BlB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAoBlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,iCAAiC,GAC/C,OAAO,CAAC,yBAAyB,CAAC;CAItC;AAED,eAAe,0BAA0B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptionPublicKeyManager.js","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAoC;AAQpC,qEAAkE;AAClE,mCAAiE;
|
|
1
|
+
{"version":3,"file":"EncryptionPublicKeyManager.js","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAoC;AAQpC,qEAAkE;AAClE,mCAAiE;AA+CjE;;GAEG;AACH,MAAa,0BAA2B,SAAQ,+CAI/C;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,4BAA4B,CAAC;IAuF/C,CAAC;IArFC;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAwC,EACxC,GAAqB;;YAErB,IAAA,8CAAsC,EAAC,aAAa,CAAC,CAAC;YACtD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;YAEtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACrC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,SAAS,WAAW,EAAE,CAAC,IAAyB,EAAE,EAAE;oBACnE,QAAQ,IAAI,CAAC,MAAM,EAAE;wBACnB,KAAK,UAAU;4BACb,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;wBACxC,KAAK,UAAU;4BACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,wEAAwE,CACzE,CACF,CAAC;wBACJ;4BACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,kDAAkD,IAAI,CAAC,SAAS,CAC9D,aAAa,CACd,EAAE,CACJ,CACF,CAAC;qBACL;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;IAED;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAwC,EACxC,GAAqB;;YAErB,IAAI,GAAG,EAAE;gBACP,aAAa,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;aACnC;YACD,MAAM,SAAS,GAAG,IAAA,SAAM,GAAE,CAAC;YAC3B,MAAM,WAAW,GAAwB;gBACvC,EAAE,EAAE,SAAS;gBACb,aAAa;gBACb,MAAM,EAAE,YAAY;gBACpB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;gBAChB,IAAI,EAAE,4BAA4B;aACnC,CAAC;YACF,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,kCAC5B,aAAa,GACb,EAAE,UAAU,EAAE,SAAS,EAAE,EAC5B,CAAC;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;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;AA/FD,gEA+FC;AAED,kBAAe,0BAA0B,CAAC","sourcesContent":["import { v1 as random } from 'uuid';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { validateEncryptionPublicKeyMessageData } from './utils';\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 */\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 EncryptionPublicKey extends 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 */\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 EncryptionPublicKeyParamsMetamask\n extends 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 EncryptionPublicKey,\n EncryptionPublicKeyParams,\n EncryptionPublicKeyParamsMetamask\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'EncryptionPublicKeyManager';\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.hub.once(`${messageId}:finished`, (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 * 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 if (req) {\n messageParams.origin = req.origin;\n }\n const messageId = random();\n const messageData: EncryptionPublicKey = {\n id: messageId,\n messageParams,\n status: 'unapproved',\n time: Date.now(),\n type: 'eth_getEncryptionPublicKey',\n };\n await this.addMessage(messageData);\n this.hub.emit(`unapprovedMessage`, {\n ...messageParams,\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageManager.d.ts","sourceRoot":"","sources":["../src/MessageManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"MessageManager.d.ts","sourceRoot":"","sources":["../src/MessageManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE;;;;;;;;;;GAUG;AAIH,MAAM,WAAW,OAAQ,SAAQ,eAAe;IAC9C,aAAa,EAAE,aAAa,CAAC;CAC9B;AAED;;;;;;;GAOG;AAIH,MAAM,WAAW,aAAc,SAAQ,qBAAqB;IAC1D,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;GASG;AAIH,MAAM,WAAW,qBAAsB,SAAQ,6BAA6B;IAC1E,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,sBAAsB,CACxD,OAAO,EACP,aAAa,EACb,qBAAqB,CACtB;IACC;;OAEG;IACM,IAAI,SAAoB;IAEjC;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,aAAa,EAC5B,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAuBlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,qBAAqB,GACnC,OAAO,CAAC,aAAa,CAAC;CAM1B;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageManager.js","sourceRoot":"","sources":["../src/MessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAoC;AAQpC,qEAAkE;AAClE,mCAAwE;
|
|
1
|
+
{"version":3,"file":"MessageManager.js","sourceRoot":"","sources":["../src/MessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAoC;A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bstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { normalizeMessageData, validateSignMessageData } from './utils';\n\n/**\n * @type Message\n *\n * Represents and contains data about a 'eth_sign' type signature request.\n * These are created when a signature for an eth_sign 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_sign method once the signature request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'Message' which always has a 'eth_sign' type\n * @property rawSig - Raw data of the signature request\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 Message extends AbstractMessage {\n messageParams: MessageParams;\n}\n\n/**\n * @type PersonalMessageParams\n *\n * Represents the parameters to pass to the eth_sign method once the signature request is approved.\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 MessageParams extends AbstractMessageParams {\n data: string;\n}\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_sign 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 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 MessageParamsMetamask extends AbstractMessageParamsMetamask {\n data: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport class MessageManager extends AbstractMessageManager<\n Message,\n MessageParams,\n MessageParamsMetamask\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'MessageManager';\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_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: MessageParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateSignMessageData(messageParams);\n if (req) {\n messageParams.origin = req.origin;\n }\n messageParams.data = normalizeMessageData(messageParams.data);\n const messageId = random();\n const messageData: Message = {\n id: messageId,\n messageParams,\n securityAlertResponse: req?.securityAlertResponse,\n status: 'unapproved',\n time: Date.now(),\n type: 'eth_sign',\n };\n await this.addMessage(messageData);\n this.hub.emit(`unapprovedMessage`, {\n ...messageParams,\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: MessageParamsMetamask,\n ): Promise<MessageParams> {\n // Using delete operation will throw an error on frozen messageParams\n const { metamaskId: _metamaskId, ...messageParamsWithoutId } =\n messageParams;\n return Promise.resolve(messageParamsWithoutId);\n }\n}\n\nexport default MessageManager;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersonalMessageManager.d.ts","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAI9D,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"PersonalMessageManager.d.ts","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAI9D,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE;;;;;;;;;;GAUG;AAIH,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,aAAa,EAAE,qBAAqB,CAAC;CACtC;AAED;;;;;;;GAOG;AAIH,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;;;;;;;GASG;AAIH,MAAM,WAAW,6BACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB,CAChE,eAAe,EACf,qBAAqB,EACrB,6BAA6B,CAC9B;IACC;;OAEG;IACM,IAAI,SAA4B;IAEzC;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,qBAAqB,EACpC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA2BlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,6BAA6B,GAC3C,OAAO,CAAC,qBAAqB,CAAC;CAMlC;AAED,eAAe,sBAAsB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersonalMessageManager.js","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA,iEAAwD;AACxD,+BAAoC;AAQpC,qEAAkE;AAClE,mCAAwE;
|
|
1
|
+
{"version":3,"file":"PersonalMessageManager.js","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA,iEAAwD;AACxD,+BAAoC;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OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACjD,CAAC;CACF;AAjED,wDAiEC;AAED,kBAAe,sBAAsB,CAAC","sourcesContent":["import type { SIWEMessage } from '@metamask/controller-utils';\nimport { detectSIWE } from '@metamask/controller-utils';\nimport { v1 as random } from 'uuid';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { normalizeMessageData, validateSignMessageData } from './utils';\n\n/**\n * @type Message\n *\n * Represents and contains data about a 'personal_sign' type signature request.\n * These are created when a signature for a personal_sign call is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the personal_sign method once the signature request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'Message' which always has a 'personal_sign' type\n * @property rawSig - Raw data of the signature request\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 PersonalMessage extends AbstractMessage {\n messageParams: PersonalMessageParams;\n}\n\n/**\n * @type PersonalMessageParams\n *\n * Represents the parameters to pass to the personal_sign method once the signature request is approved.\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 PersonalMessageParams extends AbstractMessageParams {\n data: string;\n siwe?: SIWEMessage;\n}\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the personal_sign 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 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 PersonalMessageParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport class PersonalMessageManager extends AbstractMessageManager<\n PersonalMessage,\n PersonalMessageParams,\n PersonalMessageParamsMetamask\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'PersonalMessageManager';\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: PersonalMessageParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateSignMessageData(messageParams);\n if (req) {\n messageParams.origin = req.origin;\n }\n messageParams.data = normalizeMessageData(messageParams.data);\n\n const ethereumSignInData = detectSIWE(messageParams);\n const finalMsgParams = { ...messageParams, siwe: ethereumSignInData };\n\n const messageId = random();\n const messageData: PersonalMessage = {\n id: messageId,\n messageParams: finalMsgParams,\n securityAlertResponse: req?.securityAlertResponse,\n status: 'unapproved',\n time: Date.now(),\n type: 'personal_sign',\n };\n await this.addMessage(messageData);\n this.hub.emit(`unapprovedMessage`, {\n ...finalMsgParams,\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: PersonalMessageParamsMetamask,\n ): Promise<PersonalMessageParams> {\n // Using delete operation will throw an error on frozen messageParams\n const { metamaskId: _metamaskId, ...messageParamsWithoutId } =\n messageParams;\n return Promise.resolve(messageParamsWithoutId);\n }\n}\n\nexport default PersonalMessageManager;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedMessageManager.d.ts","sourceRoot":"","sources":["../src/TypedMessageManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAMlE;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"TypedMessageManager.d.ts","sourceRoot":"","sources":["../src/TypedMessageManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAMlE;;;;;;;;;;;;GAYG;AAIH,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,kBAAkB,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,oBAAY,wBAAwB,GAAG;IACrC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;;;;;GAQG;AAIH,MAAM,WAAW,kBAAmB,SAAQ,qBAAqB;IAC/D,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,MAAM,GAAG,wBAAwB,CAAC;CACrE;AAED;;;;;;;;;;;;GAYG;AAIH,MAAM,WAAW,0BACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,sBAAsB,CAC7D,YAAY,EACZ,kBAAkB,EAClB,0BAA0B,CAC3B;IACC;;OAEG;IACM,IAAI,SAAyB;IAEtC;;;;;;;;;;OAUG;IACG,oBAAoB,CACxB,aAAa,EAAE,kBAAkB,EACjC,GAAG,CAAC,EAAE,eAAe,EACrB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC;IAuClB;;;;;OAKG;IACH,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAWxD;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,0BAA0B,GACxC,OAAO,CAAC,kBAAkB,CAAC;CAS/B;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedMessageManager.js","sourceRoot":"","sources":["../src/TypedMessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAoC;AAQpC,qEAAkE;AAClE,mCAGiB;
|
|
1
|
+
{"version":3,"file":"TypedMessageManager.js","sourceRoot":"","sources":["../src/TypedMessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAoC;AAQpC,qEAAkE;AAClE,mCAGiB;AA0EjB;;GAEG;AACH,MAAa,mBAAoB,SAAQ,+CAIxC;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,qBAAqB,CAAC;IA2FxC,CAAC;IAzFC;;;;;;;;;;OAUG;IACG,oBAAoB,CACxB,aAAiC,EACjC,GAAqB,EACrB,OAAgB;;;YAEhB,IAAI,OAAO,KAAK,IAAI,EAAE;gBACpB,IAAA,sCAA8B,EAAC,aAAa,CAAC,CAAC;aAC/C;YAED,IAAI,OAAO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Aa,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAyC;QAEzC,qEAAqE;QACrE,MAAM,EACJ,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,QAAQ,KAEf,aAAa,EADZ,sBAAsB,UACvB,aAAa,EAJX,yBAIL,CAAgB,CAAC;QAClB,OAAO,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACjD,CAAC;CACF;AAnGD,kDAmGC;AAED,kBAAe,mBAAmB,CAAC","sourcesContent":["import { v1 as random } from 'uuid';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport {\n validateTypedSignMessageDataV1,\n validateTypedSignMessageDataV3V4,\n} from './utils';\n\n/**\n * @type TypedMessage\n *\n * Represents and contains data about an 'eth_signTypedData' type signature request.\n * These are created when a signature for an eth_signTypedData call is requested.\n * @property id - An id to track and identify the message object\n * @property error - Error corresponding to eth_signTypedData error in failure case\n * @property messageParams - The parameters to pass to the eth_signTypedData method once\n * the signature request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'TypedMessage' which always has a 'eth_signTypedData' type\n * @property rawSig - Raw data of the signature request\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 TypedMessage extends AbstractMessage {\n error?: string;\n messageParams: TypedMessageParams;\n time: number;\n status: string;\n type: string;\n rawSig?: string;\n}\n\nexport type SignTypedDataMessageV3V4 = {\n types: Record<string, unknown>;\n domain: Record<string, unknown>;\n primaryType: string;\n message: unknown;\n};\n\n/**\n * @type TypedMessageParams\n *\n * Represents the parameters to pass to the eth_signTypedData method once the signature request is approved.\n * @property data - A hex string conversion of the raw buffer or an object containing data of the signature\n * request depending on version\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 TypedMessageParams extends AbstractMessageParams {\n data: Record<string, unknown>[] | string | SignTypedDataMessageV3V4;\n}\n\n/**\n * @type TypedMessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_signTypedData 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 data - A hex string conversion of the raw buffer or an object containing data of the signature\n * request depending on version\n * @property error? - Added for message errored\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n * @property version - Compatibility version EIP712\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 TypedMessageParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: TypedMessageParams['data'];\n metamaskId?: string;\n error?: string;\n version?: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - TypedMessages.\n */\nexport class TypedMessageManager extends AbstractMessageManager<\n TypedMessage,\n TypedMessageParams,\n TypedMessageParamsMetamask\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'TypedMessageManager';\n\n /**\n * Creates a new TypedMessage with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new TypedMessage to this.messages, and to save the\n * unapproved TypedMessages.\n *\n * @param messageParams - The params for the 'eth_signTypedData' call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @param version - Compatibility version EIP712.\n * @returns The id of the newly created TypedMessage.\n */\n async addUnapprovedMessage(\n messageParams: TypedMessageParams,\n req?: OriginalRequest,\n version?: string,\n ): Promise<string> {\n if (version === 'V1') {\n validateTypedSignMessageDataV1(messageParams);\n }\n\n if (version === 'V3' || version === 'V4') {\n const currentChainId = this.getCurrentChainId?.();\n validateTypedSignMessageDataV3V4(messageParams, currentChainId);\n }\n\n if (\n typeof messageParams.data !== 'string' &&\n (version === 'V3' || version === 'V4')\n ) {\n messageParams.data = JSON.stringify(messageParams.data);\n }\n\n const messageId = random();\n const messageParamsMetamask = {\n ...messageParams,\n metamaskId: messageId,\n version,\n };\n if (req) {\n messageParams.origin = req.origin;\n }\n const messageData: TypedMessage = {\n id: messageId,\n messageParams,\n securityAlertResponse: req?.securityAlertResponse,\n status: 'unapproved',\n time: Date.now(),\n type: 'eth_signTypedData',\n };\n await this.addMessage(messageData);\n this.hub.emit(`unapprovedMessage`, messageParamsMetamask);\n return messageId;\n }\n\n /**\n * Sets a TypedMessage status to 'errored' via a call to this.setMessageStatus.\n *\n * @param messageId - The id of the TypedMessage to error.\n * @param error - The error to be included in TypedMessage.\n */\n setMessageStatusErrored(messageId: string, error: string) {\n const message = this.getMessage(messageId);\n /* istanbul ignore if */\n if (!message) {\n return;\n }\n message.error = error;\n this.updateMessage(message);\n this.setMessageStatus(messageId, 'errored');\n }\n\n /**\n * Removes the metamaskId and version properties 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 and version properties removed.\n */\n prepMessageForSigning(\n messageParams: TypedMessageParamsMetamask,\n ): Promise<TypedMessageParams> {\n // Using delete operation will throw an error on frozen messageParams\n const {\n metamaskId: _metamaskId,\n version: _version,\n ...messageParamsWithoutId\n } = messageParams;\n return Promise.resolve(messageParamsWithoutId);\n }\n}\n\nexport default TypedMessageManager;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/message-manager",
|
|
3
|
-
"version": "7.3.5-preview.
|
|
3
|
+
"version": "7.3.5-preview.eb58a59",
|
|
4
4
|
"description": "Stores and manages interactions with signing requests",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -24,22 +24,23 @@
|
|
|
24
24
|
"build:docs": "typedoc",
|
|
25
25
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/message-manager",
|
|
26
26
|
"publish:preview": "yarn npm publish --tag preview",
|
|
27
|
-
"test": "jest",
|
|
27
|
+
"test": "jest --reporters=jest-silent-reporter",
|
|
28
28
|
"test:clean": "jest --clearCache",
|
|
29
|
+
"test:verbose": "jest --verbose",
|
|
29
30
|
"test:watch": "jest --watch"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"@metamask/base-controller": "^3.2.3",
|
|
33
34
|
"@metamask/controller-utils": "^5.0.2",
|
|
34
35
|
"@metamask/eth-sig-util": "^7.0.0",
|
|
35
|
-
"@metamask/utils": "^8.
|
|
36
|
+
"@metamask/utils": "^8.2.0",
|
|
36
37
|
"@types/uuid": "^8.3.0",
|
|
37
38
|
"ethereumjs-util": "^7.0.10",
|
|
38
39
|
"jsonschema": "^1.2.4",
|
|
39
40
|
"uuid": "^8.3.2"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
|
-
"@metamask/auto-changelog": "^3.4.
|
|
43
|
+
"@metamask/auto-changelog": "^3.4.3",
|
|
43
44
|
"@types/jest": "^27.4.1",
|
|
44
45
|
"deepmerge": "^4.2.2",
|
|
45
46
|
"jest": "^27.5.1",
|