@metamask/snaps-utils 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 (268) hide show
  1. package/CHANGELOG.md +222 -11
  2. package/dist/{esm/array.js → array.js} +7 -3
  3. package/dist/array.js.map +1 -0
  4. package/dist/{types/caveats.d.ts → caveats.d.ts} +4 -0
  5. package/dist/caveats.js +35 -0
  6. package/dist/caveats.js.map +1 -0
  7. package/dist/checksum.js +42 -0
  8. package/dist/checksum.js.map +1 -0
  9. package/dist/{types/cronjob.d.ts → cronjob.d.ts} +1 -1
  10. package/dist/cronjob.js +71 -0
  11. package/dist/cronjob.js.map +1 -0
  12. package/dist/deep-clone.js +9 -0
  13. package/dist/deep-clone.js.map +1 -0
  14. package/dist/{esm/default-endowments.js → default-endowments.js} +6 -3
  15. package/dist/default-endowments.js.map +1 -0
  16. package/dist/entropy.js +8 -0
  17. package/dist/entropy.js.map +1 -0
  18. package/dist/{cjs/eval-worker.js → eval-worker.js} +21 -22
  19. package/dist/eval-worker.js.map +1 -0
  20. package/dist/{types/eval.d.ts → eval.d.ts} +1 -9
  21. package/dist/eval.js +27 -0
  22. package/dist/eval.js.map +1 -0
  23. package/dist/{types/fs.d.ts → fs.d.ts} +2 -2
  24. package/dist/{esm/fs.js → fs.js} +56 -33
  25. package/dist/fs.js.map +1 -0
  26. package/dist/handlers.d.ts +105 -0
  27. package/dist/handlers.js +3 -0
  28. package/dist/handlers.js.map +1 -0
  29. package/dist/{types/iframe.d.ts → iframe.d.ts} +2 -3
  30. package/dist/{esm/iframe.js → iframe.js} +18 -16
  31. package/dist/iframe.js.map +1 -0
  32. package/dist/iframe.test.browser.js +15 -0
  33. package/dist/iframe.test.browser.js.map +1 -0
  34. package/dist/{types/index.browser.d.ts → index.browser.d.ts} +1 -5
  35. package/dist/index.browser.js +37 -0
  36. package/dist/index.browser.js.map +1 -0
  37. package/dist/{types/index.d.ts → index.d.ts} +1 -5
  38. package/dist/index.executionenv.js +22 -0
  39. package/dist/index.executionenv.js.map +1 -0
  40. package/dist/index.js +42 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/{types/json-rpc.d.ts → json-rpc.d.ts} +2 -2
  43. package/dist/json-rpc.js +46 -0
  44. package/dist/json-rpc.js.map +1 -0
  45. package/dist/json.d.ts +9 -0
  46. package/dist/json.js +18 -0
  47. package/dist/json.js.map +1 -0
  48. package/dist/{esm/logging.js → logging.js} +14 -6
  49. package/dist/logging.js.map +1 -0
  50. package/dist/manifest/index.browser.js +18 -0
  51. package/dist/manifest/index.browser.js.map +1 -0
  52. package/dist/manifest/index.js +19 -0
  53. package/dist/manifest/index.js.map +1 -0
  54. package/dist/{types/manifest → manifest}/manifest.d.ts +4 -6
  55. package/dist/{esm/manifest → manifest}/manifest.js +115 -101
  56. package/dist/manifest/manifest.js.map +1 -0
  57. package/dist/{types/manifest → manifest}/validation.d.ts +76 -34
  58. package/dist/manifest/validation.js +141 -0
  59. package/dist/manifest/validation.js.map +1 -0
  60. package/dist/{esm/mock.js → mock.js} +40 -42
  61. package/dist/mock.js.map +1 -0
  62. package/dist/namespace.d.ts +275 -0
  63. package/dist/namespace.js +225 -0
  64. package/dist/namespace.js.map +1 -0
  65. package/dist/notification.d.ts +66 -0
  66. package/dist/notification.js +58 -0
  67. package/dist/notification.js.map +1 -0
  68. package/dist/{types/npm.d.ts → npm.d.ts} +3 -2
  69. package/dist/npm.js +74 -0
  70. package/dist/npm.js.map +1 -0
  71. package/dist/path.js +21 -0
  72. package/dist/path.js.map +1 -0
  73. package/dist/{esm/post-process.js → post-process.js} +99 -110
  74. package/dist/post-process.js.map +1 -0
  75. package/dist/{types/snaps.d.ts → snaps.d.ts} +9 -17
  76. package/dist/snaps.js +202 -0
  77. package/dist/snaps.js.map +1 -0
  78. package/dist/{types/types.d.ts → types.d.ts} +22 -15
  79. package/dist/types.js +103 -0
  80. package/dist/types.js.map +1 -0
  81. package/dist/{types/versions.d.ts → versions.d.ts} +1 -1
  82. package/dist/{esm/versions.js → versions.js} +18 -15
  83. package/dist/versions.js.map +1 -0
  84. package/dist/{esm/virtual-file → virtual-file}/VirtualFile.js +33 -47
  85. package/dist/virtual-file/VirtualFile.js.map +1 -0
  86. package/dist/virtual-file/index.browser.js +18 -0
  87. package/dist/virtual-file/index.browser.js.map +1 -0
  88. package/dist/virtual-file/index.js +19 -0
  89. package/dist/virtual-file/index.js.map +1 -0
  90. package/dist/virtual-file/toVirtualFile.js +30 -0
  91. package/dist/virtual-file/toVirtualFile.js.map +1 -0
  92. package/package.json +40 -59
  93. package/dist/cjs/array.js +0 -23
  94. package/dist/cjs/array.js.map +0 -1
  95. package/dist/cjs/caveats.js +0 -33
  96. package/dist/cjs/caveats.js.map +0 -1
  97. package/dist/cjs/checksum.js +0 -38
  98. package/dist/cjs/checksum.js.map +0 -1
  99. package/dist/cjs/cronjob.js +0 -84
  100. package/dist/cjs/cronjob.js.map +0 -1
  101. package/dist/cjs/deep-clone.js +0 -22
  102. package/dist/cjs/deep-clone.js.map +0 -1
  103. package/dist/cjs/default-endowments.js +0 -49
  104. package/dist/cjs/default-endowments.js.map +0 -1
  105. package/dist/cjs/entropy.js +0 -23
  106. package/dist/cjs/entropy.js.map +0 -1
  107. package/dist/cjs/enum.js +0 -16
  108. package/dist/cjs/enum.js.map +0 -1
  109. package/dist/cjs/errors.js +0 -19
  110. package/dist/cjs/errors.js.map +0 -1
  111. package/dist/cjs/eval-worker.js.map +0 -1
  112. package/dist/cjs/eval.js +0 -77
  113. package/dist/cjs/eval.js.map +0 -1
  114. package/dist/cjs/fs.js +0 -126
  115. package/dist/cjs/fs.js.map +0 -1
  116. package/dist/cjs/handlers.js +0 -65
  117. package/dist/cjs/handlers.js.map +0 -1
  118. package/dist/cjs/icon.js +0 -37
  119. package/dist/cjs/icon.js.map +0 -1
  120. package/dist/cjs/iframe.js +0 -59
  121. package/dist/cjs/iframe.js.map +0 -1
  122. package/dist/cjs/index.browser.js +0 -43
  123. package/dist/cjs/index.browser.js.map +0 -1
  124. package/dist/cjs/index.executionenv.js +0 -24
  125. package/dist/cjs/index.executionenv.js.map +0 -1
  126. package/dist/cjs/index.js +0 -48
  127. package/dist/cjs/index.js.map +0 -1
  128. package/dist/cjs/json-rpc.js +0 -46
  129. package/dist/cjs/json-rpc.js.map +0 -1
  130. package/dist/cjs/json.js +0 -16
  131. package/dist/cjs/json.js.map +0 -1
  132. package/dist/cjs/logging.js +0 -40
  133. package/dist/cjs/logging.js.map +0 -1
  134. package/dist/cjs/manifest/index.browser.js +0 -20
  135. package/dist/cjs/manifest/index.browser.js.map +0 -1
  136. package/dist/cjs/manifest/index.js +0 -21
  137. package/dist/cjs/manifest/index.js.map +0 -1
  138. package/dist/cjs/manifest/manifest.js +0 -239
  139. package/dist/cjs/manifest/manifest.js.map +0 -1
  140. package/dist/cjs/manifest/validation.js +0 -183
  141. package/dist/cjs/manifest/validation.js.map +0 -1
  142. package/dist/cjs/mock.js +0 -128
  143. package/dist/cjs/mock.js.map +0 -1
  144. package/dist/cjs/namespace.js +0 -124
  145. package/dist/cjs/namespace.js.map +0 -1
  146. package/dist/cjs/npm.js +0 -81
  147. package/dist/cjs/npm.js.map +0 -1
  148. package/dist/cjs/path.js +0 -21
  149. package/dist/cjs/path.js.map +0 -1
  150. package/dist/cjs/post-process.js +0 -328
  151. package/dist/cjs/post-process.js.map +0 -1
  152. package/dist/cjs/snaps.js +0 -230
  153. package/dist/cjs/snaps.js.map +0 -1
  154. package/dist/cjs/strings.js +0 -21
  155. package/dist/cjs/strings.js.map +0 -1
  156. package/dist/cjs/structs.js +0 -163
  157. package/dist/cjs/structs.js.map +0 -1
  158. package/dist/cjs/types.js +0 -109
  159. package/dist/cjs/types.js.map +0 -1
  160. package/dist/cjs/validation.js +0 -22
  161. package/dist/cjs/validation.js.map +0 -1
  162. package/dist/cjs/versions.js +0 -47
  163. package/dist/cjs/versions.js.map +0 -1
  164. package/dist/cjs/virtual-file/VirtualFile.js +0 -85
  165. package/dist/cjs/virtual-file/VirtualFile.js.map +0 -1
  166. package/dist/cjs/virtual-file/index.browser.js +0 -20
  167. package/dist/cjs/virtual-file/index.browser.js.map +0 -1
  168. package/dist/cjs/virtual-file/index.js +0 -21
  169. package/dist/cjs/virtual-file/index.js.map +0 -1
  170. package/dist/cjs/virtual-file/toVirtualFile.js +0 -33
  171. package/dist/cjs/virtual-file/toVirtualFile.js.map +0 -1
  172. package/dist/esm/array.js.map +0 -1
  173. package/dist/esm/caveats.js +0 -23
  174. package/dist/esm/caveats.js.map +0 -1
  175. package/dist/esm/checksum.js +0 -36
  176. package/dist/esm/checksum.js.map +0 -1
  177. package/dist/esm/cronjob.js +0 -66
  178. package/dist/esm/cronjob.js.map +0 -1
  179. package/dist/esm/deep-clone.js +0 -7
  180. package/dist/esm/deep-clone.js.map +0 -1
  181. package/dist/esm/default-endowments.js.map +0 -1
  182. package/dist/esm/entropy.js +0 -6
  183. package/dist/esm/entropy.js.map +0 -1
  184. package/dist/esm/enum.js +0 -12
  185. package/dist/esm/enum.js.map +0 -1
  186. package/dist/esm/errors.js +0 -17
  187. package/dist/esm/errors.js.map +0 -1
  188. package/dist/esm/eval-worker.js +0 -47
  189. package/dist/esm/eval-worker.js.map +0 -1
  190. package/dist/esm/eval.js +0 -65
  191. package/dist/esm/eval.js.map +0 -1
  192. package/dist/esm/fs.js.map +0 -1
  193. package/dist/esm/handlers.js +0 -47
  194. package/dist/esm/handlers.js.map +0 -1
  195. package/dist/esm/icon.js +0 -11
  196. package/dist/esm/icon.js.map +0 -1
  197. package/dist/esm/iframe.js.map +0 -1
  198. package/dist/esm/index.browser.js +0 -26
  199. package/dist/esm/index.browser.js.map +0 -1
  200. package/dist/esm/index.executionenv.js +0 -7
  201. package/dist/esm/index.executionenv.js.map +0 -1
  202. package/dist/esm/index.js +0 -31
  203. package/dist/esm/index.js.map +0 -1
  204. package/dist/esm/json-rpc.js +0 -39
  205. package/dist/esm/json-rpc.js.map +0 -1
  206. package/dist/esm/json.js +0 -17
  207. package/dist/esm/json.js.map +0 -1
  208. package/dist/esm/logging.js.map +0 -1
  209. package/dist/esm/manifest/index.browser.js +0 -3
  210. package/dist/esm/manifest/index.browser.js.map +0 -1
  211. package/dist/esm/manifest/index.js +0 -4
  212. package/dist/esm/manifest/index.js.map +0 -1
  213. package/dist/esm/manifest/manifest.js.map +0 -1
  214. package/dist/esm/manifest/validation.js +0 -152
  215. package/dist/esm/manifest/validation.js.map +0 -1
  216. package/dist/esm/mock.js.map +0 -1
  217. package/dist/esm/namespace.js +0 -110
  218. package/dist/esm/namespace.js.map +0 -1
  219. package/dist/esm/npm.js +0 -70
  220. package/dist/esm/npm.js.map +0 -1
  221. package/dist/esm/path.js +0 -17
  222. package/dist/esm/path.js.map +0 -1
  223. package/dist/esm/post-process.js.map +0 -1
  224. package/dist/esm/snaps.js +0 -215
  225. package/dist/esm/snaps.js.map +0 -1
  226. package/dist/esm/strings.js +0 -11
  227. package/dist/esm/strings.js.map +0 -1
  228. package/dist/esm/structs.js +0 -230
  229. package/dist/esm/structs.js.map +0 -1
  230. package/dist/esm/types.js +0 -80
  231. package/dist/esm/types.js.map +0 -1
  232. package/dist/esm/validation.js +0 -17
  233. package/dist/esm/validation.js.map +0 -1
  234. package/dist/esm/versions.js.map +0 -1
  235. package/dist/esm/virtual-file/VirtualFile.js.map +0 -1
  236. package/dist/esm/virtual-file/index.browser.js +0 -3
  237. package/dist/esm/virtual-file/index.browser.js.map +0 -1
  238. package/dist/esm/virtual-file/index.js +0 -4
  239. package/dist/esm/virtual-file/index.js.map +0 -1
  240. package/dist/esm/virtual-file/toVirtualFile.js +0 -26
  241. package/dist/esm/virtual-file/toVirtualFile.js.map +0 -1
  242. package/dist/types/enum.d.ts +0 -30
  243. package/dist/types/errors.d.ts +0 -10
  244. package/dist/types/handlers.d.ts +0 -144
  245. package/dist/types/icon.d.ts +0 -4
  246. package/dist/types/json.d.ts +0 -13
  247. package/dist/types/namespace.d.ts +0 -124
  248. package/dist/types/strings.d.ts +0 -8
  249. package/dist/types/structs.d.ts +0 -158
  250. package/dist/types/validation.d.ts +0 -8
  251. /package/dist/{types/array.d.ts → array.d.ts} +0 -0
  252. /package/dist/{types/checksum.d.ts → checksum.d.ts} +0 -0
  253. /package/dist/{types/deep-clone.d.ts → deep-clone.d.ts} +0 -0
  254. /package/dist/{types/default-endowments.d.ts → default-endowments.d.ts} +0 -0
  255. /package/dist/{types/entropy.d.ts → entropy.d.ts} +0 -0
  256. /package/dist/{types/eval-worker.d.ts → eval-worker.d.ts} +0 -0
  257. /package/dist/{types/iframe.test.browser.d.ts → iframe.test.browser.d.ts} +0 -0
  258. /package/dist/{types/index.executionenv.d.ts → index.executionenv.d.ts} +0 -0
  259. /package/dist/{types/logging.d.ts → logging.d.ts} +0 -0
  260. /package/dist/{types/manifest → manifest}/index.browser.d.ts +0 -0
  261. /package/dist/{types/manifest → manifest}/index.d.ts +0 -0
  262. /package/dist/{types/mock.d.ts → mock.d.ts} +0 -0
  263. /package/dist/{types/path.d.ts → path.d.ts} +0 -0
  264. /package/dist/{types/post-process.d.ts → post-process.d.ts} +0 -0
  265. /package/dist/{types/virtual-file → virtual-file}/VirtualFile.d.ts +0 -0
  266. /package/dist/{types/virtual-file → virtual-file}/index.browser.d.ts +0 -0
  267. /package/dist/{types/virtual-file → virtual-file}/index.d.ts +0 -0
  268. /package/dist/{types/virtual-file → virtual-file}/toVirtualFile.d.ts +0 -0
