@umbra-privacy/sdk 1.0.0 → 2.0.1

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 (181) hide show
  1. package/README.md +104 -25
  2. package/dist/{addresses-Brzgurv_.d.ts → addresses-B7HybtbJ.d.ts} +2 -1
  3. package/dist/{addresses-D_0YAS6B.d.cts → addresses-CTVY1oi7.d.cts} +2 -1
  4. package/dist/arcium-BXXlryfe.d.cts +20 -0
  5. package/dist/arcium-BXXlryfe.d.ts +20 -0
  6. package/dist/chunk-3LS5P32X.cjs +10892 -0
  7. package/dist/chunk-3LS5P32X.cjs.map +1 -0
  8. package/dist/chunk-4RHXVBNI.js +203 -0
  9. package/dist/chunk-4RHXVBNI.js.map +1 -0
  10. package/dist/chunk-4TZVXB5G.js +324 -0
  11. package/dist/chunk-4TZVXB5G.js.map +1 -0
  12. package/dist/chunk-5GUSMQ74.cjs +549 -0
  13. package/dist/chunk-5GUSMQ74.cjs.map +1 -0
  14. package/dist/chunk-5KPQXPQM.js +36 -0
  15. package/dist/chunk-5KPQXPQM.js.map +1 -0
  16. package/dist/chunk-AXD7LXYY.cjs +405 -0
  17. package/dist/chunk-AXD7LXYY.cjs.map +1 -0
  18. package/dist/{chunk-HOEXDXRC.cjs → chunk-BL6WXLPV.cjs} +32 -360
  19. package/dist/chunk-BL6WXLPV.cjs.map +1 -0
  20. package/dist/chunk-CFFLOE7D.cjs +598 -0
  21. package/dist/chunk-CFFLOE7D.cjs.map +1 -0
  22. package/dist/{chunk-BM7N6N7E.js → chunk-CFTW5WNG.js} +3 -325
  23. package/dist/chunk-CFTW5WNG.js.map +1 -0
  24. package/dist/chunk-DD2WCK4C.js +327 -0
  25. package/dist/chunk-DD2WCK4C.js.map +1 -0
  26. package/dist/chunk-DMPMQ74B.cjs +246 -0
  27. package/dist/chunk-DMPMQ74B.cjs.map +1 -0
  28. package/dist/{chunk-2Q75CQQJ.js → chunk-EEKF4553.js} +2 -2
  29. package/dist/chunk-EEKF4553.js.map +1 -0
  30. package/dist/chunk-ENVYYEM4.cjs +113 -0
  31. package/dist/chunk-ENVYYEM4.cjs.map +1 -0
  32. package/dist/chunk-FQX6ZYGJ.js +500 -0
  33. package/dist/chunk-FQX6ZYGJ.js.map +1 -0
  34. package/dist/chunk-FSK2ICMB.cjs +39 -0
  35. package/dist/chunk-FSK2ICMB.cjs.map +1 -0
  36. package/dist/chunk-FZYWLQAF.cjs +355 -0
  37. package/dist/chunk-FZYWLQAF.cjs.map +1 -0
  38. package/dist/chunk-GP26R377.js +436 -0
  39. package/dist/chunk-GP26R377.js.map +1 -0
  40. package/dist/chunk-HA5FLM63.js +393 -0
  41. package/dist/chunk-HA5FLM63.js.map +1 -0
  42. package/dist/chunk-INJ73LXQ.js +1107 -0
  43. package/dist/chunk-INJ73LXQ.js.map +1 -0
  44. package/dist/chunk-KMRROOME.js +10750 -0
  45. package/dist/chunk-KMRROOME.js.map +1 -0
  46. package/dist/{chunk-MDFSBU5W.cjs → chunk-LTCKPTZC.cjs} +2 -351
  47. package/dist/chunk-LTCKPTZC.cjs.map +1 -0
  48. package/dist/chunk-MKNCBUFA.js +564 -0
  49. package/dist/chunk-MKNCBUFA.js.map +1 -0
  50. package/dist/chunk-NKVMSABR.cjs +207 -0
  51. package/dist/chunk-NKVMSABR.cjs.map +1 -0
  52. package/dist/chunk-OFDWNWCL.js +70 -0
  53. package/dist/chunk-OFDWNWCL.js.map +1 -0
  54. package/dist/chunk-QJAUUYZU.cjs +331 -0
  55. package/dist/chunk-QJAUUYZU.cjs.map +1 -0
  56. package/dist/chunk-TLR7A64G.js +103 -0
  57. package/dist/chunk-TLR7A64G.js.map +1 -0
  58. package/dist/{chunk-MVKTV3FT.cjs → chunk-TQQZGNOI.cjs} +2 -2
  59. package/dist/chunk-TQQZGNOI.cjs.map +1 -0
  60. package/dist/chunk-UOFYS6M3.js +219 -0
  61. package/dist/chunk-UOFYS6M3.js.map +1 -0
  62. package/dist/chunk-UXMQI6B7.js +2406 -0
  63. package/dist/chunk-UXMQI6B7.js.map +1 -0
  64. package/dist/chunk-WN75ORDT.js +571 -0
  65. package/dist/chunk-WN75ORDT.js.map +1 -0
  66. package/dist/chunk-Y55PYKXH.cjs +595 -0
  67. package/dist/chunk-Y55PYKXH.cjs.map +1 -0
  68. package/dist/chunk-YEZBTYCP.cjs +77 -0
  69. package/dist/chunk-YEZBTYCP.cjs.map +1 -0
  70. package/dist/chunk-ZQOIYCGA.cjs +1126 -0
  71. package/dist/chunk-ZQOIYCGA.cjs.map +1 -0
  72. package/dist/chunk-ZY3TSHMJ.cjs +2665 -0
  73. package/dist/chunk-ZY3TSHMJ.cjs.map +1 -0
  74. package/dist/client-DkVBHMWb.d.cts +2613 -0
  75. package/dist/client-V4AF6Bz9.d.ts +2613 -0
  76. package/dist/common/pda/index.cjs +145 -0
  77. package/dist/common/pda/index.cjs.map +1 -0
  78. package/dist/common/pda/index.d.cts +1250 -0
  79. package/dist/common/pda/index.d.ts +1250 -0
  80. package/dist/common/pda/index.js +8 -0
  81. package/dist/common/pda/index.js.map +1 -0
  82. package/dist/constants/index.cjs +38 -164
  83. package/dist/constants/index.cjs.map +1 -1
  84. package/dist/constants/index.d.cts +8 -425
  85. package/dist/constants/index.d.ts +8 -425
  86. package/dist/constants/index.js +15 -124
  87. package/dist/constants/index.js.map +1 -1
  88. package/dist/crypto/index.cjs +583 -0
  89. package/dist/crypto/index.cjs.map +1 -0
  90. package/dist/crypto/index.d.cts +6731 -0
  91. package/dist/crypto/index.d.ts +6731 -0
  92. package/dist/crypto/index.js +14 -0
  93. package/dist/crypto/index.js.map +1 -0
  94. package/dist/{cryptography-BTGC72u-.d.ts → cryptography-BFSJcvi6.d.ts} +3 -2465
  95. package/dist/{cryptography-BTGC72u-.d.cts → cryptography-D6tPDh-Y.d.cts} +3 -2465
  96. package/dist/errors/index.cjs +64 -54
  97. package/dist/errors/index.d.cts +7 -797
  98. package/dist/errors/index.d.ts +7 -797
  99. package/dist/errors/index.js +3 -1
  100. package/dist/errors-B9EoPeWV.d.cts +593 -0
  101. package/dist/errors-B9EoPeWV.d.ts +593 -0
  102. package/dist/errors-DAIrstEL.d.cts +300 -0
  103. package/dist/errors-DPNMfyh0.d.ts +300 -0
  104. package/dist/index-BG0yjL7C.d.cts +6006 -0
  105. package/dist/index-ByynoyBO.d.ts +6006 -0
  106. package/dist/index.cjs +5133 -16116
  107. package/dist/index.cjs.map +1 -1
  108. package/dist/index.d.cts +1031 -7685
  109. package/dist/index.d.ts +1031 -7685
  110. package/dist/index.js +3228 -14905
  111. package/dist/index.js.map +1 -1
  112. package/dist/interfaces/index.d.cts +14 -6
  113. package/dist/interfaces/index.d.ts +14 -6
  114. package/dist/interfaces-43cReBcS.d.cts +3346 -0
  115. package/dist/interfaces-B8xKNl_6.d.ts +997 -0
  116. package/dist/interfaces-D2NO6kDD.d.cts +997 -0
  117. package/dist/interfaces-z_xYJlgV.d.ts +3346 -0
  118. package/dist/math/index.cjs +115 -0
  119. package/dist/math/index.cjs.map +1 -0
  120. package/dist/math/index.d.cts +1327 -0
  121. package/dist/math/index.d.ts +1327 -0
  122. package/dist/math/index.js +10 -0
  123. package/dist/math/index.js.map +1 -0
  124. package/dist/networks-RMd3abPE.d.ts +44 -0
  125. package/dist/networks-yAoO8peQ.d.cts +44 -0
  126. package/dist/relayer-NRRMSMNB.js +4 -0
  127. package/dist/relayer-NRRMSMNB.js.map +1 -0
  128. package/dist/relayer-RJHEIXJG.cjs +21 -0
  129. package/dist/relayer-RJHEIXJG.cjs.map +1 -0
  130. package/dist/solana/index.cjs +56 -0
  131. package/dist/solana/index.cjs.map +1 -0
  132. package/dist/solana/index.d.cts +105 -0
  133. package/dist/solana/index.d.ts +105 -0
  134. package/dist/solana/index.js +7 -0
  135. package/dist/solana/index.js.map +1 -0
  136. package/dist/{index-CLj_zWSD.d.ts → temporal-BbRaEPoO.d.ts} +1 -1
  137. package/dist/{index-CX6_pIRS.d.cts → temporal-oUj7iCaq.d.cts} +1 -1
  138. package/dist/transaction-forwarder-5mAMTjw6.d.ts +1155 -0
  139. package/dist/transaction-forwarder-C6gMUG7a.d.cts +1155 -0
  140. package/dist/types/index.cjs +232 -231
  141. package/dist/types/index.d.cts +15 -1485
  142. package/dist/types/index.d.ts +15 -1485
  143. package/dist/types/index.js +2 -1
  144. package/dist/types-BohhvPth.d.cts +87 -0
  145. package/dist/types-CW0oTT0j.d.ts +87 -0
  146. package/dist/types-C_V_CaKK.d.cts +2468 -0
  147. package/dist/types-C_V_CaKK.d.ts +2468 -0
  148. package/dist/types-Ca7frykr.d.ts +793 -0
  149. package/dist/types-CuKeoI19.d.cts +1296 -0
  150. package/dist/types-CxfTIpN9.d.ts +1052 -0
  151. package/dist/{types-n-sHFcgr.d.ts → types-D1jDUjfN.d.ts} +2 -2
  152. package/dist/types-DKEDUlH9.d.ts +1296 -0
  153. package/dist/types-EKuIfxTz.d.cts +1052 -0
  154. package/dist/{types-BBuELtY8.d.cts → types-IMGYmlv-.d.cts} +2 -2
  155. package/dist/types-PwNLi_2k.d.cts +793 -0
  156. package/dist/utils/index.cjs +823 -525
  157. package/dist/utils/index.d.cts +1711 -4021
  158. package/dist/utils/index.d.ts +1711 -4021
  159. package/dist/utils/index.js +9 -3
  160. package/dist/{versions-D9PqsEvj.d.cts → versions-BRlR36EA.d.cts} +1 -0
  161. package/dist/{versions-D9PqsEvj.d.ts → versions-BRlR36EA.d.ts} +1 -0
  162. package/package.json +79 -18
  163. package/dist/chunk-2Q75CQQJ.js.map +0 -1
  164. package/dist/chunk-BM7N6N7E.js.map +0 -1
  165. package/dist/chunk-GXKSUB2U.cjs +0 -4416
  166. package/dist/chunk-GXKSUB2U.cjs.map +0 -1
  167. package/dist/chunk-HOEXDXRC.cjs.map +0 -1
  168. package/dist/chunk-MDFSBU5W.cjs.map +0 -1
  169. package/dist/chunk-MQY7HDIA.js +0 -600
  170. package/dist/chunk-MQY7HDIA.js.map +0 -1
  171. package/dist/chunk-MVKTV3FT.cjs.map +0 -1
  172. package/dist/chunk-PG2J6V6Y.js +0 -4094
  173. package/dist/chunk-PG2J6V6Y.js.map +0 -1
  174. package/dist/chunk-VEGLTTYQ.cjs +0 -621
  175. package/dist/chunk-VEGLTTYQ.cjs.map +0 -1
  176. package/dist/chunk-WVHQ46DD.js +0 -758
  177. package/dist/chunk-WVHQ46DD.js.map +0 -1
  178. package/dist/index-B9pDY73x.d.ts +0 -12933
  179. package/dist/index-D33yo0qB.d.cts +0 -12933
  180. package/dist/networks-C-orpSFW.d.ts +0 -65
  181. package/dist/networks-FxYERGD1.d.cts +0 -65
