@metamask-previews/message-manager 7.3.6-preview.3fbb6b41 → 7.3.7-preview.353ee83b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [7.3.7]
10
+ ### Changed
11
+ - Bump `@metamask/base-controller` to `^4.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695))
12
+ - Bump `@metamask/controller-utils` to `^8.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695), [#3678](https://github.com/MetaMask/core/pull/3678), [#3667](https://github.com/MetaMask/core/pull/3667), [#3580](https://github.com/MetaMask/core/pull/3580))
13
+ - Bump `@metamask/eth-sig-util` to `^7.0.1` ([#3614](https://github.com/MetaMask/core/pull/3614))
14
+
9
15
  ## [7.3.6]
10
16
  ### Changed
11
17
  - Bump `@metamask/utils` to ^8.2.0 ([#1957](https://github.com/MetaMask/core/pull/1957))
@@ -133,7 +139,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
133
139
 
134
140
  All changes listed after this point were applied to this package following the monorepo conversion.
135
141
 
136
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.3.6...HEAD
142
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.3.7...HEAD
143
+ [7.3.7]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.3.6...@metamask/message-manager@7.3.7
137
144
  [7.3.6]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.3.5...@metamask/message-manager@7.3.6
138
145
  [7.3.5]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.3.4...@metamask/message-manager@7.3.5
139
146
  [7.3.4]: https://github.com/MetaMask/core/compare/@metamask/message-manager@7.3.3...@metamask/message-manager@7.3.4
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAI3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAiBhE;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,UAUhD;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,qBAAqB,GAAG,aAAa,QAQnD;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,kBAAkB,QAgBhC;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,WAAW,EAAE,kBAAkB,EAC/B,cAAc,EAAE,GAAG,GAAG,SAAS,QAwDhC;AAED;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,WAAW,EAAE,yBAAyB,QAIvC;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,oBAAoB,QAIlC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAI3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAiBhE;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,UAUhD;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,qBAAqB,GAAG,aAAa,QAQnD;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,kBAAkB,QAkBhC;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,WAAW,EAAE,kBAAkB,EAC/B,cAAc,EAAE,GAAG,GAAG,SAAS,QAwDhC;AAED;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,WAAW,EAAE,yBAAyB,QAIvC;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,oBAAoB,QAIlC"}
package/dist/utils.js CHANGED
@@ -64,6 +64,8 @@ function validateTypedSignMessageDataV1(messageData) {
64
64
  }
65
65
  try {
66
66
  // typedSignatureHash will throw if the data is invalid.
67
+ // TODO: Replace `any` with type
68
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
69
  (0, eth_sig_util_1.typedSignatureHash)(messageData.data);
68
70
  }
69
71
  catch (e) {
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,iEAA+D;AAC/D,yDAGgC;AAEhC,qDAA4E;AAC5E,2CAAsC;AAQtC,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;QAC1E,MAAM,IAAI,KAAK,CACb,YAAY,YAAY,cAAc,OAAO,0BAA0B,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AED,MAAM,aAAa,GAAG,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;QACnD,IAAI,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE;YAC/B,MAAM,IAAI,KAAK,CACb,qCAAqC,OAAO,4CAA4C,CACzF,CAAC;SACH;QAED,IAAI,OAAO,KAAK,aAAa,EAAE;YAC7B,MAAM,IAAI,KAAK,CACb,qBAAqB,OAAO,oCAAoC,aAAa,GAAG,CACjF,CAAC;SACH;KACF;AACH,CAAC;AA1DD,4EA0DC;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 {\n TYPED_MESSAGE_SCHEMA,\n typedSignatureHash,\n} from '@metamask/eth-sig-util';\nimport type { Hex } from '@metamask/utils';\nimport { addHexPrefix, bufferToHex, stripHexPrefix } from 'ethereumjs-util';\nimport { validate } from 'jsonschema';\n\nimport type { DecryptMessageParams } from './DecryptMessageManager';\nimport type { EncryptionPublicKeyParams } from './EncryptionPublicKeyManager';\nimport type { MessageParams } from './MessageManager';\nimport type { PersonalMessageParams } from './PersonalMessageManager';\nimport type { TypedMessageParams } from './TypedMessageManager';\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 = stripHexPrefix(data);\n if (stripped.match(hexRe)) {\n return addHexPrefix(stripped);\n }\n } catch (e) {\n /* istanbul ignore next */\n }\n return bufferToHex(Buffer.from(data, 'utf8'));\n}\n\n/**\n * Validates a PersonalMessageParams and MessageParams objects for required properties and throws in\n * the event of any validation error.\n *\n * @param messageData - PersonalMessageParams object to validate.\n */\nexport function validateSignMessageData(\n messageData: PersonalMessageParams | MessageParams,\n) {\n const { from, data } = messageData;\n validateAddress(from, 'from');\n\n if (!data || typeof data !== 'string') {\n throw new Error(`Invalid message \"data\": ${data} must be a valid string.`);\n }\n}\n\n/**\n * Validates a TypedMessageParams object for required properties and throws in\n * the event of any validation error for eth_signTypedMessage_V1.\n *\n * @param messageData - TypedMessageParams object to validate.\n */\nexport function validateTypedSignMessageDataV1(\n messageData: TypedMessageParams,\n) {\n validateAddress(messageData.from, 'from');\n\n if (!messageData.data || !Array.isArray(messageData.data)) {\n throw new Error(\n `Invalid message \"data\": ${messageData.data} must be a valid array.`,\n );\n }\n\n try {\n // typedSignatureHash will throw if the data is invalid.\n typedSignatureHash(messageData.data as any);\n } catch (e) {\n throw new Error(`Expected EIP712 typed data.`);\n }\n}\n\n/**\n * Validates a TypedMessageParams object for required properties and throws in\n * the event of any validation error for eth_signTypedMessage_V3.\n *\n * @param messageData - TypedMessageParams object to validate.\n * @param currentChainId - The current chainId.\n */\nexport function validateTypedSignMessageDataV3V4(\n messageData: TypedMessageParams,\n currentChainId: Hex | undefined,\n) {\n validateAddress(messageData.from, 'from');\n\n if (\n !messageData.data ||\n Array.isArray(messageData.data) ||\n (typeof messageData.data !== 'object' &&\n typeof messageData.data !== 'string')\n ) {\n throw new Error(\n `Invalid message \"data\": Must be a valid string or object.`,\n );\n }\n\n let data;\n if (typeof messageData.data === 'object') {\n data = messageData.data;\n } else {\n try {\n data = JSON.parse(messageData.data);\n } catch (e) {\n throw new Error('Data must be passed as a valid JSON string.');\n }\n }\n\n const validation = validate(data, TYPED_MESSAGE_SCHEMA);\n if (validation.errors.length > 0) {\n throw new Error(\n 'Data must conform to EIP-712 schema. See https://git.io/fNtcx.',\n );\n }\n\n if (!currentChainId) {\n throw new Error('Current chainId cannot be null or undefined.');\n }\n\n let { chainId } = data.domain;\n if (chainId) {\n if (typeof chainId === 'string') {\n chainId = parseInt(chainId, chainId.startsWith('0x') ? 16 : 10);\n }\n\n const activeChainId = parseInt(currentChainId, 16);\n if (Number.isNaN(activeChainId)) {\n throw new Error(\n `Cannot sign messages for chainId \"${chainId}\", because MetaMask is switching networks.`,\n );\n }\n\n if (chainId !== activeChainId) {\n throw new Error(\n `Provided chainId \"${chainId}\" must match the active chainId \"${activeChainId}\"`,\n );\n }\n }\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.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,iEAA+D;AAC/D,yDAGgC;AAEhC,qDAA4E;AAC5E,2CAAsC;AAQtC,MAAM,KAAK,GAAG,kBAAkB,CAAC;AACjC;;;;;GAKG;AACH,SAAS,eAAe,CAAC,OAAe,EAAE,YAAoB;IAC5D,IAAI,CAAC,OAAO,IAAI,OAAO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K,QAAQ,EAAE;YAC/B,OAAO,GAAG,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SACjE;QAED,MAAM,aAAa,GAAG,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;QACnD,IAAI,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE;YAC/B,MAAM,IAAI,KAAK,CACb,qCAAqC,OAAO,4CAA4C,CACzF,CAAC;SACH;QAED,IAAI,OAAO,KAAK,aAAa,EAAE;YAC7B,MAAM,IAAI,KAAK,CACb,qBAAqB,OAAO,oCAAoC,aAAa,GAAG,CACjF,CAAC;SACH;KACF;AACH,CAAC;AA1DD,4EA0DC;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 {\n TYPED_MESSAGE_SCHEMA,\n typedSignatureHash,\n} from '@metamask/eth-sig-util';\nimport type { Hex } from '@metamask/utils';\nimport { addHexPrefix, bufferToHex, stripHexPrefix } from 'ethereumjs-util';\nimport { validate } from 'jsonschema';\n\nimport type { DecryptMessageParams } from './DecryptMessageManager';\nimport type { EncryptionPublicKeyParams } from './EncryptionPublicKeyManager';\nimport type { MessageParams } from './MessageManager';\nimport type { PersonalMessageParams } from './PersonalMessageManager';\nimport type { TypedMessageParams } from './TypedMessageManager';\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 = stripHexPrefix(data);\n if (stripped.match(hexRe)) {\n return addHexPrefix(stripped);\n }\n } catch (e) {\n /* istanbul ignore next */\n }\n return bufferToHex(Buffer.from(data, 'utf8'));\n}\n\n/**\n * Validates a PersonalMessageParams and MessageParams objects for required properties and throws in\n * the event of any validation error.\n *\n * @param messageData - PersonalMessageParams object to validate.\n */\nexport function validateSignMessageData(\n messageData: PersonalMessageParams | MessageParams,\n) {\n const { from, data } = messageData;\n validateAddress(from, 'from');\n\n if (!data || typeof data !== 'string') {\n throw new Error(`Invalid message \"data\": ${data} must be a valid string.`);\n }\n}\n\n/**\n * Validates a TypedMessageParams object for required properties and throws in\n * the event of any validation error for eth_signTypedMessage_V1.\n *\n * @param messageData - TypedMessageParams object to validate.\n */\nexport function validateTypedSignMessageDataV1(\n messageData: TypedMessageParams,\n) {\n validateAddress(messageData.from, 'from');\n\n if (!messageData.data || !Array.isArray(messageData.data)) {\n throw new Error(\n `Invalid message \"data\": ${messageData.data} must be a valid array.`,\n );\n }\n\n try {\n // typedSignatureHash will throw if the data is invalid.\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typedSignatureHash(messageData.data as any);\n } catch (e) {\n throw new Error(`Expected EIP712 typed data.`);\n }\n}\n\n/**\n * Validates a TypedMessageParams object for required properties and throws in\n * the event of any validation error for eth_signTypedMessage_V3.\n *\n * @param messageData - TypedMessageParams object to validate.\n * @param currentChainId - The current chainId.\n */\nexport function validateTypedSignMessageDataV3V4(\n messageData: TypedMessageParams,\n currentChainId: Hex | undefined,\n) {\n validateAddress(messageData.from, 'from');\n\n if (\n !messageData.data ||\n Array.isArray(messageData.data) ||\n (typeof messageData.data !== 'object' &&\n typeof messageData.data !== 'string')\n ) {\n throw new Error(\n `Invalid message \"data\": Must be a valid string or object.`,\n );\n }\n\n let data;\n if (typeof messageData.data === 'object') {\n data = messageData.data;\n } else {\n try {\n data = JSON.parse(messageData.data);\n } catch (e) {\n throw new Error('Data must be passed as a valid JSON string.');\n }\n }\n\n const validation = validate(data, TYPED_MESSAGE_SCHEMA);\n if (validation.errors.length > 0) {\n throw new Error(\n 'Data must conform to EIP-712 schema. See https://git.io/fNtcx.',\n );\n }\n\n if (!currentChainId) {\n throw new Error('Current chainId cannot be null or undefined.');\n }\n\n let { chainId } = data.domain;\n if (chainId) {\n if (typeof chainId === 'string') {\n chainId = parseInt(chainId, chainId.startsWith('0x') ? 16 : 10);\n }\n\n const activeChainId = parseInt(currentChainId, 16);\n if (Number.isNaN(activeChainId)) {\n throw new Error(\n `Cannot sign messages for chainId \"${chainId}\", because MetaMask is switching networks.`,\n );\n }\n\n if (chainId !== activeChainId) {\n throw new Error(\n `Provided chainId \"${chainId}\" must match the active chainId \"${activeChainId}\"`,\n );\n }\n }\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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/message-manager",
3
- "version": "7.3.6-preview.3fbb6b41",
3
+ "version": "7.3.7-preview.353ee83b",
4
4
  "description": "Stores and manages interactions with signing requests",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -22,6 +22,7 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "build:docs": "typedoc",
25
+ "changelog:update": "../../scripts/update-changelog.sh @metamask/message-manager",
25
26
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/message-manager",
26
27
  "publish:preview": "yarn npm publish --tag preview",
27
28
  "test": "jest --reporters=jest-silent-reporter",
@@ -30,8 +31,8 @@
30
31
  "test:watch": "jest --watch"
31
32
  },
32
33
  "dependencies": {
33
- "@metamask/base-controller": "^4.0.0",
34
- "@metamask/controller-utils": "^6.1.0",
34
+ "@metamask/base-controller": "^4.0.1",
35
+ "@metamask/controller-utils": "^8.0.1",
35
36
  "@metamask/eth-sig-util": "^7.0.1",
36
37
  "@metamask/utils": "^8.2.0",
37
38
  "@types/uuid": "^8.3.0",
@@ -40,7 +41,7 @@
40
41
  "uuid": "^8.3.2"
41
42
  },
42
43
  "devDependencies": {
43
- "@metamask/auto-changelog": "^3.4.3",
44
+ "@metamask/auto-changelog": "^3.4.4",
44
45
  "@types/jest": "^27.4.1",
45
46
  "deepmerge": "^4.2.2",
46
47
  "jest": "^27.5.1",