@metamask/utils 8.0.0 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/dist/assert.js +16 -0
  3. package/dist/assert.js.map +1 -0
  4. package/dist/assert.mjs +16 -0
  5. package/dist/assert.mjs.map +1 -0
  6. package/dist/base64.js +11 -0
  7. package/dist/base64.js.map +1 -0
  8. package/dist/base64.mjs +11 -0
  9. package/dist/base64.mjs.map +1 -0
  10. package/dist/bytes.js +43 -0
  11. package/dist/bytes.js.map +1 -0
  12. package/dist/bytes.mjs +43 -0
  13. package/dist/bytes.mjs.map +1 -0
  14. package/dist/caip-types.js +40 -0
  15. package/dist/caip-types.js.map +1 -0
  16. package/dist/caip-types.mjs +40 -0
  17. package/dist/caip-types.mjs.map +1 -0
  18. package/dist/checksum.js +12 -0
  19. package/dist/checksum.js.map +1 -0
  20. package/dist/checksum.mjs +12 -0
  21. package/dist/checksum.mjs.map +1 -0
  22. package/dist/chunk-2CY4F77D.mjs +95 -0
  23. package/dist/chunk-2CY4F77D.mjs.map +1 -0
  24. package/dist/chunk-2LBGT4GH.js +15 -0
  25. package/dist/chunk-2LBGT4GH.js.map +1 -0
  26. package/dist/chunk-2TBCL6EF.js +1 -0
  27. package/dist/chunk-2TBCL6EF.js.map +1 -0
  28. package/dist/chunk-3W5G4CYI.js +25 -0
  29. package/dist/chunk-3W5G4CYI.js.map +1 -0
  30. package/dist/chunk-4JNG5UTO.js +44 -0
  31. package/dist/chunk-4JNG5UTO.js.map +1 -0
  32. package/dist/chunk-4RMX5YWE.js +34 -0
  33. package/dist/chunk-4RMX5YWE.js.map +1 -0
  34. package/dist/chunk-5WQRFJVQ.js +257 -0
  35. package/dist/chunk-5WQRFJVQ.js.map +1 -0
  36. package/dist/chunk-65KBH4FZ.mjs +257 -0
  37. package/dist/chunk-65KBH4FZ.mjs.map +1 -0
  38. package/dist/chunk-7S5AWFX7.mjs +61 -0
  39. package/dist/chunk-7S5AWFX7.mjs.map +1 -0
  40. package/dist/chunk-AY6FDCBT.mjs +1 -0
  41. package/dist/chunk-AY6FDCBT.mjs.map +1 -0
  42. package/dist/chunk-BKR45GQY.mjs +273 -0
  43. package/dist/chunk-BKR45GQY.mjs.map +1 -0
  44. package/dist/chunk-CSDMTDND.mjs +59 -0
  45. package/dist/chunk-CSDMTDND.mjs.map +1 -0
  46. package/dist/chunk-DMPG3H3G.js +61 -0
  47. package/dist/chunk-DMPG3H3G.js.map +1 -0
  48. package/dist/chunk-DYMCEQIV.mjs +1 -0
  49. package/dist/chunk-DYMCEQIV.mjs.map +1 -0
  50. package/dist/chunk-EQMZL4XU.js +1 -0
  51. package/dist/chunk-EQMZL4XU.js.map +1 -0
  52. package/dist/chunk-G66TREC6.mjs +69 -0
  53. package/dist/chunk-G66TREC6.mjs.map +1 -0
  54. package/dist/chunk-H4YFDLB7.mjs +70 -0
  55. package/dist/chunk-H4YFDLB7.mjs.map +1 -0
  56. package/dist/chunk-HLDWS2JR.mjs +35 -0
  57. package/dist/chunk-HLDWS2JR.mjs.map +1 -0
  58. package/dist/chunk-I575FZFH.mjs +1 -0
  59. package/dist/chunk-I575FZFH.mjs.map +1 -0
  60. package/dist/chunk-JCYFTGED.js +95 -0
  61. package/dist/chunk-JCYFTGED.js.map +1 -0
  62. package/dist/chunk-JPAL7Q5S.mjs +90 -0
  63. package/dist/chunk-JPAL7Q5S.mjs.map +1 -0
  64. package/dist/chunk-LC2CRSWD.js +1 -0
  65. package/dist/chunk-LC2CRSWD.js.map +1 -0
  66. package/dist/chunk-N53OILN6.mjs +16 -0
  67. package/dist/chunk-N53OILN6.mjs.map +1 -0
  68. package/dist/chunk-QVEKZRZ2.js +70 -0
  69. package/dist/chunk-QVEKZRZ2.js.map +1 -0
  70. package/dist/chunk-RIRDOQPX.mjs +15 -0
  71. package/dist/chunk-RIRDOQPX.mjs.map +1 -0
  72. package/dist/chunk-RKRGAFXY.js +1 -0
  73. package/dist/chunk-RKRGAFXY.js.map +1 -0
  74. package/dist/chunk-RRYOWRCV.mjs +1 -0
  75. package/dist/chunk-RRYOWRCV.mjs.map +1 -0
  76. package/dist/chunk-TGOMTREC.mjs +75 -0
  77. package/dist/chunk-TGOMTREC.mjs.map +1 -0
  78. package/dist/chunk-THNLGEXV.mjs +34 -0
  79. package/dist/chunk-THNLGEXV.mjs.map +1 -0
  80. package/dist/chunk-U7ZUGCE7.js +75 -0
  81. package/dist/chunk-U7ZUGCE7.js.map +1 -0
  82. package/dist/chunk-UOTVU7OQ.js +1 -0
  83. package/dist/chunk-UOTVU7OQ.js.map +1 -0
  84. package/dist/chunk-VBYRLAP6.js +59 -0
  85. package/dist/chunk-VBYRLAP6.js.map +1 -0
  86. package/dist/chunk-VL5DYXC5.mjs +122 -0
  87. package/dist/chunk-VL5DYXC5.mjs.map +1 -0
  88. package/dist/chunk-VSEW3V2L.mjs +44 -0
  89. package/dist/chunk-VSEW3V2L.mjs.map +1 -0
  90. package/dist/chunk-WA4DHIND.mjs +1 -0
  91. package/dist/chunk-WA4DHIND.mjs.map +1 -0
  92. package/dist/chunk-WQDTPIQK.js +122 -0
  93. package/dist/chunk-WQDTPIQK.js.map +1 -0
  94. package/dist/chunk-WRBN6DWM.js +35 -0
  95. package/dist/chunk-WRBN6DWM.js.map +1 -0
  96. package/dist/chunk-X66SUIEF.mjs +25 -0
  97. package/dist/chunk-X66SUIEF.mjs.map +1 -0
  98. package/dist/chunk-XYYGZF5Y.js +16 -0
  99. package/dist/chunk-XYYGZF5Y.js.map +1 -0
  100. package/dist/chunk-YQJBIHC7.js +273 -0
  101. package/dist/chunk-YQJBIHC7.js.map +1 -0
  102. package/dist/chunk-Z2RGWDD7.js +90 -0
  103. package/dist/chunk-Z2RGWDD7.js.map +1 -0
  104. package/dist/chunk-ZRNIY7OW.js +69 -0
  105. package/dist/chunk-ZRNIY7OW.js.map +1 -0
  106. package/dist/coercers.js +18 -0
  107. package/dist/coercers.js.map +1 -0
  108. package/dist/coercers.mjs +18 -0
  109. package/dist/coercers.mjs.map +1 -0
  110. package/dist/collections.js +10 -0
  111. package/dist/collections.js.map +1 -0
  112. package/dist/collections.mjs +10 -0
  113. package/dist/collections.mjs.map +1 -0
  114. package/dist/encryption-types.js +2 -0
  115. package/dist/encryption-types.js.map +1 -0
  116. package/dist/encryption-types.mjs +2 -0
  117. package/dist/encryption-types.mjs.map +1 -0
  118. package/dist/errors.js +17 -0
  119. package/dist/errors.js.map +1 -0
  120. package/dist/errors.mjs +17 -0
  121. package/dist/errors.mjs.map +1 -0
  122. package/dist/fs.js +26 -0
  123. package/dist/fs.js.map +1 -0
  124. package/dist/fs.mjs +26 -0
  125. package/dist/fs.mjs.map +1 -0
  126. package/dist/hex.js +35 -0
  127. package/dist/hex.js.map +1 -0
  128. package/dist/hex.mjs +35 -0
  129. package/dist/hex.mjs.map +1 -0
  130. package/dist/index.js +289 -0
  131. package/dist/index.js.map +1 -0
  132. package/dist/index.mjs +289 -0
  133. package/dist/index.mjs.map +1 -0
  134. package/dist/json.js +75 -0
  135. package/dist/json.js.map +1 -0
  136. package/dist/json.mjs +75 -0
  137. package/dist/json.mjs.map +1 -0
  138. package/dist/keyring.js +2 -0
  139. package/dist/keyring.js.map +1 -0
  140. package/dist/keyring.mjs +2 -0
  141. package/dist/keyring.mjs.map +1 -0
  142. package/dist/logging.js +10 -0
  143. package/dist/logging.js.map +1 -0
  144. package/dist/logging.mjs +10 -0
  145. package/dist/logging.mjs.map +1 -0
  146. package/dist/misc.js +28 -0
  147. package/dist/misc.js.map +1 -0
  148. package/dist/misc.mjs +28 -0
  149. package/dist/misc.mjs.map +1 -0
  150. package/dist/node.js +309 -0
  151. package/dist/node.js.map +1 -0
  152. package/dist/node.mjs +309 -0
  153. package/dist/node.mjs.map +1 -0
  154. package/dist/number.js +18 -0
  155. package/dist/number.js.map +1 -0
  156. package/dist/number.mjs +18 -0
  157. package/dist/number.mjs.map +1 -0
  158. package/dist/opaque.js +2 -0
  159. package/dist/opaque.js.map +1 -0
  160. package/dist/opaque.mjs +2 -0
  161. package/dist/opaque.mjs.map +1 -0
  162. package/dist/time.js +12 -0
  163. package/dist/time.js.map +1 -0
  164. package/dist/time.mjs +12 -0
  165. package/dist/time.mjs.map +1 -0
  166. package/dist/transaction-types.js +2 -0
  167. package/dist/transaction-types.js.map +1 -0
  168. package/dist/transaction-types.mjs +2 -0
  169. package/dist/transaction-types.mjs.map +1 -0
  170. package/dist/types/assert.d.ts.map +1 -1
  171. package/dist/types/bytes.d.ts +14 -0
  172. package/dist/types/bytes.d.ts.map +1 -1
  173. package/dist/types/errors.d.ts +58 -0
  174. package/dist/types/errors.d.ts.map +1 -0
  175. package/dist/types/fs.d.ts +133 -0
  176. package/dist/types/fs.d.ts.map +1 -0
  177. package/dist/types/index.d.ts +1 -0
  178. package/dist/types/index.d.ts.map +1 -1
  179. package/dist/types/json.d.ts +83 -47
  180. package/dist/types/json.d.ts.map +1 -1
  181. package/dist/types/node.d.ts +3 -0
  182. package/dist/types/node.d.ts.map +1 -0
  183. package/dist/versions.js +27 -0
  184. package/dist/versions.js.map +1 -0
  185. package/dist/versions.mjs +27 -0
  186. package/dist/versions.mjs.map +1 -0
  187. package/package.json +21 -20
  188. package/dist/cjs/assert.js +0 -116
  189. package/dist/cjs/assert.js.map +0 -1
  190. package/dist/cjs/base64.js +0 -32
  191. package/dist/cjs/base64.js.map +0 -1
  192. package/dist/cjs/bytes.js +0 -255
  193. package/dist/cjs/bytes.js.map +0 -1
  194. package/dist/cjs/caip-types.js +0 -115
  195. package/dist/cjs/caip-types.js.map +0 -1
  196. package/dist/cjs/checksum.js +0 -17
  197. package/dist/cjs/checksum.js.map +0 -1
  198. package/dist/cjs/coercers.js +0 -96
  199. package/dist/cjs/coercers.js.map +0 -1
  200. package/dist/cjs/collections.js +0 -157
  201. package/dist/cjs/collections.js.map +0 -1
  202. package/dist/cjs/encryption-types.js +0 -6
  203. package/dist/cjs/encryption-types.js.map +0 -1
  204. package/dist/cjs/hex.js +0 -107
  205. package/dist/cjs/hex.js.map +0 -1
  206. package/dist/cjs/index.js +0 -37
  207. package/dist/cjs/index.js.map +0 -1
  208. package/dist/cjs/json.js +0 -263
  209. package/dist/cjs/json.js.map +0 -1
  210. package/dist/cjs/keyring.js +0 -6
  211. package/dist/cjs/keyring.js.map +0 -1
  212. package/dist/cjs/logging.js +0 -33
  213. package/dist/cjs/logging.js.map +0 -1
  214. package/dist/cjs/misc.js +0 -111
  215. package/dist/cjs/misc.js.map +0 -1
  216. package/dist/cjs/number.js +0 -52
  217. package/dist/cjs/number.js.map +0 -1
  218. package/dist/cjs/opaque.js +0 -8
  219. package/dist/cjs/opaque.js.map +0 -1
  220. package/dist/cjs/time.js +0 -63
  221. package/dist/cjs/time.js.map +0 -1
  222. package/dist/cjs/transaction-types.js +0 -6
  223. package/dist/cjs/transaction-types.js.map +0 -1
  224. package/dist/cjs/versions.js +0 -79
  225. package/dist/cjs/versions.js.map +0 -1
  226. package/dist/esm/assert.js +0 -133
  227. package/dist/esm/assert.js.map +0 -1
  228. package/dist/esm/base64.js +0 -28
  229. package/dist/esm/base64.js.map +0 -1
  230. package/dist/esm/bytes.js +0 -334
  231. package/dist/esm/bytes.js.map +0 -1
  232. package/dist/esm/caip-types.js +0 -99
  233. package/dist/esm/caip-types.js.map +0 -1
  234. package/dist/esm/checksum.js +0 -7
  235. package/dist/esm/checksum.js.map +0 -1
  236. package/dist/esm/coercers.js +0 -153
  237. package/dist/esm/coercers.js.map +0 -1
  238. package/dist/esm/collections.js +0 -140
  239. package/dist/esm/collections.js.map +0 -1
  240. package/dist/esm/encryption-types.js +0 -3
  241. package/dist/esm/encryption-types.js.map +0 -1
  242. package/dist/esm/hex.js +0 -108
  243. package/dist/esm/hex.js.map +0 -1
  244. package/dist/esm/index.js +0 -20
  245. package/dist/esm/index.js.map +0 -1
  246. package/dist/esm/json.js +0 -301
  247. package/dist/esm/json.js.map +0 -1
  248. package/dist/esm/keyring.js +0 -3
  249. package/dist/esm/keyring.js.map +0 -1
  250. package/dist/esm/logging.js +0 -34
  251. package/dist/esm/logging.js.map +0 -1
  252. package/dist/esm/misc.js +0 -129
  253. package/dist/esm/misc.js.map +0 -1
  254. package/dist/esm/number.js +0 -92
  255. package/dist/esm/number.js.map +0 -1
  256. package/dist/esm/opaque.js +0 -5
  257. package/dist/esm/opaque.js.map +0 -1
  258. package/dist/esm/package.json +0 -1
  259. package/dist/esm/time.js +0 -53
  260. package/dist/esm/time.js.map +0 -1
  261. package/dist/esm/transaction-types.js +0 -3
  262. package/dist/esm/transaction-types.js.map +0 -1
  263. package/dist/esm/versions.js +0 -78
  264. package/dist/esm/versions.js.map +0 -1
  265. package/dist/types/caip-types.test-d.d.ts +0 -2
  266. package/dist/types/caip-types.test-d.d.ts.map +0 -1
  267. package/dist/types/hex.test-d.d.ts +0 -2
  268. package/dist/types/hex.test-d.d.ts.map +0 -1
  269. package/dist/types/json.test-d.d.ts +0 -2
  270. package/dist/types/json.test-d.d.ts.map +0 -1
  271. package/dist/types/misc.test-d.d.ts +0 -2
  272. package/dist/types/misc.test-d.d.ts.map +0 -1
