@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
package/CHANGELOG.md CHANGED
@@ -6,4 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
- [Unreleased]: https://github.com/MetaMask/snaps/
9
+ ## [1.1.0]
10
+ ### Added
11
+ - Add Snap error wrappers of JSON-RPC errors ([#1924](https://github.com/MetaMask/snaps/pull/1924))
12
+
13
+ ## [1.0.0]
14
+ ### Added
15
+ - Initial release of this package.
16
+
17
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.1.0...HEAD
18
+ [1.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.0.0...@metamask/snaps-sdk@1.1.0
19
+ [1.0.0]: https://github.com/MetaMask/snaps/releases/tag/@metamask/snaps-sdk@1.0.0
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ InternalError: function() {
13
+ return InternalError;
14
+ },
15
+ InvalidInputError: function() {
16
+ return InvalidInputError;
17
+ },
18
+ InvalidParamsError: function() {
19
+ return InvalidParamsError;
20
+ },
21
+ InvalidRequestError: function() {
22
+ return InvalidRequestError;
23
+ },
24
+ LimitExceededError: function() {
25
+ return LimitExceededError;
26
+ },
27
+ MethodNotFoundError: function() {
28
+ return MethodNotFoundError;
29
+ },
30
+ MethodNotSupportedError: function() {
31
+ return MethodNotSupportedError;
32
+ },
33
+ ParseError: function() {
34
+ return ParseError;
35
+ },
36
+ ResourceNotFoundError: function() {
37
+ return ResourceNotFoundError;
38
+ },
39
+ ResourceUnavailableError: function() {
40
+ return ResourceUnavailableError;
41
+ },
42
+ TransactionRejected: function() {
43
+ return TransactionRejected;
44
+ },
45
+ ChainDisconnectedError: function() {
46
+ return ChainDisconnectedError;
47
+ },
48
+ DisconnectedError: function() {
49
+ return DisconnectedError;
50
+ },
51
+ UnauthorizedError: function() {
52
+ return UnauthorizedError;
53
+ },
54
+ UnsupportedMethodError: function() {
55
+ return UnsupportedMethodError;
56
+ },
57
+ UserRejectedRequestError: function() {
58
+ return UserRejectedRequestError;
59
+ }
60
+ });
61
+ const _rpcerrors = require("@metamask/rpc-errors");
62
+ const _internals = require("./internals");
63
+ const InternalError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.internal);
64
+ const InvalidInputError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.invalidInput);
65
+ const InvalidParamsError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.invalidParams);
66
+ const InvalidRequestError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.invalidRequest);
67
+ const LimitExceededError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.limitExceeded);
68
+ const MethodNotFoundError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.methodNotFound);
69
+ const MethodNotSupportedError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.methodNotSupported);
70
+ const ParseError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.parse);
71
+ const ResourceNotFoundError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.resourceNotFound);
72
+ const ResourceUnavailableError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.resourceUnavailable);
73
+ const TransactionRejected = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.transactionRejected);
74
+ const ChainDisconnectedError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.chainDisconnected);
75
+ const DisconnectedError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.disconnected);
76
+ const UnauthorizedError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.unauthorized);
77
+ const UnsupportedMethodError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.unsupportedMethod);
78
+ const UserRejectedRequestError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.userRejectedRequest);
79
+
80
+ //# sourceMappingURL=error-wrappers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/error-wrappers.ts"],"sourcesContent":["import { providerErrors, rpcErrors } from '@metamask/rpc-errors';\n\nimport { createSnapError } from './internals';\n\n/**\n * A JSON-RPC 2.0 Internal (-32603) error.\n *\n * This can be thrown by a Snap to indicate that an internal error occurred,\n * without crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const InternalError = createSnapError(rpcErrors.internal);\n\n/**\n * An Ethereum JSON-RPC Invalid Input (-32000) error.\n *\n * This can be thrown by a Snap to indicate that the input to a method is\n * invalid, without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const InvalidInputError = createSnapError(rpcErrors.invalidInput);\n\n/**\n * A JSON-RPC 2.0 Invalid Params (-32602) error.\n *\n * This can be thrown by a Snap to indicate that the parameters to a method are\n * invalid, without crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const InvalidParamsError = createSnapError(rpcErrors.invalidParams);\n\n/**\n * A JSON-RPC 2.0 Invalid Request (-32600) error.\n *\n * This can be thrown by a Snap to indicate that the request is invalid, without\n * crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const InvalidRequestError = createSnapError(rpcErrors.invalidRequest);\n\n/**\n * An Ethereum JSON-RPC Limit Exceeded (-32005) error.\n *\n * This can be thrown by a Snap to indicate that a limit has been exceeded,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const LimitExceededError = createSnapError(rpcErrors.limitExceeded);\n\n/**\n * An Ethereum JSON-RPC Method Not Found (-32601) error.\n *\n * This can be thrown by a Snap to indicate that a method does not exist,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const MethodNotFoundError = createSnapError(rpcErrors.methodNotFound);\n\n/**\n * An Ethereum JSON-RPC Method Not Supported (-32004) error.\n *\n * This can be thrown by a Snap to indicate that a method is not supported,\n * without crashing the Snap.\n */\nexport const MethodNotSupportedError = createSnapError(\n rpcErrors.methodNotSupported,\n);\n\n/**\n * A JSON-RPC 2.0 Parse (-32700) error.\n *\n * This can be thrown by a Snap to indicate that a request is not valid JSON,\n * without crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const ParseError = createSnapError(rpcErrors.parse);\n\n/**\n * An Ethereum JSON-RPC Resource Not Found (-32001) error.\n *\n * This can be thrown by a Snap to indicate that a resource does not exist,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const ResourceNotFoundError = createSnapError(\n rpcErrors.resourceNotFound,\n);\n\n/**\n * An Ethereum JSON-RPC Resource Unavailable (-32002) error.\n *\n * This can be thrown by a Snap to indicate that a resource is unavailable,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const ResourceUnavailableError = createSnapError(\n rpcErrors.resourceUnavailable,\n);\n\n/**\n * An Ethereum JSON-RPC Transaction Rejected (-32003) error.\n *\n * This can be thrown by a Snap to indicate that a transaction was rejected,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const TransactionRejected = createSnapError(\n rpcErrors.transactionRejected,\n);\n\n/**\n * An Ethereum Provider Chain Disconnected (4901) error.\n *\n * This can be thrown by a Snap to indicate that the provider is disconnected\n * from the requested chain, without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const ChainDisconnectedError = createSnapError(\n providerErrors.chainDisconnected,\n);\n\n/**\n * An Ethereum Provider Disconnected (4900) error.\n *\n * This can be thrown by a Snap to indicate that the provider is disconnected,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const DisconnectedError = createSnapError(providerErrors.disconnected);\n\n/**\n * An Ethereum Provider Unauthorized (4100) error.\n *\n * This can be thrown by a Snap to indicate that the requested method / account\n * is not authorized by the user, without crashing the Snap.\n */\nexport const UnauthorizedError = createSnapError(providerErrors.unauthorized);\n\n/**\n * An Ethereum Provider Unsupported Method (4200) error.\n *\n * This can be thrown by a Snap to indicate that the requested method is not\n * supported by the provider, without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const UnsupportedMethodError = createSnapError(\n providerErrors.unsupportedMethod,\n);\n\n/**\n * An Ethereum Provider User Rejected Request (4001) error.\n *\n * This can be thrown by a Snap to indicate that the user rejected the request,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const UserRejectedRequestError = createSnapError(\n providerErrors.userRejectedRequest,\n);\n"],"names":["InternalError","InvalidInputError","InvalidParamsError","InvalidRequestError","LimitExceededError","MethodNotFoundError","MethodNotSupportedError","ParseError","ResourceNotFoundError","ResourceUnavailableError","TransactionRejected","ChainDisconnectedError","DisconnectedError","UnauthorizedError","UnsupportedMethodError","UserRejectedRequestError","createSnapError","rpcErrors","internal","invalidInput","invalidParams","invalidRequest","limitExceeded","methodNotFound","methodNotSupported","parse","resourceNotFound","resourceUnavailable","transactionRejected","providerErrors","chainDisconnected","disconnected","unauthorized","unsupportedMethod","userRejectedRequest"],"mappings":";;;;;;;;;;;IAYaA,aAAa;eAAbA;;IAUAC,iBAAiB;eAAjBA;;IAUAC,kBAAkB;eAAlBA;;IAUAC,mBAAmB;eAAnBA;;IAUAC,kBAAkB;eAAlBA;;IAUAC,mBAAmB;eAAnBA;;IAQAC,uBAAuB;eAAvBA;;IAYAC,UAAU;eAAVA;;IAUAC,qBAAqB;eAArBA;;IAYAC,wBAAwB;eAAxBA;;IAYAC,mBAAmB;eAAnBA;;IAYAC,sBAAsB;eAAtBA;;IAYAC,iBAAiB;eAAjBA;;IAQAC,iBAAiB;eAAjBA;;IAUAC,sBAAsB;eAAtBA;;IAYAC,wBAAwB;eAAxBA;;;2BA1K6B;2BAEV;AAUzB,MAAMf,gBAAgBgB,IAAAA,0BAAe,EAACC,oBAAS,CAACC,QAAQ;AAUxD,MAAMjB,oBAAoBe,IAAAA,0BAAe,EAACC,oBAAS,CAACE,YAAY;AAUhE,MAAMjB,qBAAqBc,IAAAA,0BAAe,EAACC,oBAAS,CAACG,aAAa;AAUlE,MAAMjB,sBAAsBa,IAAAA,0BAAe,EAACC,oBAAS,CAACI,cAAc;AAUpE,MAAMjB,qBAAqBY,IAAAA,0BAAe,EAACC,oBAAS,CAACK,aAAa;AAUlE,MAAMjB,sBAAsBW,IAAAA,0BAAe,EAACC,oBAAS,CAACM,cAAc;AAQpE,MAAMjB,0BAA0BU,IAAAA,0BAAe,EACpDC,oBAAS,CAACO,kBAAkB;AAWvB,MAAMjB,aAAaS,IAAAA,0BAAe,EAACC,oBAAS,CAACQ,KAAK;AAUlD,MAAMjB,wBAAwBQ,IAAAA,0BAAe,EAClDC,oBAAS,CAACS,gBAAgB;AAWrB,MAAMjB,2BAA2BO,IAAAA,0BAAe,EACrDC,oBAAS,CAACU,mBAAmB;AAWxB,MAAMjB,sBAAsBM,IAAAA,0BAAe,EAChDC,oBAAS,CAACW,mBAAmB;AAWxB,MAAMjB,yBAAyBK,IAAAA,0BAAe,EACnDa,yBAAc,CAACC,iBAAiB;AAW3B,MAAMlB,oBAAoBI,IAAAA,0BAAe,EAACa,yBAAc,CAACE,YAAY;AAQrE,MAAMlB,oBAAoBG,IAAAA,0BAAe,EAACa,yBAAc,CAACG,YAAY;AAUrE,MAAMlB,yBAAyBE,IAAAA,0BAAe,EACnDa,yBAAc,CAACI,iBAAiB;AAW3B,MAAMlB,2BAA2BC,IAAAA,0BAAe,EACrDa,yBAAc,CAACK,mBAAmB"}
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "SnapError", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return SnapError;
9
+ }
10
+ });
11
+ const _internals = require("./internals");
12
+ function _check_private_redeclaration(obj, privateCollection) {
13
+ if (privateCollection.has(obj)) {
14
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
15
+ }
16
+ }
17
+ function _class_apply_descriptor_get(receiver, descriptor) {
18
+ if (descriptor.get) {
19
+ return descriptor.get.call(receiver);
20
+ }
21
+ return descriptor.value;
22
+ }
23
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
24
+ if (descriptor.set) {
25
+ descriptor.set.call(receiver, value);
26
+ } else {
27
+ if (!descriptor.writable) {
28
+ throw new TypeError("attempted to set read only private field");
29
+ }
30
+ descriptor.value = value;
31
+ }
32
+ }
33
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
34
+ if (!privateMap.has(receiver)) {
35
+ throw new TypeError("attempted to " + action + " private field on non-instance");
36
+ }
37
+ return privateMap.get(receiver);
38
+ }
39
+ function _class_private_field_get(receiver, privateMap) {
40
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
41
+ return _class_apply_descriptor_get(receiver, descriptor);
42
+ }
43
+ function _class_private_field_init(obj, privateMap, value) {
44
+ _check_private_redeclaration(obj, privateMap);
45
+ privateMap.set(obj, value);
46
+ }
47
+ function _class_private_field_set(receiver, privateMap, value) {
48
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
49
+ _class_apply_descriptor_set(receiver, descriptor, value);
50
+ return value;
51
+ }
52
+ var _code = /*#__PURE__*/ new WeakMap(), _message = /*#__PURE__*/ new WeakMap(), _data = /*#__PURE__*/ new WeakMap(), _stack = /*#__PURE__*/ new WeakMap();
53
+ class SnapError extends Error {
54
+ /**
55
+ * The error name.
56
+ *
57
+ * @returns The error name.
58
+ */ get name() {
59
+ return 'SnapError';
60
+ }
61
+ /**
62
+ * The error code.
63
+ *
64
+ * @returns The error code.
65
+ */ get code() {
66
+ return _class_private_field_get(this, _code);
67
+ }
68
+ /**
69
+ * The error message.
70
+ *
71
+ * @returns The error message.
72
+ */ // This line is covered, but Jest doesn't pick it up for some reason.
73
+ /* istanbul ignore next */ get message() {
74
+ return _class_private_field_get(this, _message);
75
+ }
76
+ /**
77
+ * Additional data for the error.
78
+ *
79
+ * @returns Additional data for the error.
80
+ */ get data() {
81
+ return _class_private_field_get(this, _data);
82
+ }
83
+ /**
84
+ * The error stack.
85
+ *
86
+ * @returns The error stack.
87
+ */ // This line is covered, but Jest doesn't pick it up for some reason.
88
+ /* istanbul ignore next */ get stack() {
89
+ return _class_private_field_get(this, _stack);
90
+ }
91
+ /**
92
+ * Convert the error to a JSON object.
93
+ *
94
+ * @returns The JSON object.
95
+ */ toJSON() {
96
+ return {
97
+ code: _internals.SNAP_ERROR_CODE,
98
+ message: _internals.SNAP_ERROR_MESSAGE,
99
+ data: {
100
+ cause: {
101
+ code: this.code,
102
+ message: this.message,
103
+ stack: this.stack,
104
+ data: this.data
105
+ }
106
+ }
107
+ };
108
+ }
109
+ /**
110
+ * Serialize the error to a JSON object. This is called by
111
+ * `@metamask/rpc-errors` when serializing the error.
112
+ *
113
+ * @returns The JSON object.
114
+ */ serialize() {
115
+ return this.toJSON();
116
+ }
117
+ /**
118
+ * Create a new `SnapError`.
119
+ *
120
+ * @param error - The error to create the `SnapError` from. If this is a
121
+ * `string`, it will be used as the error message. If this is an `Error`, its
122
+ * `message` property will be used as the error message. If this is a
123
+ * `JsonRpcError`, its `message` property will be used as the error message
124
+ * and its `code` property will be used as the error code. Otherwise, the
125
+ * error will be converted to a string and used as the error message.
126
+ * @param data - Additional data to include in the error. This will be merged
127
+ * with the error data, if any.
128
+ */ constructor(error, data = {}){
129
+ const message = (0, _internals.getErrorMessage)(error);
130
+ super(message);
131
+ _class_private_field_init(this, _code, {
132
+ writable: true,
133
+ value: void 0
134
+ });
135
+ _class_private_field_init(this, _message, {
136
+ writable: true,
137
+ value: void 0
138
+ });
139
+ _class_private_field_init(this, _data, {
140
+ writable: true,
141
+ value: void 0
142
+ });
143
+ _class_private_field_init(this, _stack, {
144
+ writable: true,
145
+ value: void 0
146
+ });
147
+ _class_private_field_set(this, _message, message);
148
+ _class_private_field_set(this, _code, (0, _internals.getErrorCode)(error));
149
+ _class_private_field_set(this, _data, {
150
+ ...(0, _internals.getErrorData)(error),
151
+ ...data
152
+ });
153
+ _class_private_field_set(this, _stack, super.stack);
154
+ }
155
+ }
156
+
157
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/errors.ts"],"sourcesContent":["import type { Json, JsonRpcError } from '@metamask/utils';\n\nimport {\n getErrorCode,\n getErrorData,\n getErrorMessage,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n} from './internals';\n\n/**\n * A generic error which can be thrown by a Snap, without it causing the Snap to\n * crash.\n */\nexport class SnapError extends Error {\n readonly #code: number;\n\n readonly #message: string;\n\n readonly #data: Record<string, Json>;\n\n readonly #stack?: string;\n\n /**\n * Create a new `SnapError`.\n *\n * @param error - The error to create the `SnapError` from. If this is a\n * `string`, it will be used as the error message. If this is an `Error`, its\n * `message` property will be used as the error message. If this is a\n * `JsonRpcError`, its `message` property will be used as the error message\n * and its `code` property will be used as the error code. Otherwise, the\n * error will be converted to a string and used as the error message.\n * @param data - Additional data to include in the error. This will be merged\n * with the error data, if any.\n */\n constructor(\n error: string | Error | JsonRpcError,\n data: Record<string, Json> = {},\n ) {\n const message = getErrorMessage(error);\n super(message);\n\n this.#message = message;\n this.#code = getErrorCode(error);\n this.#data = { ...getErrorData(error), ...data };\n this.#stack = super.stack;\n }\n\n /**\n * The error name.\n *\n * @returns The error name.\n */\n get name() {\n return 'SnapError';\n }\n\n /**\n * The error code.\n *\n * @returns The error code.\n */\n get code() {\n return this.#code;\n }\n\n /**\n * The error message.\n *\n * @returns The error message.\n */\n // This line is covered, but Jest doesn't pick it up for some reason.\n /* istanbul ignore next */\n get message() {\n return this.#message;\n }\n\n /**\n * Additional data for the error.\n *\n * @returns Additional data for the error.\n */\n get data() {\n return this.#data;\n }\n\n /**\n * The error stack.\n *\n * @returns The error stack.\n */\n // This line is covered, but Jest doesn't pick it up for some reason.\n /* istanbul ignore next */\n get stack() {\n return this.#stack;\n }\n\n /**\n * Convert the error to a JSON object.\n *\n * @returns The JSON object.\n */\n toJSON(): SerializedSnapError {\n return {\n code: SNAP_ERROR_CODE,\n message: SNAP_ERROR_MESSAGE,\n data: {\n cause: {\n code: this.code,\n message: this.message,\n stack: this.stack,\n data: this.data,\n },\n },\n };\n }\n\n /**\n * Serialize the error to a JSON object. This is called by\n * `@metamask/rpc-errors` when serializing the error.\n *\n * @returns The JSON object.\n */\n serialize() {\n return this.toJSON();\n }\n}\n\n/**\n * A serialized {@link SnapError}. It's JSON-serializable, so it can be sent\n * over the RPC. The original error is wrapped in the `cause` property.\n *\n * @property code - The error code. This is always `-31002`.\n * @property message - The error message. This is always `'Snap Error'`.\n * @property data - The error data.\n * @property data.cause - The cause of the error.\n * @property data.cause.code - The error code.\n * @property data.cause.message - The error message.\n * @property data.cause.stack - The error stack.\n * @property data.cause.data - Additional data for the error.\n * @see SnapError\n */\nexport type SerializedSnapError = {\n code: typeof SNAP_ERROR_CODE;\n message: typeof SNAP_ERROR_MESSAGE;\n data: {\n cause: JsonRpcError & {\n data: Record<string, Json>;\n };\n };\n};\n"],"names":["SnapError","Error","name","code","message","data","stack","toJSON","SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE","cause","serialize","constructor","error","getErrorMessage","getErrorCode","getErrorData"],"mappings":";;;;+BAcaA;;;eAAAA;;;2BANN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAOI,qCAEA,wCAEA,qCAEA;AAPJ,MAAMA,kBAAkBC;IAkC7B;;;;GAIC,GACD,IAAIC,OAAO;QACT,OAAO;IACT;IAEA;;;;GAIC,GACD,IAAIC,OAAO;QACT,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACD,qEAAqE;IACrE,wBAAwB,GACxB,IAAIC,UAAU;QACZ,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACD,IAAIC,OAAO;QACT,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACD,qEAAqE;IACrE,wBAAwB,GACxB,IAAIC,QAAQ;QACV,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACDC,SAA8B;QAC5B,OAAO;YACLJ,MAAMK,0BAAe;YACrBJ,SAASK,6BAAkB;YAC3BJ,MAAM;gBACJK,OAAO;oBACLP,MAAM,IAAI,CAACA,IAAI;oBACfC,SAAS,IAAI,CAACA,OAAO;oBACrBE,OAAO,IAAI,CAACA,KAAK;oBACjBD,MAAM,IAAI,CAACA,IAAI;gBACjB;YACF;QACF;IACF;IAEA;;;;;GAKC,GACDM,YAAY;QACV,OAAO,IAAI,CAACJ,MAAM;IACpB;IAtGA;;;;;;;;;;;GAWC,GACDK,YACEC,KAAoC,EACpCR,OAA6B,CAAC,CAAC,CAC/B;QACA,MAAMD,UAAUU,IAAAA,0BAAe,EAACD;QAChC,KAAK,CAACT;QAzBR,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;uCAqBQA,UAAUA;uCACVD,OAAOY,IAAAA,uBAAY,EAACF;uCACpBR,OAAO;YAAE,GAAGW,IAAAA,uBAAY,EAACH,MAAM;YAAE,GAAGR,IAAI;QAAC;uCACzCC,QAAQ,KAAK,CAACA;IACtB;AAgFF"}
package/dist/cjs/index.js CHANGED
@@ -1,5 +1,47 @@
1
- // TODO: Add SDK exports here, and remove these comments.
2
- // eslint-disable-next-line import/unambiguous
1
+ // Only internals that are used by other Snaps packages should be exported here.
3
2
  "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ function _export(target, all) {
7
+ for(var name in all)Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ getErrorData: function() {
14
+ return _internals.getErrorData;
15
+ },
16
+ getErrorMessage: function() {
17
+ return _internals.getErrorMessage;
18
+ },
19
+ getErrorStack: function() {
20
+ return _internals.getErrorStack;
21
+ },
22
+ SNAP_ERROR_CODE: function() {
23
+ return _internals.SNAP_ERROR_CODE;
24
+ },
25
+ SNAP_ERROR_MESSAGE: function() {
26
+ return _internals.SNAP_ERROR_MESSAGE;
27
+ }
28
+ });
29
+ const _internals = require("./internals");
30
+ _export_star(require("./errors"), exports);
31
+ _export_star(require("./types"), exports);
32
+ _export_star(require("./ui"), exports);
33
+ function _export_star(from, to) {
34
+ Object.keys(from).forEach(function(k) {
35
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
36
+ Object.defineProperty(to, k, {
37
+ enumerable: true,
38
+ get: function() {
39
+ return from[k];
40
+ }
41
+ });
42
+ }
43
+ });
44
+ return from;
45
+ }
4
46
 