package/dist/esm/types.js DELETED
@@ -1,80 +0,0 @@
1
- import { assertStruct, VersionStruct } from '@metamask/utils';
2
- import { instance, is, object, optional, pattern, refine, size, string, type, union, assert as assertSuperstruct } from 'superstruct';
3
- import { HandlerType } from './handlers';
4
- export var NpmSnapFileNames;
5
- (function(NpmSnapFileNames) {
6
- NpmSnapFileNames["PackageJson"] = 'package.json';
7
- NpmSnapFileNames["Manifest"] = 'snap.manifest.json';
8
- })(NpmSnapFileNames || (NpmSnapFileNames = {}));
9
- export const NameStruct = size(pattern(string(), /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u), 1, 214);
10
- // Note we use `type` instead of `object` here, because the latter does not
11
- // allow unknown keys.
12
- export const NpmSnapPackageJsonStruct = type({
13
- version: VersionStruct,
14
- name: NameStruct,
15
- main: optional(size(string(), 1, Infinity)),
16
- repository: optional(object({
17
- type: size(string(), 1, Infinity),
18
- url: size(string(), 1, Infinity)
19
- }))
20
- });
21
- /**
22
- * Check if the given value is a valid {@link NpmSnapPackageJson} object.
23
- *
24
- * @param value - The value to check.
25
- * @returns Whether the value is a valid {@link NpmSnapPackageJson} object.
26
- */ export function isNpmSnapPackageJson(value) {
27
- return is(value, NpmSnapPackageJsonStruct);
28
- }
29
- /**
30
- * Asserts that the given value is a valid {@link NpmSnapPackageJson} object.
31
- *
32
- * @param value - The value to check.
33
- * @throws If the value is not a valid {@link NpmSnapPackageJson} object.
34
- */ export function assertIsNpmSnapPackageJson(value) {
35
- assertStruct(value, NpmSnapPackageJsonStruct, `"${NpmSnapFileNames.PackageJson}" is invalid`);
36
- }
37
- export var SnapIdPrefixes;
38
- (function(SnapIdPrefixes) {
39
- SnapIdPrefixes["npm"] = 'npm:';
40
- SnapIdPrefixes["local"] = 'local:';
41
- })(SnapIdPrefixes || (SnapIdPrefixes = {}));
42
- export var SnapValidationFailureReason;
43
- (function(SnapValidationFailureReason) {
44
- SnapValidationFailureReason["NameMismatch"] = '"name" field mismatch';
45
- SnapValidationFailureReason["VersionMismatch"] = '"version" field mismatch';
46
- SnapValidationFailureReason["RepositoryMismatch"] = '"repository" field mismatch';
47
- SnapValidationFailureReason["ShasumMismatch"] = '"shasum" field mismatch';
48
- })(SnapValidationFailureReason || (SnapValidationFailureReason = {}));
49
- export var SNAP_STREAM_NAMES;
50
- (function(SNAP_STREAM_NAMES) {
51
- SNAP_STREAM_NAMES["JSON_RPC"] = 'jsonRpc';
52
- SNAP_STREAM_NAMES["COMMAND"] = 'command';
53
- })(SNAP_STREAM_NAMES || (SNAP_STREAM_NAMES = {}));
54
- /* eslint-enable @typescript-eslint/naming-convention */ export const SNAP_EXPORT_NAMES = Object.values(HandlerType);
55
- export const uri = (opts = {})=>refine(union([
56
- string(),
57
- instance(URL)
58
- ]), 'uri', (value)=>{
59
- try {
60
- const url = new URL(value);
61
- const UrlStruct = type(opts);
62
- assertSuperstruct(url, UrlStruct);
63
- return true;
64
- } catch {
65
- return `Expected URL, got "${value.toString()}".`;
66
- }
67
- });
68
- /**
69
- * Returns whether a given value is a valid URL.
70
- *
71
- * @param url - The value to check.
72
- * @param opts - Optional constraints for url checking.
73
- * @returns Whether `url` is valid URL or not.
74
- */ export function isValidUrl(url, opts = {}) {
75
- return is(url, uri(opts));
76
- }
77
- // redefining here to avoid circular dependency
78
- export const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';
79
-
80
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\nimport { assertStruct, VersionStruct } from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n instance,\n is,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n type,\n union,\n assert as assertSuperstruct,\n} from 'superstruct';\n\nimport type { SnapCaveatType } from './caveats';\nimport type { SnapFunctionExports } from './handlers';\nimport { HandlerType } from './handlers';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport enum NpmSnapFileNames {\n PackageJson = 'package.json',\n Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n pattern(\n string(),\n /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n ),\n 1,\n 214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n version: VersionStruct,\n name: NameStruct,\n main: optional(size(string(), 1, Infinity)),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n Record<string, any>;\n\n/**\n * Check if the given value is a valid {@link NpmSnapPackageJson} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link NpmSnapPackageJson} object.\n */\nexport function isNpmSnapPackageJson(\n value: unknown,\n): value is NpmSnapPackageJson {\n return is(value, NpmSnapPackageJsonStruct);\n}\n\n/**\n * Asserts that the given value is a valid {@link NpmSnapPackageJson} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link NpmSnapPackageJson} object.\n */\nexport function assertIsNpmSnapPackageJson(\n value: unknown,\n): asserts value is NpmSnapPackageJson {\n assertStruct(\n value,\n NpmSnapPackageJsonStruct,\n `\"${NpmSnapFileNames.PackageJson}\" is invalid`,\n );\n}\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n manifest?: VirtualFile<Json>;\n packageJson?: VirtualFile<Json>;\n sourceCode?: VirtualFile;\n svgIcon?: VirtualFile;\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n manifest: VirtualFile<SnapManifest>;\n packageJson: VirtualFile<NpmSnapPackageJson>;\n sourceCode: VirtualFile;\n svgIcon?: VirtualFile;\n};\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n npm = 'npm:',\n local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapId = string;\n\n/**\n * Snap validation failure reason codes that are programmatically fixable\n * if validation occurs during development.\n */\nexport enum SnapValidationFailureReason {\n NameMismatch = '\"name\" field mismatch',\n VersionMismatch = '\"version\" field mismatch',\n RepositoryMismatch = '\"repository\" field mismatch',\n ShasumMismatch = '\"shasum\" field mismatch',\n}\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n JSON_RPC = 'jsonRpc',\n COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const SNAP_EXPORT_NAMES = Object.values(HandlerType);\n\nexport type SnapRpcHookArgs = {\n origin: string;\n handler: HandlerType;\n request: Record<string, unknown>;\n};\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\nexport type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;\n\ntype UriOptions<Type extends string> = {\n protocol?: Struct<Type>;\n hash?: Struct<Type>;\n port?: Struct<Type>;\n hostname?: Struct<Type>;\n pathname?: Struct<Type>;\n search?: Struct<Type>;\n};\n\nexport const uri = (opts: UriOptions<any> = {}) =>\n refine(union([string(), instance(URL)]), 'uri', (value) => {\n try {\n const url = new URL(value);\n\n const UrlStruct = type(opts);\n assertSuperstruct(url, UrlStruct);\n return true;\n } catch {\n return `Expected URL, got \"${value.toString()}\".`;\n }\n });\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n url: unknown,\n opts: UriOptions<any> = {},\n): url is string | URL {\n return is(url, uri(opts));\n}\n\n// redefining here to avoid circular dependency\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\nexport type SnapsPermissionRequest = {\n [WALLET_SNAP_PERMISSION_KEY]: {\n caveats: [\n {\n type: SnapCaveatType.SnapIds;\n value: Record<string, Json>;\n },\n ];\n };\n};\n"],"names":["assertStruct","VersionStruct","instance","is","object","optional","pattern","refine","size","string","type","union","assert","assertSuperstruct","HandlerType","NpmSnapFileNames","PackageJson","Manifest","NameStruct","NpmSnapPackageJsonStruct","version","name","main","Infinity","repository","url","isNpmSnapPackageJson","value","assertIsNpmSnapPackageJson","SnapIdPrefixes","npm","local","SnapValidationFailureReason","NameMismatch","VersionMismatch","RepositoryMismatch","ShasumMismatch","SNAP_STREAM_NAMES","JSON_RPC","COMMAND","SNAP_EXPORT_NAMES","Object","values","uri","opts","URL","UrlStruct","toString","isValidUrl","WALLET_SNAP_PERMISSION_KEY"],"mappings":"AACA,SAASA,YAAY,EAAEC,aAAa,QAAQ,kBAAkB;AAE9D,SACEC,QAAQ,EACRC,EAAE,EACFC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACPC,MAAM,EACNC,IAAI,EACJC,MAAM,EACNC,IAAI,EACJC,KAAK,EACLC,UAAUC,iBAAiB,QACtB,cAAc;AAIrB,SAASC,WAAW,QAAQ,aAAa;WAIlC;UAAKC,gBAAgB;IAAhBA,iBACVC,iBAAc;IADJD,iBAEVE,cAAW;GAFDF,qBAAAA;AAKZ,OAAO,MAAMG,aAAaV,KACxBF,QACEG,UACA,gEAEF,GACA,KACA;AAEF,2EAA2E;AAC3E,sBAAsB;AACtB,OAAO,MAAMU,2BAA2BT,KAAK;IAC3CU,SAASnB;IACToB,MAAMH;IACNI,MAAMjB,SAASG,KAAKC,UAAU,GAAGc;IACjCC,YAAYnB,SACVD,OAAO;QACLM,MAAMF,KAAKC,UAAU,GAAGc;QACxBE,KAAKjB,KAAKC,UAAU,GAAGc;IACzB;AAEJ,GAAG;AAKH;;;;;CAKC,GACD,OAAO,SAASG,qBACdC,KAAc;IAEd,OAAOxB,GAAGwB,OAAOR;AACnB;AAEA;;;;;CAKC,GACD,OAAO,SAASS,2BACdD,KAAc;IAEd3B,aACE2B,OACAR,0BACA,CAAC,CAAC,EAAEJ,iBAAiBC,WAAW,CAAC,YAAY,CAAC;AAElD;WA2BO;UAAKa,cAAc;IAAdA,eACVC,SAAM;IADID,eAEVE,WAAQ;GAFEF,mBAAAA;WAYL;UAAKG,2BAA2B;IAA3BA,4BACVC,kBAAe;IADLD,4BAEVE,qBAAkB;IAFRF,4BAGVG,wBAAqB;IAHXH,4BAIVI,oBAAiB;GAJPJ,gCAAAA;WAQL;UAAKK,iBAAiB;IAAjBA,kBACVC,cAAW;IADDD,kBAEVE,aAAU;GAFAF,sBAAAA;AAIZ,sDAAsD,GAEtD,OAAO,MAAMG,oBAAoBC,OAAOC,MAAM,CAAC5B,aAAa;AA0B5D,OAAO,MAAM6B,MAAM,CAACC,OAAwB,CAAC,CAAC,GAC5CrC,OAAOI,MAAM;QAACF;QAAUP,SAAS2C;KAAK,GAAG,OAAO,CAAClB;QAC/C,IAAI;YACF,MAAMF,MAAM,IAAIoB,IAAIlB;YAEpB,MAAMmB,YAAYpC,KAAKkC;YACvB/B,kBAAkBY,KAAKqB;YACvB,OAAO;QACT,EAAE,OAAM;YACN,OAAO,CAAC,mBAAmB,EAAEnB,MAAMoB,QAAQ,GAAG,EAAE,CAAC;QACnD;IACF,GAAG;AAEL;;;;;;CAMC,GACD,OAAO,SAASC,WACdvB,GAAY,EACZmB,OAAwB,CAAC,CAAC;IAE1B,OAAOzC,GAAGsB,KAAKkB,IAAIC;AACrB;AAEA,+CAA+C;AAC/C,OAAO,MAAMK,6BAA6B,cAAc"}
@@ -1,17 +0,0 @@
1
- import { assertIsSnapIcon } from './icon';
2
- import { assertIsSnapManifest } from './manifest/validation';
3
- import { validateSnapShasum } from './snaps';
4
- /**
5
- * Validates the files contained in a fetched snap.
6
- *
7
- * @param files - All potentially included files in a fetched snap.
8
- * @throws If any of the files are considered invalid.
9
- */ export function validateFetchedSnap(files) {
10
- assertIsSnapManifest(files.manifest.result);
11
- validateSnapShasum(files);
12
- if (files.svgIcon) {
13
- assertIsSnapIcon(files.svgIcon);
14
- }
15
- }
16
-
17
- //# sourceMappingURL=validation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/validation.ts"],"sourcesContent":["import { assertIsSnapIcon } from './icon';\nimport { assertIsSnapManifest } from './manifest/validation';\nimport { validateSnapShasum } from './snaps';\nimport type { SnapFiles } from './types';\n\n/**\n * Validates the files contained in a fetched snap.\n *\n * @param files - All potentially included files in a fetched snap.\n * @throws If any of the files are considered invalid.\n */\nexport function validateFetchedSnap(\n files: Pick<SnapFiles, 'manifest' | 'sourceCode' | 'svgIcon'>,\n): void {\n assertIsSnapManifest(files.manifest.result);\n validateSnapShasum(files);\n\n if (files.svgIcon) {\n assertIsSnapIcon(files.svgIcon);\n }\n}\n"],"names":["assertIsSnapIcon","assertIsSnapManifest","validateSnapShasum","validateFetchedSnap","files","manifest","result","svgIcon"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,SAAS;AAC1C,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,kBAAkB,QAAQ,UAAU;AAG7C;;;;;CAKC,GACD,OAAO,SAASC,oBACdC,KAA6D;IAE7DH,qBAAqBG,MAAMC,QAAQ,CAACC,MAAM;IAC1CJ,mBAAmBE;IAEnB,IAAIA,MAAMG,OAAO,EAAE;QACjBP,iBAAiBI,MAAMG,OAAO;IAChC;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/versions.ts"],"sourcesContent":["import type { Json, SemVerVersion, SemVerRange } from '@metamask/utils';\nimport { VersionRangeStruct } from '@metamask/utils';\nimport { maxSatisfying as maxSatisfyingSemver } from 'semver';\nimport { validate } from 'superstruct';\n\nexport const DEFAULT_REQUESTED_SNAP_VERSION = '*' as SemVerRange;\n\n/**\n * Return the highest version in the list that satisfies the range, or `null` if\n * none of them do. For the satisfaction check, pre-release versions will only\n * be checked if no satisfactory non-prerelease version is found first.\n *\n * @param versions - The list of version to check.\n * @param versionRange - The SemVer version range to check against.\n * @returns The highest version in the list that satisfies the range,\n * or `null` if none of them do.\n */\nexport function getTargetVersion(\n versions: SemVerVersion[],\n versionRange: SemVerRange,\n): SemVerVersion | null {\n const maxSatisfyingNonPreRelease = maxSatisfyingSemver(\n versions,\n versionRange,\n );\n\n // By default don't use pre-release versions\n if (maxSatisfyingNonPreRelease) {\n return maxSatisfyingNonPreRelease;\n }\n\n // If no satisfying release version is found by default, try pre-release versions\n return maxSatisfyingSemver(versions, versionRange, {\n includePrerelease: true,\n });\n}\n\n/**\n * Parse a version received by some subject attempting to access a snap.\n *\n * @param version - The received version value.\n * @returns `*` if the version is `undefined` or `latest\", otherwise returns\n * the specified version.\n */\nexport function resolveVersionRange(\n version?: Json,\n): [error: undefined, range: SemVerRange] | [error: Error, range: undefined] {\n if (version === undefined || version === 'latest') {\n return [undefined, DEFAULT_REQUESTED_SNAP_VERSION];\n }\n return validate(version, VersionRangeStruct);\n}\n"],"names":["VersionRangeStruct","maxSatisfying","maxSatisfyingSemver","validate","DEFAULT_REQUESTED_SNAP_VERSION","getTargetVersion","versions","versionRange","maxSatisfyingNonPreRelease","includePrerelease","resolveVersionRange","version","undefined"],"mappings":"AACA,SAASA,kBAAkB,QAAQ,kBAAkB;AACrD,SAASC,iBAAiBC,mBAAmB,QAAQ,SAAS;AAC9D,SAASC,QAAQ,QAAQ,cAAc;AAEvC,OAAO,MAAMC,iCAAiC,IAAmB;AAEjE;;;;;;;;;CASC,GACD,OAAO,SAASC,iBACdC,QAAyB,EACzBC,YAAyB;IAEzB,MAAMC,6BAA6BN,oBACjCI,UACAC;IAGF,4CAA4C;IAC5C,IAAIC,4BAA4B;QAC9B,OAAOA;IACT;IAEA,iFAAiF;IACjF,OAAON,oBAAoBI,UAAUC,cAAc;QACjDE,mBAAmB;IACrB;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,oBACdC,OAAc;IAEd,IAAIA,YAAYC,aAAaD,YAAY,UAAU;QACjD,OAAO;YAACC;YAAWR;SAA+B;IACpD;IACA,OAAOD,SAASQ,SAASX;AAC3B"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/virtual-file/VirtualFile.ts"],"sourcesContent":["// TODO(ritave): Move into separate package @metamask/vfile / @metamask/utils + @metamask/to-vfile when passes code review\n// TODO(ritave): Streaming vfile contents similar to vinyl maybe?\n// TODO(ritave): Move fixing manifest in cli and bundler plugins to write messages to vfile\n// similar to unified instead of throwing \"ProgrammaticallyFixableErrors\".\n//\n// Using https://github.com/vfile/vfile would be helpful, but they only support ESM and we need to support CommonJS.\n// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because\n// we're calculating checksums based on original path.\nimport { assert } from '@metamask/utils';\n\nimport { deepClone } from '../deep-clone';\n\n/**\n * This map registers the type of the {@link VirtualFile.data} key of a {@link VirtualFile}.\n *\n * This type can be augmented to register custom `data` types.\n *\n * @example\n * declare module '@metamask/snaps-utils' {\n * interface DataMap {\n * // `file.data.name` is typed as `string`\n * name: string\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-interface\nexport interface DataMap {}\n\nexport type Value = string | Uint8Array;\nexport type Compatible<Result = unknown> =\n | string\n | Uint8Array\n | Options<Result>;\nexport type Data = Record<string, unknown> & Partial<DataMap>;\nexport type Options<Result = unknown> = {\n value: Value;\n path?: string;\n data?: Data;\n result?: Result;\n};\n\nexport class VirtualFile<Result = unknown> {\n constructor(value?: Compatible<Result>) {\n let options: Options | undefined;\n if (typeof value === 'string' || value instanceof Uint8Array) {\n options = { value };\n } else {\n options = value;\n }\n\n this.value = options?.value ?? '';\n // This situations happens when there's no .result used,\n // we expect the file to have default generic in that situation:\n // VirtualFile<unknown> which will handle undefined properly\n //\n // While not 100% type safe, it'll be way less frustrating to work with.\n // The alternative would be to have VirtualFile.result be Result | undefined\n // and that would result in needing to branch out and check in all situations.\n //\n // In short, optimizing for most common use case.\n this.result = options?.result ?? (undefined as any);\n this.data = options?.data ?? {};\n this.path = options?.path ?? '/';\n }\n\n value: Value;\n\n result: Result;\n\n data: Data;\n\n path: string;\n\n toString(encoding?: string) {\n if (typeof this.value === 'string') {\n assert(encoding === undefined, 'Tried to encode string.');\n return this.value;\n }\n const decoder = new TextDecoder(encoding);\n return decoder.decode(this.value);\n }\n\n clone() {\n const vfile = new VirtualFile<Result>();\n if (typeof this.value === 'string') {\n vfile.value = this.value;\n } else {\n // deep-clone doesn't clone Buffer properly, even if it's a sub-class of Uint8Array\n vfile.value = this.value.slice(0);\n }\n vfile.result = deepClone(this.result);\n vfile.data = deepClone(this.data);\n vfile.path = this.path;\n return vfile;\n }\n}\n"],"names":["assert","deepClone","VirtualFile","toString","encoding","value","undefined","decoder","TextDecoder","decode","clone","vfile","slice","result","data","path","constructor","options","Uint8Array"],"mappings":"AAAA,0HAA0H;AAC1H,iEAAiE;AACjE,2FAA2F;AAC3F,wFAAwF;AACxF,EAAE;AACF,oHAAoH;AACpH,qGAAqG;AACrG,sDAAsD;;;;;;;;;;;;;;AACtD,SAASA,MAAM,QAAQ,kBAAkB;AAEzC,SAASC,SAAS,QAAQ,gBAAgB;AA+B1C,OAAO,MAAMC;IAgCXC,SAASC,QAAiB,EAAE;QAC1B,IAAI,OAAO,IAAI,CAACC,KAAK,KAAK,UAAU;YAClCL,OAAOI,aAAaE,WAAW;YAC/B,OAAO,IAAI,CAACD,KAAK;QACnB;QACA,MAAME,UAAU,IAAIC,YAAYJ;QAChC,OAAOG,QAAQE,MAAM,CAAC,IAAI,CAACJ,KAAK;IAClC;IAEAK,QAAQ;QACN,MAAMC,QAAQ,IAAIT;QAClB,IAAI,OAAO,IAAI,CAACG,KAAK,KAAK,UAAU;YAClCM,MAAMN,KAAK,GAAG,IAAI,CAACA,KAAK;QAC1B,OAAO;YACL,mFAAmF;YACnFM,MAAMN,KAAK,GAAG,IAAI,CAACA,KAAK,CAACO,KAAK,CAAC;QACjC;QACAD,MAAME,MAAM,GAAGZ,UAAU,IAAI,CAACY,MAAM;QACpCF,MAAMG,IAAI,GAAGb,UAAU,IAAI,CAACa,IAAI;QAChCH,MAAMI,IAAI,GAAG,IAAI,CAACA,IAAI;QACtB,OAAOJ;IACT;IApDAK,YAAYX,KAA0B,CAAE;QAuBxCA,uBAAAA,SAAAA,KAAAA;QAEAQ,uBAAAA,UAAAA,KAAAA;QAEAC,uBAAAA,QAAAA,KAAAA;QAEAC,uBAAAA,QAAAA,KAAAA;QA5BE,IAAIE;QACJ,IAAI,OAAOZ,UAAU,YAAYA,iBAAiBa,YAAY;YAC5DD,UAAU;gBAAEZ;YAAM;QACpB,OAAO;YACLY,UAAUZ;QACZ;QAEA,IAAI,CAACA,KAAK,GAAGY,SAASZ,SAAS;QAC/B,wDAAwD;QACxD,gEAAgE;QAChE,4DAA4D;QAC5D,EAAE;QACF,wEAAwE;QACxE,4EAA4E;QAC5E,8EAA8E;QAC9E,EAAE;QACF,iDAAiD;QACjD,IAAI,CAACQ,MAAM,GAAGI,SAASJ,UAAWP;QAClC,IAAI,CAACQ,IAAI,GAAGG,SAASH,QAAQ,CAAC;QAC9B,IAAI,CAACC,IAAI,GAAGE,SAASF,QAAQ;IAC/B;AAgCF"}
@@ -1,3 +0,0 @@
1
- export * from './VirtualFile';
2
-
3
- //# sourceMappingURL=index.browser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/virtual-file/index.browser.ts"],"sourcesContent":["export * from './VirtualFile';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB"}
@@ -1,4 +0,0 @@
1
- export * from './toVirtualFile';
2
- export * from './VirtualFile';
3
-
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/virtual-file/index.ts"],"sourcesContent":["export * from './toVirtualFile';\nexport * from './VirtualFile';\n"],"names":[],"mappings":"AAAA,cAAc,kBAAkB;AAChC,cAAc,gBAAgB"}
@@ -1,26 +0,0 @@
1
- import { promises as fsPromises } from 'fs';
2
- import { VirtualFile } from './VirtualFile';
3
- /**
4
- * Reads a file from filesystem and creates a vfile.
5
- *
6
- * @param path - Filesystem path to load the contents from.
7
- * @param encoding - Optional encoding to pass down to fs.readFile.
8
- * @returns Promise returning VFile with loaded file contents.
9
- */ export async function readVirtualFile(path, encoding = null) {
10
- return new VirtualFile({
11
- path,
12
- value: await fsPromises.readFile(path, {
13
- encoding
14
- })
15
- });
16
- }
17
- /**
18
- * Writes vfile to filesystem.
19
- *
20
- * @param vfile - The vfile to write.
21
- * @param options - Options to pass down to fs.writeFile.
22
- */ export async function writeVirtualFile(vfile, options) {
23
- return fsPromises.writeFile(vfile.path, vfile.value, options);
24
- }
25
-
26
- //# sourceMappingURL=toVirtualFile.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/virtual-file/toVirtualFile.ts"],"sourcesContent":["import { promises as fsPromises } from 'fs';\n\nimport { VirtualFile } from './VirtualFile';\n\n/**\n * Reads a file from filesystem and creates a vfile.\n *\n * @param path - Filesystem path to load the contents from.\n * @param encoding - Optional encoding to pass down to fs.readFile.\n * @returns Promise returning VFile with loaded file contents.\n */\nexport async function readVirtualFile(\n path: string,\n encoding: BufferEncoding | null = null,\n) {\n return new VirtualFile({\n path,\n value: await fsPromises.readFile(path, { encoding }),\n });\n}\n\ntype WriteVFileOptions = Exclude<\n Parameters<typeof fsPromises['writeFile']>[2],\n undefined\n>;\n\n/**\n * Writes vfile to filesystem.\n *\n * @param vfile - The vfile to write.\n * @param options - Options to pass down to fs.writeFile.\n */\nexport async function writeVirtualFile(\n vfile: VirtualFile,\n options?: WriteVFileOptions,\n) {\n return fsPromises.writeFile(vfile.path, vfile.value, options);\n}\n"],"names":["promises","fsPromises","VirtualFile","readVirtualFile","path","encoding","value","readFile","writeVirtualFile","vfile","options","writeFile"],"mappings":"AAAA,SAASA,YAAYC,UAAU,QAAQ,KAAK;AAE5C,SAASC,WAAW,QAAQ,gBAAgB;AAE5C;;;;;;CAMC,GACD,OAAO,eAAeC,gBACpBC,IAAY,EACZC,WAAkC,IAAI;IAEtC,OAAO,IAAIH,YAAY;QACrBE;QACAE,OAAO,MAAML,WAAWM,QAAQ,CAACH,MAAM;YAAEC;QAAS;IACpD;AACF;AAOA;;;;;CAKC,GACD,OAAO,eAAeG,iBACpBC,KAAkB,EAClBC,OAA2B;IAE3B,OAAOT,WAAWU,SAAS,CAACF,MAAML,IAAI,EAAEK,MAAMH,KAAK,EAAEI;AACvD"}
@@ -1,30 +0,0 @@
1
- import type { Struct } from 'superstruct';
2
- /**
3
- * Get the enum values as union type. This allows using both the enum string
4
- * values and the enum itself as values.
5
- *
6
- * Note: This only works for string enums.
7
- *
8
- * @example
9
- * ```typescript
10
- * enum Foo {
11
- * Bar = 'bar',
12
- * Baz = 'baz',
13
- * }
14
- *
15
- * type FooValue = EnumToUnion<Foo>;
16
- * // FooValue is 'bar' | 'baz'
17
- *
18
- * const foo: FooValue = Foo.Bar; // Works
19
- * const foo: FooValue = 'bar'; // Also works
20
- * ```
21
- */
22
- export declare type EnumToUnion<Type extends string> = `${Type}`;
23
- /**
24
- * Superstruct struct for validating an enum value. This allows using both the
25
- * enum string values and the enum itself as values.
26
- *
27
- * @param constant - The enum to validate against.
28
- * @returns The superstruct struct.
29
- */
30
- export declare function enumValue<Type extends string>(constant: Type): Struct<EnumToUnion<Type>, null>;
@@ -1,10 +0,0 @@
1
- /**
2
- * Get the error message from an unknown error type.
3
- *
4
- * - If the error is an object with a `message` property, return the message.
5
- * - Otherwise, return the error converted to a string.
6
- *
7
- * @param error - The error to get the message from.
8
- * @returns The error message.
9
- */
10
- export declare function getErrorMessage(error: unknown): string;
@@ -1,144 +0,0 @@
1
- import type { Component } from '@metamask/snaps-ui';
2
- import type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';
3
- export declare enum HandlerType {
4
- OnRpcRequest = "onRpcRequest",
5
- OnTransaction = "onTransaction",
6
- OnCronjob = "onCronjob",
7
- OnInstall = "onInstall",
8
- OnUpdate = "onUpdate"
9
- }
10
- declare type SnapHandler = {
11
- /**
12
- * The type of handler.
13
- */
14
- type: HandlerType;
15
- /**
16
- * Whether the handler is required, i.e., whether the request will fail if the
17
- * handler is called, but the snap does not export it.
18
- *
19
- * This is primarily used for the lifecycle handlers, which are optional.
20
- */
21
- required: boolean;
22
- /**
23
- * Validate the given snap export. This should return a type guard for the
24
- * handler type.
25
- *
26
- * @param snapExport - The export to validate.
27
- * @returns Whether the export is valid.
28
- */
29
- validator: (snapExport: unknown) => boolean;
30
- };
31
- export declare const SNAP_EXPORTS: {
32
- readonly onRpcRequest: {
33
- readonly type: HandlerType.OnRpcRequest;
34
- readonly required: true;
35
- readonly validator: (snapExport: unknown) => snapExport is OnRpcRequestHandler<Record<string, Json> | Json[] | undefined>;
36
- };
37
- readonly onTransaction: {
38
- readonly type: HandlerType.OnTransaction;
39
- readonly required: true;
40
- readonly validator: (snapExport: unknown) => snapExport is OnTransactionHandler;
41
- };
42
- readonly onCronjob: {
43
- readonly type: HandlerType.OnCronjob;
44
- readonly required: true;
45
- readonly validator: (snapExport: unknown) => snapExport is OnCronjobHandler<Record<string, Json> | Json[] | undefined>;
46
- };
47
- readonly onInstall: {
48
- readonly type: HandlerType.OnInstall;
49
- readonly required: false;
50
- readonly validator: (snapExport: unknown) => snapExport is LifecycleEventHandler;
51
- };
52
- readonly onUpdate: {
53
- readonly type: HandlerType.OnUpdate;
54
- readonly required: false;
55
- readonly validator: (snapExport: unknown) => snapExport is LifecycleEventHandler;
56
- };
57
- };
58
- /**
59
- * The `onRpcRequest` handler. This is called whenever a JSON-RPC request is
60
- * made to the snap.
61
- *
62
- * @param args - The request arguments.
63
- * @param args.origin - The origin of the request. This can be the ID of another
64
- * snap, or the URL of a dapp.
65
- * @param args.request - The JSON-RPC request sent to the snap.
66
- * @returns The JSON-RPC response. This must be a JSON-serializable value.
67
- */
68
- export declare type OnRpcRequestHandler<Params extends JsonRpcParams = JsonRpcParams> = (args: {
69
- origin: string;
70
- request: JsonRpcRequest<Params>;
71
- }) => Promise<unknown>;
72
- /**
73
- * The response from a snap's `onTransaction` handler.
74
- *
75
- * @property content - A custom UI component, that will be shown in MetaMask. Can be created using `@metamask/snaps-ui`.
76
- *
77
- * If the snap has no insights about the transaction, this should be `null`.
78
- */
79
- export declare type OnTransactionResponse = {
80
- content: Component | null;
81
- };
82
- /**
83
- * The `onTransaction` handler. This is called whenever a transaction is
84
- * submitted to the snap. It can return insights about the transaction, which
85
- * will be displayed to the user.
86
- *
87
- * @param args - The request arguments.
88
- * @param args.transaction - The transaction object.
89
- * @param args.chainId - The CAIP-2 chain ID of the network the transaction is
90
- * being submitted to.
91
- * @param args.transactionOrigin - The origin of the transaction. This is the
92
- * URL of the dapp that submitted the transaction.
93
- * @returns Insights about the transaction. See {@link OnTransactionResponse}.
94
- */
95
- export declare type OnTransactionHandler = (args: {
96
- transaction: {
97
- [key: string]: Json;
98
- };
99
- chainId: string;
100
- transactionOrigin?: string;
101
- }) => Promise<OnTransactionResponse>;
102
- /**
103
- * The `onCronjob` handler. This is called on a regular interval, as defined by
104
- * the snap's manifest.
105
- *
106
- * @param args - The request arguments.
107
- * @param args.request - The JSON-RPC request sent to the snap.
108
- */
109
- export declare type OnCronjobHandler<Params extends JsonRpcParams = JsonRpcParams> = (args: {
110
- request: JsonRpcRequest<Params>;
111
- }) => Promise<unknown>;
112
- /**
113
- * A handler that can be used for the lifecycle hooks.
114
- */
115
- export declare type LifecycleEventHandler = (args: {
116
- request: JsonRpcRequest;
117
- }) => Promise<unknown>;
118
- /**
119
- * The `onInstall` handler. This is called after the snap is installed.
120
- *
121
- * This type is an alias for {@link LifecycleEventHandler}.
122
- */
123
- export declare type OnInstallHandler = LifecycleEventHandler;
124
- /**
125
- * The `onUpdate` handler. This is called after the snap is updated.
126
- *
127
- * This type is an alias for {@link LifecycleEventHandler}.
128
- */
129
- export declare type OnUpdateHandler = LifecycleEventHandler;
130
- /**
131
- * Utility type for getting the handler function type from a handler type.
132
- */
133
- export declare type HandlerFunction<Type extends SnapHandler> = Type['validator'] extends (snapExport: unknown) => snapExport is infer Handler ? Handler : never;
134
- /**
135
- * All the function-based handlers that a snap can implement.
136
- */
137
- export declare type SnapFunctionExports = {
138
- [Key in keyof typeof SNAP_EXPORTS]?: HandlerFunction<typeof SNAP_EXPORTS[Key]>;
139
- };
140
- /**
141
- * All handlers that a snap can implement.
142
- */
143
- export declare type SnapExports = SnapFunctionExports;
144
- export {};
@@ -1,4 +0,0 @@
1
- import type { VirtualFile } from './virtual-file';
2
- export declare const SVG_MAX_BYTE_SIZE = 100000;
3
- export declare const SVG_MAX_BYTE_SIZE_TEXT: string;
4
- export declare const assertIsSnapIcon: (icon: VirtualFile) => void;
@@ -1,13 +0,0 @@
1
- import type { Json } from '@metamask/utils';
2
- /**
3
- * Parse JSON safely.
4
- *
5
- * Does multiple kinds of validation and strips unwanted properties like
6
- * `__proto__` and `constructor`.
7
- *
8
- * @param json - A JSON string to be parsed.
9
- * @returns The parsed JSON object.
10
- * @template Type - The type of the JSON object. The type is not actually
11
- * checked, but it is used to infer the return type.
12
- */
13
- export declare function parseJson<Type extends Json = Json>(json: string): Type;
@@ -1,124 +0,0 @@
1
- import type { Infer } from 'superstruct';
2
- export declare const CHAIN_ID_REGEX: RegExp;
3
- export declare const ACCOUNT_ID_REGEX: RegExp;
4
- /**
5
- * Parse a chain ID string to an object containing the namespace and reference.
6
- * This validates the chain ID before parsing it.
7
- *
8
- * @param chainId - The chain ID to validate and parse.
9
- * @returns The parsed chain ID.
10
- */
11
- export declare function parseChainId(chainId: ChainId): {
12
- namespace: NamespaceId;
13
- reference: string;
14
- };
15
- /**
16
- * Parse an account ID to an object containing the chain, chain ID and address.
17
- * This validates the account ID before parsing it.
18
- *
19
- * @param accountId - The account ID to validate and parse.
20
- * @returns The parsed account ID.
21
- */
22
- export declare function parseAccountId(accountId: AccountId): {
23
- chain: {
24
- namespace: NamespaceId;
25
- reference: string;
26
- };
27
- chainId: ChainId;
28
- address: string;
29
- };
30
- /**
31
- * A helper struct for a string with a minimum length of 1 and a maximum length
32
- * of 40.
33
- */
34
- export declare const LimitedString: import("superstruct").Struct<string, null>;
35
- /**
36
- * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.
37
- */
38
- export declare const ChainIdStruct: import("superstruct").Struct<string, null>;
39
- export declare type ChainId = `${string}:${string}`;
40
- export declare const AccountIdStruct: import("superstruct").Struct<string, null>;
41
- export declare type AccountId = `${ChainId}:${string}`;
42
- export declare const AccountIdArrayStruct: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
43
- /**
44
- * A chain descriptor.
45
- */
46
- export declare const ChainStruct: import("superstruct").Struct<{
47
- name: string;
48
- id: string;
49
- }, {
50
- id: import("superstruct").Struct<string, null>;
51
- name: import("superstruct").Struct<string, null>;
52
- }>;
53
- export declare type Chain = Infer<typeof ChainStruct>;
54
- export declare const NamespaceStruct: import("superstruct").Struct<{
55
- chains: {
56
- name: string;
57
- id: string;
58
- }[];
59
- methods?: string[] | undefined;
60
- events?: string[] | undefined;
61
- }, {
62
- /**
63
- * A list of supported chains in the namespace.
64
- */
65
- chains: import("superstruct").Struct<{
66
- name: string;
67
- id: string;
68
- }[], import("superstruct").Struct<{
69
- name: string;
70
- id: string;
71
- }, {
72
- id: import("superstruct").Struct<string, null>;
73
- name: import("superstruct").Struct<string, null>;
74
- }>>;
75
- /**
76
- * A list of supported RPC methods on the namespace, that a DApp can call.
77
- */
78
- methods: import("superstruct").Struct<string[] | undefined, import("superstruct").Struct<string, null>>;
79
- /**
80
- * A list of supported RPC events on the namespace, that a DApp can listen to.
81
- */
82
- events: import("superstruct").Struct<string[] | undefined, import("superstruct").Struct<string, null>>;
83
- }>;
84
- export declare type Namespace = Infer<typeof NamespaceStruct>;
85
- /**
86
- * A CAIP-2 namespace, i.e., the first part of a chain ID.
87
- */
88
- export declare const NamespaceIdStruct: import("superstruct").Struct<string, null>;
89
- export declare type NamespaceId = Infer<typeof NamespaceIdStruct>;
90
- /**
91
- * Check if the given value is a CAIP-2 namespace ID.
92
- *
93
- * @param value - The value to check.
94
- * @returns Whether the value is a CAIP-2 namespace ID.
95
- */
96
- export declare function isNamespaceId(value: unknown): value is NamespaceId;
97
- /**
98
- * Check if the given value is a CAIP-2 chain ID.
99
- *
100
- * @param value - The value to check.
101
- * @returns Whether the value is a CAIP-2 chain ID.
102
- */
103
- export declare function isChainId(value: unknown): value is ChainId;
104
- /**
105
- * Check if the given value is a CAIP-10 account ID.
106
- *
107
- * @param value - The value to check.
108
- * @returns Whether the value is a CAIP-10 account ID.
109
- */
110
- export declare function isAccountId(value: unknown): value is AccountId;
111
- /**
112
- * Check if the given value is an array of CAIP-10 account IDs.
113
- *
114
- * @param value - The value to check.
115
- * @returns Whether the value is an array of CAIP-10 account IDs.
116
- */
117
- export declare function isAccountIdArray(value: unknown): value is AccountId[];
118
- /**
119
- * Check if a value is a {@link Namespace}.
120
- *
121
- * @param value - The value to validate.
122
- * @returns True if the value is a valid {@link Namespace}.
123
- */
124
- export declare function isNamespace(value: unknown): value is Namespace;
@@ -1,8 +0,0 @@
1
- /**
2
- * Indent a message by adding a number of spaces to the beginning of each line.
3
- *
4
- * @param message - The message to indent.
5
- * @param spaces - The number of spaces to indent by. Defaults to 2.
6
- * @returns The indented message.
7
- */
8
- export declare function indent(message: string, spaces?: number): string;