@metamask/utils 8.4.0 → 8.5.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 (346) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/dist/assert.cjs +127 -0
  3. package/dist/assert.cjs.map +1 -0
  4. package/dist/{types/assert.d.ts → assert.d.cts} +3 -3
  5. package/dist/assert.d.cts.map +1 -0
  6. package/dist/assert.d.mts +61 -0
  7. package/dist/assert.d.mts.map +1 -0
  8. package/dist/assert.mjs +119 -15
  9. package/dist/assert.mjs.map +1 -1
  10. package/dist/base64.cjs +34 -0
  11. package/dist/base64.cjs.map +1 -0
  12. package/dist/{types/base64.d.ts → base64.d.cts} +3 -3
  13. package/dist/base64.d.cts.map +1 -0
  14. package/dist/base64.d.mts +25 -0
  15. package/dist/base64.d.mts.map +1 -0
  16. package/dist/base64.mjs +28 -9
  17. package/dist/base64.mjs.map +1 -1
  18. package/dist/bytes.cjs +400 -0
  19. package/dist/{chunk-QEPVHEP7.js.map → bytes.cjs.map} +1 -1
  20. package/dist/{types/bytes.d.ts → bytes.d.cts} +3 -3
  21. package/dist/bytes.d.cts.map +1 -0
  22. package/dist/bytes.d.mts +183 -0
  23. package/dist/bytes.d.mts.map +1 -0
  24. package/dist/bytes.mjs +379 -42
  25. package/dist/bytes.mjs.map +1 -1
  26. package/dist/caip-types.cjs +151 -0
  27. package/dist/caip-types.cjs.map +1 -0
  28. package/dist/{types/caip-types.d.ts → caip-types.d.cts} +12 -12
  29. package/dist/caip-types.d.cts.map +1 -0
  30. package/dist/caip-types.d.mts +114 -0
  31. package/dist/caip-types.d.mts.map +1 -0
  32. package/dist/caip-types.mjs +139 -43
  33. package/dist/caip-types.mjs.map +1 -1
  34. package/dist/checksum.cjs +7 -0
  35. package/dist/checksum.cjs.map +1 -0
  36. package/dist/checksum.d.cts +2 -0
  37. package/dist/checksum.d.cts.map +1 -0
  38. package/dist/checksum.d.mts +2 -0
  39. package/dist/checksum.d.mts.map +1 -0
  40. package/dist/checksum.mjs +3 -11
  41. package/dist/checksum.mjs.map +1 -1
  42. package/dist/coercers.cjs +162 -0
  43. package/dist/coercers.cjs.map +1 -0
  44. package/dist/{types/coercers.d.ts → coercers.d.cts} +7 -7
  45. package/dist/coercers.d.cts.map +1 -0
  46. package/dist/coercers.d.mts +97 -0
  47. package/dist/coercers.d.mts.map +1 -0
  48. package/dist/coercers.mjs +154 -17
  49. package/dist/coercers.mjs.map +1 -1
  50. package/dist/collections.cjs +109 -0
  51. package/dist/collections.cjs.map +1 -0
  52. package/dist/{types/collections.d.ts → collections.d.cts} +1 -1
  53. package/dist/collections.d.cts.map +1 -0
  54. package/dist/collections.d.mts +39 -0
  55. package/dist/collections.d.mts.map +1 -0
  56. package/dist/collections.mjs +103 -8
  57. package/dist/collections.mjs.map +1 -1
  58. package/dist/encryption-types.cjs +3 -0
  59. package/dist/encryption-types.cjs.map +1 -0
  60. package/dist/{types/encryption-types.d.ts → encryption-types.d.cts} +2 -2
  61. package/dist/encryption-types.d.cts.map +1 -0
  62. package/dist/encryption-types.d.mts +7 -0
  63. package/dist/encryption-types.d.mts.map +1 -0
  64. package/dist/encryption-types.mjs +1 -1
  65. package/dist/encryption-types.mjs.map +1 -1
  66. package/dist/errors.cjs +111 -0
  67. package/dist/errors.cjs.map +1 -0
  68. package/dist/{types/errors.d.ts → errors.d.cts} +1 -1
  69. package/dist/errors.d.cts.map +1 -0
  70. package/dist/errors.d.mts +58 -0
  71. package/dist/errors.d.mts.map +1 -0
  72. package/dist/errors.mjs +102 -16
  73. package/dist/errors.mjs.map +1 -1
  74. package/dist/fs.cjs +248 -0
  75. package/dist/fs.cjs.map +1 -0
  76. package/dist/{types/fs.d.ts → fs.d.cts} +3 -3
  77. package/dist/fs.d.cts.map +1 -0
  78. package/dist/fs.d.mts +133 -0
  79. package/dist/fs.d.mts.map +1 -0
  80. package/dist/fs.mjs +209 -25
  81. package/dist/fs.mjs.map +1 -1
  82. package/dist/hex.cjs +134 -0
  83. package/dist/hex.cjs.map +1 -0
  84. package/dist/{types/hex.d.ts → hex.d.cts} +3 -3
  85. package/dist/hex.d.cts.map +1 -0
  86. package/dist/hex.d.mts +77 -0
  87. package/dist/hex.d.mts.map +1 -0
  88. package/dist/hex.mjs +121 -34
  89. package/dist/hex.mjs.map +1 -1
  90. package/dist/index.cjs +37 -0
  91. package/dist/index.cjs.map +1 -0
  92. package/dist/index.d.cts +21 -0
  93. package/dist/index.d.cts.map +1 -0
  94. package/dist/index.d.mts +21 -0
  95. package/dist/index.d.mts.map +1 -0
  96. package/dist/index.mjs +20 -296
  97. package/dist/index.mjs.map +1 -1
  98. package/dist/json.cjs +413 -0
  99. package/dist/json.cjs.map +1 -0
  100. package/dist/{types/json.d.ts → json.d.cts} +21 -22
  101. package/dist/json.d.cts.map +1 -0
  102. package/dist/json.d.mts +383 -0
  103. package/dist/json.d.mts.map +1 -0
  104. package/dist/json.mjs +389 -74
  105. package/dist/json.mjs.map +1 -1
  106. package/dist/keyring.cjs +3 -0
  107. package/dist/keyring.cjs.map +1 -0
  108. package/dist/{types/keyring.d.ts → keyring.d.cts} +7 -7
  109. package/dist/keyring.d.cts.map +1 -0
  110. package/dist/keyring.d.mts +224 -0
  111. package/dist/keyring.d.mts.map +1 -0
  112. package/dist/keyring.mjs +1 -1
  113. package/dist/keyring.mjs.map +1 -1
  114. package/dist/logging.cjs +43 -0
  115. package/dist/logging.cjs.map +1 -0
  116. package/dist/{types/logging.d.ts → logging.d.cts} +2 -2
  117. package/dist/logging.d.cts.map +1 -0
  118. package/dist/logging.d.mts +30 -0
  119. package/dist/logging.d.mts.map +1 -0
  120. package/dist/logging.mjs +34 -9
  121. package/dist/logging.mjs.map +1 -1
  122. package/dist/misc.cjs +149 -0
  123. package/dist/misc.cjs.map +1 -0
  124. package/dist/{types/misc.d.ts → misc.d.cts} +6 -6
  125. package/dist/misc.d.cts.map +1 -0
  126. package/dist/misc.d.mts +119 -0
  127. package/dist/misc.d.mts.map +1 -0
  128. package/dist/misc.mjs +136 -27
  129. package/dist/misc.mjs.map +1 -1
  130. package/dist/node.cjs +19 -0
  131. package/dist/node.cjs.map +1 -0
  132. package/dist/node.d.cts +3 -0
  133. package/dist/node.d.cts.map +1 -0
  134. package/dist/node.d.mts +3 -0
  135. package/dist/node.d.mts.map +1 -0
  136. package/dist/node.mjs +2 -316
  137. package/dist/node.mjs.map +1 -1
  138. package/dist/number.cjs +102 -0
  139. package/dist/number.cjs.map +1 -0
  140. package/dist/{types/number.d.ts → number.d.cts} +1 -1
  141. package/dist/number.d.cts.map +1 -0
  142. package/dist/number.d.mts +73 -0
  143. package/dist/number.d.mts.map +1 -0
  144. package/dist/number.mjs +93 -16
  145. package/dist/number.mjs.map +1 -1
  146. package/dist/opaque.cjs +3 -0
  147. package/dist/opaque.cjs.map +1 -0
  148. package/dist/opaque.d.cts +6 -0
  149. package/dist/opaque.d.cts.map +1 -0
  150. package/dist/opaque.d.mts +6 -0
  151. package/dist/opaque.d.mts.map +1 -0
  152. package/dist/opaque.mjs +1 -1
  153. package/dist/opaque.mjs.map +1 -1
  154. package/dist/promise.cjs +40 -0
  155. package/dist/promise.cjs.map +1 -0
  156. package/dist/{types/promise.d.ts → promise.d.cts} +2 -2
  157. package/dist/promise.d.cts.map +1 -0
  158. package/dist/promise.d.mts +45 -0
  159. package/dist/promise.d.mts.map +1 -0
  160. package/dist/promise.mjs +35 -7
  161. package/dist/promise.mjs.map +1 -1
  162. package/dist/time.cjs +67 -0
  163. package/dist/time.cjs.map +1 -0
  164. package/dist/{types/time.d.ts → time.d.cts} +1 -1
  165. package/dist/time.d.cts.map +1 -0
  166. package/dist/time.d.mts +49 -0
  167. package/dist/time.d.mts.map +1 -0
  168. package/dist/time.mjs +60 -10
  169. package/dist/time.mjs.map +1 -1
  170. package/dist/transaction-types.cjs +3 -0
  171. package/dist/transaction-types.cjs.map +1 -0
  172. package/dist/{types/transaction-types.d.ts → transaction-types.d.cts} +11 -11
  173. package/dist/transaction-types.d.cts.map +1 -0
  174. package/dist/transaction-types.d.mts +117 -0
  175. package/dist/transaction-types.d.mts.map +1 -0
  176. package/dist/transaction-types.mjs +1 -1
  177. package/dist/transaction-types.mjs.map +1 -1
  178. package/dist/versions.cjs +95 -0
  179. package/dist/versions.cjs.map +1 -0
  180. package/dist/{types/versions.d.ts → versions.d.cts} +5 -5
  181. package/dist/versions.d.cts.map +1 -0
  182. package/dist/versions.d.mts +101 -0
  183. package/dist/versions.d.mts.map +1 -0
  184. package/dist/versions.mjs +85 -26
  185. package/dist/versions.mjs.map +1 -1
  186. package/package.json +26 -17
  187. package/dist/assert.js +0 -16
  188. package/dist/assert.js.map +0 -1
  189. package/dist/base64.js +0 -11
  190. package/dist/base64.js.map +0 -1
  191. package/dist/bytes.js +0 -43
  192. package/dist/bytes.js.map +0 -1
  193. package/dist/caip-types.js +0 -44
  194. package/dist/caip-types.js.map +0 -1
  195. package/dist/checksum.js +0 -12
  196. package/dist/checksum.js.map +0 -1
  197. package/dist/chunk-2LBGT4GH.js +0 -15
  198. package/dist/chunk-2LBGT4GH.js.map +0 -1
  199. package/dist/chunk-3W5G4CYI.js +0 -25
  200. package/dist/chunk-3W5G4CYI.js.map +0 -1
  201. package/dist/chunk-4D6XQBHA.js +0 -69
  202. package/dist/chunk-4D6XQBHA.js.map +0 -1
  203. package/dist/chunk-4RMX5YWE.js +0 -34
  204. package/dist/chunk-4RMX5YWE.js.map +0 -1
  205. package/dist/chunk-5AVWINSB.js +0 -1
  206. package/dist/chunk-5AVWINSB.js.map +0 -1
  207. package/dist/chunk-622IOGVI.mjs +0 -1
  208. package/dist/chunk-622IOGVI.mjs.map +0 -1
  209. package/dist/chunk-6C35XQOF.mjs +0 -257
  210. package/dist/chunk-6C35XQOF.mjs.map +0 -1
  211. package/dist/chunk-6NZW4WK4.js +0 -35
  212. package/dist/chunk-6NZW4WK4.js.map +0 -1
  213. package/dist/chunk-6ZDHSOUV.js +0 -59
  214. package/dist/chunk-6ZDHSOUV.js.map +0 -1
  215. package/dist/chunk-74DGVJVE.mjs +0 -59
  216. package/dist/chunk-74DGVJVE.mjs.map +0 -1
  217. package/dist/chunk-AY6FDCBT.mjs +0 -1
  218. package/dist/chunk-AY6FDCBT.mjs.map +0 -1
  219. package/dist/chunk-C6HGFEYL.js +0 -23
  220. package/dist/chunk-C6HGFEYL.js.map +0 -1
  221. package/dist/chunk-DHVKFDHQ.js +0 -95
  222. package/dist/chunk-DHVKFDHQ.js.map +0 -1
  223. package/dist/chunk-DYRKZQMK.mjs +0 -122
  224. package/dist/chunk-DYRKZQMK.mjs.map +0 -1
  225. package/dist/chunk-E4C7EW4R.js +0 -16
  226. package/dist/chunk-E4C7EW4R.js.map +0 -1
  227. package/dist/chunk-EQMZL4XU.js +0 -1
  228. package/dist/chunk-EQMZL4XU.js.map +0 -1
  229. package/dist/chunk-GZS3IQBZ.mjs +0 -16
  230. package/dist/chunk-GZS3IQBZ.mjs.map +0 -1
  231. package/dist/chunk-H4YFDLB7.mjs +0 -70
  232. package/dist/chunk-H4YFDLB7.mjs.map +0 -1
  233. package/dist/chunk-I575FZFH.mjs +0 -1
  234. package/dist/chunk-I575FZFH.mjs.map +0 -1
  235. package/dist/chunk-IZC266HS.js +0 -55
  236. package/dist/chunk-IZC266HS.js.map +0 -1
  237. package/dist/chunk-JPAL7Q5S.mjs +0 -90
  238. package/dist/chunk-JPAL7Q5S.mjs.map +0 -1
  239. package/dist/chunk-LC2CRSWD.js +0 -1
  240. package/dist/chunk-LC2CRSWD.js.map +0 -1
  241. package/dist/chunk-NQMRFZHB.mjs +0 -35
  242. package/dist/chunk-NQMRFZHB.mjs.map +0 -1
  243. package/dist/chunk-O3EIM33O.mjs +0 -95
  244. package/dist/chunk-O3EIM33O.mjs.map +0 -1
  245. package/dist/chunk-OLLG4H35.js +0 -257
  246. package/dist/chunk-OLLG4H35.js.map +0 -1
  247. package/dist/chunk-OUZ3LSLX.mjs +0 -94
  248. package/dist/chunk-OUZ3LSLX.mjs.map +0 -1
  249. package/dist/chunk-QEPVHEP7.js +0 -273
  250. package/dist/chunk-QVEKZRZ2.js +0 -70
  251. package/dist/chunk-QVEKZRZ2.js.map +0 -1
  252. package/dist/chunk-RIRDOQPX.mjs +0 -15
  253. package/dist/chunk-RIRDOQPX.mjs.map +0 -1
  254. package/dist/chunk-RKRGAFXY.js +0 -1
  255. package/dist/chunk-RKRGAFXY.js.map +0 -1
  256. package/dist/chunk-RNEXSCNP.js +0 -122
  257. package/dist/chunk-RNEXSCNP.js.map +0 -1
  258. package/dist/chunk-ROQSKDP5.mjs +0 -69
  259. package/dist/chunk-ROQSKDP5.mjs.map +0 -1
  260. package/dist/chunk-RRYOWRCV.mjs +0 -1
  261. package/dist/chunk-RRYOWRCV.mjs.map +0 -1
  262. package/dist/chunk-S3UHBN2Z.mjs +0 -44
  263. package/dist/chunk-S3UHBN2Z.mjs.map +0 -1
  264. package/dist/chunk-THNLGEXV.mjs +0 -34
  265. package/dist/chunk-THNLGEXV.mjs.map +0 -1
  266. package/dist/chunk-UOTVU7OQ.js +0 -1
  267. package/dist/chunk-UOTVU7OQ.js.map +0 -1
  268. package/dist/chunk-VA2DRBDE.mjs +0 -273
  269. package/dist/chunk-VA2DRBDE.mjs.map +0 -1
  270. package/dist/chunk-VFXTVNXN.js +0 -44
  271. package/dist/chunk-VFXTVNXN.js.map +0 -1
  272. package/dist/chunk-W5XI7ERF.mjs +0 -23
  273. package/dist/chunk-W5XI7ERF.mjs.map +0 -1
  274. package/dist/chunk-WA4DHIND.mjs +0 -1
  275. package/dist/chunk-WA4DHIND.mjs.map +0 -1
  276. package/dist/chunk-X66SUIEF.mjs +0 -25
  277. package/dist/chunk-X66SUIEF.mjs.map +0 -1
  278. package/dist/chunk-XYGUOY6N.mjs +0 -55
  279. package/dist/chunk-XYGUOY6N.mjs.map +0 -1
  280. package/dist/chunk-YWAID473.js +0 -94
  281. package/dist/chunk-YWAID473.js.map +0 -1
  282. package/dist/chunk-Z2RGWDD7.js +0 -90
  283. package/dist/chunk-Z2RGWDD7.js.map +0 -1
  284. package/dist/coercers.js +0 -18
  285. package/dist/coercers.js.map +0 -1
  286. package/dist/collections.js +0 -10
  287. package/dist/collections.js.map +0 -1
  288. package/dist/encryption-types.js +0 -2
  289. package/dist/encryption-types.js.map +0 -1
  290. package/dist/errors.js +0 -17
  291. package/dist/errors.js.map +0 -1
  292. package/dist/fs.js +0 -26
  293. package/dist/fs.js.map +0 -1
  294. package/dist/hex.js +0 -35
  295. package/dist/hex.js.map +0 -1
  296. package/dist/index.js +0 -297
  297. package/dist/index.js.map +0 -1
  298. package/dist/json.js +0 -75
  299. package/dist/json.js.map +0 -1
  300. package/dist/keyring.js +0 -2
  301. package/dist/keyring.js.map +0 -1
  302. package/dist/logging.js +0 -10
  303. package/dist/logging.js.map +0 -1
  304. package/dist/misc.js +0 -28
  305. package/dist/misc.js.map +0 -1
  306. package/dist/node.js +0 -317
  307. package/dist/node.js.map +0 -1
  308. package/dist/number.js +0 -18
  309. package/dist/number.js.map +0 -1
  310. package/dist/opaque.js +0 -2
  311. package/dist/opaque.js.map +0 -1
  312. package/dist/promise.js +0 -8
  313. package/dist/promise.js.map +0 -1
  314. package/dist/time.js +0 -12
  315. package/dist/time.js.map +0 -1
  316. package/dist/transaction-types.js +0 -2
  317. package/dist/transaction-types.js.map +0 -1
  318. package/dist/types/assert.d.ts.map +0 -1
  319. package/dist/types/base64.d.ts.map +0 -1
  320. package/dist/types/bytes.d.ts.map +0 -1
  321. package/dist/types/caip-types.d.ts.map +0 -1
  322. package/dist/types/checksum.d.ts +0 -2
  323. package/dist/types/checksum.d.ts.map +0 -1
  324. package/dist/types/coercers.d.ts.map +0 -1
  325. package/dist/types/collections.d.ts.map +0 -1
  326. package/dist/types/encryption-types.d.ts.map +0 -1
  327. package/dist/types/errors.d.ts.map +0 -1
  328. package/dist/types/fs.d.ts.map +0 -1
  329. package/dist/types/hex.d.ts.map +0 -1
  330. package/dist/types/index.d.ts +0 -21
  331. package/dist/types/index.d.ts.map +0 -1
  332. package/dist/types/json.d.ts.map +0 -1
  333. package/dist/types/keyring.d.ts.map +0 -1
  334. package/dist/types/logging.d.ts.map +0 -1
  335. package/dist/types/misc.d.ts.map +0 -1
  336. package/dist/types/node.d.ts +0 -3
  337. package/dist/types/node.d.ts.map +0 -1
  338. package/dist/types/number.d.ts.map +0 -1
  339. package/dist/types/opaque.d.ts +0 -6
  340. package/dist/types/opaque.d.ts.map +0 -1
  341. package/dist/types/promise.d.ts.map +0 -1
  342. package/dist/types/time.d.ts.map +0 -1
  343. package/dist/types/transaction-types.d.ts.map +0 -1
  344. package/dist/types/versions.d.ts.map +0 -1
  345. package/dist/versions.js +0 -27
  346. package/dist/versions.js.map +0 -1
