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