From 62af1696fc8ec34391c5692f6fecd1d94a359f8a Mon Sep 17 00:00:00 2001 From: Bernardo Garces Chapero Date: Wed, 29 Mar 2023 13:12:28 +0100 Subject: [PATCH] patch to test ci --- ...message-manager-npm-2.0.0-f23d924f4f.patch | 397 ++++++++++++++++++ package.json | 4 +- yarn.lock | 96 ++++- 3 files changed, 479 insertions(+), 18 deletions(-) create mode 100644 .yarn/patches/@metamask-message-manager-npm-2.0.0-f23d924f4f.patch diff --git a/.yarn/patches/@metamask-message-manager-npm-2.0.0-f23d924f4f.patch b/.yarn/patches/@metamask-message-manager-npm-2.0.0-f23d924f4f.patch new file mode 100644 index 000000000000..c61ce24fd65e --- /dev/null +++ b/.yarn/patches/@metamask-message-manager-npm-2.0.0-f23d924f4f.patch @@ -0,0 +1,397 @@ +diff --git a/dist/AbstractMessageManager.d.ts b/dist/AbstractMessageManager.d.ts +index 5c880250d56006d0889ca008f734854d47504f71..2e7b34fddf5719f4cf493038d73b1db039cdab5f 100644 +--- a/dist/AbstractMessageManager.d.ts ++++ b/dist/AbstractMessageManager.d.ts +@@ -30,7 +30,7 @@ export interface AbstractMessage { + * @type MessageParams + * + * Represents the parameters to pass to the signing method once the signature request is approved. +- * @property from - Address to sign this message from ++ * @property from - Address from which the message is processed + * @property origin? - Added for request origin identification + */ + export interface AbstractMessageParams { +@@ -43,7 +43,7 @@ export interface AbstractMessageParams { + * Represents the parameters to pass to the signing method once the signature request is approved + * plus data added by MetaMask. + * @property metamaskId - Added for tracking and identification within MetaMask +- * @property from - Address to sign this message from ++ * @property from - Address from which the message is processed + * @property origin? - Added for request origin identification + */ + export interface AbstractMessageParamsMetamask extends AbstractMessageParams { +@@ -67,6 +67,7 @@ export interface MessageManagerState extends BaseStat + */ + export declare abstract class AbstractMessageManager extends BaseController> { + protected messages: M[]; ++ private additionalFinishStatuses; + /** + * Saves the unapproved messages, and their count to state. + * +@@ -99,8 +100,9 @@ export declare abstract class AbstractMessageManager, state?: Partial>); ++ constructor(config?: Partial, state?: Partial>, additionalFinishStatuses?: string[]); + /** + * A getter for the number of 'unapproved' Messages in this.messages. + * +@@ -154,6 +156,15 @@ export declare abstract class AbstractMessageManager\n extends BaseState {\n unapprovedMessages: { [key: string]: M };\n unapprovedMessagesCount: number;\n}\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> {\n protected messages: M[];\n\n /**\n * Saves the unapproved messages, and their count to state.\n *\n */\n protected saveMessageList() {\n const unapprovedMessages = this.getUnapprovedMessages();\n const unapprovedMessagesCount = this.getUnapprovedMessagesCount();\n this.update({ unapprovedMessages, unapprovedMessagesCount });\n this.hub.emit('updateBadge');\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 (status === 'rejected' || status === 'signed' || status === 'errored') {\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 */\n protected updateMessage(message: M) {\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();\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 */\n constructor(\n config?: Partial,\n state?: Partial>,\n ) {\n super(config, state);\n this.defaultState = {\n unapprovedMessages: {},\n unapprovedMessagesCount: 0,\n };\n this.messages = [];\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 addMessage(message: M) {\n this.messages.push(message);\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 * 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

{\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 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 const message = this.getMessage(messageId);\n /* istanbul ignore if */\n if (!message) {\n return;\n }\n message.rawSig = rawSig;\n this.updateMessage(message);\n this.setMessageStatus(messageId, 'signed');\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

;\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\nexport default AbstractMessageManager;\n"]} +\ No newline at end of file ++{"version":3,"file":"AbstractMessageManager.js","sourceRoot":"","sources":["../src/AbstractMessageManager.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AACtC,+DAImC;AAmEnC;;GAEG;AACH,MAAsB,sBAIpB,SAAQ,gCAAkD;IAiE1D;;;;;;OAMG;IACH,YACE,MAA4B,EAC5B,KAAuC,EACvC,wBAAmC;QAEnC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAtBvB;;WAEG;QACH,QAAG,GAAG,IAAI,qBAAY,EAAE,CAAC;QAEzB;;WAEG;QACM,SAAI,GAAG,wBAAwB,CAAC;QAevC,IAAI,CAAC,YAAY,GAAG;YAClB,kBAAkB,EAAE,EAAE;YACtB,uBAAuB,EAAE,CAAC;SAC3B,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,aAAxB,wBAAwB,cAAxB,wBAAwB,GAAI,EAAE,CAAC;QAC/D,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAhFD;;;OAGG;IACO,eAAe;QACvB,MAAM,kBAAkB,GAAG,IAAI,CAAC,qBAAqB,EAAE,C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E,QAAQ,CAAC,CAAC;IAC9D,CAAC;IAED;;;;;;;OAOG;IACH,yBAAyB,CAAC,SAAiB,EAAE,MAAc,EAAE,MAAc;QACzE,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAC3C,wBAAwB;QACxB,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO;SACR;QACD,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;QACxB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;IAWD;;;;OAIG;IACH,aAAa,CAAC,SAAiB;QAC7B,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAC/C,CAAC;CACF;AAhND,wDAgNC;AAED,kBAAe,sBAAsB,CAAC","sourcesContent":["import { EventEmitter } from 'events';\nimport {\n BaseController,\n BaseConfig,\n BaseState,\n} from '@metamask/base-controller';\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}\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 */\nexport interface AbstractMessage {\n id: string;\n time: number;\n status: string;\n type: string;\n rawSig?: 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 */\nexport interface AbstractMessageParams {\n from: string;\n origin?: string;\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\n extends BaseState {\n unapprovedMessages: { [key: string]: M };\n unapprovedMessagesCount: number;\n}\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> {\n protected messages: M[];\n\n private additionalFinishStatuses: string[];\n\n /**\n * Saves the unapproved messages, and their count to state.\n *\n */\n protected saveMessageList() {\n const unapprovedMessages = this.getUnapprovedMessages();\n const unapprovedMessagesCount = this.getUnapprovedMessagesCount();\n this.update({ unapprovedMessages, unapprovedMessagesCount });\n this.hub.emit('updateBadge');\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 */\n protected updateMessage(message: M) {\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();\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 additionalFinishStatuses -\n */\n constructor(\n config?: Partial,\n state?: Partial>,\n additionalFinishStatuses?: string[],\n ) {\n super(config, state);\n this.defaultState = {\n unapprovedMessages: {},\n unapprovedMessagesCount: 0,\n };\n this.messages = [];\n this.additionalFinishStatuses = additionalFinishStatuses ?? [];\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 addMessage(message: M) {\n this.messages.push(message);\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 * 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

{\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 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 to a new status via a call to this.setMsgStatus and\n * updates the rawSig field in this.messages.\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 const message = this.getMessage(messageId);\n /* istanbul ignore if */\n if (!message) {\n return;\n }\n message.rawSig = rawSig;\n this.updateMessage(message);\n this.setMessageStatus(messageId, status);\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

;\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\nexport default AbstractMessageManager;\n"]} +\ No newline at end of file +diff --git a/dist/EncryptionPublicKeyManager.d.ts b/dist/EncryptionPublicKeyManager.d.ts +new file mode 100644 +index 0000000000000000000000000000000000000000..cb9525735c42d66755785cfa6523d4ad705e0c69 +--- /dev/null ++++ b/dist/EncryptionPublicKeyManager.d.ts +@@ -0,0 +1,74 @@ ++import { AbstractMessageManager, AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest } from './AbstractMessageManager'; ++/** ++ * @type EncryptionPublicKey ++ * ++ * Represents and contains data about a 'eth_getEncryptionPublicKey' type request. ++ * These are created when an encryption public key is requested. ++ * @property id - An id to track and identify the message object ++ * @property messageParams - The parameters to pass to the eth_getEncryptionPublicKey method once the request is approved ++ * @property type - The json-prc method for which an encryption public key request has been made. ++ * A 'Message' which always has a 'eth_getEncryptionPublicKey' type ++ * @property rawSig - Encryption public key ++ */ ++export interface EncryptionPublicKey extends AbstractMessage { ++ messageParams: EncryptionPublicKeyParams; ++} ++/** ++ * @type EncryptionPublicKeyParams ++ * ++ * Represents the parameters to pass to the method once the request is approved. ++ * @property from - Address from which to extract the encryption public key ++ * @property origin? - Added for request origin identification ++ */ ++export declare type EncryptionPublicKeyParams = AbstractMessageParams; ++/** ++ * @type MessageParamsMetamask ++ * ++ * Represents the parameters to pass to the eth_getEncryptionPublicKey method once the request is approved ++ * plus data added by MetaMask. ++ * @property metamaskId - Added for tracking and identification within MetaMask ++ * @property data - Encryption public key ++ * @property from - Address from which to extract the encryption public key ++ * @property origin? - Added for request origin identification ++ */ ++export interface EncryptionPublicKeyParamsMetamask extends AbstractMessageParamsMetamask { ++ data: string; ++} ++/** ++ * Controller in charge of managing - storing, adding, removing, updating - Messages. ++ */ ++export declare class EncryptionPublicKeyManager extends AbstractMessageManager { ++ /** ++ * Name of this controller used during composition ++ */ ++ name: string; ++ /** ++ * Creates a new Message with an 'unapproved' status using the passed messageParams. ++ * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages. ++ * ++ * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message is approved. ++ * @param req - The original request object possibly containing the origin. ++ * @returns Promise resolving to the raw data of the request. ++ */ ++ addUnapprovedMessageAsync(messageParams: EncryptionPublicKeyParams, req?: OriginalRequest): Promise; ++ /** ++ * Creates a new Message with an 'unapproved' status using the passed messageParams. ++ * this.addMessage is called to add the new Message to this.messages, and to save the ++ * unapproved Messages. ++ * ++ * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message ++ * is approved. ++ * @param req - The original request object possibly containing the origin. ++ * @returns The id of the newly created message. ++ */ ++ addUnapprovedMessage(messageParams: EncryptionPublicKeyParams, req?: OriginalRequest): string; ++ /** ++ * Removes the metamaskId property from passed messageParams and returns a promise which ++ * resolves the updated messageParams. ++ * ++ * @param messageParams - The messageParams to modify. ++ * @returns Promise resolving to the messageParams with the metamaskId property removed. ++ */ ++ prepMessageForSigning(messageParams: EncryptionPublicKeyParamsMetamask): Promise; ++} ++export default EncryptionPublicKeyManager; +diff --git a/dist/EncryptionPublicKeyManager.js b/dist/EncryptionPublicKeyManager.js +new file mode 100644 +index 0000000000000000000000000000000000000000..85d736a866500ca2fe0a505de30c16d34361c9c2 +--- /dev/null ++++ b/dist/EncryptionPublicKeyManager.js +@@ -0,0 +1,82 @@ ++"use strict"; ++Object.defineProperty(exports, "__esModule", { value: true }); ++exports.EncryptionPublicKeyManager = void 0; ++const uuid_1 = require("uuid"); ++const AbstractMessageManager_1 = require("./AbstractMessageManager"); ++const utils_1 = require("./utils"); ++/** ++ * Controller in charge of managing - storing, adding, removing, updating - Messages. ++ */ ++class EncryptionPublicKeyManager extends AbstractMessageManager_1.AbstractMessageManager { ++ constructor() { ++ super(...arguments); ++ /** ++ * Name of this controller used during composition ++ */ ++ this.name = 'EncryptionPublicKeyManager'; ++ } ++ /** ++ * Creates a new Message with an 'unapproved' status using the passed messageParams. ++ * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages. ++ * ++ * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message is approved. ++ * @param req - The original request object possibly containing the origin. ++ * @returns Promise resolving to the raw data of the request. ++ */ ++ addUnapprovedMessageAsync(messageParams, req) { ++ return new Promise((resolve, reject) => { ++ (0, utils_1.validateEncryptionPublicKeyMessageData)(messageParams); ++ const messageId = this.addUnapprovedMessage(messageParams, req); ++ this.hub.once(`${messageId}:finished`, (data) => { ++ switch (data.status) { ++ case 'received': ++ return resolve(data.rawSig); ++ case 'rejected': ++ return reject(new Error('MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.')); ++ default: ++ return reject(new Error(`MetaMask EncryptionPublicKey: Unknown problem: ${JSON.stringify(messageParams)}`)); ++ } ++ }); ++ }); ++ } ++ /** ++ * Creates a new Message with an 'unapproved' status using the passed messageParams. ++ * this.addMessage is called to add the new Message to this.messages, and to save the ++ * unapproved Messages. ++ * ++ * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message ++ * is approved. ++ * @param req - The original request object possibly containing the origin. ++ * @returns The id of the newly created message. ++ */ ++ addUnapprovedMessage(messageParams, req) { ++ if (req) { ++ messageParams.origin = req.origin; ++ } ++ const messageId = (0, uuid_1.v1)(); ++ const messageData = { ++ id: messageId, ++ messageParams, ++ status: 'unapproved', ++ time: Date.now(), ++ type: 'eth_getEncryptionPublicKey', ++ }; ++ this.addMessage(messageData); ++ this.hub.emit(`unapprovedMessage`, Object.assign(Object.assign({}, messageParams), { metamaskId: messageId })); ++ return messageId; ++ } ++ /** ++ * Removes the metamaskId property from passed messageParams and returns a promise which ++ * resolves the updated messageParams. ++ * ++ * @param messageParams - The messageParams to modify. ++ * @returns Promise resolving to the messageParams with the metamaskId property removed. ++ */ ++ prepMessageForSigning(messageParams) { ++ delete messageParams.metamaskId; ++ return Promise.resolve({ from: messageParams.data }); ++ } ++} ++exports.EncryptionPublicKeyManager = EncryptionPublicKeyManager; ++exports.default = EncryptionPublicKeyManager; ++//# sourceMappingURL=EncryptionPublicKeyManager.js.map +\ No newline at end of file +diff --git a/dist/EncryptionPublicKeyManager.js.map b/dist/EncryptionPublicKeyManager.js.map +new file mode 100644 +index 0000000000000000000000000000000000000000..dfac0b7b05fac58d9904730117c8546c5767c780 +--- /dev/null ++++ b/dist/EncryptionPublicKeyManager.js.map +@@ -0,0 +1 @@ ++{"version":3,"file":"EncryptionPublicKeyManager.js","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,qEAMkC;AAClC,mCAAiE;AAyCjE;;GAEG;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AAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,kCAC5B,aAAa,GACb,EAAE,UAAU,EAAE,SAAS,EAAE,EAC5B,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;AA9FD,gEA8FC;AAED,kBAAe,0BAA0B,CAAC","sourcesContent":["import { v1 as random } from 'uuid';\nimport {\n AbstractMessageManager,\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} 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 */\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 */\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 addUnapprovedMessageAsync(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise {\n return new Promise((resolve, reject) => {\n validateEncryptionPublicKeyMessageData(messageParams);\n const messageId = this.addUnapprovedMessage(messageParams, req);\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 addUnapprovedMessage(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ) {\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 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 {\n delete messageParams.metamaskId;\n return Promise.resolve({ from: messageParams.data });\n }\n}\n\nexport default EncryptionPublicKeyManager;\n"]} +\ No newline at end of file +diff --git a/dist/index.d.ts b/dist/index.d.ts +index 239569e41c9b495d3c96b1551b147692ac3540e2..f46db1b31ede62d9a3f9ed3122961f855d6553a6 100644 +--- a/dist/index.d.ts ++++ b/dist/index.d.ts +@@ -1,3 +1,4 @@ + export * from './MessageManager'; + export * from './PersonalMessageManager'; + export * from './TypedMessageManager'; ++export * from './EncryptionPublicKeyManager'; +diff --git a/dist/index.js b/dist/index.js +index 8d75777f20c195b18edb2f0694265d308dc92b8e..1eb9f8c52c013f11d4937e3d2c168c37bc89aa82 100644 +--- a/dist/index.js ++++ b/dist/index.js +@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); + __exportStar(require("./MessageManager"), exports); + __exportStar(require("./PersonalMessageManager"), exports); + __exportStar(require("./TypedMessageManager"), exports); ++__exportStar(require("./EncryptionPublicKeyManager"), exports); + //# sourceMappingURL=index.js.map +\ No newline at end of file +diff --git a/dist/index.js.map b/dist/index.js.map +index 493206392ac232790a0ff6a32ea0e961f6138d45..0f765579ee92feec8a7ab79d05407bbb5f3f4dee 100644 +--- a/dist/index.js.map ++++ b/dist/index.js.map +@@ -1 +1 @@ +-{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,2DAAyC;AACzC,wDAAsC","sourcesContent":["export * from './MessageManager';\nexport * from './PersonalMessageManager';\nexport * from './TypedMessageManager';\n"]} +\ No newline at end of file ++{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,2DAAyC;AACzC,wDAAsC;AACtC,+DAA6C","sourcesContent":["export * from './MessageManager';\nexport * from './PersonalMessageManager';\nexport * from './TypedMessageManager';\nexport * from './EncryptionPublicKeyManager';\n"]} +\ No newline at end of file +diff --git a/dist/utils.d.ts b/dist/utils.d.ts +index 7ff922ba330d3eb2842b4ea853c31960b632a938..36eb86b5f6c49ab995864b9c22ca015e2c1ea376 100644 +--- a/dist/utils.d.ts ++++ b/dist/utils.d.ts +@@ -1,6 +1,7 @@ + import { MessageParams } from './MessageManager'; + import { PersonalMessageParams } from './PersonalMessageManager'; + import { TypedMessageParams } from './TypedMessageManager'; ++import { EncryptionPublicKeyParams } from './EncryptionPublicKeyManager'; + /** + * A helper function that converts rawmessageData buffer data to a hex, or just returns the data if + * it is already formatted as a hex. +@@ -30,3 +31,10 @@ export declare function validateTypedSignMessageDataV1(messageData: TypedMessage + * @param messageData - TypedMessageParams object to validate. + */ + export declare function validateTypedSignMessageDataV3(messageData: TypedMessageParams): void; ++/** ++ * Validates messageData for the eth_getEncryptionPublicKey message and throws in ++ * the event of any validation error. ++ * ++ * @param messageData - address string to validate. ++ */ ++export declare function validateEncryptionPublicKeyMessageData(messageData: EncryptionPublicKeyParams): void; +diff --git a/dist/utils.js b/dist/utils.js +index b4f9d5804339bbf70bc68d92a875e203f19b73ae..3d80cd8353dfdbeac2e93b706bd382980ea7cca2 100644 +--- a/dist/utils.js ++++ b/dist/utils.js +@@ -1,6 +1,6 @@ + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); +-exports.validateTypedSignMessageDataV3 = exports.validateTypedSignMessageDataV1 = exports.validateSignMessageData = exports.normalizeMessageData = void 0; ++exports.validateEncryptionPublicKeyMessageData = exports.validateTypedSignMessageDataV3 = exports.validateTypedSignMessageDataV1 = exports.validateSignMessageData = exports.normalizeMessageData = void 0; + const ethereumjs_util_1 = require("ethereumjs-util"); + const eth_sig_util_1 = require("eth-sig-util"); + const jsonschema_1 = require("jsonschema"); +@@ -94,4 +94,17 @@ function validateTypedSignMessageDataV3(messageData) { + } + } + exports.validateTypedSignMessageDataV3 = validateTypedSignMessageDataV3; ++/** ++ * Validates messageData for the eth_getEncryptionPublicKey message and throws in ++ * the event of any validation error. ++ * ++ * @param messageData - address string to validate. ++ */ ++function validateEncryptionPublicKeyMessageData(messageData) { ++ const { from } = messageData; ++ if (!from || typeof from !== 'string' || !(0, controller_utils_1.isValidHexAddress)(from)) { ++ throw new Error(`Invalid "from" address: ${from} must be a valid string.`); ++ } ++} ++exports.validateEncryptionPublicKeyMessageData = validateEncryptionPublicKeyMessageData; + //# sourceMappingURL=utils.js.map +\ No newline at end of file +diff --git a/dist/utils.js.map b/dist/utils.js.map +index e397b664d87243ea85c204c29374d930d3c4386e..885a3ff0c086531ab9fc1d9e06fa207152d320b0 100644 +--- a/dist/utils.js.map ++++ b/dist/utils.js.map +@@ -1 +1 @@ +-{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,qDAA4E;AAC5E,+CAAwE;AACxE,2CAAsC;AACtC,iEAA+D;AAK/D,MAAM,KAAK,GAAG,kBAAkB,CAAC;AAEjC;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAAC,IAAY;IAC/C,IAAI;QACF,MAAM,QAAQ,GAAG,IAAA,gCAAc,EAAC,IAAI,CAAC,CAAC;QACtC,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YACzB,OAAO,IAAA,8BAAY,EAAC,QAAQ,CAAC,CAAC;SAC/B;KACF;IAAC,OAAO,CAAC,EAAE;QACV,0BAA0B;KAC3B;IACD,OAAO,IAAA,6BAAW,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAChD,CAAC;AAVD,oDAUC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CACrC,W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C,EACpC;QACA,MAAM,IAAI,KAAK,CACb,2BAA2B,WAAW,CAAC,IAAI,0BAA0B,CACtE,CAAC;KACH;IAED,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,OAAO,WAAW,CAAC,IAAI,KAAK,QAAQ,EAAE;QAC7D,MAAM,IAAI,KAAK,CACb,2BAA2B,WAAW,CAAC,IAAI,yBAAyB,CACrE,CAAC;KACH;IACD,IAAI,IAAI,CAAC;IACT,IAAI;QACF,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;KACrC;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;KAChE;IACD,MAAM,UAAU,GAAG,IAAA,qBAAQ,EAAC,IAAI,EAAE,mCAAoB,CAAC,CAAC;IACxD,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QAChC,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;KACH;AACH,CAAC;AA9BD,wEA8BC","sourcesContent":["import { addHexPrefix, bufferToHex, stripHexPrefix } from 'ethereumjs-util';\nimport { TYPED_MESSAGE_SCHEMA, typedSignatureHash } from 'eth-sig-util';\nimport { validate } from 'jsonschema';\nimport { isValidHexAddress } from '@metamask/controller-utils';\nimport { MessageParams } from './MessageManager';\nimport { PersonalMessageParams } from './PersonalMessageManager';\nimport { TypedMessageParams } from './TypedMessageManager';\n\nconst hexRe = /^[0-9A-Fa-f]+$/gu;\n\n/**\n * A helper function that converts rawmessageData buffer data to a hex, or just returns the data if\n * it is already formatted as a hex.\n *\n * @param data - The buffer data to convert to a hex.\n * @returns A hex string conversion of the buffer data.\n */\nexport function normalizeMessageData(data: string) {\n try {\n const stripped = stripHexPrefix(data);\n if (stripped.match(hexRe)) {\n return addHexPrefix(stripped);\n }\n } catch (e) {\n /* istanbul ignore next */\n }\n return bufferToHex(Buffer.from(data, 'utf8'));\n}\n\n/**\n * Validates a PersonalMessageParams and MessageParams objects for required properties and throws in\n * the event of any validation error.\n *\n * @param messageData - PersonalMessageParams object to validate.\n */\nexport function validateSignMessageData(\n messageData: PersonalMessageParams | MessageParams,\n) {\n const { from, data } = messageData;\n if (!from || typeof from !== 'string' || !isValidHexAddress(from)) {\n throw new Error(`Invalid \"from\" address: ${from} must be a valid string.`);\n }\n\n if (!data || typeof data !== 'string') {\n throw new Error(`Invalid message \"data\": ${data} must be a valid string.`);\n }\n}\n\n/**\n * Validates a TypedMessageParams object for required properties and throws in\n * the event of any validation error for eth_signTypedMessage_V1.\n *\n * @param messageData - TypedMessageParams object to validate.\n */\nexport function validateTypedSignMessageDataV1(\n messageData: TypedMessageParams,\n) {\n if (\n !messageData.from ||\n typeof messageData.from !== 'string' ||\n !isValidHexAddress(messageData.from)\n ) {\n throw new Error(\n `Invalid \"from\" address: ${messageData.from} must be a valid string.`,\n );\n }\n\n if (!messageData.data || !Array.isArray(messageData.data)) {\n throw new Error(\n `Invalid message \"data\": ${messageData.data} must be a valid array.`,\n );\n }\n\n try {\n // typedSignatureHash will throw if the data is invalid.\n typedSignatureHash(messageData.data as any);\n } catch (e) {\n throw new Error(`Expected EIP712 typed data.`);\n }\n}\n\n/**\n * Validates a TypedMessageParams object for required properties and throws in\n * the event of any validation error for eth_signTypedMessage_V3.\n *\n * @param messageData - TypedMessageParams object to validate.\n */\nexport function validateTypedSignMessageDataV3(\n messageData: TypedMessageParams,\n) {\n if (\n !messageData.from ||\n typeof messageData.from !== 'string' ||\n !isValidHexAddress(messageData.from)\n ) {\n throw new Error(\n `Invalid \"from\" address: ${messageData.from} must be a valid string.`,\n );\n }\n\n if (!messageData.data || typeof messageData.data !== 'string') {\n throw new Error(\n `Invalid message \"data\": ${messageData.data} must be a valid array.`,\n );\n }\n let data;\n try {\n data = JSON.parse(messageData.data);\n } catch (e) {\n throw new Error('Data must be passed as a valid JSON string.');\n }\n const validation = validate(data, TYPED_MESSAGE_SCHEMA);\n if (validation.errors.length > 0) {\n throw new Error(\n 'Data must conform to EIP-712 schema. See https://git.io/fNtcx.',\n );\n }\n}\n"]} +\ No newline at end of file ++{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,qDAA4E;AAC5E,+CAAwE;AACxE,2CAAsC;AACtC,iEAA+D;AAM/D,MAAM,KAAK,GAAG,kBAAkB,CAAC;AAEjC;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAAC,IAAY;IAC/C,IAAI;QACF,MAAM,QAAQ,GAAG,IAAA,gCAAc,EAAC,IAAI,CAAC,CAAC;QACtC,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YACzB,OAAO,IAAA,8BAAY,EAAC,QAAQ,CAAC,CAAC;SAC/B;KACF;IAAC,OAAO,CAAC,EAAE;QACV,0BAA0B;KAC3B;IACD,OAAO,IAAA,6BAAW,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAChD,CAAC;AAVD,oDAUC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CACrC,WAAkD;IAElD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;IACnC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAA,oCAAiB,EAAC,IAAI,CAAC,EAAE;QACjE,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,0BAA0B,CAAC,CAAC;KAC5E;IAED,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QACrC,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,0BAA0B,CAAC,CAAC;KAC5E;AACH,CAAC;AAXD,0DAWC;AAED;;;;;GAKG;AACH,SAAgB,8BAA8B,CAC5C,WAA+B;IAE/B,IACE,CAAC,WAAW,CAAC,IAAI;QACjB,OAAO,WAAW,CAAC,IAAI,KAAK,QAAQ;QACpC,CA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AAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QAChC,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;KACH;AACH,CAAC;AA9BD,wEA8BC;AAED;;;;;GAKG;AACH,SAAgB,sCAAsC,CACpD,WAAsC;IAEtC,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;IAC7B,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAA,oCAAiB,EAAC,IAAI,CAAC,EAAE;QACjE,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,0BAA0B,CAAC,CAAC;KAC5E;AACH,CAAC;AAPD,wFAOC","sourcesContent":["import { addHexPrefix, bufferToHex, stripHexPrefix } from 'ethereumjs-util';\nimport { TYPED_MESSAGE_SCHEMA, typedSignatureHash } from 'eth-sig-util';\nimport { validate } from 'jsonschema';\nimport { isValidHexAddress } from '@metamask/controller-utils';\nimport { MessageParams } from './MessageManager';\nimport { PersonalMessageParams } from './PersonalMessageManager';\nimport { TypedMessageParams } from './TypedMessageManager';\nimport { EncryptionPublicKeyParams } from './EncryptionPublicKeyManager';\n\nconst hexRe = /^[0-9A-Fa-f]+$/gu;\n\n/**\n * A helper function that converts rawmessageData buffer data to a hex, or just returns the data if\n * it is already formatted as a hex.\n *\n * @param data - The buffer data to convert to a hex.\n * @returns A hex string conversion of the buffer data.\n */\nexport function normalizeMessageData(data: string) {\n try {\n const stripped = stripHexPrefix(data);\n if (stripped.match(hexRe)) {\n return addHexPrefix(stripped);\n }\n } catch (e) {\n /* istanbul ignore next */\n }\n return bufferToHex(Buffer.from(data, 'utf8'));\n}\n\n/**\n * Validates a PersonalMessageParams and MessageParams objects for required properties and throws in\n * the event of any validation error.\n *\n * @param messageData - PersonalMessageParams object to validate.\n */\nexport function validateSignMessageData(\n messageData: PersonalMessageParams | MessageParams,\n) {\n const { from, data } = messageData;\n if (!from || typeof from !== 'string' || !isValidHexAddress(from)) {\n throw new Error(`Invalid \"from\" address: ${from} must be a valid string.`);\n }\n\n if (!data || typeof data !== 'string') {\n throw new Error(`Invalid message \"data\": ${data} must be a valid string.`);\n }\n}\n\n/**\n * Validates a TypedMessageParams object for required properties and throws in\n * the event of any validation error for eth_signTypedMessage_V1.\n *\n * @param messageData - TypedMessageParams object to validate.\n */\nexport function validateTypedSignMessageDataV1(\n messageData: TypedMessageParams,\n) {\n if (\n !messageData.from ||\n typeof messageData.from !== 'string' ||\n !isValidHexAddress(messageData.from)\n ) {\n throw new Error(\n `Invalid \"from\" address: ${messageData.from} must be a valid string.`,\n );\n }\n\n if (!messageData.data || !Array.isArray(messageData.data)) {\n throw new Error(\n `Invalid message \"data\": ${messageData.data} must be a valid array.`,\n );\n }\n\n try {\n // typedSignatureHash will throw if the data is invalid.\n typedSignatureHash(messageData.data as any);\n } catch (e) {\n throw new Error(`Expected EIP712 typed data.`);\n }\n}\n\n/**\n * Validates a TypedMessageParams object for required properties and throws in\n * the event of any validation error for eth_signTypedMessage_V3.\n *\n * @param messageData - TypedMessageParams object to validate.\n */\nexport function validateTypedSignMessageDataV3(\n messageData: TypedMessageParams,\n) {\n if (\n !messageData.from ||\n typeof messageData.from !== 'string' ||\n !isValidHexAddress(messageData.from)\n ) {\n throw new Error(\n `Invalid \"from\" address: ${messageData.from} must be a valid string.`,\n );\n }\n\n if (!messageData.data || typeof messageData.data !== 'string') {\n throw new Error(\n `Invalid message \"data\": ${messageData.data} must be a valid array.`,\n );\n }\n let data;\n try {\n data = JSON.parse(messageData.data);\n } catch (e) {\n throw new Error('Data must be passed as a valid JSON string.');\n }\n const validation = validate(data, TYPED_MESSAGE_SCHEMA);\n if (validation.errors.length > 0) {\n throw new Error(\n 'Data must conform to EIP-712 schema. See https://git.io/fNtcx.',\n );\n }\n}\n\n/**\n * Validates messageData for the eth_getEncryptionPublicKey message and throws in\n * the event of any validation error.\n *\n * @param messageData - address string to validate.\n */\nexport function validateEncryptionPublicKeyMessageData(\n messageData: EncryptionPublicKeyParams,\n) {\n const { from } = messageData;\n if (!from || typeof from !== 'string' || !isValidHexAddress(from)) {\n throw new Error(`Invalid \"from\" address: ${from} must be a valid string.`);\n }\n}\n"]} +\ No newline at end of file diff --git a/package.json b/package.json index 142e0bbb5272..fcb2e7c6f6f2 100644 --- a/package.json +++ b/package.json @@ -205,9 +205,7 @@ "request@^2.83.0": "patch:request@npm%3A2.88.2#./.yarn/patches/request-npm-2.88.2-f4a57c72c4.patch", "request@^2.88.2": "patch:request@npm%3A2.88.2#./.yarn/patches/request-npm-2.88.2-f4a57c72c4.patch", "request@^2.85.0": "patch:request@npm%3A2.88.2#./.yarn/patches/request-npm-2.88.2-f4a57c72c4.patch", - "@metamask/controller-utils": "portal:/home/bernardo/repos/metamask/metamask-core/packages/controller-utils", - "@metamask/base-controller": "portal:/home/bernardo/repos/metamask/metamask-core/packages/base-controller", - "@metamask/message-manager": "portal:/home/bernardo/repos/metamask/metamask-core/packages/message-manager" + "@metamask/message-manager@^2.0.0": "patch:@metamask/message-manager@npm%3A2.0.0#./.yarn/patches/@metamask-message-manager-npm-2.0.0-f23d924f4f.patch" }, "dependencies": { "@babel/runtime": "^7.5.5", diff --git a/yarn.lock b/yarn.lock index 65c2f71e6dd6..f602e53d65b7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3667,14 +3667,35 @@ __metadata: languageName: node linkType: hard -"@metamask/base-controller@portal:/home/bernardo/repos/metamask/metamask-core/packages/base-controller::locator=metamask-crx%40workspace%3A.": - version: 0.0.0-use.local - resolution: "@metamask/base-controller@portal:/home/bernardo/repos/metamask/metamask-core/packages/base-controller::locator=metamask-crx%40workspace%3A." +"@metamask/base-controller@npm:^1.0.0, @metamask/base-controller@npm:^1.1.1, @metamask/base-controller@npm:^1.1.2": + version: 1.1.2 + resolution: "@metamask/base-controller@npm:1.1.2" dependencies: - "@metamask/controller-utils": "workspace:^" + "@metamask/controller-utils": ^2.0.0 immer: ^9.0.6 + checksum: 54a114615924a755fe1a1e2d0b9fd7b9f982dee813a9908889e133aec8190f7d52a7903f830d66b020b487c1c4047b1a379ac07e9c80fec67688763bd8a713dd languageName: node - linkType: soft + linkType: hard + +"@metamask/base-controller@npm:^2.0.0": + version: 2.0.0 + resolution: "@metamask/base-controller@npm:2.0.0" + dependencies: + "@metamask/controller-utils": ^3.0.0 + immer: ^9.0.6 + checksum: afd7df59cbcd26261e3d015ac0669261efbfad8e106b55ae7184f7445979b867f78f0d56fe103566150236093847b3acc68473f979e46bd9c67f654857995458 + languageName: node + linkType: hard + +"@metamask/base-controller@npm:~1.0.0": + version: 1.0.0 + resolution: "@metamask/base-controller@npm:1.0.0" + dependencies: + "@metamask/controller-utils": ~1.0.0 + immer: ^9.0.6 + checksum: 40affd024add235548c886bd8ad3348682231af8d4a2f7e6fbc5dea5ffa077ed48535f21ac17017c640c50b5d17b5211c30cbb23b7025f360801e72ccbd61a5d + languageName: node + linkType: hard "@metamask/browser-passworder@npm:^4.0.2": version: 4.0.2 @@ -3690,17 +3711,46 @@ __metadata: languageName: node linkType: hard -"@metamask/controller-utils@portal:/home/bernardo/repos/metamask/metamask-core/packages/controller-utils::locator=metamask-crx%40workspace%3A.": - version: 0.0.0-use.local - resolution: "@metamask/controller-utils@portal:/home/bernardo/repos/metamask/metamask-core/packages/controller-utils::locator=metamask-crx%40workspace%3A." +"@metamask/controller-utils@npm:^1.0.0, @metamask/controller-utils@npm:~1.0.0": + version: 1.0.0 + resolution: "@metamask/controller-utils@npm:1.0.0" dependencies: eth-ens-namehash: ^2.0.8 eth-rpc-errors: ^4.0.0 ethereumjs-util: ^7.0.10 ethjs-unit: ^0.1.6 fast-deep-equal: ^3.1.3 + isomorphic-fetch: ^3.0.0 + checksum: 76e0629ba97b0b704f2f08e346fc27cf404630a64088504dbbad3d4124afe7a6c9bf3627e999ab9a1f1c183a444978ecc288b6df3ab30b47b5398a1da848ebbf languageName: node - linkType: soft + linkType: hard + +"@metamask/controller-utils@npm:^2.0.0": + version: 2.0.0 + resolution: "@metamask/controller-utils@npm:2.0.0" + dependencies: + eth-ens-namehash: ^2.0.8 + eth-rpc-errors: ^4.0.0 + ethereumjs-util: ^7.0.10 + ethjs-unit: ^0.1.6 + fast-deep-equal: ^3.1.3 + isomorphic-fetch: ^3.0.0 + checksum: 7e77aad25057b63a62a05058685fc07f78693d737892fc617a23ae06512715ed74a536174396e04cc276999e44c7ca67bd8a0026e5b820455dbf6eb5d0c7c173 + languageName: node + linkType: hard + +"@metamask/controller-utils@npm:^3.0.0": + version: 3.0.0 + resolution: "@metamask/controller-utils@npm:3.0.0" + dependencies: + eth-ens-namehash: ^2.0.8 + eth-rpc-errors: ^4.0.0 + ethereumjs-util: ^7.0.10 + ethjs-unit: ^0.1.6 + fast-deep-equal: ^3.1.3 + checksum: 44227aa9f716f86373a1a4fb86b7ae1c51199dd819f30a3a310a9f87838b7e11c1a3bb024572253bd3cb0258281596cfab8fbf317c3fe90962fa6cf426aa6858 + languageName: node + linkType: hard "@metamask/design-tokens@npm:^1.6.0, @metamask/design-tokens@npm:^1.9.0": version: 1.11.1 @@ -3984,19 +4034,35 @@ __metadata: languageName: node linkType: hard -"@metamask/message-manager@portal:/home/bernardo/repos/metamask/metamask-core/packages/message-manager::locator=metamask-crx%40workspace%3A.": - version: 0.0.0-use.local - resolution: "@metamask/message-manager@portal:/home/bernardo/repos/metamask/metamask-core/packages/message-manager::locator=metamask-crx%40workspace%3A." +"@metamask/message-manager@npm:2.0.0": + version: 2.0.0 + resolution: "@metamask/message-manager@npm:2.0.0" dependencies: - "@metamask/base-controller": "workspace:^" - "@metamask/controller-utils": "workspace:^" + "@metamask/base-controller": ^2.0.0 + "@metamask/controller-utils": ^3.0.0 "@types/uuid": ^8.3.0 eth-sig-util: ^3.0.0 ethereumjs-util: ^7.0.10 jsonschema: ^1.2.4 uuid: ^8.3.2 + checksum: f130b5c58fbbb5ccd69da32cfa43839a09dec906974c6d0f6e2d46f15d1a872c564b0c880aac2979b7ffc8d00bcf328bf1989cb133cc41bc612e1e6e16ef9ef5 languageName: node - linkType: soft + linkType: hard + +"@metamask/message-manager@patch:@metamask/message-manager@npm%3A2.0.0#./.yarn/patches/@metamask-message-manager-npm-2.0.0-f23d924f4f.patch::locator=metamask-crx%40workspace%3A.": + version: 2.0.0 + resolution: "@metamask/message-manager@patch:@metamask/message-manager@npm%3A2.0.0#./.yarn/patches/@metamask-message-manager-npm-2.0.0-f23d924f4f.patch::version=2.0.0&hash=c81619&locator=metamask-crx%40workspace%3A." + dependencies: + "@metamask/base-controller": ^2.0.0 + "@metamask/controller-utils": ^3.0.0 + "@types/uuid": ^8.3.0 + eth-sig-util: ^3.0.0 + ethereumjs-util: ^7.0.10 + jsonschema: ^1.2.4 + uuid: ^8.3.2 + checksum: 85b237b9dbdce89140a44d340450c166c77a578bb44441f96a659579a072b67c9ba8c0ac896d9df306f8c164644ec7d192ec19e37c1976c8f49bbbe2e3721ea2 + languageName: node + linkType: hard "@metamask/metamask-eth-abis@npm:3.0.0, @metamask/metamask-eth-abis@npm:^3.0.0": version: 3.0.0