@metamask/snaps-controllers 0.38.0-flask.1 → 1.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 (317) hide show
  1. package/CHANGELOG.md +568 -11
  2. package/dist/{types/cronjob → cronjob}/CronjobController.d.ts +6 -7
  3. package/dist/cronjob/CronjobController.js +248 -0
  4. package/dist/cronjob/CronjobController.js.map +1 -0
  5. package/dist/cronjob/index.js +18 -0
  6. package/dist/cronjob/index.js.map +1 -0
  7. package/dist/{types/fsm.d.ts → fsm.d.ts} +1 -1
  8. package/dist/fsm.js +75 -0
  9. package/dist/fsm.js.map +1 -0
  10. package/dist/{types/index.d.ts → index.d.ts} +1 -0
  11. package/dist/index.js +22 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/logging.js +13 -0
  14. package/dist/logging.js.map +1 -0
  15. package/dist/multichain/MultiChainController.d.ts +137 -0
  16. package/dist/multichain/MultiChainController.js +339 -0
  17. package/dist/multichain/MultiChainController.js.map +1 -0
  18. package/dist/multichain/index.d.ts +3 -0
  19. package/dist/multichain/index.js +20 -0
  20. package/dist/multichain/index.js.map +1 -0
  21. package/dist/multichain/matching.d.ts +9 -0
  22. package/dist/multichain/matching.js +57 -0
  23. package/dist/multichain/matching.js.map +1 -0
  24. package/dist/multichain/middleware.d.ts +14 -0
  25. package/dist/multichain/middleware.js +42 -0
  26. package/dist/multichain/middleware.js.map +1 -0
  27. package/dist/{types/services → services}/AbstractExecutionService.d.ts +4 -4
  28. package/dist/services/AbstractExecutionService.js +318 -0
  29. package/dist/services/AbstractExecutionService.js.map +1 -0
  30. package/dist/{types/services → services}/ExecutionService.d.ts +3 -3
  31. package/dist/services/ExecutionService.js +4 -0
  32. package/dist/services/ExecutionService.js.map +1 -0
  33. package/dist/{types/services → services}/browser.d.ts +0 -2
  34. package/dist/services/browser.js +22 -0
  35. package/dist/services/browser.js.map +1 -0
  36. package/dist/{types/services → services}/iframe/IframeExecutionService.d.ts +2 -3
  37. package/dist/services/iframe/IframeExecutionService.js +30 -0
  38. package/dist/services/iframe/IframeExecutionService.js.map +1 -0
  39. package/dist/services/iframe/index.js +18 -0
  40. package/dist/services/iframe/index.js.map +1 -0
  41. package/dist/{types/services → services}/index.d.ts +0 -2
  42. package/dist/services/index.js +22 -0
  43. package/dist/services/index.js.map +1 -0
  44. package/dist/{types/services → services}/node/NodeProcessExecutionService.d.ts +3 -4
  45. package/dist/services/node/NodeProcessExecutionService.js +18 -0
  46. package/dist/services/node/NodeProcessExecutionService.js.map +1 -0
  47. package/dist/{types/services → services}/node/NodeThreadExecutionService.d.ts +2 -3
  48. package/dist/services/node/NodeThreadExecutionService.js +19 -0
  49. package/dist/services/node/NodeThreadExecutionService.js.map +1 -0
  50. package/dist/services/node/index.js +19 -0
  51. package/dist/services/node/index.js.map +1 -0
  52. package/dist/{types/services → services}/offscreen/OffscreenExecutionService.d.ts +3 -4
  53. package/dist/services/offscreen/OffscreenExecutionService.js +100 -0
  54. package/dist/services/offscreen/OffscreenExecutionService.js.map +1 -0
  55. package/dist/{types/services/ProxyPostMessageStream.d.ts → services/offscreen/OffscreenPostMessageStream.d.ts} +10 -10
  56. package/dist/services/offscreen/OffscreenPostMessageStream.js +66 -0
  57. package/dist/services/offscreen/OffscreenPostMessageStream.js.map +1 -0
  58. package/dist/services/offscreen/index.d.ts +2 -0
  59. package/dist/services/offscreen/index.js +19 -0
  60. package/dist/services/offscreen/index.js.map +1 -0
  61. package/dist/snaps/RequestQueue.js +44 -0
  62. package/dist/snaps/RequestQueue.js.map +1 -0
  63. package/dist/{types/snaps → snaps}/SnapController.d.ts +38 -62
  64. package/dist/snaps/SnapController.js +1478 -0
  65. package/dist/snaps/SnapController.js.map +1 -0
  66. package/dist/snaps/Timer.js +86 -0
  67. package/dist/snaps/Timer.js.map +1 -0
  68. package/dist/{types/snaps → snaps}/endowments/cronjob.d.ts +3 -5
  69. package/dist/snaps/endowments/cronjob.js +105 -0
  70. package/dist/snaps/endowments/cronjob.js.map +1 -0
  71. package/dist/{types/snaps → snaps}/endowments/enum.d.ts +2 -2
  72. package/dist/snaps/endowments/enum.js +15 -0
  73. package/dist/snaps/endowments/enum.js.map +1 -0
  74. package/dist/{types/snaps → snaps}/endowments/ethereum-provider.d.ts +1 -2
  75. package/dist/snaps/endowments/ethereum-provider.js +32 -0
  76. package/dist/snaps/endowments/ethereum-provider.js.map +1 -0
  77. package/dist/{types/snaps → snaps}/endowments/index.d.ts +14 -11
  78. package/dist/snaps/endowments/index.js +60 -0
  79. package/dist/snaps/endowments/index.js.map +1 -0
  80. package/dist/snaps/endowments/keyring.d.ts +40 -0
  81. package/dist/snaps/endowments/keyring.js +103 -0
  82. package/dist/snaps/endowments/keyring.js.map +1 -0
  83. package/dist/{types/snaps → snaps}/endowments/long-running.d.ts +1 -2
  84. package/dist/snaps/endowments/long-running.js +29 -0
  85. package/dist/snaps/endowments/long-running.js.map +1 -0
  86. package/dist/{types/snaps → snaps}/endowments/network-access.d.ts +1 -2
  87. package/dist/snaps/endowments/network-access.js +30 -0
  88. package/dist/snaps/endowments/network-access.js.map +1 -0
  89. package/dist/{types/snaps → snaps}/endowments/rpc.d.ts +3 -5
  90. package/dist/snaps/endowments/rpc.js +92 -0
  91. package/dist/snaps/endowments/rpc.js.map +1 -0
  92. package/dist/{types/snaps → snaps}/endowments/transaction-insight.d.ts +2 -3
  93. package/dist/snaps/endowments/transaction-insight.js +106 -0
  94. package/dist/snaps/endowments/transaction-insight.js.map +1 -0
  95. package/dist/{types/snaps → snaps}/endowments/web-assembly.d.ts +1 -2
  96. package/dist/snaps/endowments/web-assembly.js +31 -0
  97. package/dist/snaps/endowments/web-assembly.js.map +1 -0
  98. package/dist/{types/snaps → snaps}/index.d.ts +0 -2
  99. package/dist/snaps/index.js +21 -0
  100. package/dist/snaps/index.js.map +1 -0
  101. package/dist/{types/snaps → snaps}/location/http.d.ts +2 -3
  102. package/dist/{esm/snaps → snaps}/location/http.js +31 -52
  103. package/dist/snaps/location/http.js.map +1 -0
  104. package/dist/snaps/location/index.js +21 -0
  105. package/dist/snaps/location/index.js.map +1 -0
  106. package/dist/{types/snaps → snaps}/location/local.d.ts +3 -3
  107. package/dist/snaps/location/local.js +51 -0
  108. package/dist/snaps/location/local.js.map +1 -0
  109. package/dist/{types/snaps → snaps}/location/location.d.ts +2 -2
  110. package/dist/snaps/location/location.js +34 -0
  111. package/dist/snaps/location/location.js.map +1 -0
  112. package/dist/snaps/location/npm.d.ts +28 -0
  113. package/dist/{esm/snaps → snaps}/location/npm.js +117 -141
  114. package/dist/snaps/location/npm.js.map +1 -0
  115. package/dist/snaps/registry/index.js +19 -0
  116. package/dist/snaps/registry/index.js.map +1 -0
  117. package/dist/{types/snaps → snaps}/registry/json.d.ts +4 -5
  118. package/dist/snaps/registry/json.js +171 -0
  119. package/dist/snaps/registry/json.js.map +1 -0
  120. package/dist/{types/snaps → snaps}/registry/registry.d.ts +5 -5
  121. package/dist/snaps/registry/registry.js +11 -0
  122. package/dist/snaps/registry/registry.js.map +1 -0
  123. package/dist/snaps/selectors.d.ts +2 -0
  124. package/dist/snaps/selectors.js +6 -0
  125. package/dist/snaps/selectors.js.map +1 -0
  126. package/dist/{types/utils.d.ts → utils.d.ts} +14 -14
  127. package/dist/{esm/utils.js → utils.js} +30 -21
  128. package/dist/utils.js.map +1 -0
  129. package/package.json +32 -46
  130. package/dist/cjs/cronjob/CronjobController.js +0 -290
  131. package/dist/cjs/cronjob/CronjobController.js.map +0 -1
  132. package/dist/cjs/cronjob/index.js +0 -20
  133. package/dist/cjs/cronjob/index.js.map +0 -1
  134. package/dist/cjs/fsm.js +0 -69
  135. package/dist/cjs/fsm.js.map +0 -1
  136. package/dist/cjs/index.js +0 -23
  137. package/dist/cjs/index.js.map +0 -1
  138. package/dist/cjs/logging.js +0 -15
  139. package/dist/cjs/logging.js.map +0 -1
  140. package/dist/cjs/services/AbstractExecutionService.js +0 -386
  141. package/dist/cjs/services/AbstractExecutionService.js.map +0 -1
  142. package/dist/cjs/services/ExecutionService.js +0 -7
  143. package/dist/cjs/services/ExecutionService.js.map +0 -1
  144. package/dist/cjs/services/ProxyPostMessageStream.js +0 -116
  145. package/dist/cjs/services/ProxyPostMessageStream.js.map +0 -1
  146. package/dist/cjs/services/browser.js +0 -32
  147. package/dist/cjs/services/browser.js.map +0 -1
  148. package/dist/cjs/services/iframe/IframeExecutionService.js +0 -54
  149. package/dist/cjs/services/iframe/IframeExecutionService.js.map +0 -1
  150. package/dist/cjs/services/iframe/index.js +0 -20
  151. package/dist/cjs/services/iframe/index.js.map +0 -1
  152. package/dist/cjs/services/index.js +0 -32
  153. package/dist/cjs/services/index.js.map +0 -1
  154. package/dist/cjs/services/node/NodeProcessExecutionService.js +0 -30
  155. package/dist/cjs/services/node/NodeProcessExecutionService.js.map +0 -1
  156. package/dist/cjs/services/node/NodeThreadExecutionService.js +0 -30
  157. package/dist/cjs/services/node/NodeThreadExecutionService.js.map +0 -1
  158. package/dist/cjs/services/node/index.js +0 -21
  159. package/dist/cjs/services/node/index.js.map +0 -1
  160. package/dist/cjs/services/offscreen/OffscreenExecutionService.js +0 -159
  161. package/dist/cjs/services/offscreen/OffscreenExecutionService.js.map +0 -1
  162. package/dist/cjs/services/offscreen/index.js +0 -20
  163. package/dist/cjs/services/offscreen/index.js.map +0 -1
  164. package/dist/cjs/services/webworker/WebWorkerExecutionService.js +0 -148
  165. package/dist/cjs/services/webworker/WebWorkerExecutionService.js.map +0 -1
  166. package/dist/cjs/services/webworker/index.js +0 -20
  167. package/dist/cjs/services/webworker/index.js.map +0 -1
  168. package/dist/cjs/snaps/RequestQueue.js +0 -63
  169. package/dist/cjs/snaps/RequestQueue.js.map +0 -1
  170. package/dist/cjs/snaps/SnapController.js +0 -1735
  171. package/dist/cjs/snaps/SnapController.js.map +0 -1
  172. package/dist/cjs/snaps/Timer.js +0 -117
  173. package/dist/cjs/snaps/Timer.js.map +0 -1
  174. package/dist/cjs/snaps/endowments/cronjob.js +0 -100
  175. package/dist/cjs/snaps/endowments/cronjob.js.map +0 -1
  176. package/dist/cjs/snaps/endowments/enum.js +0 -23
  177. package/dist/cjs/snaps/endowments/enum.js.map +0 -1
  178. package/dist/cjs/snaps/endowments/ethereum-provider.js +0 -43
  179. package/dist/cjs/snaps/endowments/ethereum-provider.js.map +0 -1
  180. package/dist/cjs/snaps/endowments/index.js +0 -82
  181. package/dist/cjs/snaps/endowments/index.js.map +0 -1
  182. package/dist/cjs/snaps/endowments/lifecycle-hooks.js +0 -37
  183. package/dist/cjs/snaps/endowments/lifecycle-hooks.js.map +0 -1
  184. package/dist/cjs/snaps/endowments/long-running.js +0 -38
  185. package/dist/cjs/snaps/endowments/long-running.js.map +0 -1
  186. package/dist/cjs/snaps/endowments/network-access.js +0 -44
  187. package/dist/cjs/snaps/endowments/network-access.js.map +0 -1
  188. package/dist/cjs/snaps/endowments/rpc.js +0 -99
  189. package/dist/cjs/snaps/endowments/rpc.js.map +0 -1
  190. package/dist/cjs/snaps/endowments/transaction-insight.js +0 -106
  191. package/dist/cjs/snaps/endowments/transaction-insight.js.map +0 -1
  192. package/dist/cjs/snaps/endowments/web-assembly.js +0 -42
  193. package/dist/cjs/snaps/endowments/web-assembly.js.map +0 -1
  194. package/dist/cjs/snaps/index.js +0 -25
  195. package/dist/cjs/snaps/index.js.map +0 -1
  196. package/dist/cjs/snaps/location/http.js +0 -106
  197. package/dist/cjs/snaps/location/http.js.map +0 -1
  198. package/dist/cjs/snaps/location/index.js +0 -23
  199. package/dist/cjs/snaps/location/index.js.map +0 -1
  200. package/dist/cjs/snaps/location/local.js +0 -93
  201. package/dist/cjs/snaps/location/local.js.map +0 -1
  202. package/dist/cjs/snaps/location/location.js +0 -34
  203. package/dist/cjs/snaps/location/location.js.map +0 -1
  204. package/dist/cjs/snaps/location/npm.js +0 -291
  205. package/dist/cjs/snaps/location/npm.js.map +0 -1
  206. package/dist/cjs/snaps/permissions.js +0 -61
  207. package/dist/cjs/snaps/permissions.js.map +0 -1
  208. package/dist/cjs/snaps/registry/index.js +0 -21
  209. package/dist/cjs/snaps/registry/index.js.map +0 -1
  210. package/dist/cjs/snaps/registry/json.js +0 -250
  211. package/dist/cjs/snaps/registry/json.js.map +0 -1
  212. package/dist/cjs/snaps/registry/registry.js +0 -18
  213. package/dist/cjs/snaps/registry/registry.js.map +0 -1
  214. package/dist/cjs/snaps/selectors.js +0 -13
  215. package/dist/cjs/snaps/selectors.js.map +0 -1
  216. package/dist/cjs/utils.js +0 -70
  217. package/dist/cjs/utils.js.map +0 -1
  218. package/dist/esm/cronjob/CronjobController.js +0 -275
  219. package/dist/esm/cronjob/CronjobController.js.map +0 -1
  220. package/dist/esm/cronjob/index.js +0 -3
  221. package/dist/esm/cronjob/index.js.map +0 -1
  222. package/dist/esm/fsm.js +0 -70
  223. package/dist/esm/fsm.js.map +0 -1
  224. package/dist/esm/index.js +0 -6
  225. package/dist/esm/index.js.map +0 -1
  226. package/dist/esm/logging.js +0 -10
  227. package/dist/esm/logging.js.map +0 -1
  228. package/dist/esm/services/AbstractExecutionService.js +0 -369
  229. package/dist/esm/services/AbstractExecutionService.js.map +0 -1
  230. package/dist/esm/services/ExecutionService.js +0 -4
  231. package/dist/esm/services/ExecutionService.js.map +0 -1
  232. package/dist/esm/services/ProxyPostMessageStream.js +0 -109
  233. package/dist/esm/services/ProxyPostMessageStream.js.map +0 -1
  234. package/dist/esm/services/browser.js +0 -9
  235. package/dist/esm/services/browser.js.map +0 -1
  236. package/dist/esm/services/iframe/IframeExecutionService.js +0 -44
  237. package/dist/esm/services/iframe/IframeExecutionService.js.map +0 -1
  238. package/dist/esm/services/iframe/index.js +0 -3
  239. package/dist/esm/services/iframe/index.js.map +0 -1
  240. package/dist/esm/services/index.js +0 -9
  241. package/dist/esm/services/index.js.map +0 -1
  242. package/dist/esm/services/node/NodeProcessExecutionService.js +0 -20
  243. package/dist/esm/services/node/NodeProcessExecutionService.js.map +0 -1
  244. package/dist/esm/services/node/NodeThreadExecutionService.js +0 -21
  245. package/dist/esm/services/node/NodeThreadExecutionService.js.map +0 -1
  246. package/dist/esm/services/node/index.js +0 -4
  247. package/dist/esm/services/node/index.js.map +0 -1
  248. package/dist/esm/services/offscreen/OffscreenExecutionService.js +0 -149
  249. package/dist/esm/services/offscreen/OffscreenExecutionService.js.map +0 -1
  250. package/dist/esm/services/offscreen/index.js +0 -3
  251. package/dist/esm/services/offscreen/index.js.map +0 -1
  252. package/dist/esm/services/webworker/WebWorkerExecutionService.js +0 -130
  253. package/dist/esm/services/webworker/WebWorkerExecutionService.js.map +0 -1
  254. package/dist/esm/services/webworker/index.js +0 -3
  255. package/dist/esm/services/webworker/index.js.map +0 -1
  256. package/dist/esm/snaps/RequestQueue.js +0 -53
  257. package/dist/esm/snaps/RequestQueue.js.map +0 -1
  258. package/dist/esm/snaps/SnapController.js +0 -1714
  259. package/dist/esm/snaps/SnapController.js.map +0 -1
  260. package/dist/esm/snaps/Timer.js +0 -107
  261. package/dist/esm/snaps/Timer.js.map +0 -1
  262. package/dist/esm/snaps/endowments/cronjob.js +0 -99
  263. package/dist/esm/snaps/endowments/cronjob.js.map +0 -1
  264. package/dist/esm/snaps/endowments/enum.js +0 -13
  265. package/dist/esm/snaps/endowments/enum.js.map +0 -1
  266. package/dist/esm/snaps/endowments/ethereum-provider.js +0 -33
  267. package/dist/esm/snaps/endowments/ethereum-provider.js.map +0 -1
  268. package/dist/esm/snaps/endowments/index.js +0 -41
  269. package/dist/esm/snaps/endowments/index.js.map +0 -1
  270. package/dist/esm/snaps/endowments/lifecycle-hooks.js +0 -27
  271. package/dist/esm/snaps/endowments/lifecycle-hooks.js.map +0 -1
  272. package/dist/esm/snaps/endowments/long-running.js +0 -28
  273. package/dist/esm/snaps/endowments/long-running.js.map +0 -1
  274. package/dist/esm/snaps/endowments/network-access.js +0 -34
  275. package/dist/esm/snaps/endowments/network-access.js.map +0 -1
  276. package/dist/esm/snaps/endowments/rpc.js +0 -88
  277. package/dist/esm/snaps/endowments/rpc.js.map +0 -1
  278. package/dist/esm/snaps/endowments/transaction-insight.js +0 -99
  279. package/dist/esm/snaps/endowments/transaction-insight.js.map +0 -1
  280. package/dist/esm/snaps/endowments/web-assembly.js +0 -32
  281. package/dist/esm/snaps/endowments/web-assembly.js.map +0 -1
  282. package/dist/esm/snaps/index.js +0 -8
  283. package/dist/esm/snaps/index.js.map +0 -1
  284. package/dist/esm/snaps/location/http.js.map +0 -1
  285. package/dist/esm/snaps/location/index.js +0 -6
  286. package/dist/esm/snaps/location/index.js.map +0 -1
  287. package/dist/esm/snaps/location/local.js +0 -83
  288. package/dist/esm/snaps/location/local.js.map +0 -1
  289. package/dist/esm/snaps/location/location.js +0 -30
  290. package/dist/esm/snaps/location/location.js.map +0 -1
  291. package/dist/esm/snaps/location/npm.js.map +0 -1
  292. package/dist/esm/snaps/permissions.js +0 -50
  293. package/dist/esm/snaps/permissions.js.map +0 -1
  294. package/dist/esm/snaps/registry/index.js +0 -4
  295. package/dist/esm/snaps/registry/index.js.map +0 -1
  296. package/dist/esm/snaps/registry/json.js +0 -240
  297. package/dist/esm/snaps/registry/json.js.map +0 -1
  298. package/dist/esm/snaps/registry/registry.js +0 -8
  299. package/dist/esm/snaps/registry/registry.js.map +0 -1
  300. package/dist/esm/snaps/selectors.js +0 -3
  301. package/dist/esm/snaps/selectors.js.map +0 -1
  302. package/dist/esm/utils.js.map +0 -1
  303. package/dist/types/services/offscreen/index.d.ts +0 -1
  304. package/dist/types/services/webworker/WebWorkerExecutionService.d.ts +0 -45
  305. package/dist/types/services/webworker/index.d.ts +0 -1
  306. package/dist/types/snaps/endowments/lifecycle-hooks.d.ts +0 -15
  307. package/dist/types/snaps/location/npm.d.ts +0 -49
  308. package/dist/types/snaps/permissions.d.ts +0 -16
  309. package/dist/types/snaps/selectors.d.ts +0 -2
  310. /package/dist/{types/cronjob → cronjob}/index.d.ts +0 -0
  311. /package/dist/{types/logging.d.ts → logging.d.ts} +0 -0
  312. /package/dist/{types/services → services}/iframe/index.d.ts +0 -0
  313. /package/dist/{types/services → services}/node/index.d.ts +0 -0
  314. /package/dist/{types/snaps → snaps}/RequestQueue.d.ts +0 -0
  315. /package/dist/{types/snaps → snaps}/Timer.d.ts +0 -0
  316. /package/dist/{types/snaps → snaps}/location/index.d.ts +0 -0
  317. /package/dist/{types/snaps → snaps}/registry/index.d.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-insight.js","sourceRoot":"","sources":["../../../src/snaps/endowments/transaction-insight.ts"],"names":[],"mappings":";;;AAAA,2EAUyC;AACzC,uDAAuD;AACvD,2CAOyB;AACzB,mDAA2C;AAE3C,iCAAwC;AAExC,MAAM,cAAc,GAAG,qBAAc,CAAC,kBAAkB,CAAC;AAUzD;;;;;;GAMG;AACH,MAAM,oBAAoB,GAItB,CAAC,eAAyB,EAAE,EAAE;IAChC,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,SAAS;QACxC,UAAU,EAAE,cAAc;QAC1B,cAAc,EAAE,CAAC,4BAAc,CAAC,iBAAiB,CAAC;QAClD,eAAe,EAAE,CAAC,cAAsC,EAAE,EAAE,CAAC,SAAS;QACtE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YACzB,IACE,CAAC,OAAO,KAAK,IAAI,IAAI,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC;gBACzC,CAAC,OAAO,EAAE,MAAM,KAAK,CAAC;oBACpB,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,4BAAc,CAAC,iBAAiB,CAAC,EACvD;gBACA,MAAM,0BAAS,CAAC,GAAG,CAAC,aAAa,CAAC;oBAChC,OAAO,EAAE,sBAAsB,4BAAc,CAAC,iBAAiB,WAAW;iBAC3E,CAAC,CAAC;aACJ;QACH,CAAC;QACD,YAAY,EAAE,CAAC,mCAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAEW,QAAA,kCAAkC,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9D,UA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KAAK,4BAAc,CAAC,iBAAiB,CAAC,CAAC;IAExE,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAA4B,CAAC;IAEhE,OAAO,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC;AAC9B,CAAC;AAbD,gEAaC;AAEY,QAAA,sCAAsC,GAG/C;IACF,CAAC,4BAAc,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC;QAChD,IAAI,EAAE,4BAAc,CAAC,iBAAiB;QACtC,SAAS,EAAE,CAAC,MAA2B,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC;KACnE,CAAC;CACH,CAAC","sourcesContent":["import {\n PermissionSpecificationBuilder,\n PermissionType,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n CaveatSpecificationConstraint,\n Caveat,\n SubjectType,\n} from '@metamask/permission-controller';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport {\n assert,\n hasProperty,\n isObject,\n isPlainObject,\n Json,\n NonEmptyArray,\n} from '@metamask/utils';\nimport { ethErrors } from 'eth-rpc-errors';\n\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.TransactionInsight;\n\ntype TransactionInsightEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => undefined;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * `endowment:transaction-insight` returns nothing; it is intended to be used as a flag\n * by the extension to detect whether the snap has the capability to show information on the transaction confirmation screen.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the transaction-insight endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n TransactionInsightEndowmentSpecification\n> = (_builderOptions?: unknown) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: [SnapCaveatType.TransactionOrigin],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => undefined,\n validator: ({ caveats }) => {\n if (\n (caveats !== null && caveats?.length > 1) ||\n (caveats?.length === 1 &&\n caveats[0].type !== SnapCaveatType.TransactionOrigin)\n ) {\n throw ethErrors.rpc.invalidParams({\n message: `Expected a single \"${SnapCaveatType.TransactionOrigin}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const transactionInsightEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Validates the type of the caveat value.\n *\n * @param caveat - The caveat to validate.\n * @throws If the caveat value is invalid.\n */\nfunction validateCaveat(caveat: Caveat<string, any>): void {\n if (!hasProperty(caveat, 'value') || !isPlainObject(caveat)) {\n throw ethErrors.rpc.invalidParams({\n message: 'Expected a plain object.',\n });\n }\n\n const { value } = caveat;\n\n assert(\n typeof value === 'boolean',\n 'Expected caveat value to have type \"boolean\"',\n );\n}\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionsController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function getTransactionInsightCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n if (\n !value ||\n !isObject(value) ||\n (isObject(value) && Object.keys(value).length === 0)\n ) {\n return { caveats: null };\n }\n return {\n caveats: [\n {\n type: SnapCaveatType.TransactionOrigin,\n value:\n hasProperty(value, 'allowTransactionOrigin') &&\n (value.allowTransactionOrigin as boolean),\n },\n ],\n };\n}\n\n/**\n * Getter function to get the transaction origin caveat from a permission.\n *\n * This does basic validation of the caveat, but does not validate the type or\n * value of the namespaces object itself, as this is handled by the\n * `PermissionsController` when the permission is requested.\n *\n * @param permission - The permission to get the transaction origin caveat from.\n * @returns The transaction origin, or `null` if the permission does not have a\n * transaction origin caveat.\n */\nexport function getTransactionOriginCaveat(\n permission?: PermissionConstraint,\n): boolean | null {\n if (!permission?.caveats) {\n return null;\n }\n\n assert(permission.caveats.length === 1);\n assert(permission.caveats[0].type === SnapCaveatType.TransactionOrigin);\n\n const caveat = permission.caveats[0] as Caveat<string, boolean>;\n\n return caveat.value ?? null;\n}\n\nexport const transactionInsightCaveatSpecifications: Record<\n SnapCaveatType.TransactionOrigin,\n CaveatSpecificationConstraint\n> = {\n [SnapCaveatType.TransactionOrigin]: Object.freeze({\n type: SnapCaveatType.TransactionOrigin,\n validator: (caveat: Caveat<string, any>) => validateCaveat(caveat),\n }),\n};\n"]}
@@ -1,5 +1,4 @@
1
- import type { PermissionSpecificationBuilder } from '@metamask/permission-controller';
2
- import { PermissionType } from '@metamask/permission-controller';
1
+ import { PermissionSpecificationBuilder, PermissionType } from '@metamask/permission-controller';
3
2
  import { SnapEndowments } from './enum';
4
3
  declare const permissionName = SnapEndowments.WebAssemblyAccess;
5
4
  export declare const webAssemblyEndowmentBuilder: Readonly<{
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.webAssemblyEndowmentBuilder = void 0;
4
+ const permission_controller_1 = require("@metamask/permission-controller");
5
+ const enum_1 = require("./enum");
6
+ const permissionName = enum_1.SnapEndowments.WebAssemblyAccess;
7
+ /**
8
+ * `endowment:webassembly` returns the name of global browser API(s) that
9
+ * enable access to the WebAssembly API.
10
+ * This is intended to populate the endowments of the SES Compartment
11
+ * in which a Snap executes.
12
+ *
13
+ * @param _builderOptions - Optional specification builder options.
14
+ * @returns The specification for the WebAssembly endowment.
15
+ */
16
+ const specificationBuilder = (_builderOptions) => {
17
+ return {
18
+ permissionType: permission_controller_1.PermissionType.Endowment,
19
+ targetName: permissionName,
20
+ allowedCaveats: null,
21
+ endowmentGetter: (_getterOptions) => {
22
+ return ['WebAssembly'];
23
+ },
24
+ subjectTypes: [permission_controller_1.SubjectType.Snap],
25
+ };
26
+ };
27
+ exports.webAssemblyEndowmentBuilder = Object.freeze({
28
+ targetName: permissionName,
29
+ specificationBuilder,
30
+ });
31
+ //# sourceMappingURL=web-assembly.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-assembly.js","sourceRoot":"","sources":["../../../src/snaps/endowments/web-assembly.ts"],"names":[],"mappings":";;;AAAA,2EAMyC;AAEzC,iCAAwC;AAExC,MAAM,cAAc,GAAG,qBAAc,CAAC,iBAAiB,CAAC;AASxD;;;;;;;;GAQG;AACH,MAAM,oBAAoB,GAItB,CAAC,eAAqB,EAAE,EAAE;IAC5B,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,SAAS;QACxC,UAAU,EAAE,cAAc;QAC1B,cAAc,EAAE,IAAI;QACpB,eAAe,EAAE,CAAC,cAAsC,EAAE,EAAE;YAC1D,OAAO,CAAC,aAAa,CAAC,CAAC;QACzB,CAAC;QACD,YAAY,EAAE,CAAC,mCAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAEW,QAAA,2BAA2B,GAAG,MAAM,CAAC,MAAM,CAAC;IACvD,UAAU,EAAE,cAAc;IAC1B,oBAAoB;CACZ,CAAC,CAAC","sourcesContent":["import {\n EndowmentGetterParams,\n PermissionSpecificationBuilder,\n PermissionType,\n ValidPermissionSpecification,\n SubjectType,\n} from '@metamask/permission-controller';\n\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.WebAssemblyAccess;\n\ntype WebAssemblyEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (_options?: any) => ['WebAssembly'];\n allowedCaveats: null;\n}>;\n\n/**\n * `endowment:webassembly` returns the name of global browser API(s) that\n * enable access to the WebAssembly API.\n * This is intended to populate the endowments of the SES Compartment\n * in which a Snap executes.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the WebAssembly endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n WebAssemblyEndowmentSpecification\n> = (_builderOptions?: any) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: null,\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => {\n return ['WebAssembly'];\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const webAssemblyEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n"]}
@@ -1,6 +1,4 @@
1
- export * from './location';
2
1
  export * from './SnapController';
3
2
  export * from './endowments';
4
3
  export * from './selectors';
5
4
  export * from './registry';
6
- export * from './permissions';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./SnapController"), exports);
18
+ __exportStar(require("./endowments"), exports);
19
+ __exportStar(require("./selectors"), exports);
20
+ __exportStar(require("./registry"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/snaps/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,+CAA6B;AAC7B,8CAA4B;AAC5B,6CAA2B","sourcesContent":["export * from './SnapController';\nexport * from './endowments';\nexport * from './selectors';\nexport * from './registry';\n"]}
@@ -1,6 +1,5 @@
1
- import type { SnapManifest } from '@metamask/snaps-utils';
2
- import { VirtualFile } from '@metamask/snaps-utils';
3
- import type { SnapLocation } from './location';
1
+ import { SnapManifest, VirtualFile } from '@metamask/snaps-utils';
2
+ import { SnapLocation } from './location';
4
3
  export interface HttpOptions {
5
4
  /**
6
5
  * @default fetch
@@ -1,44 +1,45 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpLocation = void 0;
4
+ const snaps_utils_1 = require("@metamask/snaps-utils");
5
+ const utils_1 = require("@metamask/utils");
6
+ class HttpLocation {
7
+ constructor(url, opts = {}) {
8
+ // We keep contents separate because then we can use only one Blob in cache,
9
+ // which we convert to Uint8Array when actually returning the file.
10
+ //
11
+ // That avoids deepCloning file contents.
12
+ // I imagine ArrayBuffers are copy-on-write optimized, meaning
13
+ // in most often case we'll only have one file contents in common case.
14
+ this.cache = new Map();
15
+ (0, utils_1.assertStruct)(url.toString(), snaps_utils_1.HttpSnapIdStruct, 'Invalid Snap Id: ');
16
+ this.fetchFn = opts.fetch ?? globalThis.fetch.bind(globalThis);
17
+ this.fetchOptions = opts.fetchOptions;
18
+ this.url = url;
11
19
  }
12
- return obj;
13
- }
14
- import { VirtualFile, HttpSnapIdStruct, NpmSnapFileNames, createSnapManifest, normalizeRelative, parseJson } from '@metamask/snaps-utils';
15
- import { assert, assertStruct } from '@metamask/utils';
16
- export class HttpLocation {
17
20
  async manifest() {
18
21
  if (this.validatedManifest) {
19
22
  return this.validatedManifest.clone();
20
23
  }
21
24
  // jest-fetch-mock doesn't handle new URL(), we need to convert .toString()
22
- const canonicalPath = new URL(NpmSnapFileNames.Manifest, this.url).toString();
25
+ const canonicalPath = new URL(snaps_utils_1.NpmSnapFileNames.Manifest, this.url).toString();
23
26
  const response = await this.fetchFn(canonicalPath, this.fetchOptions);
24
27
  if (!response.ok) {
25
28
  throw new Error(`Failed to fetch "${canonicalPath}". Status code: ${response.status}.`);
26
29
  }
27
30
  const contents = await response.text();
28
- const manifest = parseJson(contents);
29
- const vfile = new VirtualFile({
31
+ const manifest = (0, snaps_utils_1.parseJson)(contents);
32
+ const vfile = new snaps_utils_1.VirtualFile({
30
33
  value: contents,
31
- result: createSnapManifest(manifest),
32
- path: NpmSnapFileNames.Manifest,
33
- data: {
34
- canonicalPath
35
- }
34
+ result: (0, snaps_utils_1.createSnapManifest)(manifest),
35
+ path: snaps_utils_1.NpmSnapFileNames.Manifest,
36
+ data: { canonicalPath },
36
37
  });
37
38
  this.validatedManifest = vfile;
38
39
  return this.manifest();
39
40
  }
40
41
  async fetch(path) {
41
- const relativePath = normalizeRelative(path);
42
+ const relativePath = (0, snaps_utils_1.normalizeRelative)(path);
42
43
  const cached = this.cache.get(relativePath);
43
44
  if (cached !== undefined) {
44
45
  const { file, contents } = cached;
@@ -52,45 +53,23 @@ export class HttpLocation {
52
53
  if (!response.ok) {
53
54
  throw new Error(`Failed to fetch "${canonicalPath}". Status code: ${response.status}.`);
54
55
  }
55
- const vfile = new VirtualFile({
56
+ const vfile = new snaps_utils_1.VirtualFile({
56
57
  value: '',
57
58
  path: relativePath,
58
- data: {
59
- canonicalPath
60
- }
59
+ data: { canonicalPath },
61
60
  });
62
61
  const blob = await response.blob();
63
- assert(!this.cache.has(relativePath), 'Corrupted cache, multiple files with same path.');
64
- this.cache.set(relativePath, {
65
- file: vfile,
66
- contents: blob
67
- });
62
+ (0, utils_1.assert)(!this.cache.has(relativePath), 'Corrupted cache, multiple files with same path.');
63
+ this.cache.set(relativePath, { file: vfile, contents: blob });
68
64
  return this.fetch(relativePath);
69
65
  }
70
66
  get root() {
71
67
  return new URL(this.url);
72
68
  }
73
69
  toCanonical(path) {
74
- assert(!path.startsWith('/'), 'Tried to parse absolute path.');
70
+ (0, utils_1.assert)(!path.startsWith('/'), 'Tried to parse absolute path.');
75
71
  return new URL(path, this.url);
76
72
  }
77
- constructor(url, opts = {}){
78
- // We keep contents separate because then we can use only one Blob in cache,
79
- // which we convert to Uint8Array when actually returning the file.
80
- //
81
- // That avoids deepCloning file contents.
82
- // I imagine ArrayBuffers are copy-on-write optimized, meaning
83
- // in most often case we'll only have one file contents in common case.
84
- _define_property(this, "cache", new Map());
85
- _define_property(this, "validatedManifest", void 0);
86
- _define_property(this, "url", void 0);
87
- _define_property(this, "fetchFn", void 0);
88
- _define_property(this, "fetchOptions", void 0);
89
- assertStruct(url.toString(), HttpSnapIdStruct, 'Invalid Snap Id: ');
90
- this.fetchFn = opts.fetch ?? globalThis.fetch.bind(globalThis);
91
- this.fetchOptions = opts.fetchOptions;
92
- this.url = url;
93
- }
94
73
  }
95
-
74
+ exports.HttpLocation = HttpLocation;
96
75
  //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/snaps/location/http.ts"],"names":[],"mappings":";;;AAAA,uDAQ+B;AAC/B,2CAAuD;AAYvD,MAAa,YAAY;IAoBvB,YAAY,GAAQ,EAAE,OAAoB,EAAE;QAnB5C,4EAA4E;QAC5E,mEAAmE;QACnE,EAAE;QACF,yCAAyC;QACzC,8DAA8D;QAC9D,uEAAuE;QACtD,UAAK,GAAG,IAAI,GAAG,EAG7B,CAAC;QAWF,IAAA,oBAAY,EAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,8BAAgB,EAAE,mBAAmB,CAAC,CAAC;QACpE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC/D,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,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I,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACF;AAlGD,oCAkGC","sourcesContent":["import {\n SnapManifest,\n VirtualFile,\n HttpSnapIdStruct,\n NpmSnapFileNames,\n createSnapManifest,\n normalizeRelative,\n parseJson,\n} from '@metamask/snaps-utils';\nimport { assert, assertStruct } from '@metamask/utils';\n\nimport { SnapLocation } from './location';\n\nexport interface HttpOptions {\n /**\n * @default fetch\n */\n fetch?: typeof fetch;\n fetchOptions?: RequestInit;\n}\n\nexport class HttpLocation implements SnapLocation {\n // We keep contents separate because then we can use only one Blob in cache,\n // which we convert to Uint8Array when actually returning the file.\n //\n // That avoids deepCloning file contents.\n // I imagine ArrayBuffers are copy-on-write optimized, meaning\n // in most often case we'll only have one file contents in common case.\n private readonly cache = new Map<\n string,\n { file: VirtualFile; contents: Blob }\n >();\n\n private validatedManifest?: VirtualFile<SnapManifest>;\n\n private readonly url: URL;\n\n private readonly fetchFn: typeof fetch;\n\n private readonly fetchOptions?: RequestInit;\n\n constructor(url: URL, opts: HttpOptions = {}) {\n assertStruct(url.toString(), HttpSnapIdStruct, 'Invalid Snap Id: ');\n this.fetchFn = opts.fetch ?? globalThis.fetch.bind(globalThis);\n this.fetchOptions = opts.fetchOptions;\n this.url = url;\n }\n\n async manifest(): Promise<VirtualFile<SnapManifest>> {\n if (this.validatedManifest) {\n return this.validatedManifest.clone();\n }\n\n // jest-fetch-mock doesn't handle new URL(), we need to convert .toString()\n const canonicalPath = new URL(\n NpmSnapFileNames.Manifest,\n this.url,\n ).toString();\n\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const contents = await response.text();\n const manifest = parseJson(contents);\n const vfile = new VirtualFile<SnapManifest>({\n value: contents,\n result: createSnapManifest(manifest),\n path: NpmSnapFileNames.Manifest,\n data: { canonicalPath },\n });\n this.validatedManifest = vfile;\n\n return this.manifest();\n }\n\n async fetch(path: string): Promise<VirtualFile> {\n const relativePath = normalizeRelative(path);\n const cached = this.cache.get(relativePath);\n if (cached !== undefined) {\n const { file, contents } = cached;\n const value = new Uint8Array(await contents.arrayBuffer());\n const vfile = file.clone();\n vfile.value = value;\n return vfile;\n }\n\n const canonicalPath = this.toCanonical(relativePath).toString();\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const vfile = new VirtualFile({\n value: '',\n path: relativePath,\n data: { canonicalPath },\n });\n const blob = await response.blob();\n assert(\n !this.cache.has(relativePath),\n 'Corrupted cache, multiple files with same path.',\n );\n this.cache.set(relativePath, { file: vfile, contents: blob });\n\n return this.fetch(relativePath);\n }\n\n get root(): URL {\n return new URL(this.url);\n }\n\n private toCanonical(path: string): URL {\n assert(!path.startsWith('/'), 'Tried to parse absolute path.');\n return new URL(path, this.url);\n }\n}\n"]}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./location"), exports);
18
+ __exportStar(require("./npm"), exports);
19
+ __exportStar(require("./local"), exports);
20
+ __exportStar(require("./http"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/snaps/location/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,wCAAsB;AACtB,0CAAwB;AACxB,yCAAuB","sourcesContent":["export * from './location';\nexport * from './npm';\nexport * from './local';\nexport * from './http';\n"]}
@@ -1,6 +1,6 @@
1
- import type { SnapManifest, VirtualFile } from '@metamask/snaps-utils';
2
- import type { HttpOptions } from './http';
3
- import type { SnapLocation } from './location';
1
+ import { SnapManifest, VirtualFile } from '@metamask/snaps-utils';
2
+ import { HttpOptions } from './http';
3
+ import { SnapLocation } from './location';
4
4
  export declare class LocalLocation implements SnapLocation {
5
5
  #private;
6
6
  constructor(url: URL, opts?: HttpOptions);
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _LocalLocation_http;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.LocalLocation = void 0;
16
+ const snaps_utils_1 = require("@metamask/snaps-utils");
17
+ const utils_1 = require("@metamask/utils");
18
+ const http_1 = require("./http");
19
+ class LocalLocation {
20
+ constructor(url, opts = {}) {
21
+ _LocalLocation_http.set(this, void 0);
22
+ (0, utils_1.assertStruct)(url.toString(), snaps_utils_1.LocalSnapIdStruct, 'Invalid Snap Id');
23
+ // TODO(ritave): Write deepMerge() which merges fetchOptions.
24
+ (0, utils_1.assert)(opts.fetchOptions === undefined, 'Currently adding fetch options to local: is unsupported.');
25
+ __classPrivateFieldSet(this, _LocalLocation_http, new http_1.HttpLocation(new URL(url.toString().slice(snaps_utils_1.SnapIdPrefixes.local.length)), { ...opts, fetchOptions: { cache: 'no-cache' } }), "f");
26
+ }
27
+ async manifest() {
28
+ const vfile = await __classPrivateFieldGet(this, _LocalLocation_http, "f").manifest();
29
+ return convertCanonical(vfile);
30
+ }
31
+ async fetch(path) {
32
+ return convertCanonical(await __classPrivateFieldGet(this, _LocalLocation_http, "f").fetch(path));
33
+ }
34
+ get shouldAlwaysReload() {
35
+ return true;
36
+ }
37
+ }
38
+ exports.LocalLocation = LocalLocation;
39
+ _LocalLocation_http = new WeakMap();
40
+ /**
41
+ * Converts vfiles with canonical `http:` paths into `local:` paths.
42
+ *
43
+ * @param vfile - The {@link VirtualFile} to convert.
44
+ * @returns The same object with updated `.data.canonicalPath`.
45
+ */
46
+ function convertCanonical(vfile) {
47
+ (0, utils_1.assert)(vfile.data.canonicalPath !== undefined);
48
+ vfile.data.canonicalPath = `local:${vfile.data.canonicalPath}`;
49
+ return vfile;
50
+ }
51
+ //# sourceMappingURL=local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.js","sourceRoot":"","sources":["../../../src/snaps/location/local.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAK+B;AAC/B,2CAAuD;AAEvD,iCAAmD;AAGnD,MAAa,aAAa;IAGxB,YAAY,GAAQ,EAAE,OAAoB,EAAE;QAF5C,sCAA6B;QAG3B,IAAA,oBAAY,EAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,+BAAiB,EAAE,iBAAiB,CAAC,CAAC;QACnE,6DAA6D;QAC7D,IAAA,cAAM,EACJ,IAAI,CAAC,YAAY,KAAK,SAAS,EAC/B,0DAA0D,CAC3D,CAAC;QAEF,uBAAA,IAAI,uBAAS,IAAI,mBAAY,CAC3B,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,4BAAc,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAC1D,EAAE,GAAG,IAAI,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,CACjD,MAAA,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,KAAK,GAAG,MAAM,uBAAA,IAAI,2BAAM,CAAC,QAAQ,EAAE,CAAC;QAE1C,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY;QACtB,OAAO,gBAAgB,CAAC,MAAM,uBAAA,IAAI,2BAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA9BD,sCA8BC;;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CACvB,KAA0B;IAE1B,IAAA,cAAM,EAAC,KAAK,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC;IAC/C,KAAK,CAAC,IAAI,CAAC,aAAa,GAAG,SAAS,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC/D,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import {\n LocalSnapIdStruct,\n SnapIdPrefixes,\n SnapManifest,\n VirtualFile,\n} from '@metamask/snaps-utils';\nimport { assert, assertStruct } from '@metamask/utils';\n\nimport { HttpLocation, HttpOptions } from './http';\nimport { SnapLocation } from './location';\n\nexport class LocalLocation implements SnapLocation {\n readonly #http: HttpLocation;\n\n constructor(url: URL, opts: HttpOptions = {}) {\n assertStruct(url.toString(), LocalSnapIdStruct, 'Invalid Snap Id');\n // TODO(ritave): Write deepMerge() which merges fetchOptions.\n assert(\n opts.fetchOptions === undefined,\n 'Currently adding fetch options to local: is unsupported.',\n );\n\n this.#http = new HttpLocation(\n new URL(url.toString().slice(SnapIdPrefixes.local.length)),\n { ...opts, fetchOptions: { cache: 'no-cache' } },\n );\n }\n\n async manifest(): Promise<VirtualFile<SnapManifest>> {\n const vfile = await this.#http.manifest();\n\n return convertCanonical(vfile);\n }\n\n async fetch(path: string): Promise<VirtualFile> {\n return convertCanonical(await this.#http.fetch(path));\n }\n\n get shouldAlwaysReload() {\n return true;\n }\n}\n\n/**\n * Converts vfiles with canonical `http:` paths into `local:` paths.\n *\n * @param vfile - The {@link VirtualFile} to convert.\n * @returns The same object with updated `.data.canonicalPath`.\n */\nfunction convertCanonical<Result>(\n vfile: VirtualFile<Result>,\n): VirtualFile<Result> {\n assert(vfile.data.canonicalPath !== undefined);\n vfile.data.canonicalPath = `local:${vfile.data.canonicalPath}`;\n return vfile;\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { SnapManifest, VirtualFile } from '@metamask/snaps-utils';
2
- import type { NpmOptions } from './npm';
1
+ import { SnapManifest, VirtualFile } from '@metamask/snaps-utils';
2
+ import { NpmOptions } from './npm';
3
3
  declare module '@metamask/snaps-utils' {
4
4
  interface DataMap {
5
5
  /**
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectSnapLocation = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ const http_1 = require("./http");
6
+ const local_1 = require("./local");
7
+ const npm_1 = require("./npm");
8
+ /**
9
+ * Auto-magically detects which SnapLocation object to create based on the provided {@link location}.
10
+ *
11
+ * @param location - A {@link https://github.com/MetaMask/SIPs/blob/main/SIPS/sip-8.md SIP-8} uri.
12
+ * @param opts - NPM options and feature flags.
13
+ * @returns SnapLocation based on url.
14
+ */
15
+ function detectSnapLocation(location, opts) {
16
+ const allowHttp = opts?.allowHttp ?? false;
17
+ const allowLocal = opts?.allowLocal ?? false;
18
+ const root = new URL(location);
19
+ switch (root.protocol) {
20
+ case 'npm:':
21
+ return new npm_1.NpmLocation(root, opts);
22
+ case 'local:':
23
+ (0, utils_1.assert)(allowLocal, new TypeError('Fetching local snaps is disabled.'));
24
+ return new local_1.LocalLocation(root, opts);
25
+ case 'http:':
26
+ case 'https:':
27
+ (0, utils_1.assert)(allowHttp, new TypeError('Fetching snaps through http/https is disabled.'));
28
+ return new http_1.HttpLocation(root, opts);
29
+ default:
30
+ throw new TypeError(`Unrecognized "${root.protocol}" snap location protocol.`);
31
+ }
32
+ }
33
+ exports.detectSnapLocation = detectSnapLocation;
34
+ //# sourceMappingURL=location.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"location.js","sourceRoot":"","sources":["../../../src/snaps/location/location.ts"],"names":[],"mappings":";;;AACA,2CAAyC;AAEzC,iCAAsC;AACtC,mCAAwC;AACxC,+BAAgD;AAsChD;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAChC,QAAsB,EACtB,IAAgC;IAEhC,MAAM,SAAS,GAAG,IAAI,EAAE,SAAS,IAAI,KAAK,CAAC;IAC3C,MAAM,UAAU,GAAG,IAAI,EAAE,UAAU,IAAI,KAAK,CAAC;IAC7C,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/B,QAAQ,IAAI,CAAC,QAAQ,EAAE;QACrB,KAAK,MAAM;YACT,OAAO,IAAI,iBAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACrC,KAAK,QAAQ;YACX,IAAA,cAAM,EAAC,UAAU,EAAE,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC,CAAC;YACvE,OAAO,IAAI,qBAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACvC,KAAK,OAAO,CAAC;QACb,KAAK,QAAQ;YACX,IAAA,cAAM,EACJ,SAAS,EACT,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAChE,CAAC;YACF,OAAO,IAAI,mBAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACtC;YACE,MAAM,IAAI,SAAS,CACjB,iBAAiB,IAAI,CAAC,QAAQ,2BAA2B,CAC1D,CAAC;KACL;AACH,CAAC;AAzBD,gDAyBC","sourcesContent":["import { SnapManifest, VirtualFile } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\n\nimport { HttpLocation } from './http';\nimport { LocalLocation } from './local';\nimport { NpmLocation, NpmOptions } from './npm';\n\ndeclare module '@metamask/snaps-utils' {\n interface DataMap {\n /**\n * Fully qualified, canonical path for the file in {@link https://github.com/MetaMask/SIPs/blob/main/SIPS/sip-8.md SIP-8 } URI format.\n */\n canonicalPath: string;\n }\n}\n\nexport interface SnapLocation {\n /**\n * All files are relative to the manifest, except the manifest itself.\n */\n manifest(): Promise<VirtualFile<SnapManifest>>;\n fetch(path: string): Promise<VirtualFile>;\n\n readonly shouldAlwaysReload?: boolean;\n}\n\nexport type DetectSnapLocationOptions = NpmOptions & {\n /**\n * The function used to fetch data.\n *\n * @default globalThis.fetch\n */\n fetch?: typeof fetch;\n /**\n * @default false\n */\n allowHttp?: boolean;\n /**\n * @default false\n */\n allowLocal?: boolean;\n};\n\n/**\n * Auto-magically detects which SnapLocation object to create based on the provided {@link location}.\n *\n * @param location - A {@link https://github.com/MetaMask/SIPs/blob/main/SIPS/sip-8.md SIP-8} uri.\n * @param opts - NPM options and feature flags.\n * @returns SnapLocation based on url.\n */\nexport function detectSnapLocation(\n location: string | URL,\n opts?: DetectSnapLocationOptions,\n): SnapLocation {\n const allowHttp = opts?.allowHttp ?? false;\n const allowLocal = opts?.allowLocal ?? false;\n const root = new URL(location);\n switch (root.protocol) {\n case 'npm:':\n return new NpmLocation(root, opts);\n case 'local:':\n assert(allowLocal, new TypeError('Fetching local snaps is disabled.'));\n return new LocalLocation(root, opts);\n case 'http:':\n case 'https:':\n assert(\n allowHttp,\n new TypeError('Fetching snaps through http/https is disabled.'),\n );\n return new HttpLocation(root, opts);\n default:\n throw new TypeError(\n `Unrecognized \"${root.protocol}\" snap location protocol.`,\n );\n }\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import { SnapManifest, VirtualFile } from '@metamask/snaps-utils';
2
+ import { SemVerRange } from '@metamask/utils';
3
+ import { DetectSnapLocationOptions, SnapLocation } from './location';
4
+ export interface NpmOptions {
5
+ /**
6
+ * @default DEFAULT_REQUESTED_SNAP_VERSION
7
+ */
8
+ versionRange?: SemVerRange;
9
+ /**
10
+ * Whether to allow custom NPM registries outside of {@link DEFAULT_NPM_REGISTRY}.
11
+ *
12
+ * @default false
13
+ */
14
+ allowCustomRegistries?: boolean;
15
+ }
16
+ export declare class NpmLocation implements SnapLocation {
17
+ #private;
18
+ private readonly meta;
19
+ private validatedManifest?;
20
+ private files?;
21
+ constructor(url: URL, opts?: DetectSnapLocationOptions);
22
+ manifest(): Promise<VirtualFile<SnapManifest>>;
23
+ fetch(path: string): Promise<VirtualFile>;
24
+ get packageName(): string;
25
+ get version(): string;
26
+ get registry(): URL;
27
+ get versionRange(): SemVerRange;
28
+ }