@metamask-previews/utils 11.12.1-preview-c44fd50 → 11.12.1-preview-2caaa71

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 (282) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/{assert.d.mts → assert.d.ts} +2 -2
  3. package/dist/assert.d.ts.map +1 -0
  4. package/dist/{assert.mjs → assert.js} +4 -4
  5. package/dist/assert.js.map +1 -0
  6. package/dist/{base64.d.cts → base64.d.ts} +2 -2
  7. package/dist/base64.d.ts.map +1 -0
  8. package/dist/{base64.mjs → base64.js} +3 -3
  9. package/dist/base64.js.map +1 -0
  10. package/dist/{bytes.d.cts → bytes.d.ts} +2 -2
  11. package/dist/bytes.d.ts.map +1 -0
  12. package/dist/{bytes.mjs → bytes.js} +4 -4
  13. package/dist/bytes.js.map +1 -0
  14. package/dist/{caip-types.d.cts → caip-types.d.ts} +2 -2
  15. package/dist/caip-types.d.ts.map +1 -0
  16. package/dist/{caip-types.mjs → caip-types.js} +2 -2
  17. package/dist/caip-types.js.map +1 -0
  18. package/dist/{checksum.d.cts → checksum.d.ts} +1 -1
  19. package/dist/checksum.d.ts.map +1 -0
  20. package/dist/checksum.js +4 -0
  21. package/dist/checksum.js.map +1 -0
  22. package/dist/{coercers.d.cts → coercers.d.ts} +4 -4
  23. package/dist/coercers.d.ts.map +1 -0
  24. package/dist/{coercers.mjs → coercers.js} +5 -5
  25. package/dist/coercers.js.map +1 -0
  26. package/dist/{collections.d.cts → collections.d.ts} +9 -9
  27. package/dist/collections.d.ts.map +1 -0
  28. package/dist/collections.js +93 -0
  29. package/dist/collections.js.map +1 -0
  30. package/dist/{encryption-types.d.cts → encryption-types.d.ts} +1 -1
  31. package/dist/encryption-types.d.ts.map +1 -0
  32. package/dist/encryption-types.js +2 -0
  33. package/dist/encryption-types.js.map +1 -0
  34. package/dist/{errors.d.mts → errors.d.ts} +1 -1
  35. package/dist/errors.d.ts.map +1 -0
  36. package/dist/{errors.mjs → errors.js} +4 -10
  37. package/dist/errors.js.map +1 -0
  38. package/dist/{fs.d.cts → fs.d.ts} +2 -2
  39. package/dist/fs.d.ts.map +1 -0
  40. package/dist/{fs.mjs → fs.js} +7 -7
  41. package/dist/fs.js.map +1 -0
  42. package/dist/{hashing.d.cts → hashing.d.ts} +1 -1
  43. package/dist/hashing.d.ts.map +1 -0
  44. package/dist/{hashing.mjs → hashing.js} +8 -3
  45. package/dist/hashing.js.map +1 -0
  46. package/dist/{hex.d.cts → hex.d.ts} +5 -6
  47. package/dist/hex.d.ts.map +1 -0
  48. package/dist/{hex.mjs → hex.js} +5 -6
  49. package/dist/hex.js.map +1 -0
  50. package/dist/index.d.ts +26 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +21 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/{json.d.cts → json.d.ts} +19 -29
  55. package/dist/json.d.ts.map +1 -0
  56. package/dist/{json.mjs → json.js} +5 -4
  57. package/dist/json.js.map +1 -0
  58. package/dist/{keyring.d.mts → keyring.d.ts} +5 -5
  59. package/dist/keyring.d.ts.map +1 -0
  60. package/dist/keyring.js +2 -0
  61. package/dist/keyring.js.map +1 -0
  62. package/dist/{logging.d.cts → logging.d.ts} +2 -2
  63. package/dist/logging.d.ts.map +1 -0
  64. package/dist/{logging.mjs → logging.js} +2 -9
  65. package/dist/logging.js.map +1 -0
  66. package/dist/{misc.d.mts → misc.d.ts} +1 -1
  67. package/dist/misc.d.ts.map +1 -0
  68. package/dist/{misc.mjs → misc.js} +1 -1
  69. package/dist/misc.js.map +1 -0
  70. package/dist/{mnemonic.d.cts → mnemonic.d.ts} +1 -1
  71. package/dist/mnemonic.d.ts.map +1 -0
  72. package/dist/{mnemonic.mjs → mnemonic.js} +2 -2
  73. package/dist/mnemonic.js.map +1 -0
  74. package/dist/node.d.ts +3 -0
  75. package/dist/node.d.ts.map +1 -0
  76. package/dist/node.js +3 -0
  77. package/dist/node.js.map +1 -0
  78. package/dist/{number.d.mts → number.d.ts} +2 -2
  79. package/dist/number.d.ts.map +1 -0
  80. package/dist/{number.mjs → number.js} +3 -3
  81. package/dist/number.js.map +1 -0
  82. package/dist/{opaque.d.cts → opaque.d.ts} +1 -1
  83. package/dist/opaque.d.ts.map +1 -0
  84. package/dist/opaque.js +2 -0
  85. package/dist/opaque.js.map +1 -0
  86. package/dist/{promise.d.cts → promise.d.ts} +1 -1
  87. package/dist/promise.d.ts.map +1 -0
  88. package/dist/{promise.mjs → promise.js} +1 -1
  89. package/dist/promise.js.map +1 -0
  90. package/dist/{superstruct.d.mts → superstruct.d.ts} +2 -2
  91. package/dist/superstruct.d.ts.map +1 -0
  92. package/dist/{superstruct.mjs → superstruct.js} +2 -2
  93. package/dist/superstruct.js.map +1 -0
  94. package/dist/{time.d.mts → time.d.ts} +1 -1
  95. package/dist/time.d.ts.map +1 -0
  96. package/dist/{time.mjs → time.js} +1 -1
  97. package/dist/time.js.map +1 -0
  98. package/dist/{transaction-types.d.cts → transaction-types.d.ts} +3 -3
  99. package/dist/transaction-types.d.ts.map +1 -0
  100. package/dist/transaction-types.js +2 -0
  101. package/dist/transaction-types.js.map +1 -0
  102. package/dist/{unitsConversion.d.cts → unitsConversion.d.ts} +28 -28
  103. package/dist/unitsConversion.d.ts.map +1 -0
  104. package/dist/{unitsConversion.mjs → unitsConversion.js} +1 -1
  105. package/dist/unitsConversion.js.map +1 -0
  106. package/dist/{versions.d.mts → versions.d.ts} +3 -3
  107. package/dist/versions.d.ts.map +1 -0
  108. package/dist/{versions.mjs → versions.js} +4 -4
  109. package/dist/versions.js.map +1 -0
  110. package/package.json +21 -30
  111. package/dist/assert.cjs +0 -122
  112. package/dist/assert.cjs.map +0 -1
  113. package/dist/assert.d.cts +0 -61
  114. package/dist/assert.d.cts.map +0 -1
  115. package/dist/assert.d.mts.map +0 -1
  116. package/dist/assert.mjs.map +0 -1
  117. package/dist/base64.cjs +0 -34
  118. package/dist/base64.cjs.map +0 -1
  119. package/dist/base64.d.cts.map +0 -1
  120. package/dist/base64.d.mts +0 -25
  121. package/dist/base64.d.mts.map +0 -1
  122. package/dist/base64.mjs.map +0 -1
  123. package/dist/bytes.cjs +0 -427
  124. package/dist/bytes.cjs.map +0 -1
  125. package/dist/bytes.d.cts.map +0 -1
  126. package/dist/bytes.d.mts +0 -198
  127. package/dist/bytes.d.mts.map +0 -1
  128. package/dist/bytes.mjs.map +0 -1
  129. package/dist/caip-types.cjs +0 -390
  130. package/dist/caip-types.cjs.map +0 -1
  131. package/dist/caip-types.d.cts.map +0 -1
  132. package/dist/caip-types.d.mts +0 -294
  133. package/dist/caip-types.d.mts.map +0 -1
  134. package/dist/caip-types.mjs.map +0 -1
  135. package/dist/checksum.cjs +0 -7
  136. package/dist/checksum.cjs.map +0 -1
  137. package/dist/checksum.d.cts.map +0 -1
  138. package/dist/checksum.d.mts +0 -2
  139. package/dist/checksum.d.mts.map +0 -1
  140. package/dist/checksum.mjs +0 -4
  141. package/dist/checksum.mjs.map +0 -1
  142. package/dist/coercers.cjs +0 -166
  143. package/dist/coercers.cjs.map +0 -1
  144. package/dist/coercers.d.cts.map +0 -1
  145. package/dist/coercers.d.mts +0 -97
  146. package/dist/coercers.d.mts.map +0 -1
  147. package/dist/coercers.mjs.map +0 -1
  148. package/dist/collections.cjs +0 -109
  149. package/dist/collections.cjs.map +0 -1
  150. package/dist/collections.d.cts.map +0 -1
  151. package/dist/collections.d.mts +0 -39
  152. package/dist/collections.d.mts.map +0 -1
  153. package/dist/collections.mjs +0 -105
  154. package/dist/collections.mjs.map +0 -1
  155. package/dist/encryption-types.cjs +0 -3
  156. package/dist/encryption-types.cjs.map +0 -1
  157. package/dist/encryption-types.d.cts.map +0 -1
  158. package/dist/encryption-types.d.mts +0 -7
  159. package/dist/encryption-types.d.mts.map +0 -1
  160. package/dist/encryption-types.mjs +0 -2
  161. package/dist/encryption-types.mjs.map +0 -1
  162. package/dist/errors.cjs +0 -129
  163. package/dist/errors.cjs.map +0 -1
  164. package/dist/errors.d.cts +0 -68
  165. package/dist/errors.d.cts.map +0 -1
  166. package/dist/errors.d.mts.map +0 -1
  167. package/dist/errors.mjs.map +0 -1
  168. package/dist/fs.cjs +0 -248
  169. package/dist/fs.cjs.map +0 -1
  170. package/dist/fs.d.cts.map +0 -1
  171. package/dist/fs.d.mts +0 -133
  172. package/dist/fs.d.mts.map +0 -1
  173. package/dist/fs.mjs.map +0 -1
  174. package/dist/hashing.cjs +0 -60
  175. package/dist/hashing.cjs.map +0 -1
  176. package/dist/hashing.d.cts.map +0 -1
  177. package/dist/hashing.d.mts +0 -28
  178. package/dist/hashing.d.mts.map +0 -1
  179. package/dist/hashing.mjs.map +0 -1
  180. package/dist/hex.cjs +0 -188
  181. package/dist/hex.cjs.map +0 -1
  182. package/dist/hex.d.cts.map +0 -1
  183. package/dist/hex.d.mts +0 -118
  184. package/dist/hex.d.mts.map +0 -1
  185. package/dist/hex.mjs.map +0 -1
  186. package/dist/index.cjs +0 -58
  187. package/dist/index.cjs.map +0 -1
  188. package/dist/index.d.cts +0 -26
  189. package/dist/index.d.cts.map +0 -1
  190. package/dist/index.d.mts +0 -26
  191. package/dist/index.d.mts.map +0 -1
  192. package/dist/index.mjs +0 -21
  193. package/dist/index.mjs.map +0 -1
  194. package/dist/json.cjs +0 -425
  195. package/dist/json.cjs.map +0 -1
  196. package/dist/json.d.cts.map +0 -1
  197. package/dist/json.d.mts +0 -398
  198. package/dist/json.d.mts.map +0 -1
  199. package/dist/json.mjs.map +0 -1
  200. package/dist/keyring.cjs +0 -3
  201. package/dist/keyring.cjs.map +0 -1
  202. package/dist/keyring.d.cts +0 -243
  203. package/dist/keyring.d.cts.map +0 -1
  204. package/dist/keyring.d.mts.map +0 -1
  205. package/dist/keyring.mjs +0 -2
  206. package/dist/keyring.mjs.map +0 -1
  207. package/dist/logging.cjs +0 -43
  208. package/dist/logging.cjs.map +0 -1
  209. package/dist/logging.d.cts.map +0 -1
  210. package/dist/logging.d.mts +0 -30
  211. package/dist/logging.d.mts.map +0 -1
  212. package/dist/logging.mjs.map +0 -1
  213. package/dist/misc.cjs +0 -154
  214. package/dist/misc.cjs.map +0 -1
  215. package/dist/misc.d.cts +0 -127
  216. package/dist/misc.d.cts.map +0 -1
  217. package/dist/misc.d.mts.map +0 -1
  218. package/dist/misc.mjs.map +0 -1
  219. package/dist/mnemonic.cjs +0 -53
  220. package/dist/mnemonic.cjs.map +0 -1
  221. package/dist/mnemonic.d.cts.map +0 -1
  222. package/dist/mnemonic.d.mts +0 -14
  223. package/dist/mnemonic.d.mts.map +0 -1
  224. package/dist/mnemonic.mjs.map +0 -1
  225. package/dist/node.cjs +0 -19
  226. package/dist/node.cjs.map +0 -1
  227. package/dist/node.d.cts +0 -3
  228. package/dist/node.d.cts.map +0 -1
  229. package/dist/node.d.mts +0 -3
  230. package/dist/node.d.mts.map +0 -1
  231. package/dist/node.mjs +0 -3
  232. package/dist/node.mjs.map +0 -1
  233. package/dist/number.cjs +0 -102
  234. package/dist/number.cjs.map +0 -1
  235. package/dist/number.d.cts +0 -74
  236. package/dist/number.d.cts.map +0 -1
  237. package/dist/number.d.mts.map +0 -1
  238. package/dist/number.mjs.map +0 -1
  239. package/dist/opaque.cjs +0 -3
  240. package/dist/opaque.cjs.map +0 -1
  241. package/dist/opaque.d.cts.map +0 -1
  242. package/dist/opaque.d.mts +0 -6
  243. package/dist/opaque.d.mts.map +0 -1
  244. package/dist/opaque.mjs +0 -2
  245. package/dist/opaque.mjs.map +0 -1
  246. package/dist/promise.cjs +0 -44
  247. package/dist/promise.cjs.map +0 -1
  248. package/dist/promise.d.cts.map +0 -1
  249. package/dist/promise.d.mts +0 -45
  250. package/dist/promise.d.mts.map +0 -1
  251. package/dist/promise.mjs.map +0 -1
  252. package/dist/superstruct.cjs +0 -28
  253. package/dist/superstruct.cjs.map +0 -1
  254. package/dist/superstruct.d.cts +0 -20
  255. package/dist/superstruct.d.cts.map +0 -1
  256. package/dist/superstruct.d.mts.map +0 -1
  257. package/dist/superstruct.mjs.map +0 -1
  258. package/dist/time.cjs +0 -67
  259. package/dist/time.cjs.map +0 -1
  260. package/dist/time.d.cts +0 -49
  261. package/dist/time.d.cts.map +0 -1
  262. package/dist/time.d.mts.map +0 -1
  263. package/dist/time.mjs.map +0 -1
  264. package/dist/transaction-types.cjs +0 -3
  265. package/dist/transaction-types.cjs.map +0 -1
  266. package/dist/transaction-types.d.cts.map +0 -1
  267. package/dist/transaction-types.d.mts +0 -117
  268. package/dist/transaction-types.d.mts.map +0 -1
  269. package/dist/transaction-types.mjs +0 -2
  270. package/dist/transaction-types.mjs.map +0 -1
  271. package/dist/unitsConversion.cjs +0 -217
  272. package/dist/unitsConversion.cjs.map +0 -1
  273. package/dist/unitsConversion.d.cts.map +0 -1
  274. package/dist/unitsConversion.d.mts +0 -80
  275. package/dist/unitsConversion.d.mts.map +0 -1
  276. package/dist/unitsConversion.mjs.map +0 -1
  277. package/dist/versions.cjs +0 -95
  278. package/dist/versions.cjs.map +0 -1
  279. package/dist/versions.d.cts +0 -101
  280. package/dist/versions.d.cts.map +0 -1
  281. package/dist/versions.d.mts.map +0 -1
  282. package/dist/versions.mjs.map +0 -1