@@ -0,0 +1,224 @@
1
+ import type { TypedTransaction, TxData } from "@ethereumjs/tx";
2
+ import type { Eip1024EncryptedData } from "./encryption-types.mjs";
3
+ import type { Hex } from "./hex.mjs";
4
+ import type { Json } from "./json.mjs";
5
+ /**
6
+ * A Keyring class.
7
+ *
8
+ * This type is used to validate the constructor signature and the `type`
9
+ * static property on Keyring classes. See the {@link Keyring} type for more
10
+ * information.
11
+ */
12
+ export type KeyringClass<State extends Json> = {
13
+ /**
14
+ * The Keyring constructor. Takes a single parameter, an "options" object.
15
+ * See the documentation for the specific keyring for more information about
16
+ * what these options are.
17
+ *
18
+ * @param options - The constructor options. Differs between keyring
19
+ * implementations.
20
+ */
21
+ new (options?: Record<string, unknown>): Keyring<State>;
22
+ /**
23
+ * The name of this type of keyring. This must uniquely identify the
24
+ * keyring type.
25
+ */
26
+ type: string;
27
+ };
28
+ /**
29
+ * A keyring is something that can sign messages. Keyrings are used to add new
30
+ * signing strategies; each strategy is a new keyring.
31
+ *
32
+ * Each keyring manages a collection of key pairs, which we call "accounts".
33
+ * Each account is referred to by its "address", which is a unique identifier
34
+ * derived from the public key. The address is always a "0x"-prefixed
35
+ * hexidecimal string.
36
+ *
37
+ * The keyring might store the private key for each account as well, but it's
38
+ * not guaranteed. Some keyrings delegate signing, so they don't need the
39
+ * private key directly. The keyring (and in particular the keyring state)
40
+ * should be treated with care though, just in case it does contain sensitive
41
+ * material such as a private key.
42
+ */
43
+ export type Keyring<State extends Json> = {
44
+ /**
45
+ * The name of this type of keyring. This must match the `type` property of
46
+ * the keyring class.
47
+ */
48
+ type: string;
49
+ /**
50
+ * Get the addresses for all accounts in this keyring.
51
+ *
52
+ * @returns A list of the account addresses for this keyring
53
+ */
54
+ getAccounts(): Promise<Hex[]>;
55
+ /**
56
+ * Add an account to the keyring.
57
+ *
58
+ * @param number - The number of accounts to add. Usually defaults to 1.
59
+ * @returns A list of the newly added account addresses.
60
+ */
61
+ addAccounts(number: number): Promise<Hex[]>;
62
+ /**
63
+ * Serialize the keyring state as a JSON-serializable object.
64
+ *
65
+ * @returns A JSON-serializable representation of the keyring state.
66
+ */
67
+ serialize(): Promise<State>;
68
+ /**
69
+ * Deserialize the given keyring state, overwriting any existing state with
70
+ * the serialized state provided.
71
+ *
72
+ * @param state - A JSON-serializable representation of the keyring state.
73
+ */
74
+ deserialize(state: State): Promise<void>;
75
+ /**
76
+ * Method to include asynchronous configuration.
77
+ */
78
+ init?(): Promise<void>;
79
+ /**
80
+ * Remove an account from the keyring.
81
+ *
82
+ * @param address - The address of the account to remove.
83
+ */
84
+ removeAccount?(address: Hex): void;
85
+ /**
86
+ * Export the private key for one of the keyring accounts.
87
+ *
88
+ * Some keyrings accept an "options" parameter as well. See the documentation
89
+ * for the specific keyring for more information about what these options
90
+ * are. For some keyrings, the options parameter is used to allow exporting a
91
+ * private key that is derived from the given account, rather than exporting
92
+ * that account's private key directly.
93
+ *
94
+ * @param address - The address of the account to export.
95
+ * @param options - Export options; differs between keyrings.
96
+ * @returns The non-prefixed, hex-encoded private key that was requested.
97
+ */
98
+ exportAccount?(address: Hex, options?: Record<string, unknown>): Promise<string>;
99
+ /**
100
+ * Get the "app key" address for the given account and origin. An app key is
101
+ * an application-specific key pair. See {@link https://eips.ethereum.org/EIPS/eip-1775|EIP-1775}
102
+ * for more information. The {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin|origin}
103
+ * is used as the unique identifier for the application, and it's used as
104
+ * part of the key derivation process.
105
+ *
106
+ * @param address - The address of the account the app key is derived from.
107
+ * @param origin - The origin of the application.
108
+ * @returns The address of the app key for the given account and origin.
109
+ */
110
+ getAppKeyAddress?(address: Hex, origin: string): Promise<Hex>;
111
+ /**
112
+ * Sign a transaction. This is equivalent to the `eth_signTransaction`
113
+ * Ethereum JSON-RPC method. See the Ethereum JSON-RPC API documentation for
114
+ * more details.
115
+ *
116
+ * Some keyrings accept an "options" parameter as well. See the documentation
117
+ * for the specific keyring for more information about what these options
118
+ * are. For some keyrings, the options parameter can even change which key is
119
+ * used for signing (e.g. signing with app keys).
120
+ *
121
+ * @param address - The address of the account to use for signing.
122
+ * @param transaction - The transaction to sign.
123
+ * @param options - Signing options; differs between keyrings.
124
+ * @returns The signed transaction.
125
+ */
126
+ signTransaction?(address: Hex, transaction: TypedTransaction, options?: Record<string, unknown>): Promise<TxData>;
127
+ /**
128
+ * Sign a message. This is equivalent to an older version of the the
129
+ * `eth_sign` Ethereum JSON-RPC method. The message is signed using ECDSA,
130
+ * using the curve secp256k1 the Keccak-256 hash function.
131
+ *
132
+ * For more information about this method and why we still support it, see
133
+ * the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
134
+ *
135
+ * Some keyrings accept an "options" parameter as well. See the documentation
136
+ * for the specific keyring for more information about what these options
137
+ * are. For some keyrings, the options parameter can even change which key is
138
+ * used for signing (e.g. signing with app keys).
139
+ *
140
+ * @param address - The address of the account to use for signing.
141
+ * @param message - The message to sign.
142
+ * @param options - Signing options; differs between keyrings.
143
+ * @returns The signed message.
144
+ */
145
+ signMessage?(address: Hex, message: string, options?: Record<string, unknown>): Promise<string>;
146
+ /**
147
+ * Sign a message. This is equivalent to the `eth_sign` Ethereum JSON-RPC
148
+ * method, which is exposed by MetaMask as the method `personal_sign`. See
149
+ * the Ethereum JSON-RPC API documentation for more details.
150
+ *
151
+ * For more information about this method and why we call it `personal_sign`,
152
+ * see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
153
+ *
154
+ * Some keyrings accept an "options" parameter as well. See the documentation
155
+ * for the specific keyring for more information about what these options
156
+ * are. For some keyrings, the options parameter can even change which key is
157
+ * used for signing (e.g. signing with app keys).
158
+ *
159
+ * @param address - The address of the account to use for signing.
160
+ * @param message - The message to sign.
161
+ * @param options - Signing options; differs between keyrings.
162
+ * @returns The signed message.
163
+ */
164
+ signPersonalMessage?(address: Hex, message: Hex, options?: {
165
+ version?: string;
166
+ } & Record<string, unknown>): Promise<string>;
167
+ /**
168
+ * Sign a message. This is equivalent to the `eth_signTypedData` Ethereum
169
+ * JSON-RPC method. See {@link https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md|EIP-712}
170
+ * for more details.
171
+ *
172
+ * The "version" option dictates which version of `eth_signTypedData` is
173
+ * used. The latest version reflects the specification most closely, whereas
174
+ * earlier versions reflect earlier drafts of the specification that are
175
+ * still supported for backwards-compatibility reasons. For more information
176
+ * about why we support multiple versions, see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
177
+ *
178
+ * Some keyrings accept additional options as well. See the documentation for
179
+ * the specific keyring for more information about what these options are.
180
+ * For some keyrings, the options parameter can even change which key is used
181
+ * for signing (e.g. signing with app keys).
182
+ *
183
+ * @param address - The address of the account to use for signing.
184
+ * @param typedData - The data to sign.
185
+ * @param options - Signing options; differs between keyrings.
186
+ * @returns The signed message.
187
+ */
188
+ signTypedData?(address: Hex, typedData: Record<string, unknown>, options?: Record<string, unknown>): Promise<string>;
189
+ /**
190
+ * Get a public key to use for encryption. This is equivalent to the
191
+ * ` eth_getEncryptionPublicKey` JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-getencryptionpublickey|MetaMask Docs}
192
+ * for more information.
193
+ *
194
+ * Some keyrings accept an "options" parameter as well. See the documentation
195
+ * for the specific keyring for more information about what these options
196
+ * are. For some keyrings, the options parameter can even change which key is
197
+ * used (e.g. encrypting with app keys).
198
+ *
199
+ * @param account - The address of the account you want the encryption key for.
200
+ * @param options - Options; differs between keyrings.
201
+ */
202
+ getEncryptionPublicKey?(account: Hex, options?: Record<string, unknown>): Promise<string>;
203
+ /**
204
+ * Decrypt an encrypted message. This is equivalent to the ` eth_decrypt`
205
+ * JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-decrypt|MetaMask Docs}
206
+ * for more information.
207
+ *
208
+ * @param account - The address of the account you want to use to decrypt
209
+ * the message.
210
+ * @param encryptedData - The encrypted data that you want to decrypt.
211
+ * @returns The decrypted data.
212
+ */
213
+ decryptMessage?(account: Hex, encryptedData: Eip1024EncryptedData): Promise<string>;
214
+ /**
215
+ * Generates the properties for the keyring based on the given
216
+ * BIP39-compliant mnemonic.
217
+ */
218
+ generateRandomMnemonic?(): void;
219
+ /**
220
+ * Destroy the keyring.
221
+ */
222
+ destroy?(): Promise<void>;
223
+ };
224
+ //# sourceMappingURL=keyring.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring.d.mts","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"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"}
package/dist/keyring.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import "./chunk-I575FZFH.mjs";
1
+ export {};
2
2
  //# sourceMappingURL=keyring.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"keyring.mjs","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypedTransaction, TxData } from '@ethereumjs/tx';\n\nimport type { Eip1024EncryptedData } from './encryption-types';\nimport type { Hex } from './hex';\nimport type { Json } from './json';\n\n/**\n * A Keyring class.\n *\n * This type is used to validate the constructor signature and the `type`\n * static property on Keyring classes. See the {@link Keyring} type for more\n * information.\n */\nexport type KeyringClass<State extends Json> = {\n /**\n * The Keyring constructor. Takes a single parameter, an \"options\" object.\n * See the documentation for the specific keyring for more information about\n * what these options are.\n *\n * @param options - The constructor options. Differs between keyring\n * implementations.\n */\n new (options?: Record<string, unknown>): Keyring<State>;\n\n /**\n * The name of this type of keyring. This must uniquely identify the\n * keyring type.\n */\n type: string;\n};\n\n/**\n * A keyring is something that can sign messages. Keyrings are used to add new\n * signing strategies; each strategy is a new keyring.\n *\n * Each keyring manages a collection of key pairs, which we call \"accounts\".\n * Each account is referred to by its \"address\", which is a unique identifier\n * derived from the public key. The address is always a \"0x\"-prefixed\n * hexidecimal string.\n *\n * The keyring might store the private key for each account as well, but it's\n * not guaranteed. Some keyrings delegate signing, so they don't need the\n * private key directly. The keyring (and in particular the keyring state)\n * should be treated with care though, just in case it does contain sensitive\n * material such as a private key.\n */\nexport type Keyring<State extends Json> = {\n /**\n * The name of this type of keyring. This must match the `type` property of\n * the keyring class.\n */\n type: string;\n\n /**\n * Get the addresses for all accounts in this keyring.\n *\n * @returns A list of the account addresses for this keyring\n */\n getAccounts(): Promise<Hex[]>;\n\n /**\n * Add an account to the keyring.\n *\n * @param number - The number of accounts to add. Usually defaults to 1.\n * @returns A list of the newly added account addresses.\n */\n addAccounts(number: number): Promise<Hex[]>;\n\n /**\n * Serialize the keyring state as a JSON-serializable object.\n *\n * @returns A JSON-serializable representation of the keyring state.\n */\n serialize(): Promise<State>;\n\n /**\n * Deserialize the given keyring state, overwriting any existing state with\n * the serialized state provided.\n *\n * @param state - A JSON-serializable representation of the keyring state.\n */\n deserialize(state: State): Promise<void>;\n\n /**\n * Method to include asynchronous configuration.\n */\n init?(): Promise<void>;\n\n /**\n * Remove an account from the keyring.\n *\n * @param address - The address of the account to remove.\n */\n removeAccount?(address: Hex): void;\n\n /**\n * Export the private key for one of the keyring accounts.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter is used to allow exporting a\n * private key that is derived from the given account, rather than exporting\n * that account's private key directly.\n *\n * @param address - The address of the account to export.\n * @param options - Export options; differs between keyrings.\n * @returns The non-prefixed, hex-encoded private key that was requested.\n */\n exportAccount?(\n address: Hex,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Get the \"app key\" address for the given account and origin. An app key is\n * an application-specific key pair. See {@link https://eips.ethereum.org/EIPS/eip-1775|EIP-1775}\n * for more information. The {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin|origin}\n * is used as the unique identifier for the application, and it's used as\n * part of the key derivation process.\n *\n * @param address - The address of the account the app key is derived from.\n * @param origin - The origin of the application.\n * @returns The address of the app key for the given account and origin.\n */\n getAppKeyAddress?(address: Hex, origin: string): Promise<Hex>;\n\n /**\n * Sign a transaction. This is equivalent to the `eth_signTransaction`\n * Ethereum JSON-RPC method. See the Ethereum JSON-RPC API documentation for\n * more details.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param transaction - The transaction to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed transaction.\n */\n signTransaction?(\n address: Hex,\n transaction: TypedTransaction,\n options?: Record<string, unknown>,\n ): Promise<TxData>;\n\n /**\n * Sign a message. This is equivalent to an older version of the the\n * `eth_sign` Ethereum JSON-RPC method. The message is signed using ECDSA,\n * using the curve secp256k1 the Keccak-256 hash function.\n *\n * For more information about this method and why we still support it, see\n * the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param message - The message to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signMessage?(\n address: Hex,\n message: string,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign a message. This is equivalent to the `eth_sign` Ethereum JSON-RPC\n * method, which is exposed by MetaMask as the method `personal_sign`. See\n * the Ethereum JSON-RPC API documentation for more details.\n *\n * For more information about this method and why we call it `personal_sign`,\n * see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param message - The message to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signPersonalMessage?(\n address: Hex,\n message: Hex,\n options?: { version?: string } & Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign a message. This is equivalent to the `eth_signTypedData` Ethereum\n * JSON-RPC method. See {@link https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md|EIP-712}\n * for more details.\n *\n * The \"version\" option dictates which version of `eth_signTypedData` is\n * used. The latest version reflects the specification most closely, whereas\n * earlier versions reflect earlier drafts of the specification that are\n * still supported for backwards-compatibility reasons. For more information\n * about why we support multiple versions, see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept additional options as well. See the documentation for\n * the specific keyring for more information about what these options are.\n * For some keyrings, the options parameter can even change which key is used\n * for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param typedData - The data to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signTypedData?(\n address: Hex,\n typedData: Record<string, unknown>,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Get a public key to use for encryption. This is equivalent to the\n * ` eth_getEncryptionPublicKey` JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-getencryptionpublickey|MetaMask Docs}\n * for more information.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used (e.g. encrypting with app keys).\n *\n * @param account - The address of the account you want the encryption key for.\n * @param options - Options; differs between keyrings.\n */\n getEncryptionPublicKey?(\n account: Hex,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Decrypt an encrypted message. This is equivalent to the ` eth_decrypt`\n * JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-decrypt|MetaMask Docs}\n * for more information.\n *\n * @param account - The address of the account you want to use to decrypt\n * the message.\n * @param encryptedData - The encrypted data that you want to decrypt.\n * @returns The decrypted data.\n */\n decryptMessage?(\n account: Hex,\n encryptedData: Eip1024EncryptedData,\n ): Promise<string>;\n\n /**\n * Generates the properties for the keyring based on the given\n * BIP39-compliant mnemonic.\n */\n generateRandomMnemonic?(): void;\n\n /**\n * Destroy the keyring.\n */\n destroy?(): Promise<void>;\n};\n"]}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createModuleLogger = exports.createProjectLogger = void 0;