@@ -0,0 +1,70 @@
1
+ // src/misc.ts
2
+ function isNonEmptyArray(value) {
3
+ return Array.isArray(value) && value.length > 0;
4
+ }
5
+ function isNullOrUndefined(value) {
6
+ return value === null || value === void 0;
7
+ }
8
+ function isObject(value) {
9
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
10
+ }
11
+ var hasProperty = (objectToCheck, name) => Object.hasOwnProperty.call(objectToCheck, name);
12
+ function getKnownPropertyNames(object) {
13
+ return Object.getOwnPropertyNames(object);
14
+ }
15
+ var JsonSize = /* @__PURE__ */ ((JsonSize2) => {
16
+ JsonSize2[JsonSize2["Null"] = 4] = "Null";
17
+ JsonSize2[JsonSize2["Comma"] = 1] = "Comma";
18
+ JsonSize2[JsonSize2["Wrapper"] = 1] = "Wrapper";
19
+ JsonSize2[JsonSize2["True"] = 4] = "True";
20
+ JsonSize2[JsonSize2["False"] = 5] = "False";
21
+ JsonSize2[JsonSize2["Quote"] = 1] = "Quote";
22
+ JsonSize2[JsonSize2["Colon"] = 1] = "Colon";
23
+ JsonSize2[JsonSize2["Date"] = 24] = "Date";
24
+ return JsonSize2;
25
+ })(JsonSize || {});
26
+ var ESCAPE_CHARACTERS_REGEXP = /"|\\|\n|\r|\t/gu;
27
+ function isPlainObject(value) {
28
+ if (typeof value !== "object" || value === null) {
29
+ return false;
30
+ }
31
+ try {
32
+ let proto = value;
33
+ while (Object.getPrototypeOf(proto) !== null) {
34
+ proto = Object.getPrototypeOf(proto);
35
+ }
36
+ return Object.getPrototypeOf(value) === proto;
37
+ } catch (_) {
38
+ return false;
39
+ }
40
+ }
41
+ function isASCII(character) {
42
+ return character.charCodeAt(0) <= 127;
43
+ }
44
+ function calculateStringSize(value) {
45
+ const size = value.split("").reduce((total, character) => {
46
+ if (isASCII(character)) {
47
+ return total + 1;
48
+ }
49
+ return total + 2;
50
+ }, 0);
51
+ return size + (value.match(ESCAPE_CHARACTERS_REGEXP) ?? []).length;
52
+ }
53
+ function calculateNumberSize(value) {
54
+ return value.toString().length;
55
+ }
56
+
57
+ export {
58
+ isNonEmptyArray,
59
+ isNullOrUndefined,
60
+ isObject,
61
+ hasProperty,
62
+ getKnownPropertyNames,
63
+ JsonSize,
64
+ ESCAPE_CHARACTERS_REGEXP,
65
+ isPlainObject,
66
+ isASCII,
67
+ calculateStringSize,
68
+ calculateNumberSize
69
+ };
70
+ //# sourceMappingURL=chunk-H4YFDLB7.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/misc.ts"],"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"],"mappings":";AAiDO,SAAS,gBACd,OACiC;AACjC,SAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS;AAChD;AAQO,SAAS,kBAAkB,OAA2C;AAC3E,SAAO,UAAU,QAAQ,UAAU;AACrC;AASO,SAAS,SAAS,OAAwC;AAC/D,SAAO,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAcO,IAAM,cAAc,CAKzB,eACA,SAKK,OAAO,eAAe,KAAK,eAAe,IAAI;AAa9C,SAAS,sBACd,QACO;AACP,SAAO,OAAO,oBAAoB,MAAM;AAC1C;AAOO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,aAAU,KAAV;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,WAAQ,KAAR;AAEA,EAAAA,oBAAA,UAAO,MAAP;AATU,SAAAA;AAAA,GAAA;AAeL,IAAM,2BAA2B;AASjC,SAAS,cAAc,OAAsC;AAClE,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AAEA,MAAI;AACF,QAAI,QAAQ;AACZ,WAAO,OAAO,eAAe,KAAK,MAAM,MAAM;AAC5C,cAAQ,OAAO,eAAe,KAAK;AAAA,IACrC;AAEA,WAAO,OAAO,eAAe,KAAK,MAAM;AAAA,EAC1C,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;AAQO,SAAS,QAAQ,WAAmB;AACzC,SAAO,UAAU,WAAW,CAAC,KAAK;AACpC;AAQO,SAAS,oBAAoB,OAAuB;AACzD,QAAM,OAAO,MAAM,MAAM,EAAE,EAAE,OAAO,CAAC,OAAO,cAAc;AACxD,QAAI,QAAQ,SAAS,GAAG;AACtB,aAAO,QAAQ;AAAA,IACjB;AACA,WAAO,QAAQ;AAAA,EACjB,GAAG,CAAC;AAGJ,SAAO,QAAQ,MAAM,MAAM,wBAAwB,KAAK,CAAC,GAAG;AAC9D;AAQO,SAAS,oBAAoB,OAAuB;AACzD,SAAO,MAAM,SAAS,EAAE;AAC1B;","names":["JsonSize"]}
@@ -0,0 +1,35 @@
1
+ import {
2
+ assert
3
+ } from "./chunk-CSDMTDND.mjs";
4
+
5
+ // src/base64.ts
6
+ import { pattern } from "superstruct";
7
+ var base64 = (struct, options = {}) => {
8
+ const paddingRequired = options.paddingRequired ?? false;
9
+ const characterSet = options.characterSet ?? "base64";
10
+ let letters;
11
+ if (characterSet === "base64") {
12
+ letters = String.raw`[A-Za-z0-9+\/]`;
13
+ } else {
14
+ assert(characterSet === "base64url");
15
+ letters = String.raw`[-_A-Za-z0-9]`;
16
+ }
17
+ let re;
18
+ if (paddingRequired) {
19
+ re = new RegExp(
20
+ `^(?:${letters}{4})*(?:${letters}{3}=|${letters}{2}==)?$`,
21
+ "u"
22
+ );
23
+ } else {
24
+ re = new RegExp(
25
+ `^(?:${letters}{4})*(?:${letters}{2,3}|${letters}{3}=|${letters}{2}==)?$`,
26
+ "u"
27
+ );
28
+ }
29
+ return pattern(struct, re);
30
+ };
31
+
32
+ export {
33
+ base64
34
+ };
35
+ //# sourceMappingURL=chunk-HLDWS2JR.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/base64.ts"],"sourcesContent":["import type { Struct } from 'superstruct';\nimport { pattern } from 'superstruct';\n\nimport { assert } from './assert';\n\nexport type Base64Options = {\n /**\n * Is the `=` padding at the end required or not.\n *\n * @default false\n */\n // Padding is optional in RFC 4648, that's why the default value is false\n paddingRequired?: boolean;\n /**\n * Which character set should be used.\n * The sets are based on {@link https://datatracker.ietf.org/doc/html/rfc4648 RFC 4648}.\n *\n * @default 'base64'\n */\n characterSet?: 'base64' | 'base64url';\n};\n\n/**\n * Ensure that a provided string-based struct is valid base64.\n *\n * @param struct - The string based struct.\n * @param options - Optional options to specialize base64 validation. See {@link Base64Options} documentation.\n * @returns A superstruct validating base64.\n */\nexport const base64 = <Type extends string, Schema>(\n struct: Struct<Type, Schema>,\n options: Base64Options = {},\n) => {\n const paddingRequired = options.paddingRequired ?? false;\n const characterSet = options.characterSet ?? 'base64';\n\n let letters: string;\n if (characterSet === 'base64') {\n letters = String.raw`[A-Za-z0-9+\\/]`;\n } else {\n assert(characterSet === 'base64url');\n letters = String.raw`[-_A-Za-z0-9]`;\n }\n\n let re: RegExp;\n if (paddingRequired) {\n re = new RegExp(\n `^(?:${letters}{4})*(?:${letters}{3}=|${letters}{2}==)?$`,\n 'u',\n );\n } else {\n re = new RegExp(\n `^(?:${letters}{4})*(?:${letters}{2,3}|${letters}{3}=|${letters}{2}==)?$`,\n 'u',\n );\n }\n\n return pattern(struct, re);\n};\n"],"mappings":";;;;;AACA,SAAS,eAAe;AA4BjB,IAAM,SAAS,CACpB,QACA,UAAyB,CAAC,MACvB;AACH,QAAM,kBAAkB,QAAQ,mBAAmB;AACnD,QAAM,eAAe,QAAQ,gBAAgB;AAE7C,MAAI;AACJ,MAAI,iBAAiB,UAAU;AAC7B,cAAU,OAAO;AAAA,EACnB,OAAO;AACL,WAAO,iBAAiB,WAAW;AACnC,cAAU,OAAO;AAAA,EACnB;AAEA,MAAI;AACJ,MAAI,iBAAiB;AACnB,SAAK,IAAI;AAAA,MACP,OAAO,OAAO,WAAW,OAAO,QAAQ,OAAO;AAAA,MAC/C;AAAA,IACF;AAAA,EACF,OAAO;AACL,SAAK,IAAI;AAAA,MACP,OAAO,OAAO,WAAW,OAAO,SAAS,OAAO,QAAQ,OAAO;AAAA,MAC/D;AAAA,IACF;AAAA,EACF;AAEA,SAAO,QAAQ,QAAQ,EAAE;AAC3B;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-I575FZFH.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,95 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkYQJBIHC7js = require('./chunk-YQJBIHC7.js');
6
+
7
+
8
+ var _chunkVBYRLAP6js = require('./chunk-VBYRLAP6.js');
9
+
10
+ // src/coercers.ts
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+ var _superstruct = require('superstruct');
21
+ var NumberLikeStruct = _superstruct.union.call(void 0, [_superstruct.number.call(void 0, ), _superstruct.bigint.call(void 0, ), _superstruct.string.call(void 0, ), _chunkYQJBIHC7js.StrictHexStruct]);
22
+ var NumberCoercer = _superstruct.coerce.call(void 0, _superstruct.number.call(void 0, ), NumberLikeStruct, Number);
23
+ var BigIntCoercer = _superstruct.coerce.call(void 0, _superstruct.bigint.call(void 0, ), NumberLikeStruct, BigInt);
24
+ var BytesLikeStruct = _superstruct.union.call(void 0, [_chunkYQJBIHC7js.StrictHexStruct, _superstruct.instance.call(void 0, Uint8Array)]);
25
+ var BytesCoercer = _superstruct.coerce.call(void 0,
26
+ _superstruct.instance.call(void 0, Uint8Array),
27
+ _superstruct.union.call(void 0, [_chunkYQJBIHC7js.StrictHexStruct]),
28
+ _chunkYQJBIHC7js.hexToBytes
29
+ );
30
+ var HexCoercer = _superstruct.coerce.call(void 0, _chunkYQJBIHC7js.StrictHexStruct, _superstruct.instance.call(void 0, Uint8Array), _chunkYQJBIHC7js.bytesToHex);
31
+ function createNumber(value) {
32
+ try {
33
+ const result = _superstruct.create.call(void 0, value, NumberCoercer);
34
+ _chunkVBYRLAP6js.assert.call(void 0,
35
+ Number.isFinite(result),
36
+ `Expected a number-like value, got "${value}".`
37
+ );
38
+ return result;
39
+ } catch (error) {
40
+ if (error instanceof _superstruct.StructError) {
41
+ throw new Error(`Expected a number-like value, got "${value}".`);
42
+ }
43
+ throw error;
44
+ }
45
+ }
46
+ function createBigInt(value) {
47
+ try {
48
+ return _superstruct.create.call(void 0, value, BigIntCoercer);
49
+ } catch (error) {
50
+ if (error instanceof _superstruct.StructError) {
51
+ throw new Error(
52
+ `Expected a number-like value, got "${String(error.value)}".`
53
+ );
54
+ }
55
+ throw error;
56
+ }
57
+ }
58
+ function createBytes(value) {
59
+ if (typeof value === "string" && value.toLowerCase() === "0x") {
60
+ return new Uint8Array();
61
+ }
62
+ try {
63
+ return _superstruct.create.call(void 0, value, BytesCoercer);
64
+ } catch (error) {
65
+ if (error instanceof _superstruct.StructError) {
66
+ throw new Error(
67
+ `Expected a bytes-like value, got "${String(error.value)}".`
68
+ );
69
+ }
70
+ throw error;
71
+ }
72
+ }
73
+ function createHex(value) {
74
+ if (value instanceof Uint8Array && value.length === 0 || typeof value === "string" && value.toLowerCase() === "0x") {
75
+ return "0x";
76
+ }
77
+ try {
78
+ return _superstruct.create.call(void 0, value, HexCoercer);
79
+ } catch (error) {
80
+ if (error instanceof _superstruct.StructError) {
81
+ throw new Error(
82
+ `Expected a bytes-like value, got "${String(error.value)}".`
83
+ );
84
+ }
85
+ throw error;
86
+ }
87
+ }
88
+
89
+
90
+
91
+
92
+
93
+
94
+ exports.createNumber = createNumber; exports.createBigInt = createBigInt; exports.createBytes = createBytes; exports.createHex = createHex;
95
+ //# sourceMappingURL=chunk-JCYFTGED.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/coercers.ts"],"names":[],"mappings":";;;;;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAOP,IAAM,mBAAmB,MAAM,CAAC,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,eAAe,CAAC;AAC9E,IAAM,gBAAgB,OAAO,OAAO,GAAG,kBAAkB,MAAM;AAC/D,IAAM,gBAAgB,OAAO,OAAO,GAAG,kBAAkB,MAAM;AAE/D,IAAM,kBAAkB,MAAM,CAAC,iBAAiB,SAAS,UAAU,CAAC,CAAC;AACrE,IAAM,eAAe;AAAA,EACnB,SAAS,UAAU;AAAA,EACnB,MAAM,CAAC,eAAe,CAAC;AAAA,EACvB;AACF;AAEA,IAAM,aAAa,OAAO,iBAAiB,SAAS,UAAU,GAAG,UAAU;AA8BpE,SAAS,aAAa,OAA2B;AACtD,MAAI;AACF,UAAM,SAAS,OAAO,OAAO,aAAa;AAE1C;AAAA,MACE,OAAO,SAAS,MAAM;AAAA,MACtB,sCAAsC,KAAK;AAAA,IAC7C;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,IAAI,MAAM,sCAAsC,KAAK,IAAI;AAAA,IACjE;AAGA,UAAM;AAAA,EACR;AACF;AAwBO,SAAS,aAAa,OAA2B;AACtD,MAAI;AAGF,WAAO,OAAO,OAAO,aAAa;AAAA,EACpC,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,IAAI;AAAA,QACR,sCAAsC,OAAO,MAAM,KAAK,CAAC;AAAA,MAC3D;AAAA,IACF;AAGA,UAAM;AAAA,EACR;AACF;AAqBO,SAAS,YAAY,OAA8B;AACxD,MAAI,OAAO,UAAU,YAAY,MAAM,YAAY,MAAM,MAAM;AAC7D,WAAO,IAAI,WAAW;AAAA,EACxB;AAEA,MAAI;AACF,WAAO,OAAO,OAAO,YAAY;AAAA,EACnC,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,IAAI;AAAA,QACR,qCAAqC,OAAO,MAAM,KAAK,CAAC;AAAA,MAC1D;AAAA,IACF;AAGA,UAAM;AAAA,EACR;AACF;AAqBO,SAAS,UAAU,OAAuB;AAC/C,MACG,iBAAiB,cAAc,MAAM,WAAW,KAChD,OAAO,UAAU,YAAY,MAAM,YAAY,MAAM,MACtD;AACA,WAAO;AAAA,EACT;AAEA,MAAI;AACF,WAAO,OAAO,OAAO,UAAU;AAAA,EACjC,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,IAAI;AAAA,QACR,qCAAqC,OAAO,MAAM,KAAK,CAAC;AAAA,MAC1D;AAAA,IACF;AAGA,UAAM;AAAA,EACR;AACF","sourcesContent":["import type { Infer } from 'superstruct';\nimport {\n bigint,\n coerce,\n create,\n instance,\n number,\n string,\n StructError,\n union,\n} from 'superstruct';\n\nimport { assert } from './assert';\nimport { bytesToHex, hexToBytes } from './bytes';\nimport type { Hex } from './hex';\nimport { StrictHexStruct } from './hex';\n\nconst NumberLikeStruct = union([number(), bigint(), string(), StrictHexStruct]);\nconst NumberCoercer = coerce(number(), NumberLikeStruct, Number);\nconst BigIntCoercer = coerce(bigint(), NumberLikeStruct, BigInt);\n\nconst BytesLikeStruct = union([StrictHexStruct, instance(Uint8Array)]);\nconst BytesCoercer = coerce(\n instance(Uint8Array),\n union([StrictHexStruct]),\n hexToBytes,\n);\n\nconst HexCoercer = coerce(StrictHexStruct, instance(Uint8Array), bytesToHex);\n\nexport type NumberLike = Infer<typeof NumberLikeStruct>;\nexport type BytesLike = Infer<typeof BytesLikeStruct>;\n\n/**\n * Create a number from a number-like value.\n *\n * - If the value is a number, it is returned as-is.\n * - If the value is a `bigint`, it is converted to a number.\n * - If the value is a string, it is interpreted as a decimal number.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is\n * interpreted as a hexadecimal number.\n *\n * This validates that the value is a number-like value, and that the resulting\n * number is not `NaN` or `Infinity`.\n *\n * @example\n * ```typescript\n * const value = createNumber('0x010203');\n * console.log(value); // 66051\n *\n * const otherValue = createNumber(123n);\n * console.log(otherValue); // 123\n * ```\n * @param value - The value to create the number from.\n * @returns The created number.\n * @throws If the value is not a number-like value, or if the resulting number\n * is `NaN` or `Infinity`.\n */\nexport function createNumber(value: NumberLike): number {\n try {\n const result = create(value, NumberCoercer);\n\n assert(\n Number.isFinite(result),\n `Expected a number-like value, got \"${value}\".`,\n );\n\n return result;\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(`Expected a number-like value, got \"${value}\".`);\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a `bigint` from a number-like value.\n *\n * - If the value is a number, it is converted to a `bigint`.\n * - If the value is a `bigint`, it is returned as-is.\n * - If the value is a string, it is interpreted as a decimal number and\n * converted to a `bigint`.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is\n * interpreted as a hexadecimal number and converted to a `bigint`.\n *\n * @example\n * ```typescript\n * const value = createBigInt('0x010203');\n * console.log(value); // 16909060n\n *\n * const otherValue = createBigInt(123);\n * console.log(otherValue); // 123n\n * ```\n * @param value - The value to create the bigint from.\n * @returns The created bigint.\n * @throws If the value is not a number-like value.\n */\nexport function createBigInt(value: NumberLike): bigint {\n try {\n // The `BigInt` constructor throws if the value is not a number-like value.\n // There is no need to validate the value manually.\n return create(value, BigIntCoercer);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Expected a number-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a byte array from a bytes-like value.\n *\n * - If the value is a byte array, it is returned as-is.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is interpreted\n * as a hexadecimal number and converted to a byte array.\n *\n * @example\n * ```typescript\n * const value = createBytes('0x010203');\n * console.log(value); // Uint8Array [ 1, 2, 3 ]\n *\n * const otherValue = createBytes('0x010203');\n * console.log(otherValue); // Uint8Array [ 1, 2, 3 ]\n * ```\n * @param value - The value to create the byte array from.\n * @returns The created byte array.\n * @throws If the value is not a bytes-like value.\n */\nexport function createBytes(value: BytesLike): Uint8Array {\n if (typeof value === 'string' && value.toLowerCase() === '0x') {\n return new Uint8Array();\n }\n\n try {\n return create(value, BytesCoercer);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Expected a bytes-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a hexadecimal string from a bytes-like value.\n *\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is returned\n * as-is.\n * - If the value is a `Uint8Array`, it is converted to a hex string.\n *\n * @example\n * ```typescript\n * const value = createHex(new Uint8Array([1, 2, 3]));\n * console.log(value); // '0x010203'\n *\n * const otherValue = createHex('0x010203');\n * console.log(otherValue); // '0x010203'\n * ```\n * @param value - The value to create the hex string from.\n * @returns The created hex string.\n * @throws If the value is not a bytes-like value.\n */\nexport function createHex(value: BytesLike): Hex {\n if (\n (value instanceof Uint8Array && value.length === 0) ||\n (typeof value === 'string' && value.toLowerCase() === '0x')\n ) {\n return '0x';\n }\n\n try {\n return create(value, HexCoercer);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Expected a bytes-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n"]}
@@ -0,0 +1,90 @@
1
+ import {
2
+ __privateAdd,
3
+ __privateGet,
4
+ __privateSet
5
+ } from "./chunk-X66SUIEF.mjs";
6
+
7
+ // src/collections.ts
8
+ var _map;
9
+ var FrozenMap = class {
10
+ constructor(entries) {
11
+ __privateAdd(this, _map, void 0);
12
+ __privateSet(this, _map, new Map(entries));
13
+ Object.freeze(this);
14
+ }
15
+ get size() {
16
+ return __privateGet(this, _map).size;
17
+ }
18
+ [Symbol.iterator]() {
19
+ return __privateGet(this, _map)[Symbol.iterator]();
20
+ }
21
+ entries() {
22
+ return __privateGet(this, _map).entries();
23
+ }
24
+ forEach(callbackfn, thisArg) {
25
+ return __privateGet(this, _map).forEach(
26
+ (value, key, _map2) => callbackfn.call(thisArg, value, key, this)
27
+ );
28
+ }
29
+ get(key) {
30
+ return __privateGet(this, _map).get(key);
31
+ }
32
+ has(key) {
33
+ return __privateGet(this, _map).has(key);
34
+ }
35
+ keys() {
36
+ return __privateGet(this, _map).keys();
37
+ }
38
+ values() {
39
+ return __privateGet(this, _map).values();
40
+ }
41
+ toString() {
42
+ return `FrozenMap(${this.size}) {${this.size > 0 ? ` ${[...this.entries()].map(([key, value]) => `${String(key)} => ${String(value)}`).join(", ")} ` : ""}}`;
43
+ }
44
+ };
45
+ _map = new WeakMap();
46
+ var _set;
47
+ var FrozenSet = class {
48
+ constructor(values) {
49
+ __privateAdd(this, _set, void 0);
50
+ __privateSet(this, _set, new Set(values));
51
+ Object.freeze(this);
52
+ }
53
+ get size() {
54
+ return __privateGet(this, _set).size;
55
+ }
56
+ [Symbol.iterator]() {
57
+ return __privateGet(this, _set)[Symbol.iterator]();
58
+ }
59
+ entries() {
60
+ return __privateGet(this, _set).entries();
61
+ }
62
+ forEach(callbackfn, thisArg) {
63
+ return __privateGet(this, _set).forEach(
64
+ (value, value2, _set2) => callbackfn.call(thisArg, value, value2, this)
65
+ );
66
+ }
67
+ has(value) {
68
+ return __privateGet(this, _set).has(value);
69
+ }
70
+ keys() {
71
+ return __privateGet(this, _set).keys();
72
+ }
73
+ values() {
74
+ return __privateGet(this, _set).values();
75
+ }
76
+ toString() {
77
+ return `FrozenSet(${this.size}) {${this.size > 0 ? ` ${[...this.values()].map((member) => String(member)).join(", ")} ` : ""}}`;
78
+ }
79
+ };
80
+ _set = new WeakMap();
81
+ Object.freeze(FrozenMap);
82
+ Object.freeze(FrozenMap.prototype);
83
+ Object.freeze(FrozenSet);
84
+ Object.freeze(FrozenSet.prototype);
85
+
86
+ export {
87
+ FrozenMap,
88
+ FrozenSet
89
+ };
90
+ //# sourceMappingURL=chunk-JPAL7Q5S.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/collections.ts"],"sourcesContent":["/**\n * A {@link ReadonlyMap} that cannot be modified after instantiation.\n * The implementation uses an inner map hidden via a private field, and the\n * immutability guarantee relies on it being impossible to get a reference\n * to this map.\n */\nclass FrozenMap<Key, Value> implements ReadonlyMap<Key, Value> {\n readonly #map: Map<Key, Value>;\n\n public get size() {\n return this.#map.size;\n }\n\n public [Symbol.iterator]() {\n return this.#map[Symbol.iterator]();\n }\n\n constructor(entries?: readonly (readonly [Key, Value])[] | null) {\n this.#map = new Map<Key, Value>(entries);\n Object.freeze(this);\n }\n\n public entries() {\n return this.#map.entries();\n }\n\n public forEach(\n callbackfn: (value: Value, key: Key, map: this) => void,\n thisArg?: any,\n ): void {\n // We have to wrap the specified callback in order to prevent it from\n // receiving a reference to the inner map.\n return this.#map.forEach((value: Value, key: Key, _map: unknown) =>\n callbackfn.call(thisArg, value, key, this),\n );\n }\n\n public get(key: Key) {\n return this.#map.get(key);\n }\n\n public has(key: Key) {\n return this.#map.has(key);\n }\n\n public keys() {\n return this.#map.keys();\n }\n\n public values() {\n return this.#map.values();\n }\n\n public toString(): string {\n return `FrozenMap(${this.size}) {${\n this.size > 0\n ? ` ${[...this.entries()]\n .map(([key, value]) => `${String(key)} => ${String(value)}`)\n .join(', ')} `\n : ''\n }}`;\n }\n}\n\n/**\n * A {@link ReadonlySet} that cannot be modified after instantiation.\n * The implementation uses an inner set hidden via a private field, and the\n * immutability guarantee relies on it being impossible to get a reference\n * to this set.\n */\nclass FrozenSet<Value> implements ReadonlySet<Value> {\n readonly #set: Set<Value>;\n\n public get size() {\n return this.#set.size;\n }\n\n public [Symbol.iterator]() {\n return this.#set[Symbol.iterator]();\n }\n\n constructor(values?: readonly Value[] | null) {\n this.#set = new Set<Value>(values);\n Object.freeze(this);\n }\n\n public entries() {\n return this.#set.entries();\n }\n\n public forEach(\n callbackfn: (value: Value, value2: Value, set: this) => void,\n thisArg?: any,\n ): void {\n // We have to wrap the specified callback in order to prevent it from\n // receiving a reference to the inner set.\n return this.#set.forEach((value: Value, value2: Value, _set: unknown) =>\n callbackfn.call(thisArg, value, value2, this),\n );\n }\n\n public has(value: Value) {\n return this.#set.has(value);\n }\n\n public keys() {\n return this.#set.keys();\n }\n\n public values() {\n return this.#set.values();\n }\n\n public toString(): string {\n return `FrozenSet(${this.size}) {${\n this.size > 0\n ? ` ${[...this.values()].map((member) => String(member)).join(', ')} `\n : ''\n }}`;\n }\n}\n\nObject.freeze(FrozenMap);\nObject.freeze(FrozenMap.prototype);\n\nObject.freeze(FrozenSet);\nObject.freeze(FrozenSet.prototype);\n\nexport { FrozenMap, FrozenSet };\n"],"mappings":";;;;;;;AAAA;AAMA,IAAM,YAAN,MAA+D;AAAA,EAW7D,YAAY,SAAqD;AAVjE,uBAAS,MAAT;AAWE,uBAAK,MAAO,IAAI,IAAgB,OAAO;AACvC,WAAO,OAAO,IAAI;AAAA,EACpB;AAAA,EAXA,IAAW,OAAO;AAChB,WAAO,mBAAK,MAAK;AAAA,EACnB;AAAA,EAEA,CAAQ,OAAO,QAAQ,IAAI;AACzB,WAAO,mBAAK,MAAK,OAAO,QAAQ,EAAE;AAAA,EACpC;AAAA,EAOO,UAAU;AACf,WAAO,mBAAK,MAAK,QAAQ;AAAA,EAC3B;AAAA,EAEO,QACL,YACA,SACM;AAGN,WAAO,mBAAK,MAAK;AAAA,MAAQ,CAAC,OAAc,KAAUA,UAChD,WAAW,KAAK,SAAS,OAAO,KAAK,IAAI;AAAA,IAC3C;AAAA,EACF;AAAA,EAEO,IAAI,KAAU;AACnB,WAAO,mBAAK,MAAK,IAAI,GAAG;AAAA,EAC1B;AAAA,EAEO,IAAI,KAAU;AACnB,WAAO,mBAAK,MAAK,IAAI,GAAG;AAAA,EAC1B;AAAA,EAEO,OAAO;AACZ,WAAO,mBAAK,MAAK,KAAK;AAAA,EACxB;AAAA,EAEO,SAAS;AACd,WAAO,mBAAK,MAAK,OAAO;AAAA,EAC1B;AAAA,EAEO,WAAmB;AACxB,WAAO,aAAa,KAAK,IAAI,MAC3B,KAAK,OAAO,IACR,IAAI,CAAC,GAAG,KAAK,QAAQ,CAAC,EACnB,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,OAAO,GAAG,CAAC,OAAO,OAAO,KAAK,CAAC,EAAE,EAC1D,KAAK,IAAI,CAAC,MACb,EACN;AAAA,EACF;AACF;AAvDW;AAPX;AAsEA,IAAM,YAAN,MAAqD;AAAA,EAWnD,YAAY,QAAkC;AAV9C,uBAAS,MAAT;AAWE,uBAAK,MAAO,IAAI,IAAW,MAAM;AACjC,WAAO,OAAO,IAAI;AAAA,EACpB;AAAA,EAXA,IAAW,OAAO;AAChB,WAAO,mBAAK,MAAK;AAAA,EACnB;AAAA,EAEA,CAAQ,OAAO,QAAQ,IAAI;AACzB,WAAO,mBAAK,MAAK,OAAO,QAAQ,EAAE;AAAA,EACpC;AAAA,EAOO,UAAU;AACf,WAAO,mBAAK,MAAK,QAAQ;AAAA,EAC3B;AAAA,EAEO,QACL,YACA,SACM;AAGN,WAAO,mBAAK,MAAK;AAAA,MAAQ,CAAC,OAAc,QAAeC,UACrD,WAAW,KAAK,SAAS,OAAO,QAAQ,IAAI;AAAA,IAC9C;AAAA,EACF;AAAA,EAEO,IAAI,OAAc;AACvB,WAAO,mBAAK,MAAK,IAAI,KAAK;AAAA,EAC5B;AAAA,EAEO,OAAO;AACZ,WAAO,mBAAK,MAAK,KAAK;AAAA,EACxB;AAAA,EAEO,SAAS;AACd,WAAO,mBAAK,MAAK,OAAO;AAAA,EAC1B;AAAA,EAEO,WAAmB;AACxB,WAAO,aAAa,KAAK,IAAI,MAC3B,KAAK,OAAO,IACR,IAAI,CAAC,GAAG,KAAK,OAAO,CAAC,EAAE,IAAI,CAAC,WAAW,OAAO,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC,MACjE,EACN;AAAA,EACF;AACF;AAjDW;AAmDX,OAAO,OAAO,SAAS;AACvB,OAAO,OAAO,UAAU,SAAS;AAEjC,OAAO,OAAO,SAAS;AACvB,OAAO,OAAO,UAAU,SAAS;","names":["_map","_set"]}
@@ -0,0 +1 @@
1
+ "use strict";//# sourceMappingURL=chunk-LC2CRSWD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ import {
2
+ base64
3
+ } from "./chunk-HLDWS2JR.mjs";
4
+
5
+ // src/checksum.ts
6
+ import { size, string } from "superstruct";
7
+ var ChecksumStruct = size(
8
+ base64(string(), { paddingRequired: true }),
9
+ 44,
10
+ 44
11
+ );
12
+
13
+ export {
14
+ ChecksumStruct
15
+ };
16
+ //# sourceMappingURL=chunk-N53OILN6.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/checksum.ts"],"sourcesContent":["import { size, string } from 'superstruct';\n\nimport { base64 } from './base64';\n\nexport const ChecksumStruct = size(\n base64(string(), { paddingRequired: true }),\n 44,\n 44,\n);\n"],"mappings":";;;;;AAAA,SAAS,MAAM,cAAc;AAItB,IAAM,iBAAiB;AAAA,EAC5B,OAAO,OAAO,GAAG,EAAE,iBAAiB,KAAK,CAAC;AAAA,EAC1C;AAAA,EACA;AACF;","names":[]}
@@ -0,0 +1,70 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/misc.ts
2
+ function isNonEmptyArray(value) {
3
+ return Array.isArray(value) && value.length > 0;
4
+ }
5
+ function isNullOrUndefined(value) {
6
+ return value === null || value === void 0;
7
+ }
8
+ function isObject(value) {
9
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
10
+ }
11
+ var hasProperty = (objectToCheck, name) => Object.hasOwnProperty.call(objectToCheck, name);
12
+ function getKnownPropertyNames(object) {
13
+ return Object.getOwnPropertyNames(object);
14
+ }
15
+ var JsonSize = /* @__PURE__ */ ((JsonSize2) => {
16
+ JsonSize2[JsonSize2["Null"] = 4] = "Null";
17
+ JsonSize2[JsonSize2["Comma"] = 1] = "Comma";
18
+ JsonSize2[JsonSize2["Wrapper"] = 1] = "Wrapper";
19
+ JsonSize2[JsonSize2["True"] = 4] = "True";
20
+ JsonSize2[JsonSize2["False"] = 5] = "False";
21
+ JsonSize2[JsonSize2["Quote"] = 1] = "Quote";
22
+ JsonSize2[JsonSize2["Colon"] = 1] = "Colon";
23
+ JsonSize2[JsonSize2["Date"] = 24] = "Date";
24
+ return JsonSize2;
25
+ })(JsonSize || {});
26
+ var ESCAPE_CHARACTERS_REGEXP = /"|\\|\n|\r|\t/gu;
27
+ function isPlainObject(value) {
28
+ if (typeof value !== "object" || value === null) {
29
+ return false;
30
+ }
31
+ try {
32
+ let proto = value;
33
+ while (Object.getPrototypeOf(proto) !== null) {
34
+ proto = Object.getPrototypeOf(proto);
35
+ }
36
+ return Object.getPrototypeOf(value) === proto;
37
+ } catch (_) {
38
+ return false;
39
+ }
40
+ }
41
+ function isASCII(character) {
42
+ return character.charCodeAt(0) <= 127;
43
+ }
44
+ function calculateStringSize(value) {
45
+ const size = value.split("").reduce((total, character) => {
46
+ if (isASCII(character)) {
47
+ return total + 1;
48
+ }
49
+ return total + 2;
50
+ }, 0);
51
+ return size + (_nullishCoalesce(value.match(ESCAPE_CHARACTERS_REGEXP), () => ( []))).length;
52
+ }
53
+ function calculateNumberSize(value) {
54
+ return value.toString().length;
55
+ }
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+ exports.isNonEmptyArray = isNonEmptyArray; exports.isNullOrUndefined = isNullOrUndefined; exports.isObject = isObject; exports.hasProperty = hasProperty; exports.getKnownPropertyNames = getKnownPropertyNames; exports.JsonSize = JsonSize; exports.ESCAPE_CHARACTERS_REGEXP = ESCAPE_CHARACTERS_REGEXP; exports.isPlainObject = isPlainObject; exports.isASCII = isASCII; exports.calculateStringSize = calculateStringSize; exports.calculateNumberSize = calculateNumberSize;
70
+ //# sourceMappingURL=chunk-QVEKZRZ2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/misc.ts"],"names":["JsonSize"],"mappings":";AAiDO,SAAS,gBACd,OACiC;AACjC,SAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS;AAChD;AAQO,SAAS,kBAAkB,OAA2C;AAC3E,SAAO,UAAU,QAAQ,UAAU;AACrC;AASO,SAAS,SAAS,OAAwC;AAC/D,SAAO,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAcO,IAAM,cAAc,CAKzB,eACA,SAKK,OAAO,eAAe,KAAK,eAAe,IAAI;AAa9C,SAAS,sBACd,QACO;AACP,SAAO,OAAO,oBAAoB,MAAM;AAC1C;AAOO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,aAAU,KAAV;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,WAAQ,KAAR;AAEA,EAAAA,oBAAA,UAAO,MAAP;AATU,SAAAA;AAAA,GAAA;AAeL,IAAM,2BAA2B;AASjC,SAAS,cAAc,OAAsC;AAClE,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AAEA,MAAI;AACF,QAAI,QAAQ;AACZ,WAAO,OAAO,eAAe,KAAK,MAAM,MAAM;AAC5C,cAAQ,OAAO,eAAe,KAAK;AAAA,IACrC;AAEA,WAAO,OAAO,eAAe,KAAK,MAAM;AAAA,EAC1C,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;AAQO,SAAS,QAAQ,WAAmB;AACzC,SAAO,UAAU,WAAW,CAAC,KAAK;AACpC;AAQO,SAAS,oBAAoB,OAAuB;AACzD,QAAM,OAAO,MAAM,MAAM,EAAE,EAAE,OAAO,CAAC,OAAO,cAAc;AACxD,QAAI,QAAQ,SAAS,GAAG;AACtB,aAAO,QAAQ;AAAA,IACjB;AACA,WAAO,QAAQ;AAAA,EACjB,GAAG,CAAC;AAGJ,SAAO,QAAQ,MAAM,MAAM,wBAAwB,KAAK,CAAC,GAAG;AAC9D;AAQO,SAAS,oBAAoB,OAAuB;AACzD,SAAO,MAAM,SAAS,EAAE;AAC1B","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"]}
@@ -0,0 +1,15 @@
1
+ // src/logging.ts
2
+ import debug from "debug";
3
+ var globalLogger = debug("metamask");
4
+ function createProjectLogger(projectName) {
5
+ return globalLogger.extend(projectName);
6
+ }
7
+ function createModuleLogger(projectLogger, moduleName) {
8
+ return projectLogger.extend(moduleName);
9
+ }
10
+
11
+ export {
12
+ createProjectLogger,
13
+ createModuleLogger
14
+ };
15
+ //# sourceMappingURL=chunk-RIRDOQPX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/logging.ts"],"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"],"mappings":";AACA,OAAO,WAAW;AAElB,IAAM,eAAe,MAAM,UAAU;AAc9B,SAAS,oBAAoB,aAA+B;AACjE,SAAO,aAAa,OAAO,WAAW;AACxC;AAgBO,SAAS,mBACd,eACA,YACU;AACV,SAAO,cAAc,OAAO,UAAU;AACxC;","names":[]}
@@ -0,0 +1 @@
1
+ "use strict";//# sourceMappingURL=chunk-RKRGAFXY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-RRYOWRCV.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,75 @@
1
+ // src/caip-types.ts
2
+ import { is, pattern, string } from "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 = pattern(string(), CAIP_CHAIN_ID_REGEX);
9
+ var CaipNamespaceStruct = pattern(string(), CAIP_NAMESPACE_REGEX);
10
+ var CaipReferenceStruct = pattern(string(), CAIP_REFERENCE_REGEX);
11
+ var CaipAccountIdStruct = pattern(string(), CAIP_ACCOUNT_ID_REGEX);
12
+ var CaipAccountAddressStruct = pattern(
13
+ string(),
14
+ CAIP_ACCOUNT_ADDRESS_REGEX
15
+ );
16
+ function isCaipChainId(value) {
17
+ return is(value, CaipChainIdStruct);
18
+ }
19
+ function isCaipNamespace(value) {
20
+ return is(value, CaipNamespaceStruct);
21
+ }
22
+ function isCaipReference(value) {
23
+ return is(value, CaipReferenceStruct);
24
+ }
25
+ function isCaipAccountId(value) {
26
+ return is(value, CaipAccountIdStruct);
27
+ }
28
+ function isCaipAccountAddress(value) {
29
+ return is(value, CaipAccountAddressStruct);
30
+ }
31
+ function parseCaipChainId(caipChainId) {
32
+ const match = CAIP_CHAIN_ID_REGEX.exec(caipChainId);
33
+ if (!match?.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 (!match?.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
+ export {
57
+ CAIP_CHAIN_ID_REGEX,
58
+ CAIP_NAMESPACE_REGEX,
59
+ CAIP_REFERENCE_REGEX,
60
+ CAIP_ACCOUNT_ID_REGEX,
61
+ CAIP_ACCOUNT_ADDRESS_REGEX,
62
+ CaipChainIdStruct,
63
+ CaipNamespaceStruct,
64
+ CaipReferenceStruct,
65
+ CaipAccountIdStruct,
66
+ CaipAccountAddressStruct,
67
+ isCaipChainId,
68
+ isCaipNamespace,
69
+ isCaipReference,
70
+ isCaipAccountId,
71
+ isCaipAccountAddress,
72
+ parseCaipChainId,
73
+ parseCaipAccountId
74
+ };
75
+ //# sourceMappingURL=chunk-TGOMTREC.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/caip-types.ts"],"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"],"mappings":";AACA,SAAS,IAAI,SAAS,cAAc;AAE7B,IAAM,sBACX;AAEK,IAAM,uBAAuB;AAE7B,IAAM,uBAAuB;AAE7B,IAAM,wBACX;AAEK,IAAM,6BAA6B;AAKnC,IAAM,oBAAoB,QAAQ,OAAO,GAAG,mBAAmB;AAM/D,IAAM,sBAAsB,QAAQ,OAAO,GAAG,oBAAoB;AAMlE,IAAM,sBAAsB,QAAQ,OAAO,GAAG,oBAAoB;AAMlE,IAAM,sBAAsB,QAAQ,OAAO,GAAG,qBAAqB;AAMnE,IAAM,2BAA2B;AAAA,EACtC,OAAO;AAAA,EACP;AACF;AASO,SAAS,cAAc,OAAsC;AAClE,SAAO,GAAG,OAAO,iBAAiB;AACpC;AAQO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,GAAG,OAAO,mBAAmB;AACtC;AAQO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,GAAG,OAAO,mBAAmB;AACtC;AAQO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,GAAG,OAAO,mBAAmB;AACtC;AAQO,SAAS,qBACd,OAC6B;AAC7B,SAAO,GAAG,OAAO,wBAAwB;AAC3C;AASO,SAAS,iBAAiB,aAG/B;AACA,QAAM,QAAQ,oBAAoB,KAAK,WAAW;AAClD,MAAI,CAAC,OAAO,QAAQ;AAClB,UAAM,IAAI,MAAM,wBAAwB;AAAA,EAC1C;AAEA,SAAO;AAAA,IACL,WAAW,MAAM,OAAO;AAAA,IACxB,WAAW,MAAM,OAAO;AAAA,EAC1B;AACF;AASO,SAAS,mBAAmB,eAIjC;AACA,QAAM,QAAQ,sBAAsB,KAAK,aAAa;AACtD,MAAI,CAAC,OAAO,QAAQ;AAClB,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC5C;AAEA,SAAO;AAAA,IACL,SAAS,MAAM,OAAO;AAAA,IACtB,SAAS,MAAM,OAAO;AAAA,IACtB,OAAO;AAAA,MACL,WAAW,MAAM,OAAO;AAAA,MACxB,WAAW,MAAM,OAAO;AAAA,IAC1B;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,34 @@
1
+ // src/time.ts
2
+ var Duration = /* @__PURE__ */ ((Duration2) => {
3
+ Duration2[Duration2["Millisecond"] = 1] = "Millisecond";
4
+ Duration2[Duration2["Second"] = 1e3] = "Second";
5
+ Duration2[Duration2["Minute"] = 6e4] = "Minute";
6
+ Duration2[Duration2["Hour"] = 36e5] = "Hour";
7
+ Duration2[Duration2["Day"] = 864e5] = "Day";
8
+ Duration2[Duration2["Week"] = 6048e5] = "Week";
9
+ Duration2[Duration2["Year"] = 31536e6] = "Year";
10
+ return Duration2;
11
+ })(Duration || {});
12
+ var isNonNegativeInteger = (number) => Number.isInteger(number) && number >= 0;
13
+ var assertIsNonNegativeInteger = (number, name) => {
14
+ if (!isNonNegativeInteger(number)) {
15
+ throw new Error(
16
+ `"${name}" must be a non-negative integer. Received: "${number}".`
17
+ );
18
+ }
19
+ };
20
+ function inMilliseconds(count, duration) {
21
+ assertIsNonNegativeInteger(count, "count");
22
+ return count * duration;
23
+ }
24
+ function timeSince(timestamp) {
25
+ assertIsNonNegativeInteger(timestamp, "timestamp");
26
+ return Date.now() - timestamp;
27
+ }
28
+
29
+ export {
30
+ Duration,
31
+ inMilliseconds,
32
+ timeSince
33
+ };
34
+ //# sourceMappingURL=chunk-THNLGEXV.mjs.map
@@ -0,0 +1 @@
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"]}