@metamask/snaps-sdk 0.0.0 → 1.1.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 (247) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/dist/cjs/error-wrappers.js +80 -0
  3. package/dist/cjs/error-wrappers.js.map +1 -0
  4. package/dist/cjs/errors.js +157 -0
  5. package/dist/cjs/errors.js.map +1 -0
  6. package/dist/cjs/index.js +44 -2
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/cjs/internals/error-wrappers.js +25 -0
  9. package/dist/cjs/internals/error-wrappers.js.map +1 -0
  10. package/dist/cjs/internals/errors.js +59 -0
  11. package/dist/cjs/internals/errors.js.map +1 -0
  12. package/dist/cjs/internals/helpers.js +6 -0
  13. package/dist/cjs/internals/helpers.js.map +1 -0
  14. package/dist/cjs/internals/index.js +22 -0
  15. package/dist/cjs/internals/index.js.map +1 -0
  16. package/dist/cjs/types/caip.js +10 -0
  17. package/dist/cjs/types/caip.js.map +1 -0
  18. package/dist/cjs/types/global.js +6 -0
  19. package/dist/cjs/types/global.js.map +1 -0
  20. package/dist/cjs/types/handlers/cronjob.js +6 -0
  21. package/dist/cjs/types/handlers/cronjob.js.map +1 -0
  22. package/dist/cjs/types/handlers/home-page.js +6 -0
  23. package/dist/cjs/types/handlers/home-page.js.map +1 -0
  24. package/dist/cjs/types/handlers/index.js +26 -0
  25. package/dist/cjs/types/handlers/index.js.map +1 -0
  26. package/dist/cjs/types/handlers/keyring.js +6 -0
  27. package/dist/cjs/types/handlers/keyring.js.map +1 -0
  28. package/dist/cjs/types/handlers/lifecycle.js +6 -0
  29. package/dist/cjs/types/handlers/lifecycle.js.map +1 -0
  30. package/dist/cjs/types/handlers/name-lookup.js +6 -0
  31. package/dist/cjs/types/handlers/name-lookup.js.map +1 -0
  32. package/dist/cjs/types/handlers/rpc-request.js +6 -0
  33. package/dist/cjs/types/handlers/rpc-request.js.map +1 -0
  34. package/dist/cjs/types/handlers/transaction.js +16 -0
  35. package/dist/cjs/types/handlers/transaction.js.map +1 -0
  36. package/dist/cjs/types/index.js +28 -0
  37. package/dist/cjs/types/index.js.map +1 -0
  38. package/dist/cjs/types/methods/dialog.js +18 -0
  39. package/dist/cjs/types/methods/dialog.js.map +1 -0
  40. package/dist/cjs/types/methods/get-bip32-entropy.js +6 -0
  41. package/dist/cjs/types/methods/get-bip32-entropy.js.map +1 -0
  42. package/dist/cjs/types/methods/get-bip32-public-key.js +6 -0
  43. package/dist/cjs/types/methods/get-bip32-public-key.js.map +1 -0
  44. package/dist/cjs/types/methods/get-bip44-entropy.js +6 -0
  45. package/dist/cjs/types/methods/get-bip44-entropy.js.map +1 -0
  46. package/dist/cjs/types/methods/get-entropy.js +6 -0
  47. package/dist/cjs/types/methods/get-entropy.js.map +1 -0
  48. package/dist/cjs/types/methods/get-file.js +18 -0
  49. package/dist/cjs/types/methods/get-file.js.map +1 -0
  50. package/dist/cjs/types/methods/get-locale.js +10 -0
  51. package/dist/cjs/types/methods/get-locale.js.map +1 -0
  52. package/dist/cjs/types/methods/get-snaps.js +6 -0
  53. package/dist/cjs/types/methods/get-snaps.js.map +1 -0
  54. package/dist/cjs/types/methods/index.js +34 -0
  55. package/dist/cjs/types/methods/index.js.map +1 -0
  56. package/dist/cjs/types/methods/invoke-keyring.js +6 -0
  57. package/dist/cjs/types/methods/invoke-keyring.js.map +1 -0
  58. package/dist/cjs/types/methods/invoke-snap.js +6 -0
  59. package/dist/cjs/types/methods/invoke-snap.js.map +1 -0
  60. package/dist/cjs/types/methods/manage-accounts.js +6 -0
  61. package/dist/cjs/types/methods/manage-accounts.js.map +1 -0
  62. package/dist/cjs/types/methods/manage-state.js +18 -0
  63. package/dist/cjs/types/methods/manage-state.js.map +1 -0
  64. package/dist/cjs/types/methods/methods.js +6 -0
  65. package/dist/cjs/types/methods/methods.js.map +1 -0
  66. package/dist/cjs/types/methods/notify.js +17 -0
  67. package/dist/cjs/types/methods/notify.js.map +1 -0
  68. package/dist/cjs/types/methods/request-snaps.js +6 -0
  69. package/dist/cjs/types/methods/request-snaps.js.map +1 -0
  70. package/dist/cjs/types/permissions.js +6 -0
  71. package/dist/cjs/types/permissions.js.map +1 -0
  72. package/dist/cjs/types/provider.js +6 -0
  73. package/dist/cjs/types/provider.js.map +1 -0
  74. package/dist/cjs/types/snap.js +6 -0
  75. package/dist/cjs/types/snap.js.map +1 -0
  76. package/dist/cjs/ui/builder.js +44 -0
  77. package/dist/cjs/ui/builder.js.map +1 -0
  78. package/dist/cjs/ui/component.js +29 -0
  79. package/dist/cjs/ui/component.js.map +1 -0
  80. package/dist/cjs/ui/components/copyable.js +32 -0
  81. package/dist/cjs/ui/components/copyable.js.map +1 -0
  82. package/dist/cjs/ui/components/divider.js +27 -0
  83. package/dist/cjs/ui/components/divider.js.map +1 -0
  84. package/dist/cjs/ui/components/heading.js +30 -0
  85. package/dist/cjs/ui/components/heading.js.map +1 -0
  86. package/dist/cjs/ui/components/image.js +47 -0
  87. package/dist/cjs/ui/components/image.js.map +1 -0
  88. package/dist/cjs/ui/components/index.js +49 -0
  89. package/dist/cjs/ui/components/index.js.map +1 -0
  90. package/dist/cjs/ui/components/panel.js +55 -0
  91. package/dist/cjs/ui/components/panel.js.map +1 -0
  92. package/dist/cjs/ui/components/spinner.js +27 -0
  93. package/dist/cjs/ui/components/spinner.js.map +1 -0
  94. package/dist/cjs/ui/components/text.js +32 -0
  95. package/dist/cjs/ui/components/text.js.map +1 -0
  96. package/dist/cjs/ui/index.js +28 -0
  97. package/dist/cjs/ui/index.js.map +1 -0
  98. package/dist/cjs/ui/nodes.js +41 -0
  99. package/dist/cjs/ui/nodes.js.map +1 -0
  100. package/dist/esm/error-wrappers.js +128 -0
  101. package/dist/esm/error-wrappers.js.map +1 -0
  102. package/dist/esm/errors.js +150 -0
  103. package/dist/esm/errors.js.map +1 -0
  104. package/dist/esm/index.js +5 -2
  105. package/dist/esm/index.js.map +1 -1
  106. package/dist/esm/internals/error-wrappers.js +25 -0
  107. package/dist/esm/internals/error-wrappers.js.map +1 -0
  108. package/dist/esm/internals/errors.js +58 -0
  109. package/dist/esm/internals/errors.js.map +1 -0
  110. package/dist/esm/internals/helpers.js +3 -0
  111. package/dist/esm/internals/helpers.js.map +1 -0
  112. package/dist/esm/internals/index.js +5 -0
  113. package/dist/esm/internals/index.js.map +1 -0
  114. package/dist/esm/types/caip.js +7 -0
  115. package/dist/esm/types/caip.js.map +1 -0
  116. package/dist/esm/types/global.js +3 -0
  117. package/dist/esm/types/global.js.map +1 -0
  118. package/dist/esm/types/handlers/cronjob.js +3 -0
  119. package/dist/esm/types/handlers/cronjob.js.map +1 -0
  120. package/dist/esm/types/handlers/home-page.js +3 -0
  121. package/dist/esm/types/handlers/home-page.js.map +1 -0
  122. package/dist/esm/types/handlers/index.js +9 -0
  123. package/dist/esm/types/handlers/index.js.map +1 -0
  124. package/dist/esm/types/handlers/keyring.js +3 -0
  125. package/dist/esm/types/handlers/keyring.js.map +1 -0
  126. package/dist/esm/types/handlers/lifecycle.js +3 -0
  127. package/dist/esm/types/handlers/lifecycle.js.map +1 -0
  128. package/dist/esm/types/handlers/name-lookup.js +3 -0
  129. package/dist/esm/types/handlers/name-lookup.js.map +1 -0
  130. package/dist/esm/types/handlers/rpc-request.js +3 -0
  131. package/dist/esm/types/handlers/rpc-request.js.map +1 -0
  132. package/dist/esm/types/handlers/transaction.js +6 -0
  133. package/dist/esm/types/handlers/transaction.js.map +1 -0
  134. package/dist/esm/types/index.js +11 -0
  135. package/dist/esm/types/index.js.map +1 -0
  136. package/dist/esm/types/methods/dialog.js +8 -0
  137. package/dist/esm/types/methods/dialog.js.map +1 -0
  138. package/dist/esm/types/methods/get-bip32-entropy.js +3 -0
  139. package/dist/esm/types/methods/get-bip32-entropy.js.map +1 -0
  140. package/dist/esm/types/methods/get-bip32-public-key.js +3 -0
  141. package/dist/esm/types/methods/get-bip32-public-key.js.map +1 -0
  142. package/dist/esm/types/methods/get-bip44-entropy.js +3 -0
  143. package/dist/esm/types/methods/get-bip44-entropy.js.map +1 -0
  144. package/dist/esm/types/methods/get-entropy.js +3 -0
  145. package/dist/esm/types/methods/get-entropy.js.map +1 -0
  146. package/dist/esm/types/methods/get-file.js +8 -0
  147. package/dist/esm/types/methods/get-file.js.map +1 -0
  148. package/dist/esm/types/methods/get-locale.js +7 -0
  149. package/dist/esm/types/methods/get-locale.js.map +1 -0
  150. package/dist/esm/types/methods/get-snaps.js +3 -0
  151. package/dist/esm/types/methods/get-snaps.js.map +1 -0
  152. package/dist/esm/types/methods/index.js +17 -0
  153. package/dist/esm/types/methods/index.js.map +1 -0
  154. package/dist/esm/types/methods/invoke-keyring.js +3 -0
  155. package/dist/esm/types/methods/invoke-keyring.js.map +1 -0
  156. package/dist/esm/types/methods/invoke-snap.js +3 -0
  157. package/dist/esm/types/methods/invoke-snap.js.map +1 -0
  158. package/dist/esm/types/methods/manage-accounts.js +3 -0
  159. package/dist/esm/types/methods/manage-accounts.js.map +1 -0
  160. package/dist/esm/types/methods/manage-state.js +8 -0
  161. package/dist/esm/types/methods/manage-state.js.map +1 -0
  162. package/dist/esm/types/methods/methods.js +3 -0
  163. package/dist/esm/types/methods/methods.js.map +1 -0
  164. package/dist/esm/types/methods/notify.js +7 -0
  165. package/dist/esm/types/methods/notify.js.map +1 -0
  166. package/dist/esm/types/methods/request-snaps.js +3 -0
  167. package/dist/esm/types/methods/request-snaps.js.map +1 -0
  168. package/dist/esm/types/permissions.js +3 -0
  169. package/dist/esm/types/permissions.js.map +1 -0
  170. package/dist/esm/types/provider.js +3 -0
  171. package/dist/esm/types/provider.js.map +1 -0
  172. package/dist/esm/types/snap.js +3 -0
  173. package/dist/esm/types/snap.js.map +1 -0
  174. package/dist/esm/ui/builder.js +50 -0
  175. package/dist/esm/ui/builder.js.map +1 -0
  176. package/dist/esm/ui/component.js +23 -0
  177. package/dist/esm/ui/component.js.map +1 -0
  178. package/dist/esm/ui/components/copyable.js +27 -0
  179. package/dist/esm/ui/components/copyable.js.map +1 -0
  180. package/dist/esm/ui/components/divider.js +15 -0
  181. package/dist/esm/ui/components/divider.js.map +1 -0
  182. package/dist/esm/ui/components/heading.js +22 -0
  183. package/dist/esm/ui/components/heading.js.map +1 -0
  184. package/dist/esm/ui/components/image.js +37 -0
  185. package/dist/esm/ui/components/image.js.map +1 -0
  186. package/dist/esm/ui/components/index.js +9 -0
  187. package/dist/esm/ui/components/index.js.map +1 -0
  188. package/dist/esm/ui/components/panel.js +56 -0
  189. package/dist/esm/ui/components/panel.js.map +1 -0
  190. package/dist/esm/ui/components/spinner.js +15 -0
  191. package/dist/esm/ui/components/spinner.js.map +1 -0
  192. package/dist/esm/ui/components/text.js +29 -0
  193. package/dist/esm/ui/components/text.js.map +1 -0
  194. package/dist/esm/ui/index.js +5 -0
  195. package/dist/esm/ui/index.js.map +1 -0
  196. package/dist/esm/ui/nodes.js +24 -0
  197. package/dist/esm/ui/nodes.js.map +1 -0
  198. package/dist/types/error-wrappers.d.ts +413 -0
  199. package/dist/types/errors.d.ts +88 -0
  200. package/dist/types/index.d.ts +6 -0
  201. package/dist/types/internals/error-wrappers.d.ts +33 -0
  202. package/dist/types/internals/errors.d.ts +41 -0
  203. package/dist/types/internals/helpers.d.ts +36 -0
  204. package/dist/types/internals/index.d.ts +3 -0
  205. package/dist/types/types/caip.d.ts +12 -0
  206. package/dist/types/types/global.d.ts +8 -0
  207. package/dist/types/types/handlers/cronjob.d.ts +14 -0
  208. package/dist/types/types/handlers/home-page.d.ts +19 -0
  209. package/dist/types/types/handlers/index.d.ts +7 -0
  210. package/dist/types/types/handlers/keyring.d.ts +20 -0
  211. package/dist/types/types/handlers/lifecycle.d.ts +41 -0
  212. package/dist/types/types/handlers/name-lookup.d.ts +59 -0
  213. package/dist/types/types/handlers/rpc-request.d.ts +21 -0
  214. package/dist/types/types/handlers/transaction.d.ts +110 -0
  215. package/dist/types/types/index.d.ts +7 -0
  216. package/dist/types/types/methods/dialog.d.ts +67 -0
  217. package/dist/types/types/methods/get-bip32-entropy.d.ts +15 -0
  218. package/dist/types/types/methods/get-bip32-public-key.d.ts +19 -0
  219. package/dist/types/types/methods/get-bip44-entropy.d.ts +14 -0
  220. package/dist/types/types/methods/get-entropy.d.ts +16 -0
  221. package/dist/types/types/methods/get-file.d.ts +23 -0
  222. package/dist/types/types/methods/get-locale.d.ts +12 -0
  223. package/dist/types/types/methods/get-snaps.d.ts +16 -0
  224. package/dist/types/types/methods/index.d.ts +15 -0
  225. package/dist/types/types/methods/invoke-keyring.d.ts +14 -0
  226. package/dist/types/types/methods/invoke-snap.d.ts +16 -0
  227. package/dist/types/types/methods/manage-accounts.d.ts +18 -0
  228. package/dist/types/types/methods/manage-state.d.ts +69 -0
  229. package/dist/types/types/methods/methods.d.ts +62 -0
  230. package/dist/types/types/methods/notify.d.ts +27 -0
  231. package/dist/types/types/methods/request-snaps.d.ts +18 -0
  232. package/dist/types/types/permissions.d.ts +46 -0
  233. package/dist/types/types/provider.d.ts +14 -0
  234. package/dist/types/types/snap.d.ts +12 -0
  235. package/dist/types/ui/builder.d.ts +42 -0
  236. package/dist/types/ui/component.d.ts +17 -0
  237. package/dist/types/ui/components/copyable.d.ts +49 -0
  238. package/dist/types/ui/components/divider.d.ts +21 -0
  239. package/dist/types/ui/components/heading.d.ts +36 -0
  240. package/dist/types/ui/components/image.d.ts +42 -0
  241. package/dist/types/ui/components/index.d.ts +9 -0
  242. package/dist/types/ui/components/panel.d.ts +153 -0
  243. package/dist/types/ui/components/spinner.d.ts +22 -0
  244. package/dist/types/ui/components/text.d.ts +46 -0
  245. package/dist/types/ui/index.d.ts +3 -0
  246. package/dist/types/ui/nodes.d.ts +51 -0
  247. package/package.json +10 -2