5
47
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["// TODO: Add SDK exports here, and remove these comments.\n// eslint-disable-next-line import/unambiguous\n"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,8CAA8C"}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["// Only internals that are used by other Snaps packages should be exported here.\nexport type { EnumToUnion } from './internals';\nexport {\n getErrorData,\n getErrorMessage,\n getErrorStack,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n} from './internals';\n\n// Re-exported from `@metamask/utils` for convenience.\nexport type {\n Json,\n JsonRpcError,\n JsonRpcRequest,\n JsonRpcParams,\n} from '@metamask/utils';\n\nexport * from './errors';\nexport * from './types';\nexport * from './ui';\n"],"names":["getErrorData","getErrorMessage","getErrorStack","SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE"],"mappings":"AAAA,gFAAgF;;;;;;;;;;;;IAG9EA,YAAY;eAAZA,uBAAY;;IACZC,eAAe;eAAfA,0BAAe;;IACfC,aAAa;eAAbA,wBAAa;;IACbC,eAAe;eAAfA,0BAAe;;IACfC,kBAAkB;eAAlBA,6BAAkB;;;2BACb;qBAUO;qBACA;qBACA"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "createSnapError", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createSnapError;
9
+ }
10
+ });
11
+ const _errors = require("../errors");
12
+ function createSnapError(fn) {
13
+ return class SnapJsonRpcError extends _errors.SnapError {
14
+ constructor(message, data){
15
+ const error = fn(message);
16
+ super({
17
+ code: error.code,
18
+ message: error.message,
19
+ data
20
+ });
21
+ }
22
+ };
23
+ }
24
+
25
+ //# sourceMappingURL=error-wrappers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/internals/error-wrappers.ts"],"sourcesContent":["import type { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\n\nimport { SnapError } from '../errors';\n\nexport type JsonRpcErrorFunction = typeof rpcErrors.parse;\n\n/**\n * Create a `SnapError` class from an error function from\n * `@metamask/rpc-errors`. This is useful for creating custom error classes\n * which can be thrown by a Snap.\n *\n * The created class will inherit the message, code, and data properties from\n * the error function.\n *\n * @param fn - The error function to create the class from.\n * @returns The created `SnapError` class.\n */\nexport function createSnapError(fn: JsonRpcErrorFunction) {\n return class SnapJsonRpcError extends SnapError {\n constructor(message?: string, data?: Record<string, Json>) {\n const error = fn(message);\n\n super({\n code: error.code,\n message: error.message,\n data,\n });\n }\n };\n}\n"],"names":["createSnapError","fn","SnapJsonRpcError","SnapError","constructor","message","data","error","code"],"mappings":";;;;+BAkBgBA;;;eAAAA;;;wBAfU;AAenB,SAASA,gBAAgBC,EAAwB;IACtD,OAAO,MAAMC,yBAAyBC,iBAAS;QAC7CC,YAAYC,OAAgB,EAAEC,IAA2B,CAAE;YACzD,MAAMC,QAAQN,GAAGI;YAEjB,KAAK,CAAC;gBACJG,MAAMD,MAAMC,IAAI;gBAChBH,SAASE,MAAMF,OAAO;gBACtBC;YACF;QACF;IACF;AACF"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ SNAP_ERROR_CODE: function() {
13
+ return SNAP_ERROR_CODE;
14
+ },
15
+ SNAP_ERROR_MESSAGE: function() {
16
+ return SNAP_ERROR_MESSAGE;
17
+ },
18
+ getErrorMessage: function() {
19
+ return getErrorMessage;
20
+ },
21
+ getErrorStack: function() {
22
+ return getErrorStack;
23
+ },
24
+ getErrorCode: function() {
25
+ return getErrorCode;
26
+ },
27
+ getErrorData: function() {
28
+ return getErrorData;
29
+ }
30
+ });
31
+ const _utils = require("@metamask/utils");
32
+ const SNAP_ERROR_CODE = -31002;
33
+ const SNAP_ERROR_MESSAGE = 'Snap Error';
34
+ function getErrorMessage(error) {
35
+ if ((0, _utils.isObject)(error) && (0, _utils.hasProperty)(error, 'message') && typeof error.message === 'string') {
36
+ return error.message;
37
+ }
38
+ return String(error);
39
+ }
40
+ function getErrorStack(error) {
41
+ if ((0, _utils.isObject)(error) && (0, _utils.hasProperty)(error, 'stack') && typeof error.stack === 'string') {
42
+ return error.stack;
43
+ }
44
+ return undefined;
45
+ }
46
+ function getErrorCode(error) {
47
+ if ((0, _utils.isObject)(error) && (0, _utils.hasProperty)(error, 'code') && typeof error.code === 'number' && Number.isInteger(error.code)) {
48
+ return error.code;
49
+ }
50
+ return -32603;
51
+ }
52
+ function getErrorData(error) {
53
+ if ((0, _utils.isObject)(error) && (0, _utils.hasProperty)(error, 'data') && typeof error.data === 'object' && error.data !== null && (0, _utils.isValidJson)(error.data) && !Array.isArray(error.data)) {
54
+ return error.data;
55
+ }
56
+ return {};
57
+ }
58
+
59
+ //# 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":["SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE","getErrorMessage","getErrorStack","getErrorCode","getErrorData","error","isObject","hasProperty","message","String","stack","undefined","code","Number","isInteger","data","isValidJson","Array","isArray"],"mappings":";;;;;;;;;;;IAEaA,eAAe;eAAfA;;IACAC,kBAAkB;eAAlBA;;IAYGC,eAAe;eAAfA;;IAoBAC,aAAa;eAAbA;;IAmBAC,YAAY;eAAZA;;IAqBAC,YAAY;eAAZA;;;uBA3EmC;AAE5C,MAAML,kBAAkB,CAAC;AACzB,MAAMC,qBAAqB;AAY3B,SAASC,gBAAgBI,KAAc;IAC5C,IACEC,IAAAA,eAAQ,EAACD,UACTE,IAAAA,kBAAW,EAACF,OAAO,cACnB,OAAOA,MAAMG,OAAO,KAAK,UACzB;QACA,OAAOH,MAAMG,OAAO;IACtB;IAEA,OAAOC,OAAOJ;AAChB;AAUO,SAASH,cAAcG,KAAc;IAC1C,IACEC,IAAAA,eAAQ,EAACD,UACTE,IAAAA,kBAAW,EAACF,OAAO,YACnB,OAAOA,MAAMK,KAAK,KAAK,UACvB;QACA,OAAOL,MAAMK,KAAK;IACpB;IAEA,OAAOC;AACT;AASO,SAASR,aAAaE,KAAc;IACzC,IACEC,IAAAA,eAAQ,EAACD,UACTE,IAAAA,kBAAW,EAACF,OAAO,WACnB,OAAOA,MAAMO,IAAI,KAAK,YACtBC,OAAOC,SAAS,CAACT,MAAMO,IAAI,GAC3B;QACA,OAAOP,MAAMO,IAAI;IACnB;IAEA,OAAO,CAAC;AACV;AAUO,SAASR,aAAaC,KAAc;IACzC,IACEC,IAAAA,eAAQ,EAACD,UACTE,IAAAA,kBAAW,EAACF,OAAO,WACnB,OAAOA,MAAMU,IAAI,KAAK,YACtBV,MAAMU,IAAI,KAAK,QACfC,IAAAA,kBAAW,EAACX,MAAMU,IAAI,KACtB,CAACE,MAAMC,OAAO,CAACb,MAAMU,IAAI,GACzB;QACA,OAAOV,MAAMU,IAAI;IACnB;IAEA,OAAO,CAAC;AACV"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/internals/helpers.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./error-wrappers"), exports);
6
+ _export_star(require("./errors"), exports);
7
+ _export_star(require("./helpers"), exports);
8
+ function _export_star(from, to) {
9
+ Object.keys(from).forEach(function(k) {
10
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
11
+ Object.defineProperty(to, k, {
12
+ enumerable: true,
13
+ get: function() {
14
+ return from[k];
15
+ }
16
+ });
17
+ }
18
+ });
19
+ return from;
20
+ }
21
+
22
+ //# 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":";;;;qBAAc;qBACA;qBACA"}
@@ -0,0 +1,10 @@
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
+ */ "use strict";
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+
10
+ //# 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"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/types/global.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=cronjob.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/cronjob.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=home-page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/home-page.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./cronjob"), exports);
6
+ _export_star(require("./home-page"), exports);
7
+ _export_star(require("./keyring"), exports);
8
+ _export_star(require("./lifecycle"), exports);
9
+ _export_star(require("./name-lookup"), exports);
10
+ _export_star(require("./rpc-request"), exports);
11
+ _export_star(require("./transaction"), exports);
12
+ function _export_star(from, to) {
13
+ Object.keys(from).forEach(function(k) {
14
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
15
+ Object.defineProperty(to, k, {
16
+ enumerable: true,
17
+ get: function() {
18
+ return from[k];
19
+ }
20
+ });
21
+ }
22
+ });
23
+ return from;
24
+ }
25
+
26
+ //# 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":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=keyring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/keyring.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/lifecycle.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=name-lookup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/name-lookup.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=rpc-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/types/handlers/rpc-request.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "SeverityLevel", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return SeverityLevel;
9
+ }
10
+ });
11
+ var SeverityLevel;
12
+ (function(SeverityLevel) {
13
+ SeverityLevel["Critical"] = 'critical';
14
+ })(SeverityLevel || (SeverityLevel = {}));
15
+
16
+ //# 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":";;;;;;;;;;IAWO;UAAKA,aAAa;IAAbA,cACVC,cAAW;GADDD,kBAAAA"}