@xylabs/hex 5.0.82 → 5.0.84
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.
- package/README.md +236 -0
- package/dist/neutral/HexRegEx.d.ts +14 -0
- package/dist/neutral/HexRegEx.d.ts.map +1 -1
- package/dist/neutral/address/AddressTransformZod.d.ts +2 -0
- package/dist/neutral/address/AddressTransformZod.d.ts.map +1 -1
- package/dist/neutral/address/AddressValidationZod.d.ts +2 -0
- package/dist/neutral/address/AddressValidationZod.d.ts.map +1 -1
- package/dist/neutral/address/address.d.ts +5 -0
- package/dist/neutral/address/address.d.ts.map +1 -1
- package/dist/neutral/address/as.d.ts +6 -0
- package/dist/neutral/address/as.d.ts.map +1 -1
- package/dist/neutral/address/is.d.ts +6 -0
- package/dist/neutral/address/is.d.ts.map +1 -1
- package/dist/neutral/address/to.d.ts +6 -0
- package/dist/neutral/address/to.d.ts.map +1 -1
- package/dist/neutral/ethAddress.d.ts +24 -0
- package/dist/neutral/ethAddress.d.ts.map +1 -1
- package/dist/neutral/hash/as.d.ts +6 -0
- package/dist/neutral/hash/as.d.ts.map +1 -1
- package/dist/neutral/hash/hash.d.ts +13 -0
- package/dist/neutral/hash/hash.d.ts.map +1 -1
- package/dist/neutral/hash/is.d.ts +6 -0
- package/dist/neutral/hash/is.d.ts.map +1 -1
- package/dist/neutral/hash/zod.d.ts +2 -0
- package/dist/neutral/hash/zod.d.ts.map +1 -1
- package/dist/neutral/hex/as.d.ts +6 -0
- package/dist/neutral/hex/as.d.ts.map +1 -1
- package/dist/neutral/hex/from/fromHexString.d.ts +6 -0
- package/dist/neutral/hex/from/fromHexString.d.ts.map +1 -1
- package/dist/neutral/hex/from/fromNumber.d.ts +6 -0
- package/dist/neutral/hex/from/fromNumber.d.ts.map +1 -1
- package/dist/neutral/hex/hex.d.ts +3 -0
- package/dist/neutral/hex/hex.d.ts.map +1 -1
- package/dist/neutral/hex/is.d.ts +6 -0
- package/dist/neutral/hex/is.d.ts.map +1 -1
- package/dist/neutral/hex/isHexZero.d.ts +5 -0
- package/dist/neutral/hex/isHexZero.d.ts.map +1 -1
- package/dist/neutral/hex/legacy.d.ts +5 -0
- package/dist/neutral/hex/legacy.d.ts.map +1 -1
- package/dist/neutral/hex/nibble.d.ts +10 -0
- package/dist/neutral/hex/nibble.d.ts.map +1 -1
- package/dist/neutral/hexToBigInt.d.ts +5 -0
- package/dist/neutral/hexToBigInt.d.ts.map +1 -1
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/zod.d.ts +2 -0
- package/dist/neutral/zod.d.ts.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -107,20 +107,28 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
107
107
|
function HexRegExMinMax(minBytes?, maxBytes?): RegExp;
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
+
Creates a RegExp matching lowercase hex strings with a byte length in the given range.
|
|
111
|
+
|
|
110
112
|
## Parameters
|
|
111
113
|
|
|
112
114
|
### minBytes?
|
|
113
115
|
|
|
114
116
|
`number` = `0`
|
|
115
117
|
|
|
118
|
+
Minimum number of bytes (default 0)
|
|
119
|
+
|
|
116
120
|
### maxBytes?
|
|
117
121
|
|
|
118
122
|
`number` = `...`
|
|
119
123
|
|
|
124
|
+
Maximum number of bytes
|
|
125
|
+
|
|
120
126
|
## Returns
|
|
121
127
|
|
|
122
128
|
`RegExp`
|
|
123
129
|
|
|
130
|
+
A RegExp for validating hex strings within the byte range
|
|
131
|
+
|
|
124
132
|
### <a id="HexRegExMinMaxMixedCaseWithPrefix"></a>HexRegExMinMaxMixedCaseWithPrefix
|
|
125
133
|
|
|
126
134
|
[**@xylabs/hex**](#../README)
|
|
@@ -131,20 +139,28 @@ function HexRegExMinMax(minBytes?, maxBytes?): RegExp;
|
|
|
131
139
|
function HexRegExMinMaxMixedCaseWithPrefix(minBytes?, maxBytes?): RegExp;
|
|
132
140
|
```
|
|
133
141
|
|
|
142
|
+
Creates a RegExp matching mixed-case hex strings with a 0x prefix and a byte length in the given range.
|
|
143
|
+
|
|
134
144
|
## Parameters
|
|
135
145
|
|
|
136
146
|
### minBytes?
|
|
137
147
|
|
|
138
148
|
`number` = `0`
|
|
139
149
|
|
|
150
|
+
Minimum number of bytes (default 0)
|
|
151
|
+
|
|
140
152
|
### maxBytes?
|
|
141
153
|
|
|
142
154
|
`number` = `...`
|
|
143
155
|
|
|
156
|
+
Maximum number of bytes
|
|
157
|
+
|
|
144
158
|
## Returns
|
|
145
159
|
|
|
146
160
|
`RegExp`
|
|
147
161
|
|
|
162
|
+
A RegExp for validating prefixed hex strings within the byte range
|
|
163
|
+
|
|
148
164
|
### <a id="asAddress"></a>asAddress
|
|
149
165
|
|
|
150
166
|
[**@xylabs/hex**](#../README)
|
|
@@ -157,36 +173,50 @@ function HexRegExMinMaxMixedCaseWithPrefix(minBytes?, maxBytes?): RegExp;
|
|
|
157
173
|
function asAddress(value): BrandedAddress | undefined;
|
|
158
174
|
```
|
|
159
175
|
|
|
176
|
+
Attempts to coerce a value into an Address type, returning undefined or throwing based on the assert config.
|
|
177
|
+
|
|
160
178
|
### Parameters
|
|
161
179
|
|
|
162
180
|
### value
|
|
163
181
|
|
|
164
182
|
`unknown`
|
|
165
183
|
|
|
184
|
+
The value to coerce (must be a string)
|
|
185
|
+
|
|
166
186
|
### Returns
|
|
167
187
|
|
|
168
188
|
`BrandedAddress` \| `undefined`
|
|
169
189
|
|
|
190
|
+
The value as Address, or undefined if coercion fails and assert is not set
|
|
191
|
+
|
|
170
192
|
## Call Signature
|
|
171
193
|
|
|
172
194
|
```ts
|
|
173
195
|
function asAddress(value, assert): BrandedAddress;
|
|
174
196
|
```
|
|
175
197
|
|
|
198
|
+
Attempts to coerce a value into an Address type, returning undefined or throwing based on the assert config.
|
|
199
|
+
|
|
176
200
|
### Parameters
|
|
177
201
|
|
|
178
202
|
### value
|
|
179
203
|
|
|
180
204
|
`unknown`
|
|
181
205
|
|
|
206
|
+
The value to coerce (must be a string)
|
|
207
|
+
|
|
182
208
|
### assert
|
|
183
209
|
|
|
184
210
|
`AssertConfig`
|
|
185
211
|
|
|
212
|
+
If provided, throws on failure instead of returning undefined
|
|
213
|
+
|
|
186
214
|
### Returns
|
|
187
215
|
|
|
188
216
|
`BrandedAddress`
|
|
189
217
|
|
|
218
|
+
The value as Address, or undefined if coercion fails and assert is not set
|
|
219
|
+
|
|
190
220
|
### <a id="asAddressV2"></a>asAddressV2
|
|
191
221
|
|
|
192
222
|
[**@xylabs/hex**](#../README)
|
|
@@ -225,36 +255,50 @@ function asAddressV2(value, assert?): BrandedAddress | undefined;
|
|
|
225
255
|
function asEthAddress(value): EthAddress | undefined;
|
|
226
256
|
```
|
|
227
257
|
|
|
258
|
+
Attempts to coerce a value into an EthAddress, returning undefined or throwing based on the assert config.
|
|
259
|
+
|
|
228
260
|
### Parameters
|
|
229
261
|
|
|
230
262
|
### value
|
|
231
263
|
|
|
232
264
|
`unknown`
|
|
233
265
|
|
|
266
|
+
The value to coerce (must be a string)
|
|
267
|
+
|
|
234
268
|
### Returns
|
|
235
269
|
|
|
236
270
|
[`EthAddress`](#../type-aliases/EthAddress) \| `undefined`
|
|
237
271
|
|
|
272
|
+
The value as EthAddress, or undefined if coercion fails and assert is not set
|
|
273
|
+
|
|
238
274
|
## Call Signature
|
|
239
275
|
|
|
240
276
|
```ts
|
|
241
277
|
function asEthAddress(value, assert): EthAddress;
|
|
242
278
|
```
|
|
243
279
|
|
|
280
|
+
Attempts to coerce a value into an EthAddress, returning undefined or throwing based on the assert config.
|
|
281
|
+
|
|
244
282
|
### Parameters
|
|
245
283
|
|
|
246
284
|
### value
|
|
247
285
|
|
|
248
286
|
`unknown`
|
|
249
287
|
|
|
288
|
+
The value to coerce (must be a string)
|
|
289
|
+
|
|
250
290
|
### assert
|
|
251
291
|
|
|
252
292
|
`AssertConfig`
|
|
253
293
|
|
|
294
|
+
If provided, throws on failure instead of returning undefined
|
|
295
|
+
|
|
254
296
|
### Returns
|
|
255
297
|
|
|
256
298
|
[`EthAddress`](#../type-aliases/EthAddress)
|
|
257
299
|
|
|
300
|
+
The value as EthAddress, or undefined if coercion fails and assert is not set
|
|
301
|
+
|
|
258
302
|
### <a id="asHash"></a>asHash
|
|
259
303
|
|
|
260
304
|
[**@xylabs/hex**](#../README)
|
|
@@ -267,36 +311,50 @@ function asEthAddress(value, assert): EthAddress;
|
|
|
267
311
|
function asHash(value): BrandedHash | undefined;
|
|
268
312
|
```
|
|
269
313
|
|
|
314
|
+
Attempts to coerce a value into a Hash type, returning undefined or throwing based on the assert config.
|
|
315
|
+
|
|
270
316
|
### Parameters
|
|
271
317
|
|
|
272
318
|
### value
|
|
273
319
|
|
|
274
320
|
`unknown`
|
|
275
321
|
|
|
322
|
+
The value to coerce (must be a string)
|
|
323
|
+
|
|
276
324
|
### Returns
|
|
277
325
|
|
|
278
326
|
[`BrandedHash`](#../type-aliases/BrandedHash) \| `undefined`
|
|
279
327
|
|
|
328
|
+
The value as Hash, or undefined if coercion fails and assert is not set
|
|
329
|
+
|
|
280
330
|
## Call Signature
|
|
281
331
|
|
|
282
332
|
```ts
|
|
283
333
|
function asHash(value, assert): BrandedHash;
|
|
284
334
|
```
|
|
285
335
|
|
|
336
|
+
Attempts to coerce a value into a Hash type, returning undefined or throwing based on the assert config.
|
|
337
|
+
|
|
286
338
|
### Parameters
|
|
287
339
|
|
|
288
340
|
### value
|
|
289
341
|
|
|
290
342
|
`unknown`
|
|
291
343
|
|
|
344
|
+
The value to coerce (must be a string)
|
|
345
|
+
|
|
292
346
|
### assert
|
|
293
347
|
|
|
294
348
|
`AssertConfig`
|
|
295
349
|
|
|
350
|
+
If provided, throws on failure instead of returning undefined
|
|
351
|
+
|
|
296
352
|
### Returns
|
|
297
353
|
|
|
298
354
|
[`BrandedHash`](#../type-aliases/BrandedHash)
|
|
299
355
|
|
|
356
|
+
The value as Hash, or undefined if coercion fails and assert is not set
|
|
357
|
+
|
|
300
358
|
### <a id="asHex"></a>asHex
|
|
301
359
|
|
|
302
360
|
[**@xylabs/hex**](#../README)
|
|
@@ -309,36 +367,50 @@ function asHash(value, assert): BrandedHash;
|
|
|
309
367
|
function asHex(value): BrandedHex | undefined;
|
|
310
368
|
```
|
|
311
369
|
|
|
370
|
+
Attempts to coerce a value into a Hex type, returning undefined or throwing based on the assert config.
|
|
371
|
+
|
|
312
372
|
### Parameters
|
|
313
373
|
|
|
314
374
|
### value
|
|
315
375
|
|
|
316
376
|
`unknown`
|
|
317
377
|
|
|
378
|
+
The value to coerce (must be a string)
|
|
379
|
+
|
|
318
380
|
### Returns
|
|
319
381
|
|
|
320
382
|
[`BrandedHex`](#../type-aliases/BrandedHex) \| `undefined`
|
|
321
383
|
|
|
384
|
+
The value as Hex, or undefined if coercion fails and assert is not set
|
|
385
|
+
|
|
322
386
|
## Call Signature
|
|
323
387
|
|
|
324
388
|
```ts
|
|
325
389
|
function asHex(value, assert): BrandedHex;
|
|
326
390
|
```
|
|
327
391
|
|
|
392
|
+
Attempts to coerce a value into a Hex type, returning undefined or throwing based on the assert config.
|
|
393
|
+
|
|
328
394
|
### Parameters
|
|
329
395
|
|
|
330
396
|
### value
|
|
331
397
|
|
|
332
398
|
`unknown`
|
|
333
399
|
|
|
400
|
+
The value to coerce (must be a string)
|
|
401
|
+
|
|
334
402
|
### assert
|
|
335
403
|
|
|
336
404
|
`AssertConfig`
|
|
337
405
|
|
|
406
|
+
If provided, throws on failure instead of returning undefined
|
|
407
|
+
|
|
338
408
|
### Returns
|
|
339
409
|
|
|
340
410
|
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
341
411
|
|
|
412
|
+
The value as Hex, or undefined if coercion fails and assert is not set
|
|
413
|
+
|
|
342
414
|
### <a id="bitsToNibbles"></a>bitsToNibbles
|
|
343
415
|
|
|
344
416
|
[**@xylabs/hex**](#../README)
|
|
@@ -349,16 +421,22 @@ function asHex(value, assert): BrandedHex;
|
|
|
349
421
|
function bitsToNibbles(value): number;
|
|
350
422
|
```
|
|
351
423
|
|
|
424
|
+
Converts a bit count to the equivalent number of hex nibbles (4 bits each).
|
|
425
|
+
|
|
352
426
|
## Parameters
|
|
353
427
|
|
|
354
428
|
### value
|
|
355
429
|
|
|
356
430
|
`number`
|
|
357
431
|
|
|
432
|
+
The number of bits (must be a multiple of 4)
|
|
433
|
+
|
|
358
434
|
## Returns
|
|
359
435
|
|
|
360
436
|
`number`
|
|
361
437
|
|
|
438
|
+
The number of nibbles
|
|
439
|
+
|
|
362
440
|
### <a id="hexFrom"></a>hexFrom
|
|
363
441
|
|
|
364
442
|
[**@xylabs/hex**](#../README)
|
|
@@ -459,20 +537,28 @@ Configuration of output format and validation
|
|
|
459
537
|
function hexFromHexString(value, config?): BrandedHex;
|
|
460
538
|
```
|
|
461
539
|
|
|
540
|
+
Normalizes a hex string by stripping an optional 0x prefix, lowercasing, and padding to byte/bit boundaries.
|
|
541
|
+
|
|
462
542
|
## Parameters
|
|
463
543
|
|
|
464
544
|
### value
|
|
465
545
|
|
|
466
546
|
`string`
|
|
467
547
|
|
|
548
|
+
The hex string to normalize (with or without 0x prefix)
|
|
549
|
+
|
|
468
550
|
### config?
|
|
469
551
|
|
|
470
552
|
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
471
553
|
|
|
554
|
+
Configuration for prefix, byteSize, and bitLength padding
|
|
555
|
+
|
|
472
556
|
## Returns
|
|
473
557
|
|
|
474
558
|
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
475
559
|
|
|
560
|
+
The normalized Hex string
|
|
561
|
+
|
|
476
562
|
### <a id="hexFromNumber"></a>hexFromNumber
|
|
477
563
|
|
|
478
564
|
[**@xylabs/hex**](#../README)
|
|
@@ -483,20 +569,28 @@ function hexFromHexString(value, config?): BrandedHex;
|
|
|
483
569
|
function hexFromNumber(value, config?): BrandedHex;
|
|
484
570
|
```
|
|
485
571
|
|
|
572
|
+
Converts a number to a hex string by converting to BigInt first.
|
|
573
|
+
|
|
486
574
|
## Parameters
|
|
487
575
|
|
|
488
576
|
### value
|
|
489
577
|
|
|
490
578
|
`number`
|
|
491
579
|
|
|
580
|
+
The number to convert
|
|
581
|
+
|
|
492
582
|
### config?
|
|
493
583
|
|
|
494
584
|
[`HexConfig`](#../interfaces/HexConfig)
|
|
495
585
|
|
|
586
|
+
Optional hex output configuration
|
|
587
|
+
|
|
496
588
|
## Returns
|
|
497
589
|
|
|
498
590
|
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
499
591
|
|
|
592
|
+
The hex string representation
|
|
593
|
+
|
|
500
594
|
### <a id="hexToBigInt"></a>hexToBigInt
|
|
501
595
|
|
|
502
596
|
[**@xylabs/hex**](#../README)
|
|
@@ -507,16 +601,22 @@ function hexFromNumber(value, config?): BrandedHex;
|
|
|
507
601
|
function hexToBigInt(hex): bigint;
|
|
508
602
|
```
|
|
509
603
|
|
|
604
|
+
Converts a Hex string to a BigInt.
|
|
605
|
+
|
|
510
606
|
## Parameters
|
|
511
607
|
|
|
512
608
|
### hex
|
|
513
609
|
|
|
514
610
|
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
515
611
|
|
|
612
|
+
The hex string to convert
|
|
613
|
+
|
|
516
614
|
## Returns
|
|
517
615
|
|
|
518
616
|
`bigint`
|
|
519
617
|
|
|
618
|
+
The BigInt representation of the hex value
|
|
619
|
+
|
|
520
620
|
### <a id="isAddress"></a>isAddress
|
|
521
621
|
|
|
522
622
|
[**@xylabs/hex**](#../README)
|
|
@@ -527,20 +627,28 @@ function hexToBigInt(hex): bigint;
|
|
|
527
627
|
function isAddress(value, config?): value is BrandedAddress;
|
|
528
628
|
```
|
|
529
629
|
|
|
630
|
+
Type guard that checks whether a value is a valid 160-bit address.
|
|
631
|
+
|
|
530
632
|
## Parameters
|
|
531
633
|
|
|
532
634
|
### value
|
|
533
635
|
|
|
534
636
|
`unknown`
|
|
535
637
|
|
|
638
|
+
The value to check
|
|
639
|
+
|
|
536
640
|
### config?
|
|
537
641
|
|
|
538
642
|
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
539
643
|
|
|
644
|
+
Optional hex config (defaults to 160-bit, no prefix)
|
|
645
|
+
|
|
540
646
|
## Returns
|
|
541
647
|
|
|
542
648
|
`value is BrandedAddress`
|
|
543
649
|
|
|
650
|
+
True if the value is a valid Address
|
|
651
|
+
|
|
544
652
|
### <a id="isAddressV2"></a>isAddressV2
|
|
545
653
|
|
|
546
654
|
[**@xylabs/hex**](#../README)
|
|
@@ -573,20 +681,28 @@ function isAddressV2(value): value is BrandedAddress;
|
|
|
573
681
|
function isEthAddress(value, config?): value is EthAddress;
|
|
574
682
|
```
|
|
575
683
|
|
|
684
|
+
Type guard that checks whether a value is a valid 0x-prefixed Ethereum address.
|
|
685
|
+
|
|
576
686
|
## Parameters
|
|
577
687
|
|
|
578
688
|
### value
|
|
579
689
|
|
|
580
690
|
`unknown`
|
|
581
691
|
|
|
692
|
+
The value to check
|
|
693
|
+
|
|
582
694
|
### config?
|
|
583
695
|
|
|
584
696
|
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
585
697
|
|
|
698
|
+
Optional hex config (defaults to 160-bit with prefix)
|
|
699
|
+
|
|
586
700
|
## Returns
|
|
587
701
|
|
|
588
702
|
`value is EthAddress`
|
|
589
703
|
|
|
704
|
+
True if the value is a valid EthAddress
|
|
705
|
+
|
|
590
706
|
### <a id="isHash"></a>isHash
|
|
591
707
|
|
|
592
708
|
[**@xylabs/hex**](#../README)
|
|
@@ -597,20 +713,28 @@ function isEthAddress(value, config?): value is EthAddress;
|
|
|
597
713
|
function isHash(value, bitLength?): value is BrandedHash;
|
|
598
714
|
```
|
|
599
715
|
|
|
716
|
+
Type guard that checks whether a value is a valid hash of the specified bit length.
|
|
717
|
+
|
|
600
718
|
## Parameters
|
|
601
719
|
|
|
602
720
|
### value
|
|
603
721
|
|
|
604
722
|
`unknown`
|
|
605
723
|
|
|
724
|
+
The value to check
|
|
725
|
+
|
|
606
726
|
### bitLength?
|
|
607
727
|
|
|
608
728
|
[`HashBitLength`](#../type-aliases/HashBitLength) = `256`
|
|
609
729
|
|
|
730
|
+
The expected bit length of the hash (defaults to 256)
|
|
731
|
+
|
|
610
732
|
## Returns
|
|
611
733
|
|
|
612
734
|
`value is BrandedHash`
|
|
613
735
|
|
|
736
|
+
True if the value is a valid Hash
|
|
737
|
+
|
|
614
738
|
### <a id="isHashBitLength"></a>isHashBitLength
|
|
615
739
|
|
|
616
740
|
[**@xylabs/hex**](#../README)
|
|
@@ -621,16 +745,22 @@ function isHash(value, bitLength?): value is BrandedHash;
|
|
|
621
745
|
function isHashBitLength(value): value is HashBitLength;
|
|
622
746
|
```
|
|
623
747
|
|
|
748
|
+
Type guard that checks whether a value is a valid hash bit length.
|
|
749
|
+
|
|
624
750
|
## Parameters
|
|
625
751
|
|
|
626
752
|
### value
|
|
627
753
|
|
|
628
754
|
`unknown`
|
|
629
755
|
|
|
756
|
+
The value to check
|
|
757
|
+
|
|
630
758
|
## Returns
|
|
631
759
|
|
|
632
760
|
`value is HashBitLength`
|
|
633
761
|
|
|
762
|
+
True if the value is one of the supported HashBitLength values
|
|
763
|
+
|
|
634
764
|
### <a id="isHex"></a>isHex
|
|
635
765
|
|
|
636
766
|
[**@xylabs/hex**](#../README)
|
|
@@ -641,20 +771,28 @@ function isHashBitLength(value): value is HashBitLength;
|
|
|
641
771
|
function isHex(value, config?): value is BrandedHex;
|
|
642
772
|
```
|
|
643
773
|
|
|
774
|
+
Type guard that checks whether a value is a valid hex string.
|
|
775
|
+
|
|
644
776
|
## Parameters
|
|
645
777
|
|
|
646
778
|
### value
|
|
647
779
|
|
|
648
780
|
`unknown`
|
|
649
781
|
|
|
782
|
+
The value to check
|
|
783
|
+
|
|
650
784
|
### config?
|
|
651
785
|
|
|
652
786
|
[`HexConfig`](#../interfaces/HexConfig)
|
|
653
787
|
|
|
788
|
+
Optional configuration for prefix and bit length validation
|
|
789
|
+
|
|
654
790
|
## Returns
|
|
655
791
|
|
|
656
792
|
`value is BrandedHex`
|
|
657
793
|
|
|
794
|
+
True if the value is a valid Hex string
|
|
795
|
+
|
|
658
796
|
### <a id="isHexZero"></a>isHexZero
|
|
659
797
|
|
|
660
798
|
[**@xylabs/hex**](#../README)
|
|
@@ -665,16 +803,22 @@ function isHex(value, config?): value is BrandedHex;
|
|
|
665
803
|
function isHexZero(value?): boolean | undefined;
|
|
666
804
|
```
|
|
667
805
|
|
|
806
|
+
Checks whether a hex string represents a zero value.
|
|
807
|
+
|
|
668
808
|
## Parameters
|
|
669
809
|
|
|
670
810
|
### value?
|
|
671
811
|
|
|
672
812
|
`string`
|
|
673
813
|
|
|
814
|
+
The hex string to check
|
|
815
|
+
|
|
674
816
|
## Returns
|
|
675
817
|
|
|
676
818
|
`boolean` \| `undefined`
|
|
677
819
|
|
|
820
|
+
True if zero, false if non-zero, or undefined if the input is not a string
|
|
821
|
+
|
|
678
822
|
### <a id="nibblesToBits"></a>nibblesToBits
|
|
679
823
|
|
|
680
824
|
[**@xylabs/hex**](#../README)
|
|
@@ -685,16 +829,22 @@ function isHexZero(value?): boolean | undefined;
|
|
|
685
829
|
function nibblesToBits(value): number;
|
|
686
830
|
```
|
|
687
831
|
|
|
832
|
+
Converts a nibble count to the equivalent number of bits.
|
|
833
|
+
|
|
688
834
|
## Parameters
|
|
689
835
|
|
|
690
836
|
### value
|
|
691
837
|
|
|
692
838
|
`number`
|
|
693
839
|
|
|
840
|
+
The number of nibbles
|
|
841
|
+
|
|
694
842
|
## Returns
|
|
695
843
|
|
|
696
844
|
`number`
|
|
697
845
|
|
|
846
|
+
The number of bits
|
|
847
|
+
|
|
698
848
|
### <a id="toAddress"></a>toAddress
|
|
699
849
|
|
|
700
850
|
[**@xylabs/hex**](#../README)
|
|
@@ -705,20 +855,28 @@ function nibblesToBits(value): number;
|
|
|
705
855
|
function toAddress(value, config?): BrandedAddress;
|
|
706
856
|
```
|
|
707
857
|
|
|
858
|
+
Converts a value to a 160-bit Address hex string.
|
|
859
|
+
|
|
708
860
|
## Parameters
|
|
709
861
|
|
|
710
862
|
### value
|
|
711
863
|
|
|
864
|
+
The value to convert (string, number, bigint, or ArrayBuffer)
|
|
865
|
+
|
|
712
866
|
`string` | `number` | `bigint` | `ArrayBufferLike`
|
|
713
867
|
|
|
714
868
|
### config?
|
|
715
869
|
|
|
716
870
|
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
717
871
|
|
|
872
|
+
Optional hex config (defaults to 160-bit, no prefix)
|
|
873
|
+
|
|
718
874
|
## Returns
|
|
719
875
|
|
|
720
876
|
`BrandedAddress`
|
|
721
877
|
|
|
878
|
+
The value as an Address
|
|
879
|
+
|
|
722
880
|
### <a id="toAddressV2"></a>toAddressV2
|
|
723
881
|
|
|
724
882
|
[**@xylabs/hex**](#../README)
|
|
@@ -755,20 +913,28 @@ function toAddressV2(value, assert?): BrandedAddress | undefined;
|
|
|
755
913
|
function toEthAddress(value, config?): EthAddress;
|
|
756
914
|
```
|
|
757
915
|
|
|
916
|
+
Converts a value to a 0x-prefixed Ethereum address string.
|
|
917
|
+
|
|
758
918
|
## Parameters
|
|
759
919
|
|
|
760
920
|
### value
|
|
761
921
|
|
|
922
|
+
The value to convert (string, number, bigint, or ArrayBuffer)
|
|
923
|
+
|
|
762
924
|
`string` | `number` | `bigint` | `ArrayBufferLike`
|
|
763
925
|
|
|
764
926
|
### config?
|
|
765
927
|
|
|
766
928
|
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
767
929
|
|
|
930
|
+
Optional hex config (defaults to 160-bit, no inner prefix)
|
|
931
|
+
|
|
768
932
|
## Returns
|
|
769
933
|
|
|
770
934
|
[`EthAddress`](#../type-aliases/EthAddress)
|
|
771
935
|
|
|
936
|
+
The value as an EthAddress
|
|
937
|
+
|
|
772
938
|
### <a id="toHex"></a>toHex
|
|
773
939
|
|
|
774
940
|
[**@xylabs/hex**](#../README)
|
|
@@ -809,16 +975,22 @@ Configuration of output format and validation
|
|
|
809
975
|
function toHexLegacy(buffer): string;
|
|
810
976
|
```
|
|
811
977
|
|
|
978
|
+
Converts an ArrayBuffer to a hex string without padding or normalization.
|
|
979
|
+
|
|
812
980
|
## Parameters
|
|
813
981
|
|
|
814
982
|
### buffer
|
|
815
983
|
|
|
816
984
|
`ArrayBuffer`
|
|
817
985
|
|
|
986
|
+
The ArrayBuffer to convert
|
|
987
|
+
|
|
818
988
|
## Returns
|
|
819
989
|
|
|
820
990
|
`string`
|
|
821
991
|
|
|
992
|
+
A lowercase hex string representation of the buffer
|
|
993
|
+
|
|
822
994
|
### interfaces
|
|
823
995
|
|
|
824
996
|
### <a id="HexConfig"></a>HexConfig
|
|
@@ -865,6 +1037,8 @@ optional prefix: boolean;
|
|
|
865
1037
|
type Address = z.infer<typeof AddressZod>;
|
|
866
1038
|
```
|
|
867
1039
|
|
|
1040
|
+
A validated 20-byte address string type, inferred from the AddressZod schema.
|
|
1041
|
+
|
|
868
1042
|
### <a id="AddressTransformZodType"></a>AddressTransformZodType
|
|
869
1043
|
|
|
870
1044
|
[**@xylabs/hex**](#../README)
|
|
@@ -875,6 +1049,8 @@ type Address = z.infer<typeof AddressZod>;
|
|
|
875
1049
|
type AddressTransformZodType = z.infer<typeof AddressTransformZod>;
|
|
876
1050
|
```
|
|
877
1051
|
|
|
1052
|
+
The output type of AddressTransformZod after parsing and transformation.
|
|
1053
|
+
|
|
878
1054
|
### <a id="AddressValidationZodType"></a>AddressValidationZodType
|
|
879
1055
|
|
|
880
1056
|
[**@xylabs/hex**](#../README)
|
|
@@ -885,6 +1061,8 @@ type AddressTransformZodType = z.infer<typeof AddressTransformZod>;
|
|
|
885
1061
|
type AddressValidationZodType = z.infer<typeof AddressValidationZod>;
|
|
886
1062
|
```
|
|
887
1063
|
|
|
1064
|
+
The output type of AddressValidationZod after parsing.
|
|
1065
|
+
|
|
888
1066
|
### <a id="BrandedHash"></a>BrandedHash
|
|
889
1067
|
|
|
890
1068
|
[**@xylabs/hex**](#../README)
|
|
@@ -897,6 +1075,8 @@ type BrandedHash = Brand<Hex, {
|
|
|
897
1075
|
}>;
|
|
898
1076
|
```
|
|
899
1077
|
|
|
1078
|
+
Branded type representing a validated hash hex string.
|
|
1079
|
+
|
|
900
1080
|
### <a id="BrandedHex"></a>BrandedHex
|
|
901
1081
|
|
|
902
1082
|
[**@xylabs/hex**](#../README)
|
|
@@ -909,6 +1089,8 @@ type BrandedHex = Brand<Lowercase<string>, {
|
|
|
909
1089
|
}>;
|
|
910
1090
|
```
|
|
911
1091
|
|
|
1092
|
+
Branded type representing a validated lowercase hex string.
|
|
1093
|
+
|
|
912
1094
|
### <a id="EthAddress"></a>EthAddress
|
|
913
1095
|
|
|
914
1096
|
[**@xylabs/hex**](#../README)
|
|
@@ -921,6 +1103,8 @@ type EthAddress = Brand<string, {
|
|
|
921
1103
|
}>;
|
|
922
1104
|
```
|
|
923
1105
|
|
|
1106
|
+
Branded type representing a validated Ethereum address with 0x prefix.
|
|
1107
|
+
|
|
924
1108
|
### <a id="Hash"></a>Hash
|
|
925
1109
|
|
|
926
1110
|
[**@xylabs/hex**](#../README)
|
|
@@ -931,6 +1115,8 @@ type EthAddress = Brand<string, {
|
|
|
931
1115
|
type Hash = z.infer<typeof HashZod>;
|
|
932
1116
|
```
|
|
933
1117
|
|
|
1118
|
+
A validated hash string type, inferred from the HashZod schema.
|
|
1119
|
+
|
|
934
1120
|
### <a id="HashBitLength"></a>HashBitLength
|
|
935
1121
|
|
|
936
1122
|
[**@xylabs/hex**](#../README)
|
|
@@ -941,6 +1127,8 @@ type Hash = z.infer<typeof HashZod>;
|
|
|
941
1127
|
type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
942
1128
|
```
|
|
943
1129
|
|
|
1130
|
+
Valid bit lengths for hash values.
|
|
1131
|
+
|
|
944
1132
|
### <a id="Hex"></a>Hex
|
|
945
1133
|
|
|
946
1134
|
[**@xylabs/hex**](#../README)
|
|
@@ -951,6 +1139,8 @@ type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
|
951
1139
|
type Hex = z.infer<typeof HexZod>;
|
|
952
1140
|
```
|
|
953
1141
|
|
|
1142
|
+
A validated hex string type, inferred from the HexZod schema.
|
|
1143
|
+
|
|
954
1144
|
### variables
|
|
955
1145
|
|
|
956
1146
|
### <a id="ADDRESS_LENGTH"></a>ADDRESS_LENGTH
|
|
@@ -963,6 +1153,8 @@ type Hex = z.infer<typeof HexZod>;
|
|
|
963
1153
|
const ADDRESS_LENGTH: 40;
|
|
964
1154
|
```
|
|
965
1155
|
|
|
1156
|
+
The character length of an address hex string (40 hex characters / 20 bytes).
|
|
1157
|
+
|
|
966
1158
|
### <a id="AddressRegEx"></a>AddressRegEx
|
|
967
1159
|
|
|
968
1160
|
[**@xylabs/hex**](#../README)
|
|
@@ -973,6 +1165,8 @@ const ADDRESS_LENGTH: 40;
|
|
|
973
1165
|
const AddressRegEx: RegExp;
|
|
974
1166
|
```
|
|
975
1167
|
|
|
1168
|
+
Regular expression matching a 20-byte (40 hex character) address string.
|
|
1169
|
+
|
|
976
1170
|
### <a id="AddressTransformZod"></a>AddressTransformZod
|
|
977
1171
|
|
|
978
1172
|
[**@xylabs/hex**](#../README)
|
|
@@ -983,6 +1177,8 @@ const AddressRegEx: RegExp;
|
|
|
983
1177
|
const AddressTransformZod: ZodPipe<ZodPipe<ZodUnion<readonly [ZodString, ZodBigInt, ZodNumber]>, ZodTransform<string, string | number | bigint>>, ZodTransform<BrandedAddress, string>>;
|
|
984
1178
|
```
|
|
985
1179
|
|
|
1180
|
+
Zod schema that accepts a string, bigint, or number and transforms it into a validated Address.
|
|
1181
|
+
|
|
986
1182
|
### <a id="AddressValidationZod"></a>AddressValidationZod
|
|
987
1183
|
|
|
988
1184
|
[**@xylabs/hex**](#../README)
|
|
@@ -993,6 +1189,8 @@ const AddressTransformZod: ZodPipe<ZodPipe<ZodUnion<readonly [ZodString, ZodBigI
|
|
|
993
1189
|
const AddressValidationZod: ZodPipe<ZodString, ZodTransform<BrandedAddress, string>>;
|
|
994
1190
|
```
|
|
995
1191
|
|
|
1192
|
+
Zod schema that validates a string is a properly formatted 40-character hex address.
|
|
1193
|
+
|
|
996
1194
|
### <a id="AddressZod"></a>AddressZod
|
|
997
1195
|
|
|
998
1196
|
[**@xylabs/hex**](#../README)
|
|
@@ -1003,6 +1201,8 @@ const AddressValidationZod: ZodPipe<ZodString, ZodTransform<BrandedAddress, stri
|
|
|
1003
1201
|
const AddressZod: ZodPipe<ZodString, ZodTransform<BrandedAddress, string>>;
|
|
1004
1202
|
```
|
|
1005
1203
|
|
|
1204
|
+
Zod schema that validates and transforms a string into a branded Address type.
|
|
1205
|
+
|
|
1006
1206
|
### <a id="BigIntToJsonZod"></a>BigIntToJsonZod
|
|
1007
1207
|
|
|
1008
1208
|
[**@xylabs/hex**](#../README)
|
|
@@ -1013,6 +1213,8 @@ const AddressZod: ZodPipe<ZodString, ZodTransform<BrandedAddress, string>>;
|
|
|
1013
1213
|
const BigIntToJsonZod: ZodPipe<ZodBigInt, ZodTransform<BrandedHex, bigint>>;
|
|
1014
1214
|
```
|
|
1015
1215
|
|
|
1216
|
+
Zod schema that transforms a non-negative BigInt into a hex string for JSON serialization.
|
|
1217
|
+
|
|
1016
1218
|
### <a id="ETH_ZERO_ADDRESS"></a>ETH_ZERO_ADDRESS
|
|
1017
1219
|
|
|
1018
1220
|
[**@xylabs/hex**](#../README)
|
|
@@ -1023,6 +1225,8 @@ const BigIntToJsonZod: ZodPipe<ZodBigInt, ZodTransform<BrandedHex, bigint>>;
|
|
|
1023
1225
|
const ETH_ZERO_ADDRESS: EthAddress;
|
|
1024
1226
|
```
|
|
1025
1227
|
|
|
1228
|
+
The zero Ethereum address constant (0x followed by 40 zero characters).
|
|
1229
|
+
|
|
1026
1230
|
### <a id="EthAddressFromStringSchema"></a>EthAddressFromStringSchema
|
|
1027
1231
|
|
|
1028
1232
|
[**@xylabs/hex**](#../README)
|
|
@@ -1047,6 +1251,8 @@ use EthAddressFromStringZod
|
|
|
1047
1251
|
const EthAddressFromStringZod: ZodPipe<ZodString, ZodTransform<EthAddress, string>>;
|
|
1048
1252
|
```
|
|
1049
1253
|
|
|
1254
|
+
Zod schema that validates and transforms a string into an EthAddress type.
|
|
1255
|
+
|
|
1050
1256
|
### <a id="EthAddressRegEx"></a>EthAddressRegEx
|
|
1051
1257
|
|
|
1052
1258
|
[**@xylabs/hex**](#../README)
|
|
@@ -1057,6 +1263,8 @@ const EthAddressFromStringZod: ZodPipe<ZodString, ZodTransform<EthAddress, strin
|
|
|
1057
1263
|
const EthAddressRegEx: RegExp;
|
|
1058
1264
|
```
|
|
1059
1265
|
|
|
1266
|
+
Regular expression matching a 20-byte Ethereum address with 0x prefix (mixed case).
|
|
1267
|
+
|
|
1060
1268
|
### <a id="EthAddressToStringSchema"></a>EthAddressToStringSchema
|
|
1061
1269
|
|
|
1062
1270
|
[**@xylabs/hex**](#../README)
|
|
@@ -1081,6 +1289,8 @@ use EthAddressToStringZod
|
|
|
1081
1289
|
const EthAddressToStringZod: ZodString;
|
|
1082
1290
|
```
|
|
1083
1291
|
|
|
1292
|
+
Zod schema that validates a string is a properly formatted Ethereum address.
|
|
1293
|
+
|
|
1084
1294
|
### <a id="EthAddressZod"></a>EthAddressZod
|
|
1085
1295
|
|
|
1086
1296
|
[**@xylabs/hex**](#../README)
|
|
@@ -1091,6 +1301,8 @@ const EthAddressToStringZod: ZodString;
|
|
|
1091
1301
|
const EthAddressZod: ZodString & ZodType<EthAddress, string, $ZodTypeInternals<EthAddress, string>>;
|
|
1092
1302
|
```
|
|
1093
1303
|
|
|
1304
|
+
Zod schema that validates a string as a properly formatted Ethereum address using regex and type guard.
|
|
1305
|
+
|
|
1094
1306
|
### <a id="HASH_LENGTH"></a>HASH_LENGTH
|
|
1095
1307
|
|
|
1096
1308
|
[**@xylabs/hex**](#../README)
|
|
@@ -1101,6 +1313,8 @@ const EthAddressZod: ZodString & ZodType<EthAddress, string, $ZodTypeInternals<E
|
|
|
1101
1313
|
const HASH_LENGTH: 32;
|
|
1102
1314
|
```
|
|
1103
1315
|
|
|
1316
|
+
The byte length of a standard hash (32 bytes / 256 bits).
|
|
1317
|
+
|
|
1104
1318
|
### <a id="HashBitLength"></a>HashBitLength
|
|
1105
1319
|
|
|
1106
1320
|
[**@xylabs/hex**](#../README)
|
|
@@ -1111,6 +1325,8 @@ const HASH_LENGTH: 32;
|
|
|
1111
1325
|
HashBitLength: HashBitLength[];
|
|
1112
1326
|
```
|
|
1113
1327
|
|
|
1328
|
+
Array of all valid hash bit lengths for runtime validation.
|
|
1329
|
+
|
|
1114
1330
|
### <a id="HashRegEx"></a>HashRegEx
|
|
1115
1331
|
|
|
1116
1332
|
[**@xylabs/hex**](#../README)
|
|
@@ -1121,6 +1337,8 @@ HashBitLength: HashBitLength[];
|
|
|
1121
1337
|
const HashRegEx: RegExp;
|
|
1122
1338
|
```
|
|
1123
1339
|
|
|
1340
|
+
Regular expression matching a 32-byte (64 hex character) hash string.
|
|
1341
|
+
|
|
1124
1342
|
### <a id="HashToJsonZod"></a>HashToJsonZod
|
|
1125
1343
|
|
|
1126
1344
|
[**@xylabs/hex**](#../README)
|
|
@@ -1131,6 +1349,8 @@ const HashRegEx: RegExp;
|
|
|
1131
1349
|
const HashToJsonZod: ZodPipe<ZodPipe<ZodString, ZodTransform<BrandedHash, string>>, ZodTransform<string, BrandedHash>>;
|
|
1132
1350
|
```
|
|
1133
1351
|
|
|
1352
|
+
Zod schema that transforms a Hash to a plain string for JSON serialization.
|
|
1353
|
+
|
|
1134
1354
|
### <a id="HashZod"></a>HashZod
|
|
1135
1355
|
|
|
1136
1356
|
[**@xylabs/hex**](#../README)
|
|
@@ -1141,6 +1361,8 @@ const HashToJsonZod: ZodPipe<ZodPipe<ZodString, ZodTransform<BrandedHash, string
|
|
|
1141
1361
|
const HashZod: ZodPipe<ZodString, ZodTransform<BrandedHash, string>>;
|
|
1142
1362
|
```
|
|
1143
1363
|
|
|
1364
|
+
Zod schema that validates and transforms a string into a branded Hash type.
|
|
1365
|
+
|
|
1144
1366
|
### <a id="HexRegEx"></a>HexRegEx
|
|
1145
1367
|
|
|
1146
1368
|
[**@xylabs/hex**](#../README)
|
|
@@ -1151,6 +1373,8 @@ const HashZod: ZodPipe<ZodString, ZodTransform<BrandedHash, string>>;
|
|
|
1151
1373
|
const HexRegEx: RegExp;
|
|
1152
1374
|
```
|
|
1153
1375
|
|
|
1376
|
+
Regular expression matching a lowercase hex string without prefix.
|
|
1377
|
+
|
|
1154
1378
|
### <a id="HexRegExWithPrefix"></a>HexRegExWithPrefix
|
|
1155
1379
|
|
|
1156
1380
|
[**@xylabs/hex**](#../README)
|
|
@@ -1161,6 +1385,8 @@ const HexRegEx: RegExp;
|
|
|
1161
1385
|
const HexRegExWithPrefix: RegExp;
|
|
1162
1386
|
```
|
|
1163
1387
|
|
|
1388
|
+
Regular expression matching a lowercase hex string with a 0x prefix.
|
|
1389
|
+
|
|
1164
1390
|
### <a id="HexZod"></a>HexZod
|
|
1165
1391
|
|
|
1166
1392
|
[**@xylabs/hex**](#../README)
|
|
@@ -1171,6 +1397,8 @@ const HexRegExWithPrefix: RegExp;
|
|
|
1171
1397
|
const HexZod: ZodPipe<ZodString, ZodTransform<BrandedHex, string>>;
|
|
1172
1398
|
```
|
|
1173
1399
|
|
|
1400
|
+
Zod schema that validates and transforms a string into a branded Hex type.
|
|
1401
|
+
|
|
1174
1402
|
### <a id="JsonToBigIntZod"></a>JsonToBigIntZod
|
|
1175
1403
|
|
|
1176
1404
|
[**@xylabs/hex**](#../README)
|
|
@@ -1181,6 +1409,8 @@ const HexZod: ZodPipe<ZodString, ZodTransform<BrandedHex, string>>;
|
|
|
1181
1409
|
const JsonToBigIntZod: ZodPipe<ZodPipe<ZodString, ZodTransform<BrandedHex, string>>, ZodTransform<bigint, BrandedHex>>;
|
|
1182
1410
|
```
|
|
1183
1411
|
|
|
1412
|
+
Zod schema that parses a JSON hex string into a BigInt.
|
|
1413
|
+
|
|
1184
1414
|
### <a id="JsonToHashZod"></a>JsonToHashZod
|
|
1185
1415
|
|
|
1186
1416
|
[**@xylabs/hex**](#../README)
|
|
@@ -1191,6 +1421,8 @@ const JsonToBigIntZod: ZodPipe<ZodPipe<ZodString, ZodTransform<BrandedHex, strin
|
|
|
1191
1421
|
const JsonToHashZod: ZodPipe<ZodString, ZodTransform<BrandedHash, string>>;
|
|
1192
1422
|
```
|
|
1193
1423
|
|
|
1424
|
+
Zod schema that parses a JSON string into a validated Hash, throwing on invalid input.
|
|
1425
|
+
|
|
1194
1426
|
### <a id="ZERO_ADDRESS"></a>ZERO_ADDRESS
|
|
1195
1427
|
|
|
1196
1428
|
[**@xylabs/hex**](#../README)
|
|
@@ -1201,6 +1433,8 @@ const JsonToHashZod: ZodPipe<ZodString, ZodTransform<BrandedHash, string>>;
|
|
|
1201
1433
|
const ZERO_ADDRESS: BrandedAddress;
|
|
1202
1434
|
```
|
|
1203
1435
|
|
|
1436
|
+
A 160-bit zero address constant.
|
|
1437
|
+
|
|
1204
1438
|
### <a id="ZERO_HASH"></a>ZERO_HASH
|
|
1205
1439
|
|
|
1206
1440
|
[**@xylabs/hex**](#../README)
|
|
@@ -1211,6 +1445,8 @@ const ZERO_ADDRESS: BrandedAddress;
|
|
|
1211
1445
|
const ZERO_HASH: BrandedHash;
|
|
1212
1446
|
```
|
|
1213
1447
|
|
|
1448
|
+
A 256-bit zero hash constant.
|
|
1449
|
+
|
|
1214
1450
|
|
|
1215
1451
|
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|
|
1216
1452
|
|