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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/index.cjs +1 -2
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +1 -2
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.mts +1 -2
  7. package/dist/index.d.mts.map +1 -1
  8. package/dist/index.mjs +1 -2
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/types.cjs +3 -0
  11. package/dist/types.cjs.map +1 -0
  12. package/dist/types.d.cts +16 -0
  13. package/dist/types.d.cts.map +1 -0
  14. package/dist/types.d.mts +16 -0
  15. package/dist/types.d.mts.map +1 -0
  16. package/dist/types.mjs +2 -0
  17. package/dist/types.mjs.map +1 -0
  18. package/dist/utils.cjs +1 -97
  19. package/dist/utils.cjs.map +1 -1
  20. package/dist/utils.d.cts +0 -25
  21. package/dist/utils.d.cts.map +1 -1
  22. package/dist/utils.d.mts +0 -25
  23. package/dist/utils.d.mts.map +1 -1
  24. package/dist/utils.mjs +0 -94
  25. package/dist/utils.mjs.map +1 -1
  26. package/package.json +1 -1
  27. package/dist/PersonalMessageManager.cjs +0 -58
  28. package/dist/PersonalMessageManager.cjs.map +0 -1
  29. package/dist/PersonalMessageManager.d.cts +0 -72
  30. package/dist/PersonalMessageManager.d.cts.map +0 -1
  31. package/dist/PersonalMessageManager.d.mts +0 -72
  32. package/dist/PersonalMessageManager.d.mts.map +0 -1
  33. package/dist/PersonalMessageManager.mjs +0 -54
  34. package/dist/PersonalMessageManager.mjs.map +0 -1
  35. package/dist/TypedMessageManager.cjs +0 -87
  36. package/dist/TypedMessageManager.cjs.map +0 -1
  37. package/dist/TypedMessageManager.d.cts +0 -98
  38. package/dist/TypedMessageManager.d.cts.map +0 -1
  39. package/dist/TypedMessageManager.d.mts +0 -98
  40. package/dist/TypedMessageManager.d.mts.map +0 -1
  41. package/dist/TypedMessageManager.mjs +0 -83
  42. package/dist/TypedMessageManager.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Removed
