@metamask-previews/message-manager 10.1.1-preview-e46fca9e → 10.1.1-preview-2f4bcaa9

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/index.cjs +1 -2
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +1 -2
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.mts +1 -2
  7. package/dist/index.d.mts.map +1 -1
  8. package/dist/index.mjs +1 -2
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/types.cjs +3 -0
  11. package/dist/types.cjs.map +1 -0
  12. package/dist/types.d.cts +16 -0
  13. package/dist/types.d.cts.map +1 -0
  14. package/dist/types.d.mts +16 -0
  15. package/dist/types.d.mts.map +1 -0
  16. package/dist/types.mjs +2 -0
  17. package/dist/types.mjs.map +1 -0
  18. package/dist/utils.cjs +1 -97
  19. package/dist/utils.cjs.map +1 -1
  20. package/dist/utils.d.cts +0 -25
  21. package/dist/utils.d.cts.map +1 -1
  22. package/dist/utils.d.mts +0 -25
  23. package/dist/utils.d.mts.map +1 -1
  24. package/dist/utils.mjs +0 -94
  25. package/dist/utils.mjs.map +1 -1
  26. package/package.json +1 -1
  27. package/dist/PersonalMessageManager.cjs +0 -58
  28. package/dist/PersonalMessageManager.cjs.map +0 -1
  29. package/dist/PersonalMessageManager.d.cts +0 -72
  30. package/dist/PersonalMessageManager.d.cts.map +0 -1
  31. package/dist/PersonalMessageManager.d.mts +0 -72
  32. package/dist/PersonalMessageManager.d.mts.map +0 -1
  33. package/dist/PersonalMessageManager.mjs +0 -54
  34. package/dist/PersonalMessageManager.mjs.map +0 -1
  35. package/dist/TypedMessageManager.cjs +0 -87
  36. package/dist/TypedMessageManager.cjs.map +0 -1
  37. package/dist/TypedMessageManager.d.cts +0 -98
  38. package/dist/TypedMessageManager.d.cts.map +0 -1
  39. package/dist/TypedMessageManager.d.mts +0 -98
  40. package/dist/TypedMessageManager.d.mts.map +0 -1
  41. package/dist/TypedMessageManager.mjs +0 -83
  42. package/dist/TypedMessageManager.mjs.map +0 -1
