@metamask/keyring-api 10.0.0 → 11.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 (330) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/{JsonRpcRequest.js → JsonRpcRequest.cjs} +2 -2
  3. package/dist/JsonRpcRequest.cjs.map +1 -0
  4. package/dist/{JsonRpcRequest.d.ts → JsonRpcRequest.d.cts} +3 -2
  5. package/dist/JsonRpcRequest.d.cts.map +1 -0
  6. package/dist/JsonRpcRequest.d.mts +17 -0
  7. package/dist/JsonRpcRequest.d.mts.map +1 -0
  8. package/dist/JsonRpcRequest.mjs +10 -0
  9. package/dist/JsonRpcRequest.mjs.map +1 -0
  10. package/dist/{KeyringClient.js → KeyringClient.cjs} +4 -4
  11. package/dist/KeyringClient.cjs.map +1 -0
  12. package/dist/{KeyringClient.d.ts → KeyringClient.d.cts} +4 -3
  13. package/dist/KeyringClient.d.cts.map +1 -0
  14. package/dist/KeyringClient.d.mts +29 -0
  15. package/dist/KeyringClient.d.mts.map +1 -0
  16. package/dist/KeyringClient.mjs +120 -0
  17. package/dist/KeyringClient.mjs.map +1 -0
  18. package/dist/{KeyringSnapRpcClient.js → KeyringSnapRpcClient.cjs} +2 -2
  19. package/dist/KeyringSnapRpcClient.cjs.map +1 -0
  20. package/dist/{KeyringSnapRpcClient.d.ts → KeyringSnapRpcClient.d.cts} +6 -5
  21. package/dist/KeyringSnapRpcClient.d.cts.map +1 -0
  22. package/dist/KeyringSnapRpcClient.d.mts +40 -0
  23. package/dist/KeyringSnapRpcClient.d.mts.map +1 -0
  24. package/dist/KeyringSnapRpcClient.mjs +63 -0
  25. package/dist/KeyringSnapRpcClient.mjs.map +1 -0
  26. package/dist/api/{account.js → account.cjs} +12 -4
  27. package/dist/api/account.cjs.map +1 -0
  28. package/dist/api/{account.d.ts → account.d.cts} +12 -4
  29. package/dist/api/account.d.cts.map +1 -0
  30. package/dist/api/account.d.mts +70 -0
  31. package/dist/api/account.d.mts.map +1 -0
  32. package/dist/api/account.mjs +61 -0
  33. package/dist/api/account.mjs.map +1 -0
  34. package/dist/api/{balance.js → balance.cjs} +3 -3
  35. package/dist/api/balance.cjs.map +1 -0
  36. package/dist/api/{balance.d.ts → balance.d.cts} +2 -1
  37. package/dist/api/balance.d.cts.map +1 -0
  38. package/dist/api/balance.d.mts +10 -0
  39. package/dist/api/balance.d.mts.map +1 -0
  40. package/dist/api/balance.mjs +8 -0
  41. package/dist/api/balance.mjs.map +1 -0
  42. package/dist/api/{caip.js → caip.cjs} +5 -5
  43. package/dist/api/caip.cjs.map +1 -0
  44. package/dist/api/{caip.d.ts → caip.d.cts} +2 -1
  45. package/dist/api/caip.d.cts.map +1 -0
  46. package/dist/api/caip.d.mts +38 -0
  47. package/dist/api/caip.d.mts.map +1 -0
  48. package/dist/api/caip.mjs +43 -0
  49. package/dist/api/caip.mjs.map +1 -0
  50. package/dist/api/{export.js → export.cjs} +1 -1
  51. package/dist/api/export.cjs.map +1 -0
  52. package/dist/api/{export.d.ts → export.d.cts} +2 -1
  53. package/dist/api/export.d.cts.map +1 -0
  54. package/dist/api/export.d.mts +9 -0
  55. package/dist/api/export.d.mts.map +1 -0
  56. package/dist/api/export.mjs +4 -0
  57. package/dist/api/export.mjs.map +1 -0
  58. package/dist/api/{index.js → index.cjs} +7 -7
  59. package/dist/api/index.cjs.map +1 -0
  60. package/dist/api/index.d.cts +8 -0
  61. package/dist/api/index.d.cts.map +1 -0
  62. package/dist/api/index.d.mts +8 -0
  63. package/dist/api/index.d.mts.map +1 -0
  64. package/dist/api/index.mjs +7 -0
  65. package/dist/api/index.mjs.map +1 -0
  66. package/dist/api/{keyring.js → keyring.cjs} +1 -1
  67. package/dist/api/keyring.cjs.map +1 -0
  68. package/dist/api/{keyring.d.ts → keyring.d.cts} +8 -7
  69. package/dist/api/keyring.d.cts.map +1 -0
  70. package/dist/api/keyring.d.mts +160 -0
  71. package/dist/api/keyring.d.mts.map +1 -0
  72. package/dist/api/keyring.mjs +2 -0
  73. package/dist/api/keyring.mjs.map +1 -0
  74. package/dist/api/{request.js → request.cjs} +3 -3
  75. package/dist/api/request.cjs.map +1 -0
  76. package/dist/api/{request.d.ts → request.d.cts} +3 -2
  77. package/dist/api/request.d.cts.map +1 -0
  78. package/dist/api/request.d.mts +40 -0
  79. package/dist/api/request.d.mts.map +1 -0
  80. package/dist/api/request.mjs +26 -0
  81. package/dist/api/request.mjs.map +1 -0
  82. package/dist/api/{response.js → response.cjs} +2 -2
  83. package/dist/api/response.cjs.map +1 -0
  84. package/dist/api/{response.d.ts → response.d.cts} +2 -1
  85. package/dist/api/response.d.cts.map +1 -0
  86. package/dist/api/response.d.mts +25 -0
  87. package/dist/api/response.d.mts.map +1 -0
  88. package/dist/api/response.mjs +41 -0
  89. package/dist/api/response.mjs.map +1 -0
  90. package/dist/{eth/erc4337/index.js → btc/index.cjs} +2 -2
  91. package/dist/btc/index.cjs.map +1 -0
  92. package/dist/btc/index.d.cts +2 -0
  93. package/dist/btc/index.d.cts.map +1 -0
  94. package/dist/btc/index.d.mts +2 -0
  95. package/dist/btc/index.d.mts.map +1 -0
  96. package/dist/btc/index.mjs +2 -0
  97. package/dist/btc/index.mjs.map +1 -0
  98. package/dist/btc/{types.js → types.cjs} +3 -3
  99. package/dist/btc/types.cjs.map +1 -0
  100. package/dist/btc/{types.d.ts → types.d.cts} +2 -1
  101. package/dist/btc/types.d.cts.map +1 -0
  102. package/dist/btc/types.d.mts +34 -0
  103. package/dist/btc/types.d.mts.map +1 -0
  104. package/dist/btc/types.mjs +37 -0
  105. package/dist/btc/types.mjs.map +1 -0
  106. package/dist/{contexts.js → contexts.cjs} +1 -1
  107. package/dist/contexts.cjs.map +1 -0
  108. package/dist/{contexts.d.ts → contexts.d.cts} +1 -0
  109. package/dist/contexts.d.cts.map +1 -0
  110. package/dist/contexts.d.mts +8 -0
  111. package/dist/contexts.d.mts.map +1 -0
  112. package/dist/contexts.mjs +2 -0
  113. package/dist/contexts.mjs.map +1 -0
  114. package/dist/{btc/index.js → eth/erc4337/index.cjs} +2 -2
  115. package/dist/eth/erc4337/index.cjs.map +1 -0
  116. package/dist/eth/erc4337/index.d.cts +2 -0
  117. package/dist/eth/erc4337/index.d.cts.map +1 -0
  118. package/dist/eth/erc4337/index.d.mts +2 -0
  119. package/dist/eth/erc4337/index.d.mts.map +1 -0
  120. package/dist/eth/erc4337/index.mjs +2 -0
  121. package/dist/eth/erc4337/index.mjs.map +1 -0
  122. package/dist/eth/erc4337/{types.js → types.cjs} +4 -4
  123. package/dist/eth/erc4337/types.cjs.map +1 -0
  124. package/dist/eth/erc4337/{types.d.ts → types.d.cts} +6 -5
  125. package/dist/eth/erc4337/types.d.cts.map +1 -0
  126. package/dist/eth/erc4337/types.d.mts +98 -0
  127. package/dist/eth/erc4337/types.d.mts.map +1 -0
  128. package/dist/eth/erc4337/types.mjs +59 -0
  129. package/dist/eth/erc4337/types.mjs.map +1 -0
  130. package/dist/eth/index.cjs +20 -0
  131. package/dist/eth/index.cjs.map +1 -0
  132. package/dist/eth/index.d.cts +4 -0
  133. package/dist/eth/index.d.cts.map +1 -0
  134. package/dist/eth/index.d.mts +4 -0
  135. package/dist/eth/index.d.mts.map +1 -0
  136. package/dist/eth/index.mjs +4 -0
  137. package/dist/eth/index.mjs.map +1 -0
  138. package/dist/eth/{types.js → types.cjs} +3 -3
  139. package/dist/eth/types.cjs.map +1 -0
  140. package/dist/eth/{types.d.ts → types.d.cts} +2 -1
  141. package/dist/eth/types.d.cts.map +1 -0
  142. package/dist/eth/types.d.mts +81 -0
  143. package/dist/eth/types.d.mts.map +1 -0
  144. package/dist/eth/types.mjs +70 -0
  145. package/dist/eth/types.mjs.map +1 -0
  146. package/dist/eth/{utils.js → utils.cjs} +3 -4
  147. package/dist/eth/{utils.js.map → utils.cjs.map} +1 -1
  148. package/dist/eth/{utils.d.ts → utils.d.cts} +2 -1
  149. package/dist/eth/utils.d.cts.map +1 -0
  150. package/dist/eth/utils.d.mts +9 -0
  151. package/dist/eth/utils.d.mts.map +1 -0
  152. package/dist/eth/utils.mjs +11 -0
  153. package/dist/eth/utils.mjs.map +1 -0
  154. package/dist/{events.js → events.cjs} +1 -1
  155. package/dist/events.cjs.map +1 -0
  156. package/dist/{events.d.ts → events.d.cts} +1 -0
  157. package/dist/events.d.cts.map +1 -0
  158. package/dist/events.d.mts +11 -0
  159. package/dist/events.d.mts.map +1 -0
  160. package/dist/events.mjs +14 -0
  161. package/dist/events.mjs.map +1 -0
  162. package/dist/index.cjs +29 -0
  163. package/dist/index.cjs.map +1 -0
  164. package/dist/index.d.cts +14 -0
  165. package/dist/index.d.cts.map +1 -0
  166. package/dist/index.d.mts +14 -0
  167. package/dist/index.d.mts.map +1 -0
  168. package/dist/index.mjs +13 -0
  169. package/dist/index.mjs.map +1 -0
  170. package/dist/internal/{api.js → api.cjs} +5 -5
  171. package/dist/internal/api.cjs.map +1 -0
  172. package/dist/internal/{api.d.ts → api.d.cts} +20 -15
  173. package/dist/internal/api.d.cts.map +1 -0
  174. package/dist/internal/api.d.mts +420 -0
  175. package/dist/internal/api.d.mts.map +1 -0
  176. package/dist/internal/api.mjs +136 -0
  177. package/dist/internal/api.mjs.map +1 -0
  178. package/dist/internal/eth/{EthKeyring.js → EthKeyring.cjs} +1 -1
  179. package/dist/internal/eth/EthKeyring.cjs.map +1 -0
  180. package/dist/internal/eth/{EthKeyring.d.ts → EthKeyring.d.cts} +4 -3
  181. package/dist/internal/eth/EthKeyring.d.cts.map +1 -0
  182. package/dist/internal/eth/EthKeyring.d.mts +34 -0
  183. package/dist/internal/eth/EthKeyring.d.mts.map +1 -0
  184. package/dist/internal/eth/EthKeyring.mjs +2 -0
  185. package/dist/internal/eth/EthKeyring.mjs.map +1 -0
  186. package/dist/internal/eth/{index.js → index.cjs} +1 -1
  187. package/dist/internal/eth/index.cjs.map +1 -0
  188. package/dist/internal/eth/index.d.cts +2 -0
  189. package/dist/internal/eth/index.d.cts.map +1 -0
  190. package/dist/internal/eth/index.d.mts +2 -0
  191. package/dist/internal/eth/index.d.mts.map +1 -0
  192. package/dist/internal/eth/index.mjs +2 -0
  193. package/dist/internal/eth/index.mjs.map +1 -0
  194. package/dist/internal/{events.js → events.cjs} +5 -5
  195. package/dist/internal/events.cjs.map +1 -0
  196. package/dist/internal/{events.d.ts → events.d.cts} +13 -10
  197. package/dist/internal/events.d.cts.map +1 -0
  198. package/dist/internal/events.d.mts +162 -0
  199. package/dist/internal/events.d.mts.map +1 -0
  200. package/dist/internal/events.mjs +69 -0
  201. package/dist/internal/events.mjs.map +1 -0
  202. package/dist/internal/{index.js → index.cjs} +5 -5
  203. package/dist/internal/index.cjs.map +1 -0
  204. package/dist/internal/index.d.cts +6 -0
  205. package/dist/internal/index.d.cts.map +1 -0
  206. package/dist/internal/index.d.mts +6 -0
  207. package/dist/internal/index.d.mts.map +1 -0
  208. package/dist/internal/index.mjs +5 -0
  209. package/dist/internal/index.mjs.map +1 -0
  210. package/dist/internal/{rpc.js → rpc.cjs} +3 -3
  211. package/dist/internal/rpc.cjs.map +1 -0
  212. package/dist/internal/{rpc.d.ts → rpc.d.cts} +1 -0
  213. package/dist/internal/rpc.d.cts.map +1 -0
  214. package/dist/internal/rpc.d.mts +26 -0
  215. package/dist/internal/rpc.d.mts.map +1 -0
  216. package/dist/internal/rpc.mjs +29 -0
  217. package/dist/internal/{rpc.js.map → rpc.mjs.map} +1 -1
  218. package/dist/internal/{types.js → types.cjs} +12 -6
  219. package/dist/internal/types.cjs.map +1 -0
  220. package/dist/internal/{types.d.ts → types.d.cts} +87 -22
  221. package/dist/internal/types.d.cts.map +1 -0
  222. package/dist/internal/types.d.mts +392 -0
  223. package/dist/internal/types.d.mts.map +1 -0
  224. package/dist/internal/types.mjs +49 -0
  225. package/dist/internal/types.mjs.map +1 -0
  226. package/dist/{rpc-handler.js → rpc-handler.cjs} +6 -6
  227. package/dist/rpc-handler.cjs.map +1 -0
  228. package/dist/{rpc-handler.d.ts → rpc-handler.d.cts} +4 -3
  229. package/dist/rpc-handler.d.cts.map +1 -0
  230. package/dist/rpc-handler.d.mts +30 -0
  231. package/dist/rpc-handler.d.mts.map +1 -0
  232. package/dist/rpc-handler.mjs +131 -0
  233. package/dist/rpc-handler.mjs.map +1 -0
  234. package/dist/{snap-utils.js → snap-utils.cjs} +2 -3
  235. package/dist/snap-utils.cjs.map +1 -0
  236. package/dist/{snap-utils.d.ts → snap-utils.d.cts} +4 -3
  237. package/dist/snap-utils.d.cts.map +1 -0
  238. package/dist/snap-utils.d.mts +12 -0
  239. package/dist/snap-utils.d.mts.map +1 -0
  240. package/dist/snap-utils.mjs +17 -0
  241. package/dist/snap-utils.mjs.map +1 -0
  242. package/dist/{utils/index.js → sol/index.cjs} +2 -3
  243. package/dist/sol/index.cjs.map +1 -0
  244. package/dist/sol/index.d.cts +2 -0
  245. package/dist/sol/index.d.cts.map +1 -0
  246. package/dist/sol/index.d.mts +2 -0
  247. package/dist/sol/index.d.mts.map +1 -0
  248. package/dist/sol/index.mjs +2 -0
  249. package/dist/sol/index.mjs.map +1 -0
  250. package/dist/sol/types.cjs +36 -0
  251. package/dist/sol/types.cjs.map +1 -0
  252. package/dist/sol/types.d.cts +39 -0
  253. package/dist/sol/types.d.cts.map +1 -0
  254. package/dist/sol/types.d.mts +39 -0
  255. package/dist/sol/types.d.mts.map +1 -0
  256. package/dist/sol/types.mjs +33 -0
  257. package/dist/sol/types.mjs.map +1 -0
  258. package/dist/{superstruct.js → superstruct.cjs} +5 -6
  259. package/dist/superstruct.cjs.map +1 -0
  260. package/dist/{superstruct.d.ts → superstruct.d.cts} +3 -2
  261. package/dist/superstruct.d.cts.map +1 -0
  262. package/dist/superstruct.d.mts +84 -0
  263. package/dist/superstruct.d.mts.map +1 -0
  264. package/dist/superstruct.mjs +74 -0
  265. package/dist/superstruct.mjs.map +1 -0
  266. package/dist/{eth/index.js → utils/index.cjs} +3 -4
  267. package/dist/utils/index.cjs.map +1 -0
  268. package/dist/utils/index.d.cts +3 -0
  269. package/dist/utils/index.d.cts.map +1 -0
  270. package/dist/utils/index.d.mts +3 -0
  271. package/dist/utils/index.d.mts.map +1 -0
  272. package/dist/utils/index.mjs +3 -0
  273. package/dist/utils/index.mjs.map +1 -0
  274. package/dist/utils/{types.js → types.cjs} +2 -2
  275. package/dist/utils/types.cjs.map +1 -0
  276. package/dist/utils/{types.d.ts → types.d.cts} +2 -1
  277. package/dist/utils/types.d.cts.map +1 -0
  278. package/dist/utils/types.d.mts +18 -0
  279. package/dist/utils/types.d.mts.map +1 -0
  280. package/dist/utils/types.mjs +26 -0
  281. package/dist/utils/types.mjs.map +1 -0
  282. package/dist/utils/{typing.js → typing.cjs} +2 -3
  283. package/dist/utils/{typing.js.map → typing.cjs.map} +1 -1
  284. package/dist/utils/{typing.d.ts → typing.d.cts} +1 -0
  285. package/dist/utils/typing.d.cts.map +1 -0
  286. package/dist/utils/typing.d.mts +33 -0
  287. package/dist/utils/typing.d.mts.map +1 -0
  288. package/dist/utils/typing.mjs +17 -0
  289. package/dist/utils/typing.mjs.map +1 -0
  290. package/package.json +19 -8
  291. package/dist/JsonRpcRequest.js.map +0 -1
  292. package/dist/KeyringClient.js.map +0 -1
  293. package/dist/KeyringSnapRpcClient.js.map +0 -1
  294. package/dist/api/account.js.map +0 -1
  295. package/dist/api/balance.js.map +0 -1
  296. package/dist/api/caip.js.map +0 -1
  297. package/dist/api/export.js.map +0 -1
  298. package/dist/api/index.d.ts +0 -7
  299. package/dist/api/index.js.map +0 -1
  300. package/dist/api/keyring.js.map +0 -1
  301. package/dist/api/request.js.map +0 -1
  302. package/dist/api/response.js.map +0 -1
  303. package/dist/btc/index.d.ts +0 -1
  304. package/dist/btc/index.js.map +0 -1
  305. package/dist/btc/types.js.map +0 -1
  306. package/dist/contexts.js.map +0 -1
  307. package/dist/eth/erc4337/index.d.ts +0 -1
  308. package/dist/eth/erc4337/index.js.map +0 -1
  309. package/dist/eth/erc4337/types.js.map +0 -1
  310. package/dist/eth/index.d.ts +0 -3
  311. package/dist/eth/index.js.map +0 -1
  312. package/dist/eth/types.js.map +0 -1
  313. package/dist/events.js.map +0 -1
  314. package/dist/index.d.ts +0 -11
  315. package/dist/index.js +0 -27
  316. package/dist/index.js.map +0 -1
  317. package/dist/internal/api.js.map +0 -1
  318. package/dist/internal/eth/EthKeyring.js.map +0 -1
  319. package/dist/internal/eth/index.d.ts +0 -1
  320. package/dist/internal/eth/index.js.map +0 -1
  321. package/dist/internal/events.js.map +0 -1
  322. package/dist/internal/index.d.ts +0 -5
  323. package/dist/internal/index.js.map +0 -1
  324. package/dist/internal/types.js.map +0 -1
  325. package/dist/rpc-handler.js.map +0 -1
  326. package/dist/snap-utils.js.map +0 -1
  327. package/dist/superstruct.js.map +0 -1
  328. package/dist/utils/index.d.ts +0 -2
  329. package/dist/utils/index.js.map +0 -1
  330. package/dist/utils/types.js.map +0 -1
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.strictMask = exports.definePattern = exports.exactOptional = exports.object = void 0;
3
+ exports.object = object;
4
+ exports.exactOptional = exactOptional;
5
+ exports.definePattern = definePattern;
6
+ exports.strictMask = strictMask;
4
7
  const superstruct_1 = require("@metamask/superstruct");
