@metamask-previews/message-manager 14.1.2-preview-4f4c98e → 14.1.2-preview-eb263b0ee

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 (65) hide show
  1. package/CHANGELOG.md +0 -1
  2. package/dist/AbstractMessageManager.cjs +329 -0
  3. package/dist/AbstractMessageManager.cjs.map +1 -0
  4. package/dist/{AbstractMessageManager.d.ts → AbstractMessageManager.d.cts} +10 -7
  5. package/dist/AbstractMessageManager.d.cts.map +1 -0
  6. package/dist/AbstractMessageManager.d.mts +294 -0
  7. package/dist/AbstractMessageManager.d.mts.map +1 -0
  8. package/dist/{AbstractMessageManager.js → AbstractMessageManager.mjs} +4 -4
  9. package/dist/AbstractMessageManager.mjs.map +1 -0
  10. package/dist/DecryptMessageManager.cjs +82 -0
  11. package/dist/DecryptMessageManager.cjs.map +1 -0
  12. package/dist/{DecryptMessageManager.d.ts → DecryptMessageManager.d.cts} +5 -5
  13. package/dist/DecryptMessageManager.d.cts.map +1 -0
  14. package/dist/DecryptMessageManager.d.mts +96 -0
  15. package/dist/DecryptMessageManager.d.mts.map +1 -0
  16. package/dist/{DecryptMessageManager.js → DecryptMessageManager.mjs} +4 -4
  17. package/dist/DecryptMessageManager.mjs.map +1 -0
  18. package/dist/EncryptionPublicKeyManager.cjs +80 -0
  19. package/dist/EncryptionPublicKeyManager.cjs.map +1 -0
  20. package/dist/{EncryptionPublicKeyManager.d.ts → EncryptionPublicKeyManager.d.cts} +5 -5
  21. package/dist/EncryptionPublicKeyManager.d.cts.map +1 -0
  22. package/dist/EncryptionPublicKeyManager.d.mts +96 -0
  23. package/dist/EncryptionPublicKeyManager.d.mts.map +1 -0
  24. package/dist/{EncryptionPublicKeyManager.js → EncryptionPublicKeyManager.mjs} +4 -4
  25. package/dist/EncryptionPublicKeyManager.mjs.map +1 -0
  26. package/dist/index.cjs +20 -0
  27. package/dist/index.cjs.map +1 -0
  28. package/dist/index.d.cts +5 -0
  29. package/dist/index.d.cts.map +1 -0
  30. package/dist/index.d.mts +5 -0
  31. package/dist/index.d.mts.map +1 -0
  32. package/dist/index.mjs +4 -0
  33. package/dist/index.mjs.map +1 -0
  34. package/dist/types.cjs +3 -0
  35. package/dist/types.cjs.map +1 -0
  36. package/dist/{types.d.ts → types.d.cts} +3 -3
  37. package/dist/types.d.cts.map +1 -0
  38. package/dist/types.d.mts +16 -0
  39. package/dist/types.d.mts.map +1 -0
  40. package/dist/types.mjs +2 -0
  41. package/dist/types.mjs.map +1 -0
  42. package/dist/utils.cjs +60 -0
  43. package/dist/utils.cjs.map +1 -0
  44. package/dist/{utils.d.ts → utils.d.cts} +3 -3
  45. package/dist/utils.d.cts.map +1 -0
  46. package/dist/utils.d.mts +25 -0
  47. package/dist/utils.d.mts.map +1 -0
  48. package/dist/{utils.js → utils.mjs} +3 -3
  49. package/dist/utils.mjs.map +1 -0
  50. package/package.json +16 -12
  51. package/dist/AbstractMessageManager.d.ts.map +0 -1
  52. package/dist/AbstractMessageManager.js.map +0 -1
  53. package/dist/DecryptMessageManager.d.ts.map +0 -1
  54. package/dist/DecryptMessageManager.js.map +0 -1
  55. package/dist/EncryptionPublicKeyManager.d.ts.map +0 -1
  56. package/dist/EncryptionPublicKeyManager.js.map +0 -1
  57. package/dist/index.d.ts +0 -5
  58. package/dist/index.d.ts.map +0 -1
  59. package/dist/index.js +0 -4
  60. package/dist/index.js.map +0 -1
  61. package/dist/types.d.ts.map +0 -1
  62. package/dist/types.js +0 -2
  63. package/dist/types.js.map +0 -1
  64. package/dist/utils.d.ts.map +0 -1
  65. package/dist/utils.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DecryptMessageManager.mjs","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAY1D,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AACrE,OAAO,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,oBAAmB;AAEhF,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAgF5C;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,sBAM1C;IACC,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACwB;QAC7B,KAAK,CAAC;YACJ,wBAAwB;YACxB,SAAS;YACT,IAAI,EAAE,WAAW;YACjB,uBAAuB;YACvB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,yBAAyB,CAC7B,aAAmC,EACnC,GAAoB;QAEpB,4BAA4B,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QAEtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CACtB,GAAG,SAAS,WAAW,EACvB,CAAC,IAAoB,EAAE,EAAE;gBACvB,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;oBACpB,KAAK,WAAW;wBACd,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;oBACxC,KAAK,UAAU;wBACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,0DAA0D,CAC3D,CACF,CAAC;oBACJ,KAAK,SAAS;wBACZ,OAAO,MAAM,CACX,IAAI,KAAK,CACP,4DAA4D,CAC7D,CACF,CAAC;oBACJ;wBACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,6CAA6C,IAAI,CAAC,SAAS,CACzD,aAAa,CACd,EAAE,CACJ,CACF,CAAC;gBACN,CAAC;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,oBAAoB,CACxB,aAAmC,EACnC,GAAoB;QAEpB,MAAM,oBAAoB,GAAG,IAAI,CAAC,yBAAyB,CACzD,aAAa,EACb,GAAG,CAC2B,CAAC;QACjC,aAAa,CAAC,IAAI,GAAG,oBAAoB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAE9D,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAC9C,oBAAoB,EACpB,YAAY,CAAC,UAAU,EACvB,GAAG,CACqB,CAAC;QAE3B,MAAM,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;QAEjC,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACnC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,WAAW,oBAAoB,EAAE;YACzD,GAAG,oBAAoB;YACvB,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAA2C;QAE3C,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport {} from '@metamask/messenger';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n MessageRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager.js';\nimport { AbstractMessageManager } from './AbstractMessageManager.js';\nimport { normalizeMessageData, validateDecryptedMessageData } from './utils.js';\n\nconst managerName = 'DecryptMessageManager';\n\nexport type DecryptMessageManagerState = MessageManagerState<DecryptMessage>;\n\nexport type DecryptMessageManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type DecryptMessageManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\ntype DecryptMessageManagerActions = ControllerGetStateAction<\n typeof managerName,\n DecryptMessageManagerState\n>;\n\ntype DecryptMessageManagerEvents =\n | ControllerStateChangeEvent<typeof managerName, DecryptMessageManagerState>\n | DecryptMessageManagerUnapprovedMessageAddedEvent\n | DecryptMessageManagerUpdateBadgeEvent;\n\nexport type DecryptMessageManagerMessenger = Messenger<\n typeof managerName,\n DecryptMessageManagerActions,\n DecryptMessageManagerEvents\n>;\n\ntype DecryptMessageManagerOptions = {\n messenger: DecryptMessageManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<DecryptMessage>;\n additionalFinishStatuses?: string[];\n};\n\n/**\n * @type DecryptMessage\n *\n * Represents and contains data about a 'eth_decrypt' type signature request.\n * These are created when a signature for an eth_decrypt call is requested.\n *\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the eth_decrypt method once the request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'DecryptMessage' which always has a 'eth_decrypt' type\n */\nexport type DecryptMessage = AbstractMessage & {\n messageParams: DecryptMessageParams;\n};\n\n/**\n * @type DecryptMessageParams\n *\n * Represents the parameters to pass to the eth_decrypt method once the request is approved.\n * @property data - A hex string conversion of the raw buffer data of the signature request\n */\nexport type DecryptMessageParams = AbstractMessageParams & {\n data: string;\n};\n\n/**\n * @type DecryptMessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_decrypt method once the request is approved\n * plus data added by MetaMask.\n *\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface DecryptMessageParamsMetamask extends AbstractMessageParamsMetamask {\n data: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.\n */\nexport class DecryptMessageManager extends AbstractMessageManager<\n typeof managerName,\n DecryptMessage,\n DecryptMessageParams,\n DecryptMessageParamsMetamask,\n DecryptMessageManagerMessenger\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: DecryptMessageManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\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 unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns Promise resolving to the raw data of the signature request.\n */\n async addUnapprovedMessageAsync(\n messageParams: DecryptMessageParams,\n req?: MessageRequest,\n ): Promise<string> {\n validateDecryptedMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (data: DecryptMessage) => {\n switch (data.status) {\n case 'decrypted':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n 'MetaMask DecryptMessage: User denied message decryption.',\n ),\n );\n case 'errored':\n return reject(\n new Error(\n 'MetaMask DecryptMessage: This message cannot be decrypted.',\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask DecryptMessage: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: DecryptMessageParams,\n req?: MessageRequest,\n ) {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies DecryptMessageParams;\n messageParams.data = normalizeMessageData(messageParams.data);\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthDecrypt,\n req,\n ) satisfies DecryptMessage;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messenger.publish(`${managerName}: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: DecryptMessageParamsMetamask,\n ): Promise<DecryptMessageParams> {\n delete messageParams.metamaskId;\n return Promise.resolve(messageParams);\n }\n}\n"]}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EncryptionPublicKeyManager = void 0;
