@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
package/CHANGELOG.md CHANGED
@@ -9,8 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Changed
11
11
 
12
+ - **BREAKING:** Bump the TypeScript `target` and `lib` to `ES2022` ([#332](https://github.com/MetaMask/utils/pull/332))
13
+ - Emitted output now uses ES2022 syntax, matching core. Consumers on the supported Node range are unaffected.
12
14
  - **BREAKING:** Drop support for Node 18 and 20 ([#328](https://github.com/MetaMask/utils/pull/328))
13
15
  - The supported range is now `^22.14.0 || ^24`, matching core.
16
+ - **BREAKING:** The package is now ESM only ([#323](https://github.com/MetaMask/utils/pull/323))
17
+ - The CommonJS build is gone. `require('@metamask/utils')` now fails with `ERR_REQUIRE_ESM`; use `import` instead.
18
+ - `main` and `module` are removed. Both `.` and `./node` resolve through `exports` to a single `./dist/*.js` with `./dist/*.d.ts` types.
19
+ - Consumers already using `import` are unaffected.
14
20
  - Bump `@ethereumjs/tx` from `^4.2.0` to `^5.4.0` ([#321](https://github.com/MetaMask/utils/pull/321))
15
21
  - The deprecated `Keyring.signTransaction` now returns `LegacyTxData` rather than `TxData`. These describe the same shape: `@ethereumjs/tx@5` repurposed the name `TxData` for a map keyed by transaction type and renamed the old meaning to `LegacyTxData`. Implementations do not need changing.
16
22
  - Bump `@metamask/scure-bip39` from `^2.0.3` to `^2.1.1` ([#311](https://github.com/MetaMask/utils/pull/311))
@@ -1,4 +1,4 @@
1
- import type { Struct } from "@metamask/superstruct";
1
+ import type { Struct } from '@metamask/superstruct';
2
2
  export type AssertionErrorConstructor = (new (args: {
3
3
  message: string;
4
4
  }) => Error) | ((args: {
@@ -58,4 +58,4 @@ export declare function assertStruct<Type, Schema>(value: unknown, struct: Struc
58
58
  * @param _object - The object on which the switch is being operated.
59
59
  */
60
60
  export declare function assertExhaustive(_object: never): never;
61
- //# sourceMappingURL=assert.d.mts.map
61
+ //# sourceMappingURL=assert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAKpD,MAAM,MAAM,yBAAyB,GACjC,CAAC,KAAK,IAAI,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,KAAK,KAAK,CAAC,GAC1C,CAAC,CAAC,IAAI,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,KAAK,KAAK,CAAC,CAAC;AAiD3C;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,mBAAmB;IAEhC,YAAY,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,EAEvC;CACF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CACpB,KAAK,EAAE,GAAG,EACV,OAAO,GAAE,MAAM,GAAG,KAA2B,EAC7C,YAAY,GAAE,yBAA0C,GACvD,OAAO,CAAC,KAAK,CAQf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EACvC,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,EAC5B,WAAW,SAAqB,EAChC,YAAY,GAAE,yBAA0C,GACvD,OAAO,CAAC,KAAK,IAAI,IAAI,CASvB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,KAAK,GAAG,KAAK,CAItD"}
@@ -1,5 +1,5 @@
1
- import { assert as assertSuperstruct } from "@metamask/superstruct";
2
- import { getErrorMessage } from "./errors.mjs";
1
+ import { assert as assertSuperstruct } from '@metamask/superstruct';
2
+ import { getErrorMessage } from './errors.js';
3
3
  /**
4
4
  * Check if a value is a constructor, i.e., a function that can be called with
5
5
  * the `new` keyword.
@@ -46,9 +46,9 @@ function getError(ErrorWrapper, message) {
46
46
  * The default error class that is thrown if an assertion fails.
47
47
  */
48
48
  export class AssertionError extends Error {
49
+ code = 'ERR_ASSERTION';
49
50
  constructor(options) {
50
51
  super(options.message);
51
- this.code = 'ERR_ASSERTION';
52
52
  }
53
53
  }
54
54
  /**
@@ -112,4 +112,4 @@ export function assertStruct(value, struct, errorPrefix = 'Assertion failed', Er
112
112
  export function assertExhaustive(_object) {
113
113
  throw new Error('Invalid branch reached. Should be detected during compilation.');
114
114
  }
115
- //# sourceMappingURL=assert.mjs.map
115
+ //# sourceMappingURL=assert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AA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C;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,QAAQ,CACZ,YAAY,EACZ,GAAG,WAAW,KAAK,oCAAoC,CAAC,KAAK,CAAC,GAAG,CAClE,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAc;IAC7C,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;AACJ,CAAC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport { assert as assertSuperstruct } from '@metamask/superstruct';\n\nimport { getErrorMessage } from './errors.js';\n\nexport type AssertionErrorConstructor =\n | (new (args: { message: string }) => Error)\n | ((args: { message: string }) => Error);\n\n/**\n * Check if a value is a constructor, i.e., a function that can be called with\n * the `new` keyword.\n *\n * @param fn - The value to check.\n * @returns `true` if the value is a constructor, or `false` otherwise.\n */\nfunction isConstructable(\n fn: AssertionErrorConstructor,\n): fn is new (args: { message: string }) => Error {\n /* istanbul ignore next */\n return Boolean(typeof fn?.prototype?.constructor?.name === 'string');\n}\n\n/**\n * Attempts to obtain the message from a possible error object. If it is\n * possible to do so, any trailing period will be removed from the message;\n * otherwise an empty string is returned.\n *\n * @param error - The error object to get the message from.\n * @returns The message without any trailing period if `error` is an object\n * with a `message` property; the string version of `error` without any trailing\n * period if it is not `undefined` or `null`; otherwise an empty string.\n */\nfunction getErrorMessageWithoutTrailingPeriod(error: unknown): string {\n // We'll add our own period.\n return getErrorMessage(error).replace(/\\.$/u, '');\n}\n\n/**\n * Initialise an {@link AssertionErrorConstructor} error.\n *\n * @param ErrorWrapper - The error class to use.\n * @param message - The error message.\n * @returns The error object.\n */\nfunction getError(ErrorWrapper: AssertionErrorConstructor, message: string) {\n if (isConstructable(ErrorWrapper)) {\n return new ErrorWrapper({\n message,\n });\n }\n return ErrorWrapper({\n message,\n });\n}\n\n/**\n * The default error class that is thrown if an assertion fails.\n */\nexport class AssertionError extends Error {\n readonly code = 'ERR_ASSERTION';\n\n constructor(options: { message: string }) {\n super(options.message);\n }\n}\n\n/**\n * Same as Node.js assert.\n * If the value is falsy, throws an error, does nothing otherwise.\n *\n * @throws {@link AssertionError} If value is falsy.\n * @param value - The test that should be truthy to pass.\n * @param message - Message to be passed to {@link AssertionError} or an\n * {@link Error} instance to throw.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}. If a custom error class is provided for\n * the `message` argument, this argument is ignored.\n */\nexport function assert(\n value: any,\n message: string | Error = 'Assertion failed.',\n ErrorWrapper: AssertionErrorConstructor = AssertionError,\n): asserts value {\n if (!value) {\n if (message instanceof Error) {\n throw message;\n }\n\n throw getError(ErrorWrapper, message);\n }\n}\n\n/**\n * Assert a value against a Superstruct struct.\n *\n * @param value - The value to validate.\n * @param struct - The struct to validate against.\n * @param errorPrefix - A prefix to add to the error message. Defaults to\n * \"Assertion failed\".\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the value is not valid.\n */\nexport function assertStruct<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n errorPrefix = 'Assertion failed',\n ErrorWrapper: AssertionErrorConstructor = AssertionError,\n): asserts value is Type {\n try {\n assertSuperstruct(value, struct);\n } catch (error) {\n throw getError(\n ErrorWrapper,\n `${errorPrefix}: ${getErrorMessageWithoutTrailingPeriod(error)}.`,\n );\n }\n}\n\n/**\n * Use in the default case of a switch that you want to be fully exhaustive.\n * Using this function forces the compiler to enforce exhaustivity during\n * compile-time.\n *\n * @example\n * ```\n * const number = 1;\n * switch (number) {\n * case 0:\n * ...\n * case 1:\n * ...\n * default:\n * assertExhaustive(snapPrefix);\n * }\n * ```\n * @param _object - The object on which the switch is being operated.\n */\nexport function assertExhaustive(_object: never): never {\n throw new Error(\n 'Invalid branch reached. Should be detected during compilation.',\n );\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { Struct } from "@metamask/superstruct";
1
+ import type { Struct } from '@metamask/superstruct';
2
2
  export type Base64Options = {
3
3
  /**
4
4
  * Is the `=` padding at the end required or not.
@@ -22,4 +22,4 @@ export type Base64Options = {
22
22
  * @returns A superstruct validating base64.
23
23
  */
24
24
  export declare const base64: <Type extends string, Schema>(struct: Struct<Type, Schema>, options?: Base64Options) => Struct<Type, Schema>;
25
- //# sourceMappingURL=base64.d.cts.map
25
+ //# sourceMappingURL=base64.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAKpD,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;OAIG;IAEH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;CACvC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,GAAI,IAAI,SAAS,MAAM,EAAE,MAAM,UACxC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,YACnB,aAAa,yBA2BvB,CAAC"}
@@ -1,5 +1,5 @@
1
- import { pattern } from "@metamask/superstruct";
2
- import { assert } from "./assert.mjs";
1
+ import { pattern } from '@metamask/superstruct';
2
+ import { assert } from './assert.js';
3
3
  /**
4
4
  * Ensure that a provided string-based struct is valid base64.
5
5
  *
@@ -27,4 +27,4 @@ export const base64 = (struct, options = {}) => {
27
27
  }
28
28
  return pattern(struct, re);
29
29
  };
30
- //# sourceMappingURL=base64.mjs.map
30
+ //# sourceMappingURL=base64.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.js","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAmBrC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,MAA4B,EAC5B,OAAO,GAAkB,EAAE,EAC3B,EAAE;IACF,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,KAAK,CAAC;IACzD,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,QAAQ,CAAC;IAEtD,IAAI,OAAe,CAAC;IACpB,IAAI,YAAY,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,GAAG,MAAM,CAAC,GAAG,CAAA,gBAAgB,CAAC;IACvC,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,YAAY,KAAK,WAAW,CAAC,CAAC;QACrC,OAAO,GAAG,MAAM,CAAC,GAAG,CAAA,eAAe,CAAC;IACtC,CAAC;IAED,IAAI,EAAU,CAAC;IACf,IAAI,eAAe,EAAE,CAAC;QACpB,EAAE,GAAG,IAAI,MAAM,CACb,OAAO,OAAO,WAAW,OAAO,QAAQ,OAAO,UAAU,EACzD,GAAG,CACJ,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,EAAE,GAAG,IAAI,MAAM,CACb,OAAO,OAAO,WAAW,OAAO,SAAS,OAAO,QAAQ,OAAO,UAAU,EACzE,GAAG,CACJ,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC,CAAC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport { pattern } from '@metamask/superstruct';\n\nimport { assert } from './assert.js';\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"]}
@@ -1,4 +1,4 @@
1
- import type { Hex } from "./hex.cjs";
1
+ import type { Hex } from './hex.js';
2
2
  export type Bytes = bigint | number | string | Uint8Array;
3
3
  /**
4
4
  * Check if a value is a `Uint8Array`.
@@ -195,4 +195,4 @@ export declare function createDataView(bytes: Uint8Array): DataView;
195
195
  * @returns Whether the Uint8Arrays are equal.
196
196
  */
197
197
  export declare function areUint8ArraysEqual(a: Uint8Array, b: Uint8Array): boolean;
198
- //# sourceMappingURL=bytes.d.cts.map
198
+ //# sourceMappingURL=bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAUpC,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;AAwC1D;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,UAAU,CAEz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H,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAe1D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAazE"}
@@ -1,6 +1,6 @@
1
- import { base64 } from "@scure/base";
2
- import { assert } from "./assert.mjs";
3
- import { add0x, assertIsHexString, remove0x } from "./hex.mjs";
1
+ import { base64 } from '@scure/base';
2
+ import { assert } from './assert.js';
3
+ import { add0x, assertIsHexString, remove0x } from './hex.js';
4
4
  // '0'.charCodeAt(0) === 48
5
5
  const HEX_MINIMUM_NUMBER_CHARACTER = 48;
6
6
  // '9'.charCodeAt(0) === 57
@@ -403,4 +403,4 @@ export function areUint8ArraysEqual(a, b) {
403
403
  }
404
404
  return diff === 0;
405
405
  }
406
- //# sourceMappingURL=bytes.mjs.map
406
+ //# sourceMappingURL=bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE9D,2BAA2B;AAC3B,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAExC,2BAA2B;AAC3B,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAIhC;;;;;;;;;;;;;GAaG;AACH,SAAS,8BAA8B;IACrC,6EAA6E;IAC7E,6EAA6E;IAC7E,6EAA6E;IAC7E,eAAe;IACf,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,OAAO,GAAG,EAAE;QACV,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,KAAK,IAAI,C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CAAC,CAAC;AACpB,CAAC","sourcesContent":["import { base64 } from '@scure/base';\n\nimport { assert } from './assert.js';\nimport type { Hex } from './hex.js';\nimport { add0x, assertIsHexString, remove0x } from './hex.js';\n\n// '0'.charCodeAt(0) === 48\nconst HEX_MINIMUM_NUMBER_CHARACTER = 48;\n\n// '9'.charCodeAt(0) === 57\nconst HEX_MAXIMUM_NUMBER_CHARACTER = 58;\nconst HEX_CHARACTER_OFFSET = 87;\n\nexport type Bytes = bigint | number | string | Uint8Array;\n\n/**\n * Memoized function that returns an array to be used as a lookup table for\n * converting bytes to hexadecimal values.\n *\n * The array is created lazily and then cached for future use. The benefit of\n * this approach is that the performance of converting bytes to hex is much\n * better than if we were to call `toString(16)` on each byte.\n *\n * The downside is that the array is created once and then never garbage\n * collected. This is not a problem in practice because the array is only 256\n * elements long.\n *\n * @returns A function that returns the lookup table.\n */\nfunction getPrecomputedHexValuesBuilder(): () => string[] {\n // To avoid issues with tree shaking, we need to use a function to return the\n // array. This is because the array is only used in the `bytesToHex` function\n // and if we were to use a global variable, the array might be removed by the\n // tree shaker.\n const lookupTable: string[] = [];\n\n return () => {\n if (lookupTable.length === 0) {\n for (let i = 0; i < 256; i++) {\n lookupTable.push(i.toString(16).padStart(2, '0'));\n }\n }\n\n return lookupTable;\n };\n}\n\n/**\n * Function implementation of the {@link getPrecomputedHexValuesBuilder}\n * function.\n */\nconst getPrecomputedHexValues = getPrecomputedHexValuesBuilder();\n\n/**\n * Check if a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @returns Whether the value is a `Uint8Array`.\n */\nexport function isBytes(value: unknown): value is Uint8Array {\n return value instanceof Uint8Array;\n}\n\n/**\n * Assert that a value is a `Uint8Array`.\n *\n * @param value - The value to check.\n * @throws If the value is not a `Uint8Array`.\n */\nexport function assertIsBytes(value: unknown): asserts value is Uint8Array {\n assert(isBytes(value), 'Value must be a Uint8Array.');\n}\n\n/**\n * Convert a `Uint8Array` to a hexadecimal string.\n *\n * @param bytes - The bytes to convert to a hexadecimal string.\n * @returns The hexadecimal string.\n */\nexport function bytesToHex(bytes: Uint8Array): Hex {\n assertIsBytes(bytes);\n\n if (bytes.length === 0) {\n return '0x';\n }\n\n const lookupTable = getPrecomputedHexValues();\n const hexadecimal = new Array(bytes.length);\n\n for (let i = 0; i < bytes.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n hexadecimal[i] = lookupTable[bytes[i]!];\n }\n\n return add0x(hexadecimal.join(''));\n}\n\n/**\n * Convert a `Uint8Array` to a `bigint`.\n *\n * To convert a `Uint8Array` to a `number` instead, use {@link bytesToNumber}.\n * To convert a two's complement encoded `Uint8Array` to a `bigint`, use\n * {@link bytesToSignedBigInt}.\n *\n * @param bytes - The bytes to convert to a `bigint`.\n * @returns The `bigint`.\n */\nexport function bytesToBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n const hexadecimal = bytesToHex(bytes);\n return BigInt(hexadecimal);\n}\n\n/**\n * Convert a `Uint8Array` to a signed `bigint`. This assumes that the bytes are\n * encoded in two's complement.\n *\n * To convert a `Uint8Array` to an unsigned `bigint` instead, use\n * {@link bytesToBigInt}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param bytes - The bytes to convert to a signed `bigint`.\n * @returns The signed `bigint`.\n */\nexport function bytesToSignedBigInt(bytes: Uint8Array): bigint {\n assertIsBytes(bytes);\n\n let value = BigInt(0);\n for (const byte of bytes) {\n // eslint-disable-next-line no-bitwise\n value = (value << BigInt(8)) + BigInt(byte);\n }\n\n return BigInt.asIntN(bytes.length * 8, value);\n}\n\n/**\n * Convert a `Uint8Array` to a `number`.\n *\n * To convert a `Uint8Array` to a `bigint` instead, use {@link bytesToBigInt}.\n *\n * @param bytes - The bytes to convert to a number.\n * @returns The number.\n * @throws If the resulting number is not a safe integer.\n */\nexport function bytesToNumber(bytes: Uint8Array): number {\n assertIsBytes(bytes);\n\n const bigint = bytesToBigInt(bytes);\n\n assert(\n bigint <= BigInt(Number.MAX_SAFE_INTEGER),\n 'Number is not a safe integer. Use `bytesToBigInt` instead.',\n );\n\n return Number(bigint);\n}\n\n/**\n * Convert a UTF-8 encoded `Uint8Array` to a `string`.\n *\n * @param bytes - The bytes to convert to a string.\n * @returns The string.\n */\nexport function bytesToString(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return new TextDecoder().decode(bytes);\n}\n\n/**\n * Convert a `Uint8Array` to a base64 encoded string.\n *\n * @param bytes - The bytes to convert to a base64 encoded string.\n * @returns The base64 encoded string.\n */\nexport function bytesToBase64(bytes: Uint8Array): string {\n assertIsBytes(bytes);\n\n return base64.encode(bytes);\n}\n\n/**\n * Convert a hexadecimal string to a `Uint8Array`. The string can optionally be\n * prefixed with `0x`. It accepts even and odd length strings.\n *\n * If the value is \"0x\", an empty `Uint8Array` is returned.\n *\n * @param value - The hexadecimal string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function hexToBytes(value: string): Uint8Array {\n // \"0x\" is often used as empty byte array.\n if (value?.toLowerCase?.() === '0x') {\n return new Uint8Array();\n }\n\n assertIsHexString(value);\n\n // Remove the `0x` prefix if it exists, and pad the string to have an even\n // number of characters.\n const strippedValue = remove0x(value).toLowerCase();\n const normalizedValue =\n strippedValue.length % 2 === 0 ? strippedValue : `0${strippedValue}`;\n const bytes = new Uint8Array(normalizedValue.length / 2);\n\n for (let i = 0; i < bytes.length; i++) {\n // While this is not the prettiest way to convert a hexadecimal string to a\n // `Uint8Array`, it is a lot faster than using `parseInt` to convert each\n // character.\n const c1 = normalizedValue.charCodeAt(i * 2);\n const c2 = normalizedValue.charCodeAt(i * 2 + 1);\n const n1 =\n c1 -\n (c1 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n const n2 =\n c2 -\n (c2 < HEX_MAXIMUM_NUMBER_CHARACTER\n ? HEX_MINIMUM_NUMBER_CHARACTER\n : HEX_CHARACTER_OFFSET);\n\n bytes[i] = n1 * 16 + n2;\n }\n\n return bytes;\n}\n\n/**\n * Convert a `bigint` to a `Uint8Array`.\n *\n * This assumes that the `bigint` is an unsigned integer. To convert a signed\n * `bigint` instead, use {@link signedBigIntToBytes}.\n *\n * @param value - The bigint to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function bigIntToBytes(value: bigint): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= BigInt(0), 'Value must be a non-negative bigint.');\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Check if a `bigint` fits in a certain number of bytes.\n *\n * @param value - The `bigint` to check.\n * @param bytes - The number of bytes.\n * @returns Whether the `bigint` fits in the number of bytes.\n */\nfunction bigIntFits(value: bigint, bytes: number): boolean {\n assert(bytes > 0);\n\n /* eslint-disable no-bitwise */\n const mask = value >> BigInt(31);\n return !(((~value & mask) + (value & ~mask)) >> BigInt(bytes * 8 + ~0));\n /* eslint-enable no-bitwise */\n}\n\n/**\n * Convert a signed `bigint` to a `Uint8Array`. This uses two's complement\n * encoding to represent negative numbers.\n *\n * To convert an unsigned `bigint` to a `Uint8Array` instead, use\n * {@link bigIntToBytes}.\n *\n * @see https://en.wikipedia.org/wiki/Two%27s_complement\n * @param value - The number to convert to bytes.\n * @param byteLength - The length of the resulting `Uint8Array`. If the number\n * is larger than the maximum value that can be represented by the given length,\n * an error is thrown.\n * @returns The bytes as `Uint8Array`.\n */\nexport function signedBigIntToBytes(\n value: bigint,\n byteLength: number,\n): Uint8Array {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(typeof byteLength === 'number', 'Byte length must be a number.');\n assert(byteLength > 0, 'Byte length must be greater than 0.');\n assert(\n bigIntFits(value, byteLength),\n 'Byte length is too small to represent the given value.',\n );\n\n // ESLint doesn't like mutating function parameters, so to avoid having to\n // disable the rule, we create a new variable.\n let numberValue = value;\n const bytes = new Uint8Array(byteLength);\n\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Number(BigInt.asUintN(8, numberValue));\n // eslint-disable-next-line no-bitwise\n numberValue >>= BigInt(8);\n }\n\n return bytes.reverse();\n}\n\n/**\n * Convert a `number` to a `Uint8Array`.\n *\n * @param value - The number to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n * @throws If the number is not a safe integer.\n */\nexport function numberToBytes(value: number): Uint8Array {\n assert(typeof value === 'number', 'Value must be a number.');\n assert(value >= 0, 'Value must be a non-negative number.');\n assert(\n Number.isSafeInteger(value),\n 'Value is not a safe integer. Use `bigIntToBytes` instead.',\n );\n\n const hexadecimal = value.toString(16);\n return hexToBytes(hexadecimal);\n}\n\n/**\n * Convert a `string` to a UTF-8 encoded `Uint8Array`.\n *\n * @param value - The string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function stringToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return new TextEncoder().encode(value);\n}\n\n/**\n * Convert a base64 encoded string to a `Uint8Array`.\n *\n * @param value - The base64 encoded string to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function base64ToBytes(value: string): Uint8Array {\n assert(typeof value === 'string', 'Value must be a string.');\n\n return base64.decode(value);\n}\n\n/**\n * Convert a byte-like value to a `Uint8Array`. The value can be a `Uint8Array`,\n * a `bigint`, a `number`, or a `string`.\n *\n * This will attempt to guess the type of the value based on its type and\n * contents. For more control over the conversion, use the more specific\n * conversion functions, such as {@link hexToBytes} or {@link stringToBytes}.\n *\n * If the value is a `string`, and it is prefixed with `0x`, it will be\n * interpreted as a hexadecimal string. Otherwise, it will be interpreted as a\n * UTF-8 string. To convert a hexadecimal string to bytes without interpreting\n * it as a UTF-8 string, use {@link hexToBytes} instead.\n *\n * If the value is a `bigint`, it is assumed to be unsigned. To convert a signed\n * `bigint` to bytes, use {@link signedBigIntToBytes} instead.\n *\n * If the value is a `Uint8Array`, it will be returned as-is.\n *\n * @param value - The value to convert to bytes.\n * @returns The bytes as `Uint8Array`.\n */\nexport function valueToBytes(value: Bytes): Uint8Array {\n if (typeof value === 'bigint') {\n return bigIntToBytes(value);\n }\n\n if (typeof value === 'number') {\n return numberToBytes(value);\n }\n\n if (typeof value === 'string') {\n if (value.startsWith('0x')) {\n return hexToBytes(value);\n }\n\n return stringToBytes(value);\n }\n\n if (isBytes(value)) {\n return value;\n }\n\n throw new TypeError(`Unsupported value type: \"${typeof value}\".`);\n}\n\n/**\n * Concatenate multiple byte-like values into a single `Uint8Array`. The values\n * can be `Uint8Array`, `bigint`, `number`, or `string`. This uses\n * {@link valueToBytes} under the hood to convert each value to bytes. Refer to\n * the documentation of that function for more information.\n *\n * @param values - The values to concatenate.\n * @returns The concatenated bytes as `Uint8Array`.\n */\nexport function concatBytes(values: Bytes[]): Uint8Array {\n const normalizedValues = new Array(values.length);\n let byteLength = 0;\n\n for (let i = 0; i < values.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = valueToBytes(values[i]!);\n\n normalizedValues[i] = value;\n byteLength += value.length;\n }\n\n const bytes = new Uint8Array(byteLength);\n for (let i = 0, offset = 0; i < normalizedValues.length; i++) {\n // While we could simply spread the values into an array and use\n // `Uint8Array.from`, that is a lot slower than using `Uint8Array.set`.\n bytes.set(normalizedValues[i], offset);\n offset += normalizedValues[i].length;\n }\n\n return bytes;\n}\n\n/**\n * Create a {@link DataView} from a {@link Uint8Array}. This is a convenience\n * function that avoids having to create a {@link DataView} manually, which\n * requires passing the `byteOffset` and `byteLength` parameters every time.\n *\n * Not passing the `byteOffset` and `byteLength` parameters can result in\n * unexpected behavior when the {@link Uint8Array} is a view of a larger\n * {@link ArrayBuffer}, e.g., when using {@link Uint8Array.subarray}.\n *\n * This function also supports Node.js {@link Buffer}s.\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([1, 2, 3]);\n *\n * // This is equivalent to:\n * // const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n * const dataView = createDataView(bytes);\n * ```\n * @param bytes - The bytes to create the {@link DataView} from.\n * @returns The {@link DataView}.\n */\nexport function createDataView(bytes: Uint8Array): DataView {\n // To maintain compatibility with Node.js, we need to check if the bytes are\n // a Buffer. If so, we need to slice the buffer to get the underlying\n // ArrayBuffer.\n // eslint-disable-next-line no-restricted-globals\n if (typeof Buffer !== 'undefined' && bytes instanceof Buffer) {\n const buffer = bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n );\n\n return new DataView(buffer);\n }\n\n return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n}\n\n/**\n * Compare two Uint8Arrays using a constant-time style loop to reduce timing\n * side-channels when comparing sensitive data (e.g., mnemonic bytes, keys,\n * authentication tags). Does not early-return on the first difference:\n * work done depends only on the input lengths, so byte content does not affect timing.\n *\n * When to use:\n * - Use for secret or security-sensitive byte comparisons to avoid content-based timing leaks.\n * - Prefer when inputs are fixed-length (or validated to equal length) at the API boundary.\n *\n * @param a - The first Uint8Array to compare.\n * @param b - The second Uint8Array to compare.\n * @returns Whether the Uint8Arrays are equal.\n */\nexport function areUint8ArraysEqual(a: Uint8Array, b: Uint8Array): boolean {\n // eslint-disable-next-line no-bitwise\n let diff = a.byteLength ^ b.byteLength;\n const len = Math.max(a.byteLength, b.byteLength);\n\n for (let i = 0; i < len; i++) {\n const aByte = a[i] ?? 0;\n const bByte = b[i] ?? 0;\n // eslint-disable-next-line no-bitwise\n diff |= aByte ^ bByte;\n }\n\n return diff === 0;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { Infer } from "@metamask/superstruct";
1
+ import type { Infer } from '@metamask/superstruct';
2
2
  export declare const CAIP_CHAIN_ID_REGEX: RegExp;
3
3
  export declare const CAIP_NAMESPACE_REGEX: RegExp;
4
4
  export declare const CAIP_REFERENCE_REGEX: RegExp;
@@ -291,4 +291,4 @@ export declare function toCaipAssetType(namespace: CaipNamespace, reference: Cai
291
291
  * @returns A CAIP asset ID.
292
292
  */
293
293
  export declare function toCaipAssetId(namespace: CaipNamespace, reference: CaipReference, assetNamespace: CaipAssetNamespace, assetReference: CaipAssetReference, tokenId: CaipTokenId): CaipAssetId;
294
- //# sourceMappingURL=caip-types.d.cts.map
294
+ //# sourceMappingURL=caip-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caip-types.d.ts","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;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,mBAAmB,QAA4B,CAAC;AAE7D,eAAO,MAAM,qBAAqB,QAC2H,CAAC;AAE9J,eAAO,MAAM,mBAAmB,QAC+J,CAAC;AAKhM;;GAEG;AACH,eAAO,MAAM,iBAAiB,qEAG7B,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,mBAAmB,sDAG/B,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,mBAAmB,sDAG/B,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,mBAAmB,+EAI7B,CAAC;AACJ,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,wB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 -1,4 +1,4 @@
1
- import { definePattern } from "./superstruct.mjs";
1
+ import { definePattern } from './superstruct.js';
2
2
  export const CAIP_CHAIN_ID_REGEX = /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32})$/u;
3
3
  export const CAIP_NAMESPACE_REGEX = /^[-a-z0-9]{3,8}$/u;
4
4
  export const CAIP_REFERENCE_REGEX = /^[-_a-zA-Z0-9]{1,32}$/u;
@@ -366,4 +366,4 @@ export function toCaipAssetId(namespace, reference, assetNamespace, assetReferen
366
366
  }
367
367
  return `${namespace}:${reference}/${assetNamespace}:${assetReference}/${tokenId}`;
368
368
  }
369
- //# sourceMappingURL=caip-types.mjs.map
369
+ //# sourceMappingURL=caip-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caip-types.js","sourceRoot":"","sources":["../src/caip-types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,CAAC,MAAM,mBAAmB,GAC9B,mEAAmE,CAAC;AAEtE,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAExD,MAAM,CAAC,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AAE7D,MAAM,CAAC,MAAM,qBAAqB,GAChC,wHAAwH,CAAC;AAE3H,MAAM,CAAC,MAAM,0BAA0B,GAAG,0BAA0B,CAAC;AAErE,MAAM,CAAC,MAAM,0BAA0B,GAAG,mBAAmB,CAAC;AAE9D,MAAM,CAAC,MAAM,0BAA0B,GAAG,0BAA0B,CAAC;AAErE,MAAM,CAAC,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAE7D,MAAM,CAAC,MAAM,qBAAqB,GAChC,2JAA2J,CAAC;AAE9J,MAAM,CAAC,MAAM,mBAAmB,GAC9B,6LAA6L,CAAC;AAEhM,MAAM,2BAA2B,GAC/B,gMAAgM,CAAC;AAEnM;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,G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AC;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.js';\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"]}
@@ -1,2 +1,2 @@
1
1
  export declare const ChecksumStruct: import("@metamask/superstruct").Struct<string, null>;
2
- //# sourceMappingURL=checksum.d.cts.map
2
+ //# sourceMappingURL=checksum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checksum.d.ts","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,sDAI1B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { size, string } from '@metamask/superstruct';
2
+ import { base64 } from './base64.js';
3
+ export const ChecksumStruct = size(base64(string(), { paddingRequired: true }), 44, 44);
4
+ //# sourceMappingURL=checksum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checksum.js","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,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.js';\n\nexport const ChecksumStruct = size(\n base64(string(), { paddingRequired: true }),\n 44,\n 44,\n);\n"]}
@@ -1,7 +1,7 @@
1
- import type { Infer } from "@metamask/superstruct";
2
- import type { Hex } from "./hex.cjs";
1
+ import type { Infer } from '@metamask/superstruct';
2
+ import type { Hex } from './hex.js';
3
3
  declare const NumberLikeStruct: import("@metamask/superstruct").Struct<string | number | bigint, null>;
4
- declare const BytesLikeStruct: import("@metamask/superstruct").Struct<Uint8Array | `0x${string}`, null>;
4
+ declare const BytesLikeStruct: import("@metamask/superstruct").Struct<Uint8Array<ArrayBuffer> | `0x${string}`, null>;
5
5
  export type NumberLike = Infer<typeof NumberLikeStruct>;
6
6
  export type BytesLike = Infer<typeof BytesLikeStruct>;
7
7
  /**
@@ -94,4 +94,4 @@ export declare function createBytes(value: BytesLike): Uint8Array;
94
94
  */
95
95
  export declare function createHex(value: BytesLike): Hex;
96
96
  export {};
97
- //# sourceMappingURL=coercers.d.cts.map
97
+ //# sourceMappingURL=coercers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coercers.d.ts","sourceRoot":"","sources":["../src/coercers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAcnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAGpC,QAAA,MAAM,gBAAgB,wEAAyD,CAAC;AAKhF,QAAA,MAAM,eAAe,uFAAiD,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"}
@@ -1,7 +1,7 @@
1
- import { bigint, coerce, create, instance, number, string, StructError, union } from "@metamask/superstruct";
2
- import { assert } from "./assert.mjs";
3
- import { bytesToHex, hexToBytes } from "./bytes.mjs";
4
- import { StrictHexStruct } from "./hex.mjs";
1
+ import { bigint, coerce, create, instance, number, string, StructError, union, } from '@metamask/superstruct';
2
+ import { assert } from './assert.js';
3
+ import { bytesToHex, hexToBytes } from './bytes.js';
4
+ import { StrictHexStruct } from './hex.js';
5
5
  const NumberLikeStruct = union([number(), bigint(), string(), StrictHexStruct]);
6
6
  const NumberCoercer = coerce(number(), NumberLikeStruct, Number);
7
7
  const BigIntCoercer = coerce(bigint(), NumberLikeStruct, BigInt);
@@ -156,4 +156,4 @@ export function createHex(value) {
156
156
  throw error;
157
157
  }
158
158
  }
159
- //# sourceMappingURL=coercers.mjs.map
159
+ //# sourceMappingURL=coercers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coercers.js","sourceRoot":"","sources":["../src/coercers.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,WAAW,EACX,KAAK,GACN,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,eAAe,CAAC,CAAC,CAAC;AAChF,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;AACjE,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;AAEjE,mJAAmJ;AACnJ,MAAM,eAAe,GAAG,KAAK,CAAC,CAAC,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACvE,MAAM,YAAY,GAAG,MAAM,CACzB,Q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AI,KAAK,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC;QAC9D,OAAO,IAAI,UAAU,EAAE,CAAC;IAC1B,CAAC;IAED,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iHAAiH;QACjH,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,qCAAqC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAC7D,CAAC;QACJ,CAAC;QAED,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,SAAS,CAAC,KAAgB;IACxC,IACE,CAAC,KAAK,YAAY,UAAU,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;QACnD,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,EAC3D,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iHAAiH;QACjH,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,qCAAqC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAC7D,CAAC;QACJ,CAAC;QAED,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["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.js';\nimport { bytesToHex, hexToBytes } from './bytes.js';\nimport type { Hex } from './hex.js';\nimport { StrictHexStruct } from './hex.js';\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"]}
@@ -7,14 +7,14 @@
7
7
  declare class FrozenMap<Key, Value> implements ReadonlyMap<Key, Value> {
8
8
  #private;
9
9
  get size(): number;
10
- [Symbol.iterator](): IterableIterator<[Key, Value]>;
10
+ [Symbol.iterator](): MapIterator<[Key, Value]>;
11
11
  constructor(entries?: readonly (readonly [Key, Value])[] | null);
12
- entries(): IterableIterator<[Key, Value]>;
12
+ entries(): MapIterator<[Key, Value]>;
13
13
  forEach(callbackfn: (value: Value, key: Key, map: this) => void, thisArg?: any): void;
14
14
  get(key: Key): Value | undefined;
15
15
  has(key: Key): boolean;
16
- keys(): IterableIterator<Key>;
17
- values(): IterableIterator<Value>;
16
+ keys(): MapIterator<Key>;
17
+ values(): MapIterator<Value>;
18
18
  toString(): string;
19
19
  }
20
20
  /**
@@ -26,14 +26,14 @@ declare class FrozenMap<Key, Value> implements ReadonlyMap<Key, Value> {
26
26
  declare class FrozenSet<Value> implements ReadonlySet<Value> {
27
27
  #private;
28
28
  get size(): number;
29
- [Symbol.iterator](): IterableIterator<Value>;
29
+ [Symbol.iterator](): SetIterator<Value>;
30
30
  constructor(values?: readonly Value[] | null);
31
- entries(): IterableIterator<[Value, Value]>;
31
+ entries(): SetIterator<[Value, Value]>;
32
32
  forEach(callbackfn: (value: Value, value2: Value, set: this) => void, thisArg?: any): void;
33
33
  has(value: Value): boolean;
34
- keys(): IterableIterator<Value>;
35
- values(): IterableIterator<Value>;
34
+ keys(): SetIterator<Value>;
35
+ values(): SetIterator<Value>;
36
36
  toString(): string;
37
37
  }
38
38
  export { FrozenMap, FrozenSet };
39
- //# sourceMappingURL=collections.d.cts.map
39
+ //# sourceMappingURL=collections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAM,SAAS,CAAC,GAAG,EAAE,KAAK,CAAE,YAAW,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC;;IAG5D,IAAW,IAAI,WAEd;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC,8BAEvB;IAED,YAAY,OAAO,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,IAAI,EAG9D;IAEM,OAAO,8BAEb;IAEM,OAAO,CACZ,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,KAAK,IAAI,EACvD,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI,CAMN;IAEM,GAAG,CAAC,GAAG,EAAE,GAAG,qBAElB;IAEM,GAAG,CAAC,GAAG,EAAE,GAAG,WAElB;IAEM,IAAI,qBAEV;IAEM,MAAM,uBAEZ;IAEM,QAAQ,IAAI,MAAM,CAQxB;CACF;AAED;;;;;GAKG;AACH,cAAM,SAAS,CAAC,KAAK,CAAE,YAAW,WAAW,CAAC,KAAK,CAAC;;IAGlD,IAAW,IAAI,WAEd;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAEvB;IAED,YAAY,MAAM,CAAC,EAAE,SAAS,KAAK,EAAE,GAAG,IAAI,EAG3C;IAEM,OAAO,gCAEb;IAEM,OAAO,CACZ,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,KAAK,IAAI,EAC5D,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI,CAMN;IAEM,GAAG,CAAC,KAAK,EAAE,KAAK,WAEtB;IAEM,IAAI,uBAEV;IAEM,MAAM,uBAEZ;IAEM,QAAQ,IAAI,MAAM,CAMxB;CACF;AAQD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * A {@link ReadonlyMap} that cannot be modified after instantiation.
3
+ * The implementation uses an inner map hidden via a private field, and the
4
+ * immutability guarantee relies on it being impossible to get a reference
5
+ * to this map.
6
+ */
7
+ class FrozenMap {
8
+ #map;
9
+ get size() {
10
+ return this.#map.size;
11
+ }
12
+ [Symbol.iterator]() {
13
+ return this.#map[Symbol.iterator]();
14
+ }
15
+ constructor(entries) {
16
+ this.#map = new Map(entries);
17
+ Object.freeze(this);
18
+ }
19
+ entries() {
20
+ return this.#map.entries();
21
+ }
22
+ forEach(callbackfn, thisArg) {
23
+ // We have to wrap the specified callback in order to prevent it from
24
+ // receiving a reference to the inner map.
25
+ return this.#map.forEach((value, key, _map) => callbackfn.call(thisArg, value, key, this));
26
+ }
27
+ get(key) {
28
+ return this.#map.get(key);
29
+ }
30
+ has(key) {
31
+ return this.#map.has(key);
32
+ }
33
+ keys() {
34
+ return this.#map.keys();
35
+ }
36
+ values() {
37
+ return this.#map.values();
38
+ }
39
+ toString() {
40
+ return `FrozenMap(${this.size}) {${this.size > 0
41
+ ? ` ${[...this.entries()]
42
+ .map(([key, value]) => `${String(key)} => ${String(value)}`)
43
+ .join(', ')} `
44
+ : ''}}`;
45
+ }
46
+ }
47
+ /**
48
+ * A {@link ReadonlySet} that cannot be modified after instantiation.
49
+ * The implementation uses an inner set hidden via a private field, and the
50
+ * immutability guarantee relies on it being impossible to get a reference
51
+ * to this set.
52
+ */
53
+ class FrozenSet {
54
+ #set;
55
+ get size() {
56
+ return this.#set.size;
57
+ }
58
+ [Symbol.iterator]() {
59
+ return this.#set[Symbol.iterator]();
60
+ }
61
+ constructor(values) {
62
+ this.#set = new Set(values);
63
+ Object.freeze(this);
64
+ }
65
+ entries() {
66
+ return this.#set.entries();
67
+ }
68
+ forEach(callbackfn, thisArg) {
69
+ // We have to wrap the specified callback in order to prevent it from
70
+ // receiving a reference to the inner set.
71
+ return this.#set.forEach((value, value2, _set) => callbackfn.call(thisArg, value, value2, this));
72
+ }
73
+ has(value) {
74
+ return this.#set.has(value);
75
+ }
76
+ keys() {
77
+ return this.#set.keys();
78
+ }
79
+ values() {
80
+ return this.#set.values();
81
+ }
82
+ toString() {
83
+ return `FrozenSet(${this.size}) {${this.size > 0
84
+ ? ` ${[...this.values()].map((member) => String(member)).join(', ')} `
85
+ : ''}}`;
86
+ }
87
+ }
88
+ Object.freeze(FrozenMap);
89
+ Object.freeze(FrozenMap.prototype);
90
+ Object.freeze(FrozenSet);
91
+ Object.freeze(FrozenSet.prototype);
92
+ export { FrozenMap, FrozenSet };
93
+ //# sourceMappingURL=collections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.js","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,SAAS;IACJ,IAAI,CAAkB;IAE/B,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC;QACtB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IACtC,CAAC;IAED,YAAY,OAAmD;QAC7D,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,CAAa,OAAO,CAAC,CAAC;QACzC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC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AC,MAAM,CAAC,SAAS,CAAC,CAAC;AACzB,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC","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"]}
@@ -4,4 +4,4 @@ export type Eip1024EncryptedData = {
4
4
  ephemPublicKey: string;
5
5
  ciphertext: string;
6
6
  };
7
- //# sourceMappingURL=encryption-types.d.cts.map
7
+ //# sourceMappingURL=encryption-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption-types.d.ts","sourceRoot":"","sources":["../src/encryption-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=encryption-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption-types.js","sourceRoot":"","sources":["../src/encryption-types.ts"],"names":[],"mappings":"","sourcesContent":["export type Eip1024EncryptedData = {\n version: string;\n nonce: string;\n ephemPublicKey: string;\n ciphertext: string;\n};\n"]}
@@ -65,4 +65,4 @@ export declare function wrapError<Throwable>(originalError: Throwable, message:
65
65
  * @returns A proper Error instance.
66
66
  */
67
67
  export declare function ensureError(error: unknown): Error;
68
- //# sourceMappingURL=errors.d.mts.map
68
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAmBA;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAEzE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAE9B;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAE3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAWtD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,SAAS,EACjC,aAAa,EAAE,SAAS,EACxB,OAAO,EAAE,MAAM,GACd,KAAK,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAqB3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAQjD"}