5
8
  /**
6
9
  * Change the return type of a superstruct object struct to support exact
@@ -12,7 +15,6 @@ const superstruct_1 = require("@metamask/superstruct");
12
15
  function object(schema) {
13
16
  return (0, superstruct_1.object)(schema);
14
17
  }
15
- exports.object = object;
16
18
  /**
17
19
  * Check if the current property is present in its parent object.
18
20
  *
@@ -44,7 +46,6 @@ function exactOptional(struct) {
44
46
  refiner: (value, ctx) => !hasOptional(ctx) || struct.refiner(value, ctx),
45
47
  });
46
48
  }
47
- exports.exactOptional = exactOptional;
48
49
  /**
49
50
  * Defines a new string-struct matching a regular expression.
50
51
  *
@@ -61,7 +62,6 @@ exports.exactOptional = exactOptional;
61
62
  function definePattern(name, pattern) {
62
63
  return (0, superstruct_1.define)(name, (value) => typeof value === 'string' && pattern.test(value));
63
64
  }
64
- exports.definePattern = definePattern;
65
65
  /**
66
66
  * Assert that a value is valid according to a struct.
67
67
  *
@@ -77,5 +77,4 @@ function strictMask(value, struct, message) {
77
77
  (0, superstruct_1.assert)(value, struct, message);
78
78
  return value;
79
79
  }
80
- exports.strictMask = strictMask;
81
- //# sourceMappingURL=superstruct.js.map
80
+ //# sourceMappingURL=superstruct.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"superstruct.cjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;AAiEA,wBAIC;AA4BD,sCAYC;AAeD,sCASC;AAaD,gCAOC;AAzJD,uDAK+B;AAqD/B;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,MAAc;IAEd,OAAO,IAAA,oBAAQ,EAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,MAAM,MAAM,GAA4B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,MAA4B;IAE5B,OAAO,IAAI,oBAAM,CAAC;QAChB,GAAG,MAAM;QAET,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;QAEnD,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACtB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,GAAG,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,IAAA,oBAAM,EACX,IAAI,EACJ,CAAC,KAAc,EAAW,EAAE,CAC1B,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,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} from '@metamask/superstruct';\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"]}
@@ -1,5 +1,5 @@
1
- import { Struct } from '@metamask/superstruct';
2
- import type { Infer, ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from '@metamask/superstruct';
1
+ import { Struct } from "@metamask/superstruct";
2
+ import type { Infer, ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from "@metamask/superstruct";
3
3
  declare const ExactOptionalSymbol: unique symbol;
4
4
  export type ExactOptionalTag = {
5
5
  type: typeof ExactOptionalSymbol;
@@ -81,3 +81,4 @@ export declare function definePattern(name: string, pattern: RegExp): Struct<str
81
81
  */