@@ -0,0 +1,58 @@
1
+ import { hasProperty, isObject, isValidJson } from '@metamask/utils';
2
+ export const SNAP_ERROR_CODE = -31002;
3
+ export const SNAP_ERROR_MESSAGE = 'Snap Error';
4
+ /**
5
+ * Get the error message from an unknown error type.
6
+ *
7
+ * - If the error is an object with a `message` property, return the message.
8
+ * - Otherwise, return the error converted to a string.
9
+ *
10
+ * @param error - The error to get the message from.
11
+ * @returns The error message.
12
+ * @internal
13
+ */ export function getErrorMessage(error) {
14
+ if (isObject(error) && hasProperty(error, 'message') && typeof error.message === 'string') {
15
+ return error.message;
16
+ }
17
+ return String(error);
18
+ }
19
+ /**
20
+ * Get the error stack from an unknown error type.
21
+ *
22
+ * @param error - The error to get the stack from.
23
+ * @returns The error stack, or undefined if the error does not have a valid
24
+ * stack.
25
+ * @internal
26
+ */ export function getErrorStack(error) {
27
+ if (isObject(error) && hasProperty(error, 'stack') && typeof error.stack === 'string') {
28
+ return error.stack;
29
+ }
30
+ return undefined;
31
+ }
32
+ /**
33
+ * Get the error code from an unknown error type.
34
+ *
35
+ * @param error - The error to get the code from.
36
+ * @returns The error code, or `-32603` if the error does not have a valid code.
37
+ * @internal
38
+ */ export function getErrorCode(error) {
39
+ if (isObject(error) && hasProperty(error, 'code') && typeof error.code === 'number' && Number.isInteger(error.code)) {
40
+ return error.code;
41
+ }
42
+ return -32603;
43
+ }
44
+ /**
45
+ * Get the error data from an unknown error type.
46
+ *
47
+ * @param error - The error to get the data from.
48
+ * @returns The error data, or an empty object if the error does not have valid
49
+ * data.
50
+ * @internal
51
+ */ export function getErrorData(error) {
52
+ if (isObject(error) && hasProperty(error, 'data') && typeof error.data === 'object' && error.data !== null && isValidJson(error.data) && !Array.isArray(error.data)) {
53
+ return error.data;
54
+ }
55
+ return {};
56
+ }
57
+
58
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/internals/errors.ts"],"sourcesContent":["import { hasProperty, isObject, isValidJson } from '@metamask/utils';\n\nexport const SNAP_ERROR_CODE = -31002;\nexport const SNAP_ERROR_MESSAGE = 'Snap Error';\n\n/**\n * Get the error message from an unknown error type.\n *\n * - If the error is an object with a `message` property, return the message.\n * - Otherwise, return the error converted to a string.\n *\n * @param error - The error to get the message from.\n * @returns The error message.\n * @internal\n */\nexport function getErrorMessage(error: unknown) {\n if (\n isObject(error) &&\n hasProperty(error, 'message') &&\n typeof error.message === 'string'\n ) {\n return error.message;\n }\n\n return String(error);\n}\n\n/**\n * Get the error stack from an unknown error type.\n *\n * @param error - The error to get the stack from.\n * @returns The error stack, or undefined if the error does not have a valid\n * stack.\n * @internal\n */\nexport function getErrorStack(error: unknown) {\n if (\n isObject(error) &&\n hasProperty(error, 'stack') &&\n typeof error.stack === 'string'\n ) {\n return error.stack;\n }\n\n return undefined;\n}\n\n/**\n * Get the error code from an unknown error type.\n *\n * @param error - The error to get the code from.\n * @returns The error code, or `-32603` if the error does not have a valid code.\n * @internal\n */\nexport function getErrorCode(error: unknown) {\n if (\n isObject(error) &&\n hasProperty(error, 'code') &&\n typeof error.code === 'number' &&\n Number.isInteger(error.code)\n ) {\n return error.code;\n }\n\n return -32603;\n}\n\n/**\n * Get the error data from an unknown error type.\n *\n * @param error - The error to get the data from.\n * @returns The error data, or an empty object if the error does not have valid\n * data.\n * @internal\n */\nexport function getErrorData(error: unknown) {\n if (\n isObject(error) &&\n hasProperty(error, 'data') &&\n typeof error.data === 'object' &&\n error.data !== null &&\n isValidJson(error.data) &&\n !Array.isArray(error.data)\n ) {\n return error.data;\n }\n\n return {};\n}\n"],"names":["hasProperty","isObject","isValidJson","SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE","getErrorMessage","error","message","String","getErrorStack","stack","undefined","getErrorCode","code","Number","isInteger","getErrorData","data","Array","isArray"],"mappings":"AAAA,SAASA,WAAW,EAAEC,QAAQ,EAAEC,WAAW,QAAQ,kBAAkB;AAErE,OAAO,MAAMC,kBAAkB,CAAC,MAAM;AACtC,OAAO,MAAMC,qBAAqB,aAAa;AAE/C;;;;;;;;;CASC,GACD,OAAO,SAASC,gBAAgBC,KAAc;IAC5C,IACEL,SAASK,UACTN,YAAYM,OAAO,cACnB,OAAOA,MAAMC,OAAO,KAAK,UACzB;QACA,OAAOD,MAAMC,OAAO;IACtB;IAEA,OAAOC,OAAOF;AAChB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASG,cAAcH,KAAc;IAC1C,IACEL,SAASK,UACTN,YAAYM,OAAO,YACnB,OAAOA,MAAMI,KAAK,KAAK,UACvB;QACA,OAAOJ,MAAMI,KAAK;IACpB;IAEA,OAAOC;AACT;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,aAAaN,KAAc;IACzC,IACEL,SAASK,UACTN,YAAYM,OAAO,WACnB,OAAOA,MAAMO,IAAI,KAAK,YACtBC,OAAOC,SAAS,CAACT,MAAMO,IAAI,GAC3B;QACA,OAAOP,MAAMO,IAAI;IACnB;IAEA,OAAO,CAAC;AACV;AAEA;;;;;;;CAOC,GACD,OAAO,SAASG,aAAaV,KAAc;IACzC,IACEL,SAASK,UACTN,YAAYM,OAAO,WACnB,OAAOA,MAAMW,IAAI,KAAK,YACtBX,MAAMW,IAAI,KAAK,QACff,YAAYI,MAAMW,IAAI,KACtB,CAACC,MAAMC,OAAO,CAACb,MAAMW,IAAI,GACzB;QACA,OAAOX,MAAMW,IAAI;IACnB;IAEA,OAAO,CAAC;AACV"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/internals/helpers.ts"],"sourcesContent":["import type { JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\n/**\n * Get the enum values as union type. This allows using both the enum string\n * values and the enum itself as values.\n *\n * Note: This only works for string enums.\n *\n * @example\n * enum Foo {\n * Bar = 'bar',\n * Baz = 'baz',\n * }\n *\n * // FooValue is 'bar' | 'baz'\n * type FooValue = EnumToUnion<Foo>;\n *\n * const foo: FooValue = Foo.Bar; // Works\n * const foo: FooValue = 'bar'; // Also works\n * @internal\n */\nexport type EnumToUnion<Type extends string> = `${Type}`;\n\n/**\n * Get a JSON-RPC method with the given name and parameters. If params extends\n * `never`, then the `params` property is omitted.\n *\n * @example\n * // MyMethod is { method: 'my_method', params: { foo: string } }\n * type MyMethod = Method<'my_method', { foo: string }>;\n * @internal\n */\nexport type Method<\n MethodName extends string,\n Params extends JsonRpcParams,\n> = Partial<JsonRpcRequest> & Params extends never\n ? {\n method: MethodName;\n }\n : {\n method: MethodName;\n params: Params;\n };\n"],"names":[],"mappings":"AAAA,WA0CM"}
@@ -0,0 +1,5 @@
1
+ export * from './error-wrappers';
2
+ export * from './errors';
3
+ export * from './helpers';
4
+
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/internals/index.ts"],"sourcesContent":["export * from './error-wrappers';\nexport * from './errors';\nexport * from './helpers';\n"],"names":[],"mappings":"AAAA,cAAc,mBAAmB;AACjC,cAAc,WAAW;AACzB,cAAc,YAAY"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.
3
+ *
4
+ * @see https://chainagnostic.org/CAIPs/caip-2
5
+ */ export { };
6
+
7
+ //# sourceMappingURL=caip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/types/caip.ts"],"sourcesContent":["/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n *\n * @see https://chainagnostic.org/CAIPs/caip-2\n */\nexport type ChainId = `${string}:${string}`;\n\n/**\n * A CAIP-10 account ID, i.e., a chain ID and an account address.\n *\n * @see https://chainagnostic.org/CAIPs/caip-10\n */\nexport type AccountId = `${ChainId}:${string}`;\n"],"names":[],"mappings":"AAAA;;;;CAIC,GACD,WAO+C"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/types/global.ts"],"sourcesContent":["import type { SnapsEthereumProvider, SnapsProvider } from './provider';\n\n/**\n * Constants that are available globally in the Snap.\n */\ndeclare global {\n const ethereum: SnapsEthereumProvider;\n const snap: SnapsProvider;\n}\n"],"names":[],"mappings":"AAAA,WAQC"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=cronjob.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/cronjob.ts"],"sourcesContent":["import type { JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\n/**\n * The `onCronjob` handler. This is called on a regular interval, as defined by\n * the Snap's manifest.\n *\n * Note that using this handler requires the `endowment:cronjob` permission.\n *\n * @param args - The request arguments.\n * @param args.request - The JSON-RPC request sent to the snap. The parameters\n * are defined by the Snap's manifest.\n */\nexport type OnCronjobHandler<Params extends JsonRpcParams = JsonRpcParams> =\n (args: { request: JsonRpcRequest<Params> }) => Promise<unknown>;\n"],"names":[],"mappings":"AAAA,WAakE"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=home-page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/home-page.ts"],"sourcesContent":["import type { Component } from '../../ui';\n\n/**\n * The `onHomePage` handler. This is called when the user navigates to the\n * Snap's home page in the MetaMask UI.\n *\n * This function does not receive any arguments.\n *\n * @returns The content to display on the home page. See\n * {@link OnHomePageResponse}.\n */\nexport type OnHomePageHandler = () => Promise<OnHomePageResponse>;\n\n/**\n * The content to display on the home page.\n *\n * @property content - A custom UI component, that will be shown in MetaMask.\n */\nexport type OnHomePageResponse = {\n content: Component;\n};\n"],"names":[],"mappings":"AAAA,WAoBE"}
@@ -0,0 +1,9 @@
1
+ export * from './cronjob';
2
+ export * from './home-page';
3
+ export * from './keyring';
4
+ export * from './lifecycle';
5
+ export * from './name-lookup';
6
+ export * from './rpc-request';
7
+ export * from './transaction';
8
+
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/index.ts"],"sourcesContent":["export * from './cronjob';\nexport * from './home-page';\nexport * from './keyring';\nexport * from './lifecycle';\nexport * from './name-lookup';\nexport * from './rpc-request';\nexport * from './transaction';\n"],"names":[],"mappings":"AAAA,cAAc,YAAY;AAC1B,cAAc,cAAc;AAC5B,cAAc,YAAY;AAC1B,cAAc,cAAc;AAC5B,cAAc,gBAAgB;AAC9B,cAAc,gBAAgB;AAC9B,cAAc,gBAAgB"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=keyring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/keyring.ts"],"sourcesContent":["import type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\n/**\n * The `onKeyringRequest` handler, which is called when a Snap receives a\n * keyring request.\n *\n * Note that using this handler requires the `endowment:keyring` permission.\n *\n * @param args - The request arguments.\n * @param args.origin - The origin of the request. This can be the ID of another\n * Snap, or the URL of a website.\n * @param args.request - The keyring request sent to the Snap. This includes\n * the method name and parameters.\n * @returns The response to the keyring request. This must be a\n * JSON-serializable value. In order to return an error, throw a `SnapError`\n * instead.\n */\nexport type OnKeyringRequestHandler<\n Params extends JsonRpcParams = JsonRpcParams,\n> = (args: {\n origin: string;\n request: JsonRpcRequest<Params>;\n}) => Promise<Json>;\n"],"names":[],"mappings":"AAAA,WAsBoB"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/lifecycle.ts"],"sourcesContent":["import type { JsonRpcRequest } from '@metamask/utils';\n\n/**\n * A lifecycle event handler. This is called whenever a lifecycle event occurs,\n * such as the Snap being installed or updated.\n *\n * Note that using this handler requires the `endowment:lifecycle-hooks`\n * permission.\n *\n * @param args - The request arguments.\n * @param args.request - The JSON-RPC request sent to the Snap. This does not\n * contain any parameters.\n */\nexport type LifecycleEventHandler = (args: {\n request: JsonRpcRequest;\n}) => Promise<unknown>;\n\n/**\n * The `onInstall` handler. This is called after the Snap is installed.\n *\n * Note that using this handler requires the `endowment:lifecycle-hooks`\n * permission.\n *\n * This type is an alias for {@link LifecycleEventHandler}.\n *\n * @param args - The request arguments.\n * @param args.request - The JSON-RPC request sent to the Snap. This does not\n * contain any parameters.\n */\nexport type OnInstallHandler = LifecycleEventHandler;\n\n/**\n * The `onUpdate` handler. This is called after the Snap is updated.\n *\n * Note that using this handler requires the `endowment:lifecycle-hooks`\n * permission.\n *\n * This type is an alias for {@link LifecycleEventHandler}.\n *\n * @param args - The request arguments.\n * @param args.request - The JSON-RPC request sent to the Snap. This does not\n * contain any parameters.\n */\nexport type OnUpdateHandler = LifecycleEventHandler;\n"],"names":[],"mappings":"AAAA,WA2CoD"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=name-lookup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/name-lookup.ts"],"sourcesContent":["import type { ChainId } from '../caip';\n\ntype BaseOnNameLookupArgs = {\n chainId: ChainId;\n};\n\n/**\n * The arguments for a domain lookup.\n *\n * @property domain - The human-readable domain name that is to be resolved.\n */\nexport type DomainLookupArgs = BaseOnNameLookupArgs & {\n domain: string;\n address?: never;\n};\n\n/**\n * The result of a domain lookup.\n *\n * @property resolvedAddress - The resolved address.\n */\nexport type DomainLookupResult = {\n resolvedAddress: string;\n resolvedDomain?: never;\n};\n\n/**\n * The arguments for an address lookup.\n *\n * @property address - The address that is to be resolved.\n */\nexport type AddressLookupArgs = BaseOnNameLookupArgs & {\n address: string;\n domain?: never;\n};\n\n/**\n * The result of an address lookup.\n *\n * @property resolvedDomain - The resolved domain name.\n */\nexport type AddressLookupResult = {\n resolvedDomain: string;\n resolvedAddress?: never;\n};\n\n/**\n * The `onNameLookup` handler, which is called when MetaMask needs to resolve an\n * address or domain.\n *\n * Note that using this handler requires the `endowment:name-lookup` permission.\n *\n * @param args - The request arguments.\n * @param args.chainId - The CAIP-2 {@link ChainId} of the network the\n * transaction is being submitted to.\n * @param args.domain - The human-readable address that is to be resolved. This\n * is mutually exclusive with `args.address`.\n * @param args.address - The address that is to be resolved. This is mutually\n * exclusive with `args.domain`.\n * @returns The resolved domain or address from the lookup. Must be either\n * {@link AddressLookupResult}, {@link DomainLookupResult}, or `null` if the\n * address or domain could not be resolved.\n */\nexport type OnNameLookupHandler = (\n args: AddressLookupArgs | DomainLookupArgs,\n) => Promise<AddressLookupResult | DomainLookupResult | null>;\n"],"names":[],"mappings":"AAAA,WAiE8D"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=rpc-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/rpc-request.ts"],"sourcesContent":["import type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\n/**\n * The `onRpcRequest` handler, which is called when a Snap receives a JSON-RPC\n * request. This can be called from another Snap, or from a website, depending\n * on the Snap's `endowment:rpc` permission.\n *\n * Note that using this handler requires the `endowment:rpc` permission.\n *\n * @param args - The request arguments.\n * @param args.origin - The origin of the request. This can be the ID of another\n * Snap, or the URL of a website.\n * @param args.request - The JSON-RPC request sent to the snap. This includes\n * the method name and parameters.\n * @returns The response to the JSON-RPC request. This must be a\n * JSON-serializable value. In order to return an error, throw a `SnapError`\n * instead.\n */\nexport type OnRpcRequestHandler<Params extends JsonRpcParams = JsonRpcParams> =\n (args: { origin: string; request: JsonRpcRequest<Params> }) => Promise<Json>;\n"],"names":[],"mappings":"AAAA,WAmB+E"}
@@ -0,0 +1,6 @@
1
+ export var SeverityLevel;
2
+ (function(SeverityLevel) {
3
+ SeverityLevel["Critical"] = 'critical';
4
+ })(SeverityLevel || (SeverityLevel = {}));
5
+
6
+ //# sourceMappingURL=transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/transaction.ts"],"sourcesContent":["import type { EnumToUnion } from '../../internals';\nimport type { Component } from '../../ui';\nimport type { ChainId } from '../caip';\n\n/**\n * The severity level of content being returned from a transaction insight.\n * Currently only one level is supported:\n *\n * - `critical` - The transaction is critical and should not be submitted by the\n * user.\n */\nexport enum SeverityLevel {\n Critical = 'critical',\n}\n\n/**\n * An EIP-1559 (type 2) transaction object.\n *\n * @property from - The address the transaction is being sent from.\n * @property to - The address the transaction is being sent to.\n * @property nonce - The nonce of the transaction.\n * @property value - The value of the transaction.\n * @property data - The data of the transaction.\n * @property gas - The gas limit of the transaction.\n * @property maxFeePerGas - The maximum fee per gas of the transaction.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas of the\n * transaction.\n * @property estimateSuggested - The suggested gas price for the transaction.\n * @property estimateUsed - The gas price used for the transaction.\n * @see https://eips.ethereum.org/EIPS/eip-1559\n */\nexport type EIP1559Transaction = {\n from: string;\n to: string;\n nonce: string;\n value: string;\n data: string;\n gas: string;\n maxFeePerGas: string;\n maxPriorityFeePerGas: string;\n estimateSuggested: string;\n estimateUsed: string;\n};\n\n/**\n * A legacy (type \"0\") transaction object.\n *\n * @property from - The address the transaction is being sent from.\n * @property to - The address the transaction is being sent to.\n * @property nonce - The nonce of the transaction.\n * @property value - The value of the transaction.\n * @property data - The data of the transaction.\n * @property gas - The gas limit of the transaction.\n * @property gasPrice - The gas price of the transaction.\n * @property estimateSuggested - The suggested gas price for the transaction.\n * @property estimateUsed - The gas price used for the transaction.\n */\nexport type LegacyTransaction = {\n from: string;\n to: string;\n nonce: string;\n value: string;\n data: string;\n gas: string;\n gasPrice: string;\n estimateSuggested: string;\n estimateUsed: string;\n};\n\n/**\n * A transaction object. This can be either an EIP-1559 transaction or a legacy\n * transaction.\n *\n * @see EIP1559Transaction\n * @see LegacyTransaction\n */\nexport type Transaction = EIP1559Transaction | LegacyTransaction;\n\n/**\n * The `onTransaction` handler. This is called whenever a transaction is\n * submitted to the snap. It can return insights about the transaction, which\n * will be displayed to the user.\n *\n * Note that using this handler requires the `endowment:transaction-insights`\n * permission.\n *\n * @param args - The request arguments.\n * @param args.transaction - The transaction object, containing the address,\n * value, data, and other properties of the transaction.\n * @param args.chainId - The CAIP-2 {@link ChainId} of the network the\n * transaction is being submitted to.\n * @param args.transactionOrigin - The origin of the transaction. This is the\n * URL of the website that submitted the transaction. This is only available if\n * the Snap has enabled the `allowTransactionOrigin` option in the\n * `endowment:transaction-insight` permission.\n * @returns An object containing insights about the transaction. See\n * {@link OnTransactionResponse}. Can also return `null` if no insights are\n * available.\n */\nexport type OnTransactionHandler = (args: {\n transaction: Transaction;\n chainId: ChainId;\n transactionOrigin?: string;\n}) => Promise<OnTransactionResponse | null>;\n\n/**\n * The response from a Snap's `onTransaction` handler.\n *\n * @property component - A custom UI component, that will be shown in MetaMask.\n * @property severity - The severity level of the content. Currently only one\n * level is supported: `critical`.\n */\nexport type OnTransactionResponse = {\n content: Component;\n severity?: EnumToUnion<SeverityLevel>;\n};\n"],"names":["SeverityLevel","Critical"],"mappings":"WAWO;UAAKA,aAAa;IAAbA,cACVC,cAAW;GADDD,kBAAAA"}
@@ -0,0 +1,11 @@
1
+ // This is intentionally imported, rather than re-exported.
2
+ // eslint-disable-next-line import/no-unassigned-import
3
+ import './global';
4
+ export * from './caip';
5
+ export * from './handlers';
6
+ export * from './methods';
7
+ export * from './permissions';
8
+ export * from './provider';
9
+ export * from './snap';
10
+
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["// This is intentionally imported, rather than re-exported.\n// eslint-disable-next-line import/no-unassigned-import\nimport './global';\n\nexport * from './caip';\nexport * from './handlers';\nexport * from './methods';\nexport * from './permissions';\nexport * from './provider';\nexport * from './snap';\n"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,uDAAuD;AACvD,OAAO,WAAW;AAElB,cAAc,SAAS;AACvB,cAAc,aAAa;AAC3B,cAAc,YAAY;AAC1B,cAAc,gBAAgB;AAC9B,cAAc,aAAa;AAC3B,cAAc,SAAS"}
@@ -0,0 +1,8 @@
1
+ export var DialogType;
2
+ (function(DialogType) {
3
+ DialogType["Alert"] = 'alert';
4
+ DialogType["Confirmation"] = 'confirmation';
5
+ DialogType["Prompt"] = 'prompt';
6
+ })(DialogType || (DialogType = {}));
7
+
8
+ //# sourceMappingURL=dialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/dialog.ts"],"sourcesContent":["import type { EnumToUnion } from '../../internals';\nimport type { Component } from '../../ui';\n\n/**\n * The type of dialog to display.\n *\n * - `alert` - A dialog with a single button.\n * - `confirmation` - A dialog with two buttons, one to confirm and one to\n * cancel.\n * - `prompt` - A dialog with two buttons and a text input.\n */\nexport enum DialogType {\n Alert = 'alert',\n Confirmation = 'confirmation',\n Prompt = 'prompt',\n}\n\n/**\n * An alert dialog.\n *\n * @property type - The type of dialog. Must be `alert`.\n * @property content - The content to display in the dialog.\n */\nexport type AlertDialog = {\n type: EnumToUnion<DialogType.Alert>;\n content: Component;\n};\n\n/**\n * A confirmation dialog.\n *\n * @property type - The type of dialog. Must be `confirmation`.\n * @property content - The content to display in the dialog.\n */\nexport type ConfirmationDialog = {\n type: EnumToUnion<DialogType.Confirmation>;\n content: Component;\n};\n\n/**\n * A prompt dialog.\n *\n * @property type - The type of dialog. Must be `prompt`.\n * @property content - The content to display in the dialog.\n * @property placeholder - An optional placeholder text to display in the text\n * input.\n */\nexport type PromptDialog = {\n type: EnumToUnion<DialogType.Prompt>;\n content: Component;\n placeholder?: string;\n};\n\n/**\n * The request parameters for the `snap_dialog` method.\n *\n * @property type - The type of dialog to display.\n * @property content - The content to display in the dialog.\n * @property placeholder - The placeholder text to display in the dialog. Only\n * applicable for the `prompt` dialog.\n */\nexport type DialogParams = AlertDialog | ConfirmationDialog | PromptDialog;\n\n/**\n * The result returned by the `snap_dialog` method.\n *\n * - If the dialog is an `alert`, the result is `null`.\n * - If the dialog is a `confirmation`, the result is a boolean indicating\n * whether the user confirmed the dialog.\n * - If the dialog is a `prompt`, the result is the value entered by\n * the user.\n */\nexport type DialogResult = null | boolean | string;\n"],"names":["DialogType","Alert","Confirmation","Prompt"],"mappings":"WAWO;UAAKA,UAAU;IAAVA,WACVC,WAAQ;IADED,WAEVE,kBAAe;IAFLF,WAGVG,YAAS;GAHCH,eAAAA"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=get-bip32-entropy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/get-bip32-entropy.ts"],"sourcesContent":["import type { JsonSLIP10Node } from '@metamask/key-tree';\n\nimport type { Bip32Entropy } from '../permissions';\n\n/**\n * The request parameters for the `snap_getBip32Entropy` method.\n *\n * @property path - The BIP-32 path to derive the entropy from.\n * @property curve - The curve to use when deriving the entropy.\n */\nexport type GetBip32EntropyParams = Bip32Entropy;\n\n/**\n * The result returned by the `snap_getBip32Entropy` method.\n *\n * @see https://github.com/MetaMask/key-tree#usage\n */\nexport type GetBip32EntropyResult = JsonSLIP10Node;\n"],"names":[],"mappings":"AAAA,WAiBmD"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=get-bip32-public-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/get-bip32-public-key.ts"],"sourcesContent":["import type { Bip32Entropy } from '../permissions';\n\n/**\n * The request parameters for the `snap_getBip32PublicKey` method.\n *\n * @property path - The BIP-32 path to derive the public key from.\n * @property curve - The curve to use when deriving the public key.\n * @property compressed - Whether to return the compressed public key. Defaults\n * to `false`.\n */\nexport type GetBip32PublicKeyParams = Bip32Entropy & {\n compressed?: boolean;\n};\n\n/**\n * The result returned by the `snap_getBip32PublicKey` method.\n *\n * It is the public key in hexadecimal format, in either compressed or\n * uncompressed format, depending on the `compressed` parameter.\n */\nexport type GetBip32PublicKeyResult = string;\n"],"names":[],"mappings":"AAAA,WAoB6C"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=get-bip44-entropy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/get-bip44-entropy.ts"],"sourcesContent":["import type { JsonBIP44CoinTypeNode } from '@metamask/key-tree';\n\nimport type { Bip44Entropy } from '../permissions';\n\n/**\n * The request parameters for the `snap_getBip44Entropy` method.\n *\n * @property coinType - The BIP-44 coin type to derive the entropy from.\n */\nexport type GetBip44EntropyParams = Bip44Entropy;\n\n/**\n * The result returned by the `snap_getBip44Entropy` method.\n *\n * @see https://github.com/MetaMask/key-tree#usage\n */\nexport type GetBip44EntropyResult = JsonBIP44CoinTypeNode;\n"],"names":[],"mappings":"AAAA,WAgB0D"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=get-entropy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/get-entropy.ts"],"sourcesContent":["import type { Hex } from '@metamask/utils';\n\n/**\n * The request parameters for the `snap_getEntropy` method.\n *\n * @property version - The version of the entropy to retrieve. This is used for\n * backwards compatibility. As of now, only version 1 is supported.\n * @property salt - The optional salt to use when deriving the entropy.\n */\nexport type GetEntropyParams = {\n version: 1;\n salt?: string;\n};\n\n/**\n * The result returned by the `snap_getEntropy` method.\n */\nexport type GetEntropyResult = Hex;\n"],"names":[],"mappings":"AAAA,WAiBmC"}
@@ -0,0 +1,8 @@
1
+ export var AuxiliaryFileEncoding;
2
+ (function(AuxiliaryFileEncoding) {
3
+ AuxiliaryFileEncoding["Base64"] = 'base64';
4
+ AuxiliaryFileEncoding["Hex"] = 'hex';
5
+ AuxiliaryFileEncoding["Utf8"] = 'utf8';
6
+ })(AuxiliaryFileEncoding || (AuxiliaryFileEncoding = {}));
7
+
8
+ //# sourceMappingURL=get-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/get-file.ts"],"sourcesContent":["import type { EnumToUnion } from '../../internals';\n\n/**\n * The encoding to use when retrieving the file. Defaults to `Base64`.\n */\nexport enum AuxiliaryFileEncoding {\n Base64 = 'base64',\n Hex = 'hex',\n Utf8 = 'utf8',\n}\n\n/**\n * The request parameters for the `snap_getFile` method.\n *\n * @property path - The path to the file to retrieve.\n * @property encoding - The encoding to use when retrieving the file.\n */\nexport type GetFileParams = {\n path: string;\n encoding?: EnumToUnion<AuxiliaryFileEncoding>;\n};\n\n/**\n * The result returned by the `snap_getFile` method.\n */\nexport type GetFileResult = string;\n"],"names":["AuxiliaryFileEncoding","Base64","Hex","Utf8"],"mappings":"WAKO;UAAKA,qBAAqB;IAArBA,sBACVC,YAAS;IADCD,sBAEVE,SAAM;IAFIF,sBAGVG,UAAO;GAHGH,0BAAAA"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The request parameters for the `snap_getLocale` method.
3
+ *
4
+ * This method does not accept any parameters.
5
+ */ export { };
6
+
7
+ //# sourceMappingURL=get-locale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/get-locale.ts"],"sourcesContent":["/**\n * The request parameters for the `snap_getLocale` method.\n *\n * This method does not accept any parameters.\n */\nexport type GetLocaleParams = never;\n\n/**\n * The result returned by the `snap_getLocale` method.\n *\n * It is the locale of the user's MetaMask extension.\n */\nexport type GetLocaleResult = string;\n"],"names":[],"mappings":"AAAA;;;;CAIC,GACD,WAOqC"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=get-snaps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/get-snaps.ts"],"sourcesContent":["import type { JsonRpcError } from '@metamask/utils';\n\nimport type { Snap, SnapId } from '../snap';\n\n/**\n * The request parameters for the `wallet_getSnaps` method.\n *\n * This method does not accept any parameters.\n */\nexport type GetSnapsParams = never;\n\n/**\n * The result returned by the `wallet_getSnaps` method.\n *\n * It consists of a map of Snap IDs to either the Snap object or an error.\n */\nexport type GetSnapsResult = Record<SnapId, { error: JsonRpcError } | Snap>;\n"],"names":[],"mappings":"AAAA,WAgB4E"}
@@ -0,0 +1,17 @@
1
+ export * from './dialog';
2
+ export * from './get-bip32-entropy';
3
+ export * from './get-bip32-public-key';
4
+ export * from './get-bip44-entropy';
5
+ export * from './get-entropy';
6
+ export * from './get-file';
7
+ export * from './get-locale';
8
+ export * from './get-snaps';
9
+ export * from './invoke-keyring';
10
+ export * from './invoke-snap';
11
+ export * from './manage-accounts';
12
+ export * from './manage-state';
13
+ export * from './methods';
14
+ export * from './notify';
15
+ export * from './request-snaps';
16
+
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/index.ts"],"sourcesContent":["export * from './dialog';\nexport * from './get-bip32-entropy';\nexport * from './get-bip32-public-key';\nexport * from './get-bip44-entropy';\nexport * from './get-entropy';\nexport * from './get-file';\nexport * from './get-locale';\nexport * from './get-snaps';\nexport * from './invoke-keyring';\nexport * from './invoke-snap';\nexport * from './manage-accounts';\nexport * from './manage-state';\nexport * from './methods';\nexport * from './notify';\nexport * from './request-snaps';\n"],"names":[],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,sBAAsB;AACpC,cAAc,yBAAyB;AACvC,cAAc,sBAAsB;AACpC,cAAc,gBAAgB;AAC9B,cAAc,aAAa;AAC3B,cAAc,eAAe;AAC7B,cAAc,cAAc;AAC5B,cAAc,mBAAmB;AACjC,cAAc,gBAAgB;AAC9B,cAAc,oBAAoB;AAClC,cAAc,iBAAiB;AAC/B,cAAc,YAAY;AAC1B,cAAc,WAAW;AACzB,cAAc,kBAAkB"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=invoke-keyring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/invoke-keyring.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\n\nimport type { InvokeSnapParams } from './invoke-snap';\n\n/**\n * The request parameters for the `wallet_invokeKeyring` method.\n *\n * @property snapId - The ID of the snap to invoke.\n * @property request - The JSON-RPC request to send to the snap.\n */\nexport type InvokeKeyringParams = InvokeSnapParams;\n\n/**\n * The result returned by the `wallet_invokeKeyring` method, which is the result\n * returned by the Snap.\n */\nexport type InvokeKeyringResult = Json;\n"],"names":[],"mappings":"AAAA,WAgBuC"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=invoke-snap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/invoke-snap.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\n\n/**\n * The request parameters for the `wallet_invokeSnap` method.\n *\n * @property snapId - The ID of the Snap to invoke.\n * @property request - The JSON-RPC request to send to the Snap.\n */\nexport type InvokeSnapParams = {\n snapId: string;\n request: Record<string, Json>;\n};\n\n/**\n * The result returned by the `wallet_invokeSnap` method, which is the result\n * returned by the Snap.\n */\nexport type InvokeSnapResult = Json;\n"],"names":[],"mappings":"AAAA,WAiBoC"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=manage-accounts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/manage-accounts.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\n\n/**\n * The request parameters for the `snap_manageAccounts` method.\n *\n * @property method - The method to call on the Snap.\n * @property params - The optional parameters to pass to the Snap method.\n */\nexport type ManageAccountsParams =\n | {\n method: string;\n }\n | {\n method: string;\n params: Json[] | Record<string, Json>;\n };\n\n/**\n * The result returned by the `snap_manageAccounts` method, which is the result\n * returned by the Snap.\n */\nexport type ManageAccountsResult = Json;\n"],"names":[],"mappings":"AAAA,WAqBwC"}
@@ -0,0 +1,8 @@
1
+ export var ManageStateOperation;
2
+ (function(ManageStateOperation) {
3
+ ManageStateOperation["ClearState"] = 'clear';
4
+ ManageStateOperation["GetState"] = 'get';
5
+ ManageStateOperation["UpdateState"] = 'update';
6
+ })(ManageStateOperation || (ManageStateOperation = {}));
7
+
8
+ //# sourceMappingURL=manage-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/manage-state.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\n\nimport type { EnumToUnion } from '../../internals';\n\n/**\n * The operations that can be performed on the state.\n */\nexport enum ManageStateOperation {\n ClearState = 'clear',\n GetState = 'get',\n UpdateState = 'update',\n}\n\n/**\n * The clear state operation, which clears the state.\n *\n * @property operation - The operation to perform on the state. Must be `clear`.\n * @property encrypted - Whether to use the separate encrypted state, or the\n * unencrypted state. Defaults to the encrypted state. Encrypted state can only\n * be used if the extension is unlocked, while unencrypted state can be used\n * whether the extension is locked or unlocked.\n */\nexport type ClearStateOperation = {\n operation: EnumToUnion<ManageStateOperation.ClearState>;\n encrypted?: boolean;\n};\n\n/**\n * The get state operation, which retrieves the state.\n *\n * @property operation - The operation to perform on the state. Must be `get`.\n * @property encrypted - Whether to use the separate encrypted state, or the\n * unencrypted state. Defaults to the encrypted state. Encrypted state can only\n * be used if the extension is unlocked, while unencrypted state can be used\n * whether the extension is locked or unlocked.\n */\nexport type GetStateOperation = {\n operation: EnumToUnion<ManageStateOperation.GetState>;\n encrypted?: boolean;\n};\n\n/**\n * The update state operation, which updates the state.\n *\n * @property operation - The operation to perform on the state. Must be\n * `update`.\n * @property encrypted - Whether to use the separate encrypted state, or the\n * unencrypted state. Defaults to the encrypted state. Encrypted state can only\n * be used if the extension is unlocked, while unencrypted state can be used\n * whether the extension is locked or unlocked.\n * @property newState - The new state to set.\n */\nexport type UpdateStateOperation = {\n operation: EnumToUnion<ManageStateOperation.UpdateState>;\n encrypted?: boolean;\n newState: Record<string, Json>;\n};\n\n/**\n * The request parameters for the `snap_manageState` method.\n *\n * @property operation - The operation to perform on the state.\n * @property encrypted - Whether to use the separate encrypted state, or the\n * unencrypted state. Defaults to the encrypted state.\n * @property newState - The new state to set. Only applicable for the `set`\n * operation.\n */\nexport type ManageStateParams =\n | ClearStateOperation\n | GetStateOperation\n | UpdateStateOperation;\n\n/**\n * The result returned by the `snap_manageState` method.\n *\n * If the operation is `get`, the result is the state. Otherwise, the result is\n * `null`.\n */\nexport type ManageStateResult = Record<string, Json> | null;\n"],"names":["ManageStateOperation","ClearState","GetState","UpdateState"],"mappings":"WAOO;UAAKA,oBAAoB;IAApBA,qBACVC,gBAAa;IADHD,qBAEVE,cAAW;IAFDF,qBAGVG,iBAAc;GAHJH,yBAAAA"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/methods.ts"],"sourcesContent":["import type { Method } from '../../internals';\nimport type { DialogParams, DialogResult } from './dialog';\nimport type {\n GetBip32EntropyParams,\n GetBip32EntropyResult,\n} from './get-bip32-entropy';\nimport type {\n GetBip32PublicKeyParams,\n GetBip32PublicKeyResult,\n} from './get-bip32-public-key';\nimport type {\n GetBip44EntropyParams,\n GetBip44EntropyResult,\n} from './get-bip44-entropy';\nimport type { GetEntropyParams, GetEntropyResult } from './get-entropy';\nimport type { GetFileParams, GetFileResult } from './get-file';\nimport type { GetLocaleParams, GetLocaleResult } from './get-locale';\nimport type { GetSnapsParams, GetSnapsResult } from './get-snaps';\nimport type {\n InvokeKeyringParams,\n InvokeKeyringResult,\n} from './invoke-keyring';\nimport type { InvokeSnapParams, InvokeSnapResult } from './invoke-snap';\nimport type {\n ManageAccountsParams,\n ManageAccountsResult,\n} from './manage-accounts';\nimport type { ManageStateParams, ManageStateResult } from './manage-state';\nimport type { NotifyParams, NotifyResult } from './notify';\nimport type { RequestSnapsParams, RequestSnapsResult } from './request-snaps';\n\n/**\n * The methods that are available to the Snap. Each method is a tuple of the\n * request parameters and the result returned by the method.\n */\nexport type SnapMethods = {\n /* eslint-disable @typescript-eslint/naming-convention */\n snap_dialog: [DialogParams, DialogResult];\n snap_getBip32Entropy: [GetBip32EntropyParams, GetBip32EntropyResult];\n snap_getBip32PublicKey: [GetBip32PublicKeyParams, GetBip32PublicKeyResult];\n snap_getBip44Entropy: [GetBip44EntropyParams, GetBip44EntropyResult];\n snap_getEntropy: [GetEntropyParams, GetEntropyResult];\n snap_getFile: [GetFileParams, GetFileResult];\n snap_getLocale: [GetLocaleParams, GetLocaleResult];\n snap_manageAccounts: [ManageAccountsParams, ManageAccountsResult];\n snap_manageState: [ManageStateParams, ManageStateResult];\n snap_notify: [NotifyParams, NotifyResult];\n wallet_getSnaps: [GetSnapsParams, GetSnapsResult];\n wallet_invokeKeyring: [InvokeKeyringParams, InvokeKeyringResult];\n wallet_invokeSnap: [InvokeSnapParams, InvokeSnapResult];\n wallet_snap: [InvokeSnapParams, InvokeSnapResult];\n wallet_requestSnaps: [RequestSnapsParams, RequestSnapsResult];\n /* eslint-enable @typescript-eslint/naming-convention */\n};\n\n/**\n * The request function that is available to the Snap. It takes a request\n * object and returns a promise that resolves to the result of the request.\n *\n * @param request - The request object.\n * @param request.method - The method to call.\n * @param request.params - The parameters to pass to the method. This is\n * inferred from the method, based on the {@link SnapMethods} type, and may be\n * optional.\n * @returns A promise that resolves to the result of the request. This is\n * inferred from the request method, based on the {@link SnapMethods} type.\n * @example\n * // Get the user's locale\n * const result = await request({\n * method: 'snap_getLocale',\n * });\n * @example\n * // Get a file\n * const result = await request({\n * method: 'snap_getFile',\n * params: {\n * path: 'foo/bar.txt',\n * },\n * });\n */\nexport type RequestFunction = <MethodName extends keyof SnapMethods>(\n request: Method<MethodName, SnapMethods[MethodName][0]>,\n) => Promise<SnapMethods[MethodName][1]>;\n"],"names":[],"mappings":"AAAA,WAkFyC"}
@@ -0,0 +1,7 @@
1
+ export var NotificationType;
2
+ (function(NotificationType) {
3
+ NotificationType["InApp"] = 'inApp';
4
+ NotificationType["Native"] = 'native';
5
+ })(NotificationType || (NotificationType = {}));
6
+
7
+ //# sourceMappingURL=notify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/notify.ts"],"sourcesContent":["import type { EnumToUnion } from '../../internals';\n\n/**\n * The types of notifications that can be displayed.\n *\n * - `InApp` - A notification that is displayed in by the MetaMask extension.\n * - `Native` - A notification that is displayed by the operating system.\n */\nexport enum NotificationType {\n InApp = 'inApp',\n Native = 'native',\n}\n\n/**\n * The request parameters for the `snap_notify` method.\n *\n * @property type - The type of notification to display.\n * @property message - The message to display in the notification.\n */\nexport type NotifyParams = {\n type: EnumToUnion<NotificationType>;\n message: string;\n};\n\n/**\n * The result returned by the `snap_notify` method.\n *\n * This method does not return anything.\n */\nexport type NotifyResult = null;\n"],"names":["NotificationType","InApp","Native"],"mappings":"WAQO;UAAKA,gBAAgB;IAAhBA,iBACVC,WAAQ;IADED,iBAEVE,YAAS;GAFCF,qBAAAA"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=request-snaps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/methods/request-snaps.ts"],"sourcesContent":["import type { JsonRpcError } from '@metamask/utils';\n\nimport type { Snap } from '../snap';\n\n/**\n * The request parameters for the `wallet_requestSnaps` method.\n *\n * It consists of a map of Snap IDs to optional version strings to request.\n */\nexport type RequestSnapsParams = Record<string, { version?: string }>;\n\n/**\n * The result returned by the `wallet_requestSnaps` method.\n *\n * It consists of a map of Snap IDs to either the Snap object or an error.\n */\nexport type RequestSnapsResult = Record<string, { error: JsonRpcError } | Snap>;\n"],"names":[],"mappings":"AAAA,WAgBgF"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/types/permissions.ts"],"sourcesContent":["import type { JsonRpcRequest } from '@metamask/utils';\n\nimport type { ChainId } from './caip';\n\nexport type EmptyObject = Record<string, never>;\n\nexport type Cronjob = {\n expression: string;\n request: Omit<JsonRpcRequest, 'jsonrpc' | 'id'>;\n};\n\nexport type Bip32Entropy = {\n curve: 'secp256k1' | 'ed25519';\n path: string[];\n};\n\nexport type Bip44Entropy = {\n coinType: number;\n};\n\nexport type RequestedSnap = {\n version?: string;\n};\n\nexport type InitialPermissions = {\n 'endowment:cronjob'?: {\n jobs: Cronjob[];\n };\n 'endowment:keyring'?: {\n allowedOrigins?: string[];\n };\n 'endowment:name-lookup'?: ChainId[];\n 'endowment:network-access'?: EmptyObject;\n 'endowment:rpc'?: {\n dapps?: boolean;\n snaps?: boolean;\n allowedOrigins?: string[];\n };\n 'endowment:transaction-insight'?: {\n allowTransactionOrigin?: boolean;\n };\n 'endowment:webassembly'?: EmptyObject;\n\n /* eslint-disable @typescript-eslint/naming-convention */\n snap_confirm?: EmptyObject;\n snap_dialog?: EmptyObject;\n snap_getBip32Entropy?: Bip32Entropy[];\n snap_getBip32PublicKey?: Bip32Entropy[];\n snap_getBip44Entropy?: Bip44Entropy[];\n snap_getEntropy?: EmptyObject;\n snap_manageAccounts?: EmptyObject;\n snap_manageState?: EmptyObject;\n snap_notify?: EmptyObject;\n wallet_snap?: Record<string, RequestedSnap>;\n /* eslint-enable @typescript-eslint/naming-convention */\n};\n"],"names":[],"mappings":"AAAA,WAuDE"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/types/provider.ts"],"sourcesContent":["import type { BaseProvider } from '@metamask/providers';\n\nimport type { RequestFunction } from './methods';\n\ntype BaseProviderInstance = InstanceType<typeof BaseProvider>;\n\n/**\n * The `window.ethereum` provider for Snaps.\n */\nexport type SnapsEthereumProvider = Pick<\n BaseProviderInstance,\n // Snaps have access to a limited set of methods. This is enforced by the\n // `proxyStreamProvider` function in `@metamask/snaps-execution-environments`.\n 'request' | 'on' | 'removeListener'\n>;\n\n/**\n * The `window.snap` provider.\n */\nexport type SnapsProvider = {\n request: RequestFunction;\n};\n"],"names":[],"mappings":"AAAA,WAqBE"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=snap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/types/snap.ts"],"sourcesContent":["import type { SemVerVersion, Opaque } from '@metamask/utils';\n\nimport type { InitialPermissions } from './permissions';\n\nexport type SnapId = Opaque<string, typeof snapIdSymbol>;\ndeclare const snapIdSymbol: unique symbol;\n\nexport type Snap = {\n id: SnapId;\n initialPermissions: InitialPermissions;\n version: SemVerVersion;\n enabled: boolean;\n blocked: boolean;\n};\n"],"names":[],"mappings":"AAAA,WAaE"}
@@ -0,0 +1,50 @@
1
+ import { assertStruct, isPlainObject } from '@metamask/utils';
2
+ /**
3
+ * A function that returns a function to "build" a {@link Component}. It infers
4
+ * the type of the component from the given struct, and performs validation on
5
+ * the created component.
6
+ *
7
+ * The returned function can handle the node arguments in two ways:
8
+ * 1. As a single object, with the keys corresponding to the node's properties,
9
+ * excluding the `type` property.
10
+ * 2. As an array of arguments, with the order corresponding to the given keys.
11
+ *
12
+ * @param type - The type of the component to build.
13
+ * @param struct - The struct to use to validate the component.
14
+ * @param keys - The keys of the component to use as arguments to the builder.
15
+ * The order of the keys determines the order of the arguments.
16
+ * @returns A function that builds a component of the given type.
17
+ * @internal
18
+ */ export function createBuilder(type, struct, keys = []) {
19
+ return (...args)=>{
20
+ // Node passed as a single object.
21
+ if (args.length === 1 && isPlainObject(args[0])) {
22
+ const node = {
23
+ ...args[0],
24
+ type
25
+ };
26
+ // The user could be passing invalid values to the builder, so we need to
27
+ // validate them as per the component's struct.
28
+ assertStruct(node, struct, `Invalid ${type} component`);
29
+ return node;
30
+ }
31
+ // Node passed as an array of arguments.
32
+ const node = keys.reduce((partialNode, key, index)=>{
33
+ if (args[index] !== undefined) {
34
+ return {
35
+ ...partialNode,
36
+ [key]: args[index]
37
+ };
38
+ }
39
+ return partialNode;
40
+ }, {
41
+ type
42
+ });
43
+ // The user could be passing invalid values to the builder, so we need to
44
+ // validate them as per the component's struct.
45
+ assertStruct(node, struct, `Invalid ${type} component`);
46
+ return node;
47
+ };
48
+ }
49
+
50
+ //# sourceMappingURL=builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/ui/builder.ts"],"sourcesContent":["import { assertStruct, isPlainObject } from '@metamask/utils';\nimport type { Struct } from 'superstruct';\n\nimport type { Component } from './components';\nimport type { NodeType } from './nodes';\n\n/**\n * A function that builds a {@link Component}. This infers the proper args type\n * from the given node.\n *\n * @internal\n */\ntype NodeBuilder<Node extends Component, Keys extends (keyof Node)[]> = Omit<\n Node,\n 'type'\n> extends Record<string, never>\n ? (...args: []) => Node\n : (...args: [Omit<Node, 'type'>] | NodeArrayType<Node, Keys>) => Node;\n\n/**\n * Map from an array of node keys to the corresponding array type.\n *\n * @example\n * type Node = { type: 'node'; a: string; b: number; c: boolean };\n * type Keys = ['a', 'b', 'c'];\n *\n * type NodeArray = NodeArrayType<Node, Keys>; // [string, number, boolean]\n * @internal\n */\ntype NodeArrayType<Node extends Component, Keys extends (keyof Node)[]> = {\n [Key in keyof Keys]: Node[Keys[Key]];\n};\n\n/**\n * A function that returns a function to \"build\" a {@link Component}. It infers\n * the type of the component from the given struct, and performs validation on\n * the created component.\n *\n * The returned function can handle the node arguments in two ways:\n * 1. As a single object, with the keys corresponding to the node's properties,\n * excluding the `type` property.\n * 2. As an array of arguments, with the order corresponding to the given keys.\n *\n * @param type - The type of the component to build.\n * @param struct - The struct to use to validate the component.\n * @param keys - The keys of the component to use as arguments to the builder.\n * The order of the keys determines the order of the arguments.\n * @returns A function that builds a component of the given type.\n * @internal\n */\nexport function createBuilder<\n Node extends Component,\n Keys extends (keyof Node)[] = [],\n>(\n type: NodeType,\n struct: Struct<Node>,\n keys: Keys = [] as unknown as Keys,\n): NodeBuilder<Node, Keys> {\n return (...args: [Omit<Node, 'type'>] | NodeArrayType<Node, Keys> | []) => {\n // Node passed as a single object.\n if (args.length === 1 && isPlainObject(args[0])) {\n const node = { ...args[0], type };\n\n // The user could be passing invalid values to the builder, so we need to\n // validate them as per the component's struct.\n assertStruct(node, struct, `Invalid ${type} component`);\n return node;\n }\n\n // Node passed as an array of arguments.\n const node = keys.reduce<Partial<Component>>(\n (partialNode, key, index) => {\n if (args[index] !== undefined) {\n return {\n ...partialNode,\n [key]: args[index],\n };\n }\n\n return partialNode;\n },\n { type },\n );\n\n // The user could be passing invalid values to the builder, so we need to\n // validate them as per the component's struct.\n assertStruct(node, struct, `Invalid ${type} component`);\n return node;\n };\n}\n"],"names":["assertStruct","isPlainObject","createBuilder","type","struct","keys","args","length","node","reduce","partialNode","key","index","undefined"],"mappings":"AAAA,SAASA,YAAY,EAAEC,aAAa,QAAQ,kBAAkB;AAiC9D;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASC,cAIdC,IAAc,EACdC,MAAoB,EACpBC,OAAa,EAAE,AAAmB;IAElC,OAAO,CAAC,GAAGC;QACT,kCAAkC;QAClC,IAAIA,KAAKC,MAAM,KAAK,KAAKN,cAAcK,IAAI,CAAC,EAAE,GAAG;YAC/C,MAAME,OAAO;gBAAE,GAAGF,IAAI,CAAC,EAAE;gBAAEH;YAAK;YAEhC,yEAAyE;YACzE,+CAA+C;YAC/CH,aAAaQ,MAAMJ,QAAQ,CAAC,QAAQ,EAAED,KAAK,UAAU,CAAC;YACtD,OAAOK;QACT;QAEA,wCAAwC;QACxC,MAAMA,OAAOH,KAAKI,MAAM,CACtB,CAACC,aAAaC,KAAKC;YACjB,IAAIN,IAAI,CAACM,MAAM,KAAKC,WAAW;gBAC7B,OAAO;oBACL,GAAGH,WAAW;oBACd,CAACC,IAAI,EAAEL,IAAI,CAACM,MAAM;gBACpB;YACF;YAEA,OAAOF;QACT,GACA;YAAEP;QAAK;QAGT,yEAAyE;QACzE,+CAA+C;QAC/CH,aAAaQ,MAAMJ,QAAQ,CAAC,QAAQ,EAAED,KAAK,UAAU,CAAC;QACtD,OAAOK;IACT;AACF"}
@@ -0,0 +1,23 @@
1
+ import { assertStruct } from '@metamask/utils';
2
+ import { is } from 'superstruct';
3
+ import { ComponentStruct } from './components';
4
+ /**
5
+ * Check if the given value is a {@link Component}. This performs recursive
6
+ * validation of the component's children (if any).
7
+ *
8
+ * @param value - The value to check.
9
+ * @returns `true` if the value is a {@link Component}, `false` otherwise.
10
+ */ export function isComponent(value) {
11
+ return is(value, ComponentStruct);
12
+ }
13
+ /**
14
+ * Assert that the given value is a {@link Component}. This performs recursive
15
+ * validation of the component's children (if any).
16
+ *
17
+ * @param value - The value to check.
18
+ * @throws If the value is not a {@link Component}.
19
+ */ export function assertIsComponent(value) {
20
+ assertStruct(value, ComponentStruct, 'Invalid component');
21
+ }
22
+
23
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/ui/component.ts"],"sourcesContent":["import { assertStruct } from '@metamask/utils';\nimport { is } from 'superstruct';\n\nimport { ComponentStruct } from './components';\nimport type { Component } from './components';\n\n/**\n * Check if the given value is a {@link Component}. This performs recursive\n * validation of the component's children (if any).\n *\n * @param value - The value to check.\n * @returns `true` if the value is a {@link Component}, `false` otherwise.\n */\nexport function isComponent(value: unknown): value is Component {\n return is(value, ComponentStruct);\n}\n\n/**\n * Assert that the given value is a {@link Component}. This performs recursive\n * validation of the component's children (if any).\n *\n * @param value - The value to check.\n * @throws If the value is not a {@link Component}.\n */\nexport function assertIsComponent(value: unknown): asserts value is Component {\n assertStruct(value, ComponentStruct, 'Invalid component');\n}\n"],"names":["assertStruct","is","ComponentStruct","isComponent","value","assertIsComponent"],"mappings":"AAAA,SAASA,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,EAAE,QAAQ,cAAc;AAEjC,SAASC,eAAe,QAAQ,eAAe;AAG/C;;;;;;CAMC,GACD,OAAO,SAASC,YAAYC,KAAc;IACxC,OAAOH,GAAGG,OAAOF;AACnB;AAEA;;;;;;CAMC,GACD,OAAO,SAASG,kBAAkBD,KAAc;IAC9CJ,aAAaI,OAAOF,iBAAiB;AACvC"}
@@ -0,0 +1,27 @@
1
+ import { assign, boolean, literal, object, optional, string } from 'superstruct';
2
+ import { createBuilder } from '../builder';
3
+ import { LiteralStruct, NodeType } from '../nodes';
4
+ export const CopyableStruct = assign(LiteralStruct, object({
5
+ type: literal(NodeType.Copyable),
6
+ value: string(),
7
+ sensitive: optional(boolean())
8
+ }));
9
+ /**
10
+ * Create a {@link Copyable} component.
11
+ *
12
+ * @param args - The node arguments. This can either be a string, or an object
13
+ * with the `text` property.
14
+ * @param args.value - The text to be copied.
15
+ * @param args.sensitive - Whether the value is sensitive or not. Sensitive
16
+ * values are only displayed to the user after clicking on the component.
17
+ * Defaults to false.
18
+ * @returns A {@link Copyable} component.
19
+ * @example
20
+ * const node = copyable('Hello, world!');
21
+ * const node = copyable({ value: 'Hello, world!' });
22
+ */ export const copyable = createBuilder(NodeType.Copyable, CopyableStruct, [
23
+ 'value',
24
+ 'sensitive'
25
+ ]);
26
+
27
+ //# sourceMappingURL=copyable.js.map