@metamask-previews/eth-json-rpc-middleware 21.0.0-preview-468843ab

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 (164) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE +15 -0
  3. package/README.md +23 -0
  4. package/dist/block-cache.cjs +165 -0
  5. package/dist/block-cache.cjs.map +1 -0
  6. package/dist/block-cache.d.cts +9 -0
  7. package/dist/block-cache.d.cts.map +1 -0
  8. package/dist/block-cache.d.mts +9 -0
  9. package/dist/block-cache.d.mts.map +1 -0
  10. package/dist/block-cache.mjs +161 -0
  11. package/dist/block-cache.mjs.map +1 -0
  12. package/dist/block-ref-rewrite.cjs +33 -0
  13. package/dist/block-ref-rewrite.cjs.map +1 -0
  14. package/dist/block-ref-rewrite.d.cts +9 -0
  15. package/dist/block-ref-rewrite.d.cts.map +1 -0
  16. package/dist/block-ref-rewrite.d.mts +9 -0
  17. package/dist/block-ref-rewrite.d.mts.map +1 -0
  18. package/dist/block-ref-rewrite.mjs +29 -0
  19. package/dist/block-ref-rewrite.mjs.map +1 -0
  20. package/dist/block-ref.cjs +46 -0
  21. package/dist/block-ref.cjs.map +1 -0
  22. package/dist/block-ref.d.cts +11 -0
  23. package/dist/block-ref.d.cts.map +1 -0
  24. package/dist/block-ref.d.mts +11 -0
  25. package/dist/block-ref.d.mts.map +1 -0
  26. package/dist/block-ref.mjs +42 -0
  27. package/dist/block-ref.mjs.map +1 -0
  28. package/dist/block-tracker-inspector.cjs +58 -0
  29. package/dist/block-tracker-inspector.cjs.map +1 -0
  30. package/dist/block-tracker-inspector.d.cts +9 -0
  31. package/dist/block-tracker-inspector.d.cts.map +1 -0
  32. package/dist/block-tracker-inspector.d.mts +9 -0
  33. package/dist/block-tracker-inspector.d.mts.map +1 -0
  34. package/dist/block-tracker-inspector.mjs +54 -0
  35. package/dist/block-tracker-inspector.mjs.map +1 -0
  36. package/dist/fetch.cjs +48 -0
  37. package/dist/fetch.cjs.map +1 -0
  38. package/dist/fetch.d.cts +22 -0
  39. package/dist/fetch.d.cts.map +1 -0
  40. package/dist/fetch.d.mts +22 -0
  41. package/dist/fetch.d.mts.map +1 -0
  42. package/dist/fetch.mjs +44 -0
  43. package/dist/fetch.mjs.map +1 -0
  44. package/dist/index.cjs +28 -0
  45. package/dist/index.cjs.map +1 -0
  46. package/dist/index.d.cts +12 -0
  47. package/dist/index.d.cts.map +1 -0
  48. package/dist/index.d.mts +12 -0
  49. package/dist/index.d.mts.map +1 -0
  50. package/dist/index.mjs +10 -0
  51. package/dist/index.mjs.map +1 -0
  52. package/dist/inflight-cache.cjs +80 -0
  53. package/dist/inflight-cache.cjs.map +1 -0
  54. package/dist/inflight-cache.d.cts +4 -0
  55. package/dist/inflight-cache.d.cts.map +1 -0
  56. package/dist/inflight-cache.d.mts +4 -0
  57. package/dist/inflight-cache.d.mts.map +1 -0
  58. package/dist/inflight-cache.mjs +76 -0
  59. package/dist/inflight-cache.mjs.map +1 -0
  60. package/dist/logging-utils.cjs +7 -0
  61. package/dist/logging-utils.cjs.map +1 -0
  62. package/dist/logging-utils.d.cts +5 -0
  63. package/dist/logging-utils.d.cts.map +1 -0
  64. package/dist/logging-utils.d.mts +5 -0
  65. package/dist/logging-utils.d.mts.map +1 -0
  66. package/dist/logging-utils.mjs +4 -0
  67. package/dist/logging-utils.mjs.map +1 -0
  68. package/dist/methods/wallet-request-execution-permissions.cjs +41 -0
  69. package/dist/methods/wallet-request-execution-permissions.cjs.map +1 -0
  70. package/dist/methods/wallet-request-execution-permissions.d.cts +131 -0
  71. package/dist/methods/wallet-request-execution-permissions.d.cts.map +1 -0
  72. package/dist/methods/wallet-request-execution-permissions.d.mts +131 -0
  73. package/dist/methods/wallet-request-execution-permissions.d.mts.map +1 -0
  74. package/dist/methods/wallet-request-execution-permissions.mjs +37 -0
  75. package/dist/methods/wallet-request-execution-permissions.mjs.map +1 -0
  76. package/dist/methods/wallet-revoke-execution-permission.cjs +20 -0
  77. package/dist/methods/wallet-revoke-execution-permission.cjs.map +1 -0
  78. package/dist/methods/wallet-revoke-execution-permission.d.cts +13 -0
  79. package/dist/methods/wallet-revoke-execution-permission.d.cts.map +1 -0
  80. package/dist/methods/wallet-revoke-execution-permission.d.mts +13 -0
  81. package/dist/methods/wallet-revoke-execution-permission.d.mts.map +1 -0
  82. package/dist/methods/wallet-revoke-execution-permission.mjs +16 -0
  83. package/dist/methods/wallet-revoke-execution-permission.mjs.map +1 -0
  84. package/dist/providerAsMiddleware.cjs +11 -0
  85. package/dist/providerAsMiddleware.cjs.map +1 -0
  86. package/dist/providerAsMiddleware.d.cts +5 -0
  87. package/dist/providerAsMiddleware.d.cts.map +1 -0
  88. package/dist/providerAsMiddleware.d.mts +5 -0
  89. package/dist/providerAsMiddleware.d.mts.map +1 -0
  90. package/dist/providerAsMiddleware.mjs +7 -0
  91. package/dist/providerAsMiddleware.mjs.map +1 -0
  92. package/dist/retryOnEmpty.cjs +100 -0
  93. package/dist/retryOnEmpty.cjs.map +1 -0
  94. package/dist/retryOnEmpty.d.cts +11 -0
  95. package/dist/retryOnEmpty.d.cts.map +1 -0
  96. package/dist/retryOnEmpty.d.mts +11 -0
  97. package/dist/retryOnEmpty.d.mts.map +1 -0
  98. package/dist/retryOnEmpty.mjs +96 -0
  99. package/dist/retryOnEmpty.mjs.map +1 -0
  100. package/dist/types.cjs +3 -0
  101. package/dist/types.cjs.map +1 -0
  102. package/dist/types.d.cts +25 -0
  103. package/dist/types.d.cts.map +1 -0
  104. package/dist/types.d.mts +25 -0
  105. package/dist/types.d.mts.map +1 -0
  106. package/dist/types.mjs +2 -0
  107. package/dist/types.mjs.map +1 -0
  108. package/dist/utils/cache.cjs +186 -0
  109. package/dist/utils/cache.cjs.map +1 -0
  110. package/dist/utils/cache.d.cts +68 -0
  111. package/dist/utils/cache.d.cts.map +1 -0
  112. package/dist/utils/cache.d.mts +68 -0
  113. package/dist/utils/cache.d.mts.map +1 -0
  114. package/dist/utils/cache.mjs +178 -0
  115. package/dist/utils/cache.mjs.map +1 -0
  116. package/dist/utils/common.cjs +17 -0
  117. package/dist/utils/common.cjs.map +1 -0
  118. package/dist/utils/common.d.cts +8 -0
  119. package/dist/utils/common.d.cts.map +1 -0
  120. package/dist/utils/common.d.mts +8 -0
  121. package/dist/utils/common.d.mts.map +1 -0
  122. package/dist/utils/common.mjs +13 -0
  123. package/dist/utils/common.mjs.map +1 -0
  124. package/dist/utils/error.cjs +12 -0
  125. package/dist/utils/error.cjs.map +1 -0
  126. package/dist/utils/error.d.cts +3 -0
  127. package/dist/utils/error.d.cts.map +1 -0
  128. package/dist/utils/error.d.mts +3 -0
  129. package/dist/utils/error.d.mts.map +1 -0
  130. package/dist/utils/error.mjs +8 -0
  131. package/dist/utils/error.mjs.map +1 -0
  132. package/dist/utils/normalize.cjs +52 -0
  133. package/dist/utils/normalize.cjs.map +1 -0
  134. package/dist/utils/normalize.d.cts +26 -0
  135. package/dist/utils/normalize.d.cts.map +1 -0
  136. package/dist/utils/normalize.d.mts +26 -0
  137. package/dist/utils/normalize.d.mts.map +1 -0
  138. package/dist/utils/normalize.mjs +47 -0
  139. package/dist/utils/normalize.mjs.map +1 -0
  140. package/dist/utils/timeout.cjs +14 -0
  141. package/dist/utils/timeout.cjs.map +1 -0
  142. package/dist/utils/timeout.d.cts +8 -0
  143. package/dist/utils/timeout.d.cts.map +1 -0
  144. package/dist/utils/timeout.d.mts +8 -0
  145. package/dist/utils/timeout.d.mts.map +1 -0
  146. package/dist/utils/timeout.mjs +10 -0
  147. package/dist/utils/timeout.mjs.map +1 -0
  148. package/dist/utils/validation.cjs +43 -0
  149. package/dist/utils/validation.cjs.map +1 -0
  150. package/dist/utils/validation.d.cts +8 -0
  151. package/dist/utils/validation.d.cts.map +1 -0
  152. package/dist/utils/validation.d.mts +8 -0
  153. package/dist/utils/validation.d.mts.map +1 -0
  154. package/dist/utils/validation.mjs +37 -0
  155. package/dist/utils/validation.mjs.map +1 -0
  156. package/dist/wallet.cjs +327 -0
  157. package/dist/wallet.cjs.map +1 -0
  158. package/dist/wallet.d.cts +33 -0
  159. package/dist/wallet.d.cts.map +1 -0
  160. package/dist/wallet.d.mts +33 -0
  161. package/dist/wallet.d.mts.map +1 -0
  162. package/dist/wallet.mjs +300 -0
  163. package/dist/wallet.mjs.map +1 -0
  164. package/package.json +95 -0
