@metamask/snap-networks-utils 1.0.0 → 2.0.0

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 (360) hide show
  1. package/CHANGELOG.md +63 -1
  2. package/README.md +4 -10
  3. package/dist/index.cjs +102 -5
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +51 -2
  6. package/dist/index.d.cts.map +1 -1
  7. package/dist/index.d.mts +51 -2
  8. package/dist/index.d.mts.map +1 -1
  9. package/dist/index.mjs +32 -1
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/providers/assets/AssetsProvider.cjs +36 -18
  12. package/dist/providers/assets/AssetsProvider.cjs.map +1 -1
  13. package/dist/providers/assets/AssetsProvider.d.cts +30 -2
  14. package/dist/providers/assets/AssetsProvider.d.cts.map +1 -1
  15. package/dist/providers/assets/AssetsProvider.d.mts +30 -2
  16. package/dist/providers/assets/AssetsProvider.d.mts.map +1 -1
  17. package/dist/providers/assets/AssetsProvider.mjs +36 -18
  18. package/dist/providers/assets/AssetsProvider.mjs.map +1 -1
  19. package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.cjs +4 -17
  20. package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.cjs.map +1 -1
  21. package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.mjs +4 -17
  22. package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.mjs.map +1 -1
  23. package/dist/services/analytics/AnalyticsService.cjs +225 -0
  24. package/dist/services/analytics/AnalyticsService.cjs.map +1 -0
  25. package/dist/services/analytics/AnalyticsService.d.cts +175 -0
  26. package/dist/services/analytics/AnalyticsService.d.cts.map +1 -0
  27. package/dist/services/analytics/AnalyticsService.d.mts +175 -0
  28. package/dist/services/analytics/AnalyticsService.d.mts.map +1 -0
  29. package/dist/services/analytics/AnalyticsService.mjs +221 -0
  30. package/dist/services/analytics/AnalyticsService.mjs.map +1 -0
  31. package/dist/ui/ActionHeader/ActionHeader.cjs +23 -0
  32. package/dist/ui/ActionHeader/ActionHeader.cjs.map +1 -0
  33. package/dist/ui/ActionHeader/ActionHeader.d.cts +27 -0
  34. package/dist/ui/ActionHeader/ActionHeader.d.cts.map +1 -0
  35. package/dist/ui/ActionHeader/ActionHeader.d.mts +27 -0
  36. package/dist/ui/ActionHeader/ActionHeader.d.mts.map +1 -0
  37. package/dist/ui/ActionHeader/ActionHeader.mjs +19 -0
  38. package/dist/ui/ActionHeader/ActionHeader.mjs.map +1 -0
  39. package/dist/ui/Asset/Asset.cjs +68 -0
  40. package/dist/ui/Asset/Asset.cjs.map +1 -0
  41. package/dist/ui/Asset/Asset.d.cts +83 -0
  42. package/dist/ui/Asset/Asset.d.cts.map +1 -0
  43. package/dist/ui/Asset/Asset.d.mts +83 -0
  44. package/dist/ui/Asset/Asset.d.mts.map +1 -0
  45. package/dist/ui/Asset/Asset.mjs +60 -0
  46. package/dist/ui/Asset/Asset.mjs.map +1 -0
  47. package/dist/ui/Asset/question-mark.svg +3 -0
  48. package/dist/ui/EstimatedChanges/EstimatedChanges.cjs +57 -0
  49. package/dist/ui/EstimatedChanges/EstimatedChanges.cjs.map +1 -0
  50. package/dist/ui/EstimatedChanges/EstimatedChanges.d.cts +50 -0
  51. package/dist/ui/EstimatedChanges/EstimatedChanges.d.cts.map +1 -0
  52. package/dist/ui/EstimatedChanges/EstimatedChanges.d.mts +50 -0
  53. package/dist/ui/EstimatedChanges/EstimatedChanges.d.mts.map +1 -0
  54. package/dist/ui/EstimatedChanges/EstimatedChanges.mjs +53 -0
  55. package/dist/ui/EstimatedChanges/EstimatedChanges.mjs.map +1 -0
  56. package/dist/ui/TransactionAlert/TransactionAlert.cjs +72 -0
  57. package/dist/ui/TransactionAlert/TransactionAlert.cjs.map +1 -0
  58. package/dist/ui/TransactionAlert/TransactionAlert.d.cts +58 -0
  59. package/dist/ui/TransactionAlert/TransactionAlert.d.cts.map +1 -0
  60. package/dist/ui/TransactionAlert/TransactionAlert.d.mts +58 -0
  61. package/dist/ui/TransactionAlert/TransactionAlert.d.mts.map +1 -0
  62. package/dist/ui/TransactionAlert/TransactionAlert.mjs +68 -0
  63. package/dist/ui/TransactionAlert/TransactionAlert.mjs.map +1 -0
  64. package/dist/utils/async/async.cjs +95 -0
  65. package/dist/utils/async/async.cjs.map +1 -0
  66. package/dist/utils/async/async.d.cts +51 -0
  67. package/dist/utils/async/async.d.cts.map +1 -0
  68. package/dist/utils/async/async.d.mts +51 -0
  69. package/dist/utils/async/async.d.mts.map +1 -0
  70. package/dist/utils/async/async.mjs +88 -0
  71. package/dist/utils/async/async.mjs.map +1 -0
  72. package/dist/utils/buildUrl/buildUrl.cjs +54 -0
  73. package/dist/utils/buildUrl/buildUrl.cjs.map +1 -0
  74. package/dist/utils/buildUrl/buildUrl.d.cts +15 -0
  75. package/dist/utils/buildUrl/buildUrl.d.cts.map +1 -0
  76. package/dist/utils/buildUrl/buildUrl.d.mts +15 -0
  77. package/dist/utils/buildUrl/buildUrl.d.mts.map +1 -0
  78. package/dist/utils/buildUrl/buildUrl.mjs +51 -0
  79. package/dist/utils/buildUrl/buildUrl.mjs.map +1 -0
  80. package/dist/utils/cache/InMemoryCache.cjs +134 -0
  81. package/dist/utils/cache/InMemoryCache.cjs.map +1 -0
  82. package/dist/utils/cache/InMemoryCache.d.cts +29 -0
  83. package/dist/utils/cache/InMemoryCache.d.cts.map +1 -0
  84. package/dist/utils/cache/InMemoryCache.d.mts +29 -0
  85. package/dist/utils/cache/InMemoryCache.d.mts.map +1 -0
  86. package/dist/utils/cache/InMemoryCache.mjs +130 -0
  87. package/dist/utils/cache/InMemoryCache.mjs.map +1 -0
  88. package/dist/utils/cache/StateCache.cjs +193 -0
  89. package/dist/utils/cache/StateCache.cjs.map +1 -0
  90. package/dist/utils/cache/StateCache.d.cts +96 -0
  91. package/dist/utils/cache/StateCache.d.cts.map +1 -0
  92. package/dist/utils/cache/StateCache.d.mts +96 -0
  93. package/dist/utils/cache/StateCache.d.mts.map +1 -0
  94. package/dist/utils/cache/StateCache.mjs +189 -0
  95. package/dist/utils/cache/StateCache.mjs.map +1 -0
  96. package/dist/utils/cache/types.cjs +3 -0
  97. package/dist/utils/cache/types.cjs.map +1 -0
  98. package/dist/utils/cache/types.d.cts +99 -0
  99. package/dist/utils/cache/types.d.cts.map +1 -0
  100. package/dist/utils/cache/types.d.mts +99 -0
  101. package/dist/utils/cache/types.d.mts.map +1 -0
  102. package/dist/utils/cache/types.mjs +2 -0
  103. package/dist/utils/cache/types.mjs.map +1 -0
  104. package/dist/utils/cache/useCache.cjs +82 -0
  105. package/dist/utils/cache/useCache.cjs.map +1 -0
  106. package/dist/utils/cache/useCache.d.cts +57 -0
  107. package/dist/utils/cache/useCache.d.cts.map +1 -0
  108. package/dist/utils/cache/useCache.d.mts +57 -0
  109. package/dist/utils/cache/useCache.d.mts.map +1 -0
  110. package/dist/utils/cache/useCache.mjs +78 -0
  111. package/dist/utils/cache/useCache.mjs.map +1 -0
  112. package/dist/utils/cache/useCacheUntil.cjs +80 -0
  113. package/dist/utils/cache/useCacheUntil.cjs.map +1 -0
  114. package/dist/utils/cache/useCacheUntil.d.cts +54 -0
  115. package/dist/utils/cache/useCacheUntil.d.cts.map +1 -0
  116. package/dist/utils/cache/useCacheUntil.d.mts +54 -0
  117. package/dist/utils/cache/useCacheUntil.d.mts.map +1 -0
  118. package/dist/utils/cache/useCacheUntil.mjs +76 -0
  119. package/dist/utils/cache/useCacheUntil.mjs.map +1 -0
  120. package/dist/utils/config/BaseConfigProvider.cjs +62 -0
  121. package/dist/utils/config/BaseConfigProvider.cjs.map +1 -0
  122. package/dist/utils/config/BaseConfigProvider.d.cts +54 -0
  123. package/dist/utils/config/BaseConfigProvider.d.cts.map +1 -0
  124. package/dist/utils/config/BaseConfigProvider.d.mts +54 -0
  125. package/dist/utils/config/BaseConfigProvider.d.mts.map +1 -0
  126. package/dist/utils/config/BaseConfigProvider.mjs +58 -0
  127. package/dist/utils/config/BaseConfigProvider.mjs.map +1 -0
  128. package/dist/utils/config/envStructs.cjs +69 -0
  129. package/dist/utils/config/envStructs.cjs.map +1 -0
  130. package/dist/utils/config/envStructs.d.cts +57 -0
  131. package/dist/utils/config/envStructs.d.cts.map +1 -0
  132. package/dist/utils/config/envStructs.d.mts +57 -0
  133. package/dist/utils/config/envStructs.d.mts.map +1 -0
  134. package/dist/utils/config/envStructs.mjs +61 -0
  135. package/dist/utils/config/envStructs.mjs.map +1 -0
  136. package/dist/utils/config/environmentStruct.cjs +19 -0
  137. package/dist/utils/config/environmentStruct.cjs.map +1 -0
  138. package/dist/utils/config/environmentStruct.d.cts +20 -0
  139. package/dist/utils/config/environmentStruct.d.cts.map +1 -0
  140. package/dist/utils/config/environmentStruct.d.mts +20 -0
  141. package/dist/utils/config/environmentStruct.d.mts.map +1 -0
  142. package/dist/utils/config/environmentStruct.mjs +16 -0
  143. package/dist/utils/config/environmentStruct.mjs.map +1 -0
  144. package/dist/utils/config/logLevelStruct.cjs +14 -0
  145. package/dist/utils/config/logLevelStruct.cjs.map +1 -0
  146. package/dist/utils/config/logLevelStruct.d.cts +17 -0
  147. package/dist/utils/config/logLevelStruct.d.cts.map +1 -0
  148. package/dist/utils/config/logLevelStruct.d.mts +17 -0
  149. package/dist/utils/config/logLevelStruct.d.mts.map +1 -0
  150. package/dist/utils/config/logLevelStruct.mjs +11 -0
  151. package/dist/utils/config/logLevelStruct.mjs.map +1 -0
  152. package/dist/utils/config/parseEnv.cjs +30 -0
  153. package/dist/utils/config/parseEnv.cjs.map +1 -0
  154. package/dist/utils/config/parseEnv.d.cts +19 -0
  155. package/dist/utils/config/parseEnv.d.cts.map +1 -0
  156. package/dist/utils/config/parseEnv.d.mts +19 -0
  157. package/dist/utils/config/parseEnv.d.mts.map +1 -0
  158. package/dist/utils/config/parseEnv.mjs +26 -0
  159. package/dist/utils/config/parseEnv.mjs.map +1 -0
  160. package/dist/utils/dedupe/InFlightCoalescer.cjs +28 -0
  161. package/dist/utils/dedupe/InFlightCoalescer.cjs.map +1 -0
  162. package/dist/utils/dedupe/InFlightCoalescer.d.cts +12 -0
  163. package/dist/utils/dedupe/InFlightCoalescer.d.cts.map +1 -0
  164. package/dist/utils/dedupe/InFlightCoalescer.d.mts +12 -0
  165. package/dist/utils/dedupe/InFlightCoalescer.d.mts.map +1 -0
  166. package/dist/utils/dedupe/InFlightCoalescer.mjs +24 -0
  167. package/dist/utils/dedupe/InFlightCoalescer.mjs.map +1 -0
  168. package/dist/utils/errors/errors.cjs +44 -0
  169. package/dist/utils/errors/errors.cjs.map +1 -0
  170. package/dist/utils/errors/errors.d.cts +37 -0
  171. package/dist/utils/errors/errors.d.cts.map +1 -0
  172. package/dist/utils/errors/errors.d.mts +37 -0
  173. package/dist/utils/errors/errors.d.mts.map +1 -0
  174. package/dist/utils/errors/errors.mjs +40 -0
  175. package/dist/utils/errors/errors.mjs.map +1 -0
  176. package/dist/utils/errors/index.cjs +18 -0
  177. package/dist/utils/errors/index.cjs.map +1 -0
  178. package/dist/utils/errors/index.d.cts +10 -0
  179. package/dist/utils/errors/index.d.cts.map +1 -0
  180. package/dist/utils/errors/index.d.mts +10 -0
  181. package/dist/utils/errors/index.d.mts.map +1 -0
  182. package/dist/utils/errors/index.mjs +6 -0
  183. package/dist/utils/errors/index.mjs.map +1 -0
  184. package/dist/utils/errors/snapRpcError.cjs +33 -0
  185. package/dist/utils/errors/snapRpcError.cjs.map +1 -0
  186. package/dist/utils/errors/snapRpcError.d.cts +11 -0
  187. package/dist/utils/errors/snapRpcError.d.cts.map +1 -0
  188. package/dist/utils/errors/snapRpcError.d.mts +11 -0
  189. package/dist/utils/errors/snapRpcError.d.mts.map +1 -0
  190. package/dist/utils/errors/snapRpcError.mjs +30 -0
  191. package/dist/utils/errors/snapRpcError.mjs.map +1 -0
  192. package/dist/utils/errors/stringifyReason.cjs +36 -0
  193. package/dist/utils/errors/stringifyReason.cjs.map +1 -0
  194. package/dist/utils/errors/stringifyReason.d.cts +15 -0
  195. package/dist/utils/errors/stringifyReason.d.cts.map +1 -0
  196. package/dist/utils/errors/stringifyReason.d.mts +15 -0
  197. package/dist/utils/errors/stringifyReason.d.mts.map +1 -0
  198. package/dist/utils/errors/stringifyReason.mjs +33 -0
  199. package/dist/utils/errors/stringifyReason.mjs.map +1 -0
  200. package/dist/utils/errors/syncError.cjs +98 -0
  201. package/dist/utils/errors/syncError.cjs.map +1 -0
  202. package/dist/utils/errors/syncError.d.cts +60 -0
  203. package/dist/utils/errors/syncError.d.cts.map +1 -0
  204. package/dist/utils/errors/syncError.d.mts +60 -0
  205. package/dist/utils/errors/syncError.d.mts.map +1 -0
  206. package/dist/utils/errors/syncError.mjs +92 -0
  207. package/dist/utils/errors/syncError.mjs.map +1 -0
  208. package/dist/utils/errors/trackError.cjs +76 -0
  209. package/dist/utils/errors/trackError.cjs.map +1 -0
  210. package/dist/utils/errors/trackError.d.cts +64 -0
  211. package/dist/utils/errors/trackError.d.cts.map +1 -0
  212. package/dist/utils/errors/trackError.d.mts +64 -0
  213. package/dist/utils/errors/trackError.d.mts.map +1 -0
  214. package/dist/utils/errors/trackError.mjs +72 -0
  215. package/dist/utils/errors/trackError.mjs.map +1 -0
  216. package/dist/utils/handlers/wrapSnapHandlers.cjs +57 -0
  217. package/dist/utils/handlers/wrapSnapHandlers.cjs.map +1 -0
  218. package/dist/utils/handlers/wrapSnapHandlers.d.cts +74 -0
  219. package/dist/utils/handlers/wrapSnapHandlers.d.cts.map +1 -0
  220. package/dist/utils/handlers/wrapSnapHandlers.d.mts +74 -0
  221. package/dist/utils/handlers/wrapSnapHandlers.d.mts.map +1 -0
  222. package/dist/utils/handlers/wrapSnapHandlers.mjs +53 -0
  223. package/dist/utils/handlers/wrapSnapHandlers.mjs.map +1 -0
  224. package/dist/utils/keyringAccount/keyringAccount.cjs +25 -0
  225. package/dist/utils/keyringAccount/keyringAccount.cjs.map +1 -0
  226. package/dist/utils/keyringAccount/keyringAccount.d.cts +29 -0
  227. package/dist/utils/keyringAccount/keyringAccount.d.cts.map +1 -0
  228. package/dist/utils/keyringAccount/keyringAccount.d.mts +29 -0
  229. package/dist/utils/keyringAccount/keyringAccount.d.mts.map +1 -0
  230. package/dist/utils/keyringAccount/keyringAccount.mjs +22 -0
  231. package/dist/utils/keyringAccount/keyringAccount.mjs.map +1 -0
  232. package/dist/utils/logger/Logger.cjs +140 -0
  233. package/dist/utils/logger/Logger.cjs.map +1 -0
  234. package/dist/utils/logger/Logger.d.cts +118 -0
  235. package/dist/utils/logger/Logger.d.cts.map +1 -0
  236. package/dist/utils/logger/Logger.d.mts +118 -0
  237. package/dist/utils/logger/Logger.d.mts.map +1 -0
  238. package/dist/utils/logger/Logger.mjs +136 -0
  239. package/dist/utils/logger/Logger.mjs.map +1 -0
  240. package/dist/utils/logger/__mocks__/Logger.cjs +26 -0
  241. package/dist/utils/logger/__mocks__/Logger.cjs.map +1 -0
  242. package/dist/utils/logger/__mocks__/Logger.d.cts +3 -0
  243. package/dist/utils/logger/__mocks__/Logger.d.cts.map +1 -0
  244. package/dist/utils/logger/__mocks__/Logger.d.mts +3 -0
  245. package/dist/utils/logger/__mocks__/Logger.d.mts.map +1 -0
  246. package/dist/utils/logger/__mocks__/Logger.mjs +23 -0
  247. package/dist/utils/logger/__mocks__/Logger.mjs.map +1 -0
  248. package/dist/utils/originPermissions/createOriginPermissions.cjs +30 -0
  249. package/dist/utils/originPermissions/createOriginPermissions.cjs.map +1 -0
  250. package/dist/utils/originPermissions/createOriginPermissions.d.cts +24 -0
  251. package/dist/utils/originPermissions/createOriginPermissions.d.cts.map +1 -0
  252. package/dist/utils/originPermissions/createOriginPermissions.d.mts +24 -0
  253. package/dist/utils/originPermissions/createOriginPermissions.d.mts.map +1 -0
  254. package/dist/utils/originPermissions/createOriginPermissions.mjs +26 -0
  255. package/dist/utils/originPermissions/createOriginPermissions.mjs.map +1 -0
  256. package/dist/utils/originPermissions/validateOrigin.cjs +23 -0
  257. package/dist/utils/originPermissions/validateOrigin.cjs.map +1 -0
  258. package/dist/utils/originPermissions/validateOrigin.d.cts +10 -0
  259. package/dist/utils/originPermissions/validateOrigin.d.cts.map +1 -0
  260. package/dist/utils/originPermissions/validateOrigin.d.mts +10 -0
  261. package/dist/utils/originPermissions/validateOrigin.d.mts.map +1 -0
  262. package/dist/utils/originPermissions/validateOrigin.mjs +19 -0
  263. package/dist/utils/originPermissions/validateOrigin.mjs.map +1 -0
  264. package/dist/utils/proofOfOwnership/proofOfOwnership.cjs +89 -0
  265. package/dist/utils/proofOfOwnership/proofOfOwnership.cjs.map +1 -0
  266. package/dist/utils/proofOfOwnership/proofOfOwnership.d.cts +143 -0
  267. package/dist/utils/proofOfOwnership/proofOfOwnership.d.cts.map +1 -0
  268. package/dist/utils/proofOfOwnership/proofOfOwnership.d.mts +143 -0
  269. package/dist/utils/proofOfOwnership/proofOfOwnership.d.mts.map +1 -0
  270. package/dist/utils/proofOfOwnership/proofOfOwnership.mjs +85 -0
  271. package/dist/utils/proofOfOwnership/proofOfOwnership.mjs.map +1 -0
  272. package/dist/utils/safeMerge/safeMerge.cjs +26 -0
  273. package/dist/utils/safeMerge/safeMerge.cjs.map +1 -0
  274. package/dist/utils/safeMerge/safeMerge.d.cts +17 -0
  275. package/dist/utils/safeMerge/safeMerge.d.cts.map +1 -0
  276. package/dist/utils/safeMerge/safeMerge.d.mts +17 -0
  277. package/dist/utils/safeMerge/safeMerge.d.mts.map +1 -0
  278. package/dist/utils/safeMerge/safeMerge.mjs +22 -0
  279. package/dist/utils/safeMerge/safeMerge.mjs.map +1 -0
  280. package/dist/utils/sanitize/sanitize.cjs +42 -0
  281. package/dist/utils/sanitize/sanitize.cjs.map +1 -0
  282. package/dist/utils/sanitize/sanitize.d.cts +15 -0
  283. package/dist/utils/sanitize/sanitize.d.cts.map +1 -0
  284. package/dist/utils/sanitize/sanitize.d.mts +15 -0
  285. package/dist/utils/sanitize/sanitize.d.mts.map +1 -0
  286. package/dist/utils/sanitize/sanitize.mjs +38 -0
  287. package/dist/utils/sanitize/sanitize.mjs.map +1 -0
  288. package/dist/utils/serialization/serialization.cjs +73 -0
  289. package/dist/utils/serialization/serialization.cjs.map +1 -0
  290. package/dist/utils/serialization/serialization.d.cts +19 -0
  291. package/dist/utils/serialization/serialization.d.cts.map +1 -0
  292. package/dist/utils/serialization/serialization.d.mts +19 -0
  293. package/dist/utils/serialization/serialization.d.mts.map +1 -0
  294. package/dist/utils/serialization/serialization.mjs +69 -0
  295. package/dist/utils/serialization/serialization.mjs.map +1 -0
  296. package/dist/utils/serialization/types.cjs +3 -0
  297. package/dist/utils/serialization/types.cjs.map +1 -0
  298. package/dist/utils/serialization/types.d.cts +8 -0
  299. package/dist/utils/serialization/types.d.cts.map +1 -0
  300. package/dist/utils/serialization/types.d.mts +8 -0
  301. package/dist/utils/serialization/types.d.mts.map +1 -0
  302. package/dist/utils/serialization/types.mjs +2 -0
  303. package/dist/utils/serialization/types.mjs.map +1 -0
  304. package/dist/utils/state/IStateManager.cjs +3 -0
  305. package/dist/utils/state/IStateManager.cjs.map +1 -0
  306. package/dist/utils/state/IStateManager.d.cts +69 -0
  307. package/dist/utils/state/IStateManager.d.cts.map +1 -0
  308. package/dist/utils/state/IStateManager.d.mts +69 -0
  309. package/dist/utils/state/IStateManager.d.mts.map +1 -0
  310. package/dist/utils/state/IStateManager.mjs +2 -0
  311. package/dist/utils/state/IStateManager.mjs.map +1 -0
  312. package/dist/utils/state/InMemoryState.cjs +41 -0
  313. package/dist/utils/state/InMemoryState.cjs.map +1 -0
  314. package/dist/utils/state/InMemoryState.d.cts +18 -0
  315. package/dist/utils/state/InMemoryState.d.cts.map +1 -0
  316. package/dist/utils/state/InMemoryState.d.mts +18 -0
  317. package/dist/utils/state/InMemoryState.d.mts.map +1 -0
  318. package/dist/utils/state/InMemoryState.mjs +38 -0
  319. package/dist/utils/state/InMemoryState.mjs.map +1 -0
  320. package/dist/utils/state/State.cjs +159 -0
  321. package/dist/utils/state/State.cjs.map +1 -0
  322. package/dist/utils/state/State.d.cts +25 -0
  323. package/dist/utils/state/State.d.cts.map +1 -0
  324. package/dist/utils/state/State.d.mts +25 -0
  325. package/dist/utils/state/State.d.mts.map +1 -0
  326. package/dist/utils/state/State.mjs +156 -0
  327. package/dist/utils/state/State.mjs.map +1 -0
  328. package/dist/utils/transactionType/transactionType.cjs +32 -0
  329. package/dist/utils/transactionType/transactionType.cjs.map +1 -0
  330. package/dist/utils/transactionType/transactionType.d.cts +17 -0
  331. package/dist/utils/transactionType/transactionType.d.cts.map +1 -0
  332. package/dist/utils/transactionType/transactionType.d.mts +17 -0
  333. package/dist/utils/transactionType/transactionType.d.mts.map +1 -0
  334. package/dist/utils/transactionType/transactionType.mjs +28 -0
  335. package/dist/utils/transactionType/transactionType.mjs.map +1 -0
  336. package/dist/utils/urlStruct/urlStruct.cjs +96 -0
  337. package/dist/utils/urlStruct/urlStruct.cjs.map +1 -0
  338. package/dist/utils/urlStruct/urlStruct.d.cts +25 -0
  339. package/dist/utils/urlStruct/urlStruct.d.cts.map +1 -0
  340. package/dist/utils/urlStruct/urlStruct.d.mts +25 -0
  341. package/dist/utils/urlStruct/urlStruct.d.mts.map +1 -0
  342. package/dist/utils/urlStruct/urlStruct.mjs +93 -0
  343. package/dist/utils/urlStruct/urlStruct.mjs.map +1 -0
  344. package/dist/utils/uuidStruct/uuidStruct.cjs +12 -0
  345. package/dist/utils/uuidStruct/uuidStruct.cjs.map +1 -0
  346. package/dist/utils/uuidStruct/uuidStruct.d.cts +8 -0
  347. package/dist/utils/uuidStruct/uuidStruct.d.cts.map +1 -0
  348. package/dist/utils/uuidStruct/uuidStruct.d.mts +8 -0
  349. package/dist/utils/uuidStruct/uuidStruct.d.mts.map +1 -0
  350. package/dist/utils/uuidStruct/uuidStruct.mjs +9 -0
  351. package/dist/utils/uuidStruct/uuidStruct.mjs.map +1 -0
  352. package/package.json +33 -13
  353. package/dist/logger.cjs +0 -57
  354. package/dist/logger.cjs.map +0 -1
  355. package/dist/logger.d.cts +0 -30
  356. package/dist/logger.d.cts.map +0 -1
  357. package/dist/logger.d.mts +0 -30
  358. package/dist/logger.d.mts.map +0 -1
  359. package/dist/logger.mjs +0 -53
  360. package/dist/logger.mjs.map +0 -1
