toolbox-x 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/LICENSE +201 -0
  2. package/dist/Color-B3mgF9Dh.d.cts +486 -0
  3. package/dist/Color-D38Xrw65.d.mts +486 -0
  4. package/dist/Stylog-Df7eq3-j.d.cts +519 -0
  5. package/dist/Stylog-jvlLcMQq.d.mts +519 -0
  6. package/dist/array-DvW0zIu6.d.mts +130 -0
  7. package/dist/array-rUnEVisO.d.cts +130 -0
  8. package/dist/basics-D_eSv0cu.cjs +132 -0
  9. package/dist/basics-Dp_aEK81.mjs +115 -0
  10. package/dist/basics-WEYWlnRO.d.cts +95 -0
  11. package/dist/basics-uBSfkBEI.d.mts +95 -0
  12. package/dist/case-BWIt8Ash.mjs +449 -0
  13. package/dist/case-C-S-b5YP.d.cts +327 -0
  14. package/dist/case-CS8Ii3A7.cjs +526 -0
  15. package/dist/case-CybASFPD.d.mts +327 -0
  16. package/dist/change-case.cjs +32 -0
  17. package/dist/change-case.d.cts +18 -0
  18. package/dist/change-case.d.mts +18 -0
  19. package/dist/change-case.mjs +19 -0
  20. package/dist/colors.cjs +574 -0
  21. package/dist/colors.d.cts +355 -0
  22. package/dist/colors.d.mts +355 -0
  23. package/dist/colors.mjs +547 -0
  24. package/dist/constants-2gAw23_7.mjs +144 -0
  25. package/dist/constants-B34K0QPi.d.cts +21 -0
  26. package/dist/constants-BIBDKY1u.cjs +924 -0
  27. package/dist/constants-BWT-810U.cjs +158 -0
  28. package/dist/constants-BwbHnXlM.mjs +662 -0
  29. package/dist/constants-BxN9l5el.cjs +74 -0
  30. package/dist/constants-CLS_bgKD.d.mts +847 -0
  31. package/dist/constants-D73iFu8g.mjs +171 -0
  32. package/dist/constants-DAfRxaa8.mjs +62 -0
  33. package/dist/constants-DQYeCjlx.cjs +207 -0
  34. package/dist/constants-Deeie-iH.d.mts +21 -0
  35. package/dist/constants-DpTG9RP6.d.mts +29 -0
  36. package/dist/constants-DqwnkJ_d.cjs +740 -0
  37. package/dist/constants-DvRUY_FY.cjs +150 -0
  38. package/dist/constants-VcRtQu0K.d.cts +29 -0
  39. package/dist/constants-X5hm1UtB.mjs +912 -0
  40. package/dist/constants-eNd-iYsV.mjs +134 -0
  41. package/dist/constants-qm8FafmD.d.cts +847 -0
  42. package/dist/constants.cjs +415 -0
  43. package/dist/constants.d.cts +184 -0
  44. package/dist/constants.d.mts +184 -0
  45. package/dist/constants.mjs +378 -0
  46. package/dist/convert-BOCgUv2D.cjs +252 -0
  47. package/dist/convert-Bn4jFomQ.mjs +169 -0
  48. package/dist/convert-BrzlG-m_.cjs +475 -0
  49. package/dist/convert-DhaUoPVU.mjs +368 -0
  50. package/dist/converter-1P90_RcP.d.mts +402 -0
  51. package/dist/converter-CmkcAppi.d.cts +402 -0
  52. package/dist/converter.cjs +780 -0
  53. package/dist/converter.d.cts +29 -0
  54. package/dist/converter.d.mts +29 -0
  55. package/dist/converter.mjs +771 -0
  56. package/dist/countries-CIpmtEzV.cjs +1469 -0
  57. package/dist/countries-Cy0xiqS3.mjs +1463 -0
  58. package/dist/css-colors-Bx947Ng3.d.cts +179 -0
  59. package/dist/css-colors-CXCDqQbG.cjs +186 -0
  60. package/dist/css-colors-CXTp1vvy.d.mts +179 -0
  61. package/dist/css-colors-DfUW3nTR.mjs +180 -0
  62. package/dist/date.cjs +332 -0
  63. package/dist/date.d.cts +213 -0
  64. package/dist/date.d.mts +213 -0
  65. package/dist/date.mjs +298 -0
  66. package/dist/dom.cjs +461 -0
  67. package/dist/dom.d.cts +228 -0
  68. package/dist/dom.d.mts +228 -0
  69. package/dist/dom.mjs +429 -0
  70. package/dist/form-BMFVGUrN.d.mts +118 -0
  71. package/dist/form-DRFbryvK.d.cts +118 -0
  72. package/dist/guards-3kaUX66g.mjs +157 -0
  73. package/dist/guards-C8gkvIHb.cjs +240 -0
  74. package/dist/guards-DdyU4h4o.mjs +110 -0
  75. package/dist/guards-Efhp1mNy.cjs +151 -0
  76. package/dist/guards.cjs +172 -0
  77. package/dist/guards.d.cts +399 -0
  78. package/dist/guards.d.mts +399 -0
  79. package/dist/guards.mjs +75 -0
  80. package/dist/hash-B6JPEyAz.d.mts +131 -0
  81. package/dist/hash-NTpeKYB_.d.cts +131 -0
  82. package/dist/hash.cjs +2126 -0
  83. package/dist/hash.d.cts +1239 -0
  84. package/dist/hash.d.mts +1239 -0
  85. package/dist/hash.mjs +2095 -0
  86. package/dist/http-status-BAZdtr7-.d.mts +65 -0
  87. package/dist/http-status-U_3MtoGb.d.cts +65 -0
  88. package/dist/http-status.cjs +173 -0
  89. package/dist/http-status.d.cts +142 -0
  90. package/dist/http-status.d.mts +142 -0
  91. package/dist/http-status.mjs +171 -0
  92. package/dist/index.cjs +2551 -0
  93. package/dist/index.d.cts +1493 -0
  94. package/dist/index.d.mts +1493 -0
  95. package/dist/index.mjs +2357 -0
  96. package/dist/object-B0TV3eHx.d.mts +8052 -0
  97. package/dist/object-Blq0Amdv.d.cts +8052 -0
  98. package/dist/objectify-CDs0Fbr1.mjs +417 -0
  99. package/dist/objectify-DIJ-OBmo.cjs +524 -0
  100. package/dist/paginator.cjs +245 -0
  101. package/dist/paginator.d.cts +144 -0
  102. package/dist/paginator.d.mts +144 -0
  103. package/dist/paginator.mjs +243 -0
  104. package/dist/parse-2ubxXZRp.cjs +211 -0
  105. package/dist/parse-N7g942uy.mjs +164 -0
  106. package/dist/pluralizer-BjMIc6uT.d.mts +42 -0
  107. package/dist/pluralizer-Cb6ZmrDl.d.cts +42 -0
  108. package/dist/pluralizer.cjs +678 -0
  109. package/dist/pluralizer.d.cts +152 -0
  110. package/dist/pluralizer.d.mts +152 -0
  111. package/dist/pluralizer.mjs +676 -0
  112. package/dist/primitives-B26uZolQ.cjs +228 -0
  113. package/dist/primitives-KsFUp3kQ.mjs +144 -0
  114. package/dist/specials-D48_IZbd.d.mts +108 -0
  115. package/dist/specials-DzLr1ZgU.cjs +477 -0
  116. package/dist/specials-LVONlKbQ.d.cts +108 -0
  117. package/dist/specials-uhDuRg8H.mjs +292 -0
  118. package/dist/string-CBAbxaG1.d.mts +258 -0
  119. package/dist/string-CsNsm_65.d.cts +258 -0
  120. package/dist/stylog.cjs +621 -0
  121. package/dist/stylog.d.cts +49 -0
  122. package/dist/stylog.d.mts +49 -0
  123. package/dist/stylog.mjs +614 -0
  124. package/dist/timezone-B2OYK6Fh.mjs +5589 -0
  125. package/dist/timezone-Beh9IGpw.cjs +5625 -0
  126. package/dist/types/array.cjs +16 -0
  127. package/dist/types/array.d.cts +18 -0
  128. package/dist/types/array.d.mts +18 -0
  129. package/dist/types/array.mjs +17 -0
  130. package/dist/types/colors.cjs +16 -0
  131. package/dist/types/colors.d.cts +18 -0
  132. package/dist/types/colors.d.mts +18 -0
  133. package/dist/types/colors.mjs +17 -0
  134. package/dist/types/converter.cjs +16 -0
  135. package/dist/types/converter.d.cts +18 -0
  136. package/dist/types/converter.d.mts +18 -0
  137. package/dist/types/converter.mjs +17 -0
  138. package/dist/types/form.cjs +16 -0
  139. package/dist/types/form.d.cts +18 -0
  140. package/dist/types/form.d.mts +18 -0
  141. package/dist/types/form.mjs +17 -0
  142. package/dist/types/hash.cjs +16 -0
  143. package/dist/types/hash.d.cts +18 -0
  144. package/dist/types/hash.d.mts +18 -0
  145. package/dist/types/hash.mjs +17 -0
  146. package/dist/types/http-status.cjs +16 -0
  147. package/dist/types/http-status.d.cts +18 -0
  148. package/dist/types/http-status.d.mts +18 -0
  149. package/dist/types/http-status.mjs +17 -0
  150. package/dist/types/index.cjs +16 -0
  151. package/dist/types/index.d.cts +18 -0
  152. package/dist/types/index.d.mts +18 -0
  153. package/dist/types/index.mjs +17 -0
  154. package/dist/types/number.cjs +16 -0
  155. package/dist/types/number.d.cts +18 -0
  156. package/dist/types/number.d.mts +18 -0
  157. package/dist/types/number.mjs +17 -0
  158. package/dist/types/object.cjs +16 -0
  159. package/dist/types/object.d.cts +18 -0
  160. package/dist/types/object.d.mts +18 -0
  161. package/dist/types/object.mjs +17 -0
  162. package/dist/types/pluralizer.cjs +16 -0
  163. package/dist/types/pluralizer.d.cts +18 -0
  164. package/dist/types/pluralizer.d.mts +18 -0
  165. package/dist/types/pluralizer.mjs +17 -0
  166. package/dist/types/string.cjs +16 -0
  167. package/dist/types/string.d.cts +18 -0
  168. package/dist/types/string.d.mts +18 -0
  169. package/dist/types/string.mjs +17 -0
  170. package/dist/types/stylog.cjs +16 -0
  171. package/dist/types/stylog.d.cts +18 -0
  172. package/dist/types/stylog.d.mts +18 -0
  173. package/dist/types/stylog.mjs +17 -0
  174. package/dist/types/utils.cjs +16 -0
  175. package/dist/types/utils.d.cts +18 -0
  176. package/dist/types/utils.d.mts +18 -0
  177. package/dist/types/utils.mjs +17 -0
  178. package/dist/types/verbalizer.cjs +16 -0
  179. package/dist/types/verbalizer.d.cts +30 -0
  180. package/dist/types/verbalizer.d.mts +30 -0
  181. package/dist/types/verbalizer.mjs +17 -0
  182. package/dist/utilities-CLUmdQeV.cjs +140 -0
  183. package/dist/utilities-m5yFKqLd.mjs +105 -0
  184. package/dist/utils-ClW9LA6f.mjs +449 -0
  185. package/dist/utils-DLFRgXUC.cjs +568 -0
  186. package/dist/verbalizer.cjs +998 -0
  187. package/dist/verbalizer.d.cts +148 -0
  188. package/dist/verbalizer.d.mts +148 -0
  189. package/dist/verbalizer.mjs +996 -0
  190. package/package.json +249 -0