82
82
  export declare function strictMask<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, message?: string): Type;
83
83
  export {};
84
+ //# sourceMappingURL=superstruct.d.cts.map
@@ -0,0 +1 @@
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,EACT,8BAA8B;AAG/B,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,EAAE,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,SAAS,YAAY,IAAI,QAAQ,CAC5D,gBAAgB,CAAC,WAAW,CAAC;KAAG,CAAC,IAAI,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,CAAC,CACzE,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,SAAS,YAAY,EAChD,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAEpC;AAeD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EACxC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAC3B,MAAM,CAAC,IAAI,GAAG,gBAAgB,EAAE,MAAM,CAAC,CAUzC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,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"}
@@ -0,0 +1,84 @@
1
+ import { Struct } from "@metamask/superstruct";
2
+ import type { Infer, ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from "@metamask/superstruct";
3
+ declare const ExactOptionalSymbol: unique symbol;
4
+ export type ExactOptionalTag = {
5
+ type: typeof ExactOptionalSymbol;
6
+ };
7
+ /**
8
+ * Exclude type `Type` from the properties of `Obj`.
9
+ *
10
+ * ```ts
11
+ * type Foo = { a: string | null; b: number };
12
+ * type Bar = ExcludeType<Foo, null>;
13
+ * // Bar = { a: string, b: number }
14
+ * ```
15
+ */
16
+ export type ExcludeType<Obj, Type> = {
17
+ [K in keyof Obj]: Exclude<Obj[K], Type>;
18
+ };
19
+ /**
20
+ * Make optional all properties that have the `ExactOptionalTag` type.
21
+ *
22
+ * ```ts
23
+ * type Foo = { a: string | ExactOptionalTag; b: number};
24
+ * type Bar = ExactOptionalize<Foo>;
25
+ * // Bar = { a?: string; b: number}
26
+ * ```
27
+ */
28
+ export type ExactOptionalize<Schema extends object> = OmitBy<Schema, ExactOptionalTag> & Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;
29
+ /**
30
+ * Infer a type from an superstruct object schema.
31
+ */
32
+ export type ObjectType<Schema extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
33
+ [K in keyof Schema]: Infer<Schema[K]>;
34
+ }>>>;
35
+ /**
36
+ * Change the return type of a superstruct object struct to support exact
37
+ * optional properties.
38
+ *
39
+ * @param schema - The object schema.
40
+ * @returns A struct representing an object with a known set of properties.
41
+ */
42
+ export declare function object<Schema extends ObjectSchema>(schema: Schema): Struct<ObjectType<Schema>, Schema>;
43
+ /**
44
+ * Augment a struct to allow exact-optional values. Exact-optional values can
45
+ * be omitted but cannot be `undefined`.
46
+ *
47
+ * ```ts
48
+ * const foo = object({ bar: exactOptional(string()) });
49
+ * type Foo = Infer<typeof foo>;
50
+ * // Foo = { bar?: string }
51
+ * ```
52
+ *
53
+ * @param struct - The struct to augment.
54
+ * @returns The augmented struct.
55
+ */
56
+ export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>): Struct<Type | ExactOptionalTag, Schema>;
57
+ /**
58
+ * Defines a new string-struct matching a regular expression.
59
+ *
60
+ * Example:
61
+ *
62
+ * ```ts
63
+ * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
64
+ * ```
65
+ *
66
+ * @param name - Type name.
67
+ * @param pattern - Regular expression to match.
68
+ * @returns A new string-struct that matches the given pattern.
69
+ */
70
+ export declare function definePattern(name: string, pattern: RegExp): Struct<string, null>;
71
+ /**
72
+ * Assert that a value is valid according to a struct.
73
+ *
74
+ * It is similar to superstruct's mask function, but it does not ignore extra
75
+ * properties.
76
+ *
77
+ * @param value - Value to check.
78
+ * @param struct - Struct to validate the value against.
79
+ * @param message - Error message to throw if the value is not valid.
80
+ * @returns The value if it is valid.
81
+ */
82
+ export declare function strictMask<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, message?: string): Type;
83
+ export {};
84
+ //# sourceMappingURL=superstruct.d.mts.map
@@ -0,0 +1 @@
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,EACT,8BAA8B;AAG/B,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,EAAE,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,SAAS,YAAY,IAAI,QAAQ,CAC5D,gBAAgB,CAAC,WAAW,CAAC;KAAG,CAAC,IAAI,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,CAAC,CACzE,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,SAAS,YAAY,EAChD,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAEpC;AAeD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EACxC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAC3B,MAAM,CAAC,IAAI,GAAG,gBAAgB,EAAE,MAAM,CAAC,CAUzC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,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"}
@@ -0,0 +1,74 @@
1
+ import { Struct, assert, define, object as stObject } from "@metamask/superstruct";
2
+ /**
3
+ * Change the return type of a superstruct object struct to support exact
4
+ * optional properties.
5
+ *
6
+ * @param schema - The object schema.
7
+ * @returns A struct representing an object with a known set of properties.
8
+ */
9
+ export function object(schema) {
10
+ return stObject(schema);
11
+ }
12
+ /**
13
+ * Check if the current property is present in its parent object.
14
+ *
15
+ * @param ctx - The context to check.
16
+ * @returns `true` if the property is present, `false` otherwise.
17
+ */
18
+ function hasOptional(ctx) {
19
+ const property = ctx.path[ctx.path.length - 1];
20
+ const parent = ctx.branch[ctx.branch.length - 2];
21
+ return property in parent;
22
+ }
23
+ /**
24
+ * Augment a struct to allow exact-optional values. Exact-optional values can
25
+ * be omitted but cannot be `undefined`.
26
+ *
27
+ * ```ts
28
+ * const foo = object({ bar: exactOptional(string()) });
29
+ * type Foo = Infer<typeof foo>;
30
+ * // Foo = { bar?: string }
31
+ * ```
32
+ *
33
+ * @param struct - The struct to augment.
34
+ * @returns The augmented struct.
35
+ */
36
+ export function exactOptional(struct) {
37
+ return new Struct({
38
+ ...struct,
39
+ validator: (value, ctx) => !hasOptional(ctx) || struct.validator(value, ctx),
40
+ refiner: (value, ctx) => !hasOptional(ctx) || struct.refiner(value, ctx),
41
+ });
42
+ }
43
+ /**
44
+ * Defines a new string-struct matching a regular expression.
45
+ *
46
+ * Example:
47
+ *
48
+ * ```ts
49
+ * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
50
+ * ```
51
+ *
52
+ * @param name - Type name.
53
+ * @param pattern - Regular expression to match.
54
+ * @returns A new string-struct that matches the given pattern.
55
+ */
56
+ export function definePattern(name, pattern) {
57
+ return define(name, (value) => typeof value === 'string' && pattern.test(value));
58
+ }
59
+ /**
60
+ * Assert that a value is valid according to a struct.
61
+ *
62
+ * It is similar to superstruct's mask function, but it does not ignore extra
63
+ * properties.
64
+ *
65
+ * @param value - Value to check.
66
+ * @param struct - Struct to validate the value against.
67
+ * @param message - Error message to throw if the value is not valid.
68
+ * @returns The value if it is valid.
69
+ */
70
+ export function strictMask(value, struct, message) {
71
+ assert(value, struct, message);
72
+ return value;
73
+ }
74
+ //# sourceMappingURL=superstruct.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"superstruct.mjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,IAAI,QAAQ,EACnB,8BAA8B;AAqD/B;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CACpB,MAAc;IAEd,OAAO,QAAQ,CAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,MAAM,MAAM,GAA4B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAC3B,MAA4B;IAE5B,OAAO,IAAI,MAAM,CAAC;QAChB,GAAG,MAAM;QAET,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;QAEnD,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACtB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,GAAG,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,MAAM,CACX,IAAI,EACJ,CAAC,KAAc,EAAW,EAAE,CAC1B,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,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} from '@metamask/superstruct';\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"]}
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./erc4337"), exports);
18
- __exportStar(require("./types"), exports);
19
- __exportStar(require("./utils"), exports);
20
- //# sourceMappingURL=index.js.map
17
+ __exportStar(require("./types.cjs"), exports);
18
+ __exportStar(require("./typing.cjs"), exports);
19
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,+CAAyB","sourcesContent":["export * from './types';\nexport * from './typing';\n"]}
@@ -0,0 +1,3 @@
1
+ export * from "./types.cjs";
2
+ export * from "./typing.cjs";
3
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,6BAAyB"}
@@ -0,0 +1,3 @@
1
+ export * from "./types.mjs";
2
+ export * from "./typing.mjs";
3
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,6BAAyB"}
@@ -0,0 +1,3 @@
1
+ export * from "./types.mjs";
2
+ export * from "./typing.mjs";
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,6BAAyB","sourcesContent":["export * from './types';\nexport * from './typing';\n"]}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StringNumberStruct = exports.UrlStruct = exports.UuidStruct = void 0;
4
4
  const superstruct_1 = require("@metamask/superstruct");