@@ -0,0 +1,175 @@
1
+ import type { TransactionType } from "@metamask/keyring-api";
2
+ import type { Json } from "@metamask/snaps-sdk";
3
+ import type { TrackErrorFn } from "../../utils/errors/index.cjs";
4
+ import type { Logger } from "../../utils/logger/Logger.cjs";
5
+ export declare const TransactionEventType: {
6
+ readonly TransactionAdded: "Transaction Added";
7
+ readonly TransactionRejected: "Transaction Rejected";
8
+ readonly TransactionApproved: "Transaction Approved";
9
+ readonly TransactionSubmitted: "Transaction Submitted";
10
+ readonly TransactionFinalized: "Transaction Finalized";
11
+ };
12
+ export type TransactionEventType = (typeof TransactionEventType)[keyof typeof TransactionEventType];
13
+ export declare const SecurityEventType: {
14
+ readonly SecurityAlertDetected: "Security Alert Detected";
15
+ readonly SecurityScanCompleted: "Security Scan Completed";
16
+ };
17
+ export type SecurityEventType = (typeof SecurityEventType)[keyof typeof SecurityEventType];
18
+ export type SnapTrackEventRequest = {
19
+ method: 'snap_trackEvent';
20
+ params: {
21
+ event: {
22
+ event: string;
23
+ properties: Record<string, Json>;
24
+ };
25
+ };
26
+ };
27
+ export type TrackEventCapableProvider = {
28
+ request: (args: SnapTrackEventRequest) => Promise<unknown>;
29
+ };
30
+ export type AnalyticsServiceOptions<TProvider extends TrackEventCapableProvider = TrackEventCapableProvider> = {
31
+ getSnapProvider: () => TProvider;
32
+ logger: Logger;
33
+ trackError: TrackErrorFn;
34
+ };
35
+ /**
36
+ * Fields shared by every event tied to an account on a chain.
37
+ */
38
+ export type AccountEventProperties = {
39
+ origin: string;
40
+ accountType: string;
41
+ chainIdCaip: string;
42
+ };
43
+ /**
44
+ * Properties of a transaction lifecycle event.
45
+ *
46
+ * `transactionType` is the optional classification of the transaction.
47
+ *
48
+ * Security events intentionally do not extend this type: they are not tied to a
49
+ * transaction classification, so advertising `transactionType` there would let
50
+ * callers pass a value that is silently discarded.
51
+ */
52
+ export type TransactionEventProperties = AccountEventProperties & {
53
+ transactionType?: `${TransactionType}`;
54
+ };
55
+ export type TransactionFinalizedEventProperties = TransactionEventProperties & {
56
+ transactionStatus?: string;
57
+ };
58
+ export type SecurityAlertDetectedEventProperties = AccountEventProperties & {
59
+ securityAlertResponse: string;
60
+ securityAlertReason: string | null;
61
+ securityAlertDescription: string;
62
+ };
63
+ export type SecurityScanCompletedEventProperties = AccountEventProperties & {
64
+ scanStatus: string;
65
+ hasSecurityAlerts: boolean;
66
+ };
67
+ export type WebSocketConnectionClosedEventProperties = {
68
+ origin: string;
69
+ code: number;
70
+ reason: string | null;
71
+ };
72
+ /**
73
+ * Tracks common network Snap analytics events.
74
+ */
75
+ export declare class AnalyticsService<TProvider extends TrackEventCapableProvider = TrackEventCapableProvider> {
76
+ #private;
77
+ constructor({ getSnapProvider, logger, trackError, }: AnalyticsServiceOptions<TProvider>);
78
+ /**
79
+ * Track an event in MetaMask analytics.
80
+ *
81
+ * Tracking and error-reporting failures are logged but never interrupt the
82
+ * user flow.
83
+ *
84
+ * @param event - Event name.
85
+ * @param properties - Event properties.
86
+ */
87
+ trackEvent(event: string, properties: Record<string, Json>): Promise<void>;
88
+ /**
89
+ * Track a "Transaction Added" event when a transaction confirmation is shown.
90
+ *
91
+ * @param properties - Event properties.
92
+ * @param properties.origin - The origin of the request.
93
+ * @param properties.accountType - The type of account.
94
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
95
+ * @param properties.transactionType - Optional transaction type.
96
+ */
97
+ trackTransactionAdded(properties: TransactionEventProperties): Promise<void>;
98
+ /**
99
+ * Track a "Transaction Rejected" event when the user rejects a transaction.
100
+ *
101
+ * @param properties - Event properties.
102
+ * @param properties.origin - The origin of the request.
103
+ * @param properties.accountType - The type of account.
104
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
105
+ * @param properties.transactionType - Optional transaction type.
106
+ */
107
+ trackTransactionRejected(properties: TransactionEventProperties): Promise<void>;
108
+ /**
109
+ * Track a "Transaction Approved" event when a transaction is approved.
110
+ *
111
+ * @param properties - Event properties.
112
+ * @param properties.origin - The origin of the request.
113
+ * @param properties.accountType - The type of account.
114
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
115
+ * @param properties.transactionType - Optional transaction type.
116
+ */
117
+ trackTransactionApproved(properties: TransactionEventProperties): Promise<void>;
118
+ /**
119
+ * Track a "Transaction Submitted" event when a transaction is broadcast.
120
+ *
121
+ * @param properties - Event properties.
122
+ * @param properties.origin - The origin of the request.
123
+ * @param properties.accountType - The type of account.
124
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
125
+ * @param properties.transactionType - Optional transaction type.
126
+ */
127
+ trackTransactionSubmitted(properties: TransactionEventProperties): Promise<void>;
128
+ /**
129
+ * Track a "Transaction Finalized" event when a transaction reaches a final state.
130
+ *
131
+ * @param properties - Event properties.
132
+ * @param properties.origin - The origin of the request.
133
+ * @param properties.accountType - The type of account.
134
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
135
+ * @param properties.transactionStatus - Optional final transaction status.
136
+ * @param properties.transactionType - Optional transaction type.
137
+ */
138
+ trackTransactionFinalized({ origin, accountType, chainIdCaip, transactionStatus, transactionType, }: TransactionFinalizedEventProperties): Promise<void>;
139
+ /**
140
+ * Track a "Security Alert Detected" event when a malicious or warning
141
+ * transaction is detected.
142
+ *
143
+ * @param properties - Event properties.
144
+ * @param properties.origin - The origin of the request.
145
+ * @param properties.accountType - The type of account.
146
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
147
+ * @param properties.securityAlertResponse - The type of security alert.
148
+ * @param properties.securityAlertReason - The reason for the security alert.
149
+ * @param properties.securityAlertDescription - Human-readable description of the alert.
150
+ */
151
+ trackSecurityAlertDetected({ origin, accountType, chainIdCaip, securityAlertResponse, securityAlertReason, securityAlertDescription, }: SecurityAlertDetectedEventProperties): Promise<void>;
152
+ /**
153
+ * Track a "Security Scan Completed" event when a transaction security scan
154
+ * finishes.
155
+ *
156
+ * @param properties - Event properties.
157
+ * @param properties.origin - The origin of the request.
158
+ * @param properties.accountType - The type of account.
159
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
160
+ * @param properties.scanStatus - The status of the scan.
161
+ * @param properties.hasSecurityAlerts - Whether security alerts were detected.
162
+ */
163
+ trackSecurityScanCompleted({ origin, accountType, chainIdCaip, scanStatus, hasSecurityAlerts, }: SecurityScanCompletedEventProperties): Promise<void>;
164
+ /**
165
+ * Track a "WebSocket Connection Closed Not Cleanly" event when a Snap
166
+ * WebSocket disconnects without a clean close.
167
+ *
168
+ * @param properties - Event properties.
169
+ * @param properties.origin - The origin of the connection.
170
+ * @param properties.code - The WebSocket close code.
171
+ * @param properties.reason - The close reason, if any.
172
+ */
173
+ trackWebSocketConnectionClosedNotCleanly({ origin, code, reason, }: WebSocketConnectionClosedEventProperties): Promise<void>;
174
+ }
175
+ //# sourceMappingURL=AnalyticsService.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnalyticsService.d.cts","sourceRoot":"","sources":["../../../src/services/analytics/AnalyticsService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,4BAA4B;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,qCAA2B;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,sCAAkC;AAExD,eAAO,MAAM,oBAAoB;;;;;;CAMvB,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAC9B,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,OAAO,oBAAoB,CAAC,CAAC;AAEnE,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE7D,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,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C,CAAC,EAC7C,MAAM,EACN,IAAI,EACJ,MAAM,GACP,EAAE,wCAAwC,GAAG,OAAO,CAAC,IAAI,CAAC;CA4C5D"}
@@ -0,0 +1,175 @@
1
+ import type { TransactionType } from "@metamask/keyring-api";
2
+ import type { Json } from "@metamask/snaps-sdk";
3
+ import type { TrackErrorFn } from "../../utils/errors/index.mjs";
4
+ import type { Logger } from "../../utils/logger/Logger.mjs";
5
+ export declare const TransactionEventType: {
6
+ readonly TransactionAdded: "Transaction Added";
7
+ readonly TransactionRejected: "Transaction Rejected";
8
+ readonly TransactionApproved: "Transaction Approved";
9
+ readonly TransactionSubmitted: "Transaction Submitted";
10
+ readonly TransactionFinalized: "Transaction Finalized";
11
+ };
12
+ export type TransactionEventType = (typeof TransactionEventType)[keyof typeof TransactionEventType];
13
+ export declare const SecurityEventType: {
14
+ readonly SecurityAlertDetected: "Security Alert Detected";
15
+ readonly SecurityScanCompleted: "Security Scan Completed";
16
+ };
17
+ export type SecurityEventType = (typeof SecurityEventType)[keyof typeof SecurityEventType];
18
+ export type SnapTrackEventRequest = {
19
+ method: 'snap_trackEvent';
20
+ params: {
21
+ event: {
22
+ event: string;
23
+ properties: Record<string, Json>;
24
+ };
25
+ };
26
+ };
27
+ export type TrackEventCapableProvider = {
28
+ request: (args: SnapTrackEventRequest) => Promise<unknown>;
29
+ };
30
+ export type AnalyticsServiceOptions<TProvider extends TrackEventCapableProvider = TrackEventCapableProvider> = {
31
+ getSnapProvider: () => TProvider;
32
+ logger: Logger;
33
+ trackError: TrackErrorFn;
34
+ };
35
+ /**
36
+ * Fields shared by every event tied to an account on a chain.
37
+ */
38
+ export type AccountEventProperties = {
39
+ origin: string;
40
+ accountType: string;
41
+ chainIdCaip: string;
42
+ };
43
+ /**
44
+ * Properties of a transaction lifecycle event.
45
+ *
46
+ * `transactionType` is the optional classification of the transaction.
47
+ *
48
+ * Security events intentionally do not extend this type: they are not tied to a
49
+ * transaction classification, so advertising `transactionType` there would let
50
+ * callers pass a value that is silently discarded.
51
+ */
52
+ export type TransactionEventProperties = AccountEventProperties & {
53
+ transactionType?: `${TransactionType}`;
54
+ };
55
+ export type TransactionFinalizedEventProperties = TransactionEventProperties & {
56
+ transactionStatus?: string;
57
+ };
58
+ export type SecurityAlertDetectedEventProperties = AccountEventProperties & {
59
+ securityAlertResponse: string;
60
+ securityAlertReason: string | null;
61
+ securityAlertDescription: string;
62
+ };
63
+ export type SecurityScanCompletedEventProperties = AccountEventProperties & {
64
+ scanStatus: string;
65
+ hasSecurityAlerts: boolean;
66
+ };
67
+ export type WebSocketConnectionClosedEventProperties = {
68
+ origin: string;
69
+ code: number;
70
+ reason: string | null;
71
+ };
72
+ /**
73
+ * Tracks common network Snap analytics events.
74
+ */
75
+ export declare class AnalyticsService<TProvider extends TrackEventCapableProvider = TrackEventCapableProvider> {
76
+ #private;
77
+ constructor({ getSnapProvider, logger, trackError, }: AnalyticsServiceOptions<TProvider>);
78
+ /**
79
+ * Track an event in MetaMask analytics.
80
+ *
81
+ * Tracking and error-reporting failures are logged but never interrupt the
82
+ * user flow.
83
+ *
84
+ * @param event - Event name.
85
+ * @param properties - Event properties.
86
+ */
87
+ trackEvent(event: string, properties: Record<string, Json>): Promise<void>;
88
+ /**
89
+ * Track a "Transaction Added" event when a transaction confirmation is shown.
90
+ *
91
+ * @param properties - Event properties.
92
+ * @param properties.origin - The origin of the request.
93
+ * @param properties.accountType - The type of account.
94
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
95
+ * @param properties.transactionType - Optional transaction type.
96
+ */
97
+ trackTransactionAdded(properties: TransactionEventProperties): Promise<void>;
98
+ /**
99
+ * Track a "Transaction Rejected" event when the user rejects a transaction.
100
+ *
101
+ * @param properties - Event properties.
102
+ * @param properties.origin - The origin of the request.
103
+ * @param properties.accountType - The type of account.
104
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
105
+ * @param properties.transactionType - Optional transaction type.
106
+ */
107
+ trackTransactionRejected(properties: TransactionEventProperties): Promise<void>;
108
+ /**
109
+ * Track a "Transaction Approved" event when a transaction is approved.
110
+ *
111
+ * @param properties - Event properties.
112
+ * @param properties.origin - The origin of the request.
113
+ * @param properties.accountType - The type of account.
114
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
115
+ * @param properties.transactionType - Optional transaction type.
116
+ */
117
+ trackTransactionApproved(properties: TransactionEventProperties): Promise<void>;
118
+ /**
119
+ * Track a "Transaction Submitted" event when a transaction is broadcast.
120
+ *
121
+ * @param properties - Event properties.
122
+ * @param properties.origin - The origin of the request.
123
+ * @param properties.accountType - The type of account.
124
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
125
+ * @param properties.transactionType - Optional transaction type.
126
+ */
127
+ trackTransactionSubmitted(properties: TransactionEventProperties): Promise<void>;
128
+ /**
129
+ * Track a "Transaction Finalized" event when a transaction reaches a final state.
130
+ *
131
+ * @param properties - Event properties.
132
+ * @param properties.origin - The origin of the request.
133
+ * @param properties.accountType - The type of account.
134
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
135
+ * @param properties.transactionStatus - Optional final transaction status.
136
+ * @param properties.transactionType - Optional transaction type.
137
+ */
138
+ trackTransactionFinalized({ origin, accountType, chainIdCaip, transactionStatus, transactionType, }: TransactionFinalizedEventProperties): Promise<void>;
139
+ /**
140
+ * Track a "Security Alert Detected" event when a malicious or warning
141
+ * transaction is detected.
142
+ *
143
+ * @param properties - Event properties.
144
+ * @param properties.origin - The origin of the request.
145
+ * @param properties.accountType - The type of account.
146
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
147
+ * @param properties.securityAlertResponse - The type of security alert.
148
+ * @param properties.securityAlertReason - The reason for the security alert.
149
+ * @param properties.securityAlertDescription - Human-readable description of the alert.
150
+ */
151
+ trackSecurityAlertDetected({ origin, accountType, chainIdCaip, securityAlertResponse, securityAlertReason, securityAlertDescription, }: SecurityAlertDetectedEventProperties): Promise<void>;
152
+ /**
153
+ * Track a "Security Scan Completed" event when a transaction security scan
154
+ * finishes.
155
+ *
156
+ * @param properties - Event properties.
157
+ * @param properties.origin - The origin of the request.
158
+ * @param properties.accountType - The type of account.
159
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
160
+ * @param properties.scanStatus - The status of the scan.
161
+ * @param properties.hasSecurityAlerts - Whether security alerts were detected.
162
+ */
163
+ trackSecurityScanCompleted({ origin, accountType, chainIdCaip, scanStatus, hasSecurityAlerts, }: SecurityScanCompletedEventProperties): Promise<void>;
164
+ /**
165
+ * Track a "WebSocket Connection Closed Not Cleanly" event when a Snap
166
+ * WebSocket disconnects without a clean close.
167
+ *
168
+ * @param properties - Event properties.
169
+ * @param properties.origin - The origin of the connection.
170
+ * @param properties.code - The WebSocket close code.
171
+ * @param properties.reason - The close reason, if any.
172
+ */
173
+ trackWebSocketConnectionClosedNotCleanly({ origin, code, reason, }: WebSocketConnectionClosedEventProperties): Promise<void>;
174
+ }
175
+ //# sourceMappingURL=AnalyticsService.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnalyticsService.d.mts","sourceRoot":"","sources":["../../../src/services/analytics/AnalyticsService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,4BAA4B;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,qCAA2B;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,sCAAkC;AAExD,eAAO,MAAM,oBAAoB;;;;;;CAMvB,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAC9B,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,OAAO,oBAAoB,CAAC,CAAC;AAEnE,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE7D,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,iBAAiB,CAAC;IAC1B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,EACN,IAAI,EACJ,MAAM,GACP,EAAE,wCAAwC,GAAG,OAAO,CAAC,IAAI,CAAC;CA4C5D"}
@@ -0,0 +1,221 @@
1
+ export const TransactionEventType = {
2
+ TransactionAdded: 'Transaction Added',
3
+ TransactionRejected: 'Transaction Rejected',
4
+ TransactionApproved: 'Transaction Approved',
5
+ TransactionSubmitted: 'Transaction Submitted',
6
+ TransactionFinalized: 'Transaction Finalized',
7
+ };
8
+ export const SecurityEventType = {
9
+ SecurityAlertDetected: 'Security Alert Detected',
10
+ SecurityScanCompleted: 'Security Scan Completed',
11
+ };
12
+ /**
13
+ * Tracks common network Snap analytics events.
14
+ */
15
+ export class AnalyticsService {
16
+ #getSnapProvider;
17
+ #logger;
18
+ #trackError;
19
+ constructor({ getSnapProvider, logger, trackError, }) {
20
+ this.#getSnapProvider = getSnapProvider;
21
+ this.#logger = logger.withPrefix('[AnalyticsService]');
22
+ this.#trackError = trackError;
23
+ }
24
+ /**
25
+ * Track an event in MetaMask analytics.
26
+ *
27
+ * Tracking and error-reporting failures are logged but never interrupt the
28
+ * user flow.
29
+ *
30
+ * @param event - Event name.
31
+ * @param properties - Event properties.
32
+ */
33
+ async trackEvent(event, properties) {
34
+ try {
35
+ await this.#getSnapProvider().request({
36
+ method: 'snap_trackEvent',
37
+ params: {
38
+ event: {
39
+ event,
40
+ properties,
41
+ },
42
+ },
43
+ });
44
+ }
45
+ catch (error) {
46
+ try {
47
+ await this.#trackError(error);
48
+ }
49
+ catch (trackingError) {
50
+ this.#logger.warn('Failed to report analytics error', {
51
+ error: trackingError,
52
+ });
53
+ }
54
+ this.#logger.warn('Failed to track event', {
55
+ error,
56
+ event,
57
+ properties,
58
+ });
59
+ }
60
+ }
61
+ /**
62
+ * Track a "Transaction Added" event when a transaction confirmation is shown.
63
+ *
64
+ * @param properties - Event properties.
65
+ * @param properties.origin - The origin of the request.
66
+ * @param properties.accountType - The type of account.
67
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
68
+ * @param properties.transactionType - Optional transaction type.
69
+ */
70
+ async trackTransactionAdded(properties) {
71
+ await this.#trackTransactionEvent(TransactionEventType.TransactionAdded, 'Snap transaction added', properties);
72
+ }
73
+ /**
74
+ * Track a "Transaction Rejected" event when the user rejects a transaction.
75
+ *
76
+ * @param properties - Event properties.
77
+ * @param properties.origin - The origin of the request.
78
+ * @param properties.accountType - The type of account.
79
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
80
+ * @param properties.transactionType - Optional transaction type.
81
+ */
82
+ async trackTransactionRejected(properties) {
83
+ await this.#trackTransactionEvent(TransactionEventType.TransactionRejected, 'Snap transaction rejected', properties);
84
+ }
85
+ /**
86
+ * Track a "Transaction Approved" event when a transaction is approved.
87
+ *
88
+ * @param properties - Event properties.
89
+ * @param properties.origin - The origin of the request.
90
+ * @param properties.accountType - The type of account.
91
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
92
+ * @param properties.transactionType - Optional transaction type.
93
+ */
94
+ async trackTransactionApproved(properties) {
95
+ await this.#trackTransactionEvent(TransactionEventType.TransactionApproved, 'Snap transaction approved', properties);
96
+ }
97
+ /**
98
+ * Track a "Transaction Submitted" event when a transaction is broadcast.
99
+ *
100
+ * @param properties - Event properties.
101
+ * @param properties.origin - The origin of the request.
102
+ * @param properties.accountType - The type of account.
103
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
104
+ * @param properties.transactionType - Optional transaction type.
105
+ */
106
+ async trackTransactionSubmitted(properties) {
107
+ await this.#trackTransactionEvent(TransactionEventType.TransactionSubmitted, 'Snap transaction submitted', properties);
108
+ }
109
+ /**
110
+ * Track a "Transaction Finalized" event when a transaction reaches a final state.
111
+ *
112
+ * @param properties - Event properties.
113
+ * @param properties.origin - The origin of the request.
114
+ * @param properties.accountType - The type of account.
115
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
116
+ * @param properties.transactionStatus - Optional final transaction status.
117
+ * @param properties.transactionType - Optional transaction type.
118
+ */
119
+ async trackTransactionFinalized({ origin, accountType, chainIdCaip, transactionStatus, transactionType, }) {
120
+ await this.trackEvent(TransactionEventType.TransactionFinalized, {
121
+ message: 'Snap transaction finalized',
122
+ origin,
123
+ account_type: accountType,
124
+ chain_id_caip: chainIdCaip,
125
+ ...(transactionStatus === undefined
126
+ ? {}
127
+ : { transaction_status: transactionStatus }),
128
+ ...(transactionType === undefined
129
+ ? {}
130
+ : { transaction_type: transactionType }),
131
+ });
132
+ }
133
+ /**
134
+ * Track a "Security Alert Detected" event when a malicious or warning
135
+ * transaction is detected.
136
+ *
137
+ * @param properties - Event properties.
138
+ * @param properties.origin - The origin of the request.
139
+ * @param properties.accountType - The type of account.
140
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
141
+ * @param properties.securityAlertResponse - The type of security alert.
142
+ * @param properties.securityAlertReason - The reason for the security alert.
143
+ * @param properties.securityAlertDescription - Human-readable description of the alert.
144
+ */
145
+ async trackSecurityAlertDetected({ origin, accountType, chainIdCaip, securityAlertResponse, securityAlertReason, securityAlertDescription, }) {
146
+ await this.trackEvent(SecurityEventType.SecurityAlertDetected, {
147
+ message: 'Snap security alert detected',
148
+ origin,
149
+ account_type: accountType,
150
+ chain_id_caip: chainIdCaip,
151
+ security_alert_response: securityAlertResponse,
152
+ security_alert_reason: securityAlertReason,
153
+ security_alert_description: securityAlertDescription,
154
+ });
155
+ }
156
+ /**
157
+ * Track a "Security Scan Completed" event when a transaction security scan
158
+ * finishes.
159
+ *
160
+ * @param properties - Event properties.
161
+ * @param properties.origin - The origin of the request.
162
+ * @param properties.accountType - The type of account.
163
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
164
+ * @param properties.scanStatus - The status of the scan.
165
+ * @param properties.hasSecurityAlerts - Whether security alerts were detected.
166
+ */
167
+ async trackSecurityScanCompleted({ origin, accountType, chainIdCaip, scanStatus, hasSecurityAlerts, }) {
168
+ await this.trackEvent(SecurityEventType.SecurityScanCompleted, {
169
+ message: 'Snap security scan completed',
170
+ origin,
171
+ account_type: accountType,
172
+ chain_id_caip: chainIdCaip,
173
+ scan_status: scanStatus,
174
+ has_security_alerts: hasSecurityAlerts,
175
+ });
176
+ }
177
+ /**
178
+ * Track a "WebSocket Connection Closed Not Cleanly" event when a Snap
179
+ * WebSocket disconnects without a clean close.
180
+ *
181
+ * @param properties - Event properties.
182
+ * @param properties.origin - The origin of the connection.
183
+ * @param properties.code - The WebSocket close code.
184
+ * @param properties.reason - The close reason, if any.
185
+ */
186
+ async trackWebSocketConnectionClosedNotCleanly({ origin, code, reason, }) {
187
+ await this.trackEvent('WebSocket Connection Closed Not Cleanly', {
188
+ message: 'Snap WebSocket connection closed not cleanly',
189
+ origin,
190
+ code,
191
+ reason,
192
+ });
193
+ }
194
+ /**
195
+ * Track a transaction lifecycle event.
196
+ *
197
+ * Centralizes the shared payload so the common properties only have to change
198
+ * in one place. `transaction_type` is added only when the emitting Snap could
199
+ * classify the transaction.
200
+ *
201
+ * @param event - Event name.
202
+ * @param message - Human-readable event message.
203
+ * @param properties - Event properties.
204
+ * @param properties.origin - The origin of the request.
205
+ * @param properties.accountType - The type of account.
206
+ * @param properties.chainIdCaip - The CAIP-2 chain ID.
207
+ * @param properties.transactionType - Optional transaction type.
208
+ */
209
+ async #trackTransactionEvent(event, message, { origin, accountType, chainIdCaip, transactionType, }) {
210
+ await this.trackEvent(event, {
211
+ message,
212
+ origin,
213
+ account_type: accountType,
214
+ chain_id_caip: chainIdCaip,
215
+ ...(transactionType === undefined
216
+ ? {}
217
+ : { transaction_type: transactionType }),
218
+ });
219
+ }
220
+ }
221
+ //# sourceMappingURL=AnalyticsService.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnalyticsService.mjs","sourceRoot":"","sources":["../../../src/services/analytics/AnalyticsService.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,gBAAgB,EAAE,mBAAmB;IACrC,mBAAmB,EAAE,sBAAsB;IAC3C,mBAAmB,EAAE,sBAAsB;IAC3C,oBA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gBACJ,CAAC,CAAC,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC;SAC3C,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { TransactionType } from '@metamask/keyring-api';\nimport type { Json } from '@metamask/snaps-sdk';\n\nimport type { TrackErrorFn } from '../../utils/errors';\nimport type { Logger } from '../../utils/logger/Logger';\n\nexport const TransactionEventType = {\n TransactionAdded: 'Transaction Added',\n TransactionRejected: 'Transaction Rejected',\n TransactionApproved: 'Transaction Approved',\n TransactionSubmitted: 'Transaction Submitted',\n TransactionFinalized: 'Transaction Finalized',\n} as const;\n\nexport type TransactionEventType =\n (typeof TransactionEventType)[keyof typeof TransactionEventType];\n\nexport const SecurityEventType = {\n SecurityAlertDetected: 'Security Alert Detected',\n SecurityScanCompleted: 'Security Scan Completed',\n} as const;\n\nexport type SecurityEventType =\n (typeof SecurityEventType)[keyof typeof SecurityEventType];\n\nexport type SnapTrackEventRequest = {\n method: 'snap_trackEvent';\n params: {\n event: {\n event: string;\n properties: Record<string, Json>;\n };\n };\n};\n\nexport type TrackEventCapableProvider = {\n request: (args: SnapTrackEventRequest) => Promise<unknown>;\n};\n\nexport type AnalyticsServiceOptions<\n TProvider extends TrackEventCapableProvider = TrackEventCapableProvider,\n> = {\n getSnapProvider: () => TProvider;\n logger: Logger;\n trackError: TrackErrorFn;\n};\n\n/**\n * Fields shared by every event tied to an account on a chain.\n */\nexport type AccountEventProperties = {\n origin: string;\n accountType: string;\n chainIdCaip: string;\n};\n\n/**\n * Properties of a transaction lifecycle event.\n *\n * `transactionType` is the optional classification of the transaction.\n *\n * Security events intentionally do not extend this type: they are not tied to a\n * transaction classification, so advertising `transactionType` there would let\n * callers pass a value that is silently discarded.\n */\nexport type TransactionEventProperties = AccountEventProperties & {\n transactionType?: `${TransactionType}`;\n};\n\nexport type TransactionFinalizedEventProperties = TransactionEventProperties & {\n transactionStatus?: string;\n};\n\nexport type SecurityAlertDetectedEventProperties = AccountEventProperties & {\n securityAlertResponse: string;\n securityAlertReason: string | null;\n securityAlertDescription: string;\n};\n\nexport type SecurityScanCompletedEventProperties = AccountEventProperties & {\n scanStatus: string;\n hasSecurityAlerts: boolean;\n};\n\nexport type WebSocketConnectionClosedEventProperties = {\n origin: string;\n code: number;\n reason: string | null;\n};\n\n/**\n * Tracks common network Snap analytics events.\n */\nexport class AnalyticsService<\n TProvider extends TrackEventCapableProvider = TrackEventCapableProvider,\n> {\n readonly #getSnapProvider: () => TProvider;\n\n readonly #logger: Logger;\n\n readonly #trackError: TrackErrorFn;\n\n constructor({\n getSnapProvider,\n logger,\n trackError,\n }: AnalyticsServiceOptions<TProvider>) {\n this.#getSnapProvider = getSnapProvider;\n this.#logger = logger.withPrefix('[AnalyticsService]');\n this.#trackError = trackError;\n }\n\n /**\n * Track an event in MetaMask analytics.\n *\n * Tracking and error-reporting failures are logged but never interrupt the\n * user flow.\n *\n * @param event - Event name.\n * @param properties - Event properties.\n */\n async trackEvent(\n event: string,\n properties: Record<string, Json>,\n ): Promise<void> {\n try {\n await this.#getSnapProvider().request({\n method: 'snap_trackEvent',\n params: {\n event: {\n event,\n properties,\n },\n },\n });\n } catch (error) {\n try {\n await this.#trackError(error);\n } catch (trackingError) {\n this.#logger.warn('Failed to report analytics error', {\n error: trackingError,\n });\n }\n\n this.#logger.warn('Failed to track event', {\n error,\n event,\n properties,\n });\n }\n }\n\n /**\n * Track a \"Transaction Added\" event when a transaction confirmation is shown.\n *\n * @param properties - Event properties.\n * @param properties.origin - The origin of the request.\n * @param properties.accountType - The type of account.\n * @param properties.chainIdCaip - The CAIP-2 chain ID.\n * @param properties.transactionType - Optional transaction type.\n */\n async trackTransactionAdded(\n properties: TransactionEventProperties,\n ): Promise<void> {\n await this.#trackTransactionEvent(\n TransactionEventType.TransactionAdded,\n 'Snap transaction added',\n properties,\n );\n }\n\n /**\n * Track a \"Transaction Rejected\" event when the user rejects a transaction.\n *\n * @param properties - Event properties.\n * @param properties.origin - The origin of the request.\n * @param properties.accountType - The type of account.\n * @param properties.chainIdCaip - The CAIP-2 chain ID.\n * @param properties.transactionType - Optional transaction type.\n */\n async trackTransactionRejected(\n properties: TransactionEventProperties,\n ): Promise<void> {\n await this.#trackTransactionEvent(\n TransactionEventType.TransactionRejected,\n 'Snap transaction rejected',\n properties,\n );\n }\n\n /**\n * Track a \"Transaction Approved\" event when a transaction is approved.\n *\n * @param properties - Event properties.\n * @param properties.origin - The origin of the request.\n * @param properties.accountType - The type of account.\n * @param properties.chainIdCaip - The CAIP-2 chain ID.\n * @param properties.transactionType - Optional transaction type.\n */\n async trackTransactionApproved(\n properties: TransactionEventProperties,\n ): Promise<void> {\n await this.#trackTransactionEvent(\n TransactionEventType.TransactionApproved,\n 'Snap transaction approved',\n properties,\n );\n }\n\n /**\n * Track a \"Transaction Submitted\" event when a transaction is broadcast.\n *\n * @param properties - Event properties.\n * @param properties.origin - The origin of the request.\n * @param properties.accountType - The type of account.\n * @param properties.chainIdCaip - The CAIP-2 chain ID.\n * @param properties.transactionType - Optional transaction type.\n */\n async trackTransactionSubmitted(\n properties: TransactionEventProperties,\n ): Promise<void> {\n await this.#trackTransactionEvent(\n TransactionEventType.TransactionSubmitted,\n 'Snap transaction submitted',\n properties,\n );\n }\n\n /**\n * Track a \"Transaction Finalized\" event when a transaction reaches a final state.\n *\n * @param properties - Event properties.\n * @param properties.origin - The origin of the request.\n * @param properties.accountType - The type of account.\n * @param properties.chainIdCaip - The CAIP-2 chain ID.\n * @param properties.transactionStatus - Optional final transaction status.\n * @param properties.transactionType - Optional transaction type.\n */\n async trackTransactionFinalized({\n origin,\n accountType,\n chainIdCaip,\n transactionStatus,\n transactionType,\n }: TransactionFinalizedEventProperties): Promise<void> {\n await this.trackEvent(TransactionEventType.TransactionFinalized, {\n message: 'Snap transaction finalized',\n origin,\n account_type: accountType,\n chain_id_caip: chainIdCaip,\n ...(transactionStatus === undefined\n ? {}\n : { transaction_status: transactionStatus }),\n ...(transactionType === undefined\n ? {}\n : { transaction_type: transactionType }),\n });\n }\n\n /**\n * Track a \"Security Alert Detected\" event when a malicious or warning\n * transaction is detected.\n *\n * @param properties - Event properties.\n * @param properties.origin - The origin of the request.\n * @param properties.accountType - The type of account.\n * @param properties.chainIdCaip - The CAIP-2 chain ID.\n * @param properties.securityAlertResponse - The type of security alert.\n * @param properties.securityAlertReason - The reason for the security alert.\n * @param properties.securityAlertDescription - Human-readable description of the alert.\n */\n async trackSecurityAlertDetected({\n origin,\n accountType,\n chainIdCaip,\n securityAlertResponse,\n securityAlertReason,\n securityAlertDescription,\n }: SecurityAlertDetectedEventProperties): Promise<void> {\n await this.trackEvent(SecurityEventType.SecurityAlertDetected, {\n message: 'Snap security alert detected',\n origin,\n account_type: accountType,\n chain_id_caip: chainIdCaip,\n security_alert_response: securityAlertResponse,\n security_alert_reason: securityAlertReason,\n security_alert_description: securityAlertDescription,\n });\n }\n\n /**\n * Track a \"Security Scan Completed\" event when a transaction security scan\n * finishes.\n *\n * @param properties - Event properties.\n * @param properties.origin - The origin of the request.\n * @param properties.accountType - The type of account.\n * @param properties.chainIdCaip - The CAIP-2 chain ID.\n * @param properties.scanStatus - The status of the scan.\n * @param properties.hasSecurityAlerts - Whether security alerts were detected.\n */\n async trackSecurityScanCompleted({\n origin,\n accountType,\n chainIdCaip,\n scanStatus,\n hasSecurityAlerts,\n }: SecurityScanCompletedEventProperties): Promise<void> {\n await this.trackEvent(SecurityEventType.SecurityScanCompleted, {\n message: 'Snap security scan completed',\n origin,\n account_type: accountType,\n chain_id_caip: chainIdCaip,\n scan_status: scanStatus,\n has_security_alerts: hasSecurityAlerts,\n });\n }\n\n /**\n * Track a \"WebSocket Connection Closed Not Cleanly\" event when a Snap\n * WebSocket disconnects without a clean close.\n *\n * @param properties - Event properties.\n * @param properties.origin - The origin of the connection.\n * @param properties.code - The WebSocket close code.\n * @param properties.reason - The close reason, if any.\n */\n async trackWebSocketConnectionClosedNotCleanly({\n origin,\n code,\n reason,\n }: WebSocketConnectionClosedEventProperties): Promise<void> {\n await this.trackEvent('WebSocket Connection Closed Not Cleanly', {\n message: 'Snap WebSocket connection closed not cleanly',\n origin,\n code,\n reason,\n });\n }\n\n /**\n * Track a transaction lifecycle event.\n *\n * Centralizes the shared payload so the common properties only have to change\n * in one place. `transaction_type` is added only when the emitting Snap could\n * classify the transaction.\n *\n * @param event - Event name.\n * @param message - Human-readable event message.\n * @param properties - Event properties.\n * @param properties.origin - The origin of the request.\n * @param properties.accountType - The type of account.\n * @param properties.chainIdCaip - The CAIP-2 chain ID.\n * @param properties.transactionType - Optional transaction type.\n */\n async #trackTransactionEvent(\n event: TransactionEventType,\n message: string,\n {\n origin,\n accountType,\n chainIdCaip,\n transactionType,\n }: TransactionEventProperties,\n ): Promise<void> {\n await this.trackEvent(event, {\n message,\n origin,\n account_type: accountType,\n chain_id_caip: chainIdCaip,\n ...(transactionType === undefined\n ? {}\n : { transaction_type: transactionType }),\n });\n }\n}\n"]}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ActionHeader = void 0;
4
+ const jsx_runtime_1 = require("@metamask/snaps-sdk/jsx-runtime");
5
+ const jsx_1 = require("@metamask/snaps-sdk/jsx");
6
+ const Asset_1 = require("../Asset/Asset.cjs");
7
+ /**
8
+ * Renders the centered header at the top of a confirmation: a large title,
9
+ * then an optional subtitle and asset icon.
10
+ *
11
+ * @param props - The component props.
12
+ * @param props.title - The title.
13
+ * @param props.subtitle - The subtitle.
14
+ * @param props.iconUrl - The asset icon URL.
15
+ * @returns The header element.
16
+ * @example
17
+ * ```tsx
18
+ * <ActionHeader title={translate('confirmation.signMessage.title')} />;
19
+ * ```
20
+ */
21
+ const ActionHeader = ({ title, subtitle, iconUrl, }) => ((0, jsx_runtime_1.jsxs)(jsx_1.Box, { alignment: "center", center: true, children: [(0, jsx_runtime_1.jsx)(jsx_1.Box, { children: null }), (0, jsx_runtime_1.jsx)(jsx_1.Heading, { size: "lg", children: title }), subtitle ? ((0, jsx_runtime_1.jsx)(jsx_1.Text, { color: "muted", alignment: "center", children: subtitle })) : null, iconUrl === undefined ? null : ((0, jsx_runtime_1.jsx)(jsx_1.Box, { children: (0, jsx_runtime_1.jsx)(Asset_1.AssetIcon, { iconUrl: iconUrl, size: "xl" }) })), (0, jsx_runtime_1.jsx)(jsx_1.Box, { children: null })] }));
22
+ exports.ActionHeader = ActionHeader;
23
+ //# sourceMappingURL=ActionHeader.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ActionHeader.cjs","sourceRoot":"","sources":["../../../src/ui/ActionHeader/ActionHeader.tsx"],"names":[],"mappings":";;;;AACA,iDAAyE;AAEzE,8CAA2C;AAa3C;;;;;;;;;;;;;GAaG;AACI,MAAM,YAAY,GAAG,CAAC,EAC3B,KAAK,EACL,QAAQ,EACR,OAAO,GACW,EAAsB,EAAE,CAAC,CAC3C,wBAAC,SAAG,IAAC,SAAS,EAAC,QAAQ,EAAC,MAAM,mBAC5B,uBAAC,SAAG,cAAE,IAAI,GAAO,EACjB,uBAAC,aAAO,IAAC,IAAI,EAAC,IAAI,YAAE,KAAK,GAAW,EACnC,QAAQ,CAAC,CAAC,CAAC,CACV,uBAAC,UAAQ,IAAC,KAAK,EAAC,OAAO,EAAC,SAAS,EAAC,QAAQ,YACvC,QAAQ,GACA,CACZ,CAAC,CAAC,CAAC,IAAI,EACP,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAC9B,uBAAC,SAAG,cACF,uBAAC,iBAAS,IAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,IAAI,GAAG,GACrC,CACP,EACD,uBAAC,SAAG,cAAE,IAAI,GAAO,IACb,CACP,CAAC;AApBW,QAAA,YAAY,gBAoBvB","sourcesContent":["import type { ComponentOrElement } from '@metamask/snaps-sdk';\nimport { Box, Heading, Text as SnapText } from '@metamask/snaps-sdk/jsx';\n\nimport { AssetIcon } from '../Asset/Asset';\n\nexport type ActionHeaderProps = {\n title: string;\n /** Muted text shown below the title. */\n subtitle?: string;\n /**\n * Asset icon URL; when set, an extra-large asset icon is shown below the\n * title. A blank URL shows the question-mark icon.\n */\n iconUrl?: string;\n};\n\n/**\n * Renders the centered header at the top of a confirmation: a large title,\n * then an optional subtitle and asset icon.\n *\n * @param props - The component props.\n * @param props.title - The title.\n * @param props.subtitle - The subtitle.\n * @param props.iconUrl - The asset icon URL.\n * @returns The header element.\n * @example\n * ```tsx\n * <ActionHeader title={translate('confirmation.signMessage.title')} />;\n * ```\n */\nexport const ActionHeader = ({\n title,\n subtitle,\n iconUrl,\n}: ActionHeaderProps): ComponentOrElement => (\n <Box alignment=\"center\" center>\n <Box>{null}</Box>\n <Heading size=\"lg\">{title}</Heading>\n {subtitle ? (\n <SnapText color=\"muted\" alignment=\"center\">\n {subtitle}\n </SnapText>\n ) : null}\n {iconUrl === undefined ? null : (\n <Box>\n <AssetIcon iconUrl={iconUrl} size=\"xl\" />\n </Box>\n )}\n <Box>{null}</Box>\n </Box>\n);\n"]}