@@ -0,0 +1,68 @@
1
+ import type { Json, JsonRpcRequest } from "@metamask/utils";
2
+ /**
3
+ * The cache strategy to use for a given method.
4
+ */
5
+ export declare enum CacheStrategy {
6
+ /**
7
+ * Cache per-block.
8
+ */
9
+ Block = "block",
10
+ /**
11
+ * Cache until a chain reorganization occurs.
12
+ */
13
+ Fork = "fork",
14
+ /**
15
+ * Never cache.
16
+ */
17
+ Never = "never",
18
+ /**
19
+ * Permanently cache.
20
+ */
21
+ Permanent = "perma"
22
+ }
23
+ /**
24
+ * Return a cache identifier for the given request.
25
+ *
26
+ * This identifier should include any request details that might impact the
27
+ * response, with the exception of the block parameter if the `skipBlockRef`
28
+ * option is set,
29
+ *
30
+ * If the request cannot be cached, this will return `null`.
31
+ *
32
+ * @param request - The JSON-RPC request.
33
+ * @param skipBlockRef - Skip the block parameter when generating the cache
34
+ * identifier.
35
+ * @returns The cache identifier for this request, or `null` if it can't be
36
+ * cached.
37
+ */
38
+ export declare function cacheIdentifierForRequest(request: JsonRpcRequest, skipBlockRef?: boolean): string | null;
39
+ /**
40
+ * Return whether a method can be cached or not.
41
+ *
42
+ * @param method - The method to check.
43
+ * @returns Whether the method can be cached.
44
+ */
45
+ export declare function canCache(method: string): boolean;
46
+ /**
47
+ * Return the block parameter for the given request, if it has one.
48
+ *
49
+ * @param request - The JSON-RPC request.
50
+ * @returns The block parameter in the given request, or `undefined` if none was found.
51
+ */
52
+ export declare function blockTagForRequest(request: JsonRpcRequest): Json | undefined;
53
+ /**
54
+ * Returns the index of the block parameter for the given method.
55
+ *
56
+ * @param method - A JSON-RPC method.
57
+ * @returns The index of the block parameter for that method, or `undefined` if
58
+ * there is no known block parameter.
59
+ */
60
+ export declare function blockTagParamIndex(method: string): number | undefined;
61
+ /**
62
+ * Return the cache type used for the given method.
63
+ *
64
+ * @param method - A JSON-RPC method.
65
+ * @returns The cache type to use for that method.
66
+ */
67
+ export declare function cacheTypeForMethod(method: string): CacheStrategy;
68
+ //# sourceMappingURL=cache.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.cts","sourceRoot":"","sources":["../../src/utils/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,wBAAwB;AAK5D;;GAEG;AACH,oBAAY,aAAa;IACvB;;OAEG;IACH,KAAK,UAAU;IACf;;OAEG;IACH,IAAI,SAAS;IACb;;OAEG;IACH,KAAK,UAAU;IACf;;OAEG;IACH,SAAS,UAAU;CACpB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,cAAc,EACvB,YAAY,CAAC,EAAE,OAAO,GACrB,MAAM,GAAG,IAAI,CAQf;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,CAgB5E;AA8BD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAkBrE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAgDhE"}
@@ -0,0 +1,68 @@
1
+ import type { Json, JsonRpcRequest } from "@metamask/utils";
2
+ /**
3
+ * The cache strategy to use for a given method.
4
+ */
5
+ export declare enum CacheStrategy {
6
+ /**
7
+ * Cache per-block.
8
+ */
9
+ Block = "block",
10
+ /**
11
+ * Cache until a chain reorganization occurs.
12
+ */
13
+ Fork = "fork",
14
+ /**
15
+ * Never cache.
16
+ */
17
+ Never = "never",
18
+ /**
19
+ * Permanently cache.
20
+ */
21
+ Permanent = "perma"
22
+ }
23
+ /**
24
+ * Return a cache identifier for the given request.
25
+ *
26
+ * This identifier should include any request details that might impact the
27
+ * response, with the exception of the block parameter if the `skipBlockRef`
28
+ * option is set,
29
+ *
30
+ * If the request cannot be cached, this will return `null`.
31
+ *
32
+ * @param request - The JSON-RPC request.
33
+ * @param skipBlockRef - Skip the block parameter when generating the cache
34
+ * identifier.
35
+ * @returns The cache identifier for this request, or `null` if it can't be
36
+ * cached.
37
+ */
38
+ export declare function cacheIdentifierForRequest(request: JsonRpcRequest, skipBlockRef?: boolean): string | null;
39
+ /**
40
+ * Return whether a method can be cached or not.
41
+ *
42
+ * @param method - The method to check.
43
+ * @returns Whether the method can be cached.
44
+ */
45
+ export declare function canCache(method: string): boolean;
46
+ /**
47
+ * Return the block parameter for the given request, if it has one.
48
+ *
49
+ * @param request - The JSON-RPC request.
50
+ * @returns The block parameter in the given request, or `undefined` if none was found.
51
+ */
52
+ export declare function blockTagForRequest(request: JsonRpcRequest): Json | undefined;
53
+ /**
54
+ * Returns the index of the block parameter for the given method.
55
+ *
56
+ * @param method - A JSON-RPC method.
57
+ * @returns The index of the block parameter for that method, or `undefined` if
58
+ * there is no known block parameter.
59
+ */
60
+ export declare function blockTagParamIndex(method: string): number | undefined;
61
+ /**
62
+ * Return the cache type used for the given method.
63
+ *
64
+ * @param method - A JSON-RPC method.
65
+ * @returns The cache type to use for that method.
66
+ */
67
+ export declare function cacheTypeForMethod(method: string): CacheStrategy;
68
+ //# sourceMappingURL=cache.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.mts","sourceRoot":"","sources":["../../src/utils/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,wBAAwB;AAK5D;;GAEG;AACH,oBAAY,aAAa;IACvB;;OAEG;IACH,KAAK,UAAU;IACf;;OAEG;IACH,IAAI,SAAS;IACb;;OAEG;IACH,KAAK,UAAU;IACf;;OAEG;IACH,SAAS,UAAU;CACpB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,cAAc,EACvB,YAAY,CAAC,EAAE,OAAO,GACrB,MAAM,GAAG,IAAI,CAQf;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,CAgB5E;AA8BD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAkBrE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAgDhE"}
@@ -0,0 +1,178 @@
1
+ import { configure } from "safe-stable-stringify";
2
+ const stringify = configure({ bigint: false, circularValue: Error });
3
+ /**
4
+ * The cache strategy to use for a given method.
5
+ */
6
+ export var CacheStrategy;
7
+ (function (CacheStrategy) {
8
+ /**
9
+ * Cache per-block.
10
+ */
11
+ CacheStrategy["Block"] = "block";
12
+ /**
13
+ * Cache until a chain reorganization occurs.
14
+ */
15
+ CacheStrategy["Fork"] = "fork";
16
+ /**
17
+ * Never cache.
18
+ */
19
+ CacheStrategy["Never"] = "never";
20
+ /**
21
+ * Permanently cache.
22
+ */
23
+ CacheStrategy["Permanent"] = "perma";
24
+ })(CacheStrategy || (CacheStrategy = {}));
25
+ /**
26
+ * Return a cache identifier for the given request.
27
+ *
28
+ * This identifier should include any request details that might impact the
29
+ * response, with the exception of the block parameter if the `skipBlockRef`
30
+ * option is set,
31
+ *
32
+ * If the request cannot be cached, this will return `null`.
33
+ *
34
+ * @param request - The JSON-RPC request.
35
+ * @param skipBlockRef - Skip the block parameter when generating the cache
36
+ * identifier.
37
+ * @returns The cache identifier for this request, or `null` if it can't be
38
+ * cached.
39
+ */
40
+ export function cacheIdentifierForRequest(request, skipBlockRef) {
41
+ const simpleParams = skipBlockRef
42
+ ? paramsWithoutBlockTag(request)
43
+ : (request.params ?? []);
44
+ if (canCache(request.method)) {
45
+ return `${request.method}:${stringify(simpleParams)}`;
46
+ }
47
+ return null;
48
+ }
49
+ /**
50
+ * Return whether a method can be cached or not.
51
+ *
52
+ * @param method - The method to check.
53
+ * @returns Whether the method can be cached.
54
+ */
55
+ export function canCache(method) {
56
+ return cacheTypeForMethod(method) !== CacheStrategy.Never;
57
+ }
58
+ /**
59
+ * Return the block parameter for the given request, if it has one.
60
+ *
61
+ * @param request - The JSON-RPC request.
62
+ * @returns The block parameter in the given request, or `undefined` if none was found.
63
+ */
64
+ export function blockTagForRequest(request) {
65
+ if (!request.params) {
66
+ return undefined;
67
+ }
68
+ const index = blockTagParamIndex(request.method);
69
+ // Block tag param not passed.
70
+ if (index === undefined ||
71
+ !Array.isArray(request.params) ||
72
+ index >= request.params.length) {
73
+ return undefined;
74
+ }
75
+ return request.params[index];
76
+ }
77
+ /**
78
+ * Return the request parameters without the block parameter.
79
+ *
80
+ * @param request - The JSON-RPC request.
81
+ * @returns The request parameters with the block parameter removed, if one was found.
82
+ */
83
+ function paramsWithoutBlockTag(request) {
84
+ if (!request.params) {
85
+ return [];
86
+ }
87
+ const index = blockTagParamIndex(request.method);
88
+ // Block tag param not passed.
89
+ if (index === undefined ||
90
+ !Array.isArray(request.params) ||
91
+ index >= request.params.length) {
92
+ return request.params;
93
+ }
94
+ // eth_getBlockByNumber has the block tag first, then the optional includeTx? param
95
+ if (request.method === 'eth_getBlockByNumber') {
96
+ return request.params.slice(1);
97
+ }
98
+ return request.params.slice(0, index);
99
+ }
100
+ /**
101
+ * Returns the index of the block parameter for the given method.
102
+ *
103
+ * @param method - A JSON-RPC method.
104
+ * @returns The index of the block parameter for that method, or `undefined` if
105
+ * there is no known block parameter.
106
+ */
107
+ export function blockTagParamIndex(method) {
108
+ switch (method) {
109
+ // blockTag is at index 2
110
+ case 'eth_getStorageAt':
111
+ return 2;
112
+ // blockTag is at index 1
113
+ case 'eth_getBalance':
114
+ case 'eth_getCode':
115
+ case 'eth_getTransactionCount':
116
+ case 'eth_call':
117
+ return 1;
118
+ // blockTag is at index 0
119
+ case 'eth_getBlockByNumber':
120
+ return 0;
121
+ // there is no blockTag
122
+ default:
123
+ return undefined;
124
+ }
125
+ }
126
+ /**
127
+ * Return the cache type used for the given method.
128
+ *
129
+ * @param method - A JSON-RPC method.
130
+ * @returns The cache type to use for that method.
131
+ */
132
+ export function cacheTypeForMethod(method) {
133
+ switch (method) {
134
+ // cache permanently
135
+ case 'web3_clientVersion':
136
+ case 'web3_sha3':
137
+ case 'eth_protocolVersion':
138
+ case 'eth_getBlockTransactionCountByHash':
139
+ case 'eth_getUncleCountByBlockHash':
140
+ case 'eth_getCode':
141
+ case 'eth_getBlockByHash':
142
+ case 'eth_getTransactionByHash':
143
+ case 'eth_getTransactionByBlockHashAndIndex':
144
+ case 'eth_getTransactionReceipt':
145
+ case 'eth_getUncleByBlockHashAndIndex':
146
+ case 'eth_getCompilers':
147
+ case 'eth_compileLLL':
148
+ case 'eth_compileSolidity':
149
+ case 'eth_compileSerpent':
150
+ case 'shh_version':
151
+ case 'test_permaCache':
152
+ return CacheStrategy.Permanent;
153
+ // cache until fork
154
+ case 'eth_getBlockByNumber':
155
+ case 'eth_getBlockTransactionCountByNumber':
156
+ case 'eth_getUncleCountByBlockNumber':
157
+ case 'eth_getTransactionByBlockNumberAndIndex':
158
+ case 'eth_getUncleByBlockNumberAndIndex':
159
+ case 'test_forkCache':
160
+ return CacheStrategy.Fork;
161
+ // cache for block
162
+ case 'eth_gasPrice':
163
+ case 'eth_blockNumber':
164
+ case 'eth_getBalance':
165
+ case 'eth_getStorageAt':
166
+ case 'eth_getTransactionCount':
167
+ case 'eth_call':
168
+ case 'eth_estimateGas':
169
+ case 'eth_getFilterLogs':
170
+ case 'eth_getLogs':
171
+ case 'test_blockCache':
172
+ return CacheStrategy.Block;
173
+ // never cache
174
+ default:
175
+ return CacheStrategy.Never;
176
+ }
177
+ }
178
+ //# sourceMappingURL=cache.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.mjs","sourceRoot":"","sources":["../../src/utils/cache.ts"],"names":[],"mappings":"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","sourcesContent":["import type { Json, JsonRpcRequest } from '@metamask/utils';\nimport { configure } from 'safe-stable-stringify';\n\nconst stringify = configure({ bigint: false, circularValue: Error });\n\n/**\n * The cache strategy to use for a given method.\n */\nexport enum CacheStrategy {\n /**\n * Cache per-block.\n */\n Block = 'block',\n /**\n * Cache until a chain reorganization occurs.\n */\n Fork = 'fork',\n /**\n * Never cache.\n */\n Never = 'never',\n /**\n * Permanently cache.\n */\n Permanent = 'perma',\n}\n\n/**\n * Return a cache identifier for the given request.\n *\n * This identifier should include any request details that might impact the\n * response, with the exception of the block parameter if the `skipBlockRef`\n * option is set,\n *\n * If the request cannot be cached, this will return `null`.\n *\n * @param request - The JSON-RPC request.\n * @param skipBlockRef - Skip the block parameter when generating the cache\n * identifier.\n * @returns The cache identifier for this request, or `null` if it can't be\n * cached.\n */\nexport function cacheIdentifierForRequest(\n request: JsonRpcRequest,\n skipBlockRef?: boolean,\n): string | null {\n const simpleParams = skipBlockRef\n ? paramsWithoutBlockTag(request)\n : (request.params ?? []);\n if (canCache(request.method)) {\n return `${request.method}:${stringify(simpleParams)}`;\n }\n return null;\n}\n\n/**\n * Return whether a method can be cached or not.\n *\n * @param method - The method to check.\n * @returns Whether the method can be cached.\n */\nexport function canCache(method: string): boolean {\n return cacheTypeForMethod(method) !== CacheStrategy.Never;\n}\n\n/**\n * Return the block parameter for the given request, if it has one.\n *\n * @param request - The JSON-RPC request.\n * @returns The block parameter in the given request, or `undefined` if none was found.\n */\nexport function blockTagForRequest(request: JsonRpcRequest): Json | undefined {\n if (!request.params) {\n return undefined;\n }\n const index: number | undefined = blockTagParamIndex(request.method);\n\n // Block tag param not passed.\n if (\n index === undefined ||\n !Array.isArray(request.params) ||\n index >= request.params.length\n ) {\n return undefined;\n }\n\n return request.params[index];\n}\n\n/**\n * Return the request parameters without the block parameter.\n *\n * @param request - The JSON-RPC request.\n * @returns The request parameters with the block parameter removed, if one was found.\n */\nfunction paramsWithoutBlockTag(request: JsonRpcRequest): Json {\n if (!request.params) {\n return [];\n }\n const index: number | undefined = blockTagParamIndex(request.method);\n\n // Block tag param not passed.\n if (\n index === undefined ||\n !Array.isArray(request.params) ||\n index >= request.params.length\n ) {\n return request.params;\n }\n\n // eth_getBlockByNumber has the block tag first, then the optional includeTx? param\n if (request.method === 'eth_getBlockByNumber') {\n return request.params.slice(1);\n }\n return request.params.slice(0, index);\n}\n\n/**\n * Returns the index of the block parameter for the given method.\n *\n * @param method - A JSON-RPC method.\n * @returns The index of the block parameter for that method, or `undefined` if\n * there is no known block parameter.\n */\nexport function blockTagParamIndex(method: string): number | undefined {\n switch (method) {\n // blockTag is at index 2\n case 'eth_getStorageAt':\n return 2;\n // blockTag is at index 1\n case 'eth_getBalance':\n case 'eth_getCode':\n case 'eth_getTransactionCount':\n case 'eth_call':\n return 1;\n // blockTag is at index 0\n case 'eth_getBlockByNumber':\n return 0;\n // there is no blockTag\n default:\n return undefined;\n }\n}\n\n/**\n * Return the cache type used for the given method.\n *\n * @param method - A JSON-RPC method.\n * @returns The cache type to use for that method.\n */\nexport function cacheTypeForMethod(method: string): CacheStrategy {\n switch (method) {\n // cache permanently\n case 'web3_clientVersion':\n case 'web3_sha3':\n case 'eth_protocolVersion':\n case 'eth_getBlockTransactionCountByHash':\n case 'eth_getUncleCountByBlockHash':\n case 'eth_getCode':\n case 'eth_getBlockByHash':\n case 'eth_getTransactionByHash':\n case 'eth_getTransactionByBlockHashAndIndex':\n case 'eth_getTransactionReceipt':\n case 'eth_getUncleByBlockHashAndIndex':\n case 'eth_getCompilers':\n case 'eth_compileLLL':\n case 'eth_compileSolidity':\n case 'eth_compileSerpent':\n case 'shh_version':\n case 'test_permaCache':\n return CacheStrategy.Permanent;\n\n // cache until fork\n case 'eth_getBlockByNumber':\n case 'eth_getBlockTransactionCountByNumber':\n case 'eth_getUncleCountByBlockNumber':\n case 'eth_getTransactionByBlockNumberAndIndex':\n case 'eth_getUncleByBlockNumberAndIndex':\n case 'test_forkCache':\n return CacheStrategy.Fork;\n\n // cache for block\n case 'eth_gasPrice':\n case 'eth_blockNumber':\n case 'eth_getBalance':\n case 'eth_getStorageAt':\n case 'eth_getTransactionCount':\n case 'eth_call':\n case 'eth_estimateGas':\n case 'eth_getFilterLogs':\n case 'eth_getLogs':\n case 'test_blockCache':\n return CacheStrategy.Block;\n\n // never cache\n default:\n return CacheStrategy.Never;\n }\n}\n"]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stripArrayTypeIfPresent = void 0;
4
+ /**
5
+ * Function to stripe array brackets if string defining the type has it.
6
+ *
7
+ * @param typeString - String defining type from which array brackets are required to be removed.
8
+ * @returns Parameter string with array brackets [] removed.
9
+ */
10
+ const stripArrayTypeIfPresent = (typeString) => {
11
+ if (typeString?.match(/\S\[\d*\]$/u)) {
12
+ return typeString.replace(/\[\d*\]$/gu, '').trim();
13
+ }
14
+ return typeString;
15
+ };
16
+ exports.stripArrayTypeIfPresent = stripArrayTypeIfPresent;
17
+ //# sourceMappingURL=common.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.cjs","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CAAC,UAAkB,EAAE,EAAE;IAC5D,IAAI,UAAU,EAAE,KAAK,CAAC,aAAa,CAAC,EAAE;QACpC,OAAO,UAAU,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;KACpD;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AALW,QAAA,uBAAuB,2BAKlC","sourcesContent":["/**\n * Function to stripe array brackets if string defining the type has it.\n *\n * @param typeString - String defining type from which array brackets are required to be removed.\n * @returns Parameter string with array brackets [] removed.\n */\nexport const stripArrayTypeIfPresent = (typeString: string) => {\n if (typeString?.match(/\\S\\[\\d*\\]$/u)) {\n return typeString.replace(/\\[\\d*\\]$/gu, '').trim();\n }\n return typeString;\n};\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Function to stripe array brackets if string defining the type has it.
3
+ *
4
+ * @param typeString - String defining type from which array brackets are required to be removed.
5
+ * @returns Parameter string with array brackets [] removed.
6
+ */
7
+ export declare const stripArrayTypeIfPresent: (typeString: string) => string;
8
+ //# sourceMappingURL=common.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.cts","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,eAAgB,MAAM,WAKzD,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Function to stripe array brackets if string defining the type has it.
3
+ *
4
+ * @param typeString - String defining type from which array brackets are required to be removed.
5
+ * @returns Parameter string with array brackets [] removed.
6
+ */
7
+ export declare const stripArrayTypeIfPresent: (typeString: string) => string;
8
+ //# sourceMappingURL=common.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.mts","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,eAAgB,MAAM,WAKzD,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Function to stripe array brackets if string defining the type has it.
3
+ *
4
+ * @param typeString - String defining type from which array brackets are required to be removed.
5
+ * @returns Parameter string with array brackets [] removed.
6
+ */
7
+ export const stripArrayTypeIfPresent = (typeString) => {
8
+ if (typeString?.match(/\S\[\d*\]$/u)) {
9
+ return typeString.replace(/\[\d*\]$/gu, '').trim();
10
+ }
11
+ return typeString;
12
+ };
13
+ //# sourceMappingURL=common.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.mjs","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,UAAkB,EAAE,EAAE;IAC5D,IAAI,UAAU,EAAE,KAAK,CAAC,aAAa,CAAC,EAAE;QACpC,OAAO,UAAU,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;KACpD;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC","sourcesContent":["/**\n * Function to stripe array brackets if string defining the type has it.\n *\n * @param typeString - String defining type from which array brackets are required to be removed.\n * @returns Parameter string with array brackets [] removed.\n */\nexport const stripArrayTypeIfPresent = (typeString: string) => {\n if (typeString?.match(/\\S\\[\\d*\\]$/u)) {\n return typeString.replace(/\\[\\d*\\]$/gu, '').trim();\n }\n return typeString;\n};\n"]}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isExecutionRevertedError = void 0;
4
+ const rpc_errors_1 = require("@metamask/rpc-errors");
5
+ const utils_1 = require("@metamask/utils");
6
+ function isExecutionRevertedError(error) {
7
+ return ((0, utils_1.isJsonRpcError)(error) &&
8
+ error.code === rpc_errors_1.errorCodes.rpc.invalidInput &&
9
+ error.message === 'execution reverted');
10
+ }
11
+ exports.isExecutionRevertedError = isExecutionRevertedError;
12
+ //# sourceMappingURL=error.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.cjs","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAClD,2CAAiD;AAGjD,SAAgB,wBAAwB,CACtC,KAAc;IAEd,OAAO,CACL,IAAA,sBAAc,EAAC,KAAK,CAAC;QACrB,KAAK,CAAC,IAAI,KAAK,uBAAU,CAAC,GAAG,CAAC,YAAY;QAC1C,KAAK,CAAC,OAAO,KAAK,oBAAoB,CACvC,CAAC;AACJ,CAAC;AARD,4DAQC","sourcesContent":["import { errorCodes } from '@metamask/rpc-errors';\nimport { isJsonRpcError } from '@metamask/utils';\nimport type { JsonRpcError } from '@metamask/utils';\n\nexport function isExecutionRevertedError(\n error: unknown,\n): error is JsonRpcError {\n return (\n isJsonRpcError(error) &&\n error.code === errorCodes.rpc.invalidInput &&\n error.message === 'execution reverted'\n );\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { JsonRpcError } from "@metamask/utils";
2
+ export declare function isExecutionRevertedError(error: unknown): error is JsonRpcError;
3
+ //# sourceMappingURL=error.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.cts","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB;AAEpD,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,YAAY,CAMvB"}
@@ -0,0 +1,3 @@
1
+ import type { JsonRpcError } from "@metamask/utils";
2
+ export declare function isExecutionRevertedError(error: unknown): error is JsonRpcError;
3
+ //# sourceMappingURL=error.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.mts","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB;AAEpD,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,YAAY,CAMvB"}
@@ -0,0 +1,8 @@
1
+ import { errorCodes } from "@metamask/rpc-errors";
2
+ import { isJsonRpcError } from "@metamask/utils";
3
+ export function isExecutionRevertedError(error) {
4
+ return (isJsonRpcError(error) &&
5
+ error.code === errorCodes.rpc.invalidInput &&
6
+ error.message === 'execution reverted');
7
+ }
8
+ //# sourceMappingURL=error.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.mjs","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,6BAA6B;AAClD,OAAO,EAAE,cAAc,EAAE,wBAAwB;AAGjD,MAAM,UAAU,wBAAwB,CACtC,KAAc;IAEd,OAAO,CACL,cAAc,CAAC,KAAK,CAAC;QACrB,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,GAAG,CAAC,YAAY;QAC1C,KAAK,CAAC,OAAO,KAAK,oBAAoB,CACvC,CAAC;AACJ,CAAC","sourcesContent":["import { errorCodes } from '@metamask/rpc-errors';\nimport { isJsonRpcError } from '@metamask/utils';\nimport type { JsonRpcError } from '@metamask/utils';\n\nexport function isExecutionRevertedError(\n error: unknown,\n): error is JsonRpcError {\n return (\n isJsonRpcError(error) &&\n error.code === errorCodes.rpc.invalidInput &&\n error.message === 'execution reverted'\n );\n}\n"]}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseTypedMessage = exports.normalizeTypedMessage = void 0;
4
+ /**
5
+ * Normalizes the messageData for the eth_signTypedData
6
+ *
7
+ * @param messageData - The messageData to normalize.
8
+ * @returns The normalized messageData.
9
+ */
10
+ function normalizeTypedMessage(messageData) {
11
+ let data;
12
+ try {
13
+ data = parseTypedMessage(messageData);
14
+ }
15
+ catch {
16
+ // Ignore normalization errors and pass the message as is
17
+ return messageData;
18
+ }
19
+ const { verifyingContract } = data.domain ?? {};
20
+ if (!verifyingContract) {
21
+ return messageData;
22
+ }
23
+ data.domain.verifyingContract = normalizeContractAddress(verifyingContract);
24
+ return JSON.stringify(data);
25
+ }
26
+ exports.normalizeTypedMessage = normalizeTypedMessage;
27
+ /**
28
+ * Parses the messageData to obtain the data object for EIP712 normalization
29
+ *
30
+ * @param data - The messageData to parse.
31
+ * @returns The data object for EIP712 normalization.
32
+ */
33
+ function parseTypedMessage(data) {
34
+ if (typeof data !== 'string') {
35
+ return data;
36
+ }
37
+ return JSON.parse(data);
38
+ }
39
+ exports.parseTypedMessage = parseTypedMessage;
40
+ /**
41
+ * Normalizes the address to standard hexadecimal format
42
+ *
43
+ * @param address - The address to normalize.
44
+ * @returns The normalized address.
45
+ */
46
+ function normalizeContractAddress(address) {
47
+ if (address.startsWith('0X')) {
48
+ return `0x${address.slice(2)}`;
49
+ }
50
+ return address;
51
+ }
52
+ //# sourceMappingURL=normalize.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.cjs","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":";;;AAaA;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,WAAmB;IACvD,IAAI,IAAI,CAAC;IACT,IAAI;QACF,IAAI,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;KACvC;IAAC,MAAM;QACN,yDAAyD;QACzD,OAAO,WAAW,CAAC;KACpB;IAED,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;IAEhD,IAAI,CAAC,iBAAiB,EAAE;QACtB,OAAO,WAAW,CAAC;KACpB;IAED,IAAI,CAAC,MAAM,CAAC,iBAAiB,GAAG,wBAAwB,CAAC,iBAAiB,CAAC,CAAC;IAE5E,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAlBD,sDAkBC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,IAAI,CAAC;KACb;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAwC,CAAC;AACjE,CAAC;AAND,8CAMC;AAED;;;;;GAKG;AACH,SAAS,wBAAwB,CAAC,OAAY;IAC5C,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAC5B,OAAO,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;KAChC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\ntype EIP712Domain = {\n verifyingContract: Hex;\n};\n\ntype SignTypedMessageDataV3V4 = {\n types: Record<string, unknown>;\n domain: EIP712Domain;\n primaryType: string;\n message: unknown;\n};\n\n/**\n * Normalizes the messageData for the eth_signTypedData\n *\n * @param messageData - The messageData to normalize.\n * @returns The normalized messageData.\n */\nexport function normalizeTypedMessage(messageData: string) {\n let data;\n try {\n data = parseTypedMessage(messageData);\n } catch {\n // Ignore normalization errors and pass the message as is\n return messageData;\n }\n\n const { verifyingContract } = data.domain ?? {};\n\n if (!verifyingContract) {\n return messageData;\n }\n\n data.domain.verifyingContract = normalizeContractAddress(verifyingContract);\n\n return JSON.stringify(data);\n}\n\n/**\n * Parses the messageData to obtain the data object for EIP712 normalization\n *\n * @param data - The messageData to parse.\n * @returns The data object for EIP712 normalization.\n */\nexport function parseTypedMessage(data: string) {\n if (typeof data !== 'string') {\n return data;\n }\n\n return JSON.parse(data) as unknown as SignTypedMessageDataV3V4;\n}\n\n/**\n * Normalizes the address to standard hexadecimal format\n *\n * @param address - The address to normalize.\n * @returns The normalized address.\n */\nfunction normalizeContractAddress(address: Hex): Hex {\n if (address.startsWith('0X')) {\n return `0x${address.slice(2)}`;\n }\n return address;\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import type { Hex } from "@metamask/utils";
2
+ type EIP712Domain = {
3
+ verifyingContract: Hex;
4
+ };
5
+ type SignTypedMessageDataV3V4 = {
6
+ types: Record<string, unknown>;
7
+ domain: EIP712Domain;
8
+ primaryType: string;
9
+ message: unknown;
10
+ };
11
+ /**
12
+ * Normalizes the messageData for the eth_signTypedData
13
+ *
14
+ * @param messageData - The messageData to normalize.
15
+ * @returns The normalized messageData.
16
+ */
17
+ export declare function normalizeTypedMessage(messageData: string): string;
18
+ /**
19
+ * Parses the messageData to obtain the data object for EIP712 normalization
20
+ *
21
+ * @param data - The messageData to parse.
22
+ * @returns The data object for EIP712 normalization.
23
+ */
24
+ export declare function parseTypedMessage(data: string): SignTypedMessageDataV3V4;
25
+ export {};
26
+ //# sourceMappingURL=normalize.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.d.cts","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,KAAK,YAAY,GAAG;IAClB,iBAAiB,EAAE,GAAG,CAAC;CACxB,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,UAkBxD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,4BAM7C"}
@@ -0,0 +1,26 @@
1
+ import type { Hex } from "@metamask/utils";
2
+ type EIP712Domain = {
3
+ verifyingContract: Hex;
4
+ };
5
+ type SignTypedMessageDataV3V4 = {
6
+ types: Record<string, unknown>;
7
+ domain: EIP712Domain;
8
+ primaryType: string;
9
+ message: unknown;
10
+ };
11
+ /**
12
+ * Normalizes the messageData for the eth_signTypedData
13
+ *
14
+ * @param messageData - The messageData to normalize.
15
+ * @returns The normalized messageData.
16
+ */
17
+ export declare function normalizeTypedMessage(messageData: string): string;
18
+ /**
19
+ * Parses the messageData to obtain the data object for EIP712 normalization
20
+ *
21
+ * @param data - The messageData to parse.
22
+ * @returns The data object for EIP712 normalization.
23
+ */
24
+ export declare function parseTypedMessage(data: string): SignTypedMessageDataV3V4;
25
+ export {};
26
+ //# sourceMappingURL=normalize.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.d.mts","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,KAAK,YAAY,GAAG;IAClB,iBAAiB,EAAE,GAAG,CAAC;CACxB,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,UAkBxD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,4BAM7C"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Normalizes the messageData for the eth_signTypedData
3
+ *
4
+ * @param messageData - The messageData to normalize.
5
+ * @returns The normalized messageData.
6
+ */
7
+ export function normalizeTypedMessage(messageData) {
8
+ let data;
9
+ try {
10
+ data = parseTypedMessage(messageData);
11
+ }
12
+ catch {
13
+ // Ignore normalization errors and pass the message as is
14
+ return messageData;
15
+ }
16
+ const { verifyingContract } = data.domain ?? {};
17
+ if (!verifyingContract) {
18
+ return messageData;
19
+ }
20
+ data.domain.verifyingContract = normalizeContractAddress(verifyingContract);
21
+ return JSON.stringify(data);
22
+ }
23
+ /**
24
+ * Parses the messageData to obtain the data object for EIP712 normalization
25
+ *
26
+ * @param data - The messageData to parse.
27
+ * @returns The data object for EIP712 normalization.
28
+ */
29
+ export function parseTypedMessage(data) {
30
+ if (typeof data !== 'string') {
31
+ return data;
32
+ }
33
+ return JSON.parse(data);
34
+ }
35
+ /**
36
+ * Normalizes the address to standard hexadecimal format
37
+ *
38
+ * @param address - The address to normalize.
39
+ * @returns The normalized address.
40
+ */
41
+ function normalizeContractAddress(address) {
42
+ if (address.startsWith('0X')) {
43
+ return `0x${address.slice(2)}`;
44
+ }
45
+ return address;
46
+ }
47
+ //# sourceMappingURL=normalize.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.mjs","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,WAAmB;IACvD,IAAI,IAAI,CAAC;IACT,IAAI;QACF,IAAI,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;KACvC;IAAC,MAAM;QACN,yDAAyD;QACzD,OAAO,WAAW,CAAC;KACpB;IAED,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;IAEhD,IAAI,CAAC,iBAAiB,EAAE;QACtB,OAAO,WAAW,CAAC;KACpB;IAED,IAAI,CAAC,MAAM,CAAC,iBAAiB,GAAG,wBAAwB,CAAC,iBAAiB,CAAC,CAAC;IAE5E,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,IAAI,CAAC;KACb;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAwC,CAAC;AACjE,CAAC;AAED;;;;;GAKG;AACH,SAAS,wBAAwB,CAAC,OAAY;IAC5C,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAC5B,OAAO,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;KAChC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\ntype EIP712Domain = {\n verifyingContract: Hex;\n};\n\ntype SignTypedMessageDataV3V4 = {\n types: Record<string, unknown>;\n domain: EIP712Domain;\n primaryType: string;\n message: unknown;\n};\n\n/**\n * Normalizes the messageData for the eth_signTypedData\n *\n * @param messageData - The messageData to normalize.\n * @returns The normalized messageData.\n */\nexport function normalizeTypedMessage(messageData: string) {\n let data;\n try {\n data = parseTypedMessage(messageData);\n } catch {\n // Ignore normalization errors and pass the message as is\n return messageData;\n }\n\n const { verifyingContract } = data.domain ?? {};\n\n if (!verifyingContract) {\n return messageData;\n }\n\n data.domain.verifyingContract = normalizeContractAddress(verifyingContract);\n\n return JSON.stringify(data);\n}\n\n/**\n * Parses the messageData to obtain the data object for EIP712 normalization\n *\n * @param data - The messageData to parse.\n * @returns The data object for EIP712 normalization.\n */\nexport function parseTypedMessage(data: string) {\n if (typeof data !== 'string') {\n return data;\n }\n\n return JSON.parse(data) as unknown as SignTypedMessageDataV3V4;\n}\n\n/**\n * Normalizes the address to standard hexadecimal format\n *\n * @param address - The address to normalize.\n * @returns The normalized address.\n */\nfunction normalizeContractAddress(address: Hex): Hex {\n if (address.startsWith('0X')) {\n return `0x${address.slice(2)}`;\n }\n return address;\n}\n"]}