@metamask/snaps-utils 9.1.0 → 9.2.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 (135) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/dist/cronjob.d.cts +9 -9
  3. package/dist/cronjob.d.mts +9 -9
  4. package/dist/eval-worker.cjs +2 -2
  5. package/dist/eval-worker.cjs.map +1 -1
  6. package/dist/eval-worker.mjs +1 -1
  7. package/dist/eval-worker.mjs.map +1 -1
  8. package/dist/handlers/asset-historical-price.cjs +25 -0
  9. package/dist/handlers/asset-historical-price.cjs.map +1 -0
  10. package/dist/handlers/asset-historical-price.d.cts +37 -0
  11. package/dist/handlers/asset-historical-price.d.cts.map +1 -0
  12. package/dist/handlers/asset-historical-price.d.mts +37 -0
  13. package/dist/handlers/asset-historical-price.d.mts.map +1 -0
  14. package/dist/handlers/asset-historical-price.mjs +22 -0
  15. package/dist/handlers/asset-historical-price.mjs.map +1 -0
  16. package/dist/handlers/assets-conversion.cjs +38 -0
  17. package/dist/handlers/assets-conversion.cjs.map +1 -0
  18. package/dist/handlers/assets-conversion.d.cts +90 -0
  19. package/dist/handlers/assets-conversion.d.cts.map +1 -0
  20. package/dist/handlers/assets-conversion.d.mts +90 -0
  21. package/dist/handlers/assets-conversion.d.mts.map +1 -0
  22. package/dist/handlers/assets-conversion.mjs +35 -0
  23. package/dist/handlers/assets-conversion.mjs.map +1 -0
  24. package/dist/handlers/exports.cjs +113 -0
  25. package/dist/handlers/exports.cjs.map +1 -0
  26. package/dist/handlers/exports.d.cts +81 -0
  27. package/dist/handlers/exports.d.cts.map +1 -0
  28. package/dist/handlers/exports.d.mts +81 -0
  29. package/dist/handlers/exports.d.mts.map +1 -0
  30. package/dist/{handlers.mjs → handlers/exports.mjs} +10 -45
  31. package/dist/handlers/exports.mjs.map +1 -0
  32. package/dist/handlers/home-page.cjs +16 -0
  33. package/dist/handlers/home-page.cjs.map +1 -0
  34. package/dist/handlers/home-page.d.cts +268 -0
  35. package/dist/handlers/home-page.d.cts.map +1 -0
  36. package/dist/handlers/home-page.d.mts +268 -0
  37. package/dist/handlers/home-page.d.mts.map +1 -0
  38. package/dist/handlers/home-page.mjs +13 -0
  39. package/dist/handlers/home-page.mjs.map +1 -0
  40. package/dist/handlers/index.cjs +26 -0
  41. package/dist/handlers/index.cjs.map +1 -0
  42. package/dist/handlers/index.d.cts +10 -0
  43. package/dist/handlers/index.d.cts.map +1 -0
  44. package/dist/handlers/index.d.mts +10 -0
  45. package/dist/handlers/index.d.mts.map +1 -0
  46. package/dist/handlers/index.mjs +10 -0
  47. package/dist/handlers/index.mjs.map +1 -0
  48. package/dist/handlers/name-lookup.cjs +21 -0
  49. package/dist/handlers/name-lookup.cjs.map +1 -0
  50. package/dist/handlers/name-lookup.d.cts +67 -0
  51. package/dist/handlers/name-lookup.d.cts.map +1 -0
  52. package/dist/handlers/name-lookup.d.mts +67 -0
  53. package/dist/handlers/name-lookup.d.mts.map +1 -0
  54. package/dist/handlers/name-lookup.mjs +18 -0
  55. package/dist/handlers/name-lookup.mjs.map +1 -0
  56. package/dist/handlers/settings-page.cjs +6 -0
  57. package/dist/handlers/settings-page.cjs.map +1 -0
  58. package/dist/handlers/settings-page.d.cts +90 -0
  59. package/dist/handlers/settings-page.d.cts.map +1 -0
  60. package/dist/handlers/settings-page.d.mts +90 -0
  61. package/dist/handlers/settings-page.d.mts.map +1 -0
  62. package/dist/handlers/settings-page.mjs +3 -0
  63. package/dist/handlers/settings-page.mjs.map +1 -0
  64. package/dist/handlers/signature.cjs +6 -0
  65. package/dist/handlers/signature.cjs.map +1 -0
  66. package/dist/handlers/signature.d.cts +92 -0
  67. package/dist/handlers/signature.d.cts.map +1 -0
  68. package/dist/handlers/signature.d.mts +92 -0
  69. package/dist/handlers/signature.d.mts.map +1 -0
  70. package/dist/handlers/signature.mjs +3 -0
  71. package/dist/handlers/signature.mjs.map +1 -0
  72. package/dist/handlers/transaction.cjs +19 -0
  73. package/dist/handlers/transaction.cjs.map +1 -0
  74. package/dist/handlers/transaction.d.cts +280 -0
  75. package/dist/handlers/transaction.d.cts.map +1 -0
  76. package/dist/handlers/transaction.d.mts +280 -0
  77. package/dist/handlers/transaction.d.mts.map +1 -0
  78. package/dist/handlers/transaction.mjs +16 -0
  79. package/dist/handlers/transaction.mjs.map +1 -0
  80. package/dist/{handler-types.cjs → handlers/types.cjs} +3 -3
  81. package/dist/handlers/types.cjs.map +1 -0
  82. package/dist/{handler-types.d.mts → handlers/types.d.cts} +22 -2
  83. package/dist/handlers/types.d.cts.map +1 -0
  84. package/dist/{handler-types.d.cts → handlers/types.d.mts} +22 -2
  85. package/dist/handlers/types.d.mts.map +1 -0
  86. package/dist/{handler-types.mjs → handlers/types.mjs} +2 -2
  87. package/dist/handlers/types.mjs.map +1 -0
  88. package/dist/iframe.test.browser.cjs +20 -19
  89. package/dist/iframe.test.browser.cjs.map +1 -1
  90. package/dist/iframe.test.browser.mjs +2 -1
  91. package/dist/iframe.test.browser.mjs.map +1 -1
  92. package/dist/index.cjs +2 -2
  93. package/dist/index.cjs.map +1 -1
  94. package/dist/index.d.cts +2 -2
  95. package/dist/index.d.cts.map +1 -1
  96. package/dist/index.d.mts +2 -2
  97. package/dist/index.d.mts.map +1 -1
  98. package/dist/index.executionenv.cjs +2 -2
  99. package/dist/index.executionenv.cjs.map +1 -1
  100. package/dist/index.executionenv.d.cts +2 -2
  101. package/dist/index.executionenv.d.cts.map +1 -1
  102. package/dist/index.executionenv.d.mts +2 -2
  103. package/dist/index.executionenv.d.mts.map +1 -1
  104. package/dist/index.executionenv.mjs +2 -2
  105. package/dist/index.executionenv.mjs.map +1 -1
  106. package/dist/index.mjs +2 -2
  107. package/dist/index.mjs.map +1 -1
  108. package/dist/localization.d.cts +5 -5
  109. package/dist/localization.d.mts +5 -5
  110. package/dist/manifest/validation.d.cts +12 -12
  111. package/dist/manifest/validation.d.mts +12 -12
  112. package/dist/time.cjs +34 -0
  113. package/dist/time.cjs.map +1 -0
  114. package/dist/time.d.cts +9 -0
  115. package/dist/time.d.cts.map +1 -0
  116. package/dist/time.d.mts +9 -0
  117. package/dist/time.d.mts.map +1 -0
  118. package/dist/time.mjs +31 -0
  119. package/dist/time.mjs.map +1 -0
  120. package/dist/types.d.cts +2 -2
  121. package/dist/types.d.cts.map +1 -1
  122. package/dist/types.d.mts +2 -2
  123. package/dist/types.d.mts.map +1 -1
  124. package/package.json +13 -21
  125. package/dist/handler-types.cjs.map +0 -1
  126. package/dist/handler-types.d.cts.map +0 -1
  127. package/dist/handler-types.d.mts.map +0 -1
  128. package/dist/handler-types.mjs.map +0 -1
  129. package/dist/handlers.cjs +0 -148
  130. package/dist/handlers.cjs.map +0 -1
  131. package/dist/handlers.d.cts +0 -887
  132. package/dist/handlers.d.cts.map +0 -1
  133. package/dist/handlers.d.mts +0 -887
  134. package/dist/handlers.d.mts.map +0 -1
  135. package/dist/handlers.mjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-utils",
