@metamask/keyring-api 11.1.0 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/dist/api/account.cjs +7 -4
  3. package/dist/api/account.cjs.map +1 -1
  4. package/dist/api/account.d.cts +6 -1
  5. package/dist/api/account.d.cts.map +1 -1
  6. package/dist/api/account.d.mts +6 -1
  7. package/dist/api/account.d.mts.map +1 -1
  8. package/dist/api/account.mjs +7 -4
  9. package/dist/api/account.mjs.map +1 -1
  10. package/dist/api/asset.cjs +5 -6
  11. package/dist/api/asset.cjs.map +1 -1
  12. package/dist/api/asset.d.cts +2 -2
  13. package/dist/api/asset.d.cts.map +1 -1
  14. package/dist/api/asset.d.mts +2 -2
  15. package/dist/api/asset.d.mts.map +1 -1
  16. package/dist/api/asset.mjs +1 -2
  17. package/dist/api/asset.mjs.map +1 -1
  18. package/dist/api/balance.cjs +3 -4
  19. package/dist/api/balance.cjs.map +1 -1
  20. package/dist/api/balance.d.cts.map +1 -1
  21. package/dist/api/balance.d.mts.map +1 -1
  22. package/dist/api/balance.mjs +1 -2
  23. package/dist/api/balance.mjs.map +1 -1
  24. package/dist/api/caip.cjs +3 -3
  25. package/dist/api/caip.cjs.map +1 -1
  26. package/dist/api/caip.d.cts.map +1 -1
  27. package/dist/api/caip.d.mts.map +1 -1
  28. package/dist/api/caip.mjs +1 -1
  29. package/dist/api/caip.mjs.map +1 -1
  30. package/dist/api/index.cjs +1 -0
  31. package/dist/api/index.cjs.map +1 -1
  32. package/dist/api/index.d.cts +1 -0
  33. package/dist/api/index.d.cts.map +1 -1
  34. package/dist/api/index.d.mts +1 -0
  35. package/dist/api/index.d.mts.map +1 -1
  36. package/dist/api/index.mjs +1 -0
  37. package/dist/api/index.mjs.map +1 -1
  38. package/dist/api/keyring.cjs +2 -0
  39. package/dist/api/keyring.cjs.map +1 -1
  40. package/dist/api/keyring.d.cts +1 -1
  41. package/dist/api/keyring.d.cts.map +1 -1
  42. package/dist/api/keyring.d.mts +1 -1
  43. package/dist/api/keyring.d.mts.map +1 -1
  44. package/dist/api/keyring.mjs +2 -0
  45. package/dist/api/keyring.mjs.map +1 -1
  46. package/dist/{utils → api}/pagination.cjs +3 -3
  47. package/dist/api/pagination.cjs.map +1 -0
  48. package/dist/{utils → api}/pagination.d.cts +1 -1
  49. package/dist/api/pagination.d.cts.map +1 -0
  50. package/dist/{utils → api}/pagination.d.mts +1 -1
  51. package/dist/api/pagination.d.mts.map +1 -0
  52. package/dist/{utils → api}/pagination.mjs +1 -1
  53. package/dist/api/pagination.mjs.map +1 -0
  54. package/dist/api/request.cjs +6 -7
  55. package/dist/api/request.cjs.map +1 -1
  56. package/dist/api/request.d.cts +5 -5
  57. package/dist/api/request.d.cts.map +1 -1
  58. package/dist/api/request.d.mts +5 -5
  59. package/dist/api/request.d.mts.map +1 -1
  60. package/dist/api/request.mjs +1 -2
  61. package/dist/api/request.mjs.map +1 -1
  62. package/dist/api/response.cjs +6 -6
  63. package/dist/api/response.cjs.map +1 -1
  64. package/dist/api/response.d.cts +1 -1
  65. package/dist/api/response.d.cts.map +1 -1
  66. package/dist/api/response.d.mts +1 -1
  67. package/dist/api/response.d.mts.map +1 -1
  68. package/dist/api/response.mjs +1 -1
  69. package/dist/api/response.mjs.map +1 -1
  70. package/dist/api/transaction.cjs +7 -8
  71. package/dist/api/transaction.cjs.map +1 -1
  72. package/dist/api/transaction.d.cts +65 -65
  73. package/dist/api/transaction.d.cts.map +1 -1
  74. package/dist/api/transaction.d.mts +65 -65
  75. package/dist/api/transaction.d.mts.map +1 -1
  76. package/dist/api/transaction.mjs +1 -2
  77. package/dist/api/transaction.mjs.map +1 -1
  78. package/dist/btc/constants.cjs +17 -0
  79. package/dist/btc/constants.cjs.map +1 -0
  80. package/dist/btc/constants.d.cts +12 -0
  81. package/dist/btc/constants.d.cts.map +1 -0
  82. package/dist/btc/constants.d.mts +12 -0
  83. package/dist/btc/constants.d.mts.map +1 -0
  84. package/dist/btc/constants.mjs +14 -0
  85. package/dist/btc/constants.mjs.map +1 -0
  86. package/dist/btc/index.cjs +1 -0
  87. package/dist/btc/index.cjs.map +1 -1
  88. package/dist/btc/index.d.cts +1 -0
  89. package/dist/btc/index.d.cts.map +1 -1
  90. package/dist/btc/index.d.mts +1 -0
  91. package/dist/btc/index.d.mts.map +1 -1
  92. package/dist/btc/index.mjs +1 -0
  93. package/dist/btc/index.mjs.map +1 -1
  94. package/dist/btc/types.cjs +2 -2
  95. package/dist/btc/types.cjs.map +1 -1
  96. package/dist/btc/types.d.cts +3 -1
  97. package/dist/btc/types.d.cts.map +1 -1
  98. package/dist/btc/types.d.mts +3 -1
  99. package/dist/btc/types.d.mts.map +1 -1
  100. package/dist/btc/types.mjs +2 -2
  101. package/dist/btc/types.mjs.map +1 -1
  102. package/dist/eth/constants.cjs +13 -0
  103. package/dist/eth/constants.cjs.map +1 -0
  104. package/dist/eth/constants.d.cts +8 -0
  105. package/dist/eth/constants.d.cts.map +1 -0
  106. package/dist/eth/constants.d.mts +8 -0
  107. package/dist/eth/constants.d.mts.map +1 -0
  108. package/dist/eth/constants.mjs +10 -0
  109. package/dist/eth/constants.mjs.map +1 -0
  110. package/dist/eth/erc4337/types.cjs +10 -11
  111. package/dist/eth/erc4337/types.cjs.map +1 -1
  112. package/dist/eth/erc4337/types.d.cts +5 -5
  113. package/dist/eth/erc4337/types.d.cts.map +1 -1
  114. package/dist/eth/erc4337/types.d.mts +5 -5
  115. package/dist/eth/erc4337/types.d.mts.map +1 -1
  116. package/dist/eth/erc4337/types.mjs +1 -2
  117. package/dist/eth/erc4337/types.mjs.map +1 -1
  118. package/dist/eth/index.cjs +1 -0
  119. package/dist/eth/index.cjs.map +1 -1
  120. package/dist/eth/index.d.cts +1 -0
  121. package/dist/eth/index.d.cts.map +1 -1
  122. package/dist/eth/index.d.mts +1 -0
  123. package/dist/eth/index.d.mts.map +1 -1
  124. package/dist/eth/index.mjs +1 -0
  125. package/dist/eth/index.mjs.map +1 -1
  126. package/dist/eth/types.cjs +11 -6
  127. package/dist/eth/types.cjs.map +1 -1
  128. package/dist/eth/types.d.cts +10 -2
  129. package/dist/eth/types.d.cts.map +1 -1
  130. package/dist/eth/types.d.mts +10 -2
  131. package/dist/eth/types.d.mts.map +1 -1
  132. package/dist/eth/types.mjs +7 -2
  133. package/dist/eth/types.mjs.map +1 -1
  134. package/dist/eth/utils.cjs.map +1 -1
  135. package/dist/eth/utils.d.cts.map +1 -1
  136. package/dist/eth/utils.d.mts.map +1 -1
  137. package/dist/eth/utils.mjs.map +1 -1
  138. package/dist/events.cjs +67 -1
  139. package/dist/events.cjs.map +1 -1
  140. package/dist/events.d.cts +169 -0
  141. package/dist/events.d.cts.map +1 -1
  142. package/dist/events.d.mts +169 -0
  143. package/dist/events.d.mts.map +1 -1
  144. package/dist/events.mjs +66 -0
  145. package/dist/events.mjs.map +1 -1
  146. package/dist/index.cjs +2 -8
  147. package/dist/index.cjs.map +1 -1
  148. package/dist/index.d.cts +3 -9
  149. package/dist/index.d.cts.map +1 -1
  150. package/dist/index.d.mts +3 -9
  151. package/dist/index.d.mts.map +1 -1
  152. package/dist/index.mjs +2 -8
  153. package/dist/index.mjs.map +1 -1
  154. package/dist/{internal/api.cjs → rpc.cjs} +71 -42
  155. package/dist/rpc.cjs.map +1 -0
  156. package/dist/{internal/api.d.cts → rpc.d.cts} +141 -104
  157. package/dist/rpc.d.cts.map +1 -0
  158. package/dist/{internal/api.d.mts → rpc.d.mts} +141 -104
  159. package/dist/rpc.d.mts.map +1 -0
  160. package/dist/{internal/api.mjs → rpc.mjs} +33 -5
  161. package/dist/rpc.mjs.map +1 -0
  162. package/dist/sol/constants.cjs +15 -0
  163. package/dist/sol/constants.cjs.map +1 -0
  164. package/dist/sol/constants.d.cts +10 -0
  165. package/dist/sol/constants.d.cts.map +1 -0
  166. package/dist/sol/constants.d.mts +10 -0
  167. package/dist/sol/constants.d.mts.map +1 -0
  168. package/dist/sol/constants.mjs +12 -0
  169. package/dist/sol/constants.mjs.map +1 -0
  170. package/dist/sol/index.cjs +1 -0
  171. package/dist/sol/index.cjs.map +1 -1
  172. package/dist/sol/index.d.cts +1 -0
  173. package/dist/sol/index.d.cts.map +1 -1
  174. package/dist/sol/index.d.mts +1 -0
  175. package/dist/sol/index.d.mts.map +1 -1
  176. package/dist/sol/index.mjs +1 -0
  177. package/dist/sol/index.mjs.map +1 -1
  178. package/dist/sol/types.cjs +3 -3
  179. package/dist/sol/types.cjs.map +1 -1
  180. package/dist/sol/types.d.cts +3 -1
  181. package/dist/sol/types.d.cts.map +1 -1
  182. package/dist/sol/types.d.mts +3 -1
  183. package/dist/sol/types.d.mts.map +1 -1
  184. package/dist/sol/types.mjs +1 -1
  185. package/dist/sol/types.mjs.map +1 -1
  186. package/package.json +11 -14
  187. package/dist/JsonRpcRequest.cjs +0 -13
  188. package/dist/JsonRpcRequest.cjs.map +0 -1
  189. package/dist/JsonRpcRequest.d.cts +0 -17
  190. package/dist/JsonRpcRequest.d.cts.map +0 -1
  191. package/dist/JsonRpcRequest.d.mts +0 -17
  192. package/dist/JsonRpcRequest.d.mts.map +0 -1
  193. package/dist/JsonRpcRequest.mjs +0 -10
  194. package/dist/JsonRpcRequest.mjs.map +0 -1
  195. package/dist/KeyringClient.cjs +0 -130
  196. package/dist/KeyringClient.cjs.map +0 -1
  197. package/dist/KeyringClient.d.cts +0 -31
  198. package/dist/KeyringClient.d.cts.map +0 -1
  199. package/dist/KeyringClient.d.mts +0 -31
  200. package/dist/KeyringClient.d.mts.map +0 -1
  201. package/dist/KeyringClient.mjs +0 -126
  202. package/dist/KeyringClient.mjs.map +0 -1
  203. package/dist/KeyringSnapRpcClient.cjs +0 -68
  204. package/dist/KeyringSnapRpcClient.cjs.map +0 -1
  205. package/dist/KeyringSnapRpcClient.d.cts +0 -40
  206. package/dist/KeyringSnapRpcClient.d.cts.map +0 -1
  207. package/dist/KeyringSnapRpcClient.d.mts +0 -40
  208. package/dist/KeyringSnapRpcClient.d.mts.map +0 -1
  209. package/dist/KeyringSnapRpcClient.mjs +0 -63
  210. package/dist/KeyringSnapRpcClient.mjs.map +0 -1
  211. package/dist/internal/api.cjs.map +0 -1
  212. package/dist/internal/api.d.cts.map +0 -1
  213. package/dist/internal/api.d.mts.map +0 -1
  214. package/dist/internal/api.mjs.map +0 -1
  215. package/dist/internal/eth/EthKeyring.cjs +0 -3
  216. package/dist/internal/eth/EthKeyring.cjs.map +0 -1
  217. package/dist/internal/eth/EthKeyring.d.cts +0 -34
  218. package/dist/internal/eth/EthKeyring.d.cts.map +0 -1
  219. package/dist/internal/eth/EthKeyring.d.mts +0 -34
  220. package/dist/internal/eth/EthKeyring.d.mts.map +0 -1
  221. package/dist/internal/eth/EthKeyring.mjs +0 -2
  222. package/dist/internal/eth/EthKeyring.mjs.map +0 -1
  223. package/dist/internal/eth/index.cjs +0 -3
  224. package/dist/internal/eth/index.cjs.map +0 -1
  225. package/dist/internal/eth/index.d.cts +0 -2
  226. package/dist/internal/eth/index.d.cts.map +0 -1
  227. package/dist/internal/eth/index.d.mts +0 -2
  228. package/dist/internal/eth/index.d.mts.map +0 -1
  229. package/dist/internal/eth/index.mjs +0 -2
  230. package/dist/internal/eth/index.mjs.map +0 -1
  231. package/dist/internal/events.cjs +0 -72
  232. package/dist/internal/events.cjs.map +0 -1
  233. package/dist/internal/events.d.cts +0 -162
  234. package/dist/internal/events.d.cts.map +0 -1
  235. package/dist/internal/events.d.mts +0 -162
  236. package/dist/internal/events.d.mts.map +0 -1
  237. package/dist/internal/events.mjs +0 -69
  238. package/dist/internal/events.mjs.map +0 -1
  239. package/dist/internal/index.cjs +0 -21
  240. package/dist/internal/index.cjs.map +0 -1
  241. package/dist/internal/index.d.cts +0 -6
  242. package/dist/internal/index.d.cts.map +0 -1
  243. package/dist/internal/index.d.mts +0 -6
  244. package/dist/internal/index.d.mts.map +0 -1
  245. package/dist/internal/index.mjs +0 -5
  246. package/dist/internal/index.mjs.map +0 -1
  247. package/dist/internal/rpc.cjs +0 -34
  248. package/dist/internal/rpc.cjs.map +0 -1
  249. package/dist/internal/rpc.d.cts +0 -27
  250. package/dist/internal/rpc.d.cts.map +0 -1
  251. package/dist/internal/rpc.d.mts +0 -27
  252. package/dist/internal/rpc.d.mts.map +0 -1
  253. package/dist/internal/rpc.mjs +0 -30
  254. package/dist/internal/rpc.mjs.map +0 -1
  255. package/dist/internal/types.cjs +0 -52
  256. package/dist/internal/types.cjs.map +0 -1
  257. package/dist/internal/types.d.cts +0 -392
  258. package/dist/internal/types.d.cts.map +0 -1
  259. package/dist/internal/types.d.mts +0 -392
  260. package/dist/internal/types.d.mts.map +0 -1
  261. package/dist/internal/types.mjs +0 -49
  262. package/dist/internal/types.mjs.map +0 -1
  263. package/dist/rpc-handler.cjs +0 -143
  264. package/dist/rpc-handler.cjs.map +0 -1
  265. package/dist/rpc-handler.d.cts +0 -30
  266. package/dist/rpc-handler.d.cts.map +0 -1
  267. package/dist/rpc-handler.d.mts +0 -30
  268. package/dist/rpc-handler.d.mts.map +0 -1
  269. package/dist/rpc-handler.mjs +0 -138
  270. package/dist/rpc-handler.mjs.map +0 -1
  271. package/dist/snap-utils.cjs +0 -20
  272. package/dist/snap-utils.cjs.map +0 -1
  273. package/dist/snap-utils.d.cts +0 -12
  274. package/dist/snap-utils.d.cts.map +0 -1
  275. package/dist/snap-utils.d.mts +0 -12
  276. package/dist/snap-utils.d.mts.map +0 -1
  277. package/dist/snap-utils.mjs +0 -17
  278. package/dist/snap-utils.mjs.map +0 -1
  279. package/dist/superstruct.cjs +0 -109
  280. package/dist/superstruct.cjs.map +0 -1
  281. package/dist/superstruct.d.cts +0 -102
  282. package/dist/superstruct.d.cts.map +0 -1
  283. package/dist/superstruct.d.mts +0 -102
  284. package/dist/superstruct.d.mts.map +0 -1
  285. package/dist/superstruct.mjs +0 -102
  286. package/dist/superstruct.mjs.map +0 -1
  287. package/dist/utils/index.cjs +0 -20
  288. package/dist/utils/index.cjs.map +0 -1
  289. package/dist/utils/index.d.cts +0 -4
  290. package/dist/utils/index.d.cts.map +0 -1
  291. package/dist/utils/index.d.mts +0 -4
  292. package/dist/utils/index.d.mts.map +0 -1
  293. package/dist/utils/index.mjs +0 -4
  294. package/dist/utils/index.mjs.map +0 -1
  295. package/dist/utils/pagination.cjs.map +0 -1
  296. package/dist/utils/pagination.d.cts.map +0 -1
  297. package/dist/utils/pagination.d.mts.map +0 -1
  298. package/dist/utils/pagination.mjs.map +0 -1
  299. package/dist/utils/types.cjs +0 -29
  300. package/dist/utils/types.cjs.map +0 -1
  301. package/dist/utils/types.d.cts +0 -42
  302. package/dist/utils/types.d.cts.map +0 -1
  303. package/dist/utils/types.d.mts +0 -42
  304. package/dist/utils/types.d.mts.map +0 -1
  305. package/dist/utils/types.mjs +0 -26
  306. package/dist/utils/types.mjs.map +0 -1
  307. package/dist/utils/typing.cjs +0 -20
  308. package/dist/utils/typing.cjs.map +0 -1
  309. package/dist/utils/typing.d.cts +0 -33
  310. package/dist/utils/typing.d.cts.map +0 -1
  311. package/dist/utils/typing.d.mts +0 -33
  312. package/dist/utils/typing.d.mts.map +0 -1
  313. package/dist/utils/typing.mjs +0 -17
  314. package/dist/utils/typing.mjs.map +0 -1