@@ -0,0 +1,1239 @@
1
+ /**
2
+ * Copyright 2026 - present Nazmul Hassan
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { $ as Maybe, y as GenericObject } from "./object-B0TV3eHx.mjs";
18
+ import { _ as VerifiedToken, c as DecodedUUID, d as SignetPayload, f as SupportedVersion, h as UUIDOptions, l as SignOptions, m as UUID, p as TokenString, s as DecodedToken, v as VerifyOptions } from "./hash-B6JPEyAz.mjs";
19
+ import { m as isUUID } from "./specials-D48_IZbd.mjs";
20
+ import { t as generateRandomID } from "./basics-uBSfkBEI.mjs";
21
+
22
+ //#region src/hash/Cipher.d.ts
23
+ /**
24
+ * @class Lightweight stream-cipher–style encryption utility using `HMAC-SHA256` for keystream generation and authentication.
25
+ * - The class derives separate encryption and MAC keys from the provided secret.
26
+ *
27
+ * @remarks
28
+ * - **The encryption scheme is:**
29
+ * - keystream = `HMAC(encKey, iv || counter)`
30
+ * - ciphertext = `plaintext XOR keystream`
31
+ * - tag = `HMAC(macKey, iv || ciphertext)`
32
+ * - This is a custom construction and should not be used for production-grade cryptographic security.
33
+ * - `Cipher` class is a pure JS implementation. It does not rely on `crypto` or Web APIs.
34
+ */
35
+ declare class Cipher {
36
+ #private;
37
+ /**
38
+ * * Creates a new `Cipher` instance using the provided secret.
39
+ *
40
+ * @param secret - The secret string used to derive encryption and MAC keys.
41
+ * Must be a non-empty string.
42
+ */
43
+ constructor(secret: string);
44
+ /**
45
+ * * Encrypts a UTF-8 string.
46
+ * - The output format is: `base64( iv || ciphertext || tag )`
47
+ *
48
+ * @param text - The plaintext string to encrypt.
49
+ * @returns A base64-encoded encrypted token.
50
+ */
51
+ encrypt(text: string): string;
52
+ /**
53
+ * * Checks if a token is structurally valid and contains a matching MAC using the same secret.
54
+ *
55
+ * @param token - The base64-encoded encrypted blob to validate.
56
+ * @returns `true` if the MAC is valid, `false` otherwise.
57
+ */
58
+ isValid(token: string): boolean;
59
+ /**
60
+ * * Decrypts a previously encrypted token.
61
+ * - Throws an error if the tag does not match or the token is malformed.
62
+ *
63
+ * @param token - The base64-encoded token produced by `encrypt`.
64
+ * @returns The decrypted plaintext string.
65
+ */
66
+ decrypt(token: string): string;
67
+ }
68
+ //#endregion
69
+ //#region src/hash/core.d.ts
70
+ /**
71
+ * * Computes the `MD5` digest of the given string using a pure JavaScript implementation.
72
+ *
73
+ * @remarks
74
+ * - Pure JavaScript implementation — runs on any JS engine. Does not rely on `crypto` or **Web APIs** or other external libraries.
75
+ * - Highly inspired by the algorithm used in {@link https://github.com/eustatos/pure-md5.git pure-md5} package.
76
+ *
77
+ * @param str - Input text to hash.
78
+ *
79
+ * @returns The `MD5` hash as a 32-character hex string.
80
+ *
81
+ * @example
82
+ * const hash = md5("hello");
83
+ * // → "5d41402abc4b2a76b9719d911017c592" *
84
+ *
85
+ * @example
86
+ * // Used inside UUID v3
87
+ * const digest = md5(namespace + name);
88
+ */
89
+ declare function md5(str: string): string;
90
+ /**
91
+ * * Computes the `SHA-1` digest of the given string using a pure JavaScript implementation.
92
+ *
93
+ * @remarks Pure JavaScript implementation — runs on any JS engine. Does not rely on `crypto` or **Web APIs** or other external libraries.
94
+ *
95
+ * @param msg - Input text to hash.
96
+ *
97
+ * @returns The `SHA-1` hash as a 40-character hex string.
98
+ *
99
+ * @example
100
+ * const hash = sha1("hello");
101
+ * // → "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d"
102
+ *
103
+ * @example
104
+ * // Used inside UUID v5
105
+ * const digest = sha1(namespace + name);
106
+ */
107
+ declare function sha1(msg: string): string;
108
+ /**
109
+ * * Computes the `SHA-256` hash of a `UTF-8` string and returns it as a lowercase hexadecimal string.
110
+ *
111
+ * @param msg - The input string to hash. Can contain any `UTF-8` characters.
112
+ * @returns A 64-character lowercase hexadecimal string representing the `SHA-256` hash.
113
+ *
114
+ * @remarks Pure JavaScript implementation — runs on any JS engine. Does not rely on `crypto` or **Web APIs** or other external libraries.
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * // Basic usage
119
+ * const hash = sha256('hello');
120
+ * // Returns: '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
121
+ *
122
+ * // Empty string
123
+ * const emptyHash = sha256('');
124
+ * // Returns: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
125
+ *
126
+ * // Unicode string
127
+ * const unicodeHash = sha256('Hello পৃথিবী!');
128
+ * // Returns: '7037e204b825b83553ba336a6ec35b796d505599286ae864729ed6cb33ae9fe1'
129
+ * ```
130
+ *
131
+ * @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/encoding#sha256bytes sha256Bytes} for hashing raw bytes
132
+ * @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/encoding#utf8tobytes utf8ToBytes} for converting string to bytes
133
+ * @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/encoding#bytestohex bytesToHex} for converting bytes to a hexadecimal string
134
+ */
135
+ declare function sha256(msg: string): string;
136
+ //#endregion
137
+ //#region src/hash/Signet.d.ts
138
+ /**
139
+ * @class A lightweight, secure implementation of JWT-like tokens using `HMAC-SHA256` signatures.
140
+ * - This class provides methods to create, verify, and decode tokens with a simple API similar to JSON Web Tokens (`JWT`)
141
+ * but with a smaller footprint and zero dependencies.
142
+ *
143
+ * @remarks
144
+ * - **Features:**
145
+ * - `HMAC-SHA256` signatures for security
146
+ * - Time-based claims (expiration, not-before)
147
+ * - Standard claims (audience, issuer, subject)
148
+ * - Constant-time signature comparison to prevent timing attacks
149
+ * - Automatic date conversion for timestamp claims
150
+ * - `Base64` URL-safe encoding (standard `Base64` in this implementation)
151
+ *
152
+ * - **Security considerations:**
153
+ * - Keep the secret key secure and rotate periodically
154
+ * - Use appropriate token expiration times
155
+ * - Validate all claims relevant to your application
156
+ * - Store tokens securely (HTTP-only cookies recommended for web)
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * // Create a token signer
161
+ * const signet = new Signet('my-secret-key');
162
+ *
163
+ * // Sign a token with custom payload and options
164
+ * const token = signet.sign(
165
+ * { userId: 123, role: 'admin' },
166
+ * {
167
+ * expiresIn: '1h',
168
+ * audience: 'my-app',
169
+ * issuer: 'auth-service'
170
+ * }
171
+ * );
172
+ *
173
+ * // Verify a token
174
+ * const result = signet.verify(token, {
175
+ * audience: 'my-app',
176
+ * issuer: 'auth-service'
177
+ * });
178
+ *
179
+ * if (result.isValid) {
180
+ * console.log('Valid token for user:', result.payload.userId);
181
+ * } else {
182
+ * console.log('Invalid token:', result.error);
183
+ * }
184
+ *
185
+ * // Decode without verification
186
+ * const decoded = signet.decode(token);
187
+ * console.log('Token payload:', decoded.payload);
188
+ * ```
189
+ */
190
+ declare class Signet {
191
+ #private;
192
+ /**
193
+ * * Creates a new `Signet` instance with the specified secret key.
194
+ *
195
+ * @param secret - The secret key used for signing and verifying tokens.
196
+ * Must be a non-empty string.
197
+ *
198
+ * @throws If the secret is not a non-empty string.
199
+ *
200
+ * @remarks
201
+ * - The secret is converted to `UTF-8` bytes and stored internally.
202
+ * - Choose a strong secret (at least 32 characters) and store it securely.
203
+ * - For production, consider using key rotation strategies.
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * // Initialize with a secret key
208
+ * const signet = new Signet('super-secret-key-123');
209
+ *
210
+ * // Use environment variable for the secret
211
+ * const signet = new Signet(process.env.JWT_SECRET!);
212
+ * ```
213
+ */
214
+ constructor(secret: string);
215
+ /**
216
+ * * Creates and signs a new token with the given payload and options.
217
+ *
218
+ * @param payload - Custom data to include in the token payload.
219
+ * Must be a `non-empty object`.
220
+ * @param options - Optional configuration for token claims and expiration.
221
+ *
222
+ * @returns A signed token string in the format `header.payload.signature`.
223
+ *
224
+ * @throws If payload is not a valid object.
225
+ *
226
+ * @remarks
227
+ * - **The token structure follows JWT format:**
228
+ * - Header: Contains algorithm (`HS256`) and token type (`SIGNET+JWT`)
229
+ * - Payload: Includes standard claims (`iat`, `exp`, `nbf`, `aud`, `sub`, `iss`) plus custom data
230
+ * - Signature: `HMAC-SHA256(signingInput, secret)` (the result of the hash)
231
+ * - Signing Inputs: `base64(header) + "." + base64(payload)` (the string that gets hashed)
232
+ *
233
+ * - **Automatic claims added:**
234
+ * - `iat` (issued at): Current time in seconds
235
+ * - `iatDate`: Current time as Date object
236
+ * - If `expiresIn` is provided: `exp` and `expDate`
237
+ * - If `notBefore` is provided: `nbf` and `nbfDate`
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * // Basic token with custom data
242
+ * const token = signet.sign({ userId: 123, name: 'John' });
243
+ *
244
+ * // Token with expiration and claims
245
+ * const token = signet.sign(
246
+ * { userId: 123 },
247
+ * {
248
+ * expiresIn: '2h',
249
+ * audience: 'api.example.com',
250
+ * issuer: 'auth-service',
251
+ * subject: 'user-123'
252
+ * }
253
+ * );
254
+ *
255
+ * // Token valid after 5 minutes
256
+ * const token = signet.sign(
257
+ * { action: 'reset-password' },
258
+ * { notBefore: '5m' }
259
+ * );
260
+ * ```
261
+ */
262
+ sign(payload: GenericObject, options?: SignOptions): TokenString;
263
+ /**
264
+ * * Decodes a token without verifying its signature.
265
+ *
266
+ * @typeParam T - Type of custom data in the token payload.
267
+ * @param token - The token string to decode.
268
+ *
269
+ * @returns The decoded token parts including header, payload, and signatures.
270
+ *
271
+ * @throws If the token is malformed, empty, or cannot be parsed.
272
+ *
273
+ * @remarks
274
+ * - Use this method when you need to inspect token contents without verification.
275
+ * - **Warning:** This does not validate the signature, so the data may have been tampered with.
276
+ * - Always use {@link verify} method for security-critical operations.
277
+ * - The payload includes both timestamp values (numbers) and {@link Date} objects for convenience.
278
+ *
279
+ * @example
280
+ * ```typescript
281
+ * // Decode token to inspect contents
282
+ * const decoded = signet.decode(token);
283
+ * console.log('Header:', decoded.header);
284
+ * console.log('Payload:', decoded.payload);
285
+ * console.log('Signature:', decoded.signature);
286
+ *
287
+ * // Access custom payload data with type safety
288
+ * const decoded = signet.decode<{ userId: number }>(token);
289
+ * const userId = decoded.payload.userId; // Type: number
290
+ * ```
291
+ */
292
+ decode<T extends GenericObject = GenericObject>(token: string): DecodedToken<T>;
293
+ /**
294
+ * * Checks if a token has expired based on its `exp` claim.
295
+ *
296
+ * @param token - The token to check.
297
+ *
298
+ * @returns `true` if the token has an `exp` claim and current time is past it,
299
+ * `false` if token has no expiration or is still valid.
300
+ *
301
+ * @throws If the token is malformed or cannot be decoded.
302
+ *
303
+ * @remarks
304
+ * - Tokens without `exp` claim are considered non-expiring (returns `false`)
305
+ * - Uses current system time for comparison ({@link Date.now()})
306
+ * - Does not verify the signature (use only with trusted tokens or after verification)
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * // Check expiration
311
+ * if (signet.hasExpired(token)) {
312
+ * console.log('Token has expired');
313
+ * // Prompt user to re-authenticate
314
+ * }
315
+ *
316
+ * // Use with other validation
317
+ * const isValid = !signet.hasExpired(token) && !signet.isTooEarly(token);
318
+ * ```
319
+ */
320
+ hasExpired(token: string): boolean;
321
+ /**
322
+ * * Checks if a token's `nbf` (not-before) claim indicates it's too early to use.
323
+ *
324
+ * @param token - The token to check.
325
+ *
326
+ * @returns `true` if the token has an `nbf` claim and current time is before it,
327
+ * `false` if token has no `nbf` claim or is already valid.
328
+ *
329
+ * @throws If the token is malformed or cannot be decoded.
330
+ *
331
+ * @remarks
332
+ * - Useful for implementing time-based access control, like activation links that shouldn't be used until a certain time.
333
+ * - Uses current system time for comparison ({@link Date.now()})
334
+ * - Does not verify the signature (use only with trusted tokens or after verification)
335
+ *
336
+ * @example
337
+ * ```typescript
338
+ * // Check if token is active yet
339
+ * if (signet.isTooEarly(token)) {
340
+ * console.log('Token not valid yet');
341
+ * // Wait before using
342
+ * }
343
+ * ```
344
+ */
345
+ isTooEarly(token: string): boolean;
346
+ /**
347
+ * * Validates a token's `iss` (issuer) claim against an expected value.
348
+ *
349
+ * @param token - The token to check.
350
+ * @param expected - The expected issuer value. If `undefined`, always returns `false`.
351
+ *
352
+ * @returns `true` if the token has an `iss` claim that doesn't match the expected value,
353
+ * `false` if issuer matches, token has no issuer claim, or expected issuer is undefined.
354
+ *
355
+ * @throws If the token is malformed or cannot be decoded.
356
+ *
357
+ * @remarks Use this to ensure tokens come from trusted sources in multi-issuer scenarios.
358
+ *
359
+ * @example
360
+ * ```typescript
361
+ * // Validate issuer
362
+ * if (signet.isInvalidIssuer(token, 'auth-service')) {
363
+ * console.log('Token from unexpected issuer');
364
+ * // Reject token
365
+ * }
366
+ *
367
+ * // With optional issuer check
368
+ * const issuer = process.env.EXPECTED_ISSUER;
369
+ * if (issuer && signet.isInvalidIssuer(token, issuer)) {
370
+ * throw new Error('Invalid issuer');
371
+ * }
372
+ * ```
373
+ */
374
+ isInvalidIssuer(token: string, expected: Maybe<string>): boolean;
375
+ /**
376
+ * * Validates a token's `aud` (audience) claim against expected values.
377
+ *
378
+ * @param token - The token to check.
379
+ * @param expected - The expected audience(s). Can be a string or array of strings.
380
+ * If `undefined`, always returns `false`.
381
+ *
382
+ * @returns `true` if the token has an `aud` claim and none of its values match any of the expected audiences, `false` otherwise.
383
+ *
384
+ * @throws If the token is malformed or cannot be decoded.
385
+ *
386
+ * @remarks
387
+ * - Tokens can have single audience (string) or multiple audiences (string[])
388
+ * - Returns `false` (valid) if at least one audience matches
389
+ * - Useful for multi-tenant or multi-service architectures
390
+ *
391
+ * @example
392
+ * ```typescript
393
+ * // Single audience check
394
+ * if (signet.isInvalidAudience(token, 'api.example.com')) {
395
+ * console.log('Token not intended for this audience');
396
+ * }
397
+ *
398
+ * // Multiple allowed audiences
399
+ * const validAudiences = ['web-app', 'mobile-app', 'admin-panel'];
400
+ * if (signet.isInvalidAudience(token, validAudiences)) {
401
+ * throw new Error('Invalid audience');
402
+ * }
403
+ *
404
+ * // Token with multiple audiences
405
+ * // Token payload: { aud: ['web-app', 'mobile-app'] }
406
+ * // Check if at least one matches
407
+ * const isValid = !signet.isInvalidAudience(token, ['web-app', 'admin-panel']);
408
+ * // Returns false (valid) because 'web-app' matches
409
+ * ```
410
+ */
411
+ isInvalidAudience(token: string, expected: Maybe<string | string[]>): boolean;
412
+ /**
413
+ * * Validates a token's `sub` (subject) claim against an expected value.
414
+ *
415
+ * @param token - The token to check.
416
+ * @param expected - The expected subject value. If `undefined`, always returns `false`.
417
+ *
418
+ * @returns `true` if the token has a `sub` claim that doesn't match the expected value,
419
+ * `false` if subject matches, token has no subject claim, or expected subject is undefined.
420
+ *
421
+ * @throws If the token is malformed or cannot be decoded.
422
+ *
423
+ * @remarks
424
+ * - Use this to ensure tokens are being used by the intended user/entity.
425
+ * - Common for authorization checks where tokens should be user-specific.
426
+ *
427
+ * @example
428
+ * ```typescript
429
+ * // Validate subject
430
+ * const userId = 'user-123';
431
+ * if (signet.isInvalidSubject(token, userId)) {
432
+ * console.log('Token not for this user');
433
+ * // Reject request
434
+ * }
435
+ *
436
+ * // Optional subject validation
437
+ * const expectedSubject = getExpectedSubjectFromRequest();
438
+ * if (expectedSubject && signet.isInvalidSubject(token, expectedSubject)) {
439
+ * return response.status(403).send('Invalid subject');
440
+ * }
441
+ * ```
442
+ */
443
+ isInvalidSubject(token: string, expected: Maybe<string>): boolean;
444
+ /**
445
+ * * Verifies a token's signature and validates all claims.
446
+ *
447
+ * @typeParam T - Type of custom data in the token payload.
448
+ * @param token - The token string to verify.
449
+ * @param options - Optional validation criteria for token claims.
450
+ *
451
+ * @returns A {@link VerifiedToken} object indicating success or failure.
452
+ * - If valid: `{ isValid: true, payload: SignetPayload<T> }`
453
+ * - If invalid: `{ isValid: false, error: string }`
454
+ *
455
+ * @remarks
456
+ * - **Performs the following checks in order:**
457
+ * - Token structure (3 parts separated by dots)
458
+ * - Base64 decoding of header and payload
459
+ * - JSON parsing of header and payload
460
+ * - Signature verification (constant-time comparison)
461
+ * - Expiration check (if `exp` claim exists)
462
+ * - Not-before check (if `nbf` claim exists)
463
+ * - Issuer validation (if provided in options)
464
+ * - Audience validation (if provided in options)
465
+ * - Subject validation (if provided in options)
466
+ *
467
+ * - **This is the recommended method for most token validation scenarios.**
468
+ *
469
+ * @example
470
+ * ```typescript
471
+ * // Basic verification
472
+ * const result = signet.verify(token);
473
+ * if (result.isValid) {
474
+ * console.log('Valid token:', result.payload);
475
+ * } else {
476
+ * console.log('Invalid token:', result.error);
477
+ * }
478
+ *
479
+ * // With claim validation
480
+ * const result = signet.verify(token, {
481
+ * audience: 'api.example.com',
482
+ * issuer: 'auth-service',
483
+ * subject: 'user-123'
484
+ * });
485
+ *
486
+ * // Type-safe custom payload
487
+ * interface UserToken {
488
+ * userId: number;
489
+ * role: string;
490
+ * }
491
+ * const result = signet.verify<UserToken>(token);
492
+ * if (result.isValid) {
493
+ * const { userId, role } = result.payload;
494
+ * // userId and role are typed
495
+ * }
496
+ * ```
497
+ */
498
+ verify<T extends GenericObject = GenericObject>(token: string, options?: VerifyOptions): VerifiedToken<T>;
499
+ /**
500
+ * * Verifies a token and throws an error if invalid.
501
+ *
502
+ * @typeParam T - Type of custom data in the token payload.
503
+ * @param token - The token string to verify.
504
+ * @param options - Optional validation criteria for token claims.
505
+ *
506
+ * @returns A valid {@link VerifiedToken} with `isValid: true`.
507
+ *
508
+ * @throws If the token is invalid, with a message describing the failure.
509
+ *
510
+ * @remarks
511
+ * - This method is a convenience wrapper around {@link verify} that throws instead of returning an error object.
512
+ * - Useful for `express`-style middleware or when you want to handle authentication failures with exceptions.
513
+ * - The thrown error message is the same as the `error` property in the invalid result from {@link verify}.
514
+ *
515
+ * @example
516
+ * ```typescript
517
+ * // Use in middleware/guard
518
+ * function authMiddleware(req, res, next) {
519
+ * const token = req.headers.authorization?.replace('Bearer ', '');
520
+ *
521
+ * try {
522
+ * const result = signet.verifyOrThrow(token, {
523
+ * audience: 'api.example.com'
524
+ * });
525
+ * req.user = result.payload;
526
+ * next();
527
+ * } catch (error) {
528
+ * res.status(401).json({ error: error.message });
529
+ * }
530
+ * }
531
+ *
532
+ * // In application code
533
+ * try {
534
+ * const result = signet.verifyOrThrow(token);
535
+ * // Token is guaranteed valid here
536
+ * processUserRequest(result.payload);
537
+ * } catch (error) {
538
+ * handleAuthError(error);
539
+ * }
540
+ * ```
541
+ */
542
+ verifyOrThrow<T extends GenericObject = GenericObject>(token: string, options?: VerifyOptions): VerifiedToken<T>;
543
+ /**
544
+ * * Extracts only the payload from a token without full verification.
545
+ *
546
+ * @typeParam T - Type of custom data in the token payload.
547
+ * @param token - The token string to decode.
548
+ *
549
+ * @returns The token payload including standard claims and custom data.
550
+ *
551
+ * @throws If the token is malformed, empty, or cannot be parsed.
552
+ *
553
+ * @remarks
554
+ * - This is a convenience method equivalent to `decode(token).payload`.
555
+ *
556
+ * - **Security Note:** This method does NOT verify the token signature.
557
+ *
558
+ * - **Only use it when:**
559
+ * - You've already verified the token elsewhere
560
+ * - The token comes from a trusted source
561
+ * - You're debugging or logging
562
+ * - The operation is not security-critical
563
+ *
564
+ * - For security-sensitive operations, always use {@link verify} or {@link verifyOrThrow} method.
565
+ *
566
+ * @example
567
+ * ```typescript
568
+ * // Quick payload extraction for non-critical operations
569
+ * const payload = signet.decodePayload(token);
570
+ * console.log('User ID:', payload.userId);
571
+ * console.log('Issued at:', payload.iatDate);
572
+ *
573
+ * // Type-safe with custom interface
574
+ * interface AppToken {
575
+ * userId: number;
576
+ * permissions: string[];
577
+ * }
578
+ * const payload = signet.decodePayload<AppToken>(token);
579
+ * const canDelete = payload.permissions.includes('delete');
580
+ * ```
581
+ */
582
+ decodePayload<T extends GenericObject = GenericObject>(token: string): SignetPayload<T>;
583
+ }
584
+ //#endregion
585
+ //#region src/hash/TextCodec.d.ts
586
+ /**
587
+ * @class `TextCodec` provides **UTF-8–safe** conversions between `text`, `hex`, `binary`, and `Base64` representations using byte-level transformations.
588
+ *
589
+ * @example
590
+ * TextCodec.utf8ToHex('ভাষা'); // 'e0 a6 ad e0 a6 be e0 a6 b7 e0 a6 be'
591
+ * TextCodec.hexToUtf8('e0 a6 ad e0 a6 be'); // 'ভা'
592
+ */
593
+ declare class TextCodec {
594
+ private constructor();
595
+ /**
596
+ * @static Validates whether a string represents a valid hexadecimal byte sequence.
597
+ *
598
+ * @param hex - Hex string, spaced or un-spaced (e.g. "ff 0a" or "ff0a")
599
+ * @returns `true` if the input is valid hex byte string
600
+ *
601
+ * @example
602
+ * TextCodec.isValidHex('ff 0a');
603
+ */
604
+ static isValidHex(hex: string): boolean;
605
+ /**
606
+ * @static Validates whether a string represents a valid binary byte sequence.
607
+ *
608
+ * @param binary - Binary string, spaced or un-spaced
609
+ * @returns `true` if the input is valid binary byte string
610
+ *
611
+ * @example
612
+ * TextCodec.isValidBinary('01000001');
613
+ */
614
+ static isValidBinary(binary: string): boolean;
615
+ /**
616
+ * @static Validates whether a string represents a valid Base64-encoded string.
617
+ *
618
+ * @param b64 - Base64 string to check
619
+ * @returns `true` if the input is valid Base64-encoded string
620
+ *
621
+ * @example
622
+ * TextCodec.isValidBase64('SGVsbG8=');
623
+ */
624
+ static isValidBase64(b64: string): boolean;
625
+ /**
626
+ * @static Converts UTF-8 text into hexadecimal byte representation.
627
+ *
628
+ * @param text - UTF-8 text to convert
629
+ * @param spaced - Whether to separate bytes with spaces, defaults to `true`
630
+ * @returns Hexadecimal byte string
631
+ *
632
+ * @example
633
+ * TextCodec.utf8ToHex('Hi');
634
+ */
635
+ static utf8ToHex(text: string, spaced?: boolean): string;
636
+ /**
637
+ * @static Converts UTF-8 text into binary byte representation.
638
+ *
639
+ * @param text - UTF-8 text to convert
640
+ * @param spaced - Whether to separate bytes with spaces, defaults to `true`
641
+ * @returns Binary byte string
642
+ *
643
+ * @example
644
+ * TextCodec.utf8ToBinary('A');
645
+ */
646
+ static utf8ToBinary(text: string, spaced?: boolean): string;
647
+ /**
648
+ * @static Converts hexadecimal byte string into UTF-8 text.
649
+ *
650
+ * @param hex - Hexadecimal byte string
651
+ * @returns Decoded UTF-8 text
652
+ *
653
+ * @example
654
+ * TextCodec.hexToUtf8('48 69');
655
+ */
656
+ static hexToUtf8(hex: string): string;
657
+ /**
658
+ * @static Converts binary byte string into UTF-8 text.
659
+ *
660
+ * @param binary - Binary byte string
661
+ * @returns Decoded UTF-8 text
662
+ *
663
+ * @example
664
+ * TextCodec.binaryToUtf8('01001000 01101001');
665
+ */
666
+ static binaryToUtf8(binary: string): string;
667
+ /**
668
+ * @static Converts hexadecimal byte string into binary byte string.
669
+ *
670
+ * @param hex - Hexadecimal byte string
671
+ * @param spaced - Whether to separate bytes with spaces, defaults to `true`
672
+ * @returns Binary byte string
673
+ *
674
+ * @example
675
+ * TextCodec.hexToBinary('ff');
676
+ */
677
+ static hexToBinary(hex: string, spaced?: boolean): string;
678
+ /**
679
+ * @static Converts binary byte string into hexadecimal byte string.
680
+ *
681
+ * @param binary - Binary byte string
682
+ * @param spaced - Whether to separate bytes with spaces, defaults to `true`
683
+ * @returns Hexadecimal byte string
684
+ *
685
+ * @example
686
+ * TextCodec.binaryToHex('00000001');
687
+ */
688
+ static binaryToHex(binary: string, spaced?: boolean): string;
689
+ /**
690
+ * @static Converts a Base64-encoded string into UTF-8 text.
691
+ *
692
+ * @param b64 - Base64 encoded string
693
+ * @returns Decoded UTF-8 text
694
+ *
695
+ * @example
696
+ * TextCodec.base64ToUtf8('SGVsbG8=');
697
+ */
698
+ static base64ToUtf8(b64: string): string;
699
+ /**
700
+ * @static Converts UTF-8 text into a Base64-encoded string.
701
+ *
702
+ * @param text - UTF-8 text to encode
703
+ * @returns Base64 encoded string
704
+ *
705
+ * @example
706
+ * TextCodec.utf8ToBase64('Hello');
707
+ */
708
+ static utf8ToBase64(text: string): string;
709
+ /**
710
+ * @static Converts Base64 directly into hexadecimal byte string.
711
+ *
712
+ * @param b64 - Base64 encoded string
713
+ * @param spaced - Whether to separate bytes with spaces, defaults to `true`
714
+ * @returns Hexadecimal byte string
715
+ *
716
+ * @example
717
+ * TextCodec.base64ToHex('SGVsbG8=');
718
+ */
719
+ static base64ToHex(b64: string, spaced?: boolean): string;
720
+ /**
721
+ * @static Converts Base64 directly into binary byte string.
722
+ *
723
+ * @param b64 - Base64 encoded string
724
+ * @param spaced - Whether to separate bytes with spaces, defaults to `true`
725
+ * @returns Binary byte string
726
+ *
727
+ * @example
728
+ * TextCodec.base64ToBinary('SGVsbG8=');
729
+ */
730
+ static base64ToBinary(b64: string, spaced?: boolean): string;
731
+ /**
732
+ * @static Converts hexadecimal byte string into a Base64 string.
733
+ *
734
+ * @param hex - Hexadecimal byte string
735
+ * @returns Base64 encoded string
736
+ *
737
+ * @example
738
+ * TextCodec.hexToBase64('48 69');
739
+ */
740
+ static hexToBase64(hex: string): string;
741
+ /**
742
+ * @static Converts binary byte string into a Base64 string.
743
+ *
744
+ * @param binary - Binary byte string
745
+ * @returns Base64 encoded string
746
+ *
747
+ * @example
748
+ * TextCodec.binaryToBase64('01001000 01101001');
749
+ */
750
+ static binaryToBase64(binary: string): string;
751
+ }
752
+ //#endregion
753
+ //#region src/hash/utils.d.ts
754
+ /**
755
+ * * Generates a random hexadecimal string of the specified length.
756
+ *
757
+ * @param length - Number of hex characters to generate.
758
+ * @param uppercase - Whether to return uppercase `A–F` characters. Defaults to `false` (lowercase).
759
+ *
760
+ * @returns A randomly generated hexadecimal string.
761
+ *
762
+ * @remarks
763
+ * - This function generates a random hexadecimal string of the specified length.
764
+ * - It uses {@link crypto.getRandomValues} when available for secure randomness, and falls back to {@link Math.random} if not.
765
+ * - The output is a string of hex characters (`0–9`, `a–f` or `A–F`) with no prefixes or separators.
766
+ * - If `length` is `0` or negative, an empty string is returned.
767
+ *
768
+ * @example
769
+ * // 16-character lowercase hex
770
+ * const id = randomHex(16);
771
+ *
772
+ * @example
773
+ * // 8-character uppercase hex
774
+ * const token = randomHex(8, true);
775
+ */
776
+ declare function randomHex(length: number, uppercase?: boolean): string;
777
+ /**
778
+ * * Converts a UTF-8 string to a byte array (`Uint8Array`).
779
+ *
780
+ * This function encodes a JavaScript string into UTF-8 bytes, handling all Unicode code points including supplementary characters (surrogate pairs).
781
+ *
782
+ * @example
783
+ * ```typescript
784
+ * // Basic ASCII
785
+ * const asciiBytes = utf8ToBytes('hello');
786
+ * // Returns:
787
+ * Uint8Array(5) [104, 101, 108, 108, 111]
788
+ *
789
+ * // Unicode characters
790
+ * const unicodeBytes = utf8ToBytes('Hello পৃথিবী!');
791
+ * // Returns:
792
+ * Uint8Array(25) [
793
+ * 72, 101, 108, 108, 111, 32,
794
+ * 224, 166, 170, 224, 167, 131,
795
+ * 224, 166, 165, 224, 166, 191,
796
+ * 224, 166, 172, 224, 167, 128,
797
+ * 33
798
+ * ]
799
+ * ```
800
+ *
801
+ * @param str - The input string to encode as UTF-8 bytes.
802
+ * @returns A `Uint8Array` containing the UTF-8 encoded bytes.
803
+ *
804
+ * @remarks
805
+ * - The encoding follows the UTF-8 specification:
806
+ * - 1-byte sequence for code points U+0000 to U+007F (ASCII)
807
+ * - 2-byte sequence for code points U+0080 to U+07FF
808
+ * - 3-byte sequence for code points U+0800 to U+FFFF
809
+ * - 4-byte sequence for code points U+10000 to U+10FFFF (surrogate pairs)
810
+ *
811
+ * **Note:** Invalid surrogate pairs in the input string are silently ignored.
812
+ *
813
+ * @see {@link bytesToUtf8} for the inverse operation
814
+ */
815
+ declare function utf8ToBytes(str: string): Uint8Array;
816
+ /**
817
+ * * Converts `UTF-8` encoded bytes back to a string.
818
+ *
819
+ * This function decodes a `Uint8Array` containing `UTF-8` bytes into a JavaScript string.
820
+ *
821
+ * @example
822
+ * ```typescript
823
+ * // Decode UTF-8 bytes
824
+ * const bytes = new Uint8Array([104, 101, 108, 108, 111]);
825
+ * const str = bytesToUtf8(bytes);
826
+ * // Returns: 'hello'
827
+ *
828
+ * // Round-trip conversion
829
+ * const original = 'Hello 🌍';
830
+ * const bytes = utf8ToBytes(original);
831
+ * const decoded = bytesToUtf8(bytes);
832
+ * console.log(original === decoded); // true
833
+ * ```
834
+ *
835
+ * @param bytes - A `Uint8Array` containing `UTF-8` encoded bytes.
836
+ * @returns The decoded string.
837
+ *
838
+ * @remarks
839
+ * - The function handles all valid `UTF-8` sequences:
840
+ * - 1-byte sequences (0xxxxxxx) → ASCII characters
841
+ * - 2-byte sequences (110xxxxx 10xxxxxx)
842
+ * - 3-byte sequences (1110xxxx 10xxxxxx 10xxxxxx)
843
+ * - 4-byte sequences (11110xxx 10xxxxxx 10xxxxxx 10xxxxxx) → surrogate pairs
844
+ *
845
+ * @see {@link utf8ToBytes} for the inverse operation
846
+ */
847
+ declare function bytesToUtf8(bytes: Uint8Array): string;
848
+ /**
849
+ * * Decodes a `Base64` string to bytes.
850
+ * - This function converts a `Base64`-encoded string back to its original byte representation.
851
+ * - It handles standard `Base64` encoding with '=', '+', '/' characters.
852
+ *
853
+ * @example
854
+ * ```typescript
855
+ * // Decode Base64 string
856
+ * const bytes = base64ToBytes('aGVsbG8gd29ybGQ=');
857
+ * // Returns: Uint8Array(11) [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]
858
+ *
859
+ * // Empty string
860
+ * const empty = base64ToBytes('');
861
+ * // Returns: Uint8Array(0) []
862
+ * ```
863
+ *
864
+ * @param str - The `Base64`-encoded string to decode.
865
+ * @returns A `Uint8Array` containing the decoded bytes.
866
+ *
867
+ * @remarks
868
+ * - The function supports:
869
+ * - Standard `Base64` alphabet (A-Z, a-z, 0-9, +, /)
870
+ * - Padding with '=' characters
871
+ * - Ignores whitespace (though not explicitly trimmed in this implementation)
872
+ *
873
+ * @see {@link bytesToBase64} for the inverse operation
874
+ */
875
+ declare function base64ToBytes(str: string): Uint8Array;
876
+ /**
877
+ * * Encodes bytes to a `Base64` string.
878
+ * - This function converts a `Uint8Array` to a `Base64`-encoded string using the standard `Base64` alphabet with padding.
879
+ *
880
+ * @example
881
+ * ```typescript
882
+ * // Encode bytes to Base64
883
+ * const bytes = new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]);
884
+ * const b64 = bytesToBase64(bytes);
885
+ * // Returns: 'aGVsbG8gd29ybGQ='
886
+ *
887
+ * // Empty array
888
+ * const empty = bytesToBase64(new Uint8Array(0));
889
+ * // Returns: ''
890
+ * ```
891
+ *
892
+ * @param bytes - The bytes to encode as `Base64`.
893
+ * @returns The `Base64`-encoded string.
894
+ *
895
+ * @remarks
896
+ * The encoding uses:
897
+ * - Standard `Base64` alphabet (A-Z, a-z, 0-9, +, /)
898
+ * - '=' padding for incomplete groups
899
+ * - No line breaks or whitespace
900
+ *
901
+ * This is a pure JavaScript implementation that doesn't rely on `btoa()`.
902
+ *
903
+ * @see {@link base64ToBytes} for the inverse operation
904
+ */
905
+ declare function bytesToBase64(bytes: Uint8Array): string;
906
+ /**
907
+ * * Concatenates multiple `Uint8Array`s into a single `Uint8Array`.
908
+ * - This function efficiently combines multiple byte arrays without creating intermediate strings or arrays.
909
+ *
910
+ * @example
911
+ * ```typescript
912
+ * // Concatenate multiple arrays
913
+ * const a = new Uint8Array([1, 2, 3]);
914
+ * const b = new Uint8Array([4, 5]);
915
+ * const c = new Uint8Array([6, 7, 8, 9]);
916
+ * const result = concatBytes(a, b, c);
917
+ * // Returns: Uint8Array(9) [1, 2, 3, 4, 5, 6, 7, 8, 9]
918
+ *
919
+ * // Single array
920
+ * const single = concatBytes(new Uint8Array([1, 2, 3]));
921
+ * // Returns: Uint8Array(3) [1, 2, 3]
922
+ *
923
+ * // No arrays
924
+ * const empty = concatBytes();
925
+ * // Returns: Uint8Array(0) []
926
+ * ```
927
+ *
928
+ * @param parts - One or more `Uint8Array`s to concatenate.
929
+ * @returns A new `Uint8Array` containing all the bytes from the input arrays in the order they were provided.
930
+ *
931
+ * @remarks The function allocates a single `Uint8Array` of the total combined length and copies all bytes into it using `set()` for optimal performance.
932
+ */
933
+ declare function concatBytes(...parts: Uint8Array[]): Uint8Array;
934
+ /**
935
+ * * Computes the `SHA-256` hash of raw bytes.
936
+ * - This is a pure JavaScript implementation of the `SHA-256` cryptographic hash function that operates directly on byte arrays (`Uint8Array`).
937
+ *
938
+ * @example
939
+ * ```typescript
940
+ * // Hash raw bytes
941
+ * const bytes = new Uint8Array([104, 101, 108, 108, 111]); // "hello"
942
+ * const hash = sha256Bytes(bytes);
943
+ * // Returns: Uint8Array(32) with SHA-256 hash
944
+ *
945
+ * // Verify with string hash
946
+ * const strHash = sha256('hello');
947
+ * const bytesHash = bytesToHex(sha256Bytes(utf8ToBytes('hello')));
948
+ * console.log(strHash === bytesHash); // true
949
+ * ```
950
+ *
951
+ * @param message - The bytes to hash as a `Uint8Array`.
952
+ * @returns A `Uint8Array` of 32 bytes (256 bits) containing the `SHA-256` hash.
953
+ *
954
+ * @remarks
955
+ * - Implementation details:
956
+ * - Follows the `SHA-256` specification (FIPS 180-4)
957
+ * - Uses big-endian byte order throughout
958
+ * - Processes messages in 512-bit (64-byte) blocks
959
+ * - Applies proper padding with message length
960
+ * - Uses all required `SHA-256` round constants
961
+ * - Returns hash as 32-byte array
962
+ *
963
+ * @see {@link hmacSha256} for `HMAC-SHA256` computation
964
+ */
965
+ declare function sha256Bytes(message: Uint8Array): Uint8Array;
966
+ /**
967
+ * * Computes `HMAC-SHA256` (Hash-based Message Authentication Code using `SHA-256`).
968
+ * - This function implements the `HMAC` algorithm with `SHA-256` as the underlying hash function, providing message authentication and integrity verification.
969
+ *
970
+ * @example
971
+ * ```typescript
972
+ * // Basic HMAC calculation
973
+ * const key = new TextEncoder().encode('secret-key');
974
+ * const message = new TextEncoder().encode('Hello, world!');
975
+ * const hmac = hmacSha256(key, message);
976
+ *
977
+ * // Using with string inputs
978
+ * const keyBytes = new TextEncoder().encode('my-key');
979
+ * const msgBytes = new TextEncoder().encode('data to authenticate');
980
+ * const hmacResult = hmacSha256(keyBytes, msgBytes);
981
+ * const hexResult = bytesToHex(hmacResult);
982
+ * ```
983
+ *
984
+ * @param key - The secret key as a `Uint8Array`.
985
+ * @param message - The message to authenticate as a `Uint8Array`.
986
+ * @returns A `Uint8Array` of 32 bytes containing the `HMAC-SHA256` tag.
987
+ *
988
+ * @remarks
989
+ * - Algorithm steps:
990
+ * - 1. Keys longer than 64 bytes are hashed with `SHA-256`
991
+ * - 2. Keys shorter than 64 bytes are padded with zeros
992
+ * - 3. Inner hash: `SHA-256((key ⊕ ipad) || message)` where ipad = 0x36 repeated
993
+ * - 4. Outer hash: `SHA-256((key ⊕ opad) || inner_hash)` where opad = 0x5C repeated
994
+ *
995
+ * - The implementation follows RFC 2104 and RFC 4231 specifications.
996
+ * - Block size for `SHA-256` HMAC is 64 bytes (512 bits).
997
+ *
998
+ * **Common use cases:**
999
+ * - API authentication tokens
1000
+ * - Message integrity verification
1001
+ * - Key derivation (as part of `HKDF`)
1002
+ *
1003
+ * @see {@link sha256Bytes} for the underlying hash function
1004
+ */
1005
+ declare function hmacSha256(key: Uint8Array, message: Uint8Array): Uint8Array;
1006
+ /**
1007
+ * * Converts a `Uint8Array` to a `Uint32Array` with big-endian byte order.
1008
+ * - This function groups bytes into 32-bit integers, reading them in big-endian (most significant byte first) order. Missing bytes are treated as zero.
1009
+ *
1010
+ * @example
1011
+ * ```typescript
1012
+ * // Convert bytes to 32-bit integers
1013
+ * const bytes = new Uint8Array([0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC]);
1014
+ * const words = uint8To32ArrayBE(bytes);
1015
+ * // Returns: Uint32Array(2) [0x12345678, 0x9ABC0000] or equivalent: Uint32Array(2) [ 305419896, 2596012032 ]
1016
+ *
1017
+ * // Partial final word
1018
+ * const partial = new Uint8Array([0xFF, 0xEE, 0xDD]);
1019
+ * const words2 = uint8To32ArrayBE(partial);
1020
+ * // Returns: Uint32Array(1) [0xFFEEDD00] or equivalent: Uint32Array(1) [ 4293844224 ]
1021
+ * ```
1022
+ *
1023
+ * @param bytes - The bytes to convert to 32-bit words.
1024
+ * @returns A `Uint32Array` containing the 32-bit big-endian words.
1025
+ *
1026
+ * @remarks
1027
+ * - Input length doesn't need to be a multiple of 4
1028
+ * - Missing bytes in the final word are padded with zeros
1029
+ * - Byte order: `bytes[0]` is the most significant byte of `out[0]`
1030
+ * - This is useful for cryptographic operations that work with 32-bit words
1031
+ */
1032
+ declare function uint8To32ArrayBE(bytes: Uint8Array): Uint32Array;
1033
+ /**
1034
+ * * Converts a 32-bit integer into a 4-byte `Uint8Array` in big-endian (network) byte order.
1035
+ * - This function takes a 32-bit integer and encodes it as 4 bytes with the most significant byte first (big-endian order), which is the standard for network protocols and many cryptographic operations.
1036
+ *
1037
+ * @example
1038
+ * ```typescript
1039
+ * // Convert integer to bytes
1040
+ * const bytes = intTo4BytesBE(0x12345678);
1041
+ * // Returns: Uint8Array(4) [0x12, 0x34, 0x56, 0x78] or equivalent: Uint8Array(4) [ 18, 52, 86, 120 ]
1042
+ *
1043
+ * // Maximum 32-bit value
1044
+ * const maxBytes = intTo4BytesBE(0xFFFFFFFF);
1045
+ * // Returns: Uint8Array(4) [0xFF, 0xFF, 0xFF, 0xFF]
1046
+ *
1047
+ * // Zero
1048
+ * const zeroBytes = intTo4BytesBE(0);
1049
+ * // Returns: Uint8Array(4) [0x00, 0x00, 0x00, 0x00]
1050
+ * ```
1051
+ *
1052
+ * @param n - The 32-bit integer to convert. Values beyond 32 bits will be truncated.
1053
+ * @returns A 4-byte `Uint8Array` representing the value in big-endian format.
1054
+ *
1055
+ * @remarks
1056
+ * - The function uses unsigned 32-bit arithmetic (`>>>` operator)
1057
+ * - Only the lower 32 bits of the input are used (truncation)
1058
+ * - Output is always exactly 4 bytes
1059
+ * - Big-endian order: byte[0] = most significant, byte[3] = least significant
1060
+ *
1061
+ * **Common use cases:**
1062
+ * - Encoding message lengths in network protocols
1063
+ * - Preparing data for cryptographic operations
1064
+ * - Converting integers for storage or transmission
1065
+ *
1066
+ * @see {@link uint8To32ArrayBE} for bytes to 32-bit integers conversion
1067
+ */
1068
+ declare function intTo4BytesBE(n: number): Uint8Array;
1069
+ /**
1070
+ * * Converts a `Uint8Array` to a lowercase hexadecimal string.
1071
+ * - This function encodes binary data (bytes) as a hexadecimal string, with each byte represented as two lowercase hexadecimal digits (0-9, a-f).
1072
+ *
1073
+ * @example
1074
+ * ```typescript
1075
+ * // Convert bytes to hex
1076
+ * const bytes = new Uint8Array([0x12, 0xAB, 0xFF, 0x00]);
1077
+ * const hex = bytesToHex(bytes);
1078
+ * // Returns: '12abff00'
1079
+ *
1080
+ * // Empty array
1081
+ * const emptyHex = bytesToHex(new Uint8Array(0));
1082
+ * // Returns: ''
1083
+ *
1084
+ * // SHA-256 hash to hex
1085
+ * const hashBytes = sha256Bytes(utf8ToBytes('hello'));
1086
+ * const hashHex = bytesToHex(hashBytes);
1087
+ * // Returns: '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
1088
+ * ```
1089
+ *
1090
+ * @param bytes - The bytes to convert to hexadecimal representation.
1091
+ * @returns A lowercase hexadecimal string where each byte is represented by two characters (00-ff).
1092
+ *
1093
+ * @remarks
1094
+ * - Always returns lowercase letters (a-f)
1095
+ * - Zero pads single-digit hex values (e.g., 0x0F → "0f", not "f")
1096
+ * - Efficient O(n) implementation using string concatenation
1097
+ * - No prefix (e.g., no "0x" at the beginning)
1098
+ *
1099
+ * **Common use cases:**
1100
+ * - Displaying cryptographic hashes and signatures
1101
+ * - Debugging binary data
1102
+ * - Converting binary data for JSON serialization
1103
+ * - Creating hex-encoded strings for APIs and protocols
1104
+ *
1105
+ * @see {@link hexToBytes} for reverse process
1106
+ */
1107
+ declare function bytesToHex(bytes: Uint8Array): string;
1108
+ /**
1109
+ * * Converts a hexadecimal string to a `Uint8Array`.
1110
+ * - This function decodes a hexadecimal-encoded string into its raw byte representation, where every two hexadecimal characters (00–ff) are converted into one byte.
1111
+ *
1112
+ * @example
1113
+ * // Convert hex to bytes
1114
+ * const hex = '12abff00';
1115
+ * const bytes = hexToBytes(hex);
1116
+ * // Returns: Uint8Array(4) [18, 171, 255, 0]
1117
+ *
1118
+ * // Empty string
1119
+ * const emptyBytes = hexToBytes('');
1120
+ * // Returns: Uint8Array []
1121
+ *
1122
+ * // Decode SHA-256 hash from hex
1123
+ * const hashHex = '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824';
1124
+ * const hashBytes = hexToBytes(hashHex);
1125
+ * // Returns: Uint8Array(32)
1126
+ *
1127
+ * @param hex - A hexadecimal string where each byte is represented by two characters (00–ff).
1128
+ * @returns A `Uint8Array` containing the decoded bytes. Returns an empty array for invalid input.
1129
+ *
1130
+ * @remarks
1131
+ * - Accepts lowercase and uppercase hexadecimal characters (0–9, a–f, A–F) with or without space between bytes
1132
+ * - Ignores no prefixes (e.g., does not support "0x")
1133
+ * - Requires an even number of hexadecimal characters
1134
+ * - Efficient O(n) implementation with direct byte parsing
1135
+ *
1136
+ * **Common use cases:**
1137
+ * - Decoding cryptographic hashes and signatures
1138
+ * - Parsing hex-encoded binary payloads
1139
+ * - Reconstructing binary data from storage or transport formats
1140
+ * - Working with low-level protocols and binary APIs
1141
+ *
1142
+ * @see {@link bytesToHex} for the reverse process
1143
+ */
1144
+ declare function hexToBytes(hex: string): Uint8Array;
1145
+ //#endregion
1146
+ //#region src/hash/uuid.d.ts
1147
+ /**
1148
+ * * Generates UUIDs across all major RFC-compliant versions (1, 3, 4, 5, 6, 7, 8), following standards from `RFC4122`. Default version is `v4`.
1149
+ *
1150
+ * - **Version behavior:**
1151
+ * - `v1` → Timestamp & node-identifier–based
1152
+ * - `v3` → MD5(namespace + name)
1153
+ * - `v4` → Pure random (correct variant + version injection)
1154
+ * - `v5` → SHA-1(namespace + name)
1155
+ * - `v6` → Re-ordered timestamp variant of `v1` (lexicographically sortable)
1156
+ * - `v7` → Unix-time–based, monotonic-friendly
1157
+ * - `v8` → Custom layout, '“Future'` variant (timestamp + randomness)
1158
+ *
1159
+ * @param options Controls version, formatting, and required fields for `v3` and `v5`.
1160
+ * @returns A 5-parts UUID string formatted with correct version/variant bits.
1161
+ *
1162
+ * @example
1163
+ * // Generate a random UUID v4
1164
+ * const id = uuid();
1165
+ *
1166
+ * @example
1167
+ * // Generate uppercase v7
1168
+ * const id = uuid({ version: 'v7', uppercase: true });
1169
+ *
1170
+ * @example
1171
+ * // Generate v5 UUID
1172
+ * const id = uuid({
1173
+ * version: 'v5',
1174
+ * namespace: '6ba7b810-9dad-11d1-80b4-00c04fd430c8',
1175
+ * name: 'example'
1176
+ * });
1177
+ *
1178
+ * @remarks
1179
+ * - This utility provides a complete, engine-agnostic UUID generator with full RFC compliance, predictable formatting, and reliable uniqueness characteristics, suitable for browsers, Node.js, and restricted JavaScript runtimes.
1180
+ * - **Notes**
1181
+ * - `v1` and `v6` use a generated pseudo-node identifier.
1182
+ * - `v4` and `v8` uses {@link Math.random} when {@link crypto.getRandomValues} is unavailable, ensuring broad compatibility.
1183
+ * - `v3` and `v5` use internal `MD5`/`SHA-1` implementations and remain fully deterministic.
1184
+ * - `v7` **do not rely on crypto APIs**, preserving engine-agnostic behavior.
1185
+ *
1186
+ * - **Limitations**
1187
+ * - `v1`/`v6`: Node identifier is pseudo-random, not derived from real MAC addresses (for privacy).
1188
+ * - `v3`/`v5`: Hash algorithms (`MD5`/`SHA-1`) follow RFC specs but are not cryptographically secure.
1189
+ * - `v7`: Millisecond precision; extremely high throughput may still cause rare collisions.
1190
+ * - `v8`: Uses a simple timestamp + randomness layout; custom layouts are not supported here.
1191
+ *
1192
+ * - Use {@link https://toolbox.nazmul-nhb.dev/docs/utilities/string/generateRandomID generateRandomID} for customized id generation or {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/randomHex randomHex} for hex-only random string with custom length.
1193
+ */
1194
+ declare function uuid<V extends SupportedVersion = 'v4'>(options?: UUIDOptions<V>): UUID<V>;
1195
+ /**
1196
+ * * Decodes a UUID into its internal components, including version, variant, timestamps for time-based UUIDs and other metadata.
1197
+ * - Supports `RFC4122` UUID versions: 1-8.
1198
+ *
1199
+ * @param uuid The UUID string to decode.
1200
+ * @returns A structured `DecodedUUID` object, or `null` for invalid UUIDs.
1201
+ *
1202
+ * @example
1203
+ * const info = decodeUUID("f47ac10b-58cc-4372-a567-0e02b2c3d479");
1204
+ *
1205
+ * @example
1206
+ * const info = decodeUUID(uuid({ version: "v1" }));
1207
+ *
1208
+ * @remarks
1209
+ * - Provides a cross-runtime UUID decoder covering essential metadata and timestamp interpretation for time-ordered UUID versions.
1210
+ * - **Notes**
1211
+ * - `v1/v6` timestamps are converted from the UUID epoch (1582-10-15) to standard Unix milliseconds.
1212
+ * - `v6` timestamps are lexicographically sortable and decoded accordingly.
1213
+ * - `v7` timestamps map directly to Unix time (48-bit millisecond precision).
1214
+ * - `v8` decoding is minimal because layouts are intentionally user-defined.
1215
+ *
1216
+ * - **Limitations**
1217
+ * - `v2` decoding is not implemented specifically.
1218
+ * - `v8` decoding only returns timestamp if it matches a known layout.
1219
+ * - `v3/v5` hash UUIDs contain no timestamp information.
1220
+ */
1221
+ declare function decodeUUID(uuid: string): DecodedUUID | null;
1222
+ /** Check if a value is UUID version 1 */
1223
+ declare function isUUIDv1(value: unknown): value is UUID<'v1'>;
1224
+ /** Check if a value is UUID version 2 */
1225
+ declare function isUUIDv2(value: unknown): value is UUID<'v2'>;
1226
+ /** Check if a value is UUID version 3 */
1227
+ declare function isUUIDv3(value: unknown): value is UUID<'v3'>;
1228
+ /** Check if a value is UUID version 4 */
1229
+ declare function isUUIDv4(value: unknown): value is UUID<'v4'>;
1230
+ /** Check if a value is UUID version 5 */
1231
+ declare function isUUIDv5(value: unknown): value is UUID<'v5'>;
1232
+ /** Check if a value is UUID version 6 */
1233
+ declare function isUUIDv6(value: unknown): value is UUID<'v6'>;
1234
+ /** Check if a value is UUID version 7 */
1235
+ declare function isUUIDv7(value: unknown): value is UUID<'v7'>;
1236
+ /** Check if a value is UUID version 8 */
1237
+ declare function isUUIDv8(value: unknown): value is UUID<'v8'>;
1238
+ //#endregion
1239
+ export { Cipher, Signet, TextCodec, base64ToBytes, bytesToBase64, bytesToHex, bytesToUtf8, concatBytes, decodeUUID, generateRandomID, generateRandomID as randomID, hexToBytes, hmacSha256, intTo4BytesBE, isUUID, isUUIDv1, isUUIDv2, isUUIDv3, isUUIDv4, isUUIDv5, isUUIDv6, isUUIDv7, isUUIDv8, md5, randomHex, sha1, sha256, sha256Bytes, uint8To32ArrayBE, utf8ToBytes, uuid };