3
- "version": "9.1.0",
3
+ "version": "9.2.0",
4
4
  "description": "A collection of utilities for MetaMask Snaps",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -70,9 +70,10 @@
70
70
  "publish:preview": "yarn npm publish --tag preview",
71
71
  "since-latest-release": "../../scripts/since-latest-release.sh",
72
72
  "test": "jest --reporters=jest-silent-reporter && yarn test:browser",
73
- "test:browser": "wdio run wdio.config.js",
73
+ "test:browser": "vitest",
74
+ "test:browser:firefox": "vitest --config ./vitest.config.firefox.mts",
74
75
  "test:clean": "jest --clearCache",
75
- "test:post": "ts-node scripts/coverage.ts && rimraf coverage/jest coverage/wdio",
76
+ "test:post": "ts-node scripts/coverage.ts && rimraf coverage/jest coverage/vite",
76
77
  "test:verbose": "jest --verbose",
77
78
  "test:watch": "jest --watch"
78
79
  },
@@ -85,8 +86,8 @@
85
86
  "@metamask/rpc-errors": "^7.0.2",
86
87
  "@metamask/slip44": "^4.1.0",
87
88
  "@metamask/snaps-registry": "^3.2.3",
88
- "@metamask/snaps-sdk": "^6.20.0",
89
- "@metamask/superstruct": "^3.1.0",
89
+ "@metamask/snaps-sdk": "^6.22.0",
90
+ "@metamask/superstruct": "^3.2.1",
90
91
  "@metamask/utils": "^11.2.0",
