@metamask-previews/message-manager 14.1.2-preview-7aad920a3 → 14.1.2-preview-0dfe3b334
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DecryptMessageManager.cjs +5 -5
- package/dist/DecryptMessageManager.cjs.map +1 -1
- package/dist/DecryptMessageManager.d.cts.map +1 -1
- package/dist/DecryptMessageManager.d.mts.map +1 -1
- package/dist/DecryptMessageManager.mjs.map +1 -1
- package/dist/EncryptionPublicKeyManager.cjs +4 -4
- package/dist/EncryptionPublicKeyManager.cjs.map +1 -1
- package/dist/EncryptionPublicKeyManager.d.cts.map +1 -1
- package/dist/EncryptionPublicKeyManager.d.mts.map +1 -1
- package/dist/EncryptionPublicKeyManager.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DecryptMessageManager = void 0;
|
|
4
4
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const AbstractMessageManager_js_1 = require("./AbstractMessageManager.cjs");
|
|
6
|
+
const utils_js_1 = require("./utils.cjs");
|
|
7
7
|
const managerName = 'DecryptMessageManager';
|
|
8
8
|
/**
|
|
9
9
|
* Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.
|
|
10
10
|
*/
|
|
11
|
-
class DecryptMessageManager extends
|
|
11
|
+
class DecryptMessageManager extends AbstractMessageManager_js_1.AbstractMessageManager {
|
|
12
12
|
constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }) {
|
|
13
13
|
super({
|
|
14
14
|
additionalFinishStatuses,
|
|
@@ -27,7 +27,7 @@ class DecryptMessageManager extends AbstractMessageManager_1.AbstractMessageMana
|
|
|
27
27
|
* @returns Promise resolving to the raw data of the signature request.
|
|
28
28
|
*/
|
|
29
29
|
async addUnapprovedMessageAsync(messageParams, req) {
|
|
30
|
-
(0,
|
|
30
|
+
(0, utils_js_1.validateDecryptedMessageData)(messageParams);
|
|
31
31
|
const messageId = await this.addUnapprovedMessage(messageParams, req);
|
|
32
32
|
return new Promise((resolve, reject) => {
|
|
33
33
|
this.internalEvents.once(`${messageId}:finished`, (data) => {
|
|
@@ -56,7 +56,7 @@ class DecryptMessageManager extends AbstractMessageManager_1.AbstractMessageMana
|
|
|
56
56
|
*/
|
|
57
57
|
async addUnapprovedMessage(messageParams, req) {
|
|
58
58
|
const updatedMessageParams = this.addRequestToMessageParams(messageParams, req);
|
|
59
|
-
messageParams.data = (0,
|
|
59
|
+
messageParams.data = (0, utils_js_1.normalizeMessageData)(messageParams.data);
|
|
60
60
|
const messageData = this.createUnapprovedMessage(updatedMessageParams, controller_utils_1.ApprovalType.EthDecrypt, req);
|
|
61
61
|
const messageId = messageData.id;
|
|
62
62
|
await this.addMessage(messageData);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecryptMessageManager.cjs","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":";;;AAIA,iEAA0D;AAY1D,
|
|
1
|
+
{"version":3,"file":"DecryptMessageManager.cjs","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":";;;AAIA,iEAA0D;AAY1D,4EAAqE;AACrE,0CAAgF;AAEhF,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAgF5C;;GAEG;AACH,MAAa,qBAAsB,SAAQ,kDAM1C;IACC,YAAY,EACV,wBAAwB,EACxB,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QAE9D,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAC9C,oBAAoB,EACpB,+BAAY,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;AAvHD,sDAuHC","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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecryptMessageManager.d.cts","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,cAAc,EACd,uBAAuB,EACxB,
|
|
1
|
+
{"version":3,"file":"DecryptMessageManager.d.cts","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,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,0BAA0B,CAAC;AAE5C,MAAM,MAAM,0BAA0B,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,GAAG,OAAO,WAAW,oBAAoB,CAAC;IAChD,OAAO,EAAE,CAAC,6BAA6B,CAAC,CAAC;CAC1C,CAAC;AAEF,M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c,GACnB,OAAO,CAAC,MAAM,CAAC;IAqClB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,cAAc;IAwBtB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,4BAA4B,GAC1C,OAAO,CAAC,oBAAoB,CAAC;CAIjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecryptMessageManager.d.mts","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,cAAc,EACd,uBAAuB,EACxB,
|
|
1
|
+
{"version":3,"file":"DecryptMessageManager.d.mts","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,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,0BAA0B,CAAC;AAE5C,MAAM,MAAM,0BAA0B,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,GAAG,OAAO,WAAW,oBAAoB,CAAC;IAChD,OAAO,EAAE,CAAC,6BAA6B,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,GAAG,OAAO,WAAW,cAAc,CA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xB,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,cAAc;IAwBtB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,4BAA4B,GAC1C,OAAO,CAAC,oBAAoB,CAAC;CAIjC"}
|
|
@@ -1 +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,
|
|
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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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"]}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EncryptionPublicKeyManager = void 0;
|
|
4
4
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const AbstractMessageManager_js_1 = require("./AbstractMessageManager.cjs");
|
|
6
|
+
const utils_js_1 = require("./utils.cjs");
|
|
7
7
|
const managerName = 'EncryptionPublicKeyManager';
|
|
8
8
|
/**
|
|
9
9
|
* Controller in charge of managing - storing, adding, removing, updating - Messages.
|
|
10
10
|
*/
|
|
11
|
-
class EncryptionPublicKeyManager extends
|
|
11
|
+
class EncryptionPublicKeyManager extends AbstractMessageManager_js_1.AbstractMessageManager {
|
|
12
12
|
constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }) {
|
|
13
13
|
super({
|
|
14
14
|
additionalFinishStatuses,
|
|
@@ -27,7 +27,7 @@ class EncryptionPublicKeyManager extends AbstractMessageManager_1.AbstractMessag
|
|
|
27
27
|
* @returns Promise resolving to the raw data of the request.
|
|
28
28
|
*/
|
|
29
29
|
async addUnapprovedMessageAsync(messageParams, req) {
|
|
30
|
-
(0,
|
|
30
|
+
(0, utils_js_1.validateEncryptionPublicKeyMessageData)(messageParams);
|
|
31
31
|
const messageId = await this.addUnapprovedMessage(messageParams, req);
|
|
32
32
|
return new Promise((resolve, reject) => {
|
|
33
33
|
this.internalEvents.once(`${messageId}:finished`, (data) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptionPublicKeyManager.cjs","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":";;;AAIA,iEAA0D;AAW1D,
|
|
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;IA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,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 +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,
|
|
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,W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nB,aAAa,EAAE,iCAAiC,GAC/C,OAAO,CAAC,yBAAyB,CAAC;CAItC;AAED,eAAe,0BAA0B,CAAC"}
|
|
@@ -1 +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,
|
|
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,CACh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,GAC/C,OAAO,CAAC,yBAAyB,CAAC;CAItC;AAED,eAAe,0BAA0B,CAAC"}
|
|
@@ -1 +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,
|
|
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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+
|
|
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"]}
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6CAA4C;AAC5C,iDAAgD;AAChD,4CAA2C;AAC3C,iCAAgC"}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
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.map
CHANGED
|
@@ -1 +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';\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
|
+
{"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"]}
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +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,
|
|
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"}
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +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,
|
|
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.map
CHANGED
|
@@ -1 +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';\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
|
+
{"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.map
CHANGED
|
@@ -1 +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';\nimport type { EncryptionPublicKeyParams } from './EncryptionPublicKeyManager';\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
|
+
{"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"]}
|
package/dist/utils.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,
|
|
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"}
|
package/dist/utils.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,
|
|
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,EAA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A4B,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';\nimport type { EncryptionPublicKeyParams } from './EncryptionPublicKeyManager';\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
|
+
{"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"]}
|