4
+ const controller_utils_1 = require("@metamask/controller-utils");
5
+ const AbstractMessageManager_js_1 = require("./AbstractMessageManager.cjs");
6
+ const utils_js_1 = require("./utils.cjs");
7
+ const managerName = 'EncryptionPublicKeyManager';
8
+ /**
9
+ * Controller in charge of managing - storing, adding, removing, updating - Messages.
10
+ */
11
+ class EncryptionPublicKeyManager extends AbstractMessageManager_js_1.AbstractMessageManager {
12
+ constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }) {
13
+ super({
14
+ additionalFinishStatuses,
15
+ messenger,
16
+ name: managerName,
17
+ securityProviderRequest,
18
+ state,
19
+ });
20
+ }
21
+ /**
22
+ * Creates a new Message with an 'unapproved' status using the passed messageParams.
23
+ * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.
24
+ *
25
+ * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message is approved.
26
+ * @param req - The original request object possibly containing the origin.
27
+ * @returns Promise resolving to the raw data of the request.
28
+ */
29
+ async addUnapprovedMessageAsync(messageParams, req) {
30
+ (0, utils_js_1.validateEncryptionPublicKeyMessageData)(messageParams);
31
+ const messageId = await this.addUnapprovedMessage(messageParams, req);
32
+ return new Promise((resolve, reject) => {
33
+ this.internalEvents.once(`${messageId}:finished`, (data) => {
34
+ switch (data.status) {
35
+ case 'received':
36
+ return resolve(data.rawSig);
37
+ case 'rejected':
38
+ return reject(new Error('MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.'));
39
+ default:
40
+ return reject(new Error(`MetaMask EncryptionPublicKey: Unknown problem: ${JSON.stringify(messageParams)}`));
41
+ }
42
+ });
43
+ });
44
+ }
45
+ /**
46
+ * Creates a new Message with an 'unapproved' status using the passed messageParams.
47
+ * this.addMessage is called to add the new Message to this.messages, and to save the
48
+ * unapproved Messages.
49
+ *
50
+ * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message
51
+ * is approved.
52
+ * @param req - The original request object possibly containing the origin.
53
+ * @returns The id of the newly created message.
54
+ */
55
+ async addUnapprovedMessage(messageParams, req) {
56
+ const updatedMessageParams = this.addRequestToMessageParams(messageParams, req);
57
+ const messageData = this.createUnapprovedMessage(updatedMessageParams, controller_utils_1.ApprovalType.EthGetEncryptionPublicKey, req);
58
+ const messageId = messageData.id;
59
+ await this.addMessage(messageData);
60
+ this.messenger.publish(`${this.name}:unapprovedMessage`, {
61
+ ...updatedMessageParams,
62
+ metamaskId: messageId,
63
+ });
64
+ return messageId;
65
+ }
66
+ /**
67
+ * Removes the metamaskId property from passed messageParams and returns a promise which
68
+ * resolves the updated messageParams.
69
+ *
70
+ * @param messageParams - The messageParams to modify.
71
+ * @returns Promise resolving to the messageParams with the metamaskId property removed.
72
+ */
73
+ prepMessageForSigning(messageParams) {
74
+ delete messageParams.metamaskId;
75
+ return Promise.resolve({ from: messageParams.data });
76
+ }
77
+ }
78
+ exports.EncryptionPublicKeyManager = EncryptionPublicKeyManager;
79
+ exports.default = EncryptionPublicKeyManager;
80
+ //# sourceMappingURL=EncryptionPublicKeyManager.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptionPublicKeyManager.cjs","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":";;;AAIA,iEAA0D;AAW1D,4EAAqE;AACrE,0CAAoE;AAEpE,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAkFjD;;GAEG;AACH,MAAa,0BAA2B,SAAQ,kDAM/C;IACC,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GAC6B;QAClC,KAAK,CAAC;YACJ,wBAAwB;YACxB,SAAS;YACT,IAAI,EAAE,WAAW;YACjB,uBAAuB;YACvB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,yBAAyB,CAC7B,aAAwC,EACxC,GAAoB;QAEpB,IAAA,iDAAsC,EAAC,aAAa,CAAC,CAAC;QACtD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QAEtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CACtB,GAAG,SAAS,WAAW,EACvB,CAAC,IAAyB,EAAE,EAAE;gBAC5B,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;oBACpB,KAAK,UAAU;wBACb,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;oBACxC,KAAK,UAAU;wBACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,wEAAwE,CACzE,CACF,CAAC;oBACJ;wBACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,kDAAkD,IAAI,CAAC,SAAS,CAC9D,aAAa,CACd,EAAE,CACJ,CACF,CAAC;gBACN,CAAC;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,oBAAoB,CACxB,aAAwC,EACxC,GAAoB;QAEpB,MAAM,oBAAoB,GAAG,IAAI,CAAC,yBAAyB,CACzD,aAAa,EACb,GAAG,CACgC,CAAC;QAEtC,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAC9C,oBAAoB,EACpB,+BAAY,CAAC,yBAAyB,EACtC,GAAG,CAC0B,CAAC;QAEhC,MAAM,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;QAEjC,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACnC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,oBAA6B,EAAE;YAChE,GAAG,oBAAoB;YACvB,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAgD;QAEhD,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;CACF;AAhHD,gEAgHC;AAED,kBAAe,0BAA0B,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n MessageRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager.js';\nimport { AbstractMessageManager } from './AbstractMessageManager.js';\nimport { validateEncryptionPublicKeyMessageData } from './utils.js';\n\nconst managerName = 'EncryptionPublicKeyManager';\n\nexport type EncryptionPublicKeyManagerState =\n MessageManagerState<EncryptionPublicKey>;\n\nexport type EncryptionPublicKeyManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type EncryptionPublicKeyManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\ntype EncryptionPublicKeyManagerActions = ControllerGetStateAction<\n typeof managerName,\n EncryptionPublicKeyManagerState\n>;\n\ntype EncryptionPublicKeyManagerEvents =\n | ControllerStateChangeEvent<\n typeof managerName,\n EncryptionPublicKeyManagerState\n >\n | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent\n | EncryptionPublicKeyManagerUpdateBadgeEvent;\n\nexport type EncryptionPublicKeyManagerMessenger = Messenger<\n typeof managerName,\n EncryptionPublicKeyManagerActions,\n EncryptionPublicKeyManagerEvents\n>;\n\ntype EncryptionPublicKeyManagerOptions = {\n messenger: EncryptionPublicKeyManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<EncryptionPublicKey>;\n additionalFinishStatuses?: string[];\n};\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 *\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 type EncryptionPublicKey = 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 *\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 type EncryptionPublicKeyParamsMetamask =\n 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 typeof managerName,\n EncryptionPublicKey,\n EncryptionPublicKeyParams,\n EncryptionPublicKeyParamsMetamask,\n EncryptionPublicKeyManagerMessenger\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: EncryptionPublicKeyManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\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 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?: MessageRequest,\n ): Promise<string> {\n validateEncryptionPublicKeyMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (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 /**\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?: MessageRequest,\n ): Promise<string> {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies EncryptionPublicKeyParams;\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthGetEncryptionPublicKey,\n req,\n ) satisfies EncryptionPublicKey;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messenger.publish(`${this.name}:unapprovedMessage` as const, {\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: EncryptionPublicKeyParamsMetamask,\n ): Promise<EncryptionPublicKeyParams> {\n delete messageParams.metamaskId;\n return Promise.resolve({ from: messageParams.data });\n }\n}\n\nexport default EncryptionPublicKeyManager;\n"]}
@@ -1,7 +1,7 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
2
- import type { Messenger } from '@metamask/messenger';
3
- import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, MessageRequest, SecurityProviderRequest } from './AbstractMessageManager.js';
4
- import { AbstractMessageManager } from './AbstractMessageManager.js';
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
+ import type { Messenger } from "@metamask/messenger";
3
+ import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, MessageRequest, SecurityProviderRequest } from "./AbstractMessageManager.cjs";
4
+ import { AbstractMessageManager } from "./AbstractMessageManager.cjs";
5
5
  declare const managerName = "EncryptionPublicKeyManager";