91
92
  "@noble/hashes": "^1.7.1",
92
93
  "@scure/base": "^1.1.1",
@@ -95,6 +96,7 @@
95
96
  "fast-deep-equal": "^3.1.3",
96
97
  "fast-json-stable-stringify": "^2.1.0",
97
98
  "fast-xml-parser": "^4.4.1",
99
+ "luxon": "^3.5.0",
98
100
  "marked": "^12.0.1",
99
101
  "rfdc": "^1.3.0",
100
102
  "semver": "^7.5.4",
@@ -102,31 +104,22 @@
102
104
  "validate-npm-package-name": "^5.0.0"
103
105
  },
104
106
  "devDependencies": {
105
- "@esbuild-plugins/node-globals-polyfill": "^0.2.3",
106
- "@esbuild-plugins/node-modules-polyfill": "^0.2.2",
107
107
  "@lavamoat/allow-scripts": "^3.0.4",
108
- "@metamask/auto-changelog": "^4.1.0",
108
+ "@metamask/auto-changelog": "^5.0.1",
109
109
  "@metamask/post-message-stream": "^9.0.0",
110
110
  "@swc/core": "1.3.78",
111
111
  "@swc/jest": "^0.2.26",
112
112
  "@ts-bridge/cli": "^0.6.1",
113
113
  "@types/jest": "^27.5.1",
114
- "@types/mocha": "^10.0.1",
114
+ "@types/luxon": "^3",
115
115
  "@types/node": "18.14.2",
116
116
  "@types/semver": "^7.5.0",
117
117
  "@types/validate-npm-package-name": "^4.0.0",
118
- "@wdio/browser-runner": "^8.19.0",
119
- "@wdio/cli": "^8.19.0",
120
- "@wdio/globals": "^8.19.0",
121
- "@wdio/mocha-framework": "^8.19.0",
122
- "@wdio/spec-reporter": "^8.19.0",
123
- "@wdio/static-server-service": "^8.19.0",
124
- "@wdio/types": "^8.19.0",
118
+ "@vitest/browser": "^3.0.8",
119
+ "@vitest/coverage-istanbul": "3.0.8",
125
120
  "deepmerge": "^4.2.2",
126
121
  "depcheck": "^1.4.7",
127
- "esbuild": "^0.25.1",
128
122
  "eslint": "^9.11.0",
129
- "expect-webdriverio": "^4.4.1",
130
123
  "istanbul-lib-coverage": "^3.2.0",
131
124
  "istanbul-lib-report": "^3.0.0",
132
125
  "istanbul-reports": "^3.1.5",
@@ -138,10 +131,9 @@
138
131
  "ts-node": "^10.9.1",
139
132
  "typescript": "~5.3.3",
140
133
  "vite": "^6.2.3",
134
+ "vite-plugin-node-polyfills": "^0.23.0",
141
135
  "vite-tsconfig-paths": "^4.0.5",
142
- "wdio-chromedriver-service": "^8.1.1",
143
- "wdio-geckodriver-service": "^5.0.2",
144
- "webdriverio": "^8.19.0"
136
+ "vitest": "^3.0.8"
145
137
  },