5
- const superstruct_2 = require("../superstruct");
5
+ const superstruct_2 = require("../superstruct.cjs");
6
6
  /**
7
7
  * UUIDv4 struct.
8
8
  */
@@ -26,4 +26,4 @@ exports.UrlStruct = (0, superstruct_1.define)('Url', (value) => {
26
26
  * A string which contains a positive float number.
27
27
  */
28
28
  exports.StringNumberStruct = (0, superstruct_2.definePattern)('StringNumber', /^\d+(\.\d+)?$/u);
29
- //# sourceMappingURL=types.js.map
29
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":";;;AAAA,uDAA2D;AAE3D,oDAA+C;AAE/C;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,2BAAa,EACrC,QAAQ,EACR,yEAAyE,CAC1E,CAAC;AAEF;;;;;GAKG;AACU,QAAA,SAAS,GAAG,IAAA,oBAAM,EAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,kBAAkB,GAAG,IAAA,2BAAa,EAC7C,cAAc,EACd,gBAAgB,CACjB,CAAC","sourcesContent":["import { define, type Infer } from '@metamask/superstruct';\n\nimport { definePattern } from '../superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n try {\n const url = new URL(value as string);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch {\n return false;\n }\n});\n\n/**\n * A string which contains a positive float number.\n */\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^\\d+(\\.\\d+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n"]}
@@ -1,4 +1,4 @@
1
- import { type Infer } from '@metamask/superstruct';
1
+ import { type Infer } from "@metamask/superstruct";
2
2
  /**
3
3
  * UUIDv4 struct.
4
4
  */
@@ -15,3 +15,4 @@ export declare const UrlStruct: import("@metamask/superstruct").Struct<string, n
15
15
  */
16
16
  export declare const StringNumberStruct: import("@metamask/superstruct").Struct<string, null>;
17
17
  export type StringNumber = Infer<typeof StringNumberStruct>;
18
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,KAAK,EAAE,8BAA8B;AAI3D;;GAEG;AACH,eAAO,MAAM,UAAU,sDAGtB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,sDAOpB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,kBAAkB,sDAG9B,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { type Infer } from "@metamask/superstruct";
2
+ /**
3
+ * UUIDv4 struct.
4
+ */
5
+ export declare const UuidStruct: import("@metamask/superstruct").Struct<string, null>;
6
+ /**
7
+ * Validates if a given value is a valid URL.
8
+ *
9
+ * @param value - The value to be validated.
10
+ * @returns A boolean indicating if the value is a valid URL.
11
+ */
12
+ export declare const UrlStruct: import("@metamask/superstruct").Struct<string, null>;
13
+ /**
14
+ * A string which contains a positive float number.
15
+ */
16
+ export declare const StringNumberStruct: import("@metamask/superstruct").Struct<string, null>;
17
+ export type StringNumber = Infer<typeof StringNumberStruct>;
18
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,KAAK,EAAE,8BAA8B;AAI3D;;GAEG;AACH,eAAO,MAAM,UAAU,sDAGtB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,sDAOpB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,kBAAkB,sDAG9B,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { define } from "@metamask/superstruct";
2
+ import { definePattern } from "../superstruct.mjs";
3
+ /**
4
+ * UUIDv4 struct.
5
+ */
6
+ export const UuidStruct = definePattern('UuidV4', /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu);
7
+ /**
8
+ * Validates if a given value is a valid URL.
9
+ *
10
+ * @param value - The value to be validated.
11
+ * @returns A boolean indicating if the value is a valid URL.
12
+ */
13
+ export const UrlStruct = define('Url', (value) => {
14
+ try {
15
+ const url = new URL(value);
16
+ return url.protocol === 'http:' || url.protocol === 'https:';
17
+ }
18
+ catch {
19
+ return false;
20
+ }
21
+ });
22
+ /**
23
+ * A string which contains a positive float number.
24
+ */
25
+ export const StringNumberStruct = definePattern('StringNumber', /^\d+(\.\d+)?$/u);
26
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,8BAA8B;AAE3D,OAAO,EAAE,aAAa,EAAE,2BAAuB;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CACrC,QAAQ,EACR,yEAAyE,CAC1E,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAC7C,cAAc,EACd,gBAAgB,CACjB,CAAC","sourcesContent":["import { define, type Infer } from '@metamask/superstruct';\n\nimport { definePattern } from '../superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n try {\n const url = new URL(value as string);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch {\n return false;\n }\n});\n\n/**\n * A string which contains a positive float number.\n */\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^\\d+(\\.\\d+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.expectTrue = void 0;
3
+ exports.expectTrue = expectTrue;
4
4
  /**
5
5
  * Assert that a type extends `true`. It can be used, for example, to assert
6
6
  * that a given type extends another type.
@@ -17,5 +17,4 @@ exports.expectTrue = void 0;
17
17
  function expectTrue() {
18
18
  // Intentionally empty
19
19
  }
20
- exports.expectTrue = expectTrue;
21
- //# sourceMappingURL=typing.js.map
20
+ //# sourceMappingURL=typing.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"typing.js","sourceRoot":"","sources":["../../src/utils/typing.ts"],"names":[],"mappings":";;;AAuBA;;;;;;;;;;;GAWG;AACH,6DAA6D;AAC7D,SAAgB,UAAU;IACxB,sBAAsB;AACxB,CAAC;AAFD,gCAEC","sourcesContent":["/**\n * Omit keys from a union type.\n *\n * The normal `Omit` type does not distribute over unions. So we use this\n * workaround that applies `Omit` to each member of the union.\n *\n * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>\n */\nexport type OmitUnion<Type, Key extends keyof any> = Type extends any\n ? Omit<Type, Key>\n : never;\n\n/**\n * Type that resolves to `true` if `Child` extends `Base`, otherwise `false`.\n *\n * @example\n * ```ts\n * type A = Extends<{a: string, b: string}, {a: string}>; // true\n * type B = Extends<{a: string}, {a: string, b: string}>; // false\n * ```\n */\nexport type Extends<Child, Base> = Child extends Base ? true : false;\n\n/**\n * Assert that a type extends `true`. It can be used, for example, to assert\n * that a given type extends another type.\n *\n * @example\n * ```ts\n * expectTrue<Extends<{a: string, b: string}, {a: string}>>(); // Ok\n * expectTrue<Extends<{a: string}, {a: string, b: string}>>(); // Error\n * ```\n *\n * This function follows the naming pattern used on `tsd`.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function expectTrue<Type extends true>(): void {\n // Intentionally empty\n}\n"]}
1
+ {"version":3,"file":"typing.cjs","sourceRoot":"","sources":["../../src/utils/typing.ts"],"names":[],"mappings":";;AAoCA,gCAEC;AAfD;;;;;;;;;;;GAWG;AACH,6DAA6D;AAC7D,SAAgB,UAAU;IACxB,sBAAsB;AACxB,CAAC","sourcesContent":["/**\n * Omit keys from a union type.\n *\n * The normal `Omit` type does not distribute over unions. So we use this\n * workaround that applies `Omit` to each member of the union.\n *\n * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>\n */\nexport type OmitUnion<Type, Key extends keyof any> = Type extends any\n ? Omit<Type, Key>\n : never;\n\n/**\n * Type that resolves to `true` if `Child` extends `Base`, otherwise `false`.\n *\n * @example\n * ```ts\n * type A = Extends<{a: string, b: string}, {a: string}>; // true\n * type B = Extends<{a: string}, {a: string, b: string}>; // false\n * ```\n */\nexport type Extends<Child, Base> = Child extends Base ? true : false;\n\n/**\n * Assert that a type extends `true`. It can be used, for example, to assert\n * that a given type extends another type.\n *\n * @example\n * ```ts\n * expectTrue<Extends<{a: string, b: string}, {a: string}>>(); // Ok\n * expectTrue<Extends<{a: string}, {a: string, b: string}>>(); // Error\n * ```\n *\n * This function follows the naming pattern used on `tsd`.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function expectTrue<Type extends true>(): void {\n // Intentionally empty\n}\n"]}
@@ -30,3 +30,4 @@ export type Extends<Child, Base> = Child extends Base ? true : false;
30
30
  * This function follows the naming pattern used on `tsd`.
31
31
  */
32
32
  export declare function expectTrue<Type extends true>(): void;
33
+ //# sourceMappingURL=typing.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typing.d.cts","sourceRoot":"","sources":["../../src/utils/typing.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,CAAC,IAAI,EAAE,GAAG,SAAS,MAAM,GAAG,IAAI,IAAI,SAAS,GAAG,GACjE,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,GACf,KAAK,CAAC;AAEV;;;;;;;;GAQG;AACH,MAAM,MAAM,OAAO,CAAC,KAAK,EAAE,IAAI,IAAI,KAAK,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;AAErE;;;;;;;;;;;GAWG;AAEH,wBAAgB,UAAU,CAAC,IAAI,SAAS,IAAI,KAAK,IAAI,CAEpD"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Omit keys from a union type.
3
+ *
4
+ * The normal `Omit` type does not distribute over unions. So we use this
5
+ * workaround that applies `Omit` to each member of the union.
6
+ *
7
+ * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>
8
+ */
9
+ export type OmitUnion<Type, Key extends keyof any> = Type extends any ? Omit<Type, Key> : never;
10
+ /**
11
+ * Type that resolves to `true` if `Child` extends `Base`, otherwise `false`.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * type A = Extends<{a: string, b: string}, {a: string}>; // true
16
+ * type B = Extends<{a: string}, {a: string, b: string}>; // false
17
+ * ```
18
+ */
19
+ export type Extends<Child, Base> = Child extends Base ? true : false;
20
+ /**
21
+ * Assert that a type extends `true`. It can be used, for example, to assert
22
+ * that a given type extends another type.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * expectTrue<Extends<{a: string, b: string}, {a: string}>>(); // Ok
27
+ * expectTrue<Extends<{a: string}, {a: string, b: string}>>(); // Error
28
+ * ```
29
+ *
30
+ * This function follows the naming pattern used on `tsd`.
31
+ */
32
+ export declare function expectTrue<Type extends true>(): void;
33
+ //# sourceMappingURL=typing.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typing.d.mts","sourceRoot":"","sources":["../../src/utils/typing.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,CAAC,IAAI,EAAE,GAAG,SAAS,MAAM,GAAG,IAAI,IAAI,SAAS,GAAG,GACjE,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,GACf,KAAK,CAAC;AAEV;;;;;;;;GAQG;AACH,MAAM,MAAM,OAAO,CAAC,KAAK,EAAE,IAAI,IAAI,KAAK,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;AAErE;;;;;;;;;;;GAWG;AAEH,wBAAgB,UAAU,CAAC,IAAI,SAAS,IAAI,KAAK,IAAI,CAEpD"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Assert that a type extends `true`. It can be used, for example, to assert
3
+ * that a given type extends another type.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * expectTrue<Extends<{a: string, b: string}, {a: string}>>(); // Ok
8
+ * expectTrue<Extends<{a: string}, {a: string, b: string}>>(); // Error
9
+ * ```
10
+ *
11
+ * This function follows the naming pattern used on `tsd`.
12
+ */
13
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
+ export function expectTrue() {
15
+ // Intentionally empty
16
+ }
17
+ //# sourceMappingURL=typing.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typing.mjs","sourceRoot":"","sources":["../../src/utils/typing.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;;GAWG;AACH,6DAA6D;AAC7D,MAAM,UAAU,UAAU;IACxB,sBAAsB;AACxB,CAAC","sourcesContent":["/**\n * Omit keys from a union type.\n *\n * The normal `Omit` type does not distribute over unions. So we use this\n * workaround that applies `Omit` to each member of the union.\n *\n * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>\n */\nexport type OmitUnion<Type, Key extends keyof any> = Type extends any\n ? Omit<Type, Key>\n : never;\n\n/**\n * Type that resolves to `true` if `Child` extends `Base`, otherwise `false`.\n *\n * @example\n * ```ts\n * type A = Extends<{a: string, b: string}, {a: string}>; // true\n * type B = Extends<{a: string}, {a: string, b: string}>; // false\n * ```\n */\nexport type Extends<Child, Base> = Child extends Base ? true : false;\n\n/**\n * Assert that a type extends `true`. It can be used, for example, to assert\n * that a given type extends another type.\n *\n * @example\n * ```ts\n * expectTrue<Extends<{a: string, b: string}, {a: string}>>(); // Ok\n * expectTrue<Extends<{a: string}, {a: string, b: string}>>(); // Error\n * ```\n *\n * This function follows the naming pattern used on `tsd`.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function expectTrue<Type extends true>(): void {\n // Intentionally empty\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-api",
3
- "version": "10.0.0",
3
+ "version": "11.0.0",
4
4
  "description": "MetaMask Keyring API",
5
5
  "keywords": [
6
6
  "metamask",
@@ -15,16 +15,27 @@
15
15
  "type": "git",
16
16
  "url": "https://github.com/MetaMask/keyring-api.git"
17
17
  },
18
- "main": "./dist/index.js",
19
- "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "import": {
21
+ "types": "./dist/index.d.mts",
22
+ "default": "./dist/index.mjs"
23
+ },
24
+ "require": {
25
+ "types": "./dist/index.d.cts",
26
+ "default": "./dist/index.cjs"
27
+ }
28
+ }
29
+ },
30
+ "main": "./dist/index.cjs",
31
+ "types": "./dist/index.d.cts",
20
32
  "files": [
21
33
  "dist/"
22
34
  ],