11
+
12
+ - Remove all code related to `@metamask/signature-controller` ([#4785](https://github.com/MetaMask/core/pull/4785))
13
+ - Remove `TypedMessageManager`.
14
+ - Remove `PersonalMessageManager`.
15
+ - Remove utils:
16
+ - `validateSignMessageData`
17
+ - `validateTypedSignMessageDataV1`
18
+ - `validateTypedSignMessageDataV3V4`
19
+
10
20
  ## [10.1.1]
11
21
 
12
22
  ### Fixed
package/dist/index.cjs CHANGED
@@ -15,8 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./AbstractMessageManager.cjs"), exports);
18
- __exportStar(require("./PersonalMessageManager.cjs"), exports);
19
- __exportStar(require("./TypedMessageManager.cjs"), exports);
20
18
  __exportStar(require("./EncryptionPublicKeyManager.cjs"), exports);
21
19
  __exportStar(require("./DecryptMessageManager.cjs"), exports);
20
+ __exportStar(require("./types.cjs"), exports);
22
21
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAAyC;AACzC,+DAAyC;AACzC,4DAAsC;AACtC,mEAA6C;AAC7C,8DAAwC","sourcesContent":["export * from './AbstractMessageManager';\nexport * from './PersonalMessageManager';\nexport * from './TypedMessageManager';\nexport * from './EncryptionPublicKeyManager';\nexport * from './DecryptMessageManager';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAAyC;AACzC,mEAA6C;AAC7C,8DAAwC;AACxC,8CAAwB","sourcesContent":["export * from './AbstractMessageManager';\nexport * from './EncryptionPublicKeyManager';\nexport * from './DecryptMessageManager';\nexport * from './types';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from "./AbstractMessageManager.cjs";
2
- export * from "./PersonalMessageManager.cjs";
3
- export * from "./TypedMessageManager.cjs";
4
2
  export * from "./EncryptionPublicKeyManager.cjs";
5
3
  export * from "./DecryptMessageManager.cjs";
4
+ export * from "./types.cjs";
6
5
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6CAAyC;AACzC,6CAAyC;AACzC,0CAAsC;AACtC,iDAA6C;AAC7C,4CAAwC"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6CAAyC;AACzC,iDAA6C;AAC7C,4CAAwC;AACxC,4BAAwB"}
package/dist/index.d.mts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from "./AbstractMessageManager.mjs";
2
- export * from "./PersonalMessageManager.mjs";
3
- export * from "./TypedMessageManager.mjs";
4
2
  export * from "./EncryptionPublicKeyManager.mjs";
5
3
  export * from "./DecryptMessageManager.mjs";
4
+ export * from "./types.mjs";
6
5
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6CAAyC;AACzC,6CAAyC;AACzC,0CAAsC;AACtC,iDAA6C;AAC7C,4CAAwC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6CAAyC;AACzC,iDAA6C;AAC7C,4CAAwC;AACxC,4BAAwB"}
package/dist/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from "./AbstractMessageManager.mjs";
2
- export * from "./PersonalMessageManager.mjs";
3
- export * from "./TypedMessageManager.mjs";
4
2
  export * from "./EncryptionPublicKeyManager.mjs";
5
3
  export * from "./DecryptMessageManager.mjs";
4
+ export * from "./types.mjs";
6
5
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6CAAyC;AACzC,6CAAyC;AACzC,0CAAsC;AACtC,iDAA6C;AAC7C,4CAAwC","sourcesContent":["export * from './AbstractMessageManager';\nexport * from './PersonalMessageManager';\nexport * from './TypedMessageManager';\nexport * from './EncryptionPublicKeyManager';\nexport * from './DecryptMessageManager';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6CAAyC;AACzC,iDAA6C;AAC7C,4CAAwC;AACxC,4BAAwB","sourcesContent":["export * from './AbstractMessageManager';\nexport * from './EncryptionPublicKeyManager';\nexport * from './DecryptMessageManager';\nexport * from './types';\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';\n\n// Below types are temporary as they are in use by the KeyringController.\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"]}
@@ -0,0 +1,16 @@
1
+ import type { SIWEMessage } from "@metamask/controller-utils";
2
+ import type { AbstractMessageParams } from "./AbstractMessageManager.cjs";
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.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,qCAAiC;AAItE,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,qCAAiC;AAItE,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';\n\n// Below types are temporary as they are in use by the KeyringController.\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 CHANGED
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateDecryptedMessageData = exports.validateEncryptionPublicKeyMessageData = exports.validateTypedSignMessageDataV3V4 = exports.validateTypedSignMessageDataV1 = exports.validateSignMessageData = exports.normalizeMessageData = void 0;
3
+ exports.validateDecryptedMessageData = exports.validateEncryptionPublicKeyMessageData = exports.normalizeMessageData = void 0;
4
4
  const controller_utils_1 = require("@metamask/controller-utils");
5
- const eth_sig_util_1 = require("@metamask/eth-sig-util");
6
5
  const utils_1 = require("@metamask/utils");
7
- const jsonschema_1 = require("jsonschema");
8
6
  const hexRe = /^[0-9A-Fa-f]+$/gu;
9
7
  /**
10
8
  * Validates an address string and throws in the event of any validation error.
@@ -37,100 +35,6 @@ function normalizeMessageData(data) {
37
35
  return (0, utils_1.bytesToHex)(Buffer.from(data, 'utf8'));
38
36
  }
39
37
  exports.normalizeMessageData = normalizeMessageData;
40
- /**
41
- * Validates a PersonalMessageParams objects for required properties and throws in
42
- * the event of any validation error.
43
- *
44
- * @param messageData - PersonalMessageParams object to validate.
45
- */
46
- function validateSignMessageData(messageData) {
47
- const { from, data } = messageData;
48
- validateAddress(from, 'from');
49
- if (!data || typeof data !== 'string') {
50
- throw new Error(`Invalid message "data": ${data} must be a valid string.`);
51
- }
52
- }
53
- exports.validateSignMessageData = validateSignMessageData;
54
- /**
55
- * Validates a TypedMessageParams object for required properties and throws in
56
- * the event of any validation error for eth_signTypedMessage_V1.
57
- *
58
- * @param messageData - TypedMessageParams object to validate.
59
- */
60
- function validateTypedSignMessageDataV1(messageData) {
61
- validateAddress(messageData.from, 'from');
62
- if (!messageData.data || !Array.isArray(messageData.data)) {
63
- throw new Error(
64
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
65
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
66
- `Invalid message "data": ${messageData.data} must be a valid array.`);
67
- }
68
- try {
69
- // typedSignatureHash will throw if the data is invalid.
70
- // TODO: Replace `any` with type
71
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
- (0, eth_sig_util_1.typedSignatureHash)(messageData.data);
73
- }
74
- catch (e) {
75
- throw new Error(`Expected EIP712 typed data.`);
76
- }
77
- }
78
- exports.validateTypedSignMessageDataV1 = validateTypedSignMessageDataV1;
79
- /**
80
- * Validates a TypedMessageParams object for required properties and throws in
81
- * the event of any validation error for eth_signTypedMessage_V3.
82
- *
83
- * @param messageData - TypedMessageParams object to validate.
84
- * @param currentChainId - The current chainId.
85
- */
86
- function validateTypedSignMessageDataV3V4(messageData, currentChainId) {
87
- validateAddress(messageData.from, 'from');
88
- if (!messageData.data ||
89
- Array.isArray(messageData.data) ||
90
- (typeof messageData.data !== 'object' &&
91
- typeof messageData.data !== 'string')) {
92
- throw new Error(`Invalid message "data": Must be a valid string or object.`);
93
- }
94
- let data;
95
- if (typeof messageData.data === 'object') {
96
- data = messageData.data;
97
- }
98
- else {
99
- try {
100
- data = JSON.parse(messageData.data);
101
- }
102
- catch (e) {
103
- throw new Error('Data must be passed as a valid JSON string.');
104
- }
105
- }
106
- const validation = (0, jsonschema_1.validate)(data, eth_sig_util_1.TYPED_MESSAGE_SCHEMA);
107
- if (validation.errors.length > 0) {
108
- throw new Error('Data must conform to EIP-712 schema. See https://git.io/fNtcx.');
109
- }
110
- if (!currentChainId) {
111
- throw new Error('Current chainId cannot be null or undefined.');
112
- }
113
- let { chainId } = data.domain;
114
- if (chainId) {
115
- if (typeof chainId === 'string') {
116
- chainId = parseInt(chainId, chainId.startsWith('0x') ? 16 : 10);
117
- }
118
- const activeChainId = parseInt(currentChainId, 16);
119
- if (Number.isNaN(activeChainId)) {
120
- throw new Error(
121
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
122
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
123
- `Cannot sign messages for chainId "${chainId}", because MetaMask is switching networks.`);
124
- }
125
- if (chainId !== activeChainId) {
126
- throw new Error(
127
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
128
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
129
- `Provided chainId "${chainId}" must match the active chainId "${activeChainId}"`);
130
- }
131
- }
132
- }
133
- exports.validateTypedSignMessageDataV3V4 = validateTypedSignMessageDataV3V4;
134
38
  /**
135
39
  * Validates messageData for the eth_getEncryptionPublicKey message and throws in
136
40
  * the event of any validation error.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,iEAA+D;AAC/D,yDAGgC;AAEhC,2CAA8D;AAC9D,2CAAsC;AAOtC,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,CACxE,CAAC;KACH;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAAC,IAAY;IAC/C,IAAI;QACF,MAAM,QAAQ,GAAG,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC;QAChC,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YACzB,OAAO,IAAA,aAAK,EAAC,QAAQ,CAAC,CAAC;SACxB;KACF;IAAC,OAAO,CAAC,EAAE;QACV,0BAA0B;KAC3B;IACD,OAAO,IAAA,kBAAU,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAC/C,CAAC;AAVD,oDAU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KACF;AACH,CAAC;AA9DD,4EA8DC;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 { add0x, bytesToHex, remove0x } from '@metamask/utils';\nimport { validate } from 'jsonschema';\n\nimport type { DecryptMessageParams } from './DecryptMessageManager';\nimport type { EncryptionPublicKeyParams } from './EncryptionPublicKeyManager';\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 = 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 a PersonalMessageParams 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(messageData: PersonalMessageParams) {\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 // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\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 // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Cannot sign messages for chainId \"${chainId}\", because MetaMask is switching networks.`,\n );\n }\n\n if (chainId !== activeChainId) {\n throw new Error(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\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.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;QAC1E,MAAM,IAAI,KAAK,CACb,YAAY,YAAY,cAAc,OAAO,0BAA0B,CACxE,CAAC;KACH;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAAC,IAAY;IAC/C,IAAI;QACF,MAAM,QAAQ,GAAG,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC;QAChC,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YACzB,OAAO,IAAA,aAAK,EAAC,QAAQ,CAAC,CAAC;SACxB;KACF;IAAC,OAAO,CAAC,EAAE;QACV,0BAA0B;KAC3B;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"]}
package/dist/utils.d.cts CHANGED
@@ -1,8 +1,5 @@
1
- import type { Hex } from "@metamask/utils";
2
1
  import type { DecryptMessageParams } from "./DecryptMessageManager.cjs";
3
2
  import type { EncryptionPublicKeyParams } from "./EncryptionPublicKeyManager.cjs";
4
- import type { PersonalMessageParams } from "./PersonalMessageManager.cjs";
5
- import type { TypedMessageParams } from "./TypedMessageManager.cjs";
6
3
  /**
7
4
  * A helper function that converts rawmessageData buffer data to a hex, or just returns the data if
8
5
  * it is already formatted as a hex.
@@ -11,28 +8,6 @@ import type { TypedMessageParams } from "./TypedMessageManager.cjs";
11
8
  * @returns A hex string conversion of the buffer data.
12
9
  */
13
10
  export declare function normalizeMessageData(data: string): `0x${string}`;
14
- /**
15
- * Validates a PersonalMessageParams objects for required properties and throws in
16
- * the event of any validation error.
17
- *
18
- * @param messageData - PersonalMessageParams object to validate.
19
- */
20
- export declare function validateSignMessageData(messageData: PersonalMessageParams): void;
21
- /**
22
- * Validates a TypedMessageParams object for required properties and throws in
23
- * the event of any validation error for eth_signTypedMessage_V1.
24
- *
25
- * @param messageData - TypedMessageParams object to validate.
26
- */
27
- export declare function validateTypedSignMessageDataV1(messageData: TypedMessageParams): void;
28
- /**
29
- * Validates a TypedMessageParams object for required properties and throws in
30
- * the event of any validation error for eth_signTypedMessage_V3.
31
- *
32
- * @param messageData - TypedMessageParams object to validate.
33
- * @param currentChainId - The current chainId.
34
- */
35
- export declare function validateTypedSignMessageDataV3V4(messageData: TypedMessageParams, currentChainId: Hex | undefined): void;
36
11
  /**
37
12
  * Validates messageData for the eth_getEncryptionPublicKey message and throws in
38
13
  * the event of any validation error.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,oCAAgC;AACpE,OAAO,KAAK,EAAE,yBAAyB,EAAE,yCAAqC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,qCAAiC;AACtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,kCAA8B;AAiBhE;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,iBAUhD;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,qBAAqB,QAOzE;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,kBAAkB,QAoBhC;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,WAAW,EAAE,kBAAkB,EAC/B,cAAc,EAAE,GAAG,GAAG,SAAS,QA4DhC;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.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,oCAAgC;AACpE,OAAO,KAAK,EAAE,yBAAyB,EAAE,yCAAqC;AAiB9E;;;;;;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 CHANGED
@@ -1,8 +1,5 @@
1
- import type { Hex } from "@metamask/utils";
2
1
  import type { DecryptMessageParams } from "./DecryptMessageManager.mjs";
3
2
  import type { EncryptionPublicKeyParams } from "./EncryptionPublicKeyManager.mjs";
4
- import type { PersonalMessageParams } from "./PersonalMessageManager.mjs";
5
- import type { TypedMessageParams } from "./TypedMessageManager.mjs";
6
3
  /**
7
4
  * A helper function that converts rawmessageData buffer data to a hex, or just returns the data if
8
5
  * it is already formatted as a hex.
@@ -11,28 +8,6 @@ import type { TypedMessageParams } from "./TypedMessageManager.mjs";
11
8
  * @returns A hex string conversion of the buffer data.
12
9
  */
13
10
  export declare function normalizeMessageData(data: string): `0x${string}`;
14
- /**
15
- * Validates a PersonalMessageParams objects for required properties and throws in
16
- * the event of any validation error.
17
- *
18
- * @param messageData - PersonalMessageParams object to validate.
19
- */
20
- export declare function validateSignMessageData(messageData: PersonalMessageParams): void;
21
- /**
22
- * Validates a TypedMessageParams object for required properties and throws in
23
- * the event of any validation error for eth_signTypedMessage_V1.
24
- *
25
- * @param messageData - TypedMessageParams object to validate.
26
- */
27
- export declare function validateTypedSignMessageDataV1(messageData: TypedMessageParams): void;
28
- /**
29
- * Validates a TypedMessageParams object for required properties and throws in
30
- * the event of any validation error for eth_signTypedMessage_V3.
31
- *
32
- * @param messageData - TypedMessageParams object to validate.
33
- * @param currentChainId - The current chainId.
34
- */
35
- export declare function validateTypedSignMessageDataV3V4(messageData: TypedMessageParams, currentChainId: Hex | undefined): void;
36
11
  /**
37
12
  * Validates messageData for the eth_getEncryptionPublicKey message and throws in
38
13
  * the event of any validation error.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,oCAAgC;AACpE,OAAO,KAAK,EAAE,yBAAyB,EAAE,yCAAqC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,qCAAiC;AACtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,kCAA8B;AAiBhE;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,iBAUhD;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,qBAAqB,QAOzE;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,kBAAkB,QAoBhC;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,WAAW,EAAE,kBAAkB,EAC/B,cAAc,EAAE,GAAG,GAAG,SAAS,QA4DhC;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.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,oCAAgC;AACpE,OAAO,KAAK,EAAE,yBAAyB,EAAE,yCAAqC;AAiB9E;;;;;;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.mjs CHANGED
@@ -1,8 +1,5 @@
1
1
  import { isValidHexAddress } from "@metamask/controller-utils";
2
- import $metamaskethsigutil from "@metamask/eth-sig-util";
3
- const { TYPED_MESSAGE_SCHEMA, typedSignatureHash } = $metamaskethsigutil;
4
2
  import { add0x, bytesToHex, remove0x } from "@metamask/utils";
5
- import { validate } from "jsonschema";
6
3
  const hexRe = /^[0-9A-Fa-f]+$/gu;
7
4
  /**
8
5
  * Validates an address string and throws in the event of any validation error.
@@ -34,97 +31,6 @@ export function normalizeMessageData(data) {
34
31
  }
35
32
  return bytesToHex(Buffer.from(data, 'utf8'));
36
33
  }
37
- /**
38
- * Validates a PersonalMessageParams objects for required properties and throws in
39
- * the event of any validation error.
40
- *
41
- * @param messageData - PersonalMessageParams object to validate.
42
- */
43
- export function validateSignMessageData(messageData) {
44
- const { from, data } = messageData;
45
- validateAddress(from, 'from');
46
- if (!data || typeof data !== 'string') {
47
- throw new Error(`Invalid message "data": ${data} must be a valid string.`);
48
- }
49
- }
50
- /**
51
- * Validates a TypedMessageParams object for required properties and throws in
52
- * the event of any validation error for eth_signTypedMessage_V1.
53
- *
54
- * @param messageData - TypedMessageParams object to validate.
55
- */
56
- export function validateTypedSignMessageDataV1(messageData) {
57
- validateAddress(messageData.from, 'from');
58
- if (!messageData.data || !Array.isArray(messageData.data)) {
59
- throw new Error(
60
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
61
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
62
- `Invalid message "data": ${messageData.data} must be a valid array.`);
63
- }
64
- try {
65
- // typedSignatureHash will throw if the data is invalid.
66
- // TODO: Replace `any` with type
67
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
- typedSignatureHash(messageData.data);
69
- }
70
- catch (e) {
71
- throw new Error(`Expected EIP712 typed data.`);
72
- }
73
- }
74
- /**
75
- * Validates a TypedMessageParams object for required properties and throws in
76
- * the event of any validation error for eth_signTypedMessage_V3.
77
- *
78
- * @param messageData - TypedMessageParams object to validate.
79
- * @param currentChainId - The current chainId.
80
- */
81
- export function validateTypedSignMessageDataV3V4(messageData, currentChainId) {
82
- validateAddress(messageData.from, 'from');
83
- if (!messageData.data ||
84
- Array.isArray(messageData.data) ||
85
- (typeof messageData.data !== 'object' &&
86
- typeof messageData.data !== 'string')) {
87
- throw new Error(`Invalid message "data": Must be a valid string or object.`);
88
- }
89
- let data;
90
- if (typeof messageData.data === 'object') {
91
- data = messageData.data;
92
- }
93
- else {
94
- try {
95
- data = JSON.parse(messageData.data);
96
- }
97
- catch (e) {
98
- throw new Error('Data must be passed as a valid JSON string.');
99
- }
100
- }
101
- const validation = validate(data, TYPED_MESSAGE_SCHEMA);
102
- if (validation.errors.length > 0) {
103
- throw new Error('Data must conform to EIP-712 schema. See https://git.io/fNtcx.');
104
- }
105
- if (!currentChainId) {
106
- throw new Error('Current chainId cannot be null or undefined.');
107
- }
108
- let { chainId } = data.domain;
109
- if (chainId) {
110
- if (typeof chainId === 'string') {
111
- chainId = parseInt(chainId, chainId.startsWith('0x') ? 16 : 10);
112
- }
113
- const activeChainId = parseInt(currentChainId, 16);
114
- if (Number.isNaN(activeChainId)) {
115
- throw new Error(
116
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
117
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
118
- `Cannot sign messages for chainId "${chainId}", because MetaMask is switching networks.`);
119
- }
120
- if (chainId !== activeChainId) {
121
- throw new Error(
122
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
123
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
124
- `Provided chainId "${chainId}" must match the active chainId "${activeChainId}"`);
125
- }
126
- }
127
- }
128
34
  /**
129
35
  * Validates messageData for the eth_getEncryptionPublicKey message and throws in
130
36
  * the event of any validation error.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mCAAmC;;;AAM/D,OAAO,EAAE,KA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AI,CAAC,cAAc,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;KACjE;IAED,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;IAC9B,IAAI,OAAO,EAAE;QACX,IAAI,OAAO,OAAO,KAAK,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;YACb,gFAAgF;YAChF,4EAA4E;YAC5E,qCAAqC,OAAO,4CAA4C,CACzF,CAAC;SACH;QAED,IAAI,OAAO,KAAK,aAAa,EAAE;YAC7B,MAAM,IAAI,KAAK;YACb,gFAAgF;YAChF,4EAA4E;YAC5E,qBAAqB,OAAO,oCAAoC,aAAa,GAAG,CACjF,CAAC;SACH;KACF;AACH,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 {\n TYPED_MESSAGE_SCHEMA,\n typedSignatureHash,\n} from '@metamask/eth-sig-util';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, bytesToHex, remove0x } from '@metamask/utils';\nimport { validate } from 'jsonschema';\n\nimport type { DecryptMessageParams } from './DecryptMessageManager';\nimport type { EncryptionPublicKeyParams } from './EncryptionPublicKeyManager';\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 = 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 a PersonalMessageParams 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(messageData: PersonalMessageParams) {\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 // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\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 // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n `Cannot sign messages for chainId \"${chainId}\", because MetaMask is switching networks.`,\n );\n }\n\n if (chainId !== activeChainId) {\n throw new Error(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\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.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;QAC1E,MAAM,IAAI,KAAK,CACb,YAAY,YAAY,cAAc,OAAO,0BAA0B,CACxE,CAAC;KACH;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,IAAI;QACF,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YACzB,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC;SACxB;KACF;IAAC,OAAO,CAAC,EAAE;QACV,0BAA0B;KAC3B;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';\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/message-manager",
3
- "version": "10.1.1-preview-e46fca9e",
3
+ "version": "10.1.1-preview-2f4bcaa9",
4
4
  "description": "Stores and manages interactions with signing requests",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PersonalMessageManager = void 0;
4
- const controller_utils_1 = require("@metamask/controller-utils");
5
- const AbstractMessageManager_1 = require("./AbstractMessageManager.cjs");
6
- const utils_1 = require("./utils.cjs");
7
- /**
8
- * Controller in charge of managing - storing, adding, removing, updating - Messages.
9
- */
10
- class PersonalMessageManager extends AbstractMessageManager_1.AbstractMessageManager {
11
- constructor() {
12
- super(...arguments);
13
- /**
14
- * Name of this controller used during composition
15
- */
16
- this.name = 'PersonalMessageManager';
17
- }
18
- /**
19
- * Creates a new Message with an 'unapproved' status using the passed messageParams.
20
- * this.addMessage is called to add the new Message to this.messages, and to save the
21
- * unapproved Messages.
22
- *
23
- * @param messageParams - The params for the personal_sign call to be made after the message
24
- * is approved.
25
- * @param req - The original request object possibly containing the origin.
26
- * @returns The id of the newly created message.
27
- */
28
- async addUnapprovedMessage(messageParams, req) {
29
- (0, utils_1.validateSignMessageData)(messageParams);
30
- const ethereumSignInData = (0, controller_utils_1.detectSIWE)(messageParams);
31
- const updatedMessageParams = this.addRequestToMessageParams(messageParams, req);
32
- updatedMessageParams.data = (0, utils_1.normalizeMessageData)(messageParams.data);
33
- updatedMessageParams.siwe = ethereumSignInData;
34
- const messageData = this.createUnapprovedMessage(updatedMessageParams, controller_utils_1.ApprovalType.PersonalSign, req);
35
- const messageId = messageData.id;
36
- await this.addMessage(messageData);
37
- this.hub.emit(`unapprovedMessage`, {
38
- ...updatedMessageParams,
39
- metamaskId: messageId,
40
- });
41
- return messageId;
42
- }
43
- /**
44
- * Removes the metamaskId property from passed messageParams and returns a promise which
45
- * resolves the updated messageParams.
46
- *
47
- * @param messageParams - The messageParams to modify.
48
- * @returns Promise resolving to the messageParams with the metamaskId property removed.
49
- */
50
- prepMessageForSigning(messageParams) {
51
- // Using delete operation will throw an error on frozen messageParams
52
- const { metamaskId: _metamaskId, ...messageParamsWithoutId } = messageParams;
53
- return Promise.resolve(messageParamsWithoutId);
54
- }
55
- }
56
- exports.PersonalMessageManager = PersonalMessageManager;
57
- exports.default = PersonalMessageManager;
58
- //# sourceMappingURL=PersonalMessageManager.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PersonalMessageManager.cjs","sourceRoot":"","sources":["../src/PersonalMessageManager.ts"],"names":[],"mappings":";;;AACA,iEAAsE;AAQtE,yEAAkE;AAClE,uCAAwE;AAsDxE;;GAEG;AACH,MAAa,sBAAuB,SAAQ,+CAI3C;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,wBAAiC,CAAC;IAyDpD,CAAC;IAvDC;;;;;;;;;OASG;IACH,KAAK,CAAC,oBAAoB,CACxB,aAAoC,EACpC,GAAqB;QAErB,IAAA,+BAAuB,EAAC,aAAa,CAAC,CAAC;QAEvC,MAAM,kBAAkB,GAAG,IAAA,6BAAU,EAAC,aAAa,CAAC,CAAC;QACrD,MAAM,oBAAoB,GAAG,IAAI,CAAC,yBAAyB,CACzD,aAAa,EACb,GAAG,CAC4B,CAAC;QAElC,oBAAoB,CAAC,IAAI,GAAG,IAAA,4BAAoB,EAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACrE,oBAAoB,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAE/C,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAC9C,oBAAoB,EACpB,+BAAY,CAAC,YAAY,EACzB,GAAG,CACsB,CAAC;QAE5B,MAAM,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACnC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE;YACjC,GAAG,oBAAoB;YACvB,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAA4C;QAE5C,qEAAqE;QACrE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,sBAAsB,EAAE,GAC1D,aAAa,CAAC;QAChB,OAAO,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACjD,CAAC;CACF;AAjED,wDAiEC;AAED,kBAAe,sBAAsB,CAAC","sourcesContent":["import type { SIWEMessage } from '@metamask/controller-utils';\nimport { detectSIWE, ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { normalizeMessageData, validateSignMessageData } from './utils';\n\n/**\n * @type Message\n *\n * Represents and contains data about a 'personal_sign' type signature request.\n * These are created when a signature for a personal_sign call is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the personal_sign method once the signature request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'Message' which always has a 'personal_sign' type\n * @property rawSig - Raw data of the signature request\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface PersonalMessage extends AbstractMessage {\n messageParams: PersonalMessageParams;\n}\n\n/**\n * @type PersonalMessageParams\n *\n * Represents the parameters to pass to the personal_sign method once the signature request is approved.\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface PersonalMessageParams extends AbstractMessageParams {\n data: string;\n siwe?: SIWEMessage;\n}\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the personal_sign method once the signature request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface PersonalMessageParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport class PersonalMessageManager extends AbstractMessageManager<\n PersonalMessage,\n PersonalMessageParams,\n PersonalMessageParamsMetamask\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'PersonalMessageManager' as const;\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: PersonalMessageParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateSignMessageData(messageParams);\n\n const ethereumSignInData = detectSIWE(messageParams);\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies PersonalMessageParams;\n\n updatedMessageParams.data = normalizeMessageData(messageParams.data);\n updatedMessageParams.siwe = ethereumSignInData;\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.PersonalSign,\n req,\n ) satisfies PersonalMessage;\n\n const messageId = messageData.id;\n await this.addMessage(messageData);\n this.hub.emit(`unapprovedMessage`, {\n ...updatedMessageParams,\n metamaskId: messageId,\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: PersonalMessageParamsMetamask,\n ): Promise<PersonalMessageParams> {\n // Using delete operation will throw an error on frozen messageParams\n const { metamaskId: _metamaskId, ...messageParamsWithoutId } =\n messageParams;\n return Promise.resolve(messageParamsWithoutId);\n }\n}\n\nexport default PersonalMessageManager;\n"]}