7
+ const debug_1 = __importDefault(require("debug"));
8
+ const globalLogger = (0, debug_1.default)('metamask');
9
+ /**
10
+ * Creates a logger via the `debug` library whose log messages will be tagged
11
+ * using the name of your project. By default, such messages will be
12
+ * suppressed, but you can reveal them by setting the `DEBUG` environment
13
+ * variable to `metamask:<projectName>`. You can also set this variable to
14
+ * `metamask:*` if you want to see log messages from all MetaMask projects that
15
+ * are also using this function to create their loggers.
16
+ *
17
+ * @param projectName - The name of your project. This should be the name of
18
+ * your NPM package if you're developing one.
19
+ * @returns An instance of `debug`.
20
+ */
21
+ function createProjectLogger(projectName) {
22
+ return globalLogger.extend(projectName);
23
+ }
24
+ exports.createProjectLogger = createProjectLogger;
25
+ /**
26
+ * Creates a logger via the `debug` library which is derived from the logger for
27
+ * the whole project whose log messages will be tagged using the name of your
28
+ * module. By default, such messages will be suppressed, but you can reveal them
29
+ * by setting the `DEBUG` environment variable to
30
+ * `metamask:<projectName>:<moduleName>`. You can also set this variable to
31
+ * `metamask:<projectName>:*` if you want to see log messages from the project,
32
+ * or `metamask:*` if you want to see log messages from all MetaMask projects.
33
+ *
34
+ * @param projectLogger - The logger created via {@link createProjectLogger}.
35
+ * @param moduleName - The name of your module. You could use the name of the
36
+ * file where you're using this logger or some other name.
37
+ * @returns An instance of `debug`.
38
+ */
39
+ function createModuleLogger(projectLogger, moduleName) {
40
+ return projectLogger.extend(moduleName);
41
+ }
42
+ exports.createModuleLogger = createModuleLogger;
43
+ //# sourceMappingURL=logging.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.cjs","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":";;;;;;AACA,kDAA0B;AAE1B,MAAM,YAAY,GAAG,IAAA,eAAK,EAAC,UAAU,CAAC,CAAC;AAEvC;;;;;;;;;;;GAWG;AACH,SAAgB,mBAAmB,CAAC,WAAmB;IACrD,OAAO,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC1C,CAAC;AAFD,kDAEC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,kBAAkB,CAChC,aAAuB,EACvB,UAAkB;IAElB,OAAO,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAC1C,CAAC;AALD,gDAKC","sourcesContent":["import type { Debugger } from 'debug';\nimport debug from 'debug';\n\nconst globalLogger = debug('metamask');\n\n/**\n * Creates a logger via the `debug` library whose log messages will be tagged\n * using the name of your project. By default, such messages will be\n * suppressed, but you can reveal them by setting the `DEBUG` environment\n * variable to `metamask:<projectName>`. You can also set this variable to\n * `metamask:*` if you want to see log messages from all MetaMask projects that\n * are also using this function to create their loggers.\n *\n * @param projectName - The name of your project. This should be the name of\n * your NPM package if you're developing one.\n * @returns An instance of `debug`.\n */\nexport function createProjectLogger(projectName: string): Debugger {\n return globalLogger.extend(projectName);\n}\n\n/**\n * Creates a logger via the `debug` library which is derived from the logger for\n * the whole project whose log messages will be tagged using the name of your\n * module. By default, such messages will be suppressed, but you can reveal them\n * by setting the `DEBUG` environment variable to\n * `metamask:<projectName>:<moduleName>`. You can also set this variable to\n * `metamask:<projectName>:*` if you want to see log messages from the project,\n * or `metamask:*` if you want to see log messages from all MetaMask projects.\n *\n * @param projectLogger - The logger created via {@link createProjectLogger}.\n * @param moduleName - The name of your module. You could use the name of the\n * file where you're using this logger or some other name.\n * @returns An instance of `debug`.\n */\nexport function createModuleLogger(\n projectLogger: Debugger,\n moduleName: string,\n): Debugger {\n return projectLogger.extend(moduleName);\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { Debugger } from 'debug';
1
+ import type { Debugger } from "debug";
2
2
  /**
3
3
  * Creates a logger via the `debug` library whose log messages will be tagged
4
4
  * using the name of your project. By default, such messages will be
@@ -27,4 +27,4 @@ export declare function createProjectLogger(projectName: string): Debugger;
27
27
  * @returns An instance of `debug`.
28
28
  */