6
6
  export type EncryptionPublicKeyManagerState = MessageManagerState<EncryptionPublicKey>;
7
7
  export type EncryptionPublicKeyManagerUnapprovedMessageAddedEvent = {
@@ -93,4 +93,4 @@ export declare class EncryptionPublicKeyManager extends AbstractMessageManager<t
93
93
  prepMessageForSigning(messageParams: EncryptionPublicKeyParamsMetamask): Promise<EncryptionPublicKeyParams>;
94
94
  }
95
95
  export default EncryptionPublicKeyManager;
96
- //# sourceMappingURL=EncryptionPublicKeyManager.d.ts.map
96
+ //# sourceMappingURL=EncryptionPublicKeyManager.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptionPublicKeyManager.d.cts","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,cAAc,EACd,uBAAuB,EACxB,qCAAoC;AACrC,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAGrE,QAAA,MAAM,WAAW,+BAA+B,CAAC;AAEjD,MAAM,MAAM,+BAA+B,GACzC,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;AAE3C,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,GAAG,OAAO,WAAW,oBAAoB,CAAC;IAChD,OAAO,EAAE,CAAC,6BAA6B,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,GAAG,OAAO,WAAW,cAAc,CAAC;IAC1C,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF,KAAK,iCAAiC,GAAG,wBAAwB,CAC/D,OAAO,WAAW,EAClB,+BAA+B,CAChC,CAAC;AAEF,KAAK,gCAAgC,GACjC,0BAA0B,CACxB,OAAO,WAAW,EAClB,+BAA+B,CAChC,GACD,qDAAqD,GACrD,0CAA0C,CAAC;AAE/C,MAAM,MAAM,mCAAmC,GAAG,SAAS,CACzD,OAAO,WAAW,EAClB,iCAAiC,EACjC,gCAAgC,CACjC,CAAC;AAEF,KAAK,iCAAiC,GAAG;IACvC,SAAS,EAAE,mCAAmC,CAAC;IAC/C,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;IAClD,KAAK,CAAC,EAAE,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;IACjD,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG;IAClD,aAAa,EAAE,yBAAyB,CAAC;CAC1C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,GAAG,qBAAqB,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,MAAM,iCAAiC,GAC3C,6BAA6B,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEJ;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,sBAAsB,CACpE,OAAO,WAAW,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,iCAAiC,EACjC,mCAAmC,CACpC;gBACa,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACN,EAAE,iCAAiC;IAUpC;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,cAAc,GACnB,OAAO,CAAC,MAAM,CAAC;IA+BlB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,cAAc,GACnB,OAAO,CAAC,MAAM,CAAC;IAsBlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,iCAAiC,GAC/C,OAAO,CAAC,yBAAyB,CAAC;CAItC;AAED,eAAe,0BAA0B,CAAC"}
@@ -0,0 +1,96 @@
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
+ import type { Messenger } from "@metamask/messenger";
3
+ import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, MessageRequest, SecurityProviderRequest } from "./AbstractMessageManager.mjs";
4
+ import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
5
+ declare const managerName = "EncryptionPublicKeyManager";
6
+ export type EncryptionPublicKeyManagerState = MessageManagerState<EncryptionPublicKey>;
7
+ export type EncryptionPublicKeyManagerUnapprovedMessageAddedEvent = {
8
+ type: `${typeof managerName}:unapprovedMessage`;
9
+ payload: [AbstractMessageParamsMetamask];
10
+ };
11
+ export type EncryptionPublicKeyManagerUpdateBadgeEvent = {
12
+ type: `${typeof managerName}:updateBadge`;
13
+ payload: [];
14
+ };
15
+ type EncryptionPublicKeyManagerActions = ControllerGetStateAction<typeof managerName, EncryptionPublicKeyManagerState>;
16
+ type EncryptionPublicKeyManagerEvents = ControllerStateChangeEvent<typeof managerName, EncryptionPublicKeyManagerState> | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent | EncryptionPublicKeyManagerUpdateBadgeEvent;
17
+ export type EncryptionPublicKeyManagerMessenger = Messenger<typeof managerName, EncryptionPublicKeyManagerActions, EncryptionPublicKeyManagerEvents>;
18
+ type EncryptionPublicKeyManagerOptions = {
19
+ messenger: EncryptionPublicKeyManagerMessenger;
20
+ securityProviderRequest?: SecurityProviderRequest;
21
+ state?: MessageManagerState<EncryptionPublicKey>;
22
+ additionalFinishStatuses?: string[];
23
+ };
24
+ /**
25
+ * @type EncryptionPublicKey
26
+ *
27
+ * Represents and contains data about a 'eth_getEncryptionPublicKey' type request.
28
+ * These are created when an encryption public key is requested.
29
+ *
30
+ * @property id - An id to track and identify the message object
31
+ * @property messageParams - The parameters to pass to the eth_getEncryptionPublicKey method once the request is approved
32
+ * @property type - The json-prc method for which an encryption public key request has been made.
33
+ * A 'Message' which always has a 'eth_getEncryptionPublicKey' type
34
+ * @property rawSig - Encryption public key
35
+ */
36
+ export type EncryptionPublicKey = AbstractMessage & {
37
+ messageParams: EncryptionPublicKeyParams;
38
+ };
39
+ /**
40
+ * @type EncryptionPublicKeyParams
41
+ *
42
+ * Represents the parameters to pass to the method once the request is approved.
43
+ * @property from - Address from which to extract the encryption public key
44
+ * @property origin? - Added for request origin identification
45
+ */
46
+ export type EncryptionPublicKeyParams = AbstractMessageParams;
47
+ /**
48
+ * @type MessageParamsMetamask
49
+ *
50
+ * Represents the parameters to pass to the eth_getEncryptionPublicKey method once the request is approved
51
+ * plus data added by MetaMask.
52
+ *
53
+ * @property metamaskId - Added for tracking and identification within MetaMask
54
+ * @property data - Encryption public key
55
+ * @property from - Address from which to extract the encryption public key
56
+ * @property origin? - Added for request origin identification
57
+ */
58
+ export type EncryptionPublicKeyParamsMetamask = AbstractMessageParamsMetamask & {
59
+ data: string;
60
+ };
61
+ /**
62
+ * Controller in charge of managing - storing, adding, removing, updating - Messages.
63
+ */
64
+ export declare class EncryptionPublicKeyManager extends AbstractMessageManager<typeof managerName, EncryptionPublicKey, EncryptionPublicKeyParams, EncryptionPublicKeyParamsMetamask, EncryptionPublicKeyManagerMessenger> {
65
+ constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }: EncryptionPublicKeyManagerOptions);
66
+ /**
67
+ * Creates a new Message with an 'unapproved' status using the passed messageParams.
68
+ * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.
69
+ *
70
+ * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message is approved.
71
+ * @param req - The original request object possibly containing the origin.
72
+ * @returns Promise resolving to the raw data of the request.
73
+ */
74
+ addUnapprovedMessageAsync(messageParams: EncryptionPublicKeyParams, req?: MessageRequest): Promise<string>;
75
+ /**
76
+ * Creates a new Message with an 'unapproved' status using the passed messageParams.
77
+ * this.addMessage is called to add the new Message to this.messages, and to save the
78
+ * unapproved Messages.
79
+ *
80
+ * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message
81
+ * is approved.
82
+ * @param req - The original request object possibly containing the origin.
83
+ * @returns The id of the newly created message.
84
+ */
85
+ addUnapprovedMessage(messageParams: EncryptionPublicKeyParams, req?: MessageRequest): Promise<string>;
86
+ /**
87
+ * Removes the metamaskId property 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 property removed.
92
+ */
93
+ prepMessageForSigning(messageParams: EncryptionPublicKeyParamsMetamask): Promise<EncryptionPublicKeyParams>;
94
+ }
95
+ export default EncryptionPublicKeyManager;
96
+ //# sourceMappingURL=EncryptionPublicKeyManager.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptionPublicKeyManager.d.mts","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,cAAc,EACd,uBAAuB,EACxB,qCAAoC;AACrC,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AAGrE,QAAA,MAAM,WAAW,+BAA+B,CAAC;AAEjD,MAAM,MAAM,+BAA+B,GACzC,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;AAE3C,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,GAAG,OAAO,WAAW,oBAAoB,CAAC;IAChD,OAAO,EAAE,CAAC,6BAA6B,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,GAAG,OAAO,WAAW,cAAc,CAAC;IAC1C,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF,KAAK,iCAAiC,GAAG,wBAAwB,CAC/D,OAAO,WAAW,EAClB,+BAA+B,CAChC,CAAC;AAEF,KAAK,gCAAgC,GACjC,0BAA0B,CACxB,OAAO,WAAW,EAClB,+BAA+B,CAChC,GACD,qDAAqD,GACrD,0CAA0C,CAAC;AAE/C,MAAM,MAAM,mCAAmC,GAAG,SAAS,CACzD,OAAO,WAAW,EAClB,iCAAiC,EACjC,gCAAgC,CACjC,CAAC;AAEF,KAAK,iCAAiC,GAAG;IACvC,SAAS,EAAE,mCAAmC,CAAC;IAC/C,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;IAClD,KAAK,CAAC,EAAE,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;IACjD,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG;IAClD,aAAa,EAAE,yBAAyB,CAAC;CAC1C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,GAAG,qBAAqB,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,MAAM,iCAAiC,GAC3C,6BAA6B,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEJ;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,sBAAsB,CACpE,OAAO,WAAW,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,iCAAiC,EACjC,mCAAmC,CACpC;gBACa,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACN,EAAE,iCAAiC;IAUpC;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,cAAc,GACnB,OAAO,CAAC,MAAM,CAAC;IA+BlB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,cAAc,GACnB,OAAO,CAAC,MAAM,CAAC;IAsBlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,iCAAiC,GAC/C,OAAO,CAAC,yBAAyB,CAAC;CAItC;AAED,eAAe,0BAA0B,CAAC"}
@@ -1,6 +1,6 @@
1
- import { ApprovalType } from '@metamask/controller-utils';
2
- import { AbstractMessageManager } from './AbstractMessageManager.js';
3
- import { validateEncryptionPublicKeyMessageData } from './utils.js';
1
+ import { ApprovalType } from "@metamask/controller-utils";
2
+ import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
3
+ import { validateEncryptionPublicKeyMessageData } from "./utils.mjs";
4
4
  const managerName = 'EncryptionPublicKeyManager';
