@metamask-previews/message-manager 7.3.2-preview.56ca173 → 7.3.5-preview.ce06456

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [7.3.5]
10
+ ### Changed
11
+ - Bump dependency on `@metamask/utils` to ^8.1.0 ([#1639](https://github.com/MetaMask/core/pull/1639))
12
+ - Bump dependency on `@metamask/base-controller` to ^3.2.3
13
+ - Bump dependency on `metamask/controller-utils` to ^5.0.2
14
+
15
+ ### Fixed
16
+ - Fix `prepMessageForSigning` in all message managers to handle frozen `messageParams` ([#1733](https://github.com/MetaMask/core/pull/1733))
17
+
18
+ ## [7.3.4]
19
+ ### Changed
20
+ - Update TypeScript to v4.8.x ([#1718](https://github.com/MetaMask/core/pull/1718))
21
+
22
+ ## [7.3.3]
23
+ ### Changed
24
+ - Bump dependency on `@metamask/controller-utils` to ^5.0.0
25
+
9
26
  ## [7.3.2]
10
27
  ### Changed
11
28
  - Bump @metamask/eth-sig-util from 6.0.0 to 7.0.0 ([#1669](https://github.com/MetaMask/core/pull/1669))
@@ -109,7 +126,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
109
126
 
110
127
  All changes listed after this point were applied to this package following the monorepo conversion.
111
128
 
112
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.3.2...HEAD
129
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.3.5...HEAD
130
+ [7.3.5]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.3.4...@metamask/message-manager@7.3.5
131
+ [7.3.4]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.3.3...@metamask/message-manager@7.3.4
132
+ [7.3.3]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.3.2...@metamask/message-manager@7.3.3
113
133
  [7.3.2]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.3.1...@metamask/message-manager@7.3.2
114
134
  [7.3.1]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.3.0...@metamask/message-manager@7.3.1
115
135
  [7.3.0]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.2.0...@metamask/message-manager@7.3.0
@@ -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;AACH,MAAM,WAAW,OAAQ,SAAQ,eAAe;IAC9C,aAAa,EAAE,aAAa,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,aAAc,SAAQ,qBAAqB;IAC1D,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;GASG;AACH,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;CAI1B;AAED,eAAe,cAAc,CAAC"}
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;AACH,MAAM,WAAW,OAAQ,SAAQ,eAAe;IAC9C,aAAa,EAAE,aAAa,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,aAAc,SAAQ,qBAAqB;IAC1D,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;GASG;AACH,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"}
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.MessageManager = void 0;
13
24
  const uuid_1 = require("uuid");
@@ -63,8 +74,9 @@ class MessageManager extends AbstractMessageManager_1.AbstractMessageManager {
63
74
  * @returns Promise resolving to the messageParams with the metamaskId property removed.
64
75
  */
65
76
  prepMessageForSigning(messageParams) {
66
- delete messageParams.metamaskId;
67
- return Promise.resolve(messageParams);
77
+ // Using delete operation will throw an error on frozen messageParams
78
+ const { metamaskId: _metamaskId } = messageParams, messageParamsWithoutId = __rest(messageParams, ["metamaskId"]);
79
+ return Promise.resolve(messageParamsWithoutId);
68
80
  }
69
81
  }
70
82
  exports.MessageManager = MessageManager;
@@ -1 +1 @@
1
- {"version":3,"file":"MessageManager.js","sourceRoot":"","sources":["../src/MessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAoC;AAQpC,qEAAkE;AAClE,mCAAwE;AA2CxE;;GAEG;AACH,MAAa,cAAe,SAAQ,+CAInC;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,gBAAgB,CAAC;IAmDnC,CAAC;IAjDC;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAA4B,EAC5B,GAAqB;;YAErB,IAAA,+BAAuB,EAAC,aAAa,CAAC,CAAC;YACvC,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,GAAY;gBAC3B,EAAE,EAAE,SAAS;gBACb,aAAa;gBACb,qBAAqB,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,qBAAqB;gBACjD,MAAM,EAAE,YAAY;gBACpB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;gBAChB,IAAI,EAAE,UAAU;aACjB,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,aAAoC;QAEpC,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;CACF;AA3DD,wCA2DC;AAED,kBAAe,cAAc,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 { 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 */\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 */\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 */\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 delete messageParams.metamaskId;\n return Promise.resolve(messageParams);\n }\n}\n\nexport default MessageManager;\n"]}
1
+ {"version":3,"file":"MessageManager.js","sourceRoot":"","sources":["../src/MessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAoC;AAQpC,qEAAkE;AAClE,mCAAwE;AA2CxE;;GAEG;AACH,MAAa,cAAe,SAAQ,+CAInC;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,gBAAgB,CAAC;IAqDnC,CAAC;IAnDC;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAA4B,EAC5B,GAAqB;;YAErB,IAAA,+BAAuB,EAAC,aAAa,CAAC,CAAC;YACvC,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,GAAY;gBAC3B,EAAE,EAAE,SAAS;gBACb,aAAa;gBACb,qBAAqB,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,qBAAqB;gBACjD,MAAM,EAAE,YAAY;gBACpB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;gBAChB,IAAI,EAAE,UAAU;aACjB,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,aAAoC;QAEpC,qEAAqE;QACrE,MAAM,EAAE,UAAU,EAAE,WAAW,KAC7B,aAAa,EADqB,sBAAsB,UACxD,aAAa,EADT,cAAsD,CAC7C,CAAC;QAChB,OAAO,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACjD,CAAC;CACF;AA7DD,wCA6DC;AAED,kBAAe,cAAc,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 { 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 */\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 */\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 */\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;AACH,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,aAAa,EAAE,qBAAqB,CAAC;CACtC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,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;CAIlC;AAED,eAAe,sBAAsB,CAAC"}
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;AACH,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,aAAa,EAAE,qBAAqB,CAAC;CACtC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,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"}
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.PersonalMessageManager = void 0;
13
24
  const controller_utils_1 = require("@metamask/controller-utils");
@@ -66,8 +77,9 @@ class PersonalMessageManager extends AbstractMessageManager_1.AbstractMessageMan
66
77
  * @returns Promise resolving to the messageParams with the metamaskId property removed.
67
78
  */
68
79
  prepMessageForSigning(messageParams) {
69
- delete messageParams.metamaskId;
70
- return Promise.resolve(messageParams);
80
+ // Using delete operation will throw an error on frozen messageParams
81
+ const { metamaskId: _metamaskId } = messageParams, messageParamsWithoutId = __rest(messageParams, ["metamaskId"]);
82
+ return Promise.resolve(messageParamsWithoutId);
71
83
  }
72
84
  }
73
85
  exports.PersonalMessageManager = PersonalMessageManager;
@@ -1 +1 @@
1
- {"version":3,"file":"PersonalMessageManager.js","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,iEAAwD;AACxD,+BAAoC;AAQpC,qEAAkE;AAClE,mCAAwE;AA6CxE;;GAEG;AACH,MAAa,sBAAuB,SAAQ,+CAI3C;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,wBAAwB,CAAC;IAuD3C,CAAC;IArDC;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAoC,EACpC,GAAqB;;YAErB,IAAA,+BAAuB,EAAC,aAAa,CAAC,CAAC;YACvC,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;YAE9D,MAAM,kBAAkB,GAAG,IAAA,6BAAU,EAAC,aAAa,CAAC,CAAC;YACrD,MAAM,cAAc,mCAAQ,aAAa,KAAE,IAAI,EAAE,kBAAkB,GAAE,CAAC;YAEtE,MAAM,SAAS,GAAG,IAAA,SAAM,GAAE,CAAC;YAC3B,MAAM,WAAW,GAAoB;gBACnC,EAAE,EAAE,SAAS;gBACb,aAAa,EAAE,cAAc;gBAC7B,qBAAqB,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,qBAAqB;gBACjD,MAAM,EAAE,YAAY;gBACpB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;gBAChB,IAAI,EAAE,eAAe;aACtB,CAAC;YACF,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,kCAC5B,cAAc,GACd,EAAE,UAAU,EAAE,SAAS,EAAE,EAC5B,CAAC;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAA4C;QAE5C,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;CACF;AA/DD,wDA+DC;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 */\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 */\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 */\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 delete messageParams.metamaskId;\n return Promise.resolve(messageParams);\n }\n}\n\nexport default PersonalMessageManager;\n"]}
1
+ {"version":3,"file":"PersonalMessageManager.js","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA,iEAAwD;AACxD,+BAAoC;AAQpC,qEAAkE;AAClE,mCAAwE;AA6CxE;;GAEG;AACH,MAAa,sBAAuB,SAAQ,+CAI3C;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,wBAAwB,CAAC;IAyD3C,CAAC;IAvDC;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAoC,EACpC,GAAqB;;YAErB,IAAA,+BAAuB,EAAC,aAAa,CAAC,CAAC;YACvC,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;YAE9D,MAAM,kBAAkB,GAAG,IAAA,6BAAU,EAAC,aAAa,CAAC,CAAC;YACrD,MAAM,cAAc,mCAAQ,aAAa,KAAE,IAAI,EAAE,kBAAkB,GAAE,CAAC;YAEtE,MAAM,SAAS,GAAG,IAAA,SAAM,GAAE,CAAC;YAC3B,MAAM,WAAW,GAAoB;gBACnC,EAAE,EAAE,SAAS;gBACb,aAAa,EAAE,cAAc;gBAC7B,qBAAqB,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,qBAAqB;gBACjD,MAAM,EAAE,YAAY;gBACpB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;gBAChB,IAAI,EAAE,eAAe;aACtB,CAAC;YACF,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,kCAC5B,cAAc,GACd,EAAE,UAAU,EAAE,SAAS,EAAE,EAC5B,CAAC;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAA4C;QAE5C,qEAAqE;QACrE,MAAM,EAAE,UAAU,EAAE,WAAW,KAC7B,aAAa,EADqB,sBAAsB,UACxD,aAAa,EADT,cAAsD,CAC7C,CAAC;QAChB,OAAO,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 */\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 */\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 */\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;AACH,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;AACH,MAAM,WAAW,kBAAmB,SAAQ,qBAAqB;IAC/D,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,MAAM,GAAG,wBAAwB,CAAC;CACrE;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,0BACf,SAAQ,6BAA6B;IACrC,IAAI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E,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,WAAW,kBAAmB,SAAQ,qBAAqB;IAC/D,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,MAAM,GAAG,wBAAwB,CAAC;CACrE;AAED;;;;;;;;;;;;GAYG;AACH,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"}
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.TypedMessageManager = void 0;
13
24
  const uuid_1 = require("uuid");
@@ -91,9 +102,9 @@ class TypedMessageManager extends AbstractMessageManager_1.AbstractMessageManage
91
102
  * @returns Promise resolving to the messageParams with the metamaskId and version properties removed.
92
103
  */
93
104
  prepMessageForSigning(messageParams) {
94
- delete messageParams.metamaskId;
95
- delete messageParams.version;
96
- return Promise.resolve(messageParams);
105
+ // Using delete operation will throw an error on frozen messageParams
106
+ const { metamaskId: _metamaskId, version: _version } = messageParams, messageParamsWithoutId = __rest(messageParams, ["metamaskId", "version"]);
107
+ return Promise.resolve(messageParamsWithoutId);
97
108
  }
98
109
  }
99
110
  exports.TypedMessageManager = TypedMessageManager;
@@ -1 +1 @@
1
- {"version":3,"file":"TypedMessageManager.js","sourceRoot":"","sources":["../src/TypedMessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAoC;AAQpC,qEAAkE;AAClE,mCAGiB;AAiEjB;;GAEG;AACH,MAAa,mBAAoB,SAAQ,+CAIxC;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,qBAAqB,CAAC;IAuFxC,CAAC;IArFC;;;;;;;;;;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,KAAK,IAAI,IAAI,OAAO,KAAK,IAAI,EAAE;gBACxC,MAAM,cAAc,GAAG,MAAA,IAAI,CAAC,iBAAiB,oDAAI,CAAC;gBAClD,IAA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G;IACH,qBAAqB,CACnB,aAAyC;QAEzC,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,aAAa,CAAC,OAAO,CAAC;QAC7B,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;CACF;AA/FD,kDA+FC;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 */\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 */\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 */\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 delete messageParams.metamaskId;\n delete messageParams.version;\n return Promise.resolve(messageParams);\n }\n}\n\nexport default TypedMessageManager;\n"]}
1
+ {"version":3,"file":"TypedMessageManager.js","sourceRoot":"","sources":["../src/TypedMessageManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAoC;AAQpC,qEAAkE;AAClE,mCAGiB;AAiEjB;;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,KAAK,IAAI,IAAI,OAAO,KAAK,IAAI,EAAE;gBACxC,MAAM,cAAc,GAAG,MAAA,IAAI,CAAC,iBAAiB,oDAAI,CAAC;gBAClD,IAAA,wCAAgC,EAAC,aAAa,EAAE,cAAc,CAAC,CAAC;aACjE;YAED,IACE,OAAO,aAAa,CAAC,IAAI,KAAK,QAAQ;gBACtC,CAAC,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,IAAI,CAAC,EACtC;gBACA,aAAa,CAAC,IAAI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AAC,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 */\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 */\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 */\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.2-preview.56ca173",
3
+ "version": "7.3.5-preview.ce06456",
4
4
  "description": "Stores and manages interactions with signing requests",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -25,13 +25,14 @@
25
25
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/message-manager",
26
26
  "publish:preview": "yarn npm publish --tag preview",
27
27
  "test": "jest",
28
+ "test:clean": "jest --clearCache",
28
29
  "test:watch": "jest --watch"
29
30
  },
30
31
  "dependencies": {
31
- "@metamask/base-controller": "^3.2.1",
32
- "@metamask/controller-utils": "^4.3.2",
32
+ "@metamask/base-controller": "^3.2.3",
33
+ "@metamask/controller-utils": "^5.0.2",
33
34
  "@metamask/eth-sig-util": "^7.0.0",
34
- "@metamask/utils": "^6.2.0",
35
+ "@metamask/utils": "^8.1.0",
35
36
  "@types/uuid": "^8.3.0",
36
37
  "ethereumjs-util": "^7.0.10",
37
38
  "jsonschema": "^1.2.4",
@@ -43,9 +44,9 @@
43
44
  "deepmerge": "^4.2.2",
44
45
  "jest": "^27.5.1",
45
46
  "ts-jest": "^27.1.4",
46
- "typedoc": "^0.22.15",
47
- "typedoc-plugin-missing-exports": "^0.22.6",
48
- "typescript": "~4.6.3"
47
+ "typedoc": "^0.24.8",
48
+ "typedoc-plugin-missing-exports": "^2.0.0",
49
+ "typescript": "~4.8.4"
49
50
  },
50
51
  "engines": {
51
52
  "node": ">=16.0.0"