@metamask-previews/controller-utils 12.3.0-preview-4f4c98e → 12.3.0-preview-5b293ee50

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 (83) hide show
  1. package/CHANGELOG.md +0 -4
  2. package/dist/abi.cjs +58 -0
  3. package/dist/abi.cjs.map +1 -0
  4. package/dist/{abi.d.ts → abi.d.cts} +3 -3
  5. package/dist/abi.d.cts.map +1 -0
  6. package/dist/abi.d.mts +16 -0
  7. package/dist/abi.d.mts.map +1 -0
  8. package/dist/{abi.js → abi.mjs} +3 -3
  9. package/dist/{abi.js.map → abi.mjs.map} +1 -1
  10. package/dist/constants.cjs +308 -0
  11. package/dist/constants.cjs.map +1 -0
  12. package/dist/{constants.d.ts → constants.d.cts} +3 -3
  13. package/dist/constants.d.cts.map +1 -0
  14. package/dist/constants.d.mts +283 -0
  15. package/dist/constants.d.mts.map +1 -0
  16. package/dist/{constants.js → constants.mjs} +2 -2
  17. package/dist/constants.mjs.map +1 -0
  18. package/dist/create-service-policy.cjs +250 -0
  19. package/dist/create-service-policy.cjs.map +1 -0
  20. package/dist/{create-service-policy.d.ts → create-service-policy.d.cts} +3 -3
  21. package/dist/create-service-policy.d.cts.map +1 -0
  22. package/dist/create-service-policy.d.mts +249 -0
  23. package/dist/create-service-policy.d.mts.map +1 -0
  24. package/dist/{create-service-policy.js → create-service-policy.mjs} +3 -3
  25. package/dist/create-service-policy.mjs.map +1 -0
  26. package/dist/index.cjs +102 -0
  27. package/dist/index.cjs.map +1 -0
  28. package/dist/{index.d.ts → index.d.cts} +9 -9
  29. package/dist/index.d.cts.map +1 -0
  30. package/dist/index.d.mts +9 -0
  31. package/dist/index.d.mts.map +1 -0
  32. package/dist/{index.js → index.mjs} +7 -7
  33. package/dist/index.mjs.map +1 -0
  34. package/dist/logger.cjs +7 -0
  35. package/dist/logger.cjs.map +1 -0
  36. package/dist/logger.d.cts +5 -0
  37. package/dist/logger.d.cts.map +1 -0
  38. package/dist/logger.d.mts +5 -0
  39. package/dist/logger.d.mts.map +1 -0
  40. package/dist/logger.mjs +4 -0
  41. package/dist/logger.mjs.map +1 -0
  42. package/dist/siwe.cjs +131 -0
  43. package/dist/siwe.cjs.map +1 -0
  44. package/dist/{siwe.d.ts → siwe.d.cts} +2 -2
  45. package/dist/siwe.d.cts.map +1 -0
  46. package/dist/siwe.d.mts +69 -0
  47. package/dist/siwe.d.mts.map +1 -0
  48. package/dist/{siwe.js → siwe.mjs} +4 -4
  49. package/dist/siwe.mjs.map +1 -0
  50. package/dist/types.cjs +232 -0
  51. package/dist/types.cjs.map +1 -0
  52. package/dist/{types.d.ts → types.d.cts} +98 -98
  53. package/dist/types.d.cts.map +1 -0
  54. package/dist/types.d.mts +267 -0
  55. package/dist/types.d.mts.map +1 -0
  56. package/dist/{types.js → types.mjs} +1 -1
  57. package/dist/types.mjs.map +1 -0
  58. package/dist/util.cjs +569 -0
  59. package/dist/util.cjs.map +1 -0
  60. package/dist/{util.d.ts → util.d.cts} +6 -6
  61. package/dist/util.d.cts.map +1 -0
  62. package/dist/util.d.mts +261 -0
  63. package/dist/util.d.mts.map +1 -0
  64. package/dist/{util.js → util.mjs} +18 -8
  65. package/dist/util.mjs.map +1 -0
  66. package/package.json +18 -14
  67. package/dist/abi.d.ts.map +0 -1
  68. package/dist/constants.d.ts.map +0 -1
  69. package/dist/constants.js.map +0 -1
  70. package/dist/create-service-policy.d.ts.map +0 -1
  71. package/dist/create-service-policy.js.map +0 -1
  72. package/dist/index.d.ts.map +0 -1
  73. package/dist/index.js.map +0 -1
  74. package/dist/logger.d.ts +0 -4
  75. package/dist/logger.d.ts.map +0 -1
  76. package/dist/logger.js +0 -4
  77. package/dist/logger.js.map +0 -1
  78. package/dist/siwe.d.ts.map +0 -1
  79. package/dist/siwe.js.map +0 -1
  80. package/dist/types.d.ts.map +0 -1
  81. package/dist/types.js.map +0 -1
  82. package/dist/util.d.ts.map +0 -1
  83. package/dist/util.js.map +0 -1