5
5
  /**
6
6
  * Controller in charge of managing - storing, adding, removing, updating - Messages.
@@ -73,4 +73,4 @@ export class EncryptionPublicKeyManager extends AbstractMessageManager {
73
73
  }
74
74
  }
75
75
  export default EncryptionPublicKeyManager;
76
- //# sourceMappingURL=EncryptionPublicKeyManager.js.map
76
+ //# sourceMappingURL=EncryptionPublicKeyManager.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptionPublicKeyManager.mjs","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAW1D,OAAO,EAAE,sBAAsB,EAAE,qCAAoC;AACrE,OAAO,EAAE,sCAAsC,EAAE,oBAAmB;AAEpE,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAkFjD;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,sBAM/C;IACC,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GAC6B;QAClC,KAAK,CAAC;YACJ,wBAAwB;YACxB,SAAS;YACT,IAAI,EAAE,WAAW;YACjB,uBAAuB;YACvB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,yBAAyB,CAC7B,aAAwC,EACxC,GAAoB;QAEpB,sCAAsC,CAAC,aAAa,CAAC,CAAC;QACtD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QAEtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CACtB,GAAG,SAAS,WAAW,EACvB,CAAC,IAAyB,EAAE,EAAE;gBAC5B,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;oBACpB,KAAK,UAAU;wBACb,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;oBACxC,KAAK,UAAU;wBACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,wEAAwE,CACzE,CACF,CAAC;oBACJ;wBACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,kDAAkD,IAAI,CAAC,SAAS,CAC9D,aAAa,CACd,EAAE,CACJ,CACF,CAAC;gBACN,CAAC;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,oBAAoB,CACxB,aAAwC,EACxC,GAAoB;QAEpB,MAAM,oBAAoB,GAAG,IAAI,CAAC,yBAAyB,CACzD,aAAa,EACb,GAAG,CACgC,CAAC;QAEtC,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAC9C,oBAAoB,EACpB,YAAY,CAAC,yBAAyB,EACtC,GAAG,CAC0B,CAAC;QAEhC,MAAM,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;QAEjC,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACnC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,oBAA6B,EAAE;YAChE,GAAG,oBAAoB;YACvB,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAgD;QAEhD,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;CACF;AAED,eAAe,0BAA0B,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n MessageRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager.js';\nimport { AbstractMessageManager } from './AbstractMessageManager.js';\nimport { validateEncryptionPublicKeyMessageData } from './utils.js';\n\nconst managerName = 'EncryptionPublicKeyManager';\n\nexport type EncryptionPublicKeyManagerState =\n MessageManagerState<EncryptionPublicKey>;\n\nexport type EncryptionPublicKeyManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type EncryptionPublicKeyManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\ntype EncryptionPublicKeyManagerActions = ControllerGetStateAction<\n typeof managerName,\n EncryptionPublicKeyManagerState\n>;\n\ntype EncryptionPublicKeyManagerEvents =\n | ControllerStateChangeEvent<\n typeof managerName,\n EncryptionPublicKeyManagerState\n >\n | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent\n | EncryptionPublicKeyManagerUpdateBadgeEvent;\n\nexport type EncryptionPublicKeyManagerMessenger = Messenger<\n typeof managerName,\n EncryptionPublicKeyManagerActions,\n EncryptionPublicKeyManagerEvents\n>;\n\ntype EncryptionPublicKeyManagerOptions = {\n messenger: EncryptionPublicKeyManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<EncryptionPublicKey>;\n additionalFinishStatuses?: string[];\n};\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 *\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 type EncryptionPublicKey = 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 *\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 type EncryptionPublicKeyParamsMetamask =\n 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 typeof managerName,\n EncryptionPublicKey,\n EncryptionPublicKeyParams,\n EncryptionPublicKeyParamsMetamask,\n EncryptionPublicKeyManagerMessenger\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: EncryptionPublicKeyManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\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 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?: MessageRequest,\n ): Promise<string> {\n validateEncryptionPublicKeyMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (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 /**\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?: MessageRequest,\n ): Promise<string> {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies EncryptionPublicKeyParams;\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthGetEncryptionPublicKey,\n req,\n ) satisfies EncryptionPublicKey;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messenger.publish(`${this.name}:unapprovedMessage` as const, {\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: EncryptionPublicKeyParamsMetamask,\n ): Promise<EncryptionPublicKeyParams> {\n delete messageParams.metamaskId;\n return Promise.resolve({ from: messageParams.data });\n }\n}\n\nexport default EncryptionPublicKeyManager;\n"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./AbstractMessageManager.cjs"), exports);
18
+ __exportStar(require("./EncryptionPublicKeyManager.cjs"), exports);
19
+ __exportStar(require("./DecryptMessageManager.cjs"), exports);
20
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA4C;AAC5C,mEAAgD;AAChD,8DAA2C","sourcesContent":["export * from './AbstractMessageManager.js';\nexport * from './EncryptionPublicKeyManager.js';\nexport * from './DecryptMessageManager.js';\nexport type * from './types.js';\n"]}
@@ -0,0 +1,5 @@
1
+ export * from "./AbstractMessageManager.cjs";
2
+ export * from "./EncryptionPublicKeyManager.cjs";
3
+ export * from "./DecryptMessageManager.cjs";
4
+ export type * from "./types.cjs";
5
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6CAA4C;AAC5C,iDAAgD;AAChD,4CAA2C;AAC3C,iCAAgC"}
@@ -0,0 +1,5 @@
1
+ export * from "./AbstractMessageManager.mjs";
2
+ export * from "./EncryptionPublicKeyManager.mjs";
3
+ export * from "./DecryptMessageManager.mjs";
4
+ export type * from "./types.mjs";
5
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6CAA4C;AAC5C,iDAAgD;AAChD,4CAA2C;AAC3C,iCAAgC"}
package/dist/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./AbstractMessageManager.mjs";
2
+ export * from "./EncryptionPublicKeyManager.mjs";
3
+ export * from "./DecryptMessageManager.mjs";
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6CAA4C;AAC5C,iDAAgD;AAChD,4CAA2C","sourcesContent":["export * from './AbstractMessageManager.js';\nexport * from './EncryptionPublicKeyManager.js';\nexport * from './DecryptMessageManager.js';\nexport type * from './types.js';\n"]}
package/dist/types.cjs ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SIWEMessage } from '@metamask/controller-utils';\n\nimport type { AbstractMessageParams } from './AbstractMessageManager.js';\n\n// Below types are have been moved into KeyringController, but are still exported here for backwards compatibility.\n\nexport type SignTypedDataMessageV3V4 = {\n types: Record<string, unknown>;\n domain: Record<string, unknown>;\n primaryType: string;\n message: unknown;\n};\n\nexport type PersonalMessageParams = {\n data: string;\n siwe?: SIWEMessage;\n} & AbstractMessageParams;\n\nexport type TypedMessageParams = {\n data: Record<string, unknown>[] | string | SignTypedDataMessageV3V4;\n} & AbstractMessageParams;\n"]}
@@ -1,5 +1,5 @@
1
- import type { SIWEMessage } from '@metamask/controller-utils';
2
- import type { AbstractMessageParams } from './AbstractMessageManager.js';
1
+ import type { SIWEMessage } from "@metamask/controller-utils";
2
+ import type { AbstractMessageParams } from "./AbstractMessageManager.cjs";
3
3
  export type SignTypedDataMessageV3V4 = {
4
4
  types: Record<string, unknown>;
5
5
  domain: Record<string, unknown>;
@@ -13,4 +13,4 @@ export type PersonalMessageParams = {
13
13
  export type TypedMessageParams = {
14
14
  data: Record<string, unknown>[] | string | SignTypedDataMessageV3V4;
15
15
  } & AbstractMessageParams;
16
- //# sourceMappingURL=types.d.ts.map
16
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,mCAAmC;AAE9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,qCAAoC;AAIzE,MAAM,MAAM,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,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB,GAAG,qBAAqB,CAAC;AAE1B,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,MAAM,GAAG,wBAAwB,CAAC;CACrE,GAAG,qBAAqB,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { SIWEMessage } from "@metamask/controller-utils";
2
+ import type { AbstractMessageParams } from "./AbstractMessageManager.mjs";
3
+ export type SignTypedDataMessageV3V4 = {
4
+ types: Record<string, unknown>;
5
+ domain: Record<string, unknown>;
6
+ primaryType: string;
7
+ message: unknown;
8
+ };
9
+ export type PersonalMessageParams = {
10
+ data: string;
11
+ siwe?: SIWEMessage;
12
+ } & AbstractMessageParams;
13
+ export type TypedMessageParams = {
14
+ data: Record<string, unknown>[] | string | SignTypedDataMessageV3V4;
15
+ } & AbstractMessageParams;
16
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,mCAAmC;AAE9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,qCAAoC;AAIzE,MAAM,MAAM,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,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB,GAAG,qBAAqB,CAAC;AAE1B,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,MAAM,GAAG,wBAAwB,CAAC;CACrE,GAAG,qBAAqB,CAAC"}
package/dist/types.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SIWEMessage } from '@metamask/controller-utils';\n\nimport type { AbstractMessageParams } from './AbstractMessageManager.js';\n\n// Below types are have been moved into KeyringController, but are still exported here for backwards compatibility.\n\nexport type SignTypedDataMessageV3V4 = {\n types: Record<string, unknown>;\n domain: Record<string, unknown>;\n primaryType: string;\n message: unknown;\n};\n\nexport type PersonalMessageParams = {\n data: string;\n siwe?: SIWEMessage;\n} & AbstractMessageParams;\n\nexport type TypedMessageParams = {\n data: Record<string, unknown>[] | string | SignTypedDataMessageV3V4;\n} & AbstractMessageParams;\n"]}
package/dist/utils.cjs ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateDecryptedMessageData = exports.validateEncryptionPublicKeyMessageData = exports.normalizeMessageData = void 0;
4
+ const controller_utils_1 = require("@metamask/controller-utils");
5
+ const utils_1 = require("@metamask/utils");
6
+ const hexRe = /^[0-9A-Fa-f]+$/gu;
7
+ /**
8
+ * Validates an address string and throws in the event of any validation error.
9
+ *
10
+ * @param address - The address to validate.
11
+ * @param propertyName - The name of the property source to use in the error message.
12
+ */
13
+ function validateAddress(address, propertyName) {
14
+ if (!address || typeof address !== 'string' || !(0, controller_utils_1.isValidHexAddress)(address)) {
15
+ throw new Error(`Invalid "${propertyName}" address: ${address} must be a valid string.`);
16
+ }
17
+ }
18
+ /**
19
+ * A helper function that converts rawmessageData buffer data to a hex, or just returns the data if
20
+ * it is already formatted as a hex.
21
+ *
22
+ * @param data - The buffer data to convert to a hex.
23
+ * @returns A hex string conversion of the buffer data.
24
+ */
25
+ function normalizeMessageData(data) {
26
+ try {
27
+ const stripped = (0, utils_1.remove0x)(data);
28
+ if (stripped.match(hexRe)) {
29
+ return (0, utils_1.add0x)(stripped);
30
+ }
31
+ }
32
+ catch (e) {
33
+ /* istanbul ignore next */
34
+ }
35
+ return (0, utils_1.bytesToHex)(Buffer.from(data, 'utf8'));
36
+ }
37
+ exports.normalizeMessageData = normalizeMessageData;
38
+ /**
39
+ * Validates messageData for the eth_getEncryptionPublicKey message and throws in
40
+ * the event of any validation error.
41
+ *
42
+ * @param messageData - address string to validate.
43
+ */
44
+ function validateEncryptionPublicKeyMessageData(messageData) {
45
+ const { from } = messageData;
46
+ validateAddress(from, 'from');
47
+ }
48
+ exports.validateEncryptionPublicKeyMessageData = validateEncryptionPublicKeyMessageData;
49
+ /**
50
+ * Validates messageData for the eth_decrypt message and throws in
51
+ * the event of any validation error.
52
+ *
53
+ * @param messageData - address string to validate.
54
+ */
55
+ function validateDecryptedMessageData(messageData) {
56
+ const { from } = messageData;
57
+ validateAddress(from, 'from');
58
+ }
59
+ exports.validateDecryptedMessageData = validateDecryptedMessageData;
60
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,iEAA+D;AAC/D,2CAA8D;AAK9D,MAAM,KAAK,GAAG,kBAAkB,CAAC;AACjC;;;;;GAKG;AACH,SAAS,eAAe,CAAC,OAAe,EAAE,YAAoB;IAC5D,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,IAAA,oCAAiB,EAAC,OAAO,CAAC,EAAE,CAAC;QAC3E,MAAM,IAAI,KAAK,CACb,YAAY,YAAY,cAAc,OAAO,0BAA0B,CACxE,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAAC,IAAY;IAC/C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC;QAChC,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAA,aAAK,EAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,0BAA0B;IAC5B,CAAC;IACD,OAAO,IAAA,kBAAU,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAC/C,CAAC;AAVD,oDAUC;AAED;;;;;GAKG;AACH,SAAgB,sCAAsC,CACpD,WAAsC;IAEtC,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;IAC7B,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAChC,CAAC;AALD,wFAKC;AAED;;;;;GAKG;AACH,SAAgB,4BAA4B,CAC1C,WAAiC;IAEjC,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;IAC7B,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAChC,CAAC;AALD,oEAKC","sourcesContent":["import { isValidHexAddress } from '@metamask/controller-utils';\nimport { add0x, bytesToHex, remove0x } from '@metamask/utils';\n\nimport type { DecryptMessageParams } from './DecryptMessageManager.js';\nimport type { EncryptionPublicKeyParams } from './EncryptionPublicKeyManager.js';\n\nconst hexRe = /^[0-9A-Fa-f]+$/gu;\n/**\n * Validates an address string and throws in the event of any validation error.\n *\n * @param address - The address to validate.\n * @param propertyName - The name of the property source to use in the error message.\n */\nfunction validateAddress(address: string, propertyName: string) {\n if (!address || typeof address !== 'string' || !isValidHexAddress(address)) {\n throw new Error(\n `Invalid \"${propertyName}\" address: ${address} must be a valid string.`,\n );\n }\n}\n\n/**\n * A helper function that converts rawmessageData buffer data to a hex, or just returns the data if\n * it is already formatted as a hex.\n *\n * @param data - The buffer data to convert to a hex.\n * @returns A hex string conversion of the buffer data.\n */\nexport function normalizeMessageData(data: string) {\n try {\n const stripped = remove0x(data);\n if (stripped.match(hexRe)) {\n return add0x(stripped);\n }\n } catch (e) {\n /* istanbul ignore next */\n }\n return bytesToHex(Buffer.from(data, 'utf8'));\n}\n\n/**\n * Validates messageData for the eth_getEncryptionPublicKey message and throws in\n * the event of any validation error.\n *\n * @param messageData - address string to validate.\n */\nexport function validateEncryptionPublicKeyMessageData(\n messageData: EncryptionPublicKeyParams,\n) {\n const { from } = messageData;\n validateAddress(from, 'from');\n}\n\n/**\n * Validates messageData for the eth_decrypt message and throws in\n * the event of any validation error.\n *\n * @param messageData - address string to validate.\n */\nexport function validateDecryptedMessageData(\n messageData: DecryptMessageParams,\n) {\n const { from } = messageData;\n validateAddress(from, 'from');\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { DecryptMessageParams } from './DecryptMessageManager.js';
2
- import type { EncryptionPublicKeyParams } from './EncryptionPublicKeyManager.js';
1
+ import type { DecryptMessageParams } from "./DecryptMessageManager.cjs";
2
+ import type { EncryptionPublicKeyParams } from "./EncryptionPublicKeyManager.cjs";
3
3
  /**
4
4
  * A helper function that converts rawmessageData buffer data to a hex, or just returns the data if
5
5
  * it is already formatted as a hex.
@@ -22,4 +22,4 @@ export declare function validateEncryptionPublicKeyMessageData(messageData: Encr
22
22
  * @param messageData - address string to validate.
23
23
  */
24
24
  export declare function validateDecryptedMessageData(messageData: DecryptMessageParams): void;
25
- //# sourceMappingURL=utils.d.ts.map
25
+ //# sourceMappingURL=utils.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,oCAAmC;AACvE,OAAO,KAAK,EAAE,yBAAyB,EAAE,yCAAwC;AAiBjF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,iBAUhD;AAED;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,WAAW,EAAE,yBAAyB,QAIvC;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,oBAAoB,QAIlC"}
@@ -0,0 +1,25 @@
1
+ import type { DecryptMessageParams } from "./DecryptMessageManager.mjs";
2
+ import type { EncryptionPublicKeyParams } from "./EncryptionPublicKeyManager.mjs";
3
+ /**
4
+ * A helper function that converts rawmessageData buffer data to a hex, or just returns the data if
5
+ * it is already formatted as a hex.
6
+ *
7
+ * @param data - The buffer data to convert to a hex.
8
+ * @returns A hex string conversion of the buffer data.
9
+ */
10
+ export declare function normalizeMessageData(data: string): `0x${string}`;
11
+ /**
12
+ * Validates messageData for the eth_getEncryptionPublicKey message and throws in
13
+ * the event of any validation error.
14
+ *
15
+ * @param messageData - address string to validate.
16
+ */
17
+ export declare function validateEncryptionPublicKeyMessageData(messageData: EncryptionPublicKeyParams): void;
18
+ /**
19
+ * Validates messageData for the eth_decrypt message and throws in
20
+ * the event of any validation error.
21
+ *
22
+ * @param messageData - address string to validate.
23
+ */
24
+ export declare function validateDecryptedMessageData(messageData: DecryptMessageParams): void;
25
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,oCAAmC;AACvE,OAAO,KAAK,EAAE,yBAAyB,EAAE,yCAAwC;AAiBjF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,iBAUhD;AAED;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,WAAW,EAAE,yBAAyB,QAIvC;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,oBAAoB,QAIlC"}
@@ -1,5 +1,5 @@
1
- import { isValidHexAddress } from '@metamask/controller-utils';
2
- import { add0x, bytesToHex, remove0x } from '@metamask/utils';
1
+ import { isValidHexAddress } from "@metamask/controller-utils";
2
+ import { add0x, bytesToHex, remove0x } from "@metamask/utils";
3
3
  const hexRe = /^[0-9A-Fa-f]+$/gu;
4
4
  /**
5
5
  * Validates an address string and throws in the event of any validation error.
@@ -51,4 +51,4 @@ export function validateDecryptedMessageData(messageData) {
51
51
  const { from } = messageData;
52
52
  validateAddress(from, 'from');
53
53
  }
54
- //# sourceMappingURL=utils.js.map
54
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mCAAmC;AAC/D,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,wBAAwB;AAK9D,MAAM,KAAK,GAAG,kBAAkB,CAAC;AACjC;;;;;GAKG;AACH,SAAS,eAAe,CAAC,OAAe,EAAE,YAAoB;IAC5D,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3E,MAAM,IAAI,KAAK,CACb,YAAY,YAAY,cAAc,OAAO,0BAA0B,CACxE,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,0BAA0B;IAC5B,CAAC;IACD,OAAO,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sCAAsC,CACpD,WAAsC;IAEtC,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;IAC7B,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAC1C,WAAiC;IAEjC,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;IAC7B,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { isValidHexAddress } from '@metamask/controller-utils';\nimport { add0x, bytesToHex, remove0x } from '@metamask/utils';\n\nimport type { DecryptMessageParams } from './DecryptMessageManager.js';\nimport type { EncryptionPublicKeyParams } from './EncryptionPublicKeyManager.js';\n\nconst hexRe = /^[0-9A-Fa-f]+$/gu;\n/**\n * Validates an address string and throws in the event of any validation error.\n *\n * @param address - The address to validate.\n * @param propertyName - The name of the property source to use in the error message.\n */\nfunction validateAddress(address: string, propertyName: string) {\n if (!address || typeof address !== 'string' || !isValidHexAddress(address)) {\n throw new Error(\n `Invalid \"${propertyName}\" address: ${address} must be a valid string.`,\n );\n }\n}\n\n/**\n * A helper function that converts rawmessageData buffer data to a hex, or just returns the data if\n * it is already formatted as a hex.\n *\n * @param data - The buffer data to convert to a hex.\n * @returns A hex string conversion of the buffer data.\n */\nexport function normalizeMessageData(data: string) {\n try {\n const stripped = remove0x(data);\n if (stripped.match(hexRe)) {\n return add0x(stripped);\n }\n } catch (e) {\n /* istanbul ignore next */\n }\n return bytesToHex(Buffer.from(data, 'utf8'));\n}\n\n/**\n * Validates messageData for the eth_getEncryptionPublicKey message and throws in\n * the event of any validation error.\n *\n * @param messageData - address string to validate.\n */\nexport function validateEncryptionPublicKeyMessageData(\n messageData: EncryptionPublicKeyParams,\n) {\n const { from } = messageData;\n validateAddress(from, 'from');\n}\n\n/**\n * Validates messageData for the eth_decrypt message and throws in\n * the event of any validation error.\n *\n * @param messageData - address string to validate.\n */\nexport function validateDecryptedMessageData(\n messageData: DecryptMessageParams,\n) {\n const { from } = messageData;\n validateAddress(from, 'from');\n}\n"]}