29
29
  export declare function createModuleLogger(projectLogger: Debugger, moduleName: string): Debugger;
30
- //# sourceMappingURL=logging.d.ts.map
30
+ //# sourceMappingURL=logging.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.d.cts","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc;AAKtC;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAEjE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,QAAQ,EACvB,UAAU,EAAE,MAAM,GACjB,QAAQ,CAEV"}
@@ -0,0 +1,30 @@
1
+ import type { Debugger } from "debug";
2
+ /**
3
+ * Creates a logger via the `debug` library whose log messages will be tagged
4
+ * using the name of your project. By default, such messages will be
5
+ * suppressed, but you can reveal them by setting the `DEBUG` environment
6
+ * variable to `metamask:<projectName>`. You can also set this variable to
7
+ * `metamask:*` if you want to see log messages from all MetaMask projects that
8
+ * are also using this function to create their loggers.
9
+ *
10
+ * @param projectName - The name of your project. This should be the name of
11
+ * your NPM package if you're developing one.
12
+ * @returns An instance of `debug`.
13
+ */
14
+ export declare function createProjectLogger(projectName: string): Debugger;
15
+ /**
16
+ * Creates a logger via the `debug` library which is derived from the logger for
17
+ * the whole project whose log messages will be tagged using the name of your
18
+ * module. By default, such messages will be suppressed, but you can reveal them
19
+ * by setting the `DEBUG` environment variable to
20
+ * `metamask:<projectName>:<moduleName>`. You can also set this variable to
21
+ * `metamask:<projectName>:*` if you want to see log messages from the project,
22
+ * or `metamask:*` if you want to see log messages from all MetaMask projects.
23
+ *
24
+ * @param projectLogger - The logger created via {@link createProjectLogger}.
25
+ * @param moduleName - The name of your module. You could use the name of the
26
+ * file where you're using this logger or some other name.
27
+ * @returns An instance of `debug`.
28
+ */
29
+ export declare function createModuleLogger(projectLogger: Debugger, moduleName: string): Debugger;
30
+ //# sourceMappingURL=logging.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.d.mts","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc;AAKtC;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAEjE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,QAAQ,EACvB,UAAU,EAAE,MAAM,GACjB,QAAQ,CAEV"}
package/dist/logging.mjs CHANGED
@@ -1,10 +1,35 @@
1
- import {
2
- createModuleLogger,
3
- createProjectLogger
4
- } from "./chunk-RIRDOQPX.mjs";
5
- import "./chunk-X66SUIEF.mjs";
6
- export {
7
- createModuleLogger,
8
- createProjectLogger
9
- };
1
+ import debug from "debug";
2
+ const globalLogger = debug('metamask');
3
+ /**
4
+ * Creates a logger via the `debug` library whose log messages will be tagged
5
+ * using the name of your project. By default, such messages will be
6
+ * suppressed, but you can reveal them by setting the `DEBUG` environment
7
+ * variable to `metamask:<projectName>`. You can also set this variable to
8
+ * `metamask:*` if you want to see log messages from all MetaMask projects that
9
+ * are also using this function to create their loggers.
10
+ *
11
+ * @param projectName - The name of your project. This should be the name of
12
+ * your NPM package if you're developing one.
13
+ * @returns An instance of `debug`.
14
+ */
15
+ export function createProjectLogger(projectName) {
16
+ return globalLogger.extend(projectName);
17
+ }
18
+ /**
19
+ * Creates a logger via the `debug` library which is derived from the logger for
20
+ * the whole project whose log messages will be tagged using the name of your
21
+ * module. By default, such messages will be suppressed, but you can reveal them
22
+ * by setting the `DEBUG` environment variable to
23
+ * `metamask:<projectName>:<moduleName>`. You can also set this variable to
24
+ * `metamask:<projectName>:*` if you want to see log messages from the project,
25
+ * or `metamask:*` if you want to see log messages from all MetaMask projects.
26
+ *
27
+ * @param projectLogger - The logger created via {@link createProjectLogger}.
28
+ * @param moduleName - The name of your module. You could use the name of the
29
+ * file where you're using this logger or some other name.
30
+ * @returns An instance of `debug`.
31
+ */
32
+ export function createModuleLogger(projectLogger, moduleName) {
33
+ return projectLogger.extend(moduleName);
34
+ }
10
35
  //# sourceMappingURL=logging.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"logging.mjs","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,cAAc;AAE1B,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;AAEvC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAmB;IACrD,OAAO,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAChC,aAAuB,EACvB,UAAkB;IAElB,OAAO,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import type { Debugger } from 'debug';\nimport debug from 'debug';\n\nconst globalLogger = debug('metamask');\n\n/**\n * Creates a logger via the `debug` library whose log messages will be tagged\n * using the name of your project. By default, such messages will be\n * suppressed, but you can reveal them by setting the `DEBUG` environment\n * variable to `metamask:<projectName>`. You can also set this variable to\n * `metamask:*` if you want to see log messages from all MetaMask projects that\n * are also using this function to create their loggers.\n *\n * @param projectName - The name of your project. This should be the name of\n * your NPM package if you're developing one.\n * @returns An instance of `debug`.\n */\nexport function createProjectLogger(projectName: string): Debugger {\n return globalLogger.extend(projectName);\n}\n\n/**\n * Creates a logger via the `debug` library which is derived from the logger for\n * the whole project whose log messages will be tagged using the name of your\n * module. By default, such messages will be suppressed, but you can reveal them\n * by setting the `DEBUG` environment variable to\n * `metamask:<projectName>:<moduleName>`. You can also set this variable to\n * `metamask:<projectName>:*` if you want to see log messages from the project,\n * or `metamask:*` if you want to see log messages from all MetaMask projects.\n *\n * @param projectLogger - The logger created via {@link createProjectLogger}.\n * @param moduleName - The name of your module. You could use the name of the\n * file where you're using this logger or some other name.\n * @returns An instance of `debug`.\n */\nexport function createModuleLogger(\n projectLogger: Debugger,\n moduleName: string,\n): Debugger {\n return projectLogger.extend(moduleName);\n}\n"]}