@@ -1,30 +0,0 @@
1
- import type { Json } from "@metamask/utils";
2
- import type { Keyring } from "./api/index.mjs";
3
- import type { JsonRpcRequest } from "./JsonRpcRequest.mjs";
4
- /**
5
- * Error thrown when a keyring JSON-RPC method is not supported.
6
- */
7
- export declare class MethodNotSupportedError extends Error {
8
- constructor(method: string);
9
- }
10
- /**
11
- * Handles a keyring JSON-RPC request.
12
- *
13
- * This function is meant to be used as a handler for Keyring JSON-RPC requests
14
- * in an Accounts Snap.
15
- *
16
- * @param keyring - Keyring instance.
17
- * @param request - Keyring JSON-RPC request.
18
- * @returns A promise that resolves to the keyring response.
19
- * @example
20
- * ```ts
21
- * export const onKeyringRequest: OnKeyringRequestHandler = async ({
22
- * origin,
23
- * request,
24
- * }) => {
25
- * return await handleKeyringRequest(keyring, request);
26
- * };
27
- * ```
28
- */
29
- export declare function handleKeyringRequest(keyring: Keyring, request: JsonRpcRequest): Promise<Json | void>;
30
- //# sourceMappingURL=rpc-handler.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rpc-handler.d.mts","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EAAE,OAAO,EAAE,wBAAc;AAkBrC,OAAO,KAAK,EAAE,cAAc,EAAE,6BAAyB;AAGvD;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,MAAM,EAAE,MAAM;CAG3B;AA6HD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAWtB"}
@@ -1,138 +0,0 @@
1
- import { assert } from "@metamask/superstruct";
2
- import { GetAccountRequestStruct, CreateAccountRequestStruct, ListAccountTransactionsRequestStruct, ApproveRequestRequestStruct, DeleteAccountRequestStruct, ExportAccountRequestStruct, GetRequestRequestStruct, RejectRequestRequestStruct, SubmitRequestRequestStruct, UpdateAccountRequestStruct, FilterAccountChainsStruct, ListAccountsRequestStruct, ListRequestsRequestStruct, GetAccountBalancesRequestStruct } from "./internal/api.mjs";
3
- import { KeyringRpcMethod } from "./internal/rpc.mjs";
4
- import { JsonRpcRequestStruct } from "./JsonRpcRequest.mjs";
5
- /**
6
- * Error thrown when a keyring JSON-RPC method is not supported.
7
- */
8
- export class MethodNotSupportedError extends Error {
9
- constructor(method) {
10
- super(`Method not supported: ${method}`);
11
- }
12
- }
13
- /**
14
- * Inner function that dispatches JSON-RPC request to the associated Keyring
15
- * methods.
16
- *
17
- * @param keyring - Keyring instance.
18
- * @param request - Keyring JSON-RPC request.
19
- * @returns A promise that resolves to the keyring response.
20
- */
21
- async function dispatchRequest(keyring, request) {
22
- // We first have to make sure that the request is a valid JSON-RPC request so
23
- // we can check its method name.
24
- assert(request, JsonRpcRequestStruct);
25
- switch (request.method) {
26
- case `${KeyringRpcMethod.ListAccounts}`: {
27
- assert(request, ListAccountsRequestStruct);
28
- return keyring.listAccounts();
29
- }
30
- case `${KeyringRpcMethod.GetAccount}`: {
31
- assert(request, GetAccountRequestStruct);
32
- return keyring.getAccount(request.params.id);
33
- }
34
- case `${KeyringRpcMethod.CreateAccount}`: {
35
- assert(request, CreateAccountRequestStruct);
36
- return keyring.createAccount(request.params.options);
37
- }
38
- case `${KeyringRpcMethod.ListAccountTransactions}`: {
39
- if (keyring.listAccountTransactions === undefined) {
40
- throw new MethodNotSupportedError(request.method);
41
- }
42
- assert(request, ListAccountTransactionsRequestStruct);
43
- return keyring.listAccountTransactions(request.params.id, request.params.pagination);
44
- }
45
- case `${KeyringRpcMethod.GetAccountBalances}`: {
46
- if (keyring.getAccountBalances === undefined) {
47
- throw new MethodNotSupportedError(request.method);
48
- }
49
- assert(request, GetAccountBalancesRequestStruct);
50
- return keyring.getAccountBalances(request.params.id, request.params.assets);
51
- }
52
- case `${KeyringRpcMethod.FilterAccountChains}`: {
53
- assert(request, FilterAccountChainsStruct);
54
- return keyring.filterAccountChains(request.params.id, request.params.chains);
55
- }
56
- case `${KeyringRpcMethod.UpdateAccount}`: {
57
- assert(request, UpdateAccountRequestStruct);
58
- return keyring.updateAccount(request.params.account);
59
- }
60
- case `${KeyringRpcMethod.DeleteAccount}`: {
61
- assert(request, DeleteAccountRequestStruct);
62
- return keyring.deleteAccount(request.params.id);
63
- }
64
- case `${KeyringRpcMethod.ExportAccount}`: {
65
- if (keyring.exportAccount === undefined) {
66
- throw new MethodNotSupportedError(request.method);
67
- }
68
- assert(request, ExportAccountRequestStruct);
69
- return keyring.exportAccount(request.params.id);
70
- }
71
- case `${KeyringRpcMethod.ListRequests}`: {
72
- if (keyring.listRequests === undefined) {
73
- throw new MethodNotSupportedError(request.method);
74
- }
75
- assert(request, ListRequestsRequestStruct);
76
- return keyring.listRequests();
77
- }
78
- case `${KeyringRpcMethod.GetRequest}`: {
79
- if (keyring.getRequest === undefined) {
80
- throw new MethodNotSupportedError(request.method);
81
- }
82
- assert(request, GetRequestRequestStruct);
83
- return keyring.getRequest(request.params.id);
84
- }
85
- case `${KeyringRpcMethod.SubmitRequest}`: {
86
- assert(request, SubmitRequestRequestStruct);
87
- return keyring.submitRequest(request.params);
88
- }
89
- case `${KeyringRpcMethod.ApproveRequest}`: {
90
- if (keyring.approveRequest === undefined) {
91
- throw new MethodNotSupportedError(request.method);
92
- }
93
- assert(request, ApproveRequestRequestStruct);
94
- return keyring.approveRequest(request.params.id, request.params.data);
95
- }
96
- case `${KeyringRpcMethod.RejectRequest}`: {
97
- if (keyring.rejectRequest === undefined) {
98
- throw new MethodNotSupportedError(request.method);
99
- }
100
- assert(request, RejectRequestRequestStruct);
101
- return keyring.rejectRequest(request.params.id);
102
- }
103
- default: {
104
- throw new MethodNotSupportedError(request.method);
105
- }
106
- }
107
- }
108
- /**
109
- * Handles a keyring JSON-RPC request.
110
- *
111
- * This function is meant to be used as a handler for Keyring JSON-RPC requests
112
- * in an Accounts Snap.
113
- *
114
- * @param keyring - Keyring instance.
115
- * @param request - Keyring JSON-RPC request.
116
- * @returns A promise that resolves to the keyring response.
117
- * @example
118
- * ```ts
119
- * export const onKeyringRequest: OnKeyringRequestHandler = async ({
120
- * origin,
121
- * request,
122
- * }) => {
123
- * return await handleKeyringRequest(keyring, request);
124
- * };
125
- * ```
126
- */
127
- export async function handleKeyringRequest(keyring, request) {
128
- try {
129
- return await dispatchRequest(keyring, request);
130
- }
131
- catch (error) {
132
- const message = error instanceof Error && typeof error.message === 'string'
133
- ? error.message
134
- : 'An unknown error occurred while handling the keyring request';
135
- throw new Error(message);
136
- }
137
- }
138
- //# sourceMappingURL=rpc-handler.mjs.map
@@ -1 +0,0 @@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,EAAE,CAAC;QACf,MAAM,OAAO,GACX,KAAK,YAAY,KAAK,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;YACzD,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,8DAA8D,CAAC;QAErE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC","sourcesContent":["import { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\n\nimport type { Keyring } from './api';\nimport {\n GetAccountRequestStruct,\n CreateAccountRequestStruct,\n ListAccountTransactionsRequestStruct,\n ApproveRequestRequestStruct,\n DeleteAccountRequestStruct,\n ExportAccountRequestStruct,\n GetRequestRequestStruct,\n RejectRequestRequestStruct,\n SubmitRequestRequestStruct,\n UpdateAccountRequestStruct,\n FilterAccountChainsStruct,\n ListAccountsRequestStruct,\n ListRequestsRequestStruct,\n GetAccountBalancesRequestStruct,\n} from './internal/api';\nimport { KeyringRpcMethod } from './internal/rpc';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { JsonRpcRequestStruct } from './JsonRpcRequest';\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport class MethodNotSupportedError extends Error {\n constructor(method: string) {\n super(`Method not supported: ${method}`);\n }\n}\n\n/**\n * Inner function that dispatches JSON-RPC request to the associated Keyring\n * methods.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nasync function dispatchRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case `${KeyringRpcMethod.ListAccounts}`: {\n assert(request, ListAccountsRequestStruct);\n return keyring.listAccounts();\n }\n\n case `${KeyringRpcMethod.GetAccount}`: {\n assert(request, GetAccountRequestStruct);\n return keyring.getAccount(request.params.id);\n }\n\n case `${KeyringRpcMethod.CreateAccount}`: {\n assert(request, CreateAccountRequestStruct);\n return keyring.createAccount(request.params.options);\n }\n\n case `${KeyringRpcMethod.ListAccountTransactions}`: {\n if (keyring.listAccountTransactions === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ListAccountTransactionsRequestStruct);\n return keyring.listAccountTransactions(\n request.params.id,\n request.params.pagination,\n );\n }\n\n case `${KeyringRpcMethod.GetAccountBalances}`: {\n if (keyring.getAccountBalances === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetAccountBalancesRequestStruct);\n return keyring.getAccountBalances(\n request.params.id,\n request.params.assets,\n );\n }\n\n case `${KeyringRpcMethod.FilterAccountChains}`: {\n assert(request, FilterAccountChainsStruct);\n return keyring.filterAccountChains(\n request.params.id,\n request.params.chains,\n );\n }\n\n case `${KeyringRpcMethod.UpdateAccount}`: {\n assert(request, UpdateAccountRequestStruct);\n return keyring.updateAccount(request.params.account);\n }\n\n case `${KeyringRpcMethod.DeleteAccount}`: {\n assert(request, DeleteAccountRequestStruct);\n return keyring.deleteAccount(request.params.id);\n }\n\n case `${KeyringRpcMethod.ExportAccount}`: {\n if (keyring.exportAccount === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ExportAccountRequestStruct);\n return keyring.exportAccount(request.params.id);\n }\n\n case `${KeyringRpcMethod.ListRequests}`: {\n if (keyring.listRequests === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ListRequestsRequestStruct);\n return keyring.listRequests();\n }\n\n case `${KeyringRpcMethod.GetRequest}`: {\n if (keyring.getRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetRequestRequestStruct);\n return keyring.getRequest(request.params.id);\n }\n\n case `${KeyringRpcMethod.SubmitRequest}`: {\n assert(request, SubmitRequestRequestStruct);\n return keyring.submitRequest(request.params);\n }\n\n case `${KeyringRpcMethod.ApproveRequest}`: {\n if (keyring.approveRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ApproveRequestRequestStruct);\n return keyring.approveRequest(request.params.id, request.params.data);\n }\n\n case `${KeyringRpcMethod.RejectRequest}`: {\n if (keyring.rejectRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, RejectRequestRequestStruct);\n return keyring.rejectRequest(request.params.id);\n }\n\n default: {\n throw new MethodNotSupportedError(request.method);\n }\n }\n}\n\n/**\n * Handles a keyring JSON-RPC request.\n *\n * This function is meant to be used as a handler for Keyring JSON-RPC requests\n * in an Accounts Snap.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n * @example\n * ```ts\n * export const onKeyringRequest: OnKeyringRequestHandler = async ({\n * origin,\n * request,\n * }) => {\n * return await handleKeyringRequest(keyring, request);\n * };\n * ```\n */\nexport async function handleKeyringRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n try {\n return await dispatchRequest(keyring, request);\n } catch (error) {\n const message =\n error instanceof Error && typeof error.message === 'string'\n ? error.message\n : 'An unknown error occurred while handling the keyring request';\n\n throw new Error(message);\n }\n}\n"]}
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.emitSnapKeyringEvent = emitSnapKeyringEvent;
4
- /**
5
- * Emit a keyring event from a snap.
6
- *
7
- * @param snap - The global snap object.
8
- * @param event - The event name.
9
- * @param data - The event data.
10
- */
11
- async function emitSnapKeyringEvent(snap, event, data) {
12
- await snap.request({
13
- method: 'snap_manageAccounts',
14
- params: {
15
- method: event,
16
- params: { ...data },
17
- },
18
- });
19
- }
20
- //# sourceMappingURL=snap-utils.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snap-utils.cjs","sourceRoot":"","sources":["../src/snap-utils.ts"],"names":[],"mappings":";;AAYA,oDAYC;AAnBD;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,IAAmB,EACnB,KAAmB,EACnB,IAA0B;IAE1B,MAAM,IAAI,CAAC,OAAO,CAAC;QACjB,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE;SACpB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { SnapsProvider } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\n\nimport type { KeyringEvent } from './events';\n\n/**\n * Emit a keyring event from a snap.\n *\n * @param snap - The global snap object.\n * @param event - The event name.\n * @param data - The event data.\n */\nexport async function emitSnapKeyringEvent(\n snap: SnapsProvider,\n event: KeyringEvent,\n data: Record<string, Json>,\n): Promise<void> {\n await snap.request({\n method: 'snap_manageAccounts',\n params: {\n method: event,\n params: { ...data },\n },\n });\n}\n"]}
@@ -1,12 +0,0 @@
1
- import type { SnapsProvider } from "@metamask/snaps-sdk";
2
- import type { Json } from "@metamask/utils";
3
- import type { KeyringEvent } from "./events.cjs";
4
- /**
5
- * Emit a keyring event from a snap.
6
- *
7
- * @param snap - The global snap object.
8
- * @param event - The event name.
9
- * @param data - The event data.
10
- */
11
- export declare function emitSnapKeyringEvent(snap: SnapsProvider, event: KeyringEvent, data: Record<string, Json>): Promise<void>;
12
- //# sourceMappingURL=snap-utils.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snap-utils.d.cts","sourceRoot":"","sources":["../src/snap-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,4BAA4B;AACzD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAE7C;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,aAAa,EACnB,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GACzB,OAAO,CAAC,IAAI,CAAC,CAQf"}
@@ -1,12 +0,0 @@
1
- import type { SnapsProvider } from "@metamask/snaps-sdk";
2
- import type { Json } from "@metamask/utils";
3
- import type { KeyringEvent } from "./events.mjs";
4
- /**
5
- * Emit a keyring event from a snap.
6
- *
7
- * @param snap - The global snap object.
8
- * @param event - The event name.
9
- * @param data - The event data.
10
- */
11
- export declare function emitSnapKeyringEvent(snap: SnapsProvider, event: KeyringEvent, data: Record<string, Json>): Promise<void>;
12
- //# sourceMappingURL=snap-utils.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snap-utils.d.mts","sourceRoot":"","sources":["../src/snap-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,4BAA4B;AACzD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAE7C;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,aAAa,EACnB,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GACzB,OAAO,CAAC,IAAI,CAAC,CAQf"}
@@ -1,17 +0,0 @@
1
- /**
2
- * Emit a keyring event from a snap.
3
- *
4
- * @param snap - The global snap object.
5
- * @param event - The event name.
6
- * @param data - The event data.
7
- */
8
- export async function emitSnapKeyringEvent(snap, event, data) {
9
- await snap.request({
10
- method: 'snap_manageAccounts',
11
- params: {
12
- method: event,
13
- params: { ...data },
14
- },
15
- });
16
- }
17
- //# sourceMappingURL=snap-utils.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snap-utils.mjs","sourceRoot":"","sources":["../src/snap-utils.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,IAAmB,EACnB,KAAmB,EACnB,IAA0B;IAE1B,MAAM,IAAI,CAAC,OAAO,CAAC;QACjB,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE;SACpB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { SnapsProvider } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\n\nimport type { KeyringEvent } from './events';\n\n/**\n * Emit a keyring event from a snap.\n *\n * @param snap - The global snap object.\n * @param event - The event name.\n * @param data - The event data.\n */\nexport async function emitSnapKeyringEvent(\n snap: SnapsProvider,\n event: KeyringEvent,\n data: Record<string, Json>,\n): Promise<void> {\n await snap.request({\n method: 'snap_manageAccounts',\n params: {\n method: event,\n params: { ...data },\n },\n });\n}\n"]}
@@ -1,109 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.object = object;
4
- exports.exactOptional = exactOptional;
5
- exports.definePattern = definePattern;
6
- exports.strictMask = strictMask;
7
- exports.selectiveUnion = selectiveUnion;
8
- const superstruct_1 = require("@metamask/superstruct");
9
- /**
10
- * Change the return type of a superstruct object struct to support exact
11
- * optional properties.
12
- *
13
- * @param schema - The object schema.
14
- * @returns A struct representing an object with a known set of properties.
15
- */
16
- function object(schema) {
17
- return (0, superstruct_1.object)(schema);
18
- }
19
- /**
20
- * Check if the current property is present in its parent object.
21
- *
22
- * @param ctx - The context to check.
23
- * @returns `true` if the property is present, `false` otherwise.
24
- */
25
- function hasOptional(ctx) {
26
- const property = ctx.path[ctx.path.length - 1];
27
- const parent = ctx.branch[ctx.branch.length - 2];
28
- return property in parent;
29
- }
30
- /**
31
- * Augment a struct to allow exact-optional values. Exact-optional values can
32
- * be omitted but cannot be `undefined`.
33
- *
34
- * ```ts
35
- * const foo = object({ bar: exactOptional(string()) });
36
- * type Foo = Infer<typeof foo>;
37
- * // Foo = { bar?: string }
38
- * ```
39
- *
40
- * @param struct - The struct to augment.
41
- * @returns The augmented struct.
42
- */
43
- function exactOptional(struct) {
44
- return new superstruct_1.Struct({
45
- ...struct,
46
- validator: (value, ctx) => !hasOptional(ctx) || struct.validator(value, ctx),
47
- refiner: (value, ctx) => !hasOptional(ctx) || struct.refiner(value, ctx),
48
- });
49
- }
50
- /**
51
- * Defines a new string-struct matching a regular expression.
52
- *
53
- * Example:
54
- *
55
- * ```ts
56
- * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
57
- * ```
58
- *
59
- * @param name - Type name.
60
- * @param pattern - Regular expression to match.
61
- * @returns A new string-struct that matches the given pattern.
62
- */
63
- function definePattern(name, pattern) {
64
- return (0, superstruct_1.define)(name, (value) => typeof value === 'string' && pattern.test(value));
65
- }
66
- /**
67
- * Assert that a value is valid according to a struct.
68
- *
69
- * It is similar to superstruct's mask function, but it does not ignore extra
70
- * properties.
71
- *
72
- * @param value - Value to check.
73
- * @param struct - Struct to validate the value against.
74
- * @param message - Error message to throw if the value is not valid.
75
- * @returns The value if it is valid.
76
- */
77
- function strictMask(value, struct, message) {
78
- (0, superstruct_1.assert)(value, struct, message);
79
- return value;
80
- }
81
- /**
82
- * Create a custom union struct that uses a `selector` function for choosing
83
- * the validation path.
84
- *
85
- * @param selector - The selector function choosing the struct to validate with.
86
- * @returns The `superstruct` struct, which validates that the value satisfies
87
- * one of the structs.
88
- */
89
- function selectiveUnion(selector) {
90
- return new superstruct_1.Struct({
91
- type: 'union',
92
- schema: null,
93
- *entries(value, context) {
94
- yield* selector(value).entries(value, context);
95
- },
96
- *refiner(value, context) {
97
- yield* selector(value).refiner(value, context);
98
- },
99
- coercer(value, context) {
100
- return selector(value).coercer(value, context);
101
- },
102
- validator(value, context) {
103
- // This only validates the root of the struct, entries does the rest of
104
- // the work.
105
- return selector(value).validator(value, context);
106
- },
107
- });
108
- }
109
- //# sourceMappingURL=superstruct.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"superstruct.cjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;AAoEA,wBAIC;AA4BD,sCAYC;AAeD,sCASC;AAaD,gCAOC;AAwBD,wCAyBC;AA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AAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAgBD;;;;;;;GAOG;AACH,SAAgB,cAAc,CAC5B,QAAkB;IAElB,OAAO,IAAI,oBAAM,CAAC;QAChB,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,IAAI;QAEZ,CAAC,OAAO,CAAC,KAAU,EAAE,OAAY;YAC/B,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO;YACrB,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,CAAC,KAAK,EAAE,OAAO;YACpB,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,SAAS,CAAC,KAAK,EAAE,OAAO;YACtB,uEAAuE;YACvE,YAAY;YACZ,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n Struct,\n assert,\n define,\n object as stObject,\n} from '@metamask/superstruct';\nimport type {\n Infer,\n Context,\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n AnyStruct,\n} from '@metamask/superstruct';\n\nimport type { Equals } from './utils';\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n\n/**\n * Extracts the type from a struct definition and asserts that it matches the\n * expected type. If the types do not match, the type `never` is returned.\n *\n * @param StructType - The struct type to infer.\n * @param ExpectedType - The expected type.\n */\nexport type InferEquals<\n StructType extends Struct<any, any>,\n ExpectedType,\n> = Equals<Infer<StructType>, ExpectedType> extends true\n ? Infer<StructType>\n : never;\n\n/**\n * Create a custom union struct that uses a `selector` function for choosing\n * the validation path.\n *\n * @param selector - The selector function choosing the struct to validate with.\n * @returns The `superstruct` struct, which validates that the value satisfies\n * one of the structs.\n */\nexport function selectiveUnion<Selector extends (value: any) => AnyStruct>(\n selector: Selector,\n): Struct<Infer<ReturnType<Selector>>, null> {\n return new Struct({\n type: 'union',\n schema: null,\n\n *entries(value: any, context: any): ReturnType<Struct['entries']> {\n yield* selector(value).entries(value, context);\n },\n\n *refiner(value, context): ReturnType<Struct['refiner']> {\n yield* selector(value).refiner(value, context);\n },\n\n coercer(value, context): ReturnType<Struct['coercer']> {\n return selector(value).coercer(value, context);\n },\n\n validator(value, context): ReturnType<Struct['validator']> {\n // This only validates the root of the struct, entries does the rest of\n // the work.\n return selector(value).validator(value, context);\n },\n });\n}\n"]}
@@ -1,102 +0,0 @@
1
- import { Struct } from "@metamask/superstruct";
2
- import type { Infer, ObjectSchema, OmitBy, Optionalize, PickBy, Simplify, AnyStruct } from "@metamask/superstruct";
3
- import type { Equals } from "./utils/index.cjs";
4
- declare const ExactOptionalSymbol: unique symbol;
5
- export type ExactOptionalTag = {
6
- type: typeof ExactOptionalSymbol;
7
- };
8
- /**
9
- * Exclude type `Type` from the properties of `Obj`.
10
- *
11
- * ```ts
12
- * type Foo = { a: string | null; b: number };
13
- * type Bar = ExcludeType<Foo, null>;
14
- * // Bar = { a: string, b: number }
15
- * ```
16
- */
17
- export type ExcludeType<Obj, Type> = {
18
- [K in keyof Obj]: Exclude<Obj[K], Type>;
19
- };
20
- /**
21
- * Make optional all properties that have the `ExactOptionalTag` type.
22
- *
23
- * ```ts
24
- * type Foo = { a: string | ExactOptionalTag; b: number};
25
- * type Bar = ExactOptionalize<Foo>;
26
- * // Bar = { a?: string; b: number}
27
- * ```
28
- */
29
- export type ExactOptionalize<Schema extends object> = OmitBy<Schema, ExactOptionalTag> & Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;
30
- /**
31
- * Infer a type from an superstruct object schema.
32
- */
33
- export type ObjectType<Schema extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
34
- [K in keyof Schema]: Infer<Schema[K]>;
35
- }>>>;
36
- /**
37
- * Change the return type of a superstruct object struct to support exact
38
- * optional properties.
39
- *
40
- * @param schema - The object schema.
41
- * @returns A struct representing an object with a known set of properties.
42
- */
43
- export declare function object<Schema extends ObjectSchema>(schema: Schema): Struct<ObjectType<Schema>, Schema>;
44
- /**
45
- * Augment a struct to allow exact-optional values. Exact-optional values can
46
- * be omitted but cannot be `undefined`.
47
- *
48
- * ```ts
49
- * const foo = object({ bar: exactOptional(string()) });
50
- * type Foo = Infer<typeof foo>;
51
- * // Foo = { bar?: string }
52
- * ```
53
- *
54
- * @param struct - The struct to augment.
55
- * @returns The augmented struct.
56
- */
57
- export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>): Struct<Type | ExactOptionalTag, Schema>;
58
- /**
59
- * Defines a new string-struct matching a regular expression.
60
- *
61
- * Example:
62
- *
63
- * ```ts
64
- * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
65
- * ```
66
- *
67
- * @param name - Type name.
68
- * @param pattern - Regular expression to match.
69
- * @returns A new string-struct that matches the given pattern.
70
- */
71
- export declare function definePattern(name: string, pattern: RegExp): Struct<string, null>;
72
- /**
73
- * Assert that a value is valid according to a struct.
74
- *
75
- * It is similar to superstruct's mask function, but it does not ignore extra
76
- * properties.
77
- *
78
- * @param value - Value to check.
79
- * @param struct - Struct to validate the value against.
80
- * @param message - Error message to throw if the value is not valid.
81
- * @returns The value if it is valid.
82
- */
83
- export declare function strictMask<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, message?: string): Type;
84
- /**
85
- * Extracts the type from a struct definition and asserts that it matches the
86
- * expected type. If the types do not match, the type `never` is returned.
87
- *
88
- * @param StructType - The struct type to infer.
89
- * @param ExpectedType - The expected type.
90
- */
91
- export type InferEquals<StructType extends Struct<any, any>, ExpectedType> = Equals<Infer<StructType>, ExpectedType> extends true ? Infer<StructType> : never;
92
- /**
93
- * Create a custom union struct that uses a `selector` function for choosing
94
- * the validation path.
95
- *
96
- * @param selector - The selector function choosing the struct to validate with.
97
- * @returns The `superstruct` struct, which validates that the value satisfies
98
- * one of the structs.
99
- */
100
- export declare function selectiveUnion<Selector extends (value: any) => AnyStruct>(selector: Selector): Struct<Infer<ReturnType<Selector>>, null>;
101
- export {};
102
- //# sourceMappingURL=superstruct.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"superstruct.d.cts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAIP,8BAA8B;AAC/B,OAAO,KAAK,EACV,KAAK,EAEL,YAAY,EACZ,MAAM,EACN,WAAW,EACX,MAAM,EACN,QAAQ,EACR,SAAS,EACV,8BAA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ACd,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAMtB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EACrC,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,EAC5B,OAAO,CAAC,EAAE,MAAM,GACf,IAAI,CAGN;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CACrB,UAAU,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EACnC,YAAY,IACV,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,SAAS,IAAI,GACpD,KAAK,CAAC,UAAU,CAAC,GACjB,KAAK,CAAC;AAEV;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,QAAQ,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,SAAS,EACvE,QAAQ,EAAE,QAAQ,GACjB,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAuB3C"}
@@ -1,102 +0,0 @@
1
- import { Struct } from "@metamask/superstruct";
2
- import type { Infer, ObjectSchema, OmitBy, Optionalize, PickBy, Simplify, AnyStruct } from "@metamask/superstruct";
3
- import type { Equals } from "./utils/index.mjs";
4
- declare const ExactOptionalSymbol: unique symbol;
5
- export type ExactOptionalTag = {
6
- type: typeof ExactOptionalSymbol;
7
- };
8
- /**
9
- * Exclude type `Type` from the properties of `Obj`.
10
- *
11
- * ```ts
12
- * type Foo = { a: string | null; b: number };
13
- * type Bar = ExcludeType<Foo, null>;
14
- * // Bar = { a: string, b: number }
15
- * ```
16
- */
17
- export type ExcludeType<Obj, Type> = {
18
- [K in keyof Obj]: Exclude<Obj[K], Type>;
19
- };
20
- /**
21
- * Make optional all properties that have the `ExactOptionalTag` type.
22
- *
23
- * ```ts
24
- * type Foo = { a: string | ExactOptionalTag; b: number};
25
- * type Bar = ExactOptionalize<Foo>;
26
- * // Bar = { a?: string; b: number}
27
- * ```
28
- */
29
- export type ExactOptionalize<Schema extends object> = OmitBy<Schema, ExactOptionalTag> & Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;
30
- /**
31
- * Infer a type from an superstruct object schema.
32
- */
33
- export type ObjectType<Schema extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
34
- [K in keyof Schema]: Infer<Schema[K]>;
35
- }>>>;
36
- /**
37
- * Change the return type of a superstruct object struct to support exact
38
- * optional properties.
39
- *
40
- * @param schema - The object schema.
41
- * @returns A struct representing an object with a known set of properties.
42
- */
43
- export declare function object<Schema extends ObjectSchema>(schema: Schema): Struct<ObjectType<Schema>, Schema>;
44
- /**
45
- * Augment a struct to allow exact-optional values. Exact-optional values can
46
- * be omitted but cannot be `undefined`.
47
- *
48
- * ```ts
49
- * const foo = object({ bar: exactOptional(string()) });
50
- * type Foo = Infer<typeof foo>;
51
- * // Foo = { bar?: string }
52
- * ```
53
- *
54
- * @param struct - The struct to augment.
55
- * @returns The augmented struct.
56
- */
57
- export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>): Struct<Type | ExactOptionalTag, Schema>;
58
- /**
59
- * Defines a new string-struct matching a regular expression.
60
- *
61
- * Example:
62
- *
63
- * ```ts
64
- * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
65
- * ```
66
- *
67
- * @param name - Type name.
68
- * @param pattern - Regular expression to match.
69
- * @returns A new string-struct that matches the given pattern.
70
- */
71
- export declare function definePattern(name: string, pattern: RegExp): Struct<string, null>;
72
- /**
73
- * Assert that a value is valid according to a struct.
74
- *
75
- * It is similar to superstruct's mask function, but it does not ignore extra
76
- * properties.
77
- *
78
- * @param value - Value to check.
79
- * @param struct - Struct to validate the value against.
80
- * @param message - Error message to throw if the value is not valid.
81
- * @returns The value if it is valid.
82
- */
83
- export declare function strictMask<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, message?: string): Type;
84
- /**
85
- * Extracts the type from a struct definition and asserts that it matches the
86
- * expected type. If the types do not match, the type `never` is returned.
87
- *
88
- * @param StructType - The struct type to infer.
89
- * @param ExpectedType - The expected type.
90
- */
91
- export type InferEquals<StructType extends Struct<any, any>, ExpectedType> = Equals<Infer<StructType>, ExpectedType> extends true ? Infer<StructType> : never;
92
- /**
93
- * Create a custom union struct that uses a `selector` function for choosing
94
- * the validation path.
95
- *
96
- * @param selector - The selector function choosing the struct to validate with.
97
- * @returns The `superstruct` struct, which validates that the value satisfies
98
- * one of the structs.
99
- */
100
- export declare function selectiveUnion<Selector extends (value: any) => AnyStruct>(selector: Selector): Struct<Infer<ReturnType<Selector>>, null>;
101
- export {};
102
- //# sourceMappingURL=superstruct.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"superstruct.d.mts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAIP,8BAA8B;AAC/B,OAAO,KAAK,EACV,KAAK,EAEL,YAAY,EACZ,MAAM,EACN,WAAW,EACX,MAAM,EACN,QAAQ,EACR,SAAS,EACV,8BAA8B;AAE/B,OAAO,KAAK,EAAE,MAAM,EAAE,0BAAgB;AAGtC,OAAO,CAAC,MAAM,mBAAmB,EAAE,OAAO,MAAM,CAAC;AAEjD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,OAAO,mBAAmB,CAAC;CAClC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,CAAC,GAAG,EAAE,IAAI,IAAI;KAClC,CAAC,IAAI,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;CACxC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,MAAM,IAAI,MAAM,CAC1D,MAAM,EACN,gBAAgB,CACjB,GACC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAA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