@@ -1,72 +0,0 @@
1
- import type { SIWEMessage } from "@metamask/controller-utils";
2
- import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest } from "./AbstractMessageManager.cjs";
3
- import { AbstractMessageManager } from "./AbstractMessageManager.cjs";
4
- /**
5
- * @type Message
6
- *
7
- * Represents and contains data about a 'personal_sign' type signature request.
8
- * These are created when a signature for a personal_sign call is requested.
9
- * @property id - An id to track and identify the message object
10
- * @property messageParams - The parameters to pass to the personal_sign method once the signature request is approved
11
- * @property type - The json-prc signing method for which a signature request has been made.
12
- * A 'Message' which always has a 'personal_sign' type
13
- * @property rawSig - Raw data of the signature request
14
- */
15
- export interface PersonalMessage extends AbstractMessage {
16
- messageParams: PersonalMessageParams;
17
- }
18
- /**
19
- * @type PersonalMessageParams
20
- *
21
- * Represents the parameters to pass to the personal_sign method once the signature request is approved.
22
- * @property data - A hex string conversion of the raw buffer data of the signature request
23
- * @property from - Address to sign this message from
24
- * @property origin? - Added for request origin identification
25
- */
26
- export interface PersonalMessageParams extends AbstractMessageParams {
27
- data: string;
28
- siwe?: SIWEMessage;
29
- }
30
- /**
31
- * @type MessageParamsMetamask
32
- *
33
- * Represents the parameters to pass to the personal_sign method once the signature request is approved
34
- * plus data added by MetaMask.
35
- * @property metamaskId - Added for tracking and identification within MetaMask
36
- * @property data - A hex string conversion of the raw buffer data of the signature request
37
- * @property from - Address to sign this message from
38
- * @property origin? - Added for request origin identification
39
- */
40
- export interface PersonalMessageParamsMetamask extends AbstractMessageParamsMetamask {
41
- data: string;
42
- }
43
- /**
44
- * Controller in charge of managing - storing, adding, removing, updating - Messages.
45
- */
46
- export declare class PersonalMessageManager extends AbstractMessageManager<PersonalMessage, PersonalMessageParams, PersonalMessageParamsMetamask> {
47
- /**
48
- * Name of this controller used during composition
49
- */
50
- name: "PersonalMessageManager";
51
- /**
52
- * Creates a new Message with an 'unapproved' status using the passed messageParams.
53
- * this.addMessage is called to add the new Message to this.messages, and to save the
54
- * unapproved Messages.
55
- *
56
- * @param messageParams - The params for the personal_sign call to be made after the message
57
- * is approved.
58
- * @param req - The original request object possibly containing the origin.
59
- * @returns The id of the newly created message.
60
- */
61
- addUnapprovedMessage(messageParams: PersonalMessageParams, req?: OriginalRequest): Promise<string>;
62
- /**
63
- * Removes the metamaskId property from passed messageParams and returns a promise which
64
- * resolves the updated messageParams.
65
- *
66
- * @param messageParams - The messageParams to modify.
67
- * @returns Promise resolving to the messageParams with the metamaskId property removed.
68
- */
69
- prepMessageForSigning(messageParams: PersonalMessageParamsMetamask): Promise<PersonalMessageParams>;
70
- }
71
- export default PersonalMessageManager;
72
- //# sourceMappingURL=PersonalMessageManager.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PersonalMessageManager.d.cts","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,mCAAmC;AAG9D,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE;;;;;;;;;;GAUG;AAIH,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,aAAa,EAAE,qBAAqB,CAAC;CACtC;AAED;;;;;;;GAOG;AAIH,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;;;;;;;GASG;AAIH,MAAM,WAAW,6BACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB,CAChE,eAAe,EACf,qBAAqB,EACrB,6BAA6B,CAC9B;IACC;;OAEG;IACM,IAAI,2BAAqC;IAElD;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,qBAAqB,EACpC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA2BlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,6BAA6B,GAC3C,OAAO,CAAC,qBAAqB,CAAC;CAMlC;AAED,eAAe,sBAAsB,CAAC"}
@@ -1,72 +0,0 @@
1
- import type { SIWEMessage } from "@metamask/controller-utils";
2
- import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest } from "./AbstractMessageManager.mjs";
3
- import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
4
- /**
5
- * @type Message
6
- *
7
- * Represents and contains data about a 'personal_sign' type signature request.
8
- * These are created when a signature for a personal_sign call is requested.
9
- * @property id - An id to track and identify the message object
10
- * @property messageParams - The parameters to pass to the personal_sign method once the signature request is approved
11
- * @property type - The json-prc signing method for which a signature request has been made.
12
- * A 'Message' which always has a 'personal_sign' type
13
- * @property rawSig - Raw data of the signature request
14
- */
15
- export interface PersonalMessage extends AbstractMessage {
16
- messageParams: PersonalMessageParams;
17
- }
18
- /**
19
- * @type PersonalMessageParams
20
- *
21
- * Represents the parameters to pass to the personal_sign method once the signature request is approved.
22
- * @property data - A hex string conversion of the raw buffer data of the signature request
23
- * @property from - Address to sign this message from
24
- * @property origin? - Added for request origin identification
25
- */
26
- export interface PersonalMessageParams extends AbstractMessageParams {
27
- data: string;
28
- siwe?: SIWEMessage;
29
- }
30
- /**
31
- * @type MessageParamsMetamask
32
- *
33
- * Represents the parameters to pass to the personal_sign method once the signature request is approved
34
- * plus data added by MetaMask.
35
- * @property metamaskId - Added for tracking and identification within MetaMask
36
- * @property data - A hex string conversion of the raw buffer data of the signature request
37
- * @property from - Address to sign this message from
38
- * @property origin? - Added for request origin identification
39
- */
40
- export interface PersonalMessageParamsMetamask extends AbstractMessageParamsMetamask {
41
- data: string;
42
- }
43
- /**
44
- * Controller in charge of managing - storing, adding, removing, updating - Messages.
45
- */
46
- export declare class PersonalMessageManager extends AbstractMessageManager<PersonalMessage, PersonalMessageParams, PersonalMessageParamsMetamask> {
47
- /**
48
- * Name of this controller used during composition
49
- */
50
- name: "PersonalMessageManager";
51
- /**
52
- * Creates a new Message with an 'unapproved' status using the passed messageParams.
53
- * this.addMessage is called to add the new Message to this.messages, and to save the
54
- * unapproved Messages.
55
- *
56
- * @param messageParams - The params for the personal_sign call to be made after the message
57
- * is approved.
58
- * @param req - The original request object possibly containing the origin.
59
- * @returns The id of the newly created message.
60
- */
61
- addUnapprovedMessage(messageParams: PersonalMessageParams, req?: OriginalRequest): Promise<string>;
62
- /**
63
- * Removes the metamaskId property from passed messageParams and returns a promise which
64
- * resolves the updated messageParams.
65
- *
66
- * @param messageParams - The messageParams to modify.
67
- * @returns Promise resolving to the messageParams with the metamaskId property removed.
68
- */
69
- prepMessageForSigning(messageParams: PersonalMessageParamsMetamask): Promise<PersonalMessageParams>;
70
- }
71
- export default PersonalMessageManager;
72
- //# sourceMappingURL=PersonalMessageManager.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PersonalMessageManager.d.mts","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,mCAAmC;AAG9D,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE;;;;;;;;;;GAUG;AAIH,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,aAAa,EAAE,qBAAqB,CAAC;CACtC;AAED;;;;;;;GAOG;AAIH,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;;;;;;;GASG;AAIH,MAAM,WAAW,6BACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB,CAChE,eAAe,EACf,qBAAqB,EACrB,6BAA6B,CAC9B;IACC;;OAEG;IACM,IAAI,2BAAqC;IAElD;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,qBAAqB,EACpC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA2BlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,6BAA6B,GAC3C,OAAO,CAAC,qBAAqB,CAAC;CAMlC;AAED,eAAe,sBAAsB,CAAC"}
@@ -1,54 +0,0 @@
1
- import { detectSIWE, ApprovalType } from "@metamask/controller-utils";
2
- import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
3
- import { normalizeMessageData, validateSignMessageData } from "./utils.mjs";
4
- /**
5
- * Controller in charge of managing - storing, adding, removing, updating - Messages.
6
- */
7
- export class PersonalMessageManager extends AbstractMessageManager {
8
- constructor() {
9
- super(...arguments);
10
- /**
11
- * Name of this controller used during composition
12
- */
13
- this.name = 'PersonalMessageManager';
14
- }
15
- /**
16
- * Creates a new Message with an 'unapproved' status using the passed messageParams.
17
- * this.addMessage is called to add the new Message to this.messages, and to save the
18
- * unapproved Messages.
19
- *
20
- * @param messageParams - The params for the personal_sign call to be made after the message
21
- * is approved.
22
- * @param req - The original request object possibly containing the origin.
23
- * @returns The id of the newly created message.
24
- */
25
- async addUnapprovedMessage(messageParams, req) {
26
- validateSignMessageData(messageParams);
27
- const ethereumSignInData = detectSIWE(messageParams);
28
- const updatedMessageParams = this.addRequestToMessageParams(messageParams, req);
29
- updatedMessageParams.data = normalizeMessageData(messageParams.data);
30
- updatedMessageParams.siwe = ethereumSignInData;
31
- const messageData = this.createUnapprovedMessage(updatedMessageParams, ApprovalType.PersonalSign, req);
32
- const messageId = messageData.id;
33
- await this.addMessage(messageData);
34
- this.hub.emit(`unapprovedMessage`, {
35
- ...updatedMessageParams,
36
- metamaskId: messageId,
37
- });
38
- return messageId;
39
- }
40
- /**
41
- * Removes the metamaskId property from passed messageParams and returns a promise which
42
- * resolves the updated messageParams.
43
- *
44
- * @param messageParams - The messageParams to modify.
45
- * @returns Promise resolving to the messageParams with the metamaskId property removed.
46
- */
47
- prepMessageForSigning(messageParams) {
48
- // Using delete operation will throw an error on frozen messageParams
49
- const { metamaskId: _metamaskId, ...messageParamsWithoutId } = messageParams;
50
- return Promise.resolve(messageParamsWithoutId);
51
- }
52
- }
53
- export default PersonalMessageManager;
54
- //# sourceMappingURL=PersonalMessageManager.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PersonalMessageManager.mjs","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,mCAAmC;AAQtE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,oBAAgB;AAsDxE;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,sBAI3C;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,wBAAiC,CAAC;IAyDpD,CAAC;IAvDC;;;;;;;;;OASG;IACH,KAAK,CAAC,oBAAoB,CACxB,aAAoC,EACpC,GAAqB;QAErB,uBAAuB,CAAC,aAAa,CAAC,CAAC;QAEvC,MAAM,kBAAkB,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;QACrD,MAAM,oBAAoB,GAAG,IAAI,CAAC,yBAAyB,CACzD,aAAa,EACb,GAAG,CAC4B,CAAC;QAElC,oBAAoB,CAAC,IAAI,GAAG,oBAAoB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACrE,oBAAoB,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAE/C,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAC9C,oBAAoB,EACpB,YAAY,CAAC,YAAY,EACzB,GAAG,CACsB,CAAC;QAE5B,MAAM,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACnC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE;YACjC,GAAG,oBAAoB;YACvB,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAA4C;QAE5C,qEAAqE;QACrE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,sBAAsB,EAAE,GAC1D,aAAa,CAAC;QAChB,OAAO,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACjD,CAAC;CACF;AAED,eAAe,sBAAsB,CAAC","sourcesContent":["import type { SIWEMessage } from '@metamask/controller-utils';\nimport { detectSIWE, ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { normalizeMessageData, validateSignMessageData } from './utils';\n\n/**\n * @type Message\n *\n * Represents and contains data about a 'personal_sign' type signature request.\n * These are created when a signature for a personal_sign call is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the personal_sign method once the signature request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'Message' which always has a 'personal_sign' type\n * @property rawSig - Raw data of the signature request\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface PersonalMessage extends AbstractMessage {\n messageParams: PersonalMessageParams;\n}\n\n/**\n * @type PersonalMessageParams\n *\n * Represents the parameters to pass to the personal_sign method once the signature request is approved.\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface PersonalMessageParams extends AbstractMessageParams {\n data: string;\n siwe?: SIWEMessage;\n}\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the personal_sign method once the signature request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface PersonalMessageParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport class PersonalMessageManager extends AbstractMessageManager<\n PersonalMessage,\n PersonalMessageParams,\n PersonalMessageParamsMetamask\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'PersonalMessageManager' as const;\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\n const ethereumSignInData = detectSIWE(messageParams);\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies PersonalMessageParams;\n\n updatedMessageParams.data = normalizeMessageData(messageParams.data);\n updatedMessageParams.siwe = ethereumSignInData;\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.PersonalSign,\n req,\n ) satisfies PersonalMessage;\n\n const messageId = messageData.id;\n await this.addMessage(messageData);\n this.hub.emit(`unapprovedMessage`, {\n ...updatedMessageParams,\n metamaskId: messageId,\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: 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,87 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypedMessageManager = void 0;
4
- const controller_utils_1 = require("@metamask/controller-utils");
5
- const AbstractMessageManager_1 = require("./AbstractMessageManager.cjs");
6
- const utils_1 = require("./utils.cjs");
7
- /**
8
- * Controller in charge of managing - storing, adding, removing, updating - TypedMessages.
9
- */
10
- class TypedMessageManager extends AbstractMessageManager_1.AbstractMessageManager {
11
- constructor() {
12
- super(...arguments);
13
- /**
14
- * Name of this controller used during composition
15
- */
16
- this.name = 'TypedMessageManager';
17
- }
18
- /**
19
- * Creates a new TypedMessage with an 'unapproved' status using the passed messageParams.
20
- * this.addMessage is called to add the new TypedMessage to this.messages, and to save the
21
- * unapproved TypedMessages.
22
- *
23
- * @param messageParams - The params for the 'eth_signTypedData' call to be made after the message
24
- * is approved.
25
- * @param req - The original request object possibly containing the origin.
26
- * @param version - Compatibility version EIP712.
27
- * @returns The id of the newly created TypedMessage.
28
- */
29
- async addUnapprovedMessage(messageParams, req, version) {
30
- if (version === 'V1') {
31
- (0, utils_1.validateTypedSignMessageDataV1)(messageParams);
32
- }
33
- if (version === 'V3' || version === 'V4') {
34
- const currentChainId = this.getCurrentChainId?.();
35
- (0, utils_1.validateTypedSignMessageDataV3V4)(messageParams, currentChainId);
36
- }
37
- if (typeof messageParams.data !== 'string' &&
38
- (version === 'V3' || version === 'V4')) {
39
- messageParams.data = JSON.stringify(messageParams.data);
40
- }
41
- const updatedMessageParams = this.addRequestToMessageParams(messageParams, req);
42
- const messageData = this.createUnapprovedMessage(updatedMessageParams, controller_utils_1.ApprovalType.EthSignTypedData, req);
43
- const messageId = messageData.id;
44
- await this.addMessage(messageData);
45
- /**
46
- * This intentionally splays messageParams rather than updatedMessageParams. I'm unsure if this
47
- * is exactly what we want, but I am preserving existing logic.
48
- */
49
- this.hub.emit(`unapprovedMessage`, {
50
- ...messageParams,
51
- metamaskId: messageId,
52
- version,
53
- });
54
- return messageId;
55
- }
56
- /**
57
- * Sets a TypedMessage status to 'errored' via a call to this.setMessageStatus.
58
- *
59
- * @param messageId - The id of the TypedMessage to error.
60
- * @param error - The error to be included in TypedMessage.
61
- */
62
- setMessageStatusErrored(messageId, error) {
63
- const message = this.getMessage(messageId);
64
- /* istanbul ignore if */
65
- if (!message) {
66
- return;
67
- }
68
- message.error = error;
69
- this.updateMessage(message);
70
- this.setMessageStatus(messageId, 'errored');
71
- }
72
- /**
73
- * Removes the metamaskId and version properties from passed messageParams and returns a promise which
74
- * resolves the updated messageParams.
75
- *
76
- * @param messageParams - The messageParams to modify.
77
- * @returns Promise resolving to the messageParams with the metamaskId and version properties removed.
78
- */
79
- prepMessageForSigning(messageParams) {
80
- // Using delete operation will throw an error on frozen messageParams
81
- const { metamaskId: _metamaskId, version: _version, ...messageParamsWithoutId } = messageParams;
82
- return Promise.resolve(messageParamsWithoutId);
83
- }
84
- }
85
- exports.TypedMessageManager = TypedMessageManager;
86
- exports.default = TypedMessageManager;
87
- //# sourceMappingURL=TypedMessageManager.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TypedMessageManager.cjs","sourceRoot":"","sources":["../src/TypedMessageManager.ts"],"names":[],"mappings":";;;AAAA,iEAA0D;AAQ1D,yEAAkE;AAClE,uCAGiB;AA0EjB;;GAEG;AACH,MAAa,mBAAoB,SAAQ,+CAIxC;IAJD;;QAKE;;WAEG;QAC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,CAAC,OAAO,EAAE;YACZ,OAAO;SACR;QACD,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAyC;QAEzC,qEAAqE;QACrE,MAAM,EACJ,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,QAAQ,EACjB,GAAG,sBAAsB,EAC1B,GAAG,aAAa,CAAC;QAClB,OAAO,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACjD,CAAC;CACF;AAzGD,kDAyGC;AAED,kBAAe,mBAAmB,CAAC","sourcesContent":["import { ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport {\n validateTypedSignMessageDataV1,\n validateTypedSignMessageDataV3V4,\n} from './utils';\n\n/**\n * @type TypedMessage\n *\n * Represents and contains data about an 'eth_signTypedData' type signature request.\n * These are created when a signature for an eth_signTypedData call is requested.\n * @property id - An id to track and identify the message object\n * @property error - Error corresponding to eth_signTypedData error in failure case\n * @property messageParams - The parameters to pass to the eth_signTypedData method once\n * the signature request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'TypedMessage' which always has a 'eth_signTypedData' type\n * @property rawSig - Raw data of the signature request\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface TypedMessage extends AbstractMessage {\n error?: string;\n messageParams: TypedMessageParams;\n time: number;\n status: string;\n type: string;\n rawSig?: string;\n}\n\nexport type SignTypedDataMessageV3V4 = {\n types: Record<string, unknown>;\n domain: Record<string, unknown>;\n primaryType: string;\n message: unknown;\n};\n\n/**\n * @type TypedMessageParams\n *\n * Represents the parameters to pass to the eth_signTypedData method once the signature request is approved.\n * @property data - A hex string conversion of the raw buffer or an object containing data of the signature\n * request depending on version\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface TypedMessageParams extends AbstractMessageParams {\n data: Record<string, unknown>[] | string | SignTypedDataMessageV3V4;\n}\n\n/**\n * @type TypedMessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_signTypedData method once the signature request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - A hex string conversion of the raw buffer or an object containing data of the signature\n * request depending on version\n * @property error? - Added for message errored\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n * @property version - Compatibility version EIP712\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface TypedMessageParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: TypedMessageParams['data'];\n metamaskId?: string;\n error?: string;\n version?: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - TypedMessages.\n */\nexport class TypedMessageManager extends AbstractMessageManager<\n TypedMessage,\n TypedMessageParams,\n TypedMessageParamsMetamask\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'TypedMessageManager' as const;\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 updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies TypedMessageParams;\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthSignTypedData,\n req,\n ) satisfies TypedMessage;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n\n /**\n * This intentionally splays messageParams rather than updatedMessageParams. I'm unsure if this\n * is exactly what we want, but I am preserving existing logic.\n */\n this.hub.emit(`unapprovedMessage`, {\n ...messageParams,\n metamaskId: messageId,\n version,\n });\n\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"]}
@@ -1,98 +0,0 @@
1
- import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest } from "./AbstractMessageManager.cjs";
2
- import { AbstractMessageManager } from "./AbstractMessageManager.cjs";
3
- /**
4
- * @type TypedMessage
5
- *
6
- * Represents and contains data about an 'eth_signTypedData' type signature request.
7
- * These are created when a signature for an eth_signTypedData call is requested.
8
- * @property id - An id to track and identify the message object
9
- * @property error - Error corresponding to eth_signTypedData error in failure case
10
- * @property messageParams - The parameters to pass to the eth_signTypedData method once
11
- * the signature request is approved
12
- * @property type - The json-prc signing method for which a signature request has been made.
13
- * A 'TypedMessage' which always has a 'eth_signTypedData' type
14
- * @property rawSig - Raw data of the signature request
15
- */
16
- export interface TypedMessage extends AbstractMessage {
17
- error?: string;
18
- messageParams: TypedMessageParams;
19
- time: number;
20
- status: string;
21
- type: string;
22
- rawSig?: string;
23
- }
24
- export type SignTypedDataMessageV3V4 = {
25
- types: Record<string, unknown>;
26
- domain: Record<string, unknown>;
27
- primaryType: string;
28
- message: unknown;
29
- };
30
- /**
31
- * @type TypedMessageParams
32
- *
33
- * Represents the parameters to pass to the eth_signTypedData method once the signature request is approved.
34
- * @property data - A hex string conversion of the raw buffer or an object containing data of the signature
35
- * request depending on version
36
- * @property from - Address to sign this message from
37
- * @property origin? - Added for request origin identification
38
- */
39
- export interface TypedMessageParams extends AbstractMessageParams {
40
- data: Record<string, unknown>[] | string | SignTypedDataMessageV3V4;
41
- }
42
- /**
43
- * @type TypedMessageParamsMetamask
44
- *
45
- * Represents the parameters to pass to the eth_signTypedData method once the signature request is approved
46
- * plus data added by MetaMask.
47
- * @property metamaskId - Added for tracking and identification within MetaMask
48
- * @property data - A hex string conversion of the raw buffer or an object containing data of the signature
49
- * request depending on version
50
- * @property error? - Added for message errored
51
- * @property from - Address to sign this message from
52
- * @property origin? - Added for request origin identification
53
- * @property version - Compatibility version EIP712
54
- */
55
- export interface TypedMessageParamsMetamask extends AbstractMessageParamsMetamask {
56
- data: TypedMessageParams['data'];
57
- metamaskId?: string;
58
- error?: string;
59
- version?: string;
60
- }
61
- /**
62
- * Controller in charge of managing - storing, adding, removing, updating - TypedMessages.
63
- */
64
- export declare class TypedMessageManager extends AbstractMessageManager<TypedMessage, TypedMessageParams, TypedMessageParamsMetamask> {
65
- /**
66
- * Name of this controller used during composition
67
- */
68
- name: "TypedMessageManager";
69
- /**
70
- * Creates a new TypedMessage with an 'unapproved' status using the passed messageParams.
71
- * this.addMessage is called to add the new TypedMessage to this.messages, and to save the
72
- * unapproved TypedMessages.
73
- *
74
- * @param messageParams - The params for the 'eth_signTypedData' call to be made after the message
75
- * is approved.
76
- * @param req - The original request object possibly containing the origin.
77
- * @param version - Compatibility version EIP712.
78
- * @returns The id of the newly created TypedMessage.
79
- */
80
- addUnapprovedMessage(messageParams: TypedMessageParams, req?: OriginalRequest, version?: string): Promise<string>;
81
- /**
82
- * Sets a TypedMessage status to 'errored' via a call to this.setMessageStatus.
83
- *
84
- * @param messageId - The id of the TypedMessage to error.
85
- * @param error - The error to be included in TypedMessage.
86
- */
87
- setMessageStatusErrored(messageId: string, error: string): void;
88
- /**
89
- * Removes the metamaskId and version properties from passed messageParams and returns a promise which
90
- * resolves the updated messageParams.
91
- *
92
- * @param messageParams - The messageParams to modify.
93
- * @returns Promise resolving to the messageParams with the metamaskId and version properties removed.
94
- */
95
- prepMessageForSigning(messageParams: TypedMessageParamsMetamask): Promise<TypedMessageParams>;
96
- }
97
- export default TypedMessageManager;
98
- //# sourceMappingURL=TypedMessageManager.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TypedMessageManager.d.cts","sourceRoot":"","sources":["../src/TypedMessageManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAMlE;;;;;;;;;;;;GAYG;AAIH,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,kBAAkB,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC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stractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest } from "./AbstractMessageManager.mjs";
2
- import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
3
- /**
4
- * @type TypedMessage
5
- *
6
- * Represents and contains data about an 'eth_signTypedData' type signature request.
7
- * These are created when a signature for an eth_signTypedData call is requested.
8
- * @property id - An id to track and identify the message object
9
- * @property error - Error corresponding to eth_signTypedData error in failure case
10
- * @property messageParams - The parameters to pass to the eth_signTypedData method once
11
- * the signature request is approved
12
- * @property type - The json-prc signing method for which a signature request has been made.
13
- * A 'TypedMessage' which always has a 'eth_signTypedData' type
14
- * @property rawSig - Raw data of the signature request
15
- */
16
- export interface TypedMessage extends AbstractMessage {
17
- error?: string;
18
- messageParams: TypedMessageParams;
19
- time: number;
20
- status: string;
21
- type: string;
22
- rawSig?: string;
23
- }
24
- export type SignTypedDataMessageV3V4 = {
25
- types: Record<string, unknown>;
26
- domain: Record<string, unknown>;
27
- primaryType: string;
28
- message: unknown;
29
- };
30
- /**
31
- * @type TypedMessageParams
32
- *
33
- * Represents the parameters to pass to the eth_signTypedData method once the signature request is approved.
34
- * @property data - A hex string conversion of the raw buffer or an object containing data of the signature
35
- * request depending on version
36
- * @property from - Address to sign this message from
37
- * @property origin? - Added for request origin identification
38
- */
39
- export interface TypedMessageParams extends AbstractMessageParams {
40
- data: Record<string, unknown>[] | string | SignTypedDataMessageV3V4;
41
- }
42
- /**
43
- * @type TypedMessageParamsMetamask
44
- *
45
- * Represents the parameters to pass to the eth_signTypedData method once the signature request is approved
46
- * plus data added by MetaMask.
47
- * @property metamaskId - Added for tracking and identification within MetaMask
48
- * @property data - A hex string conversion of the raw buffer or an object containing data of the signature
49
- * request depending on version
50
- * @property error? - Added for message errored
51
- * @property from - Address to sign this message from
52
- * @property origin? - Added for request origin identification
53
- * @property version - Compatibility version EIP712
54
- */
55
- export interface TypedMessageParamsMetamask extends AbstractMessageParamsMetamask {
56
- data: TypedMessageParams['data'];
57
- metamaskId?: string;
58
- error?: string;
59
- version?: string;
60
- }
61
- /**
62
- * Controller in charge of managing - storing, adding, removing, updating - TypedMessages.
63
- */
64
- export declare class TypedMessageManager extends AbstractMessageManager<TypedMessage, TypedMessageParams, TypedMessageParamsMetamask> {
65
- /**
66
- * Name of this controller used during composition
67
- */
68
- name: "TypedMessageManager";
69
- /**
70
- * Creates a new TypedMessage with an 'unapproved' status using the passed messageParams.
71
- * this.addMessage is called to add the new TypedMessage to this.messages, and to save the
72
- * unapproved TypedMessages.
73
- *
74
- * @param messageParams - The params for the 'eth_signTypedData' call to be made after the message
75
- * is approved.
76
- * @param req - The original request object possibly containing the origin.
77
- * @param version - Compatibility version EIP712.
78
- * @returns The id of the newly created TypedMessage.
79
- */
80
- addUnapprovedMessage(messageParams: TypedMessageParams, req?: OriginalRequest, version?: string): Promise<string>;
81
- /**
82
- * Sets a TypedMessage status to 'errored' via a call to this.setMessageStatus.
83
- *
84
- * @param messageId - The id of the TypedMessage to error.
85
- * @param error - The error to be included in TypedMessage.
86
- */
87
- setMessageStatusErrored(messageId: string, error: string): void;
88
- /**
89
- * Removes the metamaskId and version properties from passed messageParams and returns a promise which
90
- * resolves the updated messageParams.
91
- *
92
- * @param messageParams - The messageParams to modify.
93
- * @returns Promise resolving to the messageParams with the metamaskId and version properties removed.
94
- */
95
- prepMessageForSigning(messageParams: TypedMessageParamsMetamask): Promise<TypedMessageParams>;
96
- }
97
- export default TypedMessageManager;
98
- //# sourceMappingURL=TypedMessageManager.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TypedMessageManager.d.mts","sourceRoot":"","sources":["../src/TypedMessageManager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAMlE;;;;;;;;;;;;GAYG;AAIH,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,KAAK,CAAC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,kBAAkB,CAAC;CAS/B;AAED,eAAe,mBAAmB,CAAC"}
@@ -1,83 +0,0 @@
1
- import { ApprovalType } from "@metamask/controller-utils";
2
- import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
3
- import { validateTypedSignMessageDataV1, validateTypedSignMessageDataV3V4 } from "./utils.mjs";
4
- /**
5
- * Controller in charge of managing - storing, adding, removing, updating - TypedMessages.
6
- */
7
- export class TypedMessageManager extends AbstractMessageManager {
8
- constructor() {
9
- super(...arguments);
10
- /**
11
- * Name of this controller used during composition
12
- */
13
- this.name = 'TypedMessageManager';
14
- }
15
- /**
16
- * Creates a new TypedMessage with an 'unapproved' status using the passed messageParams.
17
- * this.addMessage is called to add the new TypedMessage to this.messages, and to save the
18
- * unapproved TypedMessages.
19
- *
20
- * @param messageParams - The params for the 'eth_signTypedData' call to be made after the message
21
- * is approved.
22
- * @param req - The original request object possibly containing the origin.
23
- * @param version - Compatibility version EIP712.
24
- * @returns The id of the newly created TypedMessage.
25
- */
26
- async addUnapprovedMessage(messageParams, req, version) {
27
- if (version === 'V1') {
28
- validateTypedSignMessageDataV1(messageParams);
29
- }
30
- if (version === 'V3' || version === 'V4') {
31
- const currentChainId = this.getCurrentChainId?.();
32
- validateTypedSignMessageDataV3V4(messageParams, currentChainId);
33
- }
34
- if (typeof messageParams.data !== 'string' &&
35
- (version === 'V3' || version === 'V4')) {
36
- messageParams.data = JSON.stringify(messageParams.data);
37
- }
38
- const updatedMessageParams = this.addRequestToMessageParams(messageParams, req);
39
- const messageData = this.createUnapprovedMessage(updatedMessageParams, ApprovalType.EthSignTypedData, req);
40
- const messageId = messageData.id;
41
- await this.addMessage(messageData);
42
- /**
43
- * This intentionally splays messageParams rather than updatedMessageParams. I'm unsure if this
44
- * is exactly what we want, but I am preserving existing logic.
45
- */
46
- this.hub.emit(`unapprovedMessage`, {
47
- ...messageParams,
48
- metamaskId: messageId,
49
- version,
50
- });
51
- return messageId;
52
- }
53
- /**
54
- * Sets a TypedMessage status to 'errored' via a call to this.setMessageStatus.
55
- *
56
- * @param messageId - The id of the TypedMessage to error.
57
- * @param error - The error to be included in TypedMessage.
58
- */
59
- setMessageStatusErrored(messageId, error) {
60
- const message = this.getMessage(messageId);
61
- /* istanbul ignore if */
62
- if (!message) {
63
- return;
64
- }
65
- message.error = error;
66
- this.updateMessage(message);
67
- this.setMessageStatus(messageId, 'errored');
68
- }
69
- /**
70
- * Removes the metamaskId and version properties from passed messageParams and returns a promise which
71
- * resolves the updated messageParams.
72
- *
73
- * @param messageParams - The messageParams to modify.
74
- * @returns Promise resolving to the messageParams with the metamaskId and version properties removed.
75
- */
76
- prepMessageForSigning(messageParams) {
77
- // Using delete operation will throw an error on frozen messageParams
78
- const { metamaskId: _metamaskId, version: _version, ...messageParamsWithoutId } = messageParams;
79
- return Promise.resolve(messageParamsWithoutId);
80
- }
81
- }
82
- export default TypedMessageManager;
83
- //# sourceMappingURL=TypedMessageManager.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TypedMessageManager.mjs","sourceRoot":"","sources":["../src/TypedMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAQ1D,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EACL,8BAA8B,EAC9B,gCAAgC,EACjC,oBAAgB;AA0EjB;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,sBAIxC;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,qBAA8B,CAAC;IAiGjD,CAAC;IA/FC;;;;;;;;;;OAUG;IACH,KAAK,CAAC,oBAAoB,CACxB,aAAiC,EACjC,GAAqB,EACrB,OAAgB;QAEhB,IAAI,OAAO,KAAK,IAAI,EAAE;YACpB,8BAA8B,CAAC,aAAa,CAAC,CAAC;SAC/C;QAED,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,IAAI,EAAE;YACxC,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,EAAE,EAAE,CA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1B,GAAG,aAAa,CAAC;QAClB,OAAO,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACjD,CAAC;CACF;AAED,eAAe,mBAAmB,CAAC","sourcesContent":["import { ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport {\n validateTypedSignMessageDataV1,\n validateTypedSignMessageDataV3V4,\n} from './utils';\n\n/**\n * @type TypedMessage\n *\n * Represents and contains data about an 'eth_signTypedData' type signature request.\n * These are created when a signature for an eth_signTypedData call is requested.\n * @property id - An id to track and identify the message object\n * @property error - Error corresponding to eth_signTypedData error in failure case\n * @property messageParams - The parameters to pass to the eth_signTypedData method once\n * the signature request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'TypedMessage' which always has a 'eth_signTypedData' type\n * @property rawSig - Raw data of the signature request\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface TypedMessage extends AbstractMessage {\n error?: string;\n messageParams: TypedMessageParams;\n time: number;\n status: string;\n type: string;\n rawSig?: string;\n}\n\nexport type SignTypedDataMessageV3V4 = {\n types: Record<string, unknown>;\n domain: Record<string, unknown>;\n primaryType: string;\n message: unknown;\n};\n\n/**\n * @type TypedMessageParams\n *\n * Represents the parameters to pass to the eth_signTypedData method once the signature request is approved.\n * @property data - A hex string conversion of the raw buffer or an object containing data of the signature\n * request depending on version\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface TypedMessageParams extends AbstractMessageParams {\n data: Record<string, unknown>[] | string | SignTypedDataMessageV3V4;\n}\n\n/**\n * @type TypedMessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_signTypedData method once the signature request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - A hex string conversion of the raw buffer or an object containing data of the signature\n * request depending on version\n * @property error? - Added for message errored\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n * @property version - Compatibility version EIP712\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface TypedMessageParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: TypedMessageParams['data'];\n metamaskId?: string;\n error?: string;\n version?: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - TypedMessages.\n */\nexport class TypedMessageManager extends AbstractMessageManager<\n TypedMessage,\n TypedMessageParams,\n TypedMessageParamsMetamask\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'TypedMessageManager' as const;\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 updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies TypedMessageParams;\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthSignTypedData,\n req,\n ) satisfies TypedMessage;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n\n /**\n * This intentionally splays messageParams rather than updatedMessageParams. I'm unsure if this\n * is exactly what we want, but I am preserving existing logic.\n */\n this.hub.emit(`unapprovedMessage`, {\n ...messageParams,\n metamaskId: messageId,\n version,\n });\n\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"]}