@@ -0,0 +1,2468 @@
1
+ /**
2
+ * Branded Types Infrastructure
3
+ *
4
+ * Provides compile-time nominal typing for the SDK through a hierarchical branded type system.
5
+ * Branded types prevent accidental mixing of structurally identical values — for example,
6
+ * passing a `U64` where a `U128` is expected, or a `RcPlaintext` where a `RcCiphertext` is
7
+ * required. Because TypeScript uses structural typing, two types with the same underlying
8
+ * representation (e.g. both `bigint`) are otherwise interchangeable, which is a silent source
9
+ * of hard-to-detect bugs in cryptographic and protocol code.
10
+ *
11
+ * ## The Branded Type Pattern
12
+ *
13
+ * A branded type is formed by intersecting a base type `T` with an object carrying a unique
14
+ * phantom symbol property. The symbol is declared with `declare const ... : unique symbol`,
15
+ * which guarantees TypeScript treats it as distinct from every other symbol — the brand itself
16
+ * never exists at runtime and adds zero bytes to the value.
17
+ *
18
+ * ```
19
+ * type UserId = BrandedType<string, "UserId">;
20
+ * // ^^^^^^^^^^ string — the runtime representation
21
+ * // ^^^^^^^^ "UserId" — the phantom brand
22
+ * ```
23
+ *
24
+ * ## Hierarchical Brands
25
+ *
26
+ * The module supports up to five levels of brand hierarchy through `SubBrandedType`,
27
+ * `SubSubBrandedType`, etc. A sub-brand inherits structural compatibility with its parent,
28
+ * allowing a more specific type to be used wherever the parent is accepted, but not vice versa.
29
+ * This mirrors subtype relationships (e.g. `U32LeBytes ⊆ LeBytes ⊆ Bytes`).
30
+ *
31
+ * ## Utility Types
32
+ *
33
+ * `UnwrapBrand` and `ExtractBrand` are provided for generic code that needs to inspect or
34
+ * strip the brand layer without discarding the base type information.
35
+ *
36
+ * @packageDocumentation
37
+ * @since 2.0.0
38
+ * @module common/branded
39
+ */
40
+ /**
41
+ * Unique symbol used as the primary brand property key.
42
+ *
43
+ * @remarks
44
+ * Declared with `unique symbol` so TypeScript guarantees no two declarations of
45
+ * `BrandSymbol` can be the same symbol, making it impossible to accidentally collide
46
+ * with user-defined properties. The value never exists at runtime.
47
+ *
48
+ * @internal
49
+ */
50
+ declare const BrandSymbol: unique symbol;
51
+ /**
52
+ * Unique symbol used as the sub-brand property key.
53
+ *
54
+ * @remarks
55
+ * Attached to a branded type by `SubBrandedType` to create a second phantom dimension
56
+ * that distinguishes sub-types from their parent without breaking parent assignability.
57
+ *
58
+ * @internal
59
+ */
60
+ declare const SubBrandSymbol: unique symbol;
61
+ /**
62
+ * Unique symbol used as the sub-sub-brand property key.
63
+ *
64
+ * @remarks
65
+ * Attached by `SubSubBrandedType` to create a third phantom dimension.
66
+ *
67
+ * @internal
68
+ */
69
+ declare const SubSubBrandSymbol: unique symbol;
70
+ /**
71
+ * Unique symbol used as the sub-sub-sub-brand property key.
72
+ *
73
+ * @remarks
74
+ * Attached by `SubSubSubBrandedType` to create a fourth phantom dimension.
75
+ *
76
+ * @internal
77
+ */
78
+ declare const SubSubSubBrandSymbol: unique symbol;
79
+ /**
80
+ * Unique symbol used as the sub-sub-sub-sub-brand property key.
81
+ *
82
+ * @remarks
83
+ * Attached by `SubSubSubSubBrandedType` to create a fifth phantom dimension.
84
+ *
85
+ * @internal
86
+ */
87
+ declare const SubSubSubSubBrandSymbol: unique symbol;
88
+ /**
89
+ * Creates a branded (nominally typed) variant of a base type.
90
+ *
91
+ * @remarks
92
+ * The brand is encoded as a readonly phantom property keyed by `BrandSymbol` whose
93
+ * value type is the string literal `Brand`. Because `BrandSymbol` is a `unique symbol`,
94
+ * no two `BrandedType` declarations share the same property key unless they name the same
95
+ * `Brand` string. This makes cross-brand assignment a compile-time error.
96
+ *
97
+ * At runtime the intersection carries no extra data — branded values are stored and
98
+ * transmitted identically to their base type.
99
+ *
100
+ * Use `UnwrapBrand` to recover `Base` and `ExtractBrand` to recover `Brand` from a
101
+ * `BrandedType` in generic contexts.
102
+ *
103
+ * @typeParam Base - The underlying runtime type (e.g. `bigint`, `Uint8Array`, `string`).
104
+ * @typeParam Brand - A unique string literal that names this brand (e.g. `"U64"`, `"UserId"`).
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * // Define two distinct identifier types with the same underlying representation.
109
+ * type UserId = BrandedType<string, "UserId">;
110
+ * type PostId = BrandedType<string, "PostId">;
111
+ *
112
+ * // Values must be explicitly branded at the boundary.
113
+ * const userId: UserId = "user-123" as UserId;
114
+ * const postId: PostId = "post-456" as PostId;
115
+ *
116
+ * // TypeScript rejects accidental mixing:
117
+ * const invalid: PostId = userId; // Error: Type 'UserId' is not assignable to type 'PostId'.
118
+ * ```
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * // Numeric brands prevent silent precision loss in the SDK.
123
+ * type U64 = BrandedType<bigint, "U64">;
124
+ * type U128 = BrandedType<bigint, "U128">;
125
+ *
126
+ * function encryptU64(value: U64): void { ... }
127
+ * encryptU64(myU128Value); // Compile-time error — prevents protocol bugs.
128
+ * ```
129
+ *
130
+ * @public
131
+ */
132
+ type BrandedType<Base, Brand extends string> = Base & {
133
+ readonly [BrandSymbol]: Brand;
134
+ };
135
+ /**
136
+ * Extracts the base (unbranded) type from a `BrandedType`.
137
+ *
138
+ * @remarks
139
+ * Useful in generic utilities that need to operate on the underlying representation
140
+ * without caring about the nominal layer. For non-branded types, `T` is returned
141
+ * unchanged, making this safe to apply unconditionally.
142
+ *
143
+ * @typeParam T - A `BrandedType` or plain type to unwrap.
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * type UserId = BrandedType<string, "UserId">;
148
+ * type Base = UnwrapBrand<UserId>; // string
149
+ *
150
+ * // Non-branded types pass through unchanged.
151
+ * type Plain = UnwrapBrand<number>; // number
152
+ * ```
153
+ *
154
+ * @public
155
+ */
156
+ type UnwrapBrand<T> = T extends BrandedType<infer Base, string> ? Base : T;
157
+ /**
158
+ * Extracts the brand string literal from a `BrandedType`.
159
+ *
160
+ * @remarks
161
+ * Returns `never` for types that are not `BrandedType` instances. Useful when building
162
+ * generic error messages or runtime assertions that need to name the expected brand.
163
+ *
164
+ * @typeParam T - A `BrandedType` from which to extract the brand name.
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * type UserId = BrandedType<string, "UserId">;
169
+ * type Name = ExtractBrand<UserId>; // "UserId"
170
+ *
171
+ * // Non-branded types yield never.
172
+ * type Nothing = ExtractBrand<string>; // never
173
+ * ```
174
+ *
175
+ * @public
176
+ */
177
+ type ExtractBrand<T> = T extends BrandedType<unknown, infer Brand> ? Brand : never;
178
+ /**
179
+ * Creates a sub-branded type that is a more specific variant of an existing `BrandedType`.
180
+ *
181
+ * @remarks
182
+ * A sub-branded type carries both the parent brand (via `[BrandSymbol]`) and its own
183
+ * sub-brand (via `[SubBrandSymbol]`). This means:
184
+ *
185
+ * - A `SubBrandedType<Parent, Sub>` is assignable to `Parent` (narrower types are compatible).
186
+ * - `Parent` is NOT assignable to `SubBrandedType<Parent, Sub>` (you cannot widen without
187
+ * an explicit assertion).
188
+ *
189
+ * This is used in the SDK to model byte-array hierarchies such as:
190
+ * `Bytes` → `LeBytes` → `U32LeBytes`.
191
+ *
192
+ * @typeParam Parent - The parent `BrandedType` to extend. Must already be a `BrandedType`.
193
+ * @typeParam SubBrand - A unique string literal for the sub-brand (e.g. `"LeBytes"`).
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * type Bytes = BrandedType<Uint8Array, "Bytes">;
198
+ * type LeBytes = SubBrandedType<Bytes, "LeBytes">;
199
+ * type BeBytes = SubBrandedType<Bytes, "BeBytes">;
200
+ *
201
+ * declare const le: LeBytes;
202
+ * declare const be: BeBytes;
203
+ *
204
+ * const asBytes: Bytes = le; // OK — LeBytes ⊆ Bytes
205
+ * const invalid: BeBytes = le; // Error — LeBytes is not BeBytes
206
+ * ```
207
+ *
208
+ * @public
209
+ */
210
+ type SubBrandedType<Parent extends BrandedType<unknown, string>, SubBrand extends string> = Parent & {
211
+ readonly [SubBrandSymbol]: SubBrand;
212
+ };
213
+ /**
214
+ * Creates a sub-sub-branded type for the third level of the brand hierarchy.
215
+ *
216
+ * @remarks
217
+ * Inherits both the parent brand and the sub-brand, adding a third phantom dimension via
218
+ * `[SubSubBrandSymbol]`. A `SubSubBrandedType` is assignable to its `SubBrandedType`
219
+ * parent and transitively to the root `BrandedType`, but nothing in the hierarchy can
220
+ * be widened to a `SubSubBrandedType` without an explicit assertion.
221
+ *
222
+ * Typical usage in the SDK:
223
+ * `Bytes` → `LeBytes` → `U32LeBytes`
224
+ *
225
+ * @typeParam Parent - The parent `SubBrandedType` to extend.
226
+ * @typeParam SubSubBrand - A unique string literal for this level (e.g. `"U32LeBytes"`).
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * type Bytes = BrandedType<Uint8Array, "Bytes">;
231
+ * type LeBytes = SubBrandedType<Bytes, "LeBytes">;
232
+ * type U32LeBytes = SubSubBrandedType<LeBytes, "U32LeBytes">;
233
+ *
234
+ * declare const u32: U32LeBytes;
235
+ * const asLe: LeBytes = u32; // OK
236
+ * const asBytes: Bytes = u32; // OK
237
+ * ```
238
+ *
239
+ * @public
240
+ */
241
+ type SubSubBrandedType<Parent extends SubBrandedType<BrandedType<unknown, string>, string>, SubSubBrand extends string> = Parent & {
242
+ readonly [SubSubBrandSymbol]: SubSubBrand;
243
+ };
244
+ /**
245
+ * Creates a sub-sub-sub-branded type for the fourth level of the brand hierarchy.
246
+ *
247
+ * @remarks
248
+ * Adds a fourth phantom dimension via `[SubSubSubBrandSymbol]` on top of a
249
+ * `SubSubBrandedType` parent. Assignable to all ancestor levels.
250
+ *
251
+ * Typical usage in the SDK:
252
+ * `Bytes` → `LeBytes` → `U256LeBytes` → `Keccak256Hash`
253
+ *
254
+ * @typeParam Parent - The parent `SubSubBrandedType` to extend.
255
+ * @typeParam SubSubSubBrand - A unique string literal for this level (e.g. `"Keccak256Hash"`).
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * type Bytes = BrandedType<Uint8Array, "Bytes">;
260
+ * type LeBytes = SubBrandedType<Bytes, "LeBytes">;
261
+ * type U32LeBytes = SubSubBrandedType<LeBytes, "U32LeBytes">;
262
+ * type ValidU32LeBytes = SubSubSubBrandedType<U32LeBytes, "ValidU32LeBytes">;
263
+ *
264
+ * declare const v: ValidU32LeBytes;
265
+ * const asU32: U32LeBytes = v; // OK
266
+ * const asLe: LeBytes = v; // OK
267
+ * const asBytes: Bytes = v; // OK
268
+ * ```
269
+ *
270
+ * @public
271
+ */
272
+ type SubSubSubBrandedType<Parent extends SubSubBrandedType<SubBrandedType<BrandedType<unknown, string>, string>, string>, SubSubSubBrand extends string> = Parent & {
273
+ readonly [SubSubSubBrandSymbol]: SubSubSubBrand;
274
+ };
275
+ /**
276
+ * Creates a sub-sub-sub-sub-branded type for the fifth level of the brand hierarchy.
277
+ *
278
+ * @remarks
279
+ * Adds a fifth phantom dimension via `[SubSubSubSubBrandSymbol]` on top of a
280
+ * `SubSubSubBrandedType` parent. This is the deepest level of branding supported by the
281
+ * SDK. Assignable to all four ancestor levels.
282
+ *
283
+ * Example chain used in the SDK for master seed derivation:
284
+ * `Bytes` → `LeBytes` → `U512LeBytes` → `Keccak512Hash` → `MasterSeed`
285
+ *
286
+ * @typeParam Parent - The parent `SubSubSubBrandedType` to extend.
287
+ * @typeParam SubSubSubSubBrand - A unique string literal for this level (e.g. `"MasterSeed"`).
288
+ *
289
+ * @example
290
+ * ```typescript
291
+ * type Bytes = BrandedType<Uint8Array, "Bytes">;
292
+ * type LeBytes = SubBrandedType<Bytes, "LeBytes">;
293
+ * type U512LeBytes = SubSubBrandedType<LeBytes, "U512LeBytes">;
294
+ * type Keccak512Hash = SubSubSubBrandedType<U512LeBytes, "Keccak512Hash">;
295
+ * type MasterSeed = SubSubSubSubBrandedType<Keccak512Hash, "MasterSeed">;
296
+ *
297
+ * // MasterSeed is assignable to every ancestor level.
298
+ * declare const seed: MasterSeed;
299
+ * const asHash: Keccak512Hash = seed; // OK
300
+ * const asU512: U512LeBytes = seed; // OK
301
+ * const asLe: LeBytes = seed; // OK
302
+ * const asBytes: Bytes = seed; // OK
303
+ * ```
304
+ *
305
+ * @public
306
+ */
307
+ type SubSubSubSubBrandedType<Parent extends SubSubSubBrandedType<SubSubBrandedType<SubBrandedType<BrandedType<unknown, string>, string>, string>, string>, SubSubSubSubBrand extends string> = Parent & {
308
+ readonly [SubSubSubSubBrandSymbol]: SubSubSubSubBrand;
309
+ };
310
+
311
+ /**
312
+ * Mathematics Types Module
313
+ *
314
+ * This module provides a comprehensive set of branded types and runtime assertions
315
+ * for mathematical primitives used throughout the SDK. These types ensure compile-time
316
+ * safety by preventing accidental mixing of incompatible numeric representations.
317
+ *
318
+ * ## Overview
319
+ *
320
+ * The module is organized into several categories:
321
+ *
322
+ * ### Byte Array Types
323
+ * - **Base types**: `LeBytes` (little-endian), `BeBytes` (big-endian)
324
+ * - **Sized types**: `U8LeBytes`, `U16LeBytes`, ..., `U1024LeBytes` (and BE equivalents)
325
+ *
326
+ * ### Integer Types
327
+ * - **Unsigned**: `U8`, `U16`, `U32`, `U64`, `U128`, `U256`, `U512`, `U1024`
328
+ * - **Signed**: `I8`, `I16`, `I32`, `I64`, `I128`, `I256`, `I512`, `I1024`
329
+ *
330
+ * ### Constants
331
+ * - Maximum values for unsigned types (`U8_MAX`, `U16_MAX`, etc.)
332
+ * - Min/max values for signed types (`I8_MIN`, `I8_MAX`, etc.)
333
+ * - Byte lengths for sized arrays (`U8_BYTE_LENGTH`, etc.)
334
+ *
335
+ * ### Assertion Functions
336
+ * - Runtime validation functions that throw `MathematicsAssertionError` on failure
337
+ * - Return branded types on success for type-safe usage
338
+ *
339
+ * ## Usage Example
340
+ *
341
+ * ```typescript
342
+ * import { assertU256, assertU256LeBytes, U256, U256LeBytes } from "./mathematics";
343
+ *
344
+ * // Validate and brand a bigint as U256
345
+ * const value: U256 = assertU256(12345n);
346
+ *
347
+ * // Validate and brand a byte array
348
+ * const bytes: U256LeBytes = assertU256LeBytes(new Uint8Array(32));
349
+ *
350
+ * // Type errors are caught at compile time
351
+ * function processU256(value: U256): void { ... }
352
+ * processU256(12345n); // Error: bigint is not assignable to U256
353
+ * processU256(assertU256(12345n)); // OK
354
+ * ```
355
+ *
356
+ * @since 2.0.0
357
+ * @module types/mathematics
358
+ * @see {@link ./branded} for the underlying branded type utilities
359
+ * @packageDocumentation
360
+ */
361
+
362
+ /**
363
+ * Generic branded byte array base type.
364
+ *
365
+ * This is the root type for all byte array types in the SDK.
366
+ * All specialized byte array types (LeBytes, BeBytes, X25519Bytes, etc.)
367
+ * derive from this type.
368
+ *
369
+ * Use this type when:
370
+ * - Endianness is not relevant to the operation
371
+ * - Endianness is handled externally
372
+ * - Working with raw binary data without numeric interpretation
373
+ *
374
+ * @example
375
+ * ```typescript
376
+ * function hashBytes(data: Bytes): Bytes {
377
+ * // Endianness doesn't matter for hashing
378
+ * return sha256(data);
379
+ * }
380
+ * ```
381
+ *
382
+ * @public
383
+ */
384
+ type Bytes = BrandedType<Uint8Array, "Bytes">;
385
+ /**
386
+ * Little-endian byte array base type.
387
+ *
388
+ * Little-endian format stores the **least significant byte first**.
389
+ * This is the native byte order for:
390
+ * - x86 and x64 processors (Intel, AMD)
391
+ * - ARM processors (in little-endian mode)
392
+ * - Most modern desktop and mobile CPUs
393
+ *
394
+ * @remarks
395
+ * Little-endian is often more efficient for arithmetic operations
396
+ * as the least significant bytes can be processed first.
397
+ *
398
+ * @example
399
+ * ```typescript
400
+ * // The 32-bit number 0x12345678 in little-endian:
401
+ * // Memory layout: [0x78, 0x56, 0x34, 0x12]
402
+ * // LSB MSB
403
+ * const leBytes = assertLeBytes(new Uint8Array([0x78, 0x56, 0x34, 0x12]));
404
+ *
405
+ * // Converting to number (conceptually):
406
+ * // 0x78 + (0x56 << 8) + (0x34 << 16) + (0x12 << 24) = 0x12345678
407
+ * ```
408
+ *
409
+ * @see {@link BeBytes} for big-endian representation
410
+ * @public
411
+ */
412
+ type LeBytes = SubBrandedType<Bytes, "LeBytes">;
413
+ /**
414
+ * Big-endian byte array base type.
415
+ *
416
+ * Big-endian format stores the **most significant byte first**.
417
+ * This is used in:
418
+ * - Network protocols (TCP/IP) - hence "network byte order"
419
+ * - Many file formats (JPEG, PNG headers)
420
+ * - Java's DataInputStream/DataOutputStream
421
+ * - Most cryptographic specifications
422
+ *
423
+ * @remarks
424
+ * Big-endian is often more human-readable as bytes appear in the
425
+ * same order as the hexadecimal representation.
426
+ *
427
+ * @example
428
+ * ```typescript
429
+ * // The 32-bit number 0x12345678 in big-endian:
430
+ * // Memory layout: [0x12, 0x34, 0x56, 0x78]
431
+ * // MSB LSB
432
+ * const beBytes = assertBeBytes(new Uint8Array([0x12, 0x34, 0x56, 0x78]));
433
+ *
434
+ * // The hex string "12345678" maps directly to bytes
435
+ * ```
436
+ *
437
+ * @see {@link LeBytes} for little-endian representation
438
+ * @public
439
+ */
440
+ type BeBytes = SubBrandedType<Bytes, "BeBytes">;
441
+ /**
442
+ * 8-bit (1 byte) little-endian byte array.
443
+ *
444
+ * Represents a single byte, which is endianness-agnostic.
445
+ * Included for API consistency with larger sizes.
446
+ *
447
+ * @remarks
448
+ * - Size: 1 byte
449
+ * - Value range: [0, 255] (0x00 to 0xFF)
450
+ *
451
+ * @example
452
+ * ```typescript
453
+ * const byte = assertU8LeBytes(new Uint8Array([0xFF]));
454
+ * // Represents the value 255
455
+ * ```
456
+ *
457
+ * @see {@link assertU8LeBytes}
458
+ * @public
459
+ */
460
+ type U8LeBytes = SubSubBrandedType<LeBytes, "U8LeBytes">;
461
+ /**
462
+ * 16-bit (2 bytes) little-endian byte array.
463
+ *
464
+ * @remarks
465
+ * - Size: 2 bytes
466
+ * - Value range: [0, 65,535] (0x0000 to 0xFFFF)
467
+ *
468
+ * @example
469
+ * ```typescript
470
+ * // Value 0x1234 in little-endian
471
+ * const bytes = assertU16LeBytes(new Uint8Array([0x34, 0x12]));
472
+ * ```
473
+ *
474
+ * @see {@link assertU16LeBytes}
475
+ * @public
476
+ */
477
+ type U16LeBytes = SubSubBrandedType<LeBytes, "U16LeBytes">;
478
+ /**
479
+ * 32-bit (4 bytes) little-endian byte array.
480
+ *
481
+ * @remarks
482
+ * - Size: 4 bytes
483
+ * - Value range: [0, 4,294,967,295] (0x00000000 to 0xFFFFFFFF)
484
+ * - Common use: IPv4 addresses, 32-bit hashes, timestamps
485
+ *
486
+ * @example
487
+ * ```typescript
488
+ * // Value 0x12345678 in little-endian
489
+ * const bytes = assertU32LeBytes(new Uint8Array([0x78, 0x56, 0x34, 0x12]));
490
+ * ```
491
+ *
492
+ * @see {@link assertU32LeBytes}
493
+ * @public
494
+ */
495
+ type U32LeBytes = SubSubBrandedType<LeBytes, "U32LeBytes">;
496
+ /**
497
+ * 64-bit (8 bytes) little-endian byte array.
498
+ *
499
+ * @remarks
500
+ * - Size: 8 bytes
501
+ * - Value range: [0, 2^64 - 1]
502
+ * - Common use: Timestamps with nanosecond precision, large counters
503
+ *
504
+ * @example
505
+ * ```typescript
506
+ * const bytes = assertU64LeBytes(new Uint8Array(8));
507
+ * ```
508
+ *
509
+ * @see {@link assertU64LeBytes}
510
+ * @public
511
+ */
512
+ type U64LeBytes = SubSubBrandedType<LeBytes, "U64LeBytes">;
513
+ /**
514
+ * 128-bit (16 bytes) little-endian byte array.
515
+ *
516
+ * @remarks
517
+ * - Size: 16 bytes
518
+ * - Value range: [0, 2^128 - 1]
519
+ * - Common use: UUIDs, AES block size
520
+ *
521
+ * @example
522
+ * ```typescript
523
+ * const bytes = assertU128LeBytes(new Uint8Array(16));
524
+ * ```
525
+ *
526
+ * @see {@link assertU128LeBytes}
527
+ * @public
528
+ */
529
+ type U128LeBytes = SubSubBrandedType<LeBytes, "U128LeBytes">;
530
+ /**
531
+ * 256-bit (32 bytes) little-endian byte array.
532
+ *
533
+ * @remarks
534
+ * - Size: 32 bytes
535
+ * - Value range: [0, 2^256 - 1]
536
+ * - Common use: SHA-256 hashes, elliptic curve scalars, private keys
537
+ *
538
+ * @example
539
+ * ```typescript
540
+ * // A 256-bit cryptographic scalar
541
+ * const scalar = assertU256LeBytes(new Uint8Array(32));
542
+ * ```
543
+ *
544
+ * @see {@link assertU256LeBytes}
545
+ * @public
546
+ */
547
+ type U256LeBytes = SubSubBrandedType<LeBytes, "U256LeBytes">;
548
+ /**
549
+ * 512-bit (64 bytes) little-endian byte array.
550
+ *
551
+ * @remarks
552
+ * - Size: 64 bytes
553
+ * - Value range: [0, 2^512 - 1]
554
+ * - Common use: SHA-512 hashes, extended keys
555
+ *
556
+ * @example
557
+ * ```typescript
558
+ * const bytes = assertU512LeBytes(new Uint8Array(64));
559
+ * ```
560
+ *
561
+ * @see {@link assertU512LeBytes}
562
+ * @public
563
+ */
564
+ type U512LeBytes = SubSubBrandedType<LeBytes, "U512LeBytes">;
565
+ /**
566
+ * 1024-bit (128 bytes) little-endian byte array.
567
+ *
568
+ * @remarks
569
+ * - Size: 128 bytes
570
+ * - Value range: [0, 2^1024 - 1]
571
+ * - Common use: RSA keys, large cryptographic values
572
+ *
573
+ * @example
574
+ * ```typescript
575
+ * const bytes = assertU1024LeBytes(new Uint8Array(128));
576
+ * ```
577
+ *
578
+ * @see {@link assertU1024LeBytes}
579
+ * @public
580
+ */
581
+ type U1024LeBytes = SubSubBrandedType<LeBytes, "U1024LeBytes">;
582
+ /**
583
+ * 8-bit (1 byte) big-endian byte array.
584
+ *
585
+ * Represents a single byte, which is endianness-agnostic.
586
+ * Included for API consistency with larger sizes.
587
+ *
588
+ * @remarks
589
+ * - Size: 1 byte
590
+ * - Value range: [0, 255] (0x00 to 0xFF)
591
+ *
592
+ * @example
593
+ * ```typescript
594
+ * const byte = assertU8BeBytes(new Uint8Array([0xFF]));
595
+ * ```
596
+ *
597
+ * @see {@link assertU8BeBytes}
598
+ * @public
599
+ */
600
+ type U8BeBytes = SubSubBrandedType<BeBytes, "U8BeBytes">;
601
+ /**
602
+ * 16-bit (2 bytes) big-endian byte array.
603
+ *
604
+ * @remarks
605
+ * - Size: 2 bytes
606
+ * - Value range: [0, 65,535]
607
+ * - Common use: Network port numbers, protocol headers
608
+ *
609
+ * @example
610
+ * ```typescript
611
+ * // Value 0x1234 in big-endian (network byte order)
612
+ * const bytes = assertU16BeBytes(new Uint8Array([0x12, 0x34]));
613
+ * ```
614
+ *
615
+ * @see {@link assertU16BeBytes}
616
+ * @public
617
+ */
618
+ type U16BeBytes = SubSubBrandedType<BeBytes, "U16BeBytes">;
619
+ /**
620
+ * 32-bit (4 bytes) big-endian byte array.
621
+ *
622
+ * @remarks
623
+ * - Size: 4 bytes
624
+ * - Value range: [0, 4,294,967,295]
625
+ * - Common use: Network addresses, protocol fields
626
+ *
627
+ * @example
628
+ * ```typescript
629
+ * // Value 0x12345678 in big-endian
630
+ * const bytes = assertU32BeBytes(new Uint8Array([0x12, 0x34, 0x56, 0x78]));
631
+ * ```
632
+ *
633
+ * @see {@link assertU32BeBytes}
634
+ * @public
635
+ */
636
+ type U32BeBytes = SubSubBrandedType<BeBytes, "U32BeBytes">;
637
+ /**
638
+ * 64-bit (8 bytes) big-endian byte array.
639
+ *
640
+ * @remarks
641
+ * - Size: 8 bytes
642
+ * - Value range: [0, 2^64 - 1]
643
+ *
644
+ * @example
645
+ * ```typescript
646
+ * const bytes = assertU64BeBytes(new Uint8Array(8));
647
+ * ```
648
+ *
649
+ * @see {@link assertU64BeBytes}
650
+ * @public
651
+ */
652
+ type U64BeBytes = SubSubBrandedType<BeBytes, "U64BeBytes">;
653
+ /**
654
+ * 128-bit (16 bytes) big-endian byte array.
655
+ *
656
+ * @remarks
657
+ * - Size: 16 bytes
658
+ * - Value range: [0, 2^128 - 1]
659
+ * - Common use: UUIDs in standard format, IPv6 addresses
660
+ *
661
+ * @example
662
+ * ```typescript
663
+ * const bytes = assertU128BeBytes(new Uint8Array(16));
664
+ * ```
665
+ *
666
+ * @see {@link assertU128BeBytes}
667
+ * @public
668
+ */
669
+ type U128BeBytes = SubSubBrandedType<BeBytes, "U128BeBytes">;
670
+ /**
671
+ * 256-bit (32 bytes) big-endian byte array.
672
+ *
673
+ * @remarks
674
+ * - Size: 32 bytes
675
+ * - Value range: [0, 2^256 - 1]
676
+ * - Common use: Ethereum addresses (20 bytes, but often padded), field elements
677
+ *
678
+ * @example
679
+ * ```typescript
680
+ * const bytes = assertU256BeBytes(new Uint8Array(32));
681
+ * ```
682
+ *
683
+ * @see {@link assertU256BeBytes}
684
+ * @public
685
+ */
686
+ type U256BeBytes = SubSubBrandedType<BeBytes, "U256BeBytes">;
687
+ /**
688
+ * 512-bit (64 bytes) big-endian byte array.
689
+ *
690
+ * @remarks
691
+ * - Size: 64 bytes
692
+ * - Value range: [0, 2^512 - 1]
693
+ *
694
+ * @example
695
+ * ```typescript
696
+ * const bytes = assertU512BeBytes(new Uint8Array(64));
697
+ * ```
698
+ *
699
+ * @see {@link assertU512BeBytes}
700
+ * @public
701
+ */
702
+ type U512BeBytes = SubSubBrandedType<BeBytes, "U512BeBytes">;
703
+ /**
704
+ * 1024-bit (128 bytes) big-endian byte array.
705
+ *
706
+ * @remarks
707
+ * - Size: 128 bytes
708
+ * - Value range: [0, 2^1024 - 1]
709
+ *
710
+ * @example
711
+ * ```typescript
712
+ * const bytes = assertU1024BeBytes(new Uint8Array(128));
713
+ * ```
714
+ *
715
+ * @see {@link assertU1024BeBytes}
716
+ * @public
717
+ */
718
+ type U1024BeBytes = SubSubBrandedType<BeBytes, "U1024BeBytes">;
719
+ /**
720
+ * Base type for all unsigned integers.
721
+ *
722
+ * Unsigned integers represent non-negative whole numbers (0, 1, 2, ...).
723
+ * All specific unsigned integer types (`U8`, `U16`, etc.) are sub-brands of this type.
724
+ *
725
+ * @remarks
726
+ * - Uses JavaScript's `BigInt` for arbitrary precision arithmetic
727
+ * - No upper bound at the base type level (bounds are enforced by sub-types)
728
+ * - Guaranteed to be non-negative (>= 0)
729
+ *
730
+ * ## Type Hierarchy
731
+ * ```
732
+ * bigint
733
+ * └── UnsignedInteger (branded, value >= 0)
734
+ * ├── U8 (0 to 255)
735
+ * ├── U16 (0 to 65,535)
736
+ * ├── U32 (0 to 4,294,967,295)
737
+ * └── ...
738
+ * ```
739
+ *
740
+ * @example
741
+ * ```typescript
742
+ * const value = assertUnsignedInteger(12345n);
743
+ * // value is typed as UnsignedInteger
744
+ *
745
+ * // Can be assigned to functions expecting UnsignedInteger
746
+ * function processUnsigned(n: UnsignedInteger): void { ... }
747
+ * processUnsigned(value); // OK
748
+ * ```
749
+ *
750
+ * @see {@link assertUnsignedInteger}
751
+ * @public
752
+ */
753
+ type UnsignedInteger = BrandedType<bigint, "UnsignedInteger">;
754
+ /**
755
+ * Base type for all signed integers.
756
+ *
757
+ * Signed integers represent whole numbers including negatives (..., -2, -1, 0, 1, 2, ...).
758
+ * All specific signed integer types (`I8`, `I16`, etc.) are sub-brands of this type.
759
+ *
760
+ * @remarks
761
+ * - Uses JavaScript's `BigInt` for arbitrary precision arithmetic
762
+ * - No bounds at the base type level (bounds are enforced by sub-types)
763
+ * - Two's complement representation is assumed for negative values
764
+ *
765
+ * ## Two's Complement
766
+ * Two's complement is the standard way computers represent signed integers:
767
+ * - Positive numbers are represented normally
768
+ * - Negative numbers: invert all bits and add 1
769
+ * - Example (8-bit): -1 = 0xFF, -128 = 0x80
770
+ *
771
+ * ## Type Hierarchy
772
+ * ```
773
+ * bigint
774
+ * └── SignedInteger (branded)
775
+ * ├── I8 (-128 to 127)
776
+ * ├── I16 (-32,768 to 32,767)
777
+ * ├── I32 (-2,147,483,648 to 2,147,483,647)
778
+ * └── ...
779
+ * ```
780
+ *
781
+ * @example
782
+ * ```typescript
783
+ * const value = assertSignedInteger(-12345n);
784
+ * // value is typed as SignedInteger
785
+ * ```
786
+ *
787
+ * @see {@link assertSignedInteger}
788
+ * @public
789
+ */
790
+ type SignedInteger = BrandedType<bigint, "SignedInteger">;
791
+ /**
792
+ * 8-bit unsigned integer.
793
+ *
794
+ * @remarks
795
+ * - Bit width: 8 bits (1 byte)
796
+ * - Range: [0, 255] or [0x00, 0xFF]
797
+ * - Max value: 2^8 - 1 = 255
798
+ *
799
+ * ## Common Uses
800
+ * - Single byte values
801
+ * - Color channel values (RGB)
802
+ * - Character codes (ASCII)
803
+ * - Small counters and flags
804
+ *
805
+ * @example
806
+ * ```typescript
807
+ * const red: U8 = assertU8(255n); // Maximum red
808
+ * const green: U8 = assertU8(128n); // Medium green
809
+ * const blue: U8 = assertU8(0n); // No blue
810
+ * ```
811
+ *
812
+ * @see {@link assertU8}
813
+ * @see {@link U8_MAX}
814
+ * @public
815
+ */
816
+ type U8 = SubBrandedType<UnsignedInteger, "U8">;
817
+ /**
818
+ * 16-bit unsigned integer.
819
+ *
820
+ * @remarks
821
+ * - Bit width: 16 bits (2 bytes)
822
+ * - Range: [0, 65,535] or [0x0000, 0xFFFF]
823
+ * - Max value: 2^16 - 1 = 65,535
824
+ *
825
+ * ## Common Uses
826
+ * - Port numbers (0-65535)
827
+ * - Unicode code points (BMP)
828
+ * - Audio samples (16-bit PCM)
829
+ * - Small array indices
830
+ *
831
+ * @example
832
+ * ```typescript
833
+ * const port: U16 = assertU16(443n); // HTTPS port
834
+ * const sample: U16 = assertU16(32768n); // Audio sample
835
+ * ```
836
+ *
837
+ * @see {@link assertU16}
838
+ * @see {@link U16_MAX}
839
+ * @public
840
+ */
841
+ type U16 = SubBrandedType<UnsignedInteger, "U16">;
842
+ /**
843
+ * 32-bit unsigned integer.
844
+ *
845
+ * @remarks
846
+ * - Bit width: 32 bits (4 bytes)
847
+ * - Range: [0, 4,294,967,295] or [0x00000000, 0xFFFFFFFF]
848
+ * - Max value: 2^32 - 1 = 4,294,967,295 (~4.3 billion)
849
+ *
850
+ * ## Common Uses
851
+ * - IPv4 addresses
852
+ * - Unix timestamps (until 2038)
853
+ * - Array indices
854
+ * - Color values (RGBA packed)
855
+ * - CRC32 checksums
856
+ *
857
+ * @example
858
+ * ```typescript
859
+ * const timestamp: U32 = assertU32(1704067200n); // 2024-01-01 00:00:00 UTC
860
+ * const ipAddress: U32 = assertU32(0x7F000001n); // 127.0.0.1
861
+ * ```
862
+ *
863
+ * @see {@link assertU32}
864
+ * @see {@link U32_MAX}
865
+ * @public
866
+ */
867
+ type U32 = SubBrandedType<UnsignedInteger, "U32">;
868
+ /**
869
+ * 64-bit unsigned integer.
870
+ *
871
+ * @remarks
872
+ * - Bit width: 64 bits (8 bytes)
873
+ * - Range: [0, 18,446,744,073,709,551,615]
874
+ * - Max value: 2^64 - 1 (~18.4 quintillion)
875
+ *
876
+ * ## Common Uses
877
+ * - High-precision timestamps (nanoseconds)
878
+ * - File sizes
879
+ * - Database primary keys
880
+ * - Memory addresses
881
+ * - Large counters
882
+ *
883
+ * @example
884
+ * ```typescript
885
+ * const nanoTimestamp: U64 = assertU64(1704067200000000000n);
886
+ * const fileSize: U64 = assertU64(1099511627776n); // 1 TiB
887
+ * ```
888
+ *
889
+ * @see {@link assertU64}
890
+ * @see {@link U64_MAX}
891
+ * @public
892
+ */
893
+ type U64 = SubBrandedType<UnsignedInteger, "U64">;
894
+ /**
895
+ * 128-bit unsigned integer.
896
+ *
897
+ * @remarks
898
+ * - Bit width: 128 bits (16 bytes)
899
+ * - Range: [0, 2^128 - 1]
900
+ * - Max value: ~3.4 × 10^38
901
+ *
902
+ * ## Common Uses
903
+ * - UUIDs (128-bit identifiers)
904
+ * - IPv6 addresses
905
+ * - Cryptographic nonces
906
+ * - Very large counters
907
+ *
908
+ * @example
909
+ * ```typescript
910
+ * const uuid: U128 = assertU128(0x550e8400e29b41d4a716446655440000n);
911
+ * ```
912
+ *
913
+ * @see {@link assertU128}
914
+ * @see {@link U128_MAX}
915
+ * @public
916
+ */
917
+ type U128 = SubBrandedType<UnsignedInteger, "U128">;
918
+ /**
919
+ * 256-bit unsigned integer.
920
+ *
921
+ * @remarks
922
+ * - Bit width: 256 bits (32 bytes)
923
+ * - Range: [0, 2^256 - 1]
924
+ * - Max value: ~1.16 × 10^77
925
+ *
926
+ * ## Common Uses
927
+ * - Elliptic curve field elements (BN254, secp256k1)
928
+ * - Cryptographic scalars and private keys
929
+ * - SHA-256 hash outputs
930
+ * - Blockchain addresses and balances
931
+ *
932
+ * ## Cryptographic Significance
933
+ * 256 bits provides approximately 128 bits of security for symmetric
934
+ * operations and is the standard size for modern elliptic curves.
935
+ *
936
+ * @example
937
+ * ```typescript
938
+ * // A private key (256-bit scalar)
939
+ * const privateKey: U256 = assertU256(
940
+ * 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdefn
941
+ * );
942
+ *
943
+ * // A SHA-256 hash interpreted as a number
944
+ * const hashValue: U256 = assertU256(hashAsNumber);
945
+ * ```
946
+ *
947
+ * @see {@link assertU256}
948
+ * @see {@link U256_MAX}
949
+ * @public
950
+ */
951
+ type U256 = SubBrandedType<UnsignedInteger, "U256">;
952
+ /**
953
+ * 512-bit unsigned integer.
954
+ *
955
+ * @remarks
956
+ * - Bit width: 512 bits (64 bytes)
957
+ * - Range: [0, 2^512 - 1]
958
+ *
959
+ * ## Common Uses
960
+ * - SHA-512 hash outputs
961
+ * - Extended cryptographic keys
962
+ * - Large field elements
963
+ *
964
+ * @example
965
+ * ```typescript
966
+ * const hash: U512 = assertU512(sha512HashValue);
967
+ * ```
968
+ *
969
+ * @see {@link assertU512}
970
+ * @see {@link U512_MAX}
971
+ * @public
972
+ */
973
+ type U512 = SubBrandedType<UnsignedInteger, "U512">;
974
+ /**
975
+ * 1024-bit unsigned integer.
976
+ *
977
+ * @remarks
978
+ * - Bit width: 1024 bits (128 bytes)
979
+ * - Range: [0, 2^1024 - 1]
980
+ *
981
+ * ## Common Uses
982
+ * - RSA key components
983
+ * - Very large cryptographic values
984
+ * - Pairing-based cryptography
985
+ *
986
+ * @example
987
+ * ```typescript
988
+ * const rsaModulus: U1024 = assertU1024(modulusValue);
989
+ * ```
990
+ *
991
+ * @see {@link assertU1024}
992
+ * @see {@link U1024_MAX}
993
+ * @public
994
+ */
995
+ type U1024 = SubBrandedType<UnsignedInteger, "U1024">;
996
+ /**
997
+ * 8-bit signed integer.
998
+ *
999
+ * @remarks
1000
+ * - Bit width: 8 bits (1 byte)
1001
+ * - Range: [-128, 127] or [-2^7, 2^7 - 1]
1002
+ * - Uses two's complement representation
1003
+ *
1004
+ * ## Two's Complement Values
1005
+ * - 0x00 = 0
1006
+ * - 0x7F = 127 (maximum positive)
1007
+ * - 0x80 = -128 (minimum negative)
1008
+ * - 0xFF = -1
1009
+ *
1010
+ * @example
1011
+ * ```typescript
1012
+ * const positive: I8 = assertI8(127n);
1013
+ * const negative: I8 = assertI8(-128n);
1014
+ * const zero: I8 = assertI8(0n);
1015
+ * ```
1016
+ *
1017
+ * @see {@link assertI8}
1018
+ * @see {@link I8_MIN}
1019
+ * @see {@link I8_MAX}
1020
+ * @public
1021
+ */
1022
+ type I8 = SubBrandedType<SignedInteger, "I8">;
1023
+ /**
1024
+ * 16-bit signed integer.
1025
+ *
1026
+ * @remarks
1027
+ * - Bit width: 16 bits (2 bytes)
1028
+ * - Range: [-32,768, 32,767] or [-2^15, 2^15 - 1]
1029
+ * - Uses two's complement representation
1030
+ *
1031
+ * ## Common Uses
1032
+ * - Audio samples (16-bit signed PCM)
1033
+ * - Small offsets and deltas
1034
+ *
1035
+ * @example
1036
+ * ```typescript
1037
+ * const audioSample: I16 = assertI16(-16384n);
1038
+ * ```
1039
+ *
1040
+ * @see {@link assertI16}
1041
+ * @see {@link I16_MIN}
1042
+ * @see {@link I16_MAX}
1043
+ * @public
1044
+ */
1045
+ type I16 = SubBrandedType<SignedInteger, "I16">;
1046
+ /**
1047
+ * 32-bit signed integer.
1048
+ *
1049
+ * @remarks
1050
+ * - Bit width: 32 bits (4 bytes)
1051
+ * - Range: [-2,147,483,648, 2,147,483,647] or [-2^31, 2^31 - 1]
1052
+ * - Uses two's complement representation
1053
+ *
1054
+ * ## Common Uses
1055
+ * - General-purpose integers
1056
+ * - Array indices (with negative sentinel values)
1057
+ * - Differences and offsets
1058
+ *
1059
+ * @example
1060
+ * ```typescript
1061
+ * const offset: I32 = assertI32(-1000n);
1062
+ * const index: I32 = assertI32(42n);
1063
+ * ```
1064
+ *
1065
+ * @see {@link assertI32}
1066
+ * @see {@link I32_MIN}
1067
+ * @see {@link I32_MAX}
1068
+ * @public
1069
+ */
1070
+ type I32 = SubBrandedType<SignedInteger, "I32">;
1071
+ /**
1072
+ * 64-bit signed integer.
1073
+ *
1074
+ * @remarks
1075
+ * - Bit width: 64 bits (8 bytes)
1076
+ * - Range: [-9,223,372,036,854,775,808, 9,223,372,036,854,775,807]
1077
+ * - Range: [-2^63, 2^63 - 1]
1078
+ * - Uses two's complement representation
1079
+ *
1080
+ * ## Common Uses
1081
+ * - Large offsets and differences
1082
+ * - Signed timestamps
1083
+ * - Financial calculations (with appropriate scaling)
1084
+ *
1085
+ * @example
1086
+ * ```typescript
1087
+ * const difference: I64 = assertI64(-1000000000000n);
1088
+ * ```
1089
+ *
1090
+ * @see {@link assertI64}
1091
+ * @see {@link I64_MIN}
1092
+ * @see {@link I64_MAX}
1093
+ * @public
1094
+ */
1095
+ type I64 = SubBrandedType<SignedInteger, "I64">;
1096
+ /**
1097
+ * 128-bit signed integer.
1098
+ *
1099
+ * @remarks
1100
+ * - Bit width: 128 bits (16 bytes)
1101
+ * - Range: [-2^127, 2^127 - 1]
1102
+ * - Uses two's complement representation
1103
+ *
1104
+ * @example
1105
+ * ```typescript
1106
+ * const value: I128 = assertI128(-170141183460469231731687303715884105728n);
1107
+ * ```
1108
+ *
1109
+ * @see {@link assertI128}
1110
+ * @see {@link I128_MIN}
1111
+ * @see {@link I128_MAX}
1112
+ * @public
1113
+ */
1114
+ type I128 = SubBrandedType<SignedInteger, "I128">;
1115
+ /**
1116
+ * 256-bit signed integer.
1117
+ *
1118
+ * @remarks
1119
+ * - Bit width: 256 bits (32 bytes)
1120
+ * - Range: [-2^255, 2^255 - 1]
1121
+ * - Uses two's complement representation
1122
+ *
1123
+ * ## Common Uses
1124
+ * - Signed cryptographic values
1125
+ * - Large signed arithmetic
1126
+ *
1127
+ * @example
1128
+ * ```typescript
1129
+ * const signedScalar: I256 = assertI256(-12345678901234567890n);
1130
+ * ```
1131
+ *
1132
+ * @see {@link assertI256}
1133
+ * @see {@link I256_MIN}
1134
+ * @see {@link I256_MAX}
1135
+ * @public
1136
+ */
1137
+ type I256 = SubBrandedType<SignedInteger, "I256">;
1138
+ /**
1139
+ * 512-bit signed integer.
1140
+ *
1141
+ * @remarks
1142
+ * - Bit width: 512 bits (64 bytes)
1143
+ * - Range: [-2^511, 2^511 - 1]
1144
+ * - Uses two's complement representation
1145
+ *
1146
+ * @example
1147
+ * ```typescript
1148
+ * const value: I512 = assertI512(-1n);
1149
+ * ```
1150
+ *
1151
+ * @see {@link assertI512}
1152
+ * @see {@link I512_MIN}
1153
+ * @see {@link I512_MAX}
1154
+ * @public
1155
+ */
1156
+ type I512 = SubBrandedType<SignedInteger, "I512">;
1157
+ /**
1158
+ * 1024-bit signed integer.
1159
+ *
1160
+ * @remarks
1161
+ * - Bit width: 1024 bits (128 bytes)
1162
+ * - Range: [-2^1023, 2^1023 - 1]
1163
+ * - Uses two's complement representation
1164
+ *
1165
+ * @example
1166
+ * ```typescript
1167
+ * const value: I1024 = assertI1024(0n);
1168
+ * ```
1169
+ *
1170
+ * @see {@link assertI1024}
1171
+ * @see {@link I1024_MIN}
1172
+ * @see {@link I1024_MAX}
1173
+ * @public
1174
+ */
1175
+ type I1024 = SubBrandedType<SignedInteger, "I1024">;
1176
+ /**
1177
+ * Maximum value for an 8-bit unsigned integer.
1178
+ *
1179
+ * @remarks
1180
+ * - Value: 255 (0xFF)
1181
+ * - Formula: 2^8 - 1
1182
+ *
1183
+ * @example
1184
+ * ```typescript
1185
+ * if (value > U8_MAX) {
1186
+ * throw new Error("Value exceeds U8 range");
1187
+ * }
1188
+ * ```
1189
+ *
1190
+ * @see {@link U8}
1191
+ * @public
1192
+ */
1193
+ declare const U8_MAX = 255n;
1194
+ /**
1195
+ * Maximum value for a 16-bit unsigned integer.
1196
+ *
1197
+ * @remarks
1198
+ * - Value: 65,535 (0xFFFF)
1199
+ * - Formula: 2^16 - 1
1200
+ *
1201
+ * @example
1202
+ * ```typescript
1203
+ * if (portNumber > U16_MAX) {
1204
+ * throw new Error("Port number exceeds U16 range");
1205
+ * }
1206
+ * ```
1207
+ *
1208
+ * @see {@link U16}
1209
+ * @public
1210
+ */
1211
+ declare const U16_MAX = 65535n;
1212
+ /**
1213
+ * Maximum value for a 32-bit unsigned integer.
1214
+ *
1215
+ * @remarks
1216
+ * - Value: 4,294,967,295 (0xFFFFFFFF)
1217
+ * - Formula: 2^32 - 1
1218
+ *
1219
+ * @example
1220
+ * ```typescript
1221
+ * if (timestamp > U32_MAX) {
1222
+ * throw new Error("Timestamp exceeds U32 range (Year 2038 problem)");
1223
+ * }
1224
+ * ```
1225
+ *
1226
+ * @see {@link U32}
1227
+ * @public
1228
+ */
1229
+ declare const U32_MAX = 4294967295n;
1230
+ /**
1231
+ * Maximum value for a 64-bit unsigned integer.
1232
+ *
1233
+ * @remarks
1234
+ * - Value: 18,446,744,073,709,551,615 (0xFFFFFFFFFFFFFFFF)
1235
+ * - Formula: 2^64 - 1
1236
+ *
1237
+ * @example
1238
+ * ```typescript
1239
+ * if (counter > U64_MAX) {
1240
+ * throw new Error("Counter exceeds U64 range");
1241
+ * }
1242
+ * ```
1243
+ *
1244
+ * @see {@link U64}
1245
+ * @public
1246
+ */
1247
+ declare const U64_MAX = 18446744073709551615n;
1248
+ /**
1249
+ * Maximum value for a 128-bit unsigned integer.
1250
+ *
1251
+ * @remarks
1252
+ * - Value: 2^128 - 1
1253
+ * - Approximately: 3.4 × 10^38
1254
+ *
1255
+ * @example
1256
+ * ```typescript
1257
+ * if (value > U128_MAX) {
1258
+ * throw new Error("Value exceeds U128 range");
1259
+ * }
1260
+ * ```
1261
+ *
1262
+ * @see {@link U128}
1263
+ * @public
1264
+ */
1265
+ declare const U128_MAX: bigint;
1266
+ /**
1267
+ * Maximum value for a 256-bit unsigned integer.
1268
+ *
1269
+ * @remarks
1270
+ * - Value: 2^256 - 1
1271
+ * - Approximately: 1.16 × 10^77
1272
+ * - This exceeds the estimated number of atoms in the observable universe
1273
+ *
1274
+ * @example
1275
+ * ```typescript
1276
+ * // Validate a field element is within BN254 range (BN254 prime < U256_MAX)
1277
+ * if (fieldElement > U256_MAX) {
1278
+ * throw new Error("Field element exceeds U256 range");
1279
+ * }
1280
+ * ```
1281
+ *
1282
+ * @see {@link U256}
1283
+ * @public
1284
+ */
1285
+ declare const U256_MAX: bigint;
1286
+ /**
1287
+ * Maximum value for a 512-bit unsigned integer.
1288
+ *
1289
+ * @remarks
1290
+ * - Value: 2^512 - 1
1291
+ *
1292
+ * @example
1293
+ * ```typescript
1294
+ * if (value > U512_MAX) {
1295
+ * throw new Error("Value exceeds U512 range");
1296
+ * }
1297
+ * ```
1298
+ *
1299
+ * @see {@link U512}
1300
+ * @public
1301
+ */
1302
+ declare const U512_MAX: bigint;
1303
+ /**
1304
+ * Maximum value for a 1024-bit unsigned integer.
1305
+ *
1306
+ * @remarks
1307
+ * - Value: 2^1024 - 1
1308
+ *
1309
+ * @example
1310
+ * ```typescript
1311
+ * if (rsaModulus > U1024_MAX) {
1312
+ * throw new Error("RSA modulus exceeds U1024 range");
1313
+ * }
1314
+ * ```
1315
+ *
1316
+ * @see {@link U1024}
1317
+ * @public
1318
+ */
1319
+ declare const U1024_MAX: bigint;
1320
+ /**
1321
+ * Minimum value for an 8-bit signed integer.
1322
+ *
1323
+ * @remarks
1324
+ * - Value: -128 (0x80 in two's complement)
1325
+ * - Formula: -2^7
1326
+ *
1327
+ * @see {@link I8}
1328
+ * @public
1329
+ */
1330
+ declare const I8_MIN: bigint;
1331
+ /**
1332
+ * Maximum value for an 8-bit signed integer.
1333
+ *
1334
+ * @remarks
1335
+ * - Value: 127 (0x7F)
1336
+ * - Formula: 2^7 - 1
1337
+ *
1338
+ * @see {@link I8}
1339
+ * @public
1340
+ */
1341
+ declare const I8_MAX: bigint;
1342
+ /**
1343
+ * Minimum value for a 16-bit signed integer.
1344
+ *
1345
+ * @remarks
1346
+ * - Value: -32,768
1347
+ * - Formula: -2^15
1348
+ *
1349
+ * @see {@link I16}
1350
+ * @public
1351
+ */
1352
+ declare const I16_MIN: bigint;
1353
+ /**
1354
+ * Maximum value for a 16-bit signed integer.
1355
+ *
1356
+ * @remarks
1357
+ * - Value: 32,767
1358
+ * - Formula: 2^15 - 1
1359
+ *
1360
+ * @see {@link I16}
1361
+ * @public
1362
+ */
1363
+ declare const I16_MAX: bigint;
1364
+ /**
1365
+ * Minimum value for a 32-bit signed integer.
1366
+ *
1367
+ * @remarks
1368
+ * - Value: -2,147,483,648
1369
+ * - Formula: -2^31
1370
+ *
1371
+ * @see {@link I32}
1372
+ * @public
1373
+ */
1374
+ declare const I32_MIN: bigint;
1375
+ /**
1376
+ * Maximum value for a 32-bit signed integer.
1377
+ *
1378
+ * @remarks
1379
+ * - Value: 2,147,483,647
1380
+ * - Formula: 2^31 - 1
1381
+ *
1382
+ * @see {@link I32}
1383
+ * @public
1384
+ */
1385
+ declare const I32_MAX: bigint;
1386
+ /**
1387
+ * Minimum value for a 64-bit signed integer.
1388
+ *
1389
+ * @remarks
1390
+ * - Value: -9,223,372,036,854,775,808
1391
+ * - Formula: -2^63
1392
+ *
1393
+ * @see {@link I64}
1394
+ * @public
1395
+ */
1396
+ declare const I64_MIN: bigint;
1397
+ /**
1398
+ * Maximum value for a 64-bit signed integer.
1399
+ *
1400
+ * @remarks
1401
+ * - Value: 9,223,372,036,854,775,807
1402
+ * - Formula: 2^63 - 1
1403
+ *
1404
+ * @see {@link I64}
1405
+ * @public
1406
+ */
1407
+ declare const I64_MAX: bigint;
1408
+ /**
1409
+ * Minimum value for a 128-bit signed integer.
1410
+ *
1411
+ * @remarks
1412
+ * - Formula: -2^127
1413
+ *
1414
+ * @see {@link I128}
1415
+ * @public
1416
+ */
1417
+ declare const I128_MIN: bigint;
1418
+ /**
1419
+ * Maximum value for a 128-bit signed integer.
1420
+ *
1421
+ * @remarks
1422
+ * - Formula: 2^127 - 1
1423
+ *
1424
+ * @see {@link I128}
1425
+ * @public
1426
+ */
1427
+ declare const I128_MAX: bigint;
1428
+ /**
1429
+ * Minimum value for a 256-bit signed integer.
1430
+ *
1431
+ * @remarks
1432
+ * - Formula: -2^255
1433
+ *
1434
+ * @see {@link I256}
1435
+ * @public
1436
+ */
1437
+ declare const I256_MIN: bigint;
1438
+ /**
1439
+ * Maximum value for a 256-bit signed integer.
1440
+ *
1441
+ * @remarks
1442
+ * - Formula: 2^255 - 1
1443
+ *
1444
+ * @see {@link I256}
1445
+ * @public
1446
+ */
1447
+ declare const I256_MAX: bigint;
1448
+ /**
1449
+ * Minimum value for a 512-bit signed integer.
1450
+ *
1451
+ * @remarks
1452
+ * - Formula: -2^511
1453
+ *
1454
+ * @see {@link I512}
1455
+ * @public
1456
+ */
1457
+ declare const I512_MIN: bigint;
1458
+ /**
1459
+ * Maximum value for a 512-bit signed integer.
1460
+ *
1461
+ * @remarks
1462
+ * - Formula: 2^511 - 1
1463
+ *
1464
+ * @see {@link I512}
1465
+ * @public
1466
+ */
1467
+ declare const I512_MAX: bigint;
1468
+ /**
1469
+ * Minimum value for a 1024-bit signed integer.
1470
+ *
1471
+ * @remarks
1472
+ * - Formula: -2^1023
1473
+ *
1474
+ * @see {@link I1024}
1475
+ * @public
1476
+ */
1477
+ declare const I1024_MIN: bigint;
1478
+ /**
1479
+ * Maximum value for a 1024-bit signed integer.
1480
+ *
1481
+ * @remarks
1482
+ * - Formula: 2^1023 - 1
1483
+ *
1484
+ * @see {@link I1024}
1485
+ * @public
1486
+ */
1487
+ declare const I1024_MAX: bigint;
1488
+ /**
1489
+ * Expected byte length for 8-bit values.
1490
+ *
1491
+ * @remarks Value: 1 byte
1492
+ *
1493
+ * @example
1494
+ * ```typescript
1495
+ * const bytes = new Uint8Array(U8_BYTE_LENGTH); // 1 byte
1496
+ * ```
1497
+ *
1498
+ * @see {@link U8LeBytes}
1499
+ * @see {@link U8BeBytes}
1500
+ * @public
1501
+ */
1502
+ declare const U8_BYTE_LENGTH = 1;
1503
+ /**
1504
+ * Expected byte length for 16-bit values.
1505
+ *
1506
+ * @remarks Value: 2 bytes
1507
+ *
1508
+ * @example
1509
+ * ```typescript
1510
+ * const bytes = new Uint8Array(U16_BYTE_LENGTH); // 2 bytes
1511
+ * ```
1512
+ *
1513
+ * @see {@link U16LeBytes}
1514
+ * @see {@link U16BeBytes}
1515
+ * @public
1516
+ */
1517
+ declare const U16_BYTE_LENGTH = 2;
1518
+ /**
1519
+ * Expected byte length for 32-bit values.
1520
+ *
1521
+ * @remarks Value: 4 bytes
1522
+ *
1523
+ * @example
1524
+ * ```typescript
1525
+ * const bytes = new Uint8Array(U32_BYTE_LENGTH); // 4 bytes
1526
+ * ```
1527
+ *
1528
+ * @see {@link U32LeBytes}
1529
+ * @see {@link U32BeBytes}
1530
+ * @public
1531
+ */
1532
+ declare const U32_BYTE_LENGTH = 4;
1533
+ /**
1534
+ * Expected byte length for 64-bit values.
1535
+ *
1536
+ * @remarks Value: 8 bytes
1537
+ *
1538
+ * @example
1539
+ * ```typescript
1540
+ * const bytes = new Uint8Array(U64_BYTE_LENGTH); // 8 bytes
1541
+ * ```
1542
+ *
1543
+ * @see {@link U64LeBytes}
1544
+ * @see {@link U64BeBytes}
1545
+ * @public
1546
+ */
1547
+ declare const U64_BYTE_LENGTH = 8;
1548
+ /**
1549
+ * Expected byte length for 128-bit values.
1550
+ *
1551
+ * @remarks Value: 16 bytes
1552
+ *
1553
+ * @example
1554
+ * ```typescript
1555
+ * const bytes = new Uint8Array(U128_BYTE_LENGTH); // 16 bytes
1556
+ * ```
1557
+ *
1558
+ * @see {@link U128LeBytes}
1559
+ * @see {@link U128BeBytes}
1560
+ * @public
1561
+ */
1562
+ declare const U128_BYTE_LENGTH = 16;
1563
+ /**
1564
+ * Expected byte length for 256-bit values.
1565
+ *
1566
+ * @remarks Value: 32 bytes
1567
+ *
1568
+ * @example
1569
+ * ```typescript
1570
+ * // Allocate a buffer for a 256-bit cryptographic scalar
1571
+ * const scalarBytes = new Uint8Array(U256_BYTE_LENGTH); // 32 bytes
1572
+ * ```
1573
+ *
1574
+ * @see {@link U256LeBytes}
1575
+ * @see {@link U256BeBytes}
1576
+ * @public
1577
+ */
1578
+ declare const U256_BYTE_LENGTH = 32;
1579
+ /**
1580
+ * Expected byte length for 512-bit values.
1581
+ *
1582
+ * @remarks Value: 64 bytes
1583
+ *
1584
+ * @example
1585
+ * ```typescript
1586
+ * const bytes = new Uint8Array(U512_BYTE_LENGTH); // 64 bytes
1587
+ * ```
1588
+ *
1589
+ * @see {@link U512LeBytes}
1590
+ * @see {@link U512BeBytes}
1591
+ * @public
1592
+ */
1593
+ declare const U512_BYTE_LENGTH = 64;
1594
+ /**
1595
+ * Expected byte length for 1024-bit values.
1596
+ *
1597
+ * @remarks Value: 128 bytes
1598
+ *
1599
+ * @example
1600
+ * ```typescript
1601
+ * const bytes = new Uint8Array(U1024_BYTE_LENGTH); // 128 bytes
1602
+ * ```
1603
+ *
1604
+ * @see {@link U1024LeBytes}
1605
+ * @see {@link U1024BeBytes}
1606
+ * @public
1607
+ */
1608
+ declare const U1024_BYTE_LENGTH = 128;
1609
+ /**
1610
+ * Error thrown when a value fails a mathematical type assertion.
1611
+ *
1612
+ * This error provides detailed information about why an assertion failed,
1613
+ * including the actual value, the expected type, and the constraint that
1614
+ * was violated.
1615
+ *
1616
+ * @remarks
1617
+ * All assertion functions in this module throw this error type on failure.
1618
+ * You can catch this specific error type to handle assertion failures
1619
+ * differently from other errors.
1620
+ *
1621
+ * ## Error Properties
1622
+ * - `value`: The actual value that failed assertion
1623
+ * - `expectedType`: The type that was expected (e.g., "U8", "U256LeBytes")
1624
+ * - `constraint`: Optional description of the constraint that was violated
1625
+ *
1626
+ * @example
1627
+ * ```typescript
1628
+ * import { assertU8, MathematicsAssertionError } from "./mathematics";
1629
+ *
1630
+ * try {
1631
+ * const value = assertU8(256n); // Will throw
1632
+ * } catch (error) {
1633
+ * if (error instanceof MathematicsAssertionError) {
1634
+ * console.error(`Assertion failed for ${error.expectedType}`);
1635
+ * console.error(`Value: ${error.value}`);
1636
+ * console.error(`Constraint: ${error.constraint}`);
1637
+ * // Output:
1638
+ * // Assertion failed for U8
1639
+ * // Value: 256
1640
+ * // Constraint: 0 <= value <= 255
1641
+ * }
1642
+ * }
1643
+ * ```
1644
+ *
1645
+ * @example
1646
+ * ```typescript
1647
+ * // Custom error handling
1648
+ * function safeParseU8(value: bigint): U8 | null {
1649
+ * try {
1650
+ * return assertU8(value);
1651
+ * } catch (error) {
1652
+ * if (error instanceof MathematicsAssertionError) {
1653
+ * console.warn(`Invalid U8 value: ${value}`);
1654
+ * return null;
1655
+ * }
1656
+ * throw error; // Re-throw unexpected errors
1657
+ * }
1658
+ * }
1659
+ * ```
1660
+ *
1661
+ * @sealed
1662
+ * @public
1663
+ */
1664
+ declare class MathematicsAssertionError extends Error {
1665
+ /**
1666
+ * The actual value that failed the assertion.
1667
+ *
1668
+ * @remarks
1669
+ * This can be any type depending on what was being asserted.
1670
+ * For integer assertions, this will be a `bigint`.
1671
+ * For byte array assertions, this will be a `Uint8Array`.
1672
+ *
1673
+ * @readonly
1674
+ */
1675
+ readonly value: unknown;
1676
+ /**
1677
+ * The type that was expected.
1678
+ *
1679
+ * @remarks
1680
+ * This is the branded type name (e.g., "U8", "U256", "U32LeBytes").
1681
+ *
1682
+ * @readonly
1683
+ */
1684
+ readonly expectedType: string;
1685
+ /**
1686
+ * Description of the constraint that was violated.
1687
+ *
1688
+ * @remarks
1689
+ * This is `undefined` if only a type check failed (e.g., expected bigint, got string).
1690
+ * It contains a human-readable constraint description when a value is out of range.
1691
+ *
1692
+ * @example
1693
+ * - "0 <= value <= 255" for U8 range violations
1694
+ * - "length === 32" for U256LeBytes length violations
1695
+ * - "value >= 0" for negative unsigned integer attempts
1696
+ *
1697
+ * @readonly
1698
+ */
1699
+ readonly constraint: string | undefined;
1700
+ /**
1701
+ * Creates a new MathematicsAssertionError.
1702
+ *
1703
+ * @param message - Human-readable error message
1704
+ * @param options - Error details
1705
+ * @param options.value - The value that failed assertion
1706
+ * @param options.expectedType - The expected type name
1707
+ * @param options.constraint - Optional constraint description
1708
+ */
1709
+ constructor(message: string, options: {
1710
+ value: unknown;
1711
+ expectedType: string;
1712
+ constraint?: string;
1713
+ });
1714
+ }
1715
+ /**
1716
+ * Asserts that a value is a valid Uint8Array and narrows it to `Bytes`.
1717
+ *
1718
+ * This is the base assertion for all byte array types. It validates that
1719
+ * the input is a `Uint8Array` instance.
1720
+ *
1721
+ * @param value - The Uint8Array to assert
1722
+ * @throws {MathematicsAssertionError} If the value is not a Uint8Array
1723
+ *
1724
+ * @example
1725
+ * ```typescript
1726
+ * const rawBytes = new Uint8Array([0x01, 0x02, 0x03]);
1727
+ * assertBytes(rawBytes);
1728
+ * // rawBytes is now typed as Bytes
1729
+ * ```
1730
+ *
1731
+ * @returns `void` — type narrowing is applied to the argument in-place.
1732
+ * @see {@link Bytes}
1733
+ * @public
1734
+ */
1735
+ declare function assertBytes(value: Uint8Array): asserts value is Bytes;
1736
+ /**
1737
+ * Asserts that a value is a valid Uint8Array and narrows it to `LeBytes`.
1738
+ *
1739
+ * This function validates that the input is a `Uint8Array` instance and
1740
+ * uses TypeScript's type narrowing to treat it as a little-endian byte array.
1741
+ * No length validation is performed.
1742
+ *
1743
+ * @param value - The Uint8Array to assert
1744
+ * @throws {MathematicsAssertionError} If the value is not a Uint8Array
1745
+ *
1746
+ * @remarks
1747
+ * This is the base assertion for little-endian byte arrays.
1748
+ * For sized byte arrays, use the specific assertions like `assertU32LeBytes`.
1749
+ *
1750
+ * @example
1751
+ * ```typescript
1752
+ * // Brand a byte array as little-endian
1753
+ * const rawBytes = new Uint8Array([0x78, 0x56, 0x34, 0x12]);
1754
+ * assertLeBytes(rawBytes);
1755
+ * // rawBytes is now typed as LeBytes
1756
+ *
1757
+ * // The branded type prevents mixing with big-endian
1758
+ * function processLittleEndian(bytes: LeBytes): void { ... }
1759
+ * processLittleEndian(rawBytes); // OK after assertion
1760
+ * ```
1761
+ *
1762
+ * @returns `void` — type narrowing is applied to the argument in-place.
1763
+ * @see {@link LeBytes}
1764
+ * @public
1765
+ */
1766
+ declare function assertLeBytes(value: Uint8Array): asserts value is LeBytes;
1767
+ /**
1768
+ * Asserts that a value is a valid Uint8Array and narrows it to `BeBytes`.
1769
+ *
1770
+ * This function validates that the input is a `Uint8Array` instance and
1771
+ * uses TypeScript's type narrowing to treat it as a big-endian byte array.
1772
+ * No length validation is performed.
1773
+ *
1774
+ * @param value - The Uint8Array to assert
1775
+ * @throws {MathematicsAssertionError} If the value is not a Uint8Array
1776
+ *
1777
+ * @remarks
1778
+ * This is the base assertion for big-endian byte arrays.
1779
+ * For sized byte arrays, use the specific assertions like `assertU32BeBytes`.
1780
+ *
1781
+ * @example
1782
+ * ```typescript
1783
+ * // Brand a byte array as big-endian (network byte order)
1784
+ * const rawBytes = new Uint8Array([0x12, 0x34, 0x56, 0x78]);
1785
+ * assertBeBytes(rawBytes);
1786
+ * // rawBytes is now typed as BeBytes
1787
+ *
1788
+ * // Use for network protocol data
1789
+ * function sendNetworkData(bytes: BeBytes): void { ... }
1790
+ * sendNetworkData(rawBytes); // OK after assertion
1791
+ * ```
1792
+ *
1793
+ * @returns `void` — type narrowing is applied to the argument in-place.
1794
+ * @see {@link BeBytes}
1795
+ * @public
1796
+ */
1797
+ declare function assertBeBytes(value: Uint8Array): asserts value is BeBytes;
1798
+ /**
1799
+ * Asserts that a value is a 1-byte little-endian byte array.
1800
+ *
1801
+ * @param value - The Uint8Array to assert (must be exactly 1 byte)
1802
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
1803
+ *
1804
+ * @example
1805
+ * ```typescript
1806
+ * const byte = new Uint8Array([0xFF]);
1807
+ * assertU8LeBytes(byte);
1808
+ * // byte is now typed as U8LeBytes
1809
+ * ```
1810
+ *
1811
+ * @returns `void` — type narrowing is applied to the argument in-place.
1812
+ * @see {@link U8LeBytes}
1813
+ * @public
1814
+ */
1815
+ declare function assertU8LeBytes(value: Uint8Array): asserts value is U8LeBytes;
1816
+ /**
1817
+ * Asserts that a value is a 2-byte little-endian byte array.
1818
+ *
1819
+ * @param value - The Uint8Array to assert (must be exactly 2 bytes)
1820
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
1821
+ *
1822
+ * @example
1823
+ * ```typescript
1824
+ * // 0x1234 in little-endian
1825
+ * const bytes = new Uint8Array([0x34, 0x12]);
1826
+ * assertU16LeBytes(bytes);
1827
+ * // bytes is now typed as U16LeBytes
1828
+ * ```
1829
+ *
1830
+ * @returns `void` — type narrowing is applied to the argument in-place.
1831
+ * @see {@link U16LeBytes}
1832
+ * @public
1833
+ */
1834
+ declare function assertU16LeBytes(value: Uint8Array): asserts value is U16LeBytes;
1835
+ /**
1836
+ * Asserts that a value is a 4-byte little-endian byte array.
1837
+ *
1838
+ * @param value - The Uint8Array to assert (must be exactly 4 bytes)
1839
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
1840
+ *
1841
+ * @example
1842
+ * ```typescript
1843
+ * // 0x12345678 in little-endian
1844
+ * const bytes = new Uint8Array([0x78, 0x56, 0x34, 0x12]);
1845
+ * assertU32LeBytes(bytes);
1846
+ * // bytes is now typed as U32LeBytes
1847
+ * ```
1848
+ *
1849
+ * @returns `void` — type narrowing is applied to the argument in-place.
1850
+ * @see {@link U32LeBytes}
1851
+ * @public
1852
+ */
1853
+ declare function assertU32LeBytes(value: Uint8Array): asserts value is U32LeBytes;
1854
+ /**
1855
+ * Asserts that a value is an 8-byte little-endian byte array.
1856
+ *
1857
+ * @param value - The Uint8Array to assert (must be exactly 8 bytes)
1858
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
1859
+ *
1860
+ * @example
1861
+ * ```typescript
1862
+ * const bytes = new Uint8Array(8);
1863
+ * assertU64LeBytes(bytes);
1864
+ * // bytes is now typed as U64LeBytes
1865
+ * ```
1866
+ *
1867
+ * @returns `void` — type narrowing is applied to the argument in-place.
1868
+ * @see {@link U64LeBytes}
1869
+ * @public
1870
+ */
1871
+ declare function assertU64LeBytes(value: Uint8Array): asserts value is U64LeBytes;
1872
+ /**
1873
+ * Asserts that a value is a 16-byte little-endian byte array.
1874
+ *
1875
+ * @param value - The Uint8Array to assert (must be exactly 16 bytes)
1876
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
1877
+ *
1878
+ * @example
1879
+ * ```typescript
1880
+ * const bytes = new Uint8Array(16);
1881
+ * assertU128LeBytes(bytes);
1882
+ * // bytes is now typed as U128LeBytes
1883
+ * ```
1884
+ *
1885
+ * @returns `void` — type narrowing is applied to the argument in-place.
1886
+ * @see {@link U128LeBytes}
1887
+ * @public
1888
+ */
1889
+ declare function assertU128LeBytes(value: Uint8Array): asserts value is U128LeBytes;
1890
+ /**
1891
+ * Asserts that a value is a 32-byte little-endian byte array.
1892
+ *
1893
+ * @param value - The Uint8Array to assert (must be exactly 32 bytes)
1894
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
1895
+ *
1896
+ * @remarks
1897
+ * 32-byte arrays are commonly used for:
1898
+ * - SHA-256 hash outputs
1899
+ * - Elliptic curve scalars
1900
+ * - Private keys
1901
+ *
1902
+ * @example
1903
+ * ```typescript
1904
+ * // Create a 256-bit scalar representation
1905
+ * const scalar = new Uint8Array(32);
1906
+ * assertU256LeBytes(scalar);
1907
+ * // scalar is now typed as U256LeBytes
1908
+ * ```
1909
+ *
1910
+ * @returns `void` — type narrowing is applied to the argument in-place.
1911
+ * @see {@link U256LeBytes}
1912
+ * @public
1913
+ */
1914
+ declare function assertU256LeBytes(value: Uint8Array): asserts value is U256LeBytes;
1915
+ /**
1916
+ * Asserts that a value is a 64-byte little-endian byte array.
1917
+ *
1918
+ * @param value - The Uint8Array to assert (must be exactly 64 bytes)
1919
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
1920
+ *
1921
+ * @example
1922
+ * ```typescript
1923
+ * const bytes = new Uint8Array(64);
1924
+ * assertU512LeBytes(bytes);
1925
+ * // bytes is now typed as U512LeBytes
1926
+ * ```
1927
+ *
1928
+ * @returns `void` — type narrowing is applied to the argument in-place.
1929
+ * @see {@link U512LeBytes}
1930
+ * @public
1931
+ */
1932
+ declare function assertU512LeBytes(value: Uint8Array): asserts value is U512LeBytes;
1933
+ /**
1934
+ * Asserts that a value is a 128-byte little-endian byte array.
1935
+ *
1936
+ * @param value - The Uint8Array to assert (must be exactly 128 bytes)
1937
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
1938
+ *
1939
+ * @example
1940
+ * ```typescript
1941
+ * const bytes = new Uint8Array(128);
1942
+ * assertU1024LeBytes(bytes);
1943
+ * // bytes is now typed as U1024LeBytes
1944
+ * ```
1945
+ *
1946
+ * @returns `void` — type narrowing is applied to the argument in-place.
1947
+ * @see {@link U1024LeBytes}
1948
+ * @public
1949
+ */
1950
+ declare function assertU1024LeBytes(value: Uint8Array): asserts value is U1024LeBytes;
1951
+ /**
1952
+ * Asserts that a value is a 1-byte big-endian byte array.
1953
+ *
1954
+ * @param value - The Uint8Array to assert (must be exactly 1 byte)
1955
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
1956
+ *
1957
+ * @example
1958
+ * ```typescript
1959
+ * const byte = new Uint8Array([0xFF]);
1960
+ * assertU8BeBytes(byte);
1961
+ * // byte is now typed as U8BeBytes
1962
+ * ```
1963
+ *
1964
+ * @returns `void` — type narrowing is applied to the argument in-place.
1965
+ * @see {@link U8BeBytes}
1966
+ * @public
1967
+ */
1968
+ declare function assertU8BeBytes(value: Uint8Array): asserts value is U8BeBytes;
1969
+ /**
1970
+ * Asserts that a value is a 2-byte big-endian byte array.
1971
+ *
1972
+ * @param value - The Uint8Array to assert (must be exactly 2 bytes)
1973
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
1974
+ *
1975
+ * @example
1976
+ * ```typescript
1977
+ * // Network port 443 in big-endian
1978
+ * const portBytes = new Uint8Array([0x01, 0xBB]);
1979
+ * assertU16BeBytes(portBytes);
1980
+ * // portBytes is now typed as U16BeBytes
1981
+ * ```
1982
+ *
1983
+ * @returns `void` — type narrowing is applied to the argument in-place.
1984
+ * @see {@link U16BeBytes}
1985
+ * @public
1986
+ */
1987
+ declare function assertU16BeBytes(value: Uint8Array): asserts value is U16BeBytes;
1988
+ /**
1989
+ * Asserts that a value is a 4-byte big-endian byte array.
1990
+ *
1991
+ * @param value - The Uint8Array to assert (must be exactly 4 bytes)
1992
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
1993
+ *
1994
+ * @example
1995
+ * ```typescript
1996
+ * // IP address 127.0.0.1 in big-endian
1997
+ * const ipBytes = new Uint8Array([127, 0, 0, 1]);
1998
+ * assertU32BeBytes(ipBytes);
1999
+ * // ipBytes is now typed as U32BeBytes
2000
+ * ```
2001
+ *
2002
+ * @returns `void` — type narrowing is applied to the argument in-place.
2003
+ * @see {@link U32BeBytes}
2004
+ * @public
2005
+ */
2006
+ declare function assertU32BeBytes(value: Uint8Array): asserts value is U32BeBytes;
2007
+ /**
2008
+ * Asserts that a value is an 8-byte big-endian byte array.
2009
+ *
2010
+ * @param value - The Uint8Array to assert (must be exactly 8 bytes)
2011
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
2012
+ *
2013
+ * @example
2014
+ * ```typescript
2015
+ * const bytes = new Uint8Array(8);
2016
+ * assertU64BeBytes(bytes);
2017
+ * // bytes is now typed as U64BeBytes
2018
+ * ```
2019
+ *
2020
+ * @returns `void` — type narrowing is applied to the argument in-place.
2021
+ * @see {@link U64BeBytes}
2022
+ * @public
2023
+ */
2024
+ declare function assertU64BeBytes(value: Uint8Array): asserts value is U64BeBytes;
2025
+ /**
2026
+ * Asserts that a value is a 16-byte big-endian byte array.
2027
+ *
2028
+ * @param value - The Uint8Array to assert (must be exactly 16 bytes)
2029
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
2030
+ *
2031
+ * @example
2032
+ * ```typescript
2033
+ * // UUID bytes in big-endian format
2034
+ * const uuidBytes = new Uint8Array(16);
2035
+ * assertU128BeBytes(uuidBytes);
2036
+ * // uuidBytes is now typed as U128BeBytes
2037
+ * ```
2038
+ *
2039
+ * @returns `void` — type narrowing is applied to the argument in-place.
2040
+ * @see {@link U128BeBytes}
2041
+ * @public
2042
+ */
2043
+ declare function assertU128BeBytes(value: Uint8Array): asserts value is U128BeBytes;
2044
+ /**
2045
+ * Asserts that a value is a 32-byte big-endian byte array.
2046
+ *
2047
+ * @param value - The Uint8Array to assert (must be exactly 32 bytes)
2048
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
2049
+ *
2050
+ * @remarks
2051
+ * Big-endian 256-bit arrays are common in cryptographic specifications
2052
+ * and blockchain protocols.
2053
+ *
2054
+ * @example
2055
+ * ```typescript
2056
+ * // Hash output in standard big-endian format
2057
+ * assertU256BeBytes(sha256Result);
2058
+ * // sha256Result is now typed as U256BeBytes
2059
+ * ```
2060
+ *
2061
+ * @returns `void` — type narrowing is applied to the argument in-place.
2062
+ * @see {@link U256BeBytes}
2063
+ * @public
2064
+ */
2065
+ declare function assertU256BeBytes(value: Uint8Array): asserts value is U256BeBytes;
2066
+ /**
2067
+ * Asserts that a value is a 64-byte big-endian byte array.
2068
+ *
2069
+ * @param value - The Uint8Array to assert (must be exactly 64 bytes)
2070
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
2071
+ *
2072
+ * @example
2073
+ * ```typescript
2074
+ * const bytes = new Uint8Array(64);
2075
+ * assertU512BeBytes(bytes);
2076
+ * // bytes is now typed as U512BeBytes
2077
+ * ```
2078
+ *
2079
+ * @returns `void` — type narrowing is applied to the argument in-place.
2080
+ * @see {@link U512BeBytes}
2081
+ * @public
2082
+ */
2083
+ declare function assertU512BeBytes(value: Uint8Array): asserts value is U512BeBytes;
2084
+ /**
2085
+ * Asserts that a value is a 128-byte big-endian byte array.
2086
+ *
2087
+ * @param value - The Uint8Array to assert (must be exactly 128 bytes)
2088
+ * @throws {MathematicsAssertionError} If not a Uint8Array or wrong length
2089
+ *
2090
+ * @example
2091
+ * ```typescript
2092
+ * const bytes = new Uint8Array(128);
2093
+ * assertU1024BeBytes(bytes);
2094
+ * // bytes is now typed as U1024BeBytes
2095
+ * ```
2096
+ *
2097
+ * @returns `void` — type narrowing is applied to the argument in-place.
2098
+ * @see {@link U1024BeBytes}
2099
+ * @public
2100
+ */
2101
+ declare function assertU1024BeBytes(value: Uint8Array): asserts value is U1024BeBytes;
2102
+ /**
2103
+ * Asserts that a value is a non-negative bigint and narrows it to `UnsignedInteger`.
2104
+ *
2105
+ * This is the base assertion for all unsigned integer types.
2106
+ * It validates that the value is a `bigint` and is non-negative (>= 0).
2107
+ *
2108
+ * @param value - The bigint to assert (must be >= 0)
2109
+ * @throws {MathematicsAssertionError} If not a bigint or if negative
2110
+ *
2111
+ * @remarks
2112
+ * Use this when you need to ensure a value is unsigned but don't need
2113
+ * a specific bit-width constraint.
2114
+ *
2115
+ * @example
2116
+ * ```typescript
2117
+ * const value = 12345n;
2118
+ * assertUnsignedInteger(value);
2119
+ * // value is now typed as UnsignedInteger
2120
+ *
2121
+ * assertUnsignedInteger(-1n); // Throws: negative value
2122
+ * ```
2123
+ *
2124
+ * @returns `void` — type narrowing is applied to the argument in-place.
2125
+ * @see {@link UnsignedInteger}
2126
+ * @public
2127
+ */
2128
+ declare function assertUnsignedInteger(value: bigint): asserts value is UnsignedInteger;
2129
+ /**
2130
+ * Asserts that a value is a bigint and narrows it to `SignedInteger`.
2131
+ *
2132
+ * This is the base assertion for all signed integer types.
2133
+ * It only validates that the value is a `bigint` (no range constraints).
2134
+ *
2135
+ * @param value - The bigint to assert
2136
+ * @throws {MathematicsAssertionError} If not a bigint
2137
+ *
2138
+ * @remarks
2139
+ * Use this when you need to ensure a value is a bigint but don't need
2140
+ * a specific bit-width constraint.
2141
+ *
2142
+ * @example
2143
+ * ```typescript
2144
+ * const value = -12345n;
2145
+ * assertSignedInteger(value);
2146
+ * // value is now typed as SignedInteger
2147
+ * ```
2148
+ *
2149
+ * @returns `void` — type narrowing is applied to the argument in-place.
2150
+ * @see {@link SignedInteger}
2151
+ * @public
2152
+ */
2153
+ declare function assertSignedInteger(value: bigint): asserts value is SignedInteger;
2154
+ /**
2155
+ * Asserts that a value is a valid 8-bit unsigned integer (0 to 255).
2156
+ *
2157
+ * @param value - The bigint to assert (must be in range [0, 255])
2158
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2159
+ *
2160
+ * @example
2161
+ * ```typescript
2162
+ * const value = 255n;
2163
+ * assertU8(value);
2164
+ * // value is now typed as U8
2165
+ *
2166
+ * assertU8(256n); // Throws: exceeds maximum
2167
+ * assertU8(-1n); // Throws: below minimum
2168
+ * ```
2169
+ *
2170
+ * @returns `void` — type narrowing is applied to the argument in-place.
2171
+ * @see {@link U8}
2172
+ * @public
2173
+ */
2174
+ declare function assertU8(value: bigint): asserts value is U8;
2175
+ /**
2176
+ * Asserts that a value is a valid 16-bit unsigned integer (0 to 65,535).
2177
+ *
2178
+ * @param value - The bigint to assert (must be in range [0, 65535])
2179
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2180
+ *
2181
+ * @example
2182
+ * ```typescript
2183
+ * const port = 443n;
2184
+ * assertU16(port);
2185
+ * // port is now typed as U16
2186
+ *
2187
+ * assertU16(65536n); // Throws: exceeds maximum
2188
+ * ```
2189
+ *
2190
+ * @returns `void` — type narrowing is applied to the argument in-place.
2191
+ * @see {@link U16}
2192
+ * @public
2193
+ */
2194
+ declare function assertU16(value: bigint): asserts value is U16;
2195
+ /**
2196
+ * Asserts that a value is a valid 32-bit unsigned integer (0 to 4,294,967,295).
2197
+ *
2198
+ * @param value - The bigint to assert (must be in range [0, 4294967295])
2199
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2200
+ *
2201
+ * @example
2202
+ * ```typescript
2203
+ * const timestamp = 1704067200n;
2204
+ * assertU32(timestamp);
2205
+ * // timestamp is now typed as U32
2206
+ *
2207
+ * assertU32(4294967296n); // Throws: exceeds maximum (2^32)
2208
+ * ```
2209
+ *
2210
+ * @returns `void` — type narrowing is applied to the argument in-place.
2211
+ * @see {@link U32}
2212
+ * @public
2213
+ */
2214
+ declare function assertU32(value: bigint): asserts value is U32;
2215
+ /**
2216
+ * Asserts that a value is a valid 64-bit unsigned integer.
2217
+ *
2218
+ * @param value - The bigint to assert (must be in range [0, 2^64 - 1])
2219
+ * @param name - The name of the variable being asserted, used in error messages for context.
2220
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2221
+ *
2222
+ * @defaultValue `name` defaults to `"value"`
2223
+ *
2224
+ * @example
2225
+ * ```typescript
2226
+ * const large = 18446744073709551615n;
2227
+ * assertU64(large, "large");
2228
+ * // large is now typed as U64
2229
+ * ```
2230
+ *
2231
+ * @returns `void` — type narrowing is applied to the argument in-place.
2232
+ * @see {@link U64}
2233
+ * @public
2234
+ */
2235
+ declare function assertU64(value: bigint, name?: string): asserts value is U64;
2236
+ /**
2237
+ * Asserts that a value is a valid 128-bit unsigned integer.
2238
+ *
2239
+ * @param value - The bigint to assert (must be in range [0, 2^128 - 1])
2240
+ * @param name - The name of the variable being asserted, used in error messages for context.
2241
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2242
+ *
2243
+ * @defaultValue `name` defaults to `"value"`
2244
+ *
2245
+ * @example
2246
+ * ```typescript
2247
+ * const uuid = 0x550e8400e29b41d4a716446655440000n;
2248
+ * assertU128(uuid, "uuid");
2249
+ * // uuid is now typed as U128
2250
+ * ```
2251
+ *
2252
+ * @returns `void` — type narrowing is applied to the argument in-place.
2253
+ * @see {@link U128}
2254
+ * @public
2255
+ */
2256
+ declare function assertU128(value: bigint, name?: string): asserts value is U128;
2257
+ /**
2258
+ * Asserts that a value is a valid 256-bit unsigned integer.
2259
+ *
2260
+ * @param value - The bigint to assert (must be in range [0, 2^256 - 1])
2261
+ * @param name - The name of the variable being asserted, used in error messages for context.
2262
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2263
+ *
2264
+ * @defaultValue `name` defaults to `"value"`
2265
+ *
2266
+ * @remarks
2267
+ * This is commonly used for elliptic curve operations where scalars
2268
+ * and field elements must be within the 256-bit range.
2269
+ *
2270
+ * @example
2271
+ * ```typescript
2272
+ * // Validate a private key is in valid range
2273
+ * assertU256(secretKeyBigInt, "secretKeyBigInt");
2274
+ * // secretKeyBigInt is now typed as U256
2275
+ *
2276
+ * // Validate a hash value
2277
+ * assertU256(sha256AsBigInt, "sha256AsBigInt");
2278
+ * // sha256AsBigInt is now typed as U256
2279
+ * ```
2280
+ *
2281
+ * @returns `void` — type narrowing is applied to the argument in-place.
2282
+ * @see {@link U256}
2283
+ * @public
2284
+ */
2285
+ declare function assertU256(value: bigint, name?: string): asserts value is U256;
2286
+ /**
2287
+ * Asserts that a value is a valid 512-bit unsigned integer.
2288
+ *
2289
+ * @param value - The bigint to assert (must be in range [0, 2^512 - 1])
2290
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2291
+ *
2292
+ * @example
2293
+ * ```typescript
2294
+ * assertU512(sha512AsBigInt);
2295
+ * // sha512AsBigInt is now typed as U512
2296
+ * ```
2297
+ *
2298
+ * @returns `void` — type narrowing is applied to the argument in-place.
2299
+ * @see {@link U512}
2300
+ * @public
2301
+ */
2302
+ declare function assertU512(value: bigint): asserts value is U512;
2303
+ /**
2304
+ * Asserts that a value is a valid 1024-bit unsigned integer.
2305
+ *
2306
+ * @param value - The bigint to assert (must be in range [0, 2^1024 - 1])
2307
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2308
+ *
2309
+ * @example
2310
+ * ```typescript
2311
+ * assertU1024(modulusBigInt);
2312
+ * // modulusBigInt is now typed as U1024
2313
+ * ```
2314
+ *
2315
+ * @returns `void` — type narrowing is applied to the argument in-place.
2316
+ * @see {@link U1024}
2317
+ * @public
2318
+ */
2319
+ declare function assertU1024(value: bigint): asserts value is U1024;
2320
+ /**
2321
+ * Asserts that a value is a valid 8-bit signed integer (-128 to 127).
2322
+ *
2323
+ * @param value - The bigint to assert (must be in range [-128, 127])
2324
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2325
+ *
2326
+ * @example
2327
+ * ```typescript
2328
+ * const value = 127n;
2329
+ * assertI8(value);
2330
+ * // value is now typed as I8
2331
+ *
2332
+ * assertI8(128n); // Throws: exceeds maximum
2333
+ * assertI8(-129n); // Throws: below minimum
2334
+ * ```
2335
+ *
2336
+ * @returns `void` — type narrowing is applied to the argument in-place.
2337
+ * @see {@link I8}
2338
+ * @public
2339
+ */
2340
+ declare function assertI8(value: bigint): asserts value is I8;
2341
+ /**
2342
+ * Asserts that a value is a valid 16-bit signed integer (-32,768 to 32,767).
2343
+ *
2344
+ * @param value - The bigint to assert (must be in range [-32768, 32767])
2345
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2346
+ *
2347
+ * @example
2348
+ * ```typescript
2349
+ * const audioSample = -16384n;
2350
+ * assertI16(audioSample);
2351
+ * // audioSample is now typed as I16
2352
+ * ```
2353
+ *
2354
+ * @returns `void` — type narrowing is applied to the argument in-place.
2355
+ * @see {@link I16}
2356
+ * @public
2357
+ */
2358
+ declare function assertI16(value: bigint): asserts value is I16;
2359
+ /**
2360
+ * Asserts that a value is a valid 32-bit signed integer.
2361
+ *
2362
+ * @param value - The bigint to assert (must be in range [-2147483648, 2147483647])
2363
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2364
+ *
2365
+ * @example
2366
+ * ```typescript
2367
+ * const offset = -1000n;
2368
+ * assertI32(offset);
2369
+ * // offset is now typed as I32
2370
+ * ```
2371
+ *
2372
+ * @returns `void` — type narrowing is applied to the argument in-place.
2373
+ * @see {@link I32}
2374
+ * @public
2375
+ */
2376
+ declare function assertI32(value: bigint): asserts value is I32;
2377
+ /**
2378
+ * Asserts that a value is a valid 64-bit signed integer.
2379
+ *
2380
+ * @param value - The bigint to assert (must be in range [-2^63, 2^63 - 1])
2381
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2382
+ *
2383
+ * @example
2384
+ * ```typescript
2385
+ * const difference = -1000000000000n;
2386
+ * assertI64(difference);
2387
+ * // difference is now typed as I64
2388
+ * ```
2389
+ *
2390
+ * @returns `void` — type narrowing is applied to the argument in-place.
2391
+ * @see {@link I64}
2392
+ * @public
2393
+ */
2394
+ declare function assertI64(value: bigint): asserts value is I64;
2395
+ /**
2396
+ * Asserts that a value is a valid 128-bit signed integer.
2397
+ *
2398
+ * @param value - The bigint to assert (must be in range [-2^127, 2^127 - 1])
2399
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2400
+ *
2401
+ * @example
2402
+ * ```typescript
2403
+ * const value = -170141183460469231731687303715884105728n;
2404
+ * assertI128(value);
2405
+ * // value is now typed as I128
2406
+ * ```
2407
+ *
2408
+ * @returns `void` — type narrowing is applied to the argument in-place.
2409
+ * @see {@link I128}
2410
+ * @public
2411
+ */
2412
+ declare function assertI128(value: bigint): asserts value is I128;
2413
+ /**
2414
+ * Asserts that a value is a valid 256-bit signed integer.
2415
+ *
2416
+ * @param value - The bigint to assert (must be in range [-2^255, 2^255 - 1])
2417
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2418
+ *
2419
+ * @example
2420
+ * ```typescript
2421
+ * const signedScalar = -12345678901234567890n;
2422
+ * assertI256(signedScalar);
2423
+ * // signedScalar is now typed as I256
2424
+ * ```
2425
+ *
2426
+ * @returns `void` — type narrowing is applied to the argument in-place.
2427
+ * @see {@link I256}
2428
+ * @public
2429
+ */
2430
+ declare function assertI256(value: bigint): asserts value is I256;
2431
+ /**
2432
+ * Asserts that a value is a valid 512-bit signed integer.
2433
+ *
2434
+ * @param value - The bigint to assert (must be in range [-2^511, 2^511 - 1])
2435
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2436
+ *
2437
+ * @example
2438
+ * ```typescript
2439
+ * const value = -1n;
2440
+ * assertI512(value);
2441
+ * // value is now typed as I512
2442
+ * ```
2443
+ *
2444
+ * @returns `void` — type narrowing is applied to the argument in-place.
2445
+ * @see {@link I512}
2446
+ * @public
2447
+ */
2448
+ declare function assertI512(value: bigint): asserts value is I512;
2449
+ /**
2450
+ * Asserts that a value is a valid 1024-bit signed integer.
2451
+ *
2452
+ * @param value - The bigint to assert (must be in range [-2^1023, 2^1023 - 1])
2453
+ * @throws {MathematicsAssertionError} If not a bigint or out of range
2454
+ *
2455
+ * @example
2456
+ * ```typescript
2457
+ * const value = 0n;
2458
+ * assertI1024(value);
2459
+ * // value is now typed as I1024
2460
+ * ```
2461
+ *
2462
+ * @returns `void` — type narrowing is applied to the argument in-place.
2463
+ * @see {@link I1024}
2464
+ * @public
2465
+ */
2466
+ declare function assertI1024(value: bigint): asserts value is I1024;
2467
+
2468
+ export { I64_MIN as $, type U8 as A, type Bytes as B, type I128 as C, type I16 as D, type I256 as E, type I32 as F, type I512 as G, type I64 as H, type I1024 as I, type I8 as J, type BeBytes as K, type ExtractBrand as L, I1024_MAX as M, I1024_MIN as N, I128_MAX as O, I128_MIN as P, I16_MAX as Q, I16_MIN as R, type SubSubBrandedType as S, I256_MAX as T, type U128 as U, I256_MIN as V, I32_MAX as W, I32_MIN as X, I512_MAX as Y, I512_MIN as Z, I64_MAX as _, type SubSubSubBrandedType as a, I8_MAX as a0, I8_MIN as a1, type LeBytes as a2, MathematicsAssertionError as a3, type SignedInteger as a4, U1024_BYTE_LENGTH as a5, U1024_MAX as a6, U128_BYTE_LENGTH as a7, U128_MAX as a8, U16_BYTE_LENGTH as a9, assertU1024BeBytes as aA, assertU1024LeBytes as aB, assertU128 as aC, assertU128BeBytes as aD, assertU128LeBytes as aE, assertU16 as aF, assertU16BeBytes as aG, assertU16LeBytes as aH, assertU256 as aI, assertU256BeBytes as aJ, assertU256LeBytes as aK, assertU32 as aL, assertU32BeBytes as aM, assertU32LeBytes as aN, assertU512 as aO, assertU512BeBytes as aP, assertU512LeBytes as aQ, assertU64 as aR, assertU64BeBytes as aS, assertU64LeBytes as aT, assertU8 as aU, assertU8BeBytes as aV, assertU8LeBytes as aW, assertUnsignedInteger as aX, U16_MAX as aa, U256_BYTE_LENGTH as ab, U256_MAX as ac, U32_BYTE_LENGTH as ad, U32_MAX as ae, U512_BYTE_LENGTH as af, U512_MAX as ag, U64_BYTE_LENGTH as ah, U64_MAX as ai, U8_BYTE_LENGTH as aj, U8_MAX as ak, type UnsignedInteger as al, type UnwrapBrand as am, assertBeBytes as an, assertBytes as ao, assertI1024 as ap, assertI128 as aq, assertI16 as ar, assertI256 as as, assertI32 as at, assertI512 as au, assertI64 as av, assertI8 as aw, assertLeBytes as ax, assertSignedInteger as ay, assertU1024 as az, type SubBrandedType as b, type SubSubSubSubBrandedType as c, type U512LeBytes as d, type U256LeBytes as e, type U256 as f, type BrandedType as g, type U512 as h, type U512BeBytes as i, type U32 as j, type U64 as k, type U128LeBytes as l, type U1024BeBytes as m, type U1024LeBytes as n, type U128BeBytes as o, type U16BeBytes as p, type U16LeBytes as q, type U256BeBytes as r, type U32BeBytes as s, type U32LeBytes as t, type U64BeBytes as u, type U64LeBytes as v, type U8BeBytes as w, type U8LeBytes as x, type U1024 as y, type U16 as z };