package/dist/siwe.cjs ADDED
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectSIWE = exports.isValidSIWEOrigin = exports.parseDomainParts = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ const siwe_parser_1 = require("@spruceid/siwe-parser");
6
+ const logger_js_1 = require("./logger.cjs");
7
+ const log = (0, logger_js_1.createModuleLogger)(logger_js_1.projectLogger, 'detect-siwe');
8
+ /**
9
+ * This function strips the hex prefix from a string if it has one.
10
+ * If the input is not a string, return it unmodified.
11
+ *
12
+ * @param str - The string to check
13
+ * @returns The string without the hex prefix
14
+ */
15
+ function safeStripHexPrefix(str) {
16
+ if (typeof str !== 'string') {
17
+ return str;
18
+ }
19
+ return (0, utils_1.remove0x)(str);
20
+ }
21
+ /**
22
+ * This function converts a hex string to text if it's not a 32 byte hex string.
23
+ *
24
+ * @param hexValue - The hex string to convert to text
25
+ * @returns The text representation of the hex string
26
+ */
27
+ function msgHexToText(hexValue) {
28
+ try {
29
+ const stripped = safeStripHexPrefix(hexValue);
30
+ // TODO: Use `@metamask/utils` version of this function to avoid Buffer
31
+ // usage here.
32
+ // eslint-disable-next-line no-restricted-globals
33
+ const buff = Buffer.from(stripped, 'hex');
34
+ return buff.length === 32 ? hexValue : buff.toString('utf8');
35
+ }
36
+ catch (error) {
37
+ log(error);
38
+ return hexValue;
39
+ }
40
+ }
41
+ const DEFAULT_PORTS_BY_PROTOCOL = {
42
+ 'http:': '80',
43
+ 'https:': '443',
44
+ };
45
+ /**
46
+ * Parses parts from RFC 3986 authority from EIP-4361 `domain` field.
47
+ *
48
+ * @param domain - input string
49
+ * @param originProtocol - implied protocol from origin
50
+ * @returns parsed parts
51
+ */
52
+ const parseDomainParts = (domain, originProtocol) => {
53
+ if (domain.match(/^[^/:]*:\/\//u)) {
54
+ return new URL(domain);
55
+ }
56
+ return new URL(`${originProtocol}//${domain}`);
57
+ };
58
+ exports.parseDomainParts = parseDomainParts;
59
+ /**
60
+ * Validates origin of a Sign-In With Ethereum (SIWE)(EIP-4361) request.
61
+ * As per spec:
62
+ * hostname must match.
63
+ * port and username must match iff specified.
64
+ * Protocol binding and full same-origin are currently not performed.
65
+ *
66
+ * @param req - Signature request
67
+ * @returns true if origin matches domain; false otherwise
68
+ */
69
+ const isValidSIWEOrigin = (req) => {
70
+ try {
71
+ const { origin, siwe } = req;
72
+ // origin = scheme://[user[:password]@]domain[:port]
73
+ // origin is supplied by environment and must match domain claim in message
74
+ if (!origin || !siwe?.parsedMessage?.domain) {
75
+ return false;
76
+ }
77
+ const originParts = new URL(origin);
78
+ const domainParts = (0, exports.parseDomainParts)(siwe.parsedMessage.domain, originParts.protocol);
79
+ if (domainParts.hostname.localeCompare(originParts.hostname, undefined, {
80
+ sensitivity: 'accent',
81
+ }) !== 0) {
82
+ return false;
83
+ }
84
+ if (domainParts.port !== '' && domainParts.port !== originParts.port) {
85
+ // If origin port is not specified, protocol default is implied
86
+ return (originParts.port === '' &&
87
+ domainParts.port === DEFAULT_PORTS_BY_PROTOCOL[originParts.protocol]);
88
+ }
89
+ if (domainParts.username !== '' &&
90
+ domainParts.username !== originParts.username) {
91
+ return false;
92
+ }
93
+ return true;
94
+ }
95
+ catch (error) {
96
+ log(error);
97
+ return false;
98
+ }
99
+ };
100
+ exports.isValidSIWEOrigin = isValidSIWEOrigin;
101
+ /**
102
+ * This function intercepts a sign message, detects if it's a
103
+ * Sign-In With Ethereum (SIWE)(EIP-4361) message, and returns an object with
104
+ * relevant SIWE data.
105
+ *
106
+ * {@see {@link https://eips.ethereum.org/EIPS/eip-4361}}
107
+ *
108
+ * @param msgParams - The params of the message to sign
109
+ * @param msgParams.data - The data of the message to sign
110
+ * @returns An object with the relevant SIWE data
111
+ */
112
+ const detectSIWE = (msgParams) => {
113
+ try {
114
+ const { data } = msgParams;
115
+ const message = msgHexToText(data);
116
+ const parsedMessage = new siwe_parser_1.ParsedMessage(message);
117
+ return {
118
+ isSIWEMessage: true,
119
+ parsedMessage,
120
+ };
121
+ }
122
+ catch {
123
+ // ignore error, it's not a valid SIWE message
124
+ return {
125
+ isSIWEMessage: false,
126
+ parsedMessage: null,
127
+ };
128
+ }
129
+ };
130
+ exports.detectSIWE = detectSIWE;
131
+ //# sourceMappingURL=siwe.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"siwe.cjs","sourceRoot":"","sources":["../src/siwe.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAC3C,uDAAsD;AAEtD,4CAAgE;AAEhE,MAAM,GAAG,GAAG,IAAA,8BAAkB,EAAC,yBAAa,EAAE,aAAa,CAAC,CAAC;AAE7D;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,GAAW;IACrC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,IAAA,gBAAQ,EAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,QAAgB;IACpC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC9C,uEAAuE;QACvE,cAAc;QACd,iDAAiD;QACjD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,CAAC;QACX,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC;AA6BD,MAAM,yBAAyB,GAAG;IAChC,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,KAAK;CACU,CAAC;AAE5B;;;;;;GAMG;AACI,MAAM,gBAAgB,GAAG,CA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,QAAQ,KAAK,WAAW,CAAC,QAAQ,EAC7C,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC;AA5CW,QAAA,iBAAiB,qBA4C5B;AAaF;;;;;;;;;;GAUG;AACI,MAAM,UAAU,GAAG,CAAC,SAA2B,EAAe,EAAE;IACrE,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC;QAC3B,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QACnC,MAAM,aAAa,GAAG,IAAI,2BAAa,CAAC,OAAO,CAAC,CAAC;QAEjD,OAAO;YACL,aAAa,EAAE,IAAI;YACnB,aAAa;SACd,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,8CAA8C;QAC9C,OAAO;YACL,aAAa,EAAE,KAAK;YACpB,aAAa,EAAE,IAAI;SACpB,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAjBW,QAAA,UAAU,cAiBrB","sourcesContent":["import { remove0x } from '@metamask/utils';\nimport { ParsedMessage } from '@spruceid/siwe-parser';\n\nimport { projectLogger, createModuleLogger } from './logger.js';\n\nconst log = createModuleLogger(projectLogger, 'detect-siwe');\n\n/**\n * This function strips the hex prefix from a string if it has one.\n * If the input is not a string, return it unmodified.\n *\n * @param str - The string to check\n * @returns The string without the hex prefix\n */\nfunction safeStripHexPrefix(str: string): string {\n if (typeof str !== 'string') {\n return str;\n }\n return remove0x(str);\n}\n\n/**\n * This function converts a hex string to text if it's not a 32 byte hex string.\n *\n * @param hexValue - The hex string to convert to text\n * @returns The text representation of the hex string\n */\nfunction msgHexToText(hexValue: string): string {\n try {\n const stripped = safeStripHexPrefix(hexValue);\n // TODO: Use `@metamask/utils` version of this function to avoid Buffer\n // usage here.\n // eslint-disable-next-line no-restricted-globals\n const buff = Buffer.from(stripped, 'hex');\n return buff.length === 32 ? hexValue : buff.toString('utf8');\n } catch (error) {\n log(error);\n return hexValue;\n }\n}\n\n/**\n * @type WrappedSIWERequest\n *\n * Sign-In With Ethereum (SIWE)(EIP-4361) message with request metadata\n *\n * @property from - Subject account address\n * @property origin - The RFC 3986 originating authority of the signing request, including scheme\n * @property siwe - The data parsed from the message\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 WrappedSIWERequest {\n from: string;\n origin: string;\n siwe: SIWEMessage;\n}\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\ninterface DomainParts {\n username?: string;\n hostname: string;\n port?: string;\n}\n\nconst DEFAULT_PORTS_BY_PROTOCOL = {\n 'http:': '80',\n 'https:': '443',\n} as Record<string, string>;\n\n/**\n * Parses parts from RFC 3986 authority from EIP-4361 `domain` field.\n *\n * @param domain - input string\n * @param originProtocol - implied protocol from origin\n * @returns parsed parts\n */\nexport const parseDomainParts = (\n domain: string,\n originProtocol: string,\n): DomainParts => {\n if (domain.match(/^[^/:]*:\\/\\//u)) {\n return new URL(domain);\n }\n return new URL(`${originProtocol}//${domain}`);\n};\n\n/**\n * Validates origin of a Sign-In With Ethereum (SIWE)(EIP-4361) request.\n * As per spec:\n * hostname must match.\n * port and username must match iff specified.\n * Protocol binding and full same-origin are currently not performed.\n *\n * @param req - Signature request\n * @returns true if origin matches domain; false otherwise\n */\nexport const isValidSIWEOrigin = (req: WrappedSIWERequest): boolean => {\n try {\n const { origin, siwe } = req;\n\n // origin = scheme://[user[:password]@]domain[:port]\n // origin is supplied by environment and must match domain claim in message\n if (!origin || !siwe?.parsedMessage?.domain) {\n return false;\n }\n\n const originParts = new URL(origin);\n const domainParts = parseDomainParts(\n siwe.parsedMessage.domain,\n originParts.protocol,\n );\n\n if (\n domainParts.hostname.localeCompare(originParts.hostname, undefined, {\n sensitivity: 'accent',\n }) !== 0\n ) {\n return false;\n }\n\n if (domainParts.port !== '' && domainParts.port !== originParts.port) {\n // If origin port is not specified, protocol default is implied\n return (\n originParts.port === '' &&\n domainParts.port === DEFAULT_PORTS_BY_PROTOCOL[originParts.protocol]\n );\n }\n\n if (\n domainParts.username !== '' &&\n domainParts.username !== originParts.username\n ) {\n return false;\n }\n\n return true;\n } catch (error) {\n log(error);\n return false;\n }\n};\n\n/**\n * A locally defined object used to provide data to identify a Sign-In With Ethereum (SIWE)(EIP-4361) message and provide the parsed message\n *\n * @typedef SIWEMessage\n * @param {boolean} isSIWEMessage - Does the intercepted message conform to the SIWE specification?\n * @param {ParsedMessage} parsedMessage - The data parsed out of the message\n */\nexport type SIWEMessage =\n | { isSIWEMessage: true; parsedMessage: ParsedMessage }\n | { isSIWEMessage: false; parsedMessage: null };\n\n/**\n * This function intercepts a sign message, detects if it's a\n * Sign-In With Ethereum (SIWE)(EIP-4361) message, and returns an object with\n * relevant SIWE data.\n *\n * {@see {@link https://eips.ethereum.org/EIPS/eip-4361}}\n *\n * @param msgParams - The params of the message to sign\n * @param msgParams.data - The data of the message to sign\n * @returns An object with the relevant SIWE data\n */\nexport const detectSIWE = (msgParams: { data: string }): SIWEMessage => {\n try {\n const { data } = msgParams;\n const message = msgHexToText(data);\n const parsedMessage = new ParsedMessage(message);\n\n return {\n isSIWEMessage: true,\n parsedMessage,\n };\n } catch {\n // ignore error, it's not a valid SIWE message\n return {\n isSIWEMessage: false,\n parsedMessage: null,\n };\n }\n};\n"]}
@@ -1,4 +1,4 @@
1
- import { ParsedMessage } from '@spruceid/siwe-parser';
1
+ import { ParsedMessage } from "@spruceid/siwe-parser";
2
2
  /**
3
3
  * @type WrappedSIWERequest
4
4
  *
@@ -66,4 +66,4 @@ export declare const detectSIWE: (msgParams: {
66
66
  data: string;
67
67
  }) => SIWEMessage;
68
68
  export {};
69
- //# sourceMappingURL=siwe.d.ts.map
69
+ //# sourceMappingURL=siwe.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"siwe.d.cts","sourceRoot":"","sources":["../src/siwe.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,8BAA8B;AAwCtD;;;;;;;;GAQG;AAIH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,WAAW,CAAC;CACnB;AAKD,UAAU,WAAW;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAOD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,WACnB,MAAM,kBACE,MAAM,KACrB,WAKF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,QAAS,kBAAkB,KAAG,OA4C3D,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,aAAa,EAAE,IAAI,CAAC;IAAC,aAAa,EAAE,aAAa,CAAA;CAAE,GACrD;IAAE,aAAa,EAAE,KAAK,CAAC;IAAC,aAAa,EAAE,IAAI,CAAA;CAAE,CAAC;AAElD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,cAAe;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,KAAG,WAiBxD,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { ParsedMessage } from "@spruceid/siwe-parser";
2
+ /**
3
+ * @type WrappedSIWERequest
4
+ *
5
+ * Sign-In With Ethereum (SIWE)(EIP-4361) message with request metadata
6
+ *
7
+ * @property from - Subject account address
8
+ * @property origin - The RFC 3986 originating authority of the signing request, including scheme
9
+ * @property siwe - The data parsed from the message
10
+ */
11
+ export interface WrappedSIWERequest {
12
+ from: string;
13
+ origin: string;
14
+ siwe: SIWEMessage;
15
+ }
16
+ interface DomainParts {
17
+ username?: string;
18
+ hostname: string;
19
+ port?: string;
20
+ }
21
+ /**
22
+ * Parses parts from RFC 3986 authority from EIP-4361 `domain` field.
23
+ *
24
+ * @param domain - input string
25
+ * @param originProtocol - implied protocol from origin
26
+ * @returns parsed parts
27
+ */
28
+ export declare const parseDomainParts: (domain: string, originProtocol: string) => DomainParts;
29
+ /**
30
+ * Validates origin of a Sign-In With Ethereum (SIWE)(EIP-4361) request.
31
+ * As per spec:
32
+ * hostname must match.
33
+ * port and username must match iff specified.
34
+ * Protocol binding and full same-origin are currently not performed.
35
+ *
36
+ * @param req - Signature request
37
+ * @returns true if origin matches domain; false otherwise
38
+ */
39
+ export declare const isValidSIWEOrigin: (req: WrappedSIWERequest) => boolean;
40
+ /**
41
+ * A locally defined object used to provide data to identify a Sign-In With Ethereum (SIWE)(EIP-4361) message and provide the parsed message
42
+ *
43
+ * @typedef SIWEMessage
44
+ * @param {boolean} isSIWEMessage - Does the intercepted message conform to the SIWE specification?
45
+ * @param {ParsedMessage} parsedMessage - The data parsed out of the message
46
+ */
47
+ export type SIWEMessage = {
48
+ isSIWEMessage: true;
49
+ parsedMessage: ParsedMessage;
50
+ } | {
51
+ isSIWEMessage: false;
52
+ parsedMessage: null;
53
+ };
54
+ /**
55
+ * This function intercepts a sign message, detects if it's a
56
+ * Sign-In With Ethereum (SIWE)(EIP-4361) message, and returns an object with
57
+ * relevant SIWE data.
58
+ *
59
+ * {@see {@link https://eips.ethereum.org/EIPS/eip-4361}}
60
+ *
61
+ * @param msgParams - The params of the message to sign
62
+ * @param msgParams.data - The data of the message to sign
63
+ * @returns An object with the relevant SIWE data
64
+ */
65
+ export declare const detectSIWE: (msgParams: {
66
+ data: string;
67
+ }) => SIWEMessage;
68
+ export {};
69
+ //# sourceMappingURL=siwe.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"siwe.d.mts","sourceRoot":"","sources":["../src/siwe.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,8BAA8B;AAwCtD;;;;;;;;GAQG;AAIH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,WAAW,CAAC;CACnB;AAKD,UAAU,WAAW;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAOD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,WACnB,MAAM,kBACE,MAAM,KACrB,WAKF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,QAAS,kBAAkB,KAAG,OA4C3D,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,aAAa,EAAE,IAAI,CAAC;IAAC,aAAa,EAAE,aAAa,CAAA;CAAE,GACrD;IAAE,aAAa,EAAE,KAAK,CAAC;IAAC,aAAa,EAAE,IAAI,CAAA;CAAE,CAAC;AAElD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,cAAe;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,KAAG,WAiBxD,CAAC"}
@@ -1,6 +1,6 @@
1
- import { remove0x } from '@metamask/utils';
2
- import { ParsedMessage } from '@spruceid/siwe-parser';
3
- import { projectLogger, createModuleLogger } from './logger.js';
1
+ import { remove0x } from "@metamask/utils";
2
+ import { ParsedMessage } from "@spruceid/siwe-parser";
3
+ import { projectLogger, createModuleLogger } from "./logger.mjs";
4
4
  const log = createModuleLogger(projectLogger, 'detect-siwe');
5
5
  /**
6
6
  * This function strips the hex prefix from a string if it has one.
@@ -122,4 +122,4 @@ export const detectSIWE = (msgParams) => {
122
122
  };
123
123
  }
124
124
  };
125
- //# sourceMappingURL=siwe.js.map
125
+ //# sourceMappingURL=siwe.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"siwe.mjs","sourceRoot":"","sources":["../src/siwe.ts"],"names":[],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;AACH,CAAC,CAAC;AAaF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,SAA2B,EAAe,EAAE;IACrE,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC;QAC3B,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QACnC,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;QAEjD,OAAO;YACL,aAAa,EAAE,IAAI;YACnB,aAAa;SACd,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,8CAA8C;QAC9C,OAAO;YACL,aAAa,EAAE,KAAK;YACpB,aAAa,EAAE,IAAI;SACpB,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { remove0x } from '@metamask/utils';\nimport { ParsedMessage } from '@spruceid/siwe-parser';\n\nimport { projectLogger, createModuleLogger } from './logger.js';\n\nconst log = createModuleLogger(projectLogger, 'detect-siwe');\n\n/**\n * This function strips the hex prefix from a string if it has one.\n * If the input is not a string, return it unmodified.\n *\n * @param str - The string to check\n * @returns The string without the hex prefix\n */\nfunction safeStripHexPrefix(str: string): string {\n if (typeof str !== 'string') {\n return str;\n }\n return remove0x(str);\n}\n\n/**\n * This function converts a hex string to text if it's not a 32 byte hex string.\n *\n * @param hexValue - The hex string to convert to text\n * @returns The text representation of the hex string\n */\nfunction msgHexToText(hexValue: string): string {\n try {\n const stripped = safeStripHexPrefix(hexValue);\n // TODO: Use `@metamask/utils` version of this function to avoid Buffer\n // usage here.\n // eslint-disable-next-line no-restricted-globals\n const buff = Buffer.from(stripped, 'hex');\n return buff.length === 32 ? hexValue : buff.toString('utf8');\n } catch (error) {\n log(error);\n return hexValue;\n }\n}\n\n/**\n * @type WrappedSIWERequest\n *\n * Sign-In With Ethereum (SIWE)(EIP-4361) message with request metadata\n *\n * @property from - Subject account address\n * @property origin - The RFC 3986 originating authority of the signing request, including scheme\n * @property siwe - The data parsed from the message\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 WrappedSIWERequest {\n from: string;\n origin: string;\n siwe: SIWEMessage;\n}\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\ninterface DomainParts {\n username?: string;\n hostname: string;\n port?: string;\n}\n\nconst DEFAULT_PORTS_BY_PROTOCOL = {\n 'http:': '80',\n 'https:': '443',\n} as Record<string, string>;\n\n/**\n * Parses parts from RFC 3986 authority from EIP-4361 `domain` field.\n *\n * @param domain - input string\n * @param originProtocol - implied protocol from origin\n * @returns parsed parts\n */\nexport const parseDomainParts = (\n domain: string,\n originProtocol: string,\n): DomainParts => {\n if (domain.match(/^[^/:]*:\\/\\//u)) {\n return new URL(domain);\n }\n return new URL(`${originProtocol}//${domain}`);\n};\n\n/**\n * Validates origin of a Sign-In With Ethereum (SIWE)(EIP-4361) request.\n * As per spec:\n * hostname must match.\n * port and username must match iff specified.\n * Protocol binding and full same-origin are currently not performed.\n *\n * @param req - Signature request\n * @returns true if origin matches domain; false otherwise\n */\nexport const isValidSIWEOrigin = (req: WrappedSIWERequest): boolean => {\n try {\n const { origin, siwe } = req;\n\n // origin = scheme://[user[:password]@]domain[:port]\n // origin is supplied by environment and must match domain claim in message\n if (!origin || !siwe?.parsedMessage?.domain) {\n return false;\n }\n\n const originParts = new URL(origin);\n const domainParts = parseDomainParts(\n siwe.parsedMessage.domain,\n originParts.protocol,\n );\n\n if (\n domainParts.hostname.localeCompare(originParts.hostname, undefined, {\n sensitivity: 'accent',\n }) !== 0\n ) {\n return false;\n }\n\n if (domainParts.port !== '' && domainParts.port !== originParts.port) {\n // If origin port is not specified, protocol default is implied\n return (\n originParts.port === '' &&\n domainParts.port === DEFAULT_PORTS_BY_PROTOCOL[originParts.protocol]\n );\n }\n\n if (\n domainParts.username !== '' &&\n domainParts.username !== originParts.username\n ) {\n return false;\n }\n\n return true;\n } catch (error) {\n log(error);\n return false;\n }\n};\n\n/**\n * A locally defined object used to provide data to identify a Sign-In With Ethereum (SIWE)(EIP-4361) message and provide the parsed message\n *\n * @typedef SIWEMessage\n * @param {boolean} isSIWEMessage - Does the intercepted message conform to the SIWE specification?\n * @param {ParsedMessage} parsedMessage - The data parsed out of the message\n */\nexport type SIWEMessage =\n | { isSIWEMessage: true; parsedMessage: ParsedMessage }\n | { isSIWEMessage: false; parsedMessage: null };\n\n/**\n * This function intercepts a sign message, detects if it's a\n * Sign-In With Ethereum (SIWE)(EIP-4361) message, and returns an object with\n * relevant SIWE data.\n *\n * {@see {@link https://eips.ethereum.org/EIPS/eip-4361}}\n *\n * @param msgParams - The params of the message to sign\n * @param msgParams.data - The data of the message to sign\n * @returns An object with the relevant SIWE data\n */\nexport const detectSIWE = (msgParams: { data: string }): SIWEMessage => {\n try {\n const { data } = msgParams;\n const message = msgHexToText(data);\n const parsedMessage = new ParsedMessage(message);\n\n return {\n isSIWEMessage: true,\n parsedMessage,\n };\n } catch {\n // ignore error, it's not a valid SIWE message\n return {\n isSIWEMessage: false,\n parsedMessage: null,\n };\n }\n};\n"]}
package/dist/types.cjs ADDED
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NetworkNickname = exports.BlockExplorerUrl = exports.NetworksTicker = exports.ChainId = exports.BuiltInNetworkName = exports.isInfuraNetworkType = exports.isNetworkType = exports.NetworkType = exports.CustomNetworkType = exports.DEFAULT_INFURA_NETWORKS = exports.InfuraNetworkType = void 0;
4
+ /**
5
+ * The names of built-in Infura networks
6
+ */
7
+ exports.InfuraNetworkType = {
8
+ mainnet: 'mainnet',
9
+ goerli: 'goerli',
10
+ sepolia: 'sepolia',
11
+ 'linea-goerli': 'linea-goerli',
12
+ 'linea-sepolia': 'linea-sepolia',
13
+ 'linea-mainnet': 'linea-mainnet',
14
+ 'base-mainnet': 'base-mainnet',
15
+ 'arbitrum-mainnet': 'arbitrum-mainnet',
16
+ 'bsc-mainnet': 'bsc-mainnet',
17
+ 'optimism-mainnet': 'optimism-mainnet',
18
+ 'polygon-mainnet': 'polygon-mainnet',
19
+ 'sei-mainnet': 'sei-mainnet',
20
+ 'monad-mainnet': 'monad-mainnet',
21
+ 'megaeth-mainnet': 'megaeth-mainnet',
22
+ 'avalanche-mainnet': 'avalanche-mainnet',
23
+ 'zksync-mainnet': 'zksync-mainnet',
24
+ };
25
+ /**
26
+ * The default set of Infura networks to include in the wallet.
27
+ *
28
+ * This is a subset of the full list of {@link InfuraNetworkType}, and can be used to determine
29
+ * which Infura networks to enable by default.
30
+ */
31
+ exports.DEFAULT_INFURA_NETWORKS = [
32
+ exports.InfuraNetworkType.mainnet,
33
+ exports.InfuraNetworkType.goerli,
34
+ exports.InfuraNetworkType.sepolia,
35
+ exports.InfuraNetworkType['linea-goerli'],
36
+ exports.InfuraNetworkType['linea-sepolia'],
37
+ exports.InfuraNetworkType['linea-mainnet'],
38
+ exports.InfuraNetworkType['base-mainnet'],
39
+ exports.InfuraNetworkType['arbitrum-mainnet'],
40
+ exports.InfuraNetworkType['bsc-mainnet'],
41
+ exports.InfuraNetworkType['optimism-mainnet'],
42
+ exports.InfuraNetworkType['polygon-mainnet'],
43
+ exports.InfuraNetworkType['monad-mainnet'],
44
+ ];
45
+ /**
46
+ * Custom network types that are not part of Infura.
47
+ */
48
+ exports.CustomNetworkType = {
49
+ /**
50
+ * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.
51
+ */
52
+ 'megaeth-testnet': 'megaeth-testnet',
53
+ 'megaeth-testnet-v2': 'megaeth-testnet-v2',
54
+ 'monad-testnet': 'monad-testnet',
55
+ };
56
+ /**
57
+ * The "network type"; either the name of a built-in network, or "rpc" for custom networks.
58
+ */
59
+ exports.NetworkType = {
60
+ ...exports.InfuraNetworkType,
61
+ ...exports.CustomNetworkType,
62
+ rpc: 'rpc',
63
+ };
64
+ /**
65
+ * A helper to determine whether a given input is NetworkType.
66
+ *
67
+ * @param val - the value to check whether it is NetworkType or not.
68
+ * @returns boolean indicating whether or not the argument is NetworkType.
69
+ */
70
+ function isNetworkType(val) {
71
+ return Object.values(exports.NetworkType).includes(val);
72
+ }
73
+ exports.isNetworkType = isNetworkType;
74
+ /**
75
+ * A type guard to determine whether the input is an InfuraNetworkType.
76
+ *
77
+ * @param value - The value to check.
78
+ * @returns True if the given value is within the InfuraNetworkType enum,
79
+ * false otherwise.
80
+ */
81
+ function isInfuraNetworkType(value) {
82
+ const infuraNetworkTypes = Object.keys(exports.InfuraNetworkType);
83
+ return infuraNetworkTypes.includes(value);
84
+ }
85
+ exports.isInfuraNetworkType = isInfuraNetworkType;
86
+ /**
87
+ * Names of networks built into the wallet.
88
+ *
89
+ * This includes both Infura and non-Infura networks.
90
+ */
91
+ var BuiltInNetworkName;
92
+ (function (BuiltInNetworkName) {
93
+ BuiltInNetworkName["Mainnet"] = "mainnet";
94
+ BuiltInNetworkName["Goerli"] = "goerli";
95
+ BuiltInNetworkName["Sepolia"] = "sepolia";
96
+ BuiltInNetworkName["LineaGoerli"] = "linea-goerli";
97
+ BuiltInNetworkName["LineaSepolia"] = "linea-sepolia";
98
+ BuiltInNetworkName["LineaMainnet"] = "linea-mainnet";
99
+ BuiltInNetworkName["Aurora"] = "aurora";
100
+ /**
101
+ * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.
102
+ */
103
+ BuiltInNetworkName["MegaETHTestnet"] = "megaeth-testnet";
104
+ BuiltInNetworkName["MegaETHTestnetV2"] = "megaeth-testnet-v2";
105
+ BuiltInNetworkName["MonadTestnet"] = "monad-testnet";
106
+ BuiltInNetworkName["BaseMainnet"] = "base-mainnet";
107
+ BuiltInNetworkName["ArbitrumOne"] = "arbitrum-mainnet";
108
+ BuiltInNetworkName["BscMainnet"] = "bsc-mainnet";
109
+ BuiltInNetworkName["OptimismMainnet"] = "optimism-mainnet";
110
+ BuiltInNetworkName["PolygonMainnet"] = "polygon-mainnet";
111
+ BuiltInNetworkName["SeiMainnet"] = "sei-mainnet";
112
+ BuiltInNetworkName["MegaETHMainnet"] = "megaeth-mainnet";
113
+ BuiltInNetworkName["MonadMainnet"] = "monad-mainnet";
114
+ BuiltInNetworkName["AvalancheMainnet"] = "avalanche-mainnet";
115
+ BuiltInNetworkName["ZksyncMainnet"] = "zksync-mainnet";
116
+ })(BuiltInNetworkName || (exports.BuiltInNetworkName = BuiltInNetworkName = {}));
117
+ /**
118
+ * Decimal string chain IDs of built-in networks, by name.
119
+ *
120
+ * `toHex` not invoked to avoid cyclic dependency
121
+ */
122
+ exports.ChainId = {
123
+ [BuiltInNetworkName.Mainnet]: '0x1', // toHex(1)
124
+ [BuiltInNetworkName.Goerli]: '0x5', // toHex(5)
125
+ [BuiltInNetworkName.Sepolia]: '0xaa36a7', // toHex(11155111)
126
+ [BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554)
127
+ [BuiltInNetworkName.LineaGoerli]: '0xe704', // toHex(59140)
128
+ [BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141)
129
+ [BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144)
130
+ /**
131
+ * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.
132
+ */
133
+ [BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342)
134
+ [BuiltInNetworkName.MegaETHTestnetV2]: '0x18c7', // toHex(6343)
135
+ [BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143)
136
+ [BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453)
137
+ [BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161)
138
+ [BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56)
139
+ [BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10)
140
+ [BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)
141
+ [BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)
142
+ [BuiltInNetworkName.MegaETHMainnet]: '0x10e6', // toHex(4326)
143
+ [BuiltInNetworkName.MonadMainnet]: '0x8f', // toHex(143)
144
+ [BuiltInNetworkName.AvalancheMainnet]: '0xa86a', // toHex(43114)
145
+ [BuiltInNetworkName.ZksyncMainnet]: '0x144', // toHex(324)
146
+ };
147
+ /* eslint-disable @typescript-eslint/naming-convention */
148
+ var NetworksTicker;
149
+ (function (NetworksTicker) {
150
+ NetworksTicker["mainnet"] = "ETH";
151
+ NetworksTicker["goerli"] = "GoerliETH";
152
+ NetworksTicker["sepolia"] = "SepoliaETH";
153
+ NetworksTicker["linea-goerli"] = "LineaETH";
154
+ // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
155
+ NetworksTicker["linea-sepolia"] = "LineaETH";
156
+ // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
157
+ NetworksTicker["linea-mainnet"] = "ETH";
158
+ /**
159
+ * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.
160
+ */
161
+ NetworksTicker["megaeth-testnet"] = "MegaETH";
162
+ // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
163
+ NetworksTicker["megaeth-testnet-v2"] = "MegaETH";
164
+ NetworksTicker["monad-testnet"] = "MON";
165
+ // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
166
+ NetworksTicker["base-mainnet"] = "ETH";
167
+ // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
168
+ NetworksTicker["arbitrum-mainnet"] = "ETH";
169
+ NetworksTicker["bsc-mainnet"] = "BNB";
170
+ // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
171
+ NetworksTicker["optimism-mainnet"] = "ETH";
172
+ NetworksTicker["polygon-mainnet"] = "POL";
173
+ NetworksTicker["sei-mainnet"] = "SEI";
174
+ // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
175
+ NetworksTicker["megaeth-mainnet"] = "ETH";
176
+ // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
177
+ NetworksTicker["monad-mainnet"] = "MON";
178
+ NetworksTicker["avalanche-mainnet"] = "AVAX";
179
+ // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
180
+ NetworksTicker["zksync-mainnet"] = "ETH";
181
+ NetworksTicker["rpc"] = "";
182
+ })(NetworksTicker || (exports.NetworksTicker = NetworksTicker = {}));
183
+ /* eslint-enable @typescript-eslint/naming-convention */
184
+ exports.BlockExplorerUrl = {
185
+ [BuiltInNetworkName.Mainnet]: 'https://etherscan.io',
186
+ [BuiltInNetworkName.Goerli]: 'https://goerli.etherscan.io',
187
+ [BuiltInNetworkName.Sepolia]: 'https://sepolia.etherscan.io',
188
+ [BuiltInNetworkName.LineaGoerli]: 'https://goerli.lineascan.build',
189
+ [BuiltInNetworkName.LineaSepolia]: 'https://sepolia.lineascan.build',
190
+ [BuiltInNetworkName.LineaMainnet]: 'https://lineascan.build',
191
+ /**
192
+ * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.
193
+ */
194
+ [BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz',
195
+ [BuiltInNetworkName.MegaETHTestnetV2]: 'https://megaeth-testnet-v2.blockscout.com',
196
+ [BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com',
197
+ [BuiltInNetworkName.BaseMainnet]: 'https://basescan.org',
198
+ [BuiltInNetworkName.ArbitrumOne]: 'https://arbiscan.io',
199
+ [BuiltInNetworkName.BscMainnet]: 'https://bscscan.com',
200
+ [BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io',
201
+ [BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com',
202
+ [BuiltInNetworkName.SeiMainnet]: 'https://seiscan.io',
203
+ [BuiltInNetworkName.MegaETHMainnet]: 'https://megaeth.blockscout.com',
204
+ [BuiltInNetworkName.MonadMainnet]: 'https://monadscan.com',
205
+ [BuiltInNetworkName.AvalancheMainnet]: 'https://snowtrace.io',
206
+ [BuiltInNetworkName.ZksyncMainnet]: 'https://explorer.zksync.io',
207
+ };
208
+ exports.NetworkNickname = {
209
+ [BuiltInNetworkName.Mainnet]: 'Ethereum',
210
+ [BuiltInNetworkName.Goerli]: 'Goerli',
211
+ [BuiltInNetworkName.Sepolia]: 'Sepolia',
212
+ [BuiltInNetworkName.LineaGoerli]: 'Linea Goerli',
213
+ [BuiltInNetworkName.LineaSepolia]: 'Linea Sepolia',
214
+ [BuiltInNetworkName.LineaMainnet]: 'Linea',
215
+ /**
216
+ * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.
217
+ */
218
+ [BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet',
219
+ [BuiltInNetworkName.MegaETHTestnetV2]: 'MegaETH Testnet',
220
+ [BuiltInNetworkName.MonadTestnet]: 'Monad Testnet',
221
+ [BuiltInNetworkName.BaseMainnet]: 'Base',
222
+ [BuiltInNetworkName.ArbitrumOne]: 'Arbitrum',
223
+ [BuiltInNetworkName.BscMainnet]: 'BNB Chain',
224
+ [BuiltInNetworkName.OptimismMainnet]: 'OP',
225
+ [BuiltInNetworkName.PolygonMainnet]: 'Polygon',
226
+ [BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet',
227
+ [BuiltInNetworkName.MegaETHMainnet]: 'MegaETH Mainnet',
228
+ [BuiltInNetworkName.MonadMainnet]: 'Monad',
229
+ [BuiltInNetworkName.AvalancheMainnet]: 'Avalanche Mainnet',
230
+ [BuiltInNetworkName.ZksyncMainnet]: 'ZKsync Era',
231
+ };
232
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,iBAAiB,GAAG;IAC/B,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,cAAc,EAAE,cAAc;IAC9B,eAAe,EAAE,eAAe;IACh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C7D,CAAC,kBAAkB,CAAC,aAAa,CAAC,EAAE,4BAA4B;CACX,CAAC;AAI3C,QAAA,eAAe,GAAG;IAC7B,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,UAAU;IACxC,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,QAAQ;IACrC,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,SAAS;IACvC,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,cAAc;IAChD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,eAAe;IAClD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,OAAO;IAC1C;;OAEG;IACH,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,cAAc;IACnD,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,EAAE,iBAAiB;IACxD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,eAAe;IAClD,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,MAAM;IACxC,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,UAAU;IAC5C,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,WAAW;IAC5C,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,IAAI;IAC1C,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,SAAS;IAC9C,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,aAAa;IAC9C,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,iBAAiB;IACtD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,OAAO;IAC1C,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,EAAE,mBAAmB;IAC1D,CAAC,kBAAkB,CAAC,aAAa,CAAC,EAAE,YAAY;CACK,CAAC","sourcesContent":["/**\n * The names of built-in Infura networks\n */\nexport const InfuraNetworkType = {\n mainnet: 'mainnet',\n goerli: 'goerli',\n sepolia: 'sepolia',\n 'linea-goerli': 'linea-goerli',\n 'linea-sepolia': 'linea-sepolia',\n 'linea-mainnet': 'linea-mainnet',\n 'base-mainnet': 'base-mainnet',\n 'arbitrum-mainnet': 'arbitrum-mainnet',\n 'bsc-mainnet': 'bsc-mainnet',\n 'optimism-mainnet': 'optimism-mainnet',\n 'polygon-mainnet': 'polygon-mainnet',\n 'sei-mainnet': 'sei-mainnet',\n 'monad-mainnet': 'monad-mainnet',\n 'megaeth-mainnet': 'megaeth-mainnet',\n 'avalanche-mainnet': 'avalanche-mainnet',\n 'zksync-mainnet': 'zksync-mainnet',\n} as const;\n\nexport type InfuraNetworkType =\n (typeof InfuraNetworkType)[keyof typeof InfuraNetworkType];\n\n/**\n * The default set of Infura networks to include in the wallet.\n *\n * This is a subset of the full list of {@link InfuraNetworkType}, and can be used to determine\n * which Infura networks to enable by default.\n */\nexport const DEFAULT_INFURA_NETWORKS = [\n InfuraNetworkType.mainnet,\n InfuraNetworkType.goerli,\n InfuraNetworkType.sepolia,\n InfuraNetworkType['linea-goerli'],\n InfuraNetworkType['linea-sepolia'],\n InfuraNetworkType['linea-mainnet'],\n InfuraNetworkType['base-mainnet'],\n InfuraNetworkType['arbitrum-mainnet'],\n InfuraNetworkType['bsc-mainnet'],\n InfuraNetworkType['optimism-mainnet'],\n InfuraNetworkType['polygon-mainnet'],\n InfuraNetworkType['monad-mainnet'],\n] as const satisfies InfuraNetworkType[];\n\n/**\n * Custom network types that are not part of Infura.\n */\nexport const CustomNetworkType = {\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet': 'megaeth-testnet',\n 'megaeth-testnet-v2': 'megaeth-testnet-v2',\n 'monad-testnet': 'monad-testnet',\n} as const;\nexport type CustomNetworkType =\n (typeof CustomNetworkType)[keyof typeof CustomNetworkType];\n\n/**\n * Network types supported including both Infura networks and other networks.\n */\nexport type BuiltInNetworkType = InfuraNetworkType | CustomNetworkType;\n\n/**\n * The \"network type\"; either the name of a built-in network, or \"rpc\" for custom networks.\n */\nexport const NetworkType = {\n ...InfuraNetworkType,\n ...CustomNetworkType,\n rpc: 'rpc',\n} as const;\n\nexport type NetworkType = (typeof NetworkType)[keyof typeof NetworkType];\n\n/**\n * A helper to determine whether a given input is NetworkType.\n *\n * @param val - the value to check whether it is NetworkType or not.\n * @returns boolean indicating whether or not the argument is NetworkType.\n */\nexport function isNetworkType(val: string): val is NetworkType {\n return Object.values(NetworkType).includes(val as NetworkType);\n}\n\n/**\n * A type guard to determine whether the input is an InfuraNetworkType.\n *\n * @param value - The value to check.\n * @returns True if the given value is within the InfuraNetworkType enum,\n * false otherwise.\n */\nexport function isInfuraNetworkType(\n value: unknown,\n): value is InfuraNetworkType {\n const infuraNetworkTypes: unknown[] = Object.keys(InfuraNetworkType);\n return infuraNetworkTypes.includes(value);\n}\n\n/**\n * Names of networks built into the wallet.\n *\n * This includes both Infura and non-Infura networks.\n */\nexport enum BuiltInNetworkName {\n Mainnet = 'mainnet',\n Goerli = 'goerli',\n Sepolia = 'sepolia',\n LineaGoerli = 'linea-goerli',\n LineaSepolia = 'linea-sepolia',\n LineaMainnet = 'linea-mainnet',\n Aurora = 'aurora',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n MegaETHTestnet = 'megaeth-testnet',\n MegaETHTestnetV2 = 'megaeth-testnet-v2',\n MonadTestnet = 'monad-testnet',\n BaseMainnet = 'base-mainnet',\n ArbitrumOne = 'arbitrum-mainnet',\n BscMainnet = 'bsc-mainnet',\n OptimismMainnet = 'optimism-mainnet',\n PolygonMainnet = 'polygon-mainnet',\n SeiMainnet = 'sei-mainnet',\n MegaETHMainnet = 'megaeth-mainnet',\n MonadMainnet = 'monad-mainnet',\n AvalancheMainnet = 'avalanche-mainnet',\n ZksyncMainnet = 'zksync-mainnet',\n}\n\n/**\n * Decimal string chain IDs of built-in networks, by name.\n *\n * `toHex` not invoked to avoid cyclic dependency\n */\nexport const ChainId = {\n [BuiltInNetworkName.Mainnet]: '0x1', // toHex(1)\n [BuiltInNetworkName.Goerli]: '0x5', // toHex(5)\n [BuiltInNetworkName.Sepolia]: '0xaa36a7', // toHex(11155111)\n [BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554)\n [BuiltInNetworkName.LineaGoerli]: '0xe704', // toHex(59140)\n [BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141)\n [BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144)\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342)\n [BuiltInNetworkName.MegaETHTestnetV2]: '0x18c7', // toHex(6343)\n [BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143)\n [BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453)\n [BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161)\n [BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56)\n [BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10)\n [BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)\n [BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)\n [BuiltInNetworkName.MegaETHMainnet]: '0x10e6', // toHex(4326)\n [BuiltInNetworkName.MonadMainnet]: '0x8f', // toHex(143)\n [BuiltInNetworkName.AvalancheMainnet]: '0xa86a', // toHex(43114)\n [BuiltInNetworkName.ZksyncMainnet]: '0x144', // toHex(324)\n} as const;\nexport type ChainId = (typeof ChainId)[keyof typeof ChainId];\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum NetworksTicker {\n mainnet = 'ETH',\n goerli = 'GoerliETH',\n sepolia = 'SepoliaETH',\n 'linea-goerli' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-sepolia' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-mainnet' = 'ETH',\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet' = 'MegaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'megaeth-testnet-v2' = 'MegaETH',\n 'monad-testnet' = 'MON',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'base-mainnet' = 'ETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'arbitrum-mainnet' = 'ETH',\n 'bsc-mainnet' = 'BNB',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'optimism-mainnet' = 'ETH',\n 'polygon-mainnet' = 'POL',\n 'sei-mainnet' = 'SEI',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'megaeth-mainnet' = 'ETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'monad-mainnet' = 'MON',\n 'avalanche-mainnet' = 'AVAX',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'zksync-mainnet' = 'ETH',\n rpc = '',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const BlockExplorerUrl = {\n [BuiltInNetworkName.Mainnet]: 'https://etherscan.io',\n [BuiltInNetworkName.Goerli]: 'https://goerli.etherscan.io',\n [BuiltInNetworkName.Sepolia]: 'https://sepolia.etherscan.io',\n [BuiltInNetworkName.LineaGoerli]: 'https://goerli.lineascan.build',\n [BuiltInNetworkName.LineaSepolia]: 'https://sepolia.lineascan.build',\n [BuiltInNetworkName.LineaMainnet]: 'https://lineascan.build',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz',\n [BuiltInNetworkName.MegaETHTestnetV2]:\n 'https://megaeth-testnet-v2.blockscout.com',\n [BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com',\n [BuiltInNetworkName.BaseMainnet]: 'https://basescan.org',\n [BuiltInNetworkName.ArbitrumOne]: 'https://arbiscan.io',\n [BuiltInNetworkName.BscMainnet]: 'https://bscscan.com',\n [BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io',\n [BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com',\n [BuiltInNetworkName.SeiMainnet]: 'https://seiscan.io',\n [BuiltInNetworkName.MegaETHMainnet]: 'https://megaeth.blockscout.com',\n [BuiltInNetworkName.MonadMainnet]: 'https://monadscan.com',\n [BuiltInNetworkName.AvalancheMainnet]: 'https://snowtrace.io',\n [BuiltInNetworkName.ZksyncMainnet]: 'https://explorer.zksync.io',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type BlockExplorerUrl =\n (typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl];\n\nexport const NetworkNickname = {\n [BuiltInNetworkName.Mainnet]: 'Ethereum',\n [BuiltInNetworkName.Goerli]: 'Goerli',\n [BuiltInNetworkName.Sepolia]: 'Sepolia',\n [BuiltInNetworkName.LineaGoerli]: 'Linea Goerli',\n [BuiltInNetworkName.LineaSepolia]: 'Linea Sepolia',\n [BuiltInNetworkName.LineaMainnet]: 'Linea',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet',\n [BuiltInNetworkName.MegaETHTestnetV2]: 'MegaETH Testnet',\n [BuiltInNetworkName.MonadTestnet]: 'Monad Testnet',\n [BuiltInNetworkName.BaseMainnet]: 'Base',\n [BuiltInNetworkName.ArbitrumOne]: 'Arbitrum',\n [BuiltInNetworkName.BscMainnet]: 'BNB Chain',\n [BuiltInNetworkName.OptimismMainnet]: 'OP',\n [BuiltInNetworkName.PolygonMainnet]: 'Polygon',\n [BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet',\n [BuiltInNetworkName.MegaETHMainnet]: 'MegaETH Mainnet',\n [BuiltInNetworkName.MonadMainnet]: 'Monad',\n [BuiltInNetworkName.AvalancheMainnet]: 'Avalanche Mainnet',\n [BuiltInNetworkName.ZksyncMainnet]: 'ZKsync Era',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type NetworkNickname =\n (typeof NetworkNickname)[keyof typeof NetworkNickname];\n\n/**\n * Makes a selection of keys in a Record optional.\n *\n * @template Type - The Record that you want to operate on.\n * @template Key - The union of keys you want to make optional.\n */\n// TODO: Move to @metamask/utils\nexport type Partialize<Type, Key extends keyof Type> = Omit<Type, Key> &\n Partial<Pick<Type, Key>>;\n\n/** A context in which to execute a trace, in order to generate nested timings. */\nexport type TraceContext = unknown;\n\n/** Request to trace an operation. */\nexport type TraceRequest = {\n /** Additional data to include in the trace. */\n data?: Record<string, number | string | boolean>;\n\n /** Name of the operation. */\n name: string;\n\n /**\n * Unique identifier for the trace.\n * Required if starting a trace and not providing a callback.\n */\n id?: string;\n\n /** Trace context in which to execute the operation. */\n parentContext?: TraceContext;\n\n /** Additional tags to include in the trace to filter results. */\n tags?: Record<string, number | string | boolean>;\n\n /**\n * Override the start time of the trace, in milliseconds.\n * Useful to backdate a span when the traced work has already completed.\n */\n startTime?: number;\n};\n\n/** Callback that traces the performance of an operation. */\nexport type TraceCallback = <ReturnType>(\n /** Request to trace the performance of an operation. */\n request: TraceRequest,\n\n /**\n * Callback to trace.\n * Thrown errors will not be caught, but the trace will still be recorded.\n *\n * @param context - The context in which the operation is running.\n */\n fn?: (context?: TraceContext) => ReturnType,\n) => Promise<ReturnType>;\n"]}