@@ -1,294 +0,0 @@
1
- import type { Infer } from "@metamask/superstruct";
2
- export declare const CAIP_CHAIN_ID_REGEX: RegExp;
3
- export declare const CAIP_NAMESPACE_REGEX: RegExp;
4
- export declare const CAIP_REFERENCE_REGEX: RegExp;
5
- export declare const CAIP_ACCOUNT_ID_REGEX: RegExp;
6
- export declare const CAIP_ACCOUNT_ADDRESS_REGEX: RegExp;
7
- export declare const CAIP_ASSET_NAMESPACE_REGEX: RegExp;
8
- export declare const CAIP_ASSET_REFERENCE_REGEX: RegExp;
9
- export declare const CAIP_TOKEN_ID_REGEX: RegExp;
10
- export declare const CAIP_ASSET_TYPE_REGEX: RegExp;
11
- export declare const CAIP_ASSET_ID_REGEX: RegExp;
12
- /**
13
- * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.
14
- */
15
- export declare const CaipChainIdStruct: import("@metamask/superstruct").Struct<`${string}:${string}`, null>;
16
- export type CaipChainId = Infer<typeof CaipChainIdStruct>;
17
- /**
18
- * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.
19
- */
20
- export declare const CaipNamespaceStruct: import("@metamask/superstruct").Struct<string, null>;
21
- export type CaipNamespace = Infer<typeof CaipNamespaceStruct>;
22
- /**
23
- * A CAIP-2 reference, i.e., the second part of a CAIP chain ID.
24
- */
25
- export declare const CaipReferenceStruct: import("@metamask/superstruct").Struct<string, null>;
26
- export type CaipReference = Infer<typeof CaipReferenceStruct>;
27
- /**
28
- * A CAIP-10 account ID, i.e., a human-readable namespace, reference, and account address.
29
- */
30
- export declare const CaipAccountIdStruct: import("@metamask/superstruct").Struct<`${string}:${string}:${string}`, null>;
31
- export type CaipAccountId = Infer<typeof CaipAccountIdStruct>;
32
- /**
33
- * A CAIP-10 account address, i.e., the third part of the CAIP account ID.
34
- */
35
- export declare const CaipAccountAddressStruct: import("@metamask/superstruct").Struct<string, null>;
36
- export type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;
37
- /**
38
- * A CAIP-19 asset namespace, i.e., a namespace domain of an asset.
39
- */
40
- export declare const CaipAssetNamespaceStruct: import("@metamask/superstruct").Struct<string, null>;
41
- export type CaipAssetNamespace = Infer<typeof CaipAssetNamespaceStruct>;
42
- /**
43
- * A CAIP-19 asset reference, i.e., an identifier for an asset within a given namespace.
44
- */
45
- export declare const CaipAssetReferenceStruct: import("@metamask/superstruct").Struct<string, null>;
46
- export type CaipAssetReference = Infer<typeof CaipAssetReferenceStruct>;
47
- /**
48
- * A CAIP-19 asset token ID, i.e., a unique identifier for an addressable asset of a given type
49
- */
50
- export declare const CaipTokenIdStruct: import("@metamask/superstruct").Struct<string, null>;
51
- export type CaipTokenId = Infer<typeof CaipTokenIdStruct>;
52
- /**
53
- * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.
54
- */
55
- export declare const CaipAssetTypeStruct: import("@metamask/superstruct").Struct<`${string}:${string}/${string}:${string}`, null>;
56
- export type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;
57
- /**
58
- * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.
59
- */
60
- export declare const CaipAssetIdStruct: import("@metamask/superstruct").Struct<`${string}:${string}/${string}:${string}/${string}`, null>;
61
- export type CaipAssetId = Infer<typeof CaipAssetIdStruct>;
62
- /**
63
- * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.
64
- */
65
- export declare const CaipAssetTypeOrIdStruct: import("@metamask/superstruct").Struct<`${string}:${string}/${string}:${string}` | `${string}:${string}/${string}:${string}/${string}`, null>;
66
- export type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;
67
- /** Known CAIP namespaces. */
68
- export declare enum KnownCaipNamespace {
69
- /** BIP-122 (Bitcoin) compatible chains. */
70
- Bip122 = "bip122",
71
- /** Solana compatible chains */
72
- Solana = "solana",
73
- /** Stellar compatible chains */
74
- Stellar = "stellar",
75
- /** Tron compatible chains */
76
- Tron = "tron",
77
- /** EIP-155 compatible chains. */
78
- Eip155 = "eip155",
79
- Wallet = "wallet"
80
- }
81
- /**
82
- * A CAIP-2 chain ID that is guaranteed to have a known CAIP namespace
83
- * (@see {@link KnownCaipNamespace}).
84
- *
85
- * This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases
86
- * where the chain namespace must be one of the known standards.
87
- *
88
- * @template Namespace - The namespace of the CAIP-2 chain ID. Must be a known namespace specified in {@link KnownCaipNamespace}.
89
- */
90
- export type KnownCaipNamespacedChainId<Namespace extends `${KnownCaipNamespace}` = `${KnownCaipNamespace}`> = `${Namespace}:${string}`;
91
- /**
92
- * Check if the given value is a {@link CaipChainId}.
93
- *
94
- * @param value - The value to check.
95
- * @returns Whether the value is a {@link CaipChainId}.
96
- */
97
- export declare function isCaipChainId(value: unknown): value is CaipChainId;
98
- /**
99
- * Check if the given value is a {@link CaipNamespace}.
100
- *
101
- * @param value - The value to check.
102
- * @returns Whether the value is a {@link CaipNamespace}.
103
- */
104
- export declare function isCaipNamespace(value: unknown): value is CaipNamespace;
105
- /**
106
- * Check if the given value is a {@link CaipReference}.
107
- *
108
- * @param value - The value to check.
109
- * @returns Whether the value is a {@link CaipReference}.
110
- */
111
- export declare function isCaipReference(value: unknown): value is CaipReference;
112
- /**
113
- * Check if the given value is a {@link CaipAccountId}.
114
- *
115
- * @param value - The value to check.
116
- * @returns Whether the value is a {@link CaipAccountId}.
117
- */
118
- export declare function isCaipAccountId(value: unknown): value is CaipAccountId;
119
- /**
120
- * Check if a value is a {@link CaipAccountAddress}.
121
- *
122
- * @param value - The value to validate.
123
- * @returns True if the value is a valid {@link CaipAccountAddress}.
124
- */
125
- export declare function isCaipAccountAddress(value: unknown): value is CaipAccountAddress;
126
- /**
127
- * Check if the given value is a {@link CaipAssetNamespace}.
128
- *
129
- * @param value - The value to check.
130
- * @returns Whether the value is a {@link CaipAssetNamespace}.
131
- */
132
- export declare function isCaipAssetNamespace(value: unknown): value is CaipAssetNamespace;
133
- /**
134
- * Check if the given value is a {@link CaipAssetReference}.
135
- *
136
- * @param value - The value to check.
137
- * @returns Whether the value is a {@link CaipAssetReference}.
138
- */
139
- export declare function isCaipAssetReference(value: unknown): value is CaipAssetReference;
140
- /**
141
- * Check if the given value is a {@link CaipTokenId}.
142
- *
143
- * @param value - The value to check.
144
- * @returns Whether the value is a {@link CaipTokenId}.
145
- */
146
- export declare function isCaipTokenId(value: unknown): value is CaipTokenId;
147
- /**
148
- * Check if the given value is a {@link CaipAssetType}.
149
- *
150
- * @param value - The value to check.
151
- * @returns Whether the value is a {@link CaipAssetType}.
152
- */
153
- export declare function isCaipAssetType(value: unknown): value is CaipAssetType;
154
- /**
155
- * Check if the given value is a {@link CaipAssetId}.
156
- *
157
- * @param value - The value to check.
158
- * @returns Whether the value is a {@link CaipAssetId}.
159
- */
160
- export declare function isCaipAssetId(value: unknown): value is CaipAssetId;
161
- /**
162
- * Parse a CAIP-2 chain ID to an object containing the namespace and reference.
163
- * This validates the CAIP-2 chain ID before parsing it.
164
- *
165
- * @param caipChainId - The CAIP-2 chain ID to validate and parse.
166
- * @returns The parsed CAIP-2 chain ID.
167
- */
168
- export declare function parseCaipChainId(caipChainId: CaipChainId): {
169
- namespace: CaipNamespace;
170
- reference: CaipReference;
171
- };
172
- /**
173
- * Parse an CAIP-10 account ID to an object containing the chain ID, parsed chain ID, and account address.
174
- * This validates the CAIP-10 account ID before parsing it.
175
- *
176
- * @param caipAccountId - The CAIP-10 account ID to validate and parse.
177
- * @returns The parsed CAIP-10 account ID.
178
- */
179
- export declare function parseCaipAccountId(caipAccountId: CaipAccountId): {
180
- address: CaipAccountAddress;
181
- chainId: CaipChainId;
182
- chain: {
183
- namespace: CaipNamespace;
184
- reference: CaipReference;
185
- };
186
- };
187
- /**
188
- * Parse a CAIP-19 asset type to an object containing the chain ID, parsed chain ID,
189
- * asset namespace, and asset reference
190
- *
191
- * This validates the CAIP-19 asset type before parsing it.
192
- *
193
- * @param caipAssetType - The CAIP-19 asset type to validate and parse.
194
- * @returns The parsed CAIP-19 asset type.
195
- */
196
- export declare function parseCaipAssetType(caipAssetType: CaipAssetType): {
197
- assetNamespace: CaipAssetNamespace;
198
- assetReference: CaipAssetReference;
199
- chainId: CaipChainId;
200
- chain: {
201
- namespace: CaipNamespace;
202
- reference: CaipReference;
203
- };
204
- };
205
- /**
206
- * Parse a CAIP-19 asset ID to an object containing the chain ID, parsed chain ID,
207
- * asset namespace, asset reference, and token ID.
208
- *
209
- * This validates the CAIP-19 asset ID before parsing it.
210
- *
211
- * @param caipAssetId - The CAIP-19 asset ID to validate and parse.
212
- * @returns The parsed CAIP-19 asset ID.
213
- */
214
- export declare function parseCaipAssetId(caipAssetId: CaipAssetId): {
215
- assetNamespace: CaipAssetNamespace;
216
- assetReference: CaipAssetReference;
217
- tokenId: CaipTokenId;
218
- chainId: CaipChainId;
219
- chain: {
220
- namespace: CaipNamespace;
221
- reference: CaipReference;
222
- };
223
- };
224
- /**
225
- * Chain ID as defined per the CAIP-2
226
- * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md}.
227
- *
228
- * It defines a way to uniquely identify any blockchain in a human-readable
229
- * way.
230
- *
231
- * @param namespace - The standard (ecosystem) of similar blockchains.
232
- * @param reference - Identify of a blockchain within a given namespace.
233
- * @throws {@link Error}
234
- * This exception is thrown if the inputs does not comply with the CAIP-2
235
- * syntax specification
236
- * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md#syntax}.
237
- * @returns A CAIP chain ID.
238
- */
239
- export declare function toCaipChainId(namespace: CaipNamespace, reference: CaipReference): CaipChainId;
240
- /**
241
- * Account ID as defined per the CAIP-10
242
- * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md}.
243
- *
244
- * It defines a way to uniquely identify any blockchain account in a human-readable
245
- * way.
246
- *
247
- * @param namespace - The standard (ecosystem) of similar blockchains.
248
- * @param reference - Identity of a blockchain within a given namespace.
249
- * @param accountAddress - The address of the blockchain account.
250
- * @throws {@link Error}
251
- * This exception is thrown if the inputs do not comply with the CAIP-10
252
- * syntax specification
253
- * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md#syntax}.
254
- * @returns A CAIP account ID.
255
- */
256
- export declare function toCaipAccountId(namespace: CaipNamespace, reference: CaipReference, accountAddress: CaipAccountAddress): CaipAccountId;
257
- /**
258
- * Asset Type as defined per the CAIP-19
259
- * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.
260
- *
261
- * It defines a way to uniquely identify any blockchain asset in a human-readable
262
- * way.
263
- *
264
- * @param namespace - The standard (ecosystem) of similar blockchains.
265
- * @param reference - Identity of a blockchain within a given namespace.
266
- * @param assetNamespace - The namespace domain of an asset.
267
- * @param assetReference - The identity of an asset within a given namespace.
268
- * @throws {@link Error}
269
- * This exception is thrown if the inputs do not comply with the CAIP-19
270
- * syntax specification
271
- * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.
272
- * @returns A CAIP asset type.
273
- */
274
- export declare function toCaipAssetType(namespace: CaipNamespace, reference: CaipReference, assetNamespace: CaipAssetNamespace, assetReference: CaipAssetReference): CaipAssetType;
275
- /**
276
- * Asset ID as defined per the CAIP-19
277
- * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.
278
- *
279
- * It defines a way to uniquely identify any blockchain asset in a human-readable
280
- * way.
281
- *
282
- * @param namespace - The standard (ecosystem) of similar blockchains.
283
- * @param reference - Identity of a blockchain within a given namespace.
284
- * @param assetNamespace - The namespace domain of an asset.
285
- * @param assetReference - The identity of an asset within a given namespace.
286
- * @param tokenId - The unique identifier for an addressable asset of a given type.
287
- * @throws {@link Error}
288
- * This exception is thrown if the inputs do not comply with the CAIP-19
289
- * syntax specification
290
- * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.
291
- * @returns A CAIP asset ID.
292
- */
293
- export declare function toCaipAssetId(namespace: CaipNamespace, reference: CaipReference, assetNamespace: CaipAssetNamespace, assetReference: CaipAssetReference, tokenId: CaipTokenId): CaipAssetId;
294
- //# sourceMappingURL=caip-types.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"caip-types.d.mts","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAInD,eAAO,MAAM,mBAAmB,QACqC,CAAC;AAEtE,eAAO,MAAM,oBAAoB,QAAsB,CAAC;AAExD,eAAO,MAAM,oBAAoB,QAA2B,CAAC;AAE7D,eAAO,MAAM,qBAAqB,QACwF,CAAC;AAE3H,eAAO,MAAM,0BAA0B,QAA6B,CAAC;AAErE,eAAO,MAAM,0BAA0B,QAAsB,CAAC;AAE9D,eAAO,MAAM,0BAA0B,QAA6B,CAAC;AAErE,eAAO,MAAM,mB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,CAAC;IAED,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CACb,yCAAyC,0BAA0B,CAAC,QAAQ,EAAE,EAAE,CACjF,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,kCAAkC,mBAAmB,CAAC,QAAQ,EAAE,EAAE,CACnE,CAAC;IACJ,CAAC;IAED,OAAO,GAAG,SAAS,IAAI,SAAS,IAAI,cAAc,IAAI,cAAc,IAAI,OAAO,EAAE,CAAC;AACpF,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\n\nimport { definePattern } 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\nexport const CAIP_ASSET_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;\n\nexport const CAIP_ASSET_REFERENCE_REGEX = /^[-.%a-zA-Z0-9]{1,128}$/u;\n\nexport const CAIP_TOKEN_ID_REGEX = /^[-.%a-zA-Z0-9]{1,78}$/u;\n\nexport const CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nexport const CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\nconst CAIP_ASSET_TYPE_OR_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})(\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78}))?$/u;\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const CaipChainIdStruct = definePattern<`${string}:${string}`>(\n 'CaipChainId',\n CAIP_CHAIN_ID_REGEX,\n);\nexport type CaipChainId = Infer<typeof CaipChainIdStruct>;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a CAIP chain ID.\n */\nexport const CaipNamespaceStruct = definePattern(\n 'CaipNamespace',\n CAIP_NAMESPACE_REGEX,\n);\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 = definePattern(\n 'CaipReference',\n CAIP_REFERENCE_REGEX,\n);\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 =\n definePattern<`${string}:${string}:${string}`>(\n 'CaipAccountId',\n CAIP_ACCOUNT_ID_REGEX,\n );\nexport type CaipAccountId = Infer<typeof CaipAccountIdStruct>;\n\n/**\n * A CAIP-10 account address, i.e., the third part of the CAIP account ID.\n */\nexport const CaipAccountAddressStruct = definePattern(\n 'CaipAccountAddress',\n CAIP_ACCOUNT_ADDRESS_REGEX,\n);\nexport type CaipAccountAddress = Infer<typeof CaipAccountAddressStruct>;\n\n/**\n * A CAIP-19 asset namespace, i.e., a namespace domain of an asset.\n */\nexport const CaipAssetNamespaceStruct = definePattern(\n 'CaipAssetNamespace',\n CAIP_ASSET_NAMESPACE_REGEX,\n);\nexport type CaipAssetNamespace = Infer<typeof CaipAssetNamespaceStruct>;\n\n/**\n * A CAIP-19 asset reference, i.e., an identifier for an asset within a given namespace.\n */\nexport const CaipAssetReferenceStruct = definePattern(\n 'CaipAssetReference',\n CAIP_ASSET_REFERENCE_REGEX,\n);\nexport type CaipAssetReference = Infer<typeof CaipAssetReferenceStruct>;\n\n/**\n * A CAIP-19 asset token ID, i.e., a unique identifier for an addressable asset of a given type\n */\nexport const CaipTokenIdStruct = definePattern(\n 'CaipTokenId',\n CAIP_TOKEN_ID_REGEX,\n);\nexport type CaipTokenId = Infer<typeof CaipTokenIdStruct>;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct =\n definePattern<`${string}:${string}/${string}:${string}`>(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n );\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct =\n definePattern<`${string}:${string}/${string}:${string}/${string}`>(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n );\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * A CAIP-19 asset type or asset ID identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeOrIdStruct = definePattern<\n CaipAssetType | CaipAssetId\n>('CaipAssetTypeOrId', CAIP_ASSET_TYPE_OR_ID_REGEX);\nexport type CaipAssetTypeOrId = Infer<typeof CaipAssetTypeOrIdStruct>;\n\n/** Known CAIP namespaces. */\nexport enum KnownCaipNamespace {\n /** BIP-122 (Bitcoin) compatible chains. */\n Bip122 = 'bip122',\n /** Solana compatible chains */\n Solana = 'solana',\n /** Stellar compatible chains */\n Stellar = 'stellar',\n /** Tron compatible chains */\n Tron = 'tron',\n /** EIP-155 compatible chains. */\n Eip155 = 'eip155',\n Wallet = 'wallet',\n}\n\n/**\n * A CAIP-2 chain ID that is guaranteed to have a known CAIP namespace\n * (@see {@link KnownCaipNamespace}).\n *\n * This is a narrower, more type-safe alternative to {@link CaipChainId} for use cases\n * where the chain namespace must be one of the known standards.\n *\n * @template Namespace - The namespace of the CAIP-2 chain ID. Must be a known namespace specified in {@link KnownCaipNamespace}.\n */\nexport type KnownCaipNamespacedChainId<\n Namespace extends `${KnownCaipNamespace}` = `${KnownCaipNamespace}`,\n> = `${Namespace}:${string}`;\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 typeof value === 'string' && CAIP_CHAIN_ID_REGEX.test(value);\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 typeof value === 'string' && CAIP_NAMESPACE_REGEX.test(value);\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 typeof value === 'string' && CAIP_REFERENCE_REGEX.test(value);\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 typeof value === 'string' && CAIP_ACCOUNT_ID_REGEX.test(value);\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 typeof value === 'string' && CAIP_ACCOUNT_ADDRESS_REGEX.test(value);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetNamespace}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetNamespace}.\n */\nexport function isCaipAssetNamespace(\n value: unknown,\n): value is CaipAssetNamespace {\n return typeof value === 'string' && CAIP_ASSET_NAMESPACE_REGEX.test(value);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetReference}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetReference}.\n */\nexport function isCaipAssetReference(\n value: unknown,\n): value is CaipAssetReference {\n return typeof value === 'string' && CAIP_ASSET_REFERENCE_REGEX.test(value);\n}\n\n/**\n * Check if the given value is a {@link CaipTokenId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipTokenId}.\n */\nexport function isCaipTokenId(value: unknown): value is CaipTokenId {\n return typeof value === 'string' && CAIP_TOKEN_ID_REGEX.test(value);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return typeof value === 'string' && CAIP_ASSET_TYPE_REGEX.test(value);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return typeof value === 'string' && CAIP_ASSET_ID_REGEX.test(value);\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\n/**\n * Parse a CAIP-19 asset type to an object containing the chain ID, parsed chain ID,\n * asset namespace, and asset reference\n *\n * This validates the CAIP-19 asset type before parsing it.\n *\n * @param caipAssetType - The CAIP-19 asset type to validate and parse.\n * @returns The parsed CAIP-19 asset type.\n */\nexport function parseCaipAssetType(caipAssetType: CaipAssetType): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_TYPE_REGEX.exec(caipAssetType);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset type.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\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\n/**\n * Parse a CAIP-19 asset ID to an object containing the chain ID, parsed chain ID,\n * asset namespace, asset reference, and token ID.\n *\n * This validates the CAIP-19 asset ID before parsing it.\n *\n * @param caipAssetId - The CAIP-19 asset ID to validate and parse.\n * @returns The parsed CAIP-19 asset ID.\n */\nexport function parseCaipAssetId(caipAssetId: CaipAssetId): {\n assetNamespace: CaipAssetNamespace;\n assetReference: CaipAssetReference;\n tokenId: CaipTokenId;\n chainId: CaipChainId;\n chain: { namespace: CaipNamespace; reference: CaipReference };\n} {\n const match = CAIP_ASSET_ID_REGEX.exec(caipAssetId);\n if (!match?.groups) {\n throw new Error('Invalid CAIP asset ID.');\n }\n\n return {\n assetNamespace: match.groups.assetNamespace as CaipAssetNamespace,\n assetReference: match.groups.assetReference as CaipAssetReference,\n tokenId: match.groups.tokenId as CaipTokenId,\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\n/**\n * Chain ID as defined per the CAIP-2\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md}.\n *\n * It defines a way to uniquely identify any blockchain in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identify of a blockchain within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs does not comply with the CAIP-2\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md#syntax}.\n * @returns A CAIP chain ID.\n */\nexport function toCaipChainId(\n namespace: CaipNamespace,\n reference: CaipReference,\n): CaipChainId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}`;\n}\n\n/**\n * Account ID as defined per the CAIP-10\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md}.\n *\n * It defines a way to uniquely identify any blockchain account in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param accountAddress - The address of the blockchain account.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-10\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md#syntax}.\n * @returns A CAIP account ID.\n */\nexport function toCaipAccountId(\n namespace: CaipNamespace,\n reference: CaipReference,\n accountAddress: CaipAccountAddress,\n): CaipAccountId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAccountAddress(accountAddress)) {\n throw new Error(\n `Invalid \"accountAddress\", must match: ${CAIP_ACCOUNT_ADDRESS_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}:${accountAddress}`;\n}\n\n/**\n * Asset Type as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset type.\n */\nexport function toCaipAssetType(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n): CaipAssetType {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}`;\n}\n\n/**\n * Asset ID as defined per the CAIP-19\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md}.\n *\n * It defines a way to uniquely identify any blockchain asset in a human-readable\n * way.\n *\n * @param namespace - The standard (ecosystem) of similar blockchains.\n * @param reference - Identity of a blockchain within a given namespace.\n * @param assetNamespace - The namespace domain of an asset.\n * @param assetReference - The identity of an asset within a given namespace.\n * @param tokenId - The unique identifier for an addressable asset of a given type.\n * @throws {@link Error}\n * This exception is thrown if the inputs do not comply with the CAIP-19\n * syntax specification\n * {@link https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md#syntax}.\n * @returns A CAIP asset ID.\n */\nexport function toCaipAssetId(\n namespace: CaipNamespace,\n reference: CaipReference,\n assetNamespace: CaipAssetNamespace,\n assetReference: CaipAssetReference,\n tokenId: CaipTokenId,\n): CaipAssetId {\n if (!isCaipNamespace(namespace)) {\n throw new Error(\n `Invalid \"namespace\", must match: ${CAIP_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipReference(reference)) {\n throw new Error(\n `Invalid \"reference\", must match: ${CAIP_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetNamespace(assetNamespace)) {\n throw new Error(\n `Invalid \"assetNamespace\", must match: ${CAIP_ASSET_NAMESPACE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipAssetReference(assetReference)) {\n throw new Error(\n `Invalid \"assetReference\", must match: ${CAIP_ASSET_REFERENCE_REGEX.toString()}`,\n );\n }\n\n if (!isCaipTokenId(tokenId)) {\n throw new Error(\n `Invalid \"tokenId\", must match: ${CAIP_TOKEN_ID_REGEX.toString()}`,\n );\n }\n\n return `${namespace}:${reference}/${assetNamespace}:${assetReference}/${tokenId}`;\n}\n"]}
package/dist/checksum.cjs DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChecksumStruct = void 0;
4
- const superstruct_1 = require("@metamask/superstruct");
5
- const base64_1 = require("./base64.cjs");
6
- exports.ChecksumStruct = (0, superstruct_1.size)((0, base64_1.base64)((0, superstruct_1.string)(), { paddingRequired: true }), 44, 44);
7
- //# sourceMappingURL=checksum.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"checksum.cjs","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAErD,yCAAkC;AAErB,QAAA,cAAc,GAAG,IAAA,kBAAI,EAChC,IAAA,eAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,EAC3C,EAAE,EACF,EAAE,CACH,CAAC","sourcesContent":["import { size, string } from '@metamask/superstruct';\n\nimport { base64 } from './base64';\n\nexport const ChecksumStruct = size(\n base64(string(), { paddingRequired: true }),\n 44,\n 44,\n);\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"checksum.d.cts","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,sDAI1B,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const ChecksumStruct: import("@metamask/superstruct").Struct<string, null>;
2
- //# sourceMappingURL=checksum.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"checksum.d.mts","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,sDAI1B,CAAC"}
package/dist/checksum.mjs DELETED
@@ -1,4 +0,0 @@
1
- import { size, string } from "@metamask/superstruct";
2
- import { base64 } from "./base64.mjs";
3
- export const ChecksumStruct = size(base64(string(), { paddingRequired: true }), 44, 44);
4
- //# sourceMappingURL=checksum.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"checksum.mjs","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,8BAA8B;AAErD,OAAO,EAAE,MAAM,EAAE,qBAAiB;AAElC,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAChC,MAAM,CAAC,MAAM,EAAE,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,EAC3C,EAAE,EACF,EAAE,CACH,CAAC","sourcesContent":["import { size, string } from '@metamask/superstruct';\n\nimport { base64 } from './base64';\n\nexport const ChecksumStruct = size(\n base64(string(), { paddingRequired: true }),\n 44,\n 44,\n);\n"]}
package/dist/coercers.cjs DELETED
@@ -1,166 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createHex = exports.createBytes = exports.createBigInt = exports.createNumber = void 0;
4
- const superstruct_1 = require("@metamask/superstruct");
5
- const assert_1 = require("./assert.cjs");
6
- const bytes_1 = require("./bytes.cjs");
7
- const hex_1 = require("./hex.cjs");
8
- const NumberLikeStruct = (0, superstruct_1.union)([(0, superstruct_1.number)(), (0, superstruct_1.bigint)(), (0, superstruct_1.string)(), hex_1.StrictHexStruct]);
9
- const NumberCoercer = (0, superstruct_1.coerce)((0, superstruct_1.number)(), NumberLikeStruct, Number);
10
- const BigIntCoercer = (0, superstruct_1.coerce)((0, superstruct_1.bigint)(), NumberLikeStruct, BigInt);
11
- // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Only referenced via `Infer<typeof ...>` below, but the value is required for that.
12
- const BytesLikeStruct = (0, superstruct_1.union)([hex_1.StrictHexStruct, (0, superstruct_1.instance)(Uint8Array)]);
13
- const BytesCoercer = (0, superstruct_1.coerce)((0, superstruct_1.instance)(Uint8Array), (0, superstruct_1.union)([hex_1.StrictHexStruct]), bytes_1.hexToBytes);
14
- const HexCoercer = (0, superstruct_1.coerce)(hex_1.StrictHexStruct, (0, superstruct_1.instance)(Uint8Array), bytes_1.bytesToHex);
15
- /**
16
- * Create a number from a number-like value.
17
- *
18
- * - If the value is a number, it is returned as-is.
19
- * - If the value is a `bigint`, it is converted to a number.
20
- * - If the value is a string, it is interpreted as a decimal number.
21
- * - If the value is a hex string (i.e., it starts with "0x"), it is
22
- * interpreted as a hexadecimal number.
23
- *
24
- * This validates that the value is a number-like value, and that the resulting
25
- * number is not `NaN` or `Infinity`.
26
- *
27
- * @example
28
- * ```typescript
29
- * const value = createNumber('0x010203');
30
- * console.log(value); // 66051
31
- *
32
- * const otherValue = createNumber(123n);
33
- * console.log(otherValue); // 123
34
- * ```
35
- * @param value - The value to create the number from.
36
- * @returns The created number.
37
- * @throws If the value is not a number-like value, or if the resulting number
38
- * is `NaN` or `Infinity`.
39
- */
40
- function createNumber(value) {
41
- try {
42
- const result = (0, superstruct_1.create)(value, NumberCoercer);
43
- (0, assert_1.assert)(Number.isFinite(result), `Expected a number-like value, got "${value}".`);
44
- return result;
45
- }
46
- catch (error) {
47
- if (error instanceof superstruct_1.StructError) {
48
- throw new Error(`Expected a number-like value, got "${value}".`);
49
- }
50
- /* istanbul ignore next */
51
- throw error;
52
- }
53
- }
54
- exports.createNumber = createNumber;
55
- /**
56
- * Create a `bigint` from a number-like value.
57
- *
58
- * - If the value is a number, it is converted to a `bigint`.
59
- * - If the value is a `bigint`, it is returned as-is.
60
- * - If the value is a string, it is interpreted as a decimal number and
61
- * converted to a `bigint`.
62
- * - If the value is a hex string (i.e., it starts with "0x"), it is
63
- * interpreted as a hexadecimal number and converted to a `bigint`.
64
- *
65
- * @example
66
- * ```typescript
67
- * const value = createBigInt('0x010203');
68
- * console.log(value); // 16909060n
69
- *
70
- * const otherValue = createBigInt(123);
71
- * console.log(otherValue); // 123n
72
- * ```
73
- * @param value - The value to create the bigint from.
74
- * @returns The created bigint.
75
- * @throws If the value is not a number-like value.
76
- */
77
- function createBigInt(value) {
78
- try {
79
- // The `BigInt` constructor throws if the value is not a number-like value.
80
- // There is no need to validate the value manually.
81
- return (0, superstruct_1.create)(value, BigIntCoercer);
82
- }
83
- catch (error) {
84
- /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */
85
- if (error instanceof superstruct_1.StructError) {
86
- throw new Error(`Expected a number-like value, got "${String(error.value)}".`);
87
- }
88
- /* istanbul ignore next */
89
- throw error;
90
- }
91
- }
92
- exports.createBigInt = createBigInt;
93
- /**
94
- * Create a byte array from a bytes-like value.
95
- *
96
- * - If the value is a byte array, it is returned as-is.
97
- * - If the value is a hex string (i.e., it starts with "0x"), it is interpreted
98
- * as a hexadecimal number and converted to a byte array.
99
- *
100
- * @example
101
- * ```typescript
102
- * const value = createBytes('0x010203');
103
- * console.log(value); // Uint8Array [ 1, 2, 3 ]
104
- *
105
- * const otherValue = createBytes('0x010203');
106
- * console.log(otherValue); // Uint8Array [ 1, 2, 3 ]
107
- * ```
108
- * @param value - The value to create the byte array from.
109
- * @returns The created byte array.
110
- * @throws If the value is not a bytes-like value.
111
- */
112
- function createBytes(value) {
113
- if (typeof value === 'string' && value.toLowerCase() === '0x') {
114
- return new Uint8Array();
115
- }
116
- try {
117
- return (0, superstruct_1.create)(value, BytesCoercer);
118
- }
119
- catch (error) {
120
- /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */
121
- if (error instanceof superstruct_1.StructError) {
122
- throw new Error(`Expected a bytes-like value, got "${String(error.value)}".`);
123
- }
124
- /* istanbul ignore next */
125
- throw error;
126
- }
127
- }
128
- exports.createBytes = createBytes;
129
- /**
130
- * Create a hexadecimal string from a bytes-like value.
131
- *
132
- * - If the value is a hex string (i.e., it starts with "0x"), it is returned
133
- * as-is.
134
- * - If the value is a `Uint8Array`, it is converted to a hex string.
135
- *
136
- * @example
137
- * ```typescript
138
- * const value = createHex(new Uint8Array([1, 2, 3]));
139
- * console.log(value); // '0x010203'
140
- *
141
- * const otherValue = createHex('0x010203');
142
- * console.log(otherValue); // '0x010203'
143
- * ```
144
- * @param value - The value to create the hex string from.
145
- * @returns The created hex string.
146
- * @throws If the value is not a bytes-like value.
147
- */
148
- function createHex(value) {
149
- if ((value instanceof Uint8Array && value.length === 0) ||
150
- (typeof value === 'string' && value.toLowerCase() === '0x')) {
151
- return '0x';
152
- }
153
- try {
154
- return (0, superstruct_1.create)(value, HexCoercer);
155
- }
156
- catch (error) {
157
- /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */
158
- if (error instanceof superstruct_1.StructError) {
159
- throw new Error(`Expected a bytes-like value, got "${String(error.value)}".`);
160
- }
161
- /* istanbul ignore next */
162
- throw error;
163
- }
164
- }
165
- exports.createHex = createHex;
166
- //# sourceMappingURL=coercers.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"coercers.cjs","sourceRoot":"","sources":["../src/coercers.ts"],"names":[],"mappings":";;;AACA,uDAS+B;AAE/B,yCAAkC;AAClC,uCAAiD;AAEjD,mCAAwC;AAExC,MAAM,gBAAgB,GAAG,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,oBAAM,GAAE,EAAE,IAAA,oBAAM,GAAE,EAAE,qBAAe,CAAC,CAAC,CAAC;AAChF,MAAM,aAAa,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;AACjE,MAAM,aAAa,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;AAEjE,mJAAmJ;AACnJ,MAAM,eAAe,GAAG,IAAA,mBAAK,EAAC,CAAC,qBAAe,EAAE,IAAA,sBAAQ,EAAC,UAAU,CAAC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["import type { Infer } from '@metamask/superstruct';\nimport {\n bigint,\n coerce,\n create,\n instance,\n number,\n string,\n StructError,\n union,\n} from '@metamask/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\n// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Only referenced via `Infer<typeof ...>` below, but the value is required for that.\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 /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */\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 /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */\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 /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */\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"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"coercers.d.cts","sourceRoot":"","sources":["../src/coercers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAcnD,OAAO,KAAK,EAAE,GAAG,EAAE,kBAAc;AAGjC,QAAA,MAAM,gBAAgB,wEAAyD,CAAC;AAKhF,QAAA,MAAM,eAAe,0EAAiD,CAAC;AASvE,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AACxD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAkBtD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAgBtD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,CAkBxD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,GAAG,CAqB/C"}