@metamask/utils 8.3.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 +26 -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} +33 -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 -39
  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 -292
  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 -312
  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} +12 -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 +28 -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 -40
  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-4NIRTM4M.js +0 -23
  204. package/dist/chunk-4NIRTM4M.js.map +0 -1
  205. package/dist/chunk-4RMX5YWE.js +0 -34
  206. package/dist/chunk-4RMX5YWE.js.map +0 -1
  207. package/dist/chunk-52OU772R.mjs +0 -122
  208. package/dist/chunk-52OU772R.mjs.map +0 -1
  209. package/dist/chunk-5AVWINSB.js +0 -1
  210. package/dist/chunk-5AVWINSB.js.map +0 -1
  211. package/dist/chunk-622IOGVI.mjs +0 -1
  212. package/dist/chunk-622IOGVI.mjs.map +0 -1
  213. package/dist/chunk-6C35XQOF.mjs +0 -257
  214. package/dist/chunk-6C35XQOF.mjs.map +0 -1
  215. package/dist/chunk-6NZW4WK4.js +0 -35
  216. package/dist/chunk-6NZW4WK4.js.map +0 -1
  217. package/dist/chunk-6ZDHSOUV.js +0 -59
  218. package/dist/chunk-6ZDHSOUV.js.map +0 -1
  219. package/dist/chunk-74DGVJVE.mjs +0 -59
  220. package/dist/chunk-74DGVJVE.mjs.map +0 -1
  221. package/dist/chunk-AY6FDCBT.mjs +0 -1
  222. package/dist/chunk-AY6FDCBT.mjs.map +0 -1
  223. package/dist/chunk-B7LIM2PK.mjs +0 -23
  224. package/dist/chunk-B7LIM2PK.mjs.map +0 -1
  225. package/dist/chunk-BFQDMI3M.js +0 -122
  226. package/dist/chunk-BFQDMI3M.js.map +0 -1
  227. package/dist/chunk-DHVKFDHQ.js +0 -95
  228. package/dist/chunk-DHVKFDHQ.js.map +0 -1
  229. package/dist/chunk-E4C7EW4R.js +0 -16
  230. package/dist/chunk-E4C7EW4R.js.map +0 -1
  231. package/dist/chunk-EQMZL4XU.js +0 -1
  232. package/dist/chunk-EQMZL4XU.js.map +0 -1
  233. package/dist/chunk-GZS3IQBZ.mjs +0 -16
  234. package/dist/chunk-GZS3IQBZ.mjs.map +0 -1
  235. package/dist/chunk-H4YFDLB7.mjs +0 -70
  236. package/dist/chunk-H4YFDLB7.mjs.map +0 -1
  237. package/dist/chunk-I575FZFH.mjs +0 -1
  238. package/dist/chunk-I575FZFH.mjs.map +0 -1
  239. package/dist/chunk-IZC266HS.js +0 -55
  240. package/dist/chunk-IZC266HS.js.map +0 -1
  241. package/dist/chunk-JPAL7Q5S.mjs +0 -90
  242. package/dist/chunk-JPAL7Q5S.mjs.map +0 -1
  243. package/dist/chunk-LC2CRSWD.js +0 -1
  244. package/dist/chunk-LC2CRSWD.js.map +0 -1
  245. package/dist/chunk-NQMRFZHB.mjs +0 -35
  246. package/dist/chunk-NQMRFZHB.mjs.map +0 -1
  247. package/dist/chunk-O3EIM33O.mjs +0 -95
  248. package/dist/chunk-O3EIM33O.mjs.map +0 -1
  249. package/dist/chunk-OLLG4H35.js +0 -257
  250. package/dist/chunk-OLLG4H35.js.map +0 -1
  251. package/dist/chunk-QEPVHEP7.js +0 -273
  252. package/dist/chunk-QVEKZRZ2.js +0 -70
  253. package/dist/chunk-QVEKZRZ2.js.map +0 -1
  254. package/dist/chunk-RIRDOQPX.mjs +0 -15
  255. package/dist/chunk-RIRDOQPX.mjs.map +0 -1
  256. package/dist/chunk-RKRGAFXY.js +0 -1
  257. package/dist/chunk-RKRGAFXY.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-TGOMTREC.mjs +0 -75
  265. package/dist/chunk-TGOMTREC.mjs.map +0 -1
  266. package/dist/chunk-THNLGEXV.mjs +0 -34
  267. package/dist/chunk-THNLGEXV.mjs.map +0 -1
  268. package/dist/chunk-U7ZUGCE7.js +0 -75
  269. package/dist/chunk-U7ZUGCE7.js.map +0 -1
  270. package/dist/chunk-UOTVU7OQ.js +0 -1
  271. package/dist/chunk-UOTVU7OQ.js.map +0 -1
  272. package/dist/chunk-VA2DRBDE.mjs +0 -273
  273. package/dist/chunk-VA2DRBDE.mjs.map +0 -1
  274. package/dist/chunk-VFXTVNXN.js +0 -44
  275. package/dist/chunk-VFXTVNXN.js.map +0 -1
  276. package/dist/chunk-WA4DHIND.mjs +0 -1
  277. package/dist/chunk-WA4DHIND.mjs.map +0 -1
  278. package/dist/chunk-X66SUIEF.mjs +0 -25
  279. package/dist/chunk-X66SUIEF.mjs.map +0 -1
  280. package/dist/chunk-XYGUOY6N.mjs +0 -55
  281. package/dist/chunk-XYGUOY6N.mjs.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 -293
  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 -313
  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
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/time.ts"],"sourcesContent":["/**\n * Common duration constants, in milliseconds.\n */\nexport enum Duration {\n /**\n * A millisecond.\n */\n Millisecond = 1,\n\n /**\n * A second, in milliseconds.\n */\n Second = 1000, // Millisecond * 1000\n\n /**\n * A minute, in milliseconds.\n */\n Minute = 60_000, // Second * 60\n\n /**\n * An hour, in milliseconds.\n */\n Hour = 3_600_000, // Minute * 60\n\n /**\n * A day, in milliseconds.\n */\n Day = 86_400_000, // Hour * 24\n\n /**\n * A week, in milliseconds.\n */\n Week = 604_800_000, // Day * 7\n\n /**\n * A year, in milliseconds.\n */\n Year = 31_536_000_000, // Day * 365\n}\n\nconst isNonNegativeInteger = (number: number) =>\n Number.isInteger(number) && number >= 0;\n\nconst assertIsNonNegativeInteger = (number: number, name: string) => {\n if (!isNonNegativeInteger(number)) {\n throw new Error(\n `\"${name}\" must be a non-negative integer. Received: \"${number}\".`,\n );\n }\n};\n\n/**\n * Calculates the millisecond value of the specified number of units of time.\n *\n * @param count - The number of units of time.\n * @param duration - The unit of time to count.\n * @returns The count multiplied by the specified duration.\n */\nexport function inMilliseconds(count: number, duration: Duration): number {\n assertIsNonNegativeInteger(count, 'count');\n return count * duration;\n}\n\n/**\n * Gets the milliseconds since a particular Unix epoch timestamp.\n *\n * @param timestamp - A Unix millisecond timestamp.\n * @returns The number of milliseconds elapsed since the specified timestamp.\n */\nexport function timeSince(timestamp: number): number {\n assertIsNonNegativeInteger(timestamp, 'timestamp');\n return Date.now() - timestamp;\n}\n"],"mappings":";AAGO,IAAK,WAAL,kBAAKA,cAAL;AAIL,EAAAA,oBAAA,iBAAc,KAAd;AAKA,EAAAA,oBAAA,YAAS,OAAT;AAKA,EAAAA,oBAAA,YAAS,OAAT;AAKA,EAAAA,oBAAA,UAAO,QAAP;AAKA,EAAAA,oBAAA,SAAM,SAAN;AAKA,EAAAA,oBAAA,UAAO,UAAP;AAKA,EAAAA,oBAAA,UAAO,WAAP;AAlCU,SAAAA;AAAA,GAAA;AAqCZ,IAAM,uBAAuB,CAAC,WAC5B,OAAO,UAAU,MAAM,KAAK,UAAU;AAExC,IAAM,6BAA6B,CAAC,QAAgB,SAAiB;AACnE,MAAI,CAAC,qBAAqB,MAAM,GAAG;AACjC,UAAM,IAAI;AAAA,MACR,IAAI,IAAI,gDAAgD,MAAM;AAAA,IAChE;AAAA,EACF;AACF;AASO,SAAS,eAAe,OAAe,UAA4B;AACxE,6BAA2B,OAAO,OAAO;AACzC,SAAO,QAAQ;AACjB;AAQO,SAAS,UAAU,WAA2B;AACnD,6BAA2B,WAAW,WAAW;AACjD,SAAO,KAAK,IAAI,IAAI;AACtB;","names":["Duration"]}
@@ -1,75 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/caip-types.ts
2
- var _superstruct = require('superstruct');
3
- var CAIP_CHAIN_ID_REGEX = /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;
4
- var CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;
5
- var CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;
6
- var CAIP_ACCOUNT_ID_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$/u;
7
- var CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;
8
- var CaipChainIdStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), CAIP_CHAIN_ID_REGEX);
9
- var CaipNamespaceStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), CAIP_NAMESPACE_REGEX);
10
- var CaipReferenceStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), CAIP_REFERENCE_REGEX);
11
- var CaipAccountIdStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), CAIP_ACCOUNT_ID_REGEX);
12
- var CaipAccountAddressStruct = _superstruct.pattern.call(void 0,
13
- _superstruct.string.call(void 0, ),
14
- CAIP_ACCOUNT_ADDRESS_REGEX
15
- );
16
- function isCaipChainId(value) {
17
- return _superstruct.is.call(void 0, value, CaipChainIdStruct);
18
- }
19
- function isCaipNamespace(value) {
20
- return _superstruct.is.call(void 0, value, CaipNamespaceStruct);
21
- }
22
- function isCaipReference(value) {
23
- return _superstruct.is.call(void 0, value, CaipReferenceStruct);
24
- }
25
- function isCaipAccountId(value) {
26
- return _superstruct.is.call(void 0, value, CaipAccountIdStruct);
27
- }
28
- function isCaipAccountAddress(value) {
29
- return _superstruct.is.call(void 0, value, CaipAccountAddressStruct);
30
- }
31
- function parseCaipChainId(caipChainId) {
32
- const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);
33
- if (!_optionalChain([match, 'optionalAccess', _ => _.groups])) {
34
- throw new Error("Invalid CAIP chain ID.");
35
- }
36
- return {
37
- namespace: match.groups.namespace,
38
- reference: match.groups.reference
39
- };
40
- }
41
- function parseCaipAccountId(caipAccountId) {
42
- const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);
43
- if (!_optionalChain([match, 'optionalAccess', _2 => _2.groups])) {
44
- throw new Error("Invalid CAIP account ID.");
45
- }
46
- return {
47
- address: match.groups.accountAddress,
48
- chainId: match.groups.chainId,
49
- chain: {
50
- namespace: match.groups.namespace,
51
- reference: match.groups.reference
52
- }
53
- };
54
- }
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
- exports.CAIP_CHAIN_ID_REGEX = CAIP_CHAIN_ID_REGEX; exports.CAIP_NAMESPACE_REGEX = CAIP_NAMESPACE_REGEX; exports.CAIP_REFERENCE_REGEX = CAIP_REFERENCE_REGEX; exports.CAIP_ACCOUNT_ID_REGEX = CAIP_ACCOUNT_ID_REGEX; exports.CAIP_ACCOUNT_ADDRESS_REGEX = CAIP_ACCOUNT_ADDRESS_REGEX; exports.CaipChainIdStruct = CaipChainIdStruct; exports.CaipNamespaceStruct = CaipNamespaceStruct; exports.CaipReferenceStruct = CaipReferenceStruct; exports.CaipAccountIdStruct = CaipAccountIdStruct; exports.CaipAccountAddressStruct = CaipAccountAddressStruct; exports.isCaipChainId = isCaipChainId; exports.isCaipNamespace = isCaipNamespace; exports.isCaipReference = isCaipReference; exports.isCaipAccountId = isCaipAccountId; exports.isCaipAccountAddress = isCaipAccountAddress; exports.parseCaipChainId = parseCaipChainId; exports.parseCaipAccountId = parseCaipAccountId;
75
- //# sourceMappingURL=chunk-U7ZUGCE7.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/caip-types.ts"],"names":[],"mappings":";AACA,SAAS,IAAI,SAAS,cAAc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sourcesContent":["import type { Infer } from 'superstruct';\nimport { is, pattern, string } from 'superstruct';\n\nexport const CAIP_CHAIN_ID_REGEX =\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;\n\nexport const CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;\n\nexport const CAIP_ACCOUNT_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})):(?<accountAddress>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ACCOUNT_ADDRESS_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const CaipChainIdStruct = pattern(string(), CAIP_CHAIN_ID_REGEX);\nexport type CaipChainId = `${string}:${string}`;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.\n */\nexport const CaipNamespaceStruct = pattern(string(), CAIP_NAMESPACE_REGEX);\nexport type CaipNamespace = Infer<typeof CaipNamespaceStruct>;\n\n/**\n * A CAIP-2 reference, i.e., the second part of a CAIP chain ID.\n */\nexport const CaipReferenceStruct = pattern(string(), CAIP_REFERENCE_REGEX);\nexport type CaipReference = Infer<typeof CaipReferenceStruct>;\n\n/**\n * A CAIP-10 account ID, i.e., a human-readable namespace, reference, and account address.\n */\nexport const CaipAccountIdStruct = pattern(string(), CAIP_ACCOUNT_ID_REGEX);\nexport type CaipAccountId = `${string}:${string}:${string}`;\n\n/**\n * A CAIP-10 account address, i.e., the third part of the CAIP account ID.\n */\nexport const CaipAccountAddressStruct = pattern(\n string(),\n CAIP_ACCOUNT_ADDRESS_REGEX,\n);\nexport type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;\n\n/**\n * Check if the given value is a {@link CaipChainId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipChainId}.\n */\nexport function isCaipChainId(value: unknown): value is CaipChainId {\n return is(value, CaipChainIdStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipNamespace}.\n */\nexport function isCaipNamespace(value: unknown): value is CaipNamespace {\n return is(value, CaipNamespaceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipReference}.\n */\nexport function isCaipReference(value: unknown): value is CaipReference {\n return is(value, CaipReferenceStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAccountId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAccountId}.\n */\nexport function isCaipAccountId(value: unknown): value is CaipAccountId {\n return is(value, CaipAccountIdStruct);\n}\n\n/**\n * Check if a value is a {@link CaipAccountAddress}.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid {@link CaipAccountAddress}.\n */\nexport function isCaipAccountAddress(\n value: unknown,\n): value is CaipAccountAddress {\n return is(value, CaipAccountAddressStruct);\n}\n\n/**\n * Parse a CAIP-2 chain ID to an object containing the namespace and reference.\n * This validates the CAIP-2 chain ID before parsing it.\n *\n * @param caipChainId - The CAIP-2 chain ID to validate and parse.\n * @returns The parsed CAIP-2 chain ID.\n */\nexport function parseCaipChainId(caipChainId: CaipChainId): {\n namespace: CaipNamespace;\n reference: CaipReference;\n} {\n const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP chain ID.');\n }\n\n return {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n };\n}\n\n/**\n * Parse an CAIP-10 account ID to an object containing the chain ID, parsed chain ID, and account address.\n * This validates the CAIP-10 account ID before parsing it.\n *\n * @param caipAccountId - The CAIP-10 account ID to validate and parse.\n * @returns The parsed CAIP-10 account ID.\n */\nexport function parseCaipAccountId(caipAccountId: CaipAccountId): {\n address: CaipAccountAddress;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ACCOUNT_ID_REGEX.exec(caipAccountId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP account ID.');\n }\n\n return {\n address: match.groups.accountAddress as CaipAccountAddress,\n chainId: match.groups.chainId as CaipChainId,\n chain: {\n namespace: match.groups.namespace as CaipNamespace,\n reference: match.groups.reference as CaipReference,\n },\n };\n}\n"]}
@@ -1 +0,0 @@
1
- "use strict";//# sourceMappingURL=chunk-UOTVU7OQ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
@@ -1,273 +0,0 @@
1
- import {
2
- assert
3
- } from "./chunk-74DGVJVE.mjs";
4
-
5
- // src/hex.ts
6
- import { keccak_256 as keccak256 } from "@noble/hashes/sha3";
7
- import { is, pattern, string } from "superstruct";
8
-
9
- // src/bytes.ts
10
- import { base64 } from "@scure/base";
11
- var HEX_MINIMUM_NUMBER_CHARACTER = 48;
12
- var HEX_MAXIMUM_NUMBER_CHARACTER = 58;
13
- var HEX_CHARACTER_OFFSET = 87;
14
- function getPrecomputedHexValuesBuilder() {
15
- const lookupTable = [];
16
- return () => {
17
- if (lookupTable.length === 0) {
18
- for (let i = 0; i < 256; i++) {
19
- lookupTable.push(i.toString(16).padStart(2, "0"));
20
- }
21
- }
22
- return lookupTable;
23
- };
24
- }
25
- var getPrecomputedHexValues = getPrecomputedHexValuesBuilder();
26
- function isBytes(value) {
27
- return value instanceof Uint8Array;
28
- }
29
- function assertIsBytes(value) {
30
- assert(isBytes(value), "Value must be a Uint8Array.");
31
- }
32
- function bytesToHex(bytes) {
33
- assertIsBytes(bytes);
34
- if (bytes.length === 0) {
35
- return "0x";
36
- }
37
- const lookupTable = getPrecomputedHexValues();
38
- const hexadecimal = new Array(bytes.length);
39
- for (let i = 0; i < bytes.length; i++) {
40
- hexadecimal[i] = lookupTable[bytes[i]];
41
- }
42
- return add0x(hexadecimal.join(""));
43
- }
44
- function bytesToBigInt(bytes) {
45
- assertIsBytes(bytes);
46
- const hexadecimal = bytesToHex(bytes);
47
- return BigInt(hexadecimal);
48
- }
49
- function bytesToSignedBigInt(bytes) {
50
- assertIsBytes(bytes);
51
- let value = BigInt(0);
52
- for (const byte of bytes) {
53
- value = (value << BigInt(8)) + BigInt(byte);
54
- }
55
- return BigInt.asIntN(bytes.length * 8, value);
56
- }
57
- function bytesToNumber(bytes) {
58
- assertIsBytes(bytes);
59
- const bigint = bytesToBigInt(bytes);
60
- assert(
61
- bigint <= BigInt(Number.MAX_SAFE_INTEGER),
62
- "Number is not a safe integer. Use `bytesToBigInt` instead."
63
- );
64
- return Number(bigint);
65
- }
66
- function bytesToString(bytes) {
67
- assertIsBytes(bytes);
68
- return new TextDecoder().decode(bytes);
69
- }
70
- function bytesToBase64(bytes) {
71
- assertIsBytes(bytes);
72
- return base64.encode(bytes);
73
- }
74
- function hexToBytes(value) {
75
- if (value?.toLowerCase?.() === "0x") {
76
- return new Uint8Array();
77
- }
78
- assertIsHexString(value);
79
- const strippedValue = remove0x(value).toLowerCase();
80
- const normalizedValue = strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;
81
- const bytes = new Uint8Array(normalizedValue.length / 2);
82
- for (let i = 0; i < bytes.length; i++) {
83
- const c1 = normalizedValue.charCodeAt(i * 2);
84
- const c2 = normalizedValue.charCodeAt(i * 2 + 1);
85
- const n1 = c1 - (c1 < HEX_MAXIMUM_NUMBER_CHARACTER ? HEX_MINIMUM_NUMBER_CHARACTER : HEX_CHARACTER_OFFSET);
86
- const n2 = c2 - (c2 < HEX_MAXIMUM_NUMBER_CHARACTER ? HEX_MINIMUM_NUMBER_CHARACTER : HEX_CHARACTER_OFFSET);
87
- bytes[i] = n1 * 16 + n2;
88
- }
89
- return bytes;
90
- }
91
- function bigIntToBytes(value) {
92
- assert(typeof value === "bigint", "Value must be a bigint.");
93
- assert(value >= BigInt(0), "Value must be a non-negative bigint.");
94
- const hexadecimal = value.toString(16);
95
- return hexToBytes(hexadecimal);
96
- }
97
- function bigIntFits(value, bytes) {
98
- assert(bytes > 0);
99
- const mask = value >> BigInt(31);
100
- return !((~value & mask) + (value & ~mask) >> BigInt(bytes * 8 + ~0));
101
- }
102
- function signedBigIntToBytes(value, byteLength) {
103
- assert(typeof value === "bigint", "Value must be a bigint.");
104
- assert(typeof byteLength === "number", "Byte length must be a number.");
105
- assert(byteLength > 0, "Byte length must be greater than 0.");
106
- assert(
107
- bigIntFits(value, byteLength),
108
- "Byte length is too small to represent the given value."
109
- );
110
- let numberValue = value;
111
- const bytes = new Uint8Array(byteLength);
112
- for (let i = 0; i < bytes.length; i++) {
113
- bytes[i] = Number(BigInt.asUintN(8, numberValue));
114
- numberValue >>= BigInt(8);
115
- }
116
- return bytes.reverse();
117
- }
118
- function numberToBytes(value) {
119
- assert(typeof value === "number", "Value must be a number.");
120
- assert(value >= 0, "Value must be a non-negative number.");
121
- assert(
122
- Number.isSafeInteger(value),
123
- "Value is not a safe integer. Use `bigIntToBytes` instead."
124
- );
125
- const hexadecimal = value.toString(16);
126
- return hexToBytes(hexadecimal);
127
- }
128
- function stringToBytes(value) {
129
- assert(typeof value === "string", "Value must be a string.");
130
- return new TextEncoder().encode(value);
131
- }
132
- function base64ToBytes(value) {
133
- assert(typeof value === "string", "Value must be a string.");
134
- return base64.decode(value);
135
- }
136
- function valueToBytes(value) {
137
- if (typeof value === "bigint") {
138
- return bigIntToBytes(value);
139
- }
140
- if (typeof value === "number") {
141
- return numberToBytes(value);
142
- }
143
- if (typeof value === "string") {
144
- if (value.startsWith("0x")) {
145
- return hexToBytes(value);
146
- }
147
- return stringToBytes(value);
148
- }
149
- if (isBytes(value)) {
150
- return value;
151
- }
152
- throw new TypeError(`Unsupported value type: "${typeof value}".`);
153
- }
154
- function concatBytes(values) {
155
- const normalizedValues = new Array(values.length);
156
- let byteLength = 0;
157
- for (let i = 0; i < values.length; i++) {
158
- const value = valueToBytes(values[i]);
159
- normalizedValues[i] = value;
160
- byteLength += value.length;
161
- }
162
- const bytes = new Uint8Array(byteLength);
163
- for (let i = 0, offset = 0; i < normalizedValues.length; i++) {
164
- bytes.set(normalizedValues[i], offset);
165
- offset += normalizedValues[i].length;
166
- }
167
- return bytes;
168
- }
169
- function createDataView(bytes) {
170
- if (typeof Buffer !== "undefined" && bytes instanceof Buffer) {
171
- const buffer = bytes.buffer.slice(
172
- bytes.byteOffset,
173
- bytes.byteOffset + bytes.byteLength
174
- );
175
- return new DataView(buffer);
176
- }
177
- return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
178
- }
179
-
180
- // src/hex.ts
181
- var HexStruct = pattern(string(), /^(?:0x)?[0-9a-f]+$/iu);
182
- var StrictHexStruct = pattern(string(), /^0x[0-9a-f]+$/iu);
183
- var HexAddressStruct = pattern(
184
- string(),
185
- /^0x[0-9a-f]{40}$/u
186
- );
187
- var HexChecksumAddressStruct = pattern(
188
- string(),
189
- /^0x[0-9a-fA-F]{40}$/u
190
- );
191
- function isHexString(value) {
192
- return is(value, HexStruct);
193
- }
194
- function isStrictHexString(value) {
195
- return is(value, StrictHexStruct);
196
- }
197
- function assertIsHexString(value) {
198
- assert(isHexString(value), "Value must be a hexadecimal string.");
199
- }
200
- function assertIsStrictHexString(value) {
201
- assert(
202
- isStrictHexString(value),
203
- 'Value must be a hexadecimal string, starting with "0x".'
204
- );
205
- }
206
- function isValidHexAddress(possibleAddress) {
207
- return is(possibleAddress, HexAddressStruct) || isValidChecksumAddress(possibleAddress);
208
- }
209
- function getChecksumAddress(address) {
210
- assert(is(address, HexChecksumAddressStruct), "Invalid hex address.");
211
- const unPrefixed = remove0x(address.toLowerCase());
212
- const unPrefixedHash = remove0x(bytesToHex(keccak256(unPrefixed)));
213
- return `0x${unPrefixed.split("").map((character, nibbleIndex) => {
214
- const hashCharacter = unPrefixedHash[nibbleIndex];
215
- assert(is(hashCharacter, string()), "Hash shorter than address.");
216
- return parseInt(hashCharacter, 16) > 7 ? character.toUpperCase() : character;
217
- }).join("")}`;
218
- }
219
- function isValidChecksumAddress(possibleChecksum) {
220
- if (!is(possibleChecksum, HexChecksumAddressStruct)) {
221
- return false;
222
- }
223
- return getChecksumAddress(possibleChecksum) === possibleChecksum;
224
- }
225
- function add0x(hexadecimal) {
226
- if (hexadecimal.startsWith("0x")) {
227
- return hexadecimal;
228
- }
229
- if (hexadecimal.startsWith("0X")) {
230
- return `0x${hexadecimal.substring(2)}`;
231
- }
232
- return `0x${hexadecimal}`;
233
- }
234
- function remove0x(hexadecimal) {
235
- if (hexadecimal.startsWith("0x") || hexadecimal.startsWith("0X")) {
236
- return hexadecimal.substring(2);
237
- }
238
- return hexadecimal;
239
- }
240
-
241
- export {
242
- HexStruct,
243
- StrictHexStruct,
244
- HexAddressStruct,
245
- HexChecksumAddressStruct,
246
- isHexString,
247
- isStrictHexString,
248
- assertIsHexString,
249
- assertIsStrictHexString,
250
- isValidHexAddress,
251
- getChecksumAddress,
252
- isValidChecksumAddress,
253
- add0x,
254
- remove0x,
255
- isBytes,
256
- assertIsBytes,
257
- bytesToHex,
258
- bytesToBigInt,
259
- bytesToSignedBigInt,
260
- bytesToNumber,
261
- bytesToString,
262
- bytesToBase64,
263
- hexToBytes,
264
- bigIntToBytes,
265
- signedBigIntToBytes,
266
- numberToBytes,
267
- stringToBytes,
268
- base64ToBytes,
269
- valueToBytes,
270
- concatBytes,
271
- createDataView
272
- };
273
- //# sourceMappingURL=chunk-VA2DRBDE.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hex.ts","../src/bytes.ts"],"sourcesContent":["import { keccak_256 as keccak256 } from '@noble/hashes/sha3';\nimport type { Struct } from 'superstruct';\nimport { is, pattern, string } from 'superstruct';\n\nimport { assert } from './assert';\nimport { bytesToHex } from './bytes';\n\nexport type Hex = `0x${string}`;\n\nexport const HexStruct = pattern(string(), /^(?:0x)?[0-9a-f]+$/iu);\nexport const StrictHexStruct = pattern(string(), /^0x[0-9a-f]+$/iu) as Struct<\n Hex,\n null\n>;\nexport const HexAddressStruct = pattern(\n string(),\n /^0x[0-9a-f]{40}$/u,\n) as Struct<Hex, null>;\nexport const HexChecksumAddressStruct = pattern(\n string(),\n /^0x[0-9a-fA-F]{40}$/u,\n) as Struct<Hex, null>;\n\n/**\n * Check if a string is a valid hex string.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isHexString(value: unknown): value is string {\n return is(value, HexStruct);\n}\n\n/**\n * Strictly check if a string is a valid hex string. A valid hex string must\n * start with the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isStrictHexString(value: unknown): value is Hex {\n return is(value, StrictHexStruct);\n}\n\n/**\n * Assert that a value is a valid hex string.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsHexString(value: unknown): asserts value is string {\n assert(isHexString(value), 'Value must be a hexadecimal string.');\n}\n\n/**\n * Assert that a value is a valid hex string. A valid hex string must start with\n * the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsStrictHexString(value: unknown): asserts value is Hex {\n assert(\n isStrictHexString(value),\n 'Value must be a hexadecimal string, starting with \"0x\".',\n );\n}\n\n/**\n * Validate that the passed prefixed hex string is an all-lowercase\n * hex address, or a valid mixed-case checksum address.\n *\n * @param possibleAddress - Input parameter to check against.\n * @returns Whether or not the input is a valid hex address.\n */\nexport function isValidHexAddress(possibleAddress: Hex) {\n return (\n is(possibleAddress, HexAddressStruct) ||\n isValidChecksumAddress(possibleAddress)\n );\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n *\n * @param address - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport function getChecksumAddress(address: Hex) {\n assert(is(address, HexChecksumAddressStruct), 'Invalid hex address.');\n const unPrefixed = remove0x(address.toLowerCase());\n const unPrefixedHash = remove0x(bytesToHex(keccak256(unPrefixed)));\n return `0x${unPrefixed\n .split('')\n .map((character, nibbleIndex) => {\n const hashCharacter = unPrefixedHash[nibbleIndex];\n assert(is(hashCharacter, string()), 'Hash shorter than address.');\n return parseInt(hashCharacter, 16) > 7\n ? character.toUpperCase()\n : character;\n })\n .join('')}`;\n}\n\n/**\n * Validate that the passed hex string is a valid ERC-55 mixed-case\n * checksum address.\n *\n * @param possibleChecksum - The hex address to check.\n * @returns True if the address is a checksum address.\n */\nexport function isValidChecksumAddress(possibleChecksum: Hex) {\n if (!is(possibleChecksum, HexChecksumAddressStruct)) {\n return false;\n }\n\n return getChecksumAddress(possibleChecksum) === possibleChecksum;\n}\n\n/**\n * Add the `0x`-prefix to a hexadecimal string. If the string already has the\n * prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to add the prefix to.\n * @returns The prefixed hexadecimal string.\n */\nexport function add0x(hexadecimal: string): Hex {\n if (hexadecimal.startsWith('0x')) {\n return hexadecimal as Hex;\n }\n\n if (hexadecimal.startsWith('0X')) {\n return `0x${hexadecimal.substring(2)}`;\n }\n\n return `0x${hexadecimal}`;\n}\n\n/**\n * Remove the `0x`-prefix from a hexadecimal string. If the string doesn't have\n * the prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to remove the prefix from.\n * @returns The un-prefixed hexadecimal string.\n */\nexport function remove0x(hexadecimal: string): string {\n if (hexadecimal.startsWith('0x') || hexadecimal.startsWith('0X')) {\n return hexadecimal.substring(2);\n }\n\n return hexadecimal;\n}\n","import { base64 } from '@scure/base';\n\nimport { assert } from './assert';\nimport type { Hex } from './hex';\nimport { add0x, assertIsHexString, remove0x } from './hex';\n\n// '0'.charCodeAt(0) === 48\nconst HEX_MINIMUM_NUMBER_CHARACTER = 48;\n\n// '9'.charCodeAt(0) === 57\nconst HEX_MAXIMUM_NUMBER_CHARACTER = 58;\nconst HEX_CHARACTER_OFFSET = 87;\n\nexport type Bytes = bigint | number | string | Uint8Array;\n\n/**\n * Memoized function that returns an array to be used as a lookup table for\n * converting bytes to hexadecimal values.\n *\n * The array is created lazily and then cached for future use. The benefit of\n * this approach is that the performance of converting bytes to hex is much\n * better than if we were to call `toString(16)` on each byte.\n *\n * The downside is that the array is created once and then never garbage\n * collected. This is not a problem in practice because the array is only 256\n * elements long.\n *\n * @returns A function that returns the lookup table.\n */\nfunction getPrecomputedHexValuesBuilder(): () => string[] {\n // To avoid issues with tree shaking, we need to use a function to return the\n // array. This is because the array is only used in the `bytesToHex` function\n // and if we were to use a global variable, the array might be removed by the\n // tree shaker.\n const lookupTable: string[] = [];\n\n return () => {\n if (lookupTable.length === 0) {\n for (let i = 0; i < 256; i++) {\n lookupTable.push(i.toString(16).padStart(2, '0'));\n }\n }\n\n return lookupTable;\n };\n}\n\n/**\n * Function implementation of the {@link getPrecomputedHexValuesBuilder}\n * function.\n */\nconst getPrecomputedHexValues = getPrecomputedHexValuesBuilder();\n\n/**\n * Check if a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @returns Whether the value is a `Uint8Array`.\n */\nexport function isBytes(value: unknown): value is Uint8Array {\n return value instanceof Uint8Array;\n}\n\n/**\n * Assert that a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @throws If the value is not a `Uint8Array`.\n */\nexport function assertIsBytes(value: unknown): asserts value is Uint8Array {\n assert(isBytes(value), 'Value must be a Uint8Array.');\n}\n\n/**\n * Convert a `Uint8Array` to a hexadecimal string.\n *\n * @param bytes - The bytes to convert to a hexadecimal string.\n * @returns The hexadecimal string.\n */\nexport function bytesToHex(bytes: Uint8Array): Hex {\n assertIsBytes(bytes);\n\n if (bytes.length === 0) {\n return '0x';\n }\n\n const lookupTable = getPrecomputedHexValues();\n const hexadecimal = new Array(bytes.length);\n\n for (let i = 0; i < bytes.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n hexadecimal[i] = lookupTable[bytes[i]!];\n }\n\n return add0x(hexadecimal.join(''));\n}\n\n/**\n * Convert a `Uint8Array` to a `bigint`.\n *\n * To convert a `Uint8Array` to a `number` instead, use {@link bytesToNumber}.\n * To convert a two's complement encoded `Uint8Array` to a `bigint`, use\n * {@link bytesToSignedBigInt}.\n *\n * @param bytes - The bytes to convert to a `bigint`.\n * @returns The `bigint`.\n */\nexport function bytesToBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n const hexadecimal = bytesToHex(bytes);\n return BigInt(hexadecimal);\n}\n\n/**\n * Convert a `Uint8Array` to a signed `bigint`. This assumes that the bytes are\n * encoded in two's complement.\n *\n * To convert a `Uint8Array` to an unsigned `bigint` instead, use\n * {@link bytesToBigInt}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param bytes - The bytes to convert to a signed `bigint`.\n * @returns The signed `bigint`.\n */\nexport function bytesToSignedBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n let value = BigInt(0);\n for (const byte of bytes) {\n // eslint-disable-next-line no-bitwise\n value = (value << BigInt(8)) + BigInt(byte);\n }\n\n return BigInt.asIntN(bytes.length * 8, value);\n}\n\n/**\n * Convert a `Uint8Array` to a `number`.\n *\n * To convert a `Uint8Array` to a `bigint` instead, use {@link bytesToBigInt}.\n *\n * @param bytes - The bytes to convert to a number.\n * @returns The number.\n * @throws If the resulting number is not a safe integer.\n */\nexport function bytesToNumber(bytes: Uint8Array): number {\n assertIsBytes(bytes);\n\n const bigint = bytesToBigInt(bytes);\n\n assert(\n bigint <= BigInt(Number.MAX_SAFE_INTEGER),\n 'Number is not a safe integer. Use `bytesToBigInt` instead.',\n );\n\n return Number(bigint);\n}\n\n/**\n * Convert a UTF-8 encoded `Uint8Array` to a `string`.\n *\n * @param bytes - The bytes to convert to a string.\n * @returns The string.\n */\nexport function bytesToString(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return new TextDecoder().decode(bytes);\n}\n\n/**\n * Convert a `Uint8Array` to a base64 encoded string.\n *\n * @param bytes - The bytes to convert to a base64 encoded string.\n * @returns The base64 encoded string.\n */\nexport function bytesToBase64(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return base64.encode(bytes);\n}\n\n/**\n * Convert a hexadecimal string to a `Uint8Array`. The string can optionally be\n * prefixed with `0x`. It accepts even and odd length strings.\n *\n * If the value is \"0x\", an empty `Uint8Array` is returned.\n *\n * @param value - The hexadecimal string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function hexToBytes(value: string): Uint8Array {\n // \"0x\" is often used as empty byte array.\n if (value?.toLowerCase?.() === '0x') {\n return new Uint8Array();\n }\n\n assertIsHexString(value);\n\n // Remove the `0x` prefix if it exists, and pad the string to have an even\n // number of characters.\n const strippedValue = remove0x(value).toLowerCase();\n const normalizedValue =\n strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;\n const bytes = new Uint8Array(normalizedValue.length / 2);\n\n for (let i = 0; i < bytes.length; i++) {\n // While this is not the prettiest way to convert a hexadecimal string to a\n // `Uint8Array`, it is a lot faster than using `parseInt` to convert each\n // character.\n const c1 = normalizedValue.charCodeAt(i * 2);\n const c2 = normalizedValue.charCodeAt(i * 2 + 1);\n const n1 =\n c1 -\n (c1 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n const n2 =\n c2 -\n (c2 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n\n bytes[i] = n1 * 16 + n2;\n }\n\n return bytes;\n}\n\n/**\n * Convert a `bigint` to a `Uint8Array`.\n *\n * This assumes that the `bigint` is an unsigned integer. To convert a signed\n * `bigint` instead, use {@link signedBigIntToBytes}.\n *\n * @param value - The bigint to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function bigIntToBytes(value: bigint): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= BigInt(0), 'Value must be a non-negative bigint.');\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Check if a `bigint` fits in a certain number of bytes.\n *\n * @param value - The `bigint` to check.\n * @param bytes - The number of bytes.\n * @returns Whether the `bigint` fits in the number of bytes.\n */\nfunction bigIntFits(value: bigint, bytes: number): boolean {\n assert(bytes > 0);\n\n /* eslint-disable no-bitwise */\n const mask = value >> BigInt(31);\n return !(((~value & mask) + (value & ~mask)) >> BigInt(bytes * 8 + ~0));\n /* eslint-enable no-bitwise */\n}\n\n/**\n * Convert a signed `bigint` to a `Uint8Array`. This uses two's complement\n * encoding to represent negative numbers.\n *\n * To convert an unsigned `bigint` to a `Uint8Array` instead, use\n * {@link bigIntToBytes}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param value - The number to convert to bytes.\n * @param byteLength - The length of the resulting `Uint8Array`. If the number\n * is larger than the maximum value that can be represented by the given length,\n * an error is thrown.\n * @returns The bytes as `Uint8Array`.\n */\nexport function signedBigIntToBytes(\n value: bigint,\n byteLength: number,\n): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(typeof byteLength === 'number', 'Byte length must be a number.');\n assert(byteLength > 0, 'Byte length must be greater than 0.');\n assert(\n bigIntFits(value, byteLength),\n 'Byte length is too small to represent the given value.',\n );\n\n // ESLint doesn't like mutating function parameters, so to avoid having to\n // disable the rule, we create a new variable.\n let numberValue = value;\n const bytes = new Uint8Array(byteLength);\n\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Number(BigInt.asUintN(8, numberValue));\n // eslint-disable-next-line no-bitwise\n numberValue >>= BigInt(8);\n }\n\n return bytes.reverse();\n}\n\n/**\n * Convert a `number` to a `Uint8Array`.\n *\n * @param value - The number to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n * @throws If the number is not a safe integer.\n */\nexport function numberToBytes(value: number): Uint8Array {\n assert(typeof value === 'number', 'Value must be a number.');\n assert(value >= 0, 'Value must be a non-negative number.');\n assert(\n Number.isSafeInteger(value),\n 'Value is not a safe integer. Use `bigIntToBytes` instead.',\n );\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Convert a `string` to a UTF-8 encoded `Uint8Array`.\n *\n * @param value - The string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function stringToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return new TextEncoder().encode(value);\n}\n\n/**\n * Convert a base64 encoded string to a `Uint8Array`.\n *\n * @param value - The base64 encoded string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function base64ToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return base64.decode(value);\n}\n\n/**\n * Convert a byte-like value to a `Uint8Array`. The value can be a `Uint8Array`,\n * a `bigint`, a `number`, or a `string`.\n *\n * This will attempt to guess the type of the value based on its type and\n * contents. For more control over the conversion, use the more specific\n * conversion functions, such as {@link hexToBytes} or {@link stringToBytes}.\n *\n * If the value is a `string`, and it is prefixed with `0x`, it will be\n * interpreted as a hexadecimal string. Otherwise, it will be interpreted as a\n * UTF-8 string. To convert a hexadecimal string to bytes without interpreting\n * it as a UTF-8 string, use {@link hexToBytes} instead.\n *\n * If the value is a `bigint`, it is assumed to be unsigned. To convert a signed\n * `bigint` to bytes, use {@link signedBigIntToBytes} instead.\n *\n * If the value is a `Uint8Array`, it will be returned as-is.\n *\n * @param value - The value to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function valueToBytes(value: Bytes): Uint8Array {\n if (typeof value === 'bigint') {\n return bigIntToBytes(value);\n }\n\n if (typeof value === 'number') {\n return numberToBytes(value);\n }\n\n if (typeof value === 'string') {\n if (value.startsWith('0x')) {\n return hexToBytes(value);\n }\n\n return stringToBytes(value);\n }\n\n if (isBytes(value)) {\n return value;\n }\n\n throw new TypeError(`Unsupported value type: \"${typeof value}\".`);\n}\n\n/**\n * Concatenate multiple byte-like values into a single `Uint8Array`. The values\n * can be `Uint8Array`, `bigint`, `number`, or `string`. This uses\n * {@link valueToBytes} under the hood to convert each value to bytes. Refer to\n * the documentation of that function for more information.\n *\n * @param values - The values to concatenate.\n * @returns The concatenated bytes as `Uint8Array`.\n */\nexport function concatBytes(values: Bytes[]): Uint8Array {\n const normalizedValues = new Array(values.length);\n let byteLength = 0;\n\n for (let i = 0; i < values.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = valueToBytes(values[i]!);\n\n normalizedValues[i] = value;\n byteLength += value.length;\n }\n\n const bytes = new Uint8Array(byteLength);\n for (let i = 0, offset = 0; i < normalizedValues.length; i++) {\n // While we could simply spread the values into an array and use\n // `Uint8Array.from`, that is a lot slower than using `Uint8Array.set`.\n bytes.set(normalizedValues[i], offset);\n offset += normalizedValues[i].length;\n }\n\n return bytes;\n}\n\n/**\n * Create a {@link DataView} from a {@link Uint8Array}. This is a convenience\n * function that avoids having to create a {@link DataView} manually, which\n * requires passing the `byteOffset` and `byteLength` parameters every time.\n *\n * Not passing the `byteOffset` and `byteLength` parameters can result in\n * unexpected behavior when the {@link Uint8Array} is a view of a larger\n * {@link ArrayBuffer}, e.g., when using {@link Uint8Array.subarray}.\n *\n * This function also supports Node.js {@link Buffer}s.\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([1, 2, 3]);\n *\n * // This is equivalent to:\n * // const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n * const dataView = createDataView(bytes);\n * ```\n * @param bytes - The bytes to create the {@link DataView} from.\n * @returns The {@link DataView}.\n */\nexport function createDataView(bytes: Uint8Array): DataView {\n // To maintain compatibility with Node.js, we need to check if the bytes are\n // a Buffer. If so, we need to slice the buffer to get the underlying\n // ArrayBuffer.\n // eslint-disable-next-line no-restricted-globals\n if (typeof Buffer !== 'undefined' && bytes instanceof Buffer) {\n const buffer = bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n );\n\n return new DataView(buffer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2
-
3
-
4
- var _chunkQEPVHEP7js = require('./chunk-QEPVHEP7.js');
5
-
6
-
7
- var _chunk6ZDHSOUVjs = require('./chunk-6ZDHSOUV.js');
8
-
9
- // src/number.ts
10
- var numberToHex = (value) => {
11
- _chunk6ZDHSOUVjs.assert.call(void 0, typeof value === "number", "Value must be a number.");
12
- _chunk6ZDHSOUVjs.assert.call(void 0, value >= 0, "Value must be a non-negative number.");
13
- _chunk6ZDHSOUVjs.assert.call(void 0,
14
- Number.isSafeInteger(value),
15
- "Value is not a safe integer. Use `bigIntToHex` instead."
16
- );
17
- return _chunkQEPVHEP7js.add0x.call(void 0, value.toString(16));
18
- };
19
- var bigIntToHex = (value) => {
20
- _chunk6ZDHSOUVjs.assert.call(void 0, typeof value === "bigint", "Value must be a bigint.");
21
- _chunk6ZDHSOUVjs.assert.call(void 0, value >= 0, "Value must be a non-negative bigint.");
22
- return _chunkQEPVHEP7js.add0x.call(void 0, value.toString(16));
23
- };
24
- var hexToNumber = (value) => {
25
- _chunkQEPVHEP7js.assertIsHexString.call(void 0, value);
26
- const numberValue = parseInt(value, 16);
27
- _chunk6ZDHSOUVjs.assert.call(void 0,
28
- Number.isSafeInteger(numberValue),
29
- "Value is not a safe integer. Use `hexToBigInt` instead."
30
- );
31
- return numberValue;
32
- };
33
- var hexToBigInt = (value) => {
34
- _chunkQEPVHEP7js.assertIsHexString.call(void 0, value);
35
- return BigInt(_chunkQEPVHEP7js.add0x.call(void 0, value));
36
- };
37
-
38
-
39
-
40
-
41
-
42
-
43
- exports.numberToHex = numberToHex; exports.bigIntToHex = bigIntToHex; exports.hexToNumber = hexToNumber; exports.hexToBigInt = hexToBigInt;
44
- //# sourceMappingURL=chunk-VFXTVNXN.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/number.ts"],"names":[],"mappings":";;;;;;;;;AAoBO,IAAM,cAAc,CAAC,UAA0B;AACpD,SAAO,OAAO,UAAU,UAAU,yBAAyB;AAC3D,SAAO,SAAS,GAAG,sCAAsC;AACzD;AAAA,IACE,OAAO,cAAc,KAAK;AAAA,IAC1B;AAAA,EACF;AAEA,SAAO,MAAM,MAAM,SAAS,EAAE,CAAC;AACjC;AAkBO,IAAM,cAAc,CAAC,UAA0B;AACpD,SAAO,OAAO,UAAU,UAAU,yBAAyB;AAC3D,SAAO,SAAS,GAAG,sCAAsC;AAEzD,SAAO,MAAM,MAAM,SAAS,EAAE,CAAC;AACjC;AAqBO,IAAM,cAAc,CAAC,UAA0B;AACpD,oBAAkB,KAAK;AAIvB,QAAM,cAAc,SAAS,OAAO,EAAE;AAEtC;AAAA,IACE,OAAO,cAAc,WAAW;AAAA,IAChC;AAAA,EACF;AAEA,SAAO;AACT;AAkBO,IAAM,cAAc,CAAC,UAA0B;AACpD,oBAAkB,KAAK;AAGvB,SAAO,OAAO,MAAM,KAAK,CAAC;AAC5B","sourcesContent":["import { assert } from './assert';\nimport { add0x, assertIsHexString } from './hex';\n\n/**\n * Convert a number to a hexadecimal string. This verifies that the number is a\n * non-negative safe integer.\n *\n * To convert a `bigint` to a hexadecimal string instead, use\n * {@link bigIntToHex}.\n *\n * @example\n * ```typescript\n * numberToHex(0); // '0x0'\n * numberToHex(1); // '0x1'\n * numberToHex(16); // '0x10'\n * ```\n * @param value - The number to convert to a hexadecimal string.\n * @returns The hexadecimal string, with the \"0x\"-prefix.\n * @throws If the number is not a non-negative safe integer.\n */\nexport const numberToHex = (value: number): string => {\n assert(typeof value === 'number', 'Value must be a number.');\n assert(value >= 0, 'Value must be a non-negative number.');\n assert(\n Number.isSafeInteger(value),\n 'Value is not a safe integer. Use `bigIntToHex` instead.',\n );\n\n return add0x(value.toString(16));\n};\n\n/**\n * Convert a `bigint` to a hexadecimal string. This verifies that the `bigint`\n * is a non-negative integer.\n *\n * To convert a number to a hexadecimal string instead, use {@link numberToHex}.\n *\n * @example\n * ```typescript\n * bigIntToHex(0n); // '0x0'\n * bigIntToHex(1n); // '0x1'\n * bigIntToHex(16n); // '0x10'\n * ```\n * @param value - The `bigint` to convert to a hexadecimal string.\n * @returns The hexadecimal string, with the \"0x\"-prefix.\n * @throws If the `bigint` is not a non-negative integer.\n */\nexport const bigIntToHex = (value: bigint): string => {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= 0, 'Value must be a non-negative bigint.');\n\n return add0x(value.toString(16));\n};\n\n/**\n * Convert a hexadecimal string to a number. This verifies that the string is a\n * valid hex string, and that the resulting number is a safe integer. Both\n * \"0x\"-prefixed and unprefixed strings are supported.\n *\n * To convert a hexadecimal string to a `bigint` instead, use\n * {@link hexToBigInt}.\n *\n * @example\n * ```typescript\n * hexToNumber('0x0'); // 0\n * hexToNumber('0x1'); // 1\n * hexToNumber('0x10'); // 16\n * ```\n * @param value - The hexadecimal string to convert to a number.\n * @returns The number.\n * @throws If the value is not a valid hexadecimal string, or if the resulting\n * number is not a safe integer.\n */\nexport const hexToNumber = (value: string): number => {\n assertIsHexString(value);\n\n // `parseInt` accepts values without the \"0x\"-prefix, whereas `Number` does\n // not. Using this is slightly faster than `Number(add0x(value))`.\n const numberValue = parseInt(value, 16);\n\n assert(\n Number.isSafeInteger(numberValue),\n 'Value is not a safe integer. Use `hexToBigInt` instead.',\n );\n\n return numberValue;\n};\n\n/**\n * Convert a hexadecimal string to a `bigint`. This verifies that the string is\n * a valid hex string. Both \"0x\"-prefixed and unprefixed strings are supported.\n *\n * To convert a hexadecimal string to a number instead, use {@link hexToNumber}.\n *\n * @example\n * ```typescript\n * hexToBigInt('0x0'); // 0n\n * hexToBigInt('0x1'); // 1n\n * hexToBigInt('0x10'); // 16n\n * ```\n * @param value - The hexadecimal string to convert to a `bigint`.\n * @returns The `bigint`.\n * @throws If the value is not a valid hexadecimal string.\n */\nexport const hexToBigInt = (value: string): bigint => {\n assertIsHexString(value);\n\n // The `BigInt` constructor requires the \"0x\"-prefix to parse a hex string.\n return BigInt(add0x(value));\n};\n"]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-WA4DHIND.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,25 +0,0 @@
1
- var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
4
- };
5
- var __privateGet = (obj, member, getter) => {
6
- __accessCheck(obj, member, "read from private field");
7
- return getter ? getter.call(obj) : member.get(obj);
8
- };
9
- var __privateAdd = (obj, member, value) => {
10
- if (member.has(obj))
11
- throw TypeError("Cannot add the same private member more than once");
12
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- };
14
- var __privateSet = (obj, member, value, setter) => {
15
- __accessCheck(obj, member, "write to private field");
16
- setter ? setter.call(obj, value) : member.set(obj, value);
17
- return value;
18
- };
19
-
20
- export {
21
- __privateGet,
22
- __privateAdd,
23
- __privateSet
24
- };
25
- //# sourceMappingURL=chunk-X66SUIEF.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,55 +0,0 @@
1
- import {
2
- isNullOrUndefined,
3
- isObject
4
- } from "./chunk-H4YFDLB7.mjs";
5
-
6
- // src/errors.ts
7
- import { ErrorWithCause } from "pony-cause";
8
- function isError(error) {
9
- return error instanceof Error || isObject(error) && error.constructor.name === "Error";
10
- }
11
- function isErrorWithCode(error) {
12
- return typeof error === "object" && error !== null && "code" in error;
13
- }
14
- function isErrorWithMessage(error) {
15
- return typeof error === "object" && error !== null && "message" in error;
16
- }
17
- function isErrorWithStack(error) {
18
- return typeof error === "object" && error !== null && "stack" in error;
19
- }
20
- function getErrorMessage(error) {
21
- if (isErrorWithMessage(error) && typeof error.message === "string") {
22
- return error.message;
23
- }
24
- if (isNullOrUndefined(error)) {
25
- return "";
26
- }
27
- return String(error);
28
- }
29
- function wrapError(originalError, message) {
30
- if (isError(originalError)) {
31
- let error;
32
- if (Error.length === 2) {
33
- error = new Error(message, { cause: originalError });
34
- } else {
35
- error = new ErrorWithCause(message, { cause: originalError });
36
- }
37
- if (isErrorWithCode(originalError)) {
38
- error.code = originalError.code;
39
- }
40
- return error;
41
- }
42
- if (message.length > 0) {
43
- return new Error(`${String(originalError)}: ${message}`);
44
- }
45
- return new Error(String(originalError));
46
- }
47
-
48
- export {
49
- isErrorWithCode,
50
- isErrorWithMessage,
51
- isErrorWithStack,
52
- getErrorMessage,
53
- wrapError
54
- };
55
- //# sourceMappingURL=chunk-XYGUOY6N.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/errors.ts"],"sourcesContent":["import { ErrorWithCause } from 'pony-cause';\n\nimport { isNullOrUndefined, isObject } from './misc';\n\n/**\n * Type guard for determining whether the given value is an instance of Error.\n * For errors generated via `fs.promises`, `error instanceof Error` won't work,\n * so we have to come up with another way of testing.\n *\n * @param error - The object to check.\n * @returns A boolean.\n */\nfunction isError(error: unknown): error is Error {\n return (\n error instanceof Error ||\n (isObject(error) && error.constructor.name === 'Error')\n );\n}\n\n/**\n * Type guard for determining whether the given value is an error object with a\n * `code` property such as the type of error that Node throws for filesystem\n * operations, etc.\n *\n * @param error - The object to check.\n * @returns A boolean.\n */\nexport function isErrorWithCode(error: unknown): error is { code: string } {\n return typeof error === 'object' && error !== null && 'code' in error;\n}\n\n/**\n * Type guard for determining whether the given value is an error object with a\n * `message` property, such as an instance of Error.\n *\n * @param error - The object to check.\n * @returns A boolean.\n */\nexport function isErrorWithMessage(\n error: unknown,\n): error is { message: string } {\n return typeof error === 'object' && error !== null && 'message' in error;\n}\n\n/**\n * Type guard for determining whether the given value is an error object with a\n * `stack` property, such as an instance of Error.\n *\n * @param error - The object to check.\n * @returns A boolean.\n */\nexport function isErrorWithStack(error: unknown): error is { stack: string } {\n return typeof error === 'object' && error !== null && 'stack' in error;\n}\n\n/**\n * Attempts to obtain the message from a possible error object, defaulting to an\n * empty string if it is impossible to do so.\n *\n * @param error - The possible error to get the message from.\n * @returns The message if `error` is an object with a `message` property;\n * the string version of `error` if it is not `undefined` or `null`; otherwise\n * an empty string.\n */\nexport function getErrorMessage(error: unknown): string {\n if (isErrorWithMessage(error) && typeof error.message === 'string') {\n return error.message;\n }\n\n if (isNullOrUndefined(error)) {\n return '';\n }\n\n return String(error);\n}\n\n/**\n * Builds a new error object, linking it to the original error via the `cause`\n * property if it is an Error.\n *\n * This function is useful to reframe error messages in general, but is\n * _critical_ when interacting with any of Node's filesystem functions as\n * provided via `fs.promises`, because these do not produce stack traces in the\n * case of an I/O error (see <https://github.com/nodejs/node/issues/30944>).\n *\n * @param originalError - The error to be wrapped (something throwable).\n * @param message - The desired message of the new error.\n * @returns A new error object.\n */\nexport function wrapError<Throwable>(\n originalError: Throwable,\n message: string,\n): Error & { code?: string } {\n if (isError(originalError)) {\n let error: Error & { code?: string };\n if (Error.length === 2) {\n // for some reason `tsserver` is not complaining that the\n // Error constructor doesn't support a second argument in the editor,\n // but `tsc` does. Error causes are not supported by our current tsc target (ES2020, we need ES2022 to make this work)\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n error = new Error(message, { cause: originalError });\n } else {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n error = new ErrorWithCause(message, { cause: originalError });\n }\n\n if (isErrorWithCode(originalError)) {\n error.code = originalError.code;\n }\n\n return error;\n }\n\n if (message.length > 0) {\n return new Error(`${String(originalError)}: ${message}`);\n }\n\n return new Error(String(originalError));\n}\n"],"mappings":";;;;;;AAAA,SAAS,sBAAsB;AAY/B,SAAS,QAAQ,OAAgC;AAC/C,SACE,iBAAiB,SAChB,SAAS,KAAK,KAAK,MAAM,YAAY,SAAS;AAEnD;AAUO,SAAS,gBAAgB,OAA2C;AACzE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;AAClE;AASO,SAAS,mBACd,OAC8B;AAC9B,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa;AACrE;AASO,SAAS,iBAAiB,OAA4C;AAC3E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,WAAW;AACnE;AAWO,SAAS,gBAAgB,OAAwB;AACtD,MAAI,mBAAmB,KAAK,KAAK,OAAO,MAAM,YAAY,UAAU;AAClE,WAAO,MAAM;AAAA,EACf;AAEA,MAAI,kBAAkB,KAAK,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,KAAK;AACrB;AAeO,SAAS,UACd,eACA,SAC2B;AAC3B,MAAI,QAAQ,aAAa,GAAG;AAC1B,QAAI;AACJ,QAAI,MAAM,WAAW,GAAG;AAMtB,cAAQ,IAAI,MAAM,SAAS,EAAE,OAAO,cAAc,CAAC;AAAA,IACrD,OAAO;AAGL,cAAQ,IAAI,eAAe,SAAS,EAAE,OAAO,cAAc,CAAC;AAAA,IAC9D;AAEA,QAAI,gBAAgB,aAAa,GAAG;AAClC,YAAM,OAAO,cAAc;AAAA,IAC7B;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,QAAQ,SAAS,GAAG;AACtB,WAAO,IAAI,MAAM,GAAG,OAAO,aAAa,CAAC,KAAK,OAAO,EAAE;AAAA,EACzD;AAEA,SAAO,IAAI,MAAM,OAAO,aAAa,CAAC;AACxC;","names":[]}