146
138
  "engines": {
147
139
  "node": "^18.16 || >=20"
@@ -1 +0,0 @@
1
- {"version":3,"file":"handler-types.cjs","sourceRoot":"","sources":["../src/handler-types.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAeX;AAfD,WAAY,WAAW;IACrB,4CAA6B,CAAA;IAC7B,0CAA2B,CAAA;IAC3B,8CAA+B,CAAA;IAC/B,sCAAuB,CAAA;IACvB,sCAAuB,CAAA;IACvB,oCAAqB,CAAA;IACrB,4CAA6B,CAAA;IAC7B,oDAAqC,CAAA;IACrC,wCAAyB,CAAA;IACzB,gDAAiC,CAAA;IACjC,0CAA2B,CAAA;IAC3B,gDAAiC,CAAA;IACjC,wDAAyC,CAAA;IACzC,sDAAuC,CAAA;AACzC,CAAC,EAfW,WAAW,2BAAX,WAAW,QAetB;AA0BY,QAAA,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC","sourcesContent":["export enum HandlerType {\n OnRpcRequest = 'onRpcRequest',\n OnSignature = 'onSignature',\n OnTransaction = 'onTransaction',\n OnCronjob = 'onCronjob',\n OnInstall = 'onInstall',\n OnUpdate = 'onUpdate',\n OnNameLookup = 'onNameLookup',\n OnKeyringRequest = 'onKeyringRequest',\n OnHomePage = 'onHomePage',\n OnSettingsPage = 'onSettingsPage',\n OnUserInput = 'onUserInput',\n OnAssetsLookup = 'onAssetsLookup',\n OnAssetsConversion = 'onAssetsConversion',\n OnProtocolRequest = 'onProtocolRequest',\n}\n\nexport type SnapHandler = {\n /**\n * The type of handler.\n */\n type: HandlerType;\n\n /**\n * Whether the handler is required, i.e., whether the request will fail if the\n * handler is called, but the snap does not export it.\n *\n * This is primarily used for the lifecycle handlers, which are optional.\n */\n required: boolean;\n\n /**\n * Validate the given snap export. This should return a type guard for the\n * handler type.\n *\n * @param snapExport - The export to validate.\n * @returns Whether the export is valid.\n */\n validator: (snapExport: unknown) => boolean;\n};\n\nexport const SNAP_EXPORT_NAMES = Object.values(HandlerType);\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"handler-types.d.cts","sourceRoot":"","sources":["../src/handler-types.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,aAAa,kBAAkB;IAC/B,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,YAAY,iBAAiB;IAC7B,gBAAgB,qBAAqB;IACrC,UAAU,eAAe;IACzB,cAAc,mBAAmB;IACjC,WAAW,gBAAgB;IAC3B,cAAc,mBAAmB;IACjC,kBAAkB,uBAAuB;IACzC,iBAAiB,sBAAsB;CACxC;AAED,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;IAElB;;;;;OAKG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,OAAO,CAAC;CAC7C,CAAC;AAEF,eAAO,MAAM,iBAAiB,eAA6B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"handler-types.d.mts","sourceRoot":"","sources":["../src/handler-types.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,aAAa,kBAAkB;IAC/B,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,YAAY,iBAAiB;IAC7B,gBAAgB,qBAAqB;IACrC,UAAU,eAAe;IACzB,cAAc,mBAAmB;IACjC,WAAW,gBAAgB;IAC3B,cAAc,mBAAmB;IACjC,kBAAkB,uBAAuB;IACzC,iBAAiB,sBAAsB;CACxC;AAED,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;IAElB;;;;;OAKG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,OAAO,CAAC;CAC7C,CAAC;AAEF,eAAO,MAAM,iBAAiB,eAA6B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"handler-types.mjs","sourceRoot":"","sources":["../src/handler-types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,WAeX;AAfD,WAAY,WAAW;IACrB,4CAA6B,CAAA;IAC7B,0CAA2B,CAAA;IAC3B,8CAA+B,CAAA;IAC/B,sCAAuB,CAAA;IACvB,sCAAuB,CAAA;IACvB,oCAAqB,CAAA;IACrB,4CAA6B,CAAA;IAC7B,oDAAqC,CAAA;IACrC,wCAAyB,CAAA;IACzB,gDAAiC,CAAA;IACjC,0CAA2B,CAAA;IAC3B,gDAAiC,CAAA;IACjC,wDAAyC,CAAA;IACzC,sDAAuC,CAAA;AACzC,CAAC,EAfW,WAAW,KAAX,WAAW,QAetB;AA0BD,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC","sourcesContent":["export enum HandlerType {\n OnRpcRequest = 'onRpcRequest',\n OnSignature = 'onSignature',\n OnTransaction = 'onTransaction',\n OnCronjob = 'onCronjob',\n OnInstall = 'onInstall',\n OnUpdate = 'onUpdate',\n OnNameLookup = 'onNameLookup',\n OnKeyringRequest = 'onKeyringRequest',\n OnHomePage = 'onHomePage',\n OnSettingsPage = 'onSettingsPage',\n OnUserInput = 'onUserInput',\n OnAssetsLookup = 'onAssetsLookup',\n OnAssetsConversion = 'onAssetsConversion',\n OnProtocolRequest = 'onProtocolRequest',\n}\n\nexport type SnapHandler = {\n /**\n * The type of handler.\n */\n type: HandlerType;\n\n /**\n * Whether the handler is required, i.e., whether the request will fail if the\n * handler is called, but the snap does not export it.\n *\n * This is primarily used for the lifecycle handlers, which are optional.\n */\n required: boolean;\n\n /**\n * Validate the given snap export. This should return a type guard for the\n * handler type.\n *\n * @param snapExport - The export to validate.\n * @returns Whether the export is valid.\n */\n validator: (snapExport: unknown) => boolean;\n};\n\nexport const SNAP_EXPORT_NAMES = Object.values(HandlerType);\n"]}
package/dist/handlers.cjs DELETED
@@ -1,148 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OnNameLookupResponseStruct = exports.DomainResolutionResponseStruct = exports.AddressResolutionResponseStruct = exports.DomainResolutionStruct = exports.AddressResolutionStruct = exports.OnSettingsPageResponseStruct = exports.OnHomePageResponseStruct = exports.OnHomePageResponseWithIdStruct = exports.OnHomePageResponseWithContentStruct = exports.OnSignatureResponseStruct = exports.OnTransactionResponseStruct = exports.OnTransactionResponseWithContentStruct = exports.OnTransactionResponseWithIdStruct = exports.OnTransactionSeverityResponseStruct = exports.SNAP_EXPORTS = void 0;
4
- const snaps_sdk_1 = require("@metamask/snaps-sdk");
5
- const superstruct_1 = require("@metamask/superstruct");
6
- const handler_types_1 = require("./handler-types.cjs");
7
- exports.SNAP_EXPORTS = {
8
- [handler_types_1.HandlerType.OnRpcRequest]: {
9
- type: handler_types_1.HandlerType.OnRpcRequest,
10
- required: true,
11
- validator: (snapExport) => {
12
- return typeof snapExport === 'function';
13
- },
14
- },
15
- [handler_types_1.HandlerType.OnTransaction]: {
16
- type: handler_types_1.HandlerType.OnTransaction,
17
- required: true,
18
- validator: (snapExport) => {
19
- return typeof snapExport === 'function';
20
- },
21
- },
22
- [handler_types_1.HandlerType.OnCronjob]: {
23
- type: handler_types_1.HandlerType.OnCronjob,
24
- required: true,
25
- validator: (snapExport) => {
26
- return typeof snapExport === 'function';
27
- },
28
- },
29
- [handler_types_1.HandlerType.OnNameLookup]: {
30
- type: handler_types_1.HandlerType.OnNameLookup,
31
- required: true,
32
- validator: (snapExport) => {
33
- return typeof snapExport === 'function';
34
- },
35
- },
36
- [handler_types_1.HandlerType.OnInstall]: {
37
- type: handler_types_1.HandlerType.OnInstall,
38
- required: false,
39
- validator: (snapExport) => {
40
- return typeof snapExport === 'function';
41
- },
42
- },
43
- [handler_types_1.HandlerType.OnUpdate]: {
44
- type: handler_types_1.HandlerType.OnUpdate,
45
- required: false,
46
- validator: (snapExport) => {
47
- return typeof snapExport === 'function';
48
- },
49
- },
50
- [handler_types_1.HandlerType.OnKeyringRequest]: {
51
- type: handler_types_1.HandlerType.OnKeyringRequest,
52
- required: true,
53
- validator: (snapExport) => {
54
- return typeof snapExport === 'function';
55
- },
56
- },
57
- [handler_types_1.HandlerType.OnHomePage]: {
58
- type: handler_types_1.HandlerType.OnHomePage,
59
- required: true,
60
- validator: (snapExport) => {
61
- return typeof snapExport === 'function';
62
- },
63
- },
64
- [handler_types_1.HandlerType.OnSettingsPage]: {
65
- type: handler_types_1.HandlerType.OnSettingsPage,
66
- required: true,
67
- validator: (snapExport) => {
68
- return typeof snapExport === 'function';
69
- },
70
- },
71
- [handler_types_1.HandlerType.OnSignature]: {
72
- type: handler_types_1.HandlerType.OnSignature,
73
- required: true,
74
- validator: (snapExport) => {
75
- return typeof snapExport === 'function';
76
- },
77
- },
78
- [handler_types_1.HandlerType.OnUserInput]: {
79
- type: handler_types_1.HandlerType.OnUserInput,
80
- required: false,
81
- validator: (snapExport) => {
82
- return typeof snapExport === 'function';
83
- },
84
- },
85
- [handler_types_1.HandlerType.OnAssetsLookup]: {
86
- type: handler_types_1.HandlerType.OnAssetsLookup,
87
- required: true,
88
- validator: (snapExport) => {
89
- return typeof snapExport === 'function';
90
- },
91
- },
92
- [handler_types_1.HandlerType.OnAssetsConversion]: {
93
- type: handler_types_1.HandlerType.OnAssetsConversion,
94
- required: true,
95
- validator: (snapExport) => {
96
- return typeof snapExport === 'function';
97
- },
98
- },
99
- [handler_types_1.HandlerType.OnProtocolRequest]: {
100
- type: handler_types_1.HandlerType.OnProtocolRequest,
101
- required: true,
102
- validator: (snapExport) => {
103
- return typeof snapExport === 'function';
104
- },
105
- },
106
- };
107
- exports.OnTransactionSeverityResponseStruct = (0, superstruct_1.object)({
108
- severity: (0, superstruct_1.optional)((0, superstruct_1.literal)(snaps_sdk_1.SeverityLevel.Critical)),
109
- });
110
- exports.OnTransactionResponseWithIdStruct = (0, superstruct_1.assign)(exports.OnTransactionSeverityResponseStruct, (0, superstruct_1.object)({
111
- id: (0, superstruct_1.string)(),
112
- }));
113
- exports.OnTransactionResponseWithContentStruct = (0, superstruct_1.assign)(exports.OnTransactionSeverityResponseStruct, (0, superstruct_1.object)({
114
- content: snaps_sdk_1.ComponentOrElementStruct,
115
- }));
116
- exports.OnTransactionResponseStruct = (0, superstruct_1.nullable)((0, superstruct_1.union)([
117
- exports.OnTransactionResponseWithContentStruct,
118
- exports.OnTransactionResponseWithIdStruct,
119
- ]));
120
- exports.OnSignatureResponseStruct = exports.OnTransactionResponseStruct;
121
- exports.OnHomePageResponseWithContentStruct = (0, superstruct_1.object)({
122
- content: snaps_sdk_1.ComponentOrElementStruct,
123
- });
124
- exports.OnHomePageResponseWithIdStruct = (0, superstruct_1.object)({
125
- id: (0, superstruct_1.string)(),
126
- });
127
- exports.OnHomePageResponseStruct = (0, superstruct_1.union)([
128
- exports.OnHomePageResponseWithContentStruct,
129
- exports.OnHomePageResponseWithIdStruct,
130
- ]);
131
- exports.OnSettingsPageResponseStruct = exports.OnHomePageResponseStruct;
132
- exports.AddressResolutionStruct = (0, superstruct_1.object)({
133
- protocol: (0, superstruct_1.string)(),
134
- resolvedDomain: (0, superstruct_1.string)(),
135
- });
136
- exports.DomainResolutionStruct = (0, superstruct_1.object)({
137
- protocol: (0, superstruct_1.string)(),
138
- resolvedAddress: (0, superstruct_1.string)(),
139
- domainName: (0, superstruct_1.string)(),
140
- });
141
- exports.AddressResolutionResponseStruct = (0, superstruct_1.object)({
142
- resolvedDomains: (0, superstruct_1.size)((0, superstruct_1.array)(exports.AddressResolutionStruct), 1, Infinity),
143
- });
144
- exports.DomainResolutionResponseStruct = (0, superstruct_1.object)({
145
- resolvedAddresses: (0, superstruct_1.size)((0, superstruct_1.array)(exports.DomainResolutionStruct), 1, Infinity),
146
- });
147
- exports.OnNameLookupResponseStruct = (0, superstruct_1.nullable)((0, superstruct_1.union)([exports.AddressResolutionResponseStruct, exports.DomainResolutionResponseStruct]));
148
- //# sourceMappingURL=handlers.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handlers.cjs","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":";;;AAgBA,mDAA8E;AAC9E,uDAU+B;AAG/B,uDAA8C;AAQjC,QAAA,YAAY,GAAG;IAC1B,CAAC,2BAAW,CAAC,YAAY,CAAC,EAAE;QAC1B,IAAI,EAAE,2BAAW,CAAC,YAAY;QAC9B,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAqC,EAAE;YACpE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,2BAAW,CAAC,aAAa,CAAC,EAAE;QAC3B,IAAI,EAAE,2BAAW,CAAC,aAAa;QAC/B,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAsC,EAAE;YACrE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,2BAAW,CAAC,SAAS,CAAC,EAAE;QACvB,IAAI,EAAE,2BAAW,CAAC,SAAS;QAC3B,QAAQ,EA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A,oBAAM,EAAC;IACpD,eAAe,EAAE,IAAA,kBAAI,EAAC,IAAA,mBAAK,EAAC,+BAAuB,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC;CACnE,CAAC,CAAC;AAEU,QAAA,8BAA8B,GAAG,IAAA,oBAAM,EAAC;IACnD,iBAAiB,EAAE,IAAA,kBAAI,EAAC,IAAA,mBAAK,EAAC,8BAAsB,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC;CACpE,CAAC,CAAC;AAEU,QAAA,0BAA0B,GAAG,IAAA,sBAAQ,EAChD,IAAA,mBAAK,EAAC,CAAC,uCAA+B,EAAE,sCAA8B,CAAC,CAAC,CACzE,CAAC","sourcesContent":["import type {\n OnAssetsConversionHandler,\n OnAssetsLookupHandler,\n OnCronjobHandler,\n OnHomePageHandler,\n OnInstallHandler,\n OnKeyringRequestHandler,\n OnNameLookupHandler,\n OnProtocolRequestHandler,\n OnRpcRequestHandler,\n OnSettingsPageHandler,\n OnSignatureHandler,\n OnTransactionHandler,\n OnUpdateHandler,\n OnUserInputHandler,\n} from '@metamask/snaps-sdk';\nimport { ComponentOrElementStruct, SeverityLevel } from '@metamask/snaps-sdk';\nimport {\n assign,\n literal,\n nullable,\n object,\n optional,\n string,\n array,\n size,\n union,\n} from '@metamask/superstruct';\n\nimport type { SnapHandler } from './handler-types';\nimport { HandlerType } from './handler-types';\n\nexport type SnapRpcHookArgs = {\n origin: string;\n handler: HandlerType;\n request: Record<string, unknown>;\n};\n\nexport const SNAP_EXPORTS = {\n [HandlerType.OnRpcRequest]: {\n type: HandlerType.OnRpcRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnRpcRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnTransaction]: {\n type: HandlerType.OnTransaction,\n required: true,\n validator: (snapExport: unknown): snapExport is OnTransactionHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnCronjob]: {\n type: HandlerType.OnCronjob,\n required: true,\n validator: (snapExport: unknown): snapExport is OnCronjobHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnNameLookup]: {\n type: HandlerType.OnNameLookup,\n required: true,\n validator: (snapExport: unknown): snapExport is OnNameLookupHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnInstall]: {\n type: HandlerType.OnInstall,\n required: false,\n validator: (snapExport: unknown): snapExport is OnInstallHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUpdate]: {\n type: HandlerType.OnUpdate,\n required: false,\n validator: (snapExport: unknown): snapExport is OnUpdateHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnKeyringRequest]: {\n type: HandlerType.OnKeyringRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnKeyringRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnHomePage]: {\n type: HandlerType.OnHomePage,\n required: true,\n validator: (snapExport: unknown): snapExport is OnHomePageHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnSettingsPage]: {\n type: HandlerType.OnSettingsPage,\n required: true,\n validator: (snapExport: unknown): snapExport is OnSettingsPageHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnSignature]: {\n type: HandlerType.OnSignature,\n required: true,\n validator: (snapExport: unknown): snapExport is OnSignatureHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUserInput]: {\n type: HandlerType.OnUserInput,\n required: false,\n validator: (snapExport: unknown): snapExport is OnUserInputHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetsLookup]: {\n type: HandlerType.OnAssetsLookup,\n required: true,\n validator: (snapExport: unknown): snapExport is OnAssetsLookupHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetsConversion]: {\n type: HandlerType.OnAssetsConversion,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnAssetsConversionHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnProtocolRequest]: {\n type: HandlerType.OnProtocolRequest,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnProtocolRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n} as const;\n\nexport const OnTransactionSeverityResponseStruct = object({\n severity: optional(literal(SeverityLevel.Critical)),\n});\n\nexport const OnTransactionResponseWithIdStruct = assign(\n OnTransactionSeverityResponseStruct,\n object({\n id: string(),\n }),\n);\n\nexport const OnTransactionResponseWithContentStruct = assign(\n OnTransactionSeverityResponseStruct,\n object({\n content: ComponentOrElementStruct,\n }),\n);\n\nexport const OnTransactionResponseStruct = nullable(\n union([\n OnTransactionResponseWithContentStruct,\n OnTransactionResponseWithIdStruct,\n ]),\n);\n\nexport const OnSignatureResponseStruct = OnTransactionResponseStruct;\n\nexport const OnHomePageResponseWithContentStruct = object({\n content: ComponentOrElementStruct,\n});\n\nexport const OnHomePageResponseWithIdStruct = object({\n id: string(),\n});\n\nexport const OnHomePageResponseStruct = union([\n OnHomePageResponseWithContentStruct,\n OnHomePageResponseWithIdStruct,\n]);\n\nexport const OnSettingsPageResponseStruct = OnHomePageResponseStruct;\n\nexport const AddressResolutionStruct = object({\n protocol: string(),\n resolvedDomain: string(),\n});\n\nexport const DomainResolutionStruct = object({\n protocol: string(),\n resolvedAddress: string(),\n domainName: string(),\n});\n\nexport const AddressResolutionResponseStruct = object({\n resolvedDomains: size(array(AddressResolutionStruct), 1, Infinity),\n});\n\nexport const DomainResolutionResponseStruct = object({\n resolvedAddresses: size(array(DomainResolutionStruct), 1, Infinity),\n});\n\nexport const OnNameLookupResponseStruct = nullable(\n union([AddressResolutionResponseStruct, DomainResolutionResponseStruct]),\n);\n\n/**\n * Utility type for getting the handler function type from a handler type.\n */\nexport type HandlerFunction<Type extends SnapHandler> =\n Type['validator'] extends (snapExport: unknown) => snapExport is infer Handler\n ? Handler\n : never;\n\n/**\n * All the function-based handlers that a snap can implement.\n */\nexport type SnapFunctionExports = {\n [Key in keyof typeof SNAP_EXPORTS]?: HandlerFunction<\n (typeof SNAP_EXPORTS)[Key]\n >;\n};\n\n/**\n * All handlers that a snap can implement.\n */\nexport type SnapExports = SnapFunctionExports;\n"]}