package/dist/misc.cjs ADDED
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ //
3
+ // Types
4
+ //
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.calculateNumberSize = exports.calculateStringSize = exports.isASCII = exports.isPlainObject = exports.ESCAPE_CHARACTERS_REGEXP = exports.JsonSize = exports.getKnownPropertyNames = exports.hasProperty = exports.isObject = exports.isNullOrUndefined = exports.isNonEmptyArray = void 0;
7
+ //
8
+ // Type Guards
9
+ //
10
+ /**
11
+ * A {@link NonEmptyArray} type guard.
12
+ *
13
+ * @template Element - The non-empty array member type.
14
+ * @param value - The value to check.
15
+ * @returns Whether the value is a non-empty array.
16
+ */
17
+ function isNonEmptyArray(value) {
18
+ return Array.isArray(value) && value.length > 0;
19
+ }
20
+ exports.isNonEmptyArray = isNonEmptyArray;
21
+ /**
22
+ * Type guard for "nullishness".
23
+ *
24
+ * @param value - Any value.
25
+ * @returns `true` if the value is null or undefined, `false` otherwise.
26
+ */
27
+ function isNullOrUndefined(value) {
28
+ return value === null || value === undefined;
29
+ }
30
+ exports.isNullOrUndefined = isNullOrUndefined;
31
+ /**
32
+ * A type guard for {@link RuntimeObject}.
33
+ *
34
+ * @param value - The value to check.
35
+ * @returns Whether the specified value has a runtime type of `object` and is
36
+ * neither `null` nor an `Array`.
37
+ */
38
+ function isObject(value) {
39
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
40
+ }
41
+ exports.isObject = isObject;
42
+ //
43
+ // Other utility functions
44
+ //
45
+ /**
46
+ * A type guard for ensuring an object has a property.
47
+ *
48
+ * @param objectToCheck - The object to check.
49
+ * @param name - The property name to check for.
50
+ * @returns Whether the specified object has an own property with the specified
51
+ * name, regardless of whether it is enumerable or not.
52
+ */
53
+ const hasProperty = (objectToCheck, name) => Object.hasOwnProperty.call(objectToCheck, name);
54
+ exports.hasProperty = hasProperty;
55
+ /**
56
+ * `Object.getOwnPropertyNames()` is intentionally generic: it returns the
57
+ * immediate property names of an object, but it cannot make guarantees about
58
+ * the contents of that object, so the type of the property names is merely
59
+ * `string[]`. While this is technically accurate, it is also unnecessary if we
60
+ * have an object with a type that we own (such as an enum).
61
+ *
62
+ * @param object - The plain object.
63
+ * @returns The own property names of the object which are assigned a type
64
+ * derived from the object itself.
65
+ */
66
+ function getKnownPropertyNames(object) {
67
+ return Object.getOwnPropertyNames(object);
68
+ }
69
+ exports.getKnownPropertyNames = getKnownPropertyNames;
70
+ /**
71
+ * Predefined sizes (in Bytes) of specific parts of JSON structure.
72
+ */
73
+ var JsonSize;
74
+ (function (JsonSize) {
75
+ JsonSize[JsonSize["Null"] = 4] = "Null";
76
+ JsonSize[JsonSize["Comma"] = 1] = "Comma";
77
+ JsonSize[JsonSize["Wrapper"] = 1] = "Wrapper";
78
+ JsonSize[JsonSize["True"] = 4] = "True";
79
+ JsonSize[JsonSize["False"] = 5] = "False";
80
+ JsonSize[JsonSize["Quote"] = 1] = "Quote";
81
+ JsonSize[JsonSize["Colon"] = 1] = "Colon";
82
+ // eslint-disable-next-line @typescript-eslint/no-shadow
83
+ JsonSize[JsonSize["Date"] = 24] = "Date";
84
+ })(JsonSize = exports.JsonSize || (exports.JsonSize = {}));
85
+ /**
86
+ * Regular expression with pattern matching for (special) escaped characters.
87
+ */
88
+ exports.ESCAPE_CHARACTERS_REGEXP = /"|\\|\n|\r|\t/gu;
89
+ /**
90
+ * Check if the value is plain object.
91
+ *
92
+ * @param value - Value to be checked.
93
+ * @returns True if an object is the plain JavaScript object,
94
+ * false if the object is not plain (e.g. function).
95
+ */
96
+ function isPlainObject(value) {
97
+ if (typeof value !== 'object' || value === null) {
98
+ return false;
99
+ }
100
+ try {
101
+ let proto = value;
102
+ while (Object.getPrototypeOf(proto) !== null) {
103
+ proto = Object.getPrototypeOf(proto);
104
+ }
105
+ return Object.getPrototypeOf(value) === proto;
106
+ }
107
+ catch (_) {
108
+ return false;
109
+ }
110
+ }
111
+ exports.isPlainObject = isPlainObject;
112
+ /**
113
+ * Check if character is ASCII.
114
+ *
115
+ * @param character - Character.
116
+ * @returns True if a character code is ASCII, false if not.
117
+ */
118
+ function isASCII(character) {
119
+ return character.charCodeAt(0) <= 127;
120
+ }
121
+ exports.isASCII = isASCII;
122
+ /**
123
+ * Calculate string size.
124
+ *
125
+ * @param value - String value to calculate size.
126
+ * @returns Number of bytes used to store whole string value.
127
+ */
128
+ function calculateStringSize(value) {
129
+ const size = value.split('').reduce((total, character) => {
130
+ if (isASCII(character)) {
131
+ return total + 1;
132
+ }
133
+ return total + 2;
134
+ }, 0);
135
+ // Also detect characters that need backslash escape
136
+ return size + (value.match(exports.ESCAPE_CHARACTERS_REGEXP) ?? []).length;
137
+ }
138
+ exports.calculateStringSize = calculateStringSize;
139
+ /**
140
+ * Calculate size of a number ofter JSON serialization.
141
+ *
142
+ * @param value - Number value to calculate size.
143
+ * @returns Number of bytes used to store whole number in JSON.
144
+ */
145
+ function calculateNumberSize(value) {
146
+ return value.toString().length;
147
+ }
148
+ exports.calculateNumberSize = calculateNumberSize;
149
+ //# sourceMappingURL=misc.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"misc.cjs","sourceRoot":"","sources":["../src/misc.ts"],"names":[],"mappings":"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","sourcesContent":["//\n// Types\n//\n\n/**\n * Makes every specified property of the specified object type mutable.\n *\n * @template ObjectValue - The object whose readonly properties to make mutable.\n * @template TargetKey - The property key(s) to make mutable.\n */\nexport type Mutable<\n ObjectValue extends Record<string, unknown>,\n TargetKey extends keyof ObjectValue,\n> = {\n -readonly [Key in keyof Pick<ObjectValue, TargetKey>]: ObjectValue[Key];\n} & {\n [Key in keyof Omit<ObjectValue, TargetKey>]: ObjectValue[Key];\n};\n\n/**\n * Useful for representing some value that _might_ be present and / or complete.\n *\n * @template Value - The value that might be present or complete.\n */\nexport type PartialOrAbsent<Value> = Partial<Value> | null | undefined;\n\n/**\n * Like {@link Array}, but always non-empty.\n *\n * @template Element - The non-empty array member type.\n */\nexport type NonEmptyArray<Element> = [Element, ...Element[]];\n\n/**\n * A JavaScript object that is not `null`, a function, or an array.\n */\nexport type RuntimeObject = Record<PropertyKey, unknown>;\n\n//\n// Type Guards\n//\n\n/**\n * A {@link NonEmptyArray} type guard.\n *\n * @template Element - The non-empty array member type.\n * @param value - The value to check.\n * @returns Whether the value is a non-empty array.\n */\nexport function isNonEmptyArray<Element>(\n value: Element[],\n): value is NonEmptyArray<Element> {\n return Array.isArray(value) && value.length > 0;\n}\n\n/**\n * Type guard for \"nullishness\".\n *\n * @param value - Any value.\n * @returns `true` if the value is null or undefined, `false` otherwise.\n */\nexport function isNullOrUndefined(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n\n/**\n * A type guard for {@link RuntimeObject}.\n *\n * @param value - The value to check.\n * @returns Whether the specified value has a runtime type of `object` and is\n * neither `null` nor an `Array`.\n */\nexport function isObject(value: unknown): value is RuntimeObject {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n}\n\n//\n// Other utility functions\n//\n\n/**\n * A type guard for ensuring an object has a property.\n *\n * @param objectToCheck - The object to check.\n * @param name - The property name to check for.\n * @returns Whether the specified object has an own property with the specified\n * name, regardless of whether it is enumerable or not.\n */\nexport const hasProperty = <\n // eslint-disable-next-line @typescript-eslint/ban-types\n ObjectToCheck extends Object,\n Property extends PropertyKey,\n>(\n objectToCheck: ObjectToCheck,\n name: Property,\n): objectToCheck is ObjectToCheck &\n Record<\n Property,\n Property extends keyof ObjectToCheck ? ObjectToCheck[Property] : unknown\n > => Object.hasOwnProperty.call(objectToCheck, name);\n\n/**\n * `Object.getOwnPropertyNames()` is intentionally generic: it returns the\n * immediate property names of an object, but it cannot make guarantees about\n * the contents of that object, so the type of the property names is merely\n * `string[]`. While this is technically accurate, it is also unnecessary if we\n * have an object with a type that we own (such as an enum).\n *\n * @param object - The plain object.\n * @returns The own property names of the object which are assigned a type\n * derived from the object itself.\n */\nexport function getKnownPropertyNames<Key extends PropertyKey>(\n object: Partial<Record<Key, any>>,\n): Key[] {\n return Object.getOwnPropertyNames(object) as Key[];\n}\n\nexport type PlainObject = Record<number | string | symbol, unknown>;\n\n/**\n * Predefined sizes (in Bytes) of specific parts of JSON structure.\n */\nexport enum JsonSize {\n Null = 4,\n Comma = 1,\n Wrapper = 1,\n True = 4,\n False = 5,\n Quote = 1,\n Colon = 1,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n Date = 24,\n}\n\n/**\n * Regular expression with pattern matching for (special) escaped characters.\n */\nexport const ESCAPE_CHARACTERS_REGEXP = /\"|\\\\|\\n|\\r|\\t/gu;\n\n/**\n * Check if the value is plain object.\n *\n * @param value - Value to be checked.\n * @returns True if an object is the plain JavaScript object,\n * false if the object is not plain (e.g. function).\n */\nexport function isPlainObject(value: unknown): value is PlainObject {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n\n try {\n let proto = value;\n while (Object.getPrototypeOf(proto) !== null) {\n proto = Object.getPrototypeOf(proto);\n }\n\n return Object.getPrototypeOf(value) === proto;\n } catch (_) {\n return false;\n }\n}\n\n/**\n * Check if character is ASCII.\n *\n * @param character - Character.\n * @returns True if a character code is ASCII, false if not.\n */\nexport function isASCII(character: string) {\n return character.charCodeAt(0) <= 127;\n}\n\n/**\n * Calculate string size.\n *\n * @param value - String value to calculate size.\n * @returns Number of bytes used to store whole string value.\n */\nexport function calculateStringSize(value: string): number {\n const size = value.split('').reduce((total, character) => {\n if (isASCII(character)) {\n return total + 1;\n }\n return total + 2;\n }, 0);\n\n // Also detect characters that need backslash escape\n return size + (value.match(ESCAPE_CHARACTERS_REGEXP) ?? []).length;\n}\n\n/**\n * Calculate size of a number ofter JSON serialization.\n *\n * @param value - Number value to calculate size.\n * @returns Number of bytes used to store whole number in JSON.\n */\nexport function calculateNumberSize(value: number): number {\n return value.toString().length;\n}\n"]}
@@ -4,7 +4,7 @@
4
4
  * @template ObjectValue - The object whose readonly properties to make mutable.