23
35
  "scripts": {
24
- "build": "tsc --build tsconfig.build.json",
25
- "build:clean": "rimraf dist && yarn build",
36
+ "build": "ts-bridge --project tsconfig.build.json --no-references",
37
+ "build:clean": "yarn build --clean",
26
38
  "build:docs": "typedoc",
27
- "build:force": "tsc --build tsconfig.build.json --force",
28
39
  "changelog:update": "../../scripts/update-changelog.sh @metamask/keyring-api",
29
40
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/keyring-api",
30
41
  "publish:preview": "yarn npm publish --tag preview",
@@ -48,6 +59,7 @@
48
59
  "@lavamoat/preinstall-always-fail": "^2.1.0",
49
60
  "@metamask/auto-changelog": "^3.4.4",
50
61
  "@metamask/providers": "^18.1.0",
62
+ "@ts-bridge/cli": "^0.6.0",
51
63
  "@types/jest": "^29.5.12",
52
64
  "@types/node": "^20.12.12",
53
65
  "@types/webextension-polyfill": "^0.12.1",
@@ -55,12 +67,11 @@
55
67
  "depcheck": "^1.4.7",
56
68
  "jest": "^29.5.0",
57
69
  "jest-it-up": "^3.1.0",
58
- "rimraf": "^5.0.10",
59
70
  "ts-jest": "^29.0.5",
60
71
  "ts-node": "^10.9.2",
61
72
  "tsd": "^0.31.0",
62
73
  "typedoc": "^0.25.13",
63
- "typescript": "~5.4.5"
74
+ "typescript": "~5.6.3"
64
75
  },
