@metamask-previews/message-manager 7.3.0-preview.d32a7cc

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 (36) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/LICENSE +20 -0
  3. package/README.md +15 -0
  4. package/dist/AbstractMessageManager.d.ts +258 -0
  5. package/dist/AbstractMessageManager.d.ts.map +1 -0
  6. package/dist/AbstractMessageManager.js +294 -0
  7. package/dist/AbstractMessageManager.js.map +1 -0
  8. package/dist/DecryptMessageManager.d.ts +75 -0
  9. package/dist/DecryptMessageManager.d.ts.map +1 -0
  10. package/dist/DecryptMessageManager.js +97 -0
  11. package/dist/DecryptMessageManager.js.map +1 -0
  12. package/dist/EncryptionPublicKeyManager.d.ts +76 -0
  13. package/dist/EncryptionPublicKeyManager.d.ts.map +1 -0
  14. package/dist/EncryptionPublicKeyManager.js +95 -0
  15. package/dist/EncryptionPublicKeyManager.js.map +1 -0
  16. package/dist/MessageManager.d.ts +70 -0
  17. package/dist/MessageManager.d.ts.map +1 -0
  18. package/dist/MessageManager.js +72 -0
  19. package/dist/MessageManager.js.map +1 -0
  20. package/dist/PersonalMessageManager.d.ts +72 -0
  21. package/dist/PersonalMessageManager.d.ts.map +1 -0
  22. package/dist/PersonalMessageManager.js +75 -0
  23. package/dist/PersonalMessageManager.js.map +1 -0
  24. package/dist/TypedMessageManager.d.ts +98 -0
  25. package/dist/TypedMessageManager.d.ts.map +1 -0
  26. package/dist/TypedMessageManager.js +101 -0
  27. package/dist/TypedMessageManager.js.map +1 -0
  28. package/dist/index.d.ts +7 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +23 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/utils.d.ts +51 -0
  33. package/dist/utils.d.ts.map +1 -0
  34. package/dist/utils.js +145 -0
  35. package/dist/utils.js.map +1 -0
  36. package/package.json +57 -0
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EncryptionPublicKeyManager = void 0;
13
+ const uuid_1 = require("uuid");
14
+ const AbstractMessageManager_1 = require("./AbstractMessageManager");
15
+ const utils_1 = require("./utils");
16
+ /**
17
+ * Controller in charge of managing - storing, adding, removing, updating - Messages.
18
+ */
19
+ class EncryptionPublicKeyManager extends AbstractMessageManager_1.AbstractMessageManager {
20
+ constructor() {
21
+ super(...arguments);
22
+ /**
23
+ * Name of this controller used during composition
24
+ */
25
+ this.name = 'EncryptionPublicKeyManager';
26
+ }
27
+ /**
28
+ * Creates a new Message with an 'unapproved' status using the passed messageParams.
29
+ * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.
30
+ *
31
+ * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message is approved.
32
+ * @param req - The original request object possibly containing the origin.
33
+ * @returns Promise resolving to the raw data of the request.
34
+ */
35
+ addUnapprovedMessageAsync(messageParams, req) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ (0, utils_1.validateEncryptionPublicKeyMessageData)(messageParams);
38
+ const messageId = yield this.addUnapprovedMessage(messageParams, req);
39
+ return new Promise((resolve, reject) => {
40
+ this.hub.once(`${messageId}:finished`, (data) => {
41
+ switch (data.status) {
42
+ case 'received':
43
+ return resolve(data.rawSig);
44
+ case 'rejected':
45
+ return reject(new Error('MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.'));
46
+ default:
47
+ return reject(new Error(`MetaMask EncryptionPublicKey: Unknown problem: ${JSON.stringify(messageParams)}`));
48
+ }
49
+ });
50
+ });
51
+ });
52
+ }
53
+ /**
54
+ * Creates a new Message with an 'unapproved' status using the passed messageParams.
55
+ * this.addMessage is called to add the new Message to this.messages, and to save the
56
+ * unapproved Messages.
57
+ *
58
+ * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message
59
+ * is approved.
60
+ * @param req - The original request object possibly containing the origin.
61
+ * @returns The id of the newly created message.
62
+ */
63
+ addUnapprovedMessage(messageParams, req) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ if (req) {
66
+ messageParams.origin = req.origin;
67
+ }
68
+ const messageId = (0, uuid_1.v1)();
69
+ const messageData = {
70
+ id: messageId,
71
+ messageParams,
72
+ status: 'unapproved',
73
+ time: Date.now(),
74
+ type: 'eth_getEncryptionPublicKey',
75
+ };
76
+ yield this.addMessage(messageData);
77
+ this.hub.emit(`unapprovedMessage`, Object.assign(Object.assign({}, messageParams), { metamaskId: messageId }));
78
+ return messageId;
79
+ });
80
+ }
81
+ /**
82
+ * Removes the metamaskId property from passed messageParams and returns a promise which
83
+ * resolves the updated messageParams.
84
+ *
85
+ * @param messageParams - The messageParams to modify.
86
+ * @returns Promise resolving to the messageParams with the metamaskId property removed.
87
+ */
88
+ prepMessageForSigning(messageParams) {
89
+ delete messageParams.metamaskId;
90
+ return Promise.resolve({ from: messageParams.data });
91
+ }
92
+ }
93
+ exports.EncryptionPublicKeyManager = EncryptionPublicKeyManager;
94
+ exports.default = EncryptionPublicKeyManager;
95
+ //# sourceMappingURL=EncryptionPublicKeyManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptionPublicKeyManager.js","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAoC;AAQpC,qEAAkE;AAClE,mCAAiE;AAyCjE;;GAEG;AACH,MAAa,0BAA2B,SAAQ,+CAI/C;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,4BAA4B,CAAC;IAuF/C,CAAC;IArFC;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAwC,EACxC,GAAqB;;YAErB,IAAA,8CAAsC,EAAC,aAAa,CAAC,CAAC;YACtD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;YAEtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACrC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,SAAS,WAAW,EAAE,CAAC,IAAyB,EAAE,EAAE;oBACnE,QAAQ,IAAI,CAAC,MAAM,EAAE;wBACnB,KAAK,UAAU;4BACb,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;wBACxC,KAAK,UAAU;4BACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,wEAAwE,CACzE,CACF,CAAC;wBACJ;4BACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,kDAAkD,IAAI,CAAC,SAAS,CAC9D,aAAa,CACd,EAAE,CACJ,CACF,CAAC;qBACL;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;IAED;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAwC,EACxC,GAAqB;;YAErB,IAAI,GAAG,EAAE;gBACP,aAAa,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;aACnC;YACD,MAAM,SAAS,GAAG,IAAA,SAAM,GAAE,CAAC;YAC3B,MAAM,WAAW,GAAwB;gBACvC,EAAE,EAAE,SAAS;gBACb,aAAa;gBACb,MAAM,EAAE,YAAY;gBACpB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;gBAChB,IAAI,EAAE,4BAA4B;aACnC,CAAC;YACF,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,kCAC5B,aAAa,GACb,EAAE,UAAU,EAAE,SAAS,EAAE,EAC5B,CAAC;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAgD;QAEhD,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;CACF;AA/FD,gEA+FC;AAED,kBAAe,0BAA0B,CAAC","sourcesContent":["import { v1 as random } from 'uuid';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { validateEncryptionPublicKeyMessageData } from './utils';\n\n/**\n * @type EncryptionPublicKey\n *\n * Represents and contains data about a 'eth_getEncryptionPublicKey' type request.\n * These are created when an encryption public key is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * @property type - The json-prc method for which an encryption public key request has been made.\n * A 'Message' which always has a 'eth_getEncryptionPublicKey' type\n * @property rawSig - Encryption public key\n */\nexport interface EncryptionPublicKey extends AbstractMessage {\n messageParams: EncryptionPublicKeyParams;\n}\n\n/**\n * @type EncryptionPublicKeyParams\n *\n * Represents the parameters to pass to the method once the request is approved.\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport type EncryptionPublicKeyParams = AbstractMessageParams;\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - Encryption public key\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport interface EncryptionPublicKeyParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport class EncryptionPublicKeyManager extends AbstractMessageManager<\n EncryptionPublicKey,\n EncryptionPublicKeyParams,\n EncryptionPublicKeyParamsMetamask\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'EncryptionPublicKeyManager';\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns Promise resolving to the raw data of the request.\n */\n async addUnapprovedMessageAsync(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateEncryptionPublicKeyMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.hub.once(`${messageId}:finished`, (data: EncryptionPublicKey) => {\n switch (data.status) {\n case 'received':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n 'MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.',\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask EncryptionPublicKey: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n });\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n if (req) {\n messageParams.origin = req.origin;\n }\n const messageId = random();\n const messageData: EncryptionPublicKey = {\n id: messageId,\n messageParams,\n status: 'unapproved',\n time: Date.now(),\n type: 'eth_getEncryptionPublicKey',\n };\n await this.addMessage(messageData);\n this.hub.emit(`unapprovedMessage`, {\n ...messageParams,\n ...{ metamaskId: messageId },\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: EncryptionPublicKeyParamsMetamask,\n ): Promise<EncryptionPublicKeyParams> {\n delete messageParams.metamaskId;\n return Promise.resolve({ from: messageParams.data });\n }\n}\n\nexport default EncryptionPublicKeyManager;\n"]}
@@ -0,0 +1,70 @@
1
+ import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest } from './AbstractMessageManager';
2
+ import { AbstractMessageManager } from './AbstractMessageManager';
3
+ /**
4
+ * @type Message
5
+ *
6
+ * Represents and contains data about a 'eth_sign' type signature request.
7
+ * These are created when a signature for an eth_sign call is requested.
8
+ * @property id - An id to track and identify the message object
9
+ * @property messageParams - The parameters to pass to the eth_sign method once the signature request is approved
10
+ * @property type - The json-prc signing method for which a signature request has been made.
11
+ * A 'Message' which always has a 'eth_sign' type
12
+ * @property rawSig - Raw data of the signature request
13
+ */
14
+ export interface Message extends AbstractMessage {
15
+ messageParams: MessageParams;
16
+ }
17
+ /**
18
+ * @type PersonalMessageParams
19
+ *
20
+ * Represents the parameters to pass to the eth_sign method once the signature request is approved.
21
+ * @property data - A hex string conversion of the raw buffer data of the signature request
22
+ * @property from - Address to sign this message from
23
+ * @property origin? - Added for request origin identification
24
+ */
25
+ export interface MessageParams extends AbstractMessageParams {
26
+ data: string;
27
+ }
28
+ /**
29
+ * @type MessageParamsMetamask
30
+ *
31
+ * Represents the parameters to pass to the eth_sign method once the signature request is approved
32
+ * plus data added by MetaMask.
33
+ * @property metamaskId - Added for tracking and identification within MetaMask
34
+ * @property data - A hex string conversion of the raw buffer data of the signature request
35
+ * @property from - Address to sign this message from
36
+ * @property origin? - Added for request origin identification
37
+ */
38
+ export interface MessageParamsMetamask extends AbstractMessageParamsMetamask {
39
+ data: string;
40
+ }
41
+ /**
42
+ * Controller in charge of managing - storing, adding, removing, updating - Messages.
43
+ */
44
+ export declare class MessageManager extends AbstractMessageManager<Message, MessageParams, MessageParamsMetamask> {
45
+ /**
46
+ * Name of this controller used during composition
47
+ */
48
+ name: string;
49
+ /**
50
+ * Creates a new Message with an 'unapproved' status using the passed messageParams.
51
+ * this.addMessage is called to add the new Message to this.messages, and to save the
52
+ * unapproved Messages.
53
+ *
54
+ * @param messageParams - The params for the eth_sign call to be made after the message
55
+ * is approved.
56
+ * @param req - The original request object possibly containing the origin.
57
+ * @returns The id of the newly created message.
58
+ */
59
+ addUnapprovedMessage(messageParams: MessageParams, req?: OriginalRequest): Promise<string>;
60
+ /**
61
+ * Removes the metamaskId property from passed messageParams and returns a promise which
62
+ * resolves the updated messageParams.
63
+ *
64
+ * @param messageParams - The messageParams to modify.
65
+ * @returns Promise resolving to the messageParams with the metamaskId property removed.
66
+ */
67
+ prepMessageForSigning(messageParams: MessageParamsMetamask): Promise<MessageParams>;
68
+ }
69
+ export default MessageManager;
70
+ //# sourceMappingURL=MessageManager.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MessageManager = void 0;
13
+ const uuid_1 = require("uuid");
14
+ const AbstractMessageManager_1 = require("./AbstractMessageManager");
15
+ const utils_1 = require("./utils");
16
+ /**
17
+ * Controller in charge of managing - storing, adding, removing, updating - Messages.
18
+ */
19
+ class MessageManager extends AbstractMessageManager_1.AbstractMessageManager {
20
+ constructor() {
21
+ super(...arguments);
22
+ /**
23
+ * Name of this controller used during composition
24
+ */
25
+ this.name = 'MessageManager';
26
+ }
27
+ /**
28
+ * Creates a new Message with an 'unapproved' status using the passed messageParams.
29
+ * this.addMessage is called to add the new Message to this.messages, and to save the
30
+ * unapproved Messages.
31
+ *
32
+ * @param messageParams - The params for the eth_sign call to be made after the message
33
+ * is approved.
34
+ * @param req - The original request object possibly containing the origin.
35
+ * @returns The id of the newly created message.
36
+ */
37
+ addUnapprovedMessage(messageParams, req) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ (0, utils_1.validateSignMessageData)(messageParams);
40
+ if (req) {
41
+ messageParams.origin = req.origin;
42
+ }
43
+ messageParams.data = (0, utils_1.normalizeMessageData)(messageParams.data);
44
+ const messageId = (0, uuid_1.v1)();
45
+ const messageData = {
46
+ id: messageId,
47
+ messageParams,
48
+ securityAlertResponse: req === null || req === void 0 ? void 0 : req.securityAlertResponse,
49
+ status: 'unapproved',
50
+ time: Date.now(),
51
+ type: 'eth_sign',
52
+ };
53
+ yield this.addMessage(messageData);
54
+ this.hub.emit(`unapprovedMessage`, Object.assign(Object.assign({}, messageParams), { metamaskId: messageId }));
55
+ return messageId;
56
+ });
57
+ }
58
+ /**
59
+ * Removes the metamaskId property from passed messageParams and returns a promise which
60
+ * resolves the updated messageParams.
61
+ *
62
+ * @param messageParams - The messageParams to modify.
63
+ * @returns Promise resolving to the messageParams with the metamaskId property removed.
64
+ */
65
+ prepMessageForSigning(messageParams) {
66
+ delete messageParams.metamaskId;
67
+ return Promise.resolve(messageParams);
68
+ }
69
+ }
70
+ exports.MessageManager = MessageManager;
71
+ exports.default = MessageManager;
72
+ //# sourceMappingURL=MessageManager.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,72 @@
1
+ import type { SIWEMessage } from '@metamask/controller-utils';
2
+ import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest } from './AbstractMessageManager';
3
+ import { AbstractMessageManager } from './AbstractMessageManager';
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: string;
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.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PersonalMessageManager = void 0;
13
+ const controller_utils_1 = require("@metamask/controller-utils");
14
+ const uuid_1 = require("uuid");
15
+ const AbstractMessageManager_1 = require("./AbstractMessageManager");
16
+ const utils_1 = require("./utils");
17
+ /**
18
+ * Controller in charge of managing - storing, adding, removing, updating - Messages.
19
+ */
20
+ class PersonalMessageManager extends AbstractMessageManager_1.AbstractMessageManager {
21
+ constructor() {
22
+ super(...arguments);
23
+ /**
24
+ * Name of this controller used during composition
25
+ */
26
+ this.name = 'PersonalMessageManager';
27
+ }
28
+ /**
29
+ * Creates a new Message with an 'unapproved' status using the passed messageParams.
30
+ * this.addMessage is called to add the new Message to this.messages, and to save the
31
+ * unapproved Messages.
32
+ *
33
+ * @param messageParams - The params for the personal_sign call to be made after the message
34
+ * is approved.
35
+ * @param req - The original request object possibly containing the origin.
36
+ * @returns The id of the newly created message.
37
+ */
38
+ addUnapprovedMessage(messageParams, req) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ (0, utils_1.validateSignMessageData)(messageParams);
41
+ if (req) {
42
+ messageParams.origin = req.origin;
43
+ }
44
+ messageParams.data = (0, utils_1.normalizeMessageData)(messageParams.data);
45
+ const ethereumSignInData = (0, controller_utils_1.detectSIWE)(messageParams);
46
+ const finalMsgParams = Object.assign(Object.assign({}, messageParams), { siwe: ethereumSignInData });
47
+ const messageId = (0, uuid_1.v1)();
48
+ const messageData = {
49
+ id: messageId,
50
+ messageParams: finalMsgParams,
51
+ securityAlertResponse: req === null || req === void 0 ? void 0 : req.securityAlertResponse,
52
+ status: 'unapproved',
53
+ time: Date.now(),
54
+ type: 'personal_sign',
55
+ };
56
+ yield this.addMessage(messageData);
57
+ this.hub.emit(`unapprovedMessage`, Object.assign(Object.assign({}, finalMsgParams), { metamaskId: messageId }));
58
+ return messageId;
59
+ });
60
+ }
61
+ /**
62
+ * Removes the metamaskId property from passed messageParams and returns a promise which
63
+ * resolves the updated messageParams.
64
+ *
65
+ * @param messageParams - The messageParams to modify.
66
+ * @returns Promise resolving to the messageParams with the metamaskId property removed.
67
+ */
68
+ prepMessageForSigning(messageParams) {
69
+ delete messageParams.metamaskId;
70
+ return Promise.resolve(messageParams);
71
+ }
72
+ }
73
+ exports.PersonalMessageManager = PersonalMessageManager;
74
+ exports.default = PersonalMessageManager;
75
+ //# sourceMappingURL=PersonalMessageManager.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,98 @@
1
+ import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest } from './AbstractMessageManager';
2
+ import { AbstractMessageManager } from './AbstractMessageManager';
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 declare 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: string;
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.ts.map
@@ -0,0 +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,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;CAK/B;AAED,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TypedMessageManager = void 0;
13
+ const uuid_1 = require("uuid");
14
+ const AbstractMessageManager_1 = require("./AbstractMessageManager");
15
+ const utils_1 = require("./utils");
16
+ /**
17
+ * Controller in charge of managing - storing, adding, removing, updating - TypedMessages.
18
+ */
19
+ class TypedMessageManager extends AbstractMessageManager_1.AbstractMessageManager {
20
+ constructor() {
21
+ super(...arguments);
22
+ /**
23
+ * Name of this controller used during composition
24
+ */
25
+ this.name = 'TypedMessageManager';
26
+ }
27
+ /**
28
+ * Creates a new TypedMessage with an 'unapproved' status using the passed messageParams.
29
+ * this.addMessage is called to add the new TypedMessage to this.messages, and to save the
30
+ * unapproved TypedMessages.
31
+ *
32
+ * @param messageParams - The params for the 'eth_signTypedData' call to be made after the message
33
+ * is approved.
34
+ * @param req - The original request object possibly containing the origin.
35
+ * @param version - Compatibility version EIP712.
36
+ * @returns The id of the newly created TypedMessage.
37
+ */
38
+ addUnapprovedMessage(messageParams, req, version) {
39
+ var _a;
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ if (version === 'V1') {
42
+ (0, utils_1.validateTypedSignMessageDataV1)(messageParams);
43
+ }
44
+ if (version === 'V3' || version === 'V4') {
45
+ const currentChainId = (_a = this.getCurrentChainId) === null || _a === void 0 ? void 0 : _a.call(this);
46
+ (0, utils_1.validateTypedSignMessageDataV3V4)(messageParams, currentChainId);
47
+ }
48
+ if (typeof messageParams.data !== 'string' &&
49
+ (version === 'V3' || version === 'V4')) {
50
+ messageParams.data = JSON.stringify(messageParams.data);
51
+ }
52
+ const messageId = (0, uuid_1.v1)();
53
+ const messageParamsMetamask = Object.assign(Object.assign({}, messageParams), { metamaskId: messageId, version });
54
+ if (req) {
55
+ messageParams.origin = req.origin;
56
+ }
57
+ const messageData = {
58
+ id: messageId,
59
+ messageParams,
60
+ securityAlertResponse: req === null || req === void 0 ? void 0 : req.securityAlertResponse,
61
+ status: 'unapproved',
62
+ time: Date.now(),
63
+ type: 'eth_signTypedData',
64
+ };
65
+ yield this.addMessage(messageData);
66
+ this.hub.emit(`unapprovedMessage`, messageParamsMetamask);
67
+ return messageId;
68
+ });
69
+ }
70
+ /**
71
+ * Sets a TypedMessage status to 'errored' via a call to this.setMessageStatus.
72
+ *
73
+ * @param messageId - The id of the TypedMessage to error.
74
+ * @param error - The error to be included in TypedMessage.
75
+ */
76
+ setMessageStatusErrored(messageId, error) {
77
+ const message = this.getMessage(messageId);
78
+ /* istanbul ignore if */
79
+ if (!message) {
80
+ return;
81
+ }
82
+ message.error = error;
83
+ this.updateMessage(message);
84
+ this.setMessageStatus(messageId, 'errored');
85
+ }
86
+ /**
87
+ * Removes the metamaskId and version properties from passed messageParams and returns a promise which
88
+ * resolves the updated messageParams.
89
+ *
90
+ * @param messageParams - The messageParams to modify.
91
+ * @returns Promise resolving to the messageParams with the metamaskId and version properties removed.
92
+ */
93
+ prepMessageForSigning(messageParams) {
94
+ delete messageParams.metamaskId;
95
+ delete messageParams.version;
96
+ return Promise.resolve(messageParams);
97
+ }
98
+ }
99
+ exports.TypedMessageManager = TypedMessageManager;
100
+ exports.default = TypedMessageManager;
101
+ //# sourceMappingURL=TypedMessageManager.js.map