5
5
  * @template TargetKey - The property key(s) to make mutable.
6
6
  */
7
- export declare type Mutable<ObjectValue extends Record<string, unknown>, TargetKey extends keyof ObjectValue> = {
7
+ export type Mutable<ObjectValue extends Record<string, unknown>, TargetKey extends keyof ObjectValue> = {
8
8
  -readonly [Key in keyof Pick<ObjectValue, TargetKey>]: ObjectValue[Key];
9
9
  } & {
10
10
  [Key in keyof Omit<ObjectValue, TargetKey>]: ObjectValue[Key];
@@ -14,17 +14,17 @@ export declare type Mutable<ObjectValue extends Record<string, unknown>, TargetK
14
14
  *
15
15
  * @template Value - The value that might be present or complete.
16
16
  */
17
- export declare type PartialOrAbsent<Value> = Partial<Value> | null | undefined;
17
+ export type PartialOrAbsent<Value> = Partial<Value> | null | undefined;
18
18
  /**
19
19
  * Like {@link Array}, but always non-empty.
20
20
  *
21
21
  * @template Element - The non-empty array member type.
22
22
  */
23
- export declare type NonEmptyArray<Element> = [Element, ...Element[]];
23
+ export type NonEmptyArray<Element> = [Element, ...Element[]];
24
24
  /**
25
25
  * A JavaScript object that is not `null`, a function, or an array.
26
26
  */
27
- export declare type RuntimeObject = Record<PropertyKey, unknown>;
27
+ export type RuntimeObject = Record<PropertyKey, unknown>;
28
28
  /**
29
29
  * A {@link NonEmptyArray} type guard.
30
30
  *
@@ -69,7 +69,7 @@ export declare const hasProperty: <ObjectToCheck extends Object, Property extend
69
69
  * derived from the object itself.
70
70
  */
71
71
  export declare function getKnownPropertyNames<Key extends PropertyKey>(object: Partial<Record<Key, any>>): Key[];
72
- export declare type PlainObject = Record<number | string | symbol, unknown>;
72
+ export type PlainObject = Record<number | string | symbol, unknown>;
73
73
  /**
74
74
  * Predefined sizes (in Bytes) of specific parts of JSON structure.
75
75
  */
@@ -116,4 +116,4 @@ export declare function calculateStringSize(value: string): number;
116
116
  * @returns Number of bytes used to store whole number in JSON.
117
117
  */
118
118
  export declare function calculateNumberSize(value: number): number;
119
- //# sourceMappingURL=misc.d.ts.map
119
+ //# sourceMappingURL=misc.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"misc.d.cts","sourceRoot":"","sources":["../src/misc.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,MAAM,OAAO,CACjB,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3C,SAAS,SAAS,MAAM,WAAW,IACjC;IACF,CAAC,UAAU,GAAG,IAAI,MAAM,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC;CACxE,GAAG;KACD,GAAG,IAAI,MAAM,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC;CAC9D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAEvE;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAMzD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EACrC,KAAK,EAAE,OAAO,EAAE,GACf,KAAK,IAAI,aAAa,CAAC,OAAO,CAAC,CAEjC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,SAAS,CAE3E;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAE/D;AAMD;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,2OAW8B,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,SAAS,WAAW,EAC3D,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAChC,GAAG,EAAE,CAEP;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpE;;GAEG;AACH,oBAAY,QAAQ;IAClB,IAAI,IAAI;IACR,KAAK,IAAI;IACT,OAAO,IAAI;IACX,IAAI,IAAI;IACR,KAAK,IAAI;IACT,KAAK,IAAI;IACT,KAAK,IAAI;IAET,IAAI,KAAK;CACV;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB,QAAoB,CAAC;AAE1D;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAelE;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,WAExC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUzD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzD"}