65
76
  "peerDependencies": {
66
77
  "@metamask/providers": "^18.1.0"
@@ -1 +0,0 @@
1
- {"version":3,"file":"JsonRpcRequest.js","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":";;;AAAA,uDAO+B;AAE/B,2CAA6C;AAE7C,+CAAsD;AAEzC,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,EAAE,EAAE,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,oBAAM,GAAE,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,MAAM,EAAE,IAAA,oBAAM,GAAE;IAChB,MAAM,EAAE,IAAA,2BAAa,EACnB,IAAA,mBAAK,EAAC,CAAC,IAAA,mBAAK,EAAC,kBAAU,CAAC,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC,CACzD;CACF,CAAC,CAAC","sourcesContent":["import {\n array,\n literal,\n number,\n record,\n string,\n union,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { exactOptional, object } from './superstruct';\n\nexport const JsonRpcRequestStruct = object({\n jsonrpc: literal('2.0'),\n id: union([string(), number(), literal(null)]),\n method: string(),\n params: exactOptional(\n union([array(JsonStruct), record(string(), JsonStruct)]),\n ),\n});\n\n/**\n * JSON-RPC request type.\n */\nexport type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAA+C;AAE/C,+BAAkC;AAWlC,wCAcwB;AACxB,wCAAkD;AAElD,+CAA2C;AAM3C,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;;QAPjB,wCAAgB;QAQvB,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAgBD,KAAK,CAAC,YAAY;QAChB,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,YAAY;SACtC,CAAC,EACF,gCAA0B,CAC3B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,UAAU;YACnC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,8BAAwB,CACzB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,kBAAkB,CACtB,EAAU,EACV,MAAuB;QAEvB,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,kBAAkB;YAC3C,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE;SACvB,CAAC,EACF,sCAAgC,CACjC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,UAAgC,EAAE;QAElC,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,OAAO,EAAE;SACpB,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,EAAU,EAAE,MAAgB;QACpD,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,mBAAmB;YAC5C,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE;SACvB,CAAC,EACF,uCAAiC,CAClC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAuB;QACzC,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,OAAO,EAAE;SACpB,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,YAAY;SACtC,CAAC,EACF,gCAA0B,CAC3B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,UAAU;YACnC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,8BAAwB,CACzB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAuB;QACzC,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,OAAO;SAChB,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,EAAU,EACV,OAA6B,EAAE;QAE/B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,cAAc;YACvC,MAAM,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE;SACrB,CAAC,EACF,kCAA4B,CAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;CACF;AAjKD,sCAiKC;;AArJC;;;;;GAKG;AACH,KAAK,8BAAO,OAA+C;IACzD,OAAO,uBAAA,IAAI,6BAAQ,CAAC,IAAI,CAAC;QACvB,OAAO,EAAE,KAAK;QACd,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n KeyringAccountData,\n KeyringResponse,\n CaipAssetType,\n Balance,\n} from './api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountBalancesResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\n ListRequestsResponseStruct,\n RejectRequestResponseStruct,\n SubmitRequestResponseStruct,\n UpdateAccountResponseStruct,\n} from './internal/api';\nimport { KeyringRpcMethod } from './internal/rpc';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { strictMask } from './superstruct';\n\nexport type Sender = {\n send(request: JsonRpcRequest): Promise<Json>;\n};\n\nexport class KeyringClient implements Keyring {\n readonly #sender: Sender;\n\n /**\n * Create a new instance of `KeyringClient`.\n *\n * @param sender - The `Sender` instance to use to send requests to the snap.\n */\n constructor(sender: Sender) {\n this.#sender = sender;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param partial - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n async #send(partial: Omit<JsonRpcRequest, 'jsonrpc' | 'id'>): Promise<Json> {\n return this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n ...partial,\n });\n }\n\n async listAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListAccounts,\n }),\n ListAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async getAccountBalances(\n id: string,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccountBalances,\n params: { id, assets },\n }),\n GetAccountBalancesResponseStruct,\n );\n }\n\n async createAccount(\n options: Record<string, Json> = {},\n ): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.CreateAccount,\n params: { options },\n }),\n CreateAccountResponseStruct,\n );\n }\n\n async filterAccountChains(id: string, chains: string[]): Promise<string[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.FilterAccountChains,\n params: { id, chains },\n }),\n FilterAccountChainsResponseStruct,\n );\n }\n\n async updateAccount(account: KeyringAccount): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.UpdateAccount,\n params: { account },\n }),\n UpdateAccountResponseStruct,\n );\n }\n\n async deleteAccount(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n async exportAccount(id: string): Promise<KeyringAccountData> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ExportAccount,\n params: { id },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async listRequests(): Promise<KeyringRequest[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListRequests,\n }),\n ListRequestsResponseStruct,\n );\n }\n\n async getRequest(id: string): Promise<KeyringRequest> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetRequest,\n params: { id },\n }),\n GetRequestResponseStruct,\n );\n }\n\n async submitRequest(request: KeyringRequest): Promise<KeyringResponse> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n\n async approveRequest(\n id: string,\n data: Record<string, Json> = {},\n ): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.ApproveRequest,\n params: { id, data },\n }),\n ApproveRequestResponseStruct,\n );\n }\n\n async rejectRequest(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.RejectRequest,\n params: { id },\n }),\n RejectRequestResponseStruct,\n );\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"KeyringSnapRpcClient.js","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,mDAAgD;AAEhD;;;GAGG;AACH,MAAa,aAAa;IAKxB;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAVnD,wCAAgB;QAEhB,0CAAkC;QASzC,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,2BAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,OAAO,uBAAA,IAAI,+BAAU,CAAC,OAAO,CAAC;YAC5B,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE;gBACN,MAAM,EAAE,uBAAA,IAAI,6BAAQ;gBACpB,OAAO;aACR;SACF,CAAkB,CAAC;IACtB,CAAC;CACF;AA/BD,sCA+BC;;AAED;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,6BAAa;IACrD;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAC1D,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF;AAVD,oDAUC","sourcesContent":["import type { MetaMaskInpageProvider } from '@metamask/providers';\nimport type { Json } from '@metamask/utils';\n\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport type { Sender } from './KeyringClient';\nimport { KeyringClient } from './KeyringClient';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through the snap JSON-RPC API.\n */\nexport class SnapRpcSender implements Sender {\n readonly #origin: string;\n\n readonly #provider: MetaMaskInpageProvider;\n\n /**\n * Create a new instance of `SnapRpcSender`.\n *\n * @param origin - The caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n this.#origin = origin;\n this.#provider = provider;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - The JSON-RPC request to send to the snap.\n * @returns A promise that resolves to the response of the request.\n */\n async send(request: JsonRpcRequest): Promise<Json> {\n return this.#provider.request({\n method: 'wallet_invokeKeyring',\n params: {\n snapId: this.#origin,\n request,\n },\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the snap\n * JSON-RPC API.\n */\nexport class KeyringSnapRpcClient extends KeyringClient {\n /**\n * Create a new instance of `KeyringSnapRpcClient`.\n *\n * @param origin - Caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n super(new SnapRpcSender(origin, provider));\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/api/account.ts"],"names":[],"mappings":";;;AACA,uDAAqE;AACrE,2CAA6C;AAE7C,gDAAwC;AACxC,oCAAsC;AAEtC;;GAEG;AACH,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,oCAAkB,CAAA;IAClB,4CAA0B,CAAA;AAC5B,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB;AAED;;GAEG;AACH,IAAY,cAEX;AAFD,WAAY,cAAc;IACxB,0CAAwB,CAAA;AAC1B,CAAC,EAFW,cAAc,8BAAd,cAAc,QAEzB;AAUD;;;;;;GAMG;AACU,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,IAAI,EAAE,IAAA,mBAAK,EAAC;QACV,GAAG,cAAc,CAAC,GAAG,EAAE;QACvB,GAAG,cAAc,CAAC,OAAO,EAAE;QAC3B,GAAG,cAAc,CAAC,MAAM,EAAE;KAC3B,CAAC;IAEF;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,GAAE;IAEjB;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC;IAErC;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC;CACzB,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { array, enums, record, string } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { object } from '../superstruct';\nimport { UuidStruct } from '../utils';\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Erc4337 = 'eip155:erc4337',\n}\n\n/**\n * Supported Bitcoin account types.\n */\nexport enum BtcAccountType {\n P2wpkh = 'bip122:p2wpkh',\n}\n\n/**\n * Supported account types.\n */\nexport type KeyringAccountType =\n | `${EthAccountType.Eoa}`\n | `${EthAccountType.Erc4337}`\n | `${BtcAccountType.P2wpkh}`;\n\n/**\n * A struct which represents a Keyring account object. It is abstract enough to\n * be used with any blockchain. Specific blockchain account types should extend\n * this struct.\n *\n * See {@link KeyringAccount}.\n */\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account type.\n */\n type: enums([\n `${EthAccountType.Eoa}`,\n `${EthAccountType.Erc4337}`,\n `${BtcAccountType.P2wpkh}`,\n ]),\n\n /**\n * Account main address.\n */\n address: string(),\n\n /**\n * Account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(string()),\n});\n\n/**\n * Keyring Account type represents an account and its properties from the\n * point of view of the keyring.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"balance.js","sourceRoot":"","sources":["../../src/api/balance.ts"],"names":[],"mappings":";;;AACA,uDAA+C;AAE/C,gDAAwC;AACxC,oCAA8C;AAEjC,QAAA,aAAa,GAAG,IAAA,oBAAM,EAAC;IAClC,MAAM,EAAE,0BAAkB;IAC1B,IAAI,EAAE,IAAA,oBAAM,GAAE;CACf,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { string } from '@metamask/superstruct';\n\nimport { object } from '../superstruct';\nimport { StringNumberStruct } from '../utils';\n\nexport const BalanceStruct = object({\n amount: StringNumberStruct,\n unit: string(),\n});\n\nexport type Balance = Infer<typeof BalanceStruct>;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"caip.js","sourceRoot":"","sources":["../../src/api/caip.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AAEvD,gDAA+C;AAE/C,MAAM,qBAAqB,GACzB,2JAA2J,CAAC;AAE9J,MAAM,mBAAmB,GACvB,6LAA6L,CAAC;AAEhM;;GAEG;AACU,QAAA,mBAAmB,GAAG,IAAA,2BAAa,EAC9C,eAAe,EACf,qBAAqB,CACtB,CAAC;AAGF;;GAEG;AACU,QAAA,iBAAiB,GAAG,IAAA,2BAAa,EAC5C,aAAa,EACb,mBAAmB,CACpB,CAAC;AAGF;;;;;;;;;;;GAWG;AACH,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,2BAAmB,CAAC,CAAC;AACxC,CAAC;AAFD,0CAEC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,yBAAiB,CAAC,CAAC;AACtC,CAAC;AAFD,sCAEC","sourcesContent":["import { is, type Infer } from '@metamask/superstruct';\n\nimport { definePattern } from '../superstruct';\n\nconst CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nconst CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct = definePattern(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n);\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct = definePattern(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n);\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n * @example\n * ```ts\n * isCaipAssetType('eip155:1/slip44:60'); // true\n * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // true\n * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // false\n * ```\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n * @example\n * ```ts\n * isCaipAssetType('eip155:1/slip44:60'); // false\n * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // false\n * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // true\n * ```\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/api/export.ts"],"names":[],"mappings":";;;AACA,uDAAuD;AACvD,2CAA6C;AAEhC,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { record, string } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nexport const KeyringAccountDataStruct = record(string(), JsonStruct);\n\n/**\n * Response to a call to `exportAccount`.\n *\n * The exact response depends on the keyring implementation.\n */\nexport type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;\n"]}