@xylabs/hex 5.0.80 → 5.0.81
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 +566 -57
- package/dist/neutral/index.mjs +1 -1
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +6 -9
- package/src/HexRegEx.ts +0 -10
- package/src/address/AddressTransformZod.ts +0 -26
- package/src/address/AddressValidationZod.ts +0 -12
- package/src/address/address.ts +0 -16
- package/src/address/as.ts +0 -37
- package/src/address/index.ts +0 -6
- package/src/address/is.ts +0 -14
- package/src/address/to.ts +0 -18
- package/src/ethAddress.ts +0 -70
- package/src/hash/as.ts +0 -24
- package/src/hash/hash.ts +0 -25
- package/src/hash/index.ts +0 -4
- package/src/hash/is.ts +0 -6
- package/src/hash/zod.ts +0 -8
- package/src/hex/as.ts +0 -24
- package/src/hex/from/from.ts +0 -31
- package/src/hex/from/fromArrayBuffer.ts +0 -13
- package/src/hex/from/fromBigInt.ts +0 -13
- package/src/hex/from/fromHexString.ts +0 -20
- package/src/hex/from/fromNumber.ts +0 -6
- package/src/hex/from/index.ts +0 -5
- package/src/hex/hex.ts +0 -17
- package/src/hex/index.ts +0 -8
- package/src/hex/is.ts +0 -16
- package/src/hex/isHexZero.ts +0 -7
- package/src/hex/legacy.ts +0 -3
- package/src/hex/nibble.ts +0 -11
- package/src/hex/to.ts +0 -13
- package/src/hexToBigInt.ts +0 -5
- package/src/index.ts +0 -7
- package/src/zod.ts +0 -7
package/README.md
CHANGED
|
@@ -27,27 +27,60 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
27
27
|
|
|
28
28
|
## Type Aliases
|
|
29
29
|
|
|
30
|
+
- [AddressTransformZodType](#type-aliases/AddressTransformZodType)
|
|
31
|
+
- [AddressValidationZodType](#type-aliases/AddressValidationZodType)
|
|
30
32
|
- [Address](#type-aliases/Address)
|
|
33
|
+
- [EthAddress](#type-aliases/EthAddress)
|
|
31
34
|
- [HashBitLength](#type-aliases/HashBitLength)
|
|
35
|
+
- [BrandedHash](#type-aliases/BrandedHash)
|
|
32
36
|
- [Hash](#type-aliases/Hash)
|
|
37
|
+
- [BrandedHex](#type-aliases/BrandedHex)
|
|
33
38
|
- [Hex](#type-aliases/Hex)
|
|
34
39
|
|
|
35
40
|
## Variables
|
|
36
41
|
|
|
42
|
+
- [HexRegEx](#variables/HexRegEx)
|
|
43
|
+
- [HexRegExWithPrefix](#variables/HexRegExWithPrefix)
|
|
44
|
+
- [AddressTransformZod](#variables/AddressTransformZod)
|
|
45
|
+
- [AddressValidationZod](#variables/AddressValidationZod)
|
|
37
46
|
- [ZERO\_ADDRESS](#variables/ZERO_ADDRESS)
|
|
47
|
+
- [ADDRESS\_LENGTH](#variables/ADDRESS_LENGTH)
|
|
48
|
+
- [AddressRegEx](#variables/AddressRegEx)
|
|
49
|
+
- [AddressZod](#variables/AddressZod)
|
|
50
|
+
- [EthAddressRegEx](#variables/EthAddressRegEx)
|
|
51
|
+
- [EthAddressToStringZod](#variables/EthAddressToStringZod)
|
|
52
|
+
- [~~EthAddressToStringSchema~~](#variables/EthAddressToStringSchema)
|
|
53
|
+
- [EthAddressFromStringZod](#variables/EthAddressFromStringZod)
|
|
54
|
+
- [~~EthAddressFromStringSchema~~](#variables/EthAddressFromStringSchema)
|
|
55
|
+
- [ETH\_ZERO\_ADDRESS](#variables/ETH_ZERO_ADDRESS)
|
|
56
|
+
- [EthAddressZod](#variables/EthAddressZod)
|
|
57
|
+
- [HASH\_LENGTH](#variables/HASH_LENGTH)
|
|
58
|
+
- [HashRegEx](#variables/HashRegEx)
|
|
38
59
|
- [ZERO\_HASH](#variables/ZERO_HASH)
|
|
39
60
|
- [HashBitLength](#variables/HashBitLength)
|
|
40
|
-
- [
|
|
41
|
-
- [
|
|
61
|
+
- [HashZod](#variables/HashZod)
|
|
62
|
+
- [HashToJsonZod](#variables/HashToJsonZod)
|
|
63
|
+
- [JsonToHashZod](#variables/JsonToHashZod)
|
|
64
|
+
- [HexZod](#variables/HexZod)
|
|
65
|
+
- [BigIntToJsonZod](#variables/BigIntToJsonZod)
|
|
66
|
+
- [JsonToBigIntZod](#variables/JsonToBigIntZod)
|
|
42
67
|
|
|
43
68
|
## Functions
|
|
44
69
|
|
|
45
|
-
- [
|
|
46
|
-
- [
|
|
70
|
+
- [HexRegExMinMax](#functions/HexRegExMinMax)
|
|
71
|
+
- [HexRegExMinMaxMixedCaseWithPrefix](#functions/HexRegExMinMaxMixedCaseWithPrefix)
|
|
47
72
|
- [asAddress](#functions/asAddress)
|
|
73
|
+
- [asAddressV2](#functions/asAddressV2)
|
|
74
|
+
- [isAddress](#functions/isAddress)
|
|
75
|
+
- [isAddressV2](#functions/isAddressV2)
|
|
76
|
+
- [toAddress](#functions/toAddress)
|
|
77
|
+
- [toAddressV2](#functions/toAddressV2)
|
|
78
|
+
- [toEthAddress](#functions/toEthAddress)
|
|
79
|
+
- [isEthAddress](#functions/isEthAddress)
|
|
80
|
+
- [asEthAddress](#functions/asEthAddress)
|
|
81
|
+
- [asHash](#functions/asHash)
|
|
48
82
|
- [isHashBitLength](#functions/isHashBitLength)
|
|
49
83
|
- [isHash](#functions/isHash)
|
|
50
|
-
- [asHash](#functions/asHash)
|
|
51
84
|
- [asHex](#functions/asHex)
|
|
52
85
|
- [hexFrom](#functions/hexFrom)
|
|
53
86
|
- [hexFromArrayBuffer](#functions/hexFromArrayBuffer)
|
|
@@ -64,6 +97,54 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
64
97
|
|
|
65
98
|
### functions
|
|
66
99
|
|
|
100
|
+
### <a id="HexRegExMinMax"></a>HexRegExMinMax
|
|
101
|
+
|
|
102
|
+
[**@xylabs/hex**](#../README)
|
|
103
|
+
|
|
104
|
+
***
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
function HexRegExMinMax(minBytes?, maxBytes?): RegExp;
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Parameters
|
|
111
|
+
|
|
112
|
+
### minBytes?
|
|
113
|
+
|
|
114
|
+
`number` = `0`
|
|
115
|
+
|
|
116
|
+
### maxBytes?
|
|
117
|
+
|
|
118
|
+
`number` = `...`
|
|
119
|
+
|
|
120
|
+
## Returns
|
|
121
|
+
|
|
122
|
+
`RegExp`
|
|
123
|
+
|
|
124
|
+
### <a id="HexRegExMinMaxMixedCaseWithPrefix"></a>HexRegExMinMaxMixedCaseWithPrefix
|
|
125
|
+
|
|
126
|
+
[**@xylabs/hex**](#../README)
|
|
127
|
+
|
|
128
|
+
***
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
function HexRegExMinMaxMixedCaseWithPrefix(minBytes?, maxBytes?): RegExp;
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Parameters
|
|
135
|
+
|
|
136
|
+
### minBytes?
|
|
137
|
+
|
|
138
|
+
`number` = `0`
|
|
139
|
+
|
|
140
|
+
### maxBytes?
|
|
141
|
+
|
|
142
|
+
`number` = `...`
|
|
143
|
+
|
|
144
|
+
## Returns
|
|
145
|
+
|
|
146
|
+
`RegExp`
|
|
147
|
+
|
|
67
148
|
### <a id="asAddress"></a>asAddress
|
|
68
149
|
|
|
69
150
|
[**@xylabs/hex**](#../README)
|
|
@@ -73,7 +154,75 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
73
154
|
## Call Signature
|
|
74
155
|
|
|
75
156
|
```ts
|
|
76
|
-
function asAddress(value):
|
|
157
|
+
function asAddress(value): BrandedAddress | undefined;
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Parameters
|
|
161
|
+
|
|
162
|
+
### value
|
|
163
|
+
|
|
164
|
+
`unknown`
|
|
165
|
+
|
|
166
|
+
### Returns
|
|
167
|
+
|
|
168
|
+
`BrandedAddress` \| `undefined`
|
|
169
|
+
|
|
170
|
+
## Call Signature
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
function asAddress(value, assert): BrandedAddress;
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Parameters
|
|
177
|
+
|
|
178
|
+
### value
|
|
179
|
+
|
|
180
|
+
`unknown`
|
|
181
|
+
|
|
182
|
+
### assert
|
|
183
|
+
|
|
184
|
+
`AssertConfig`
|
|
185
|
+
|
|
186
|
+
### Returns
|
|
187
|
+
|
|
188
|
+
`BrandedAddress`
|
|
189
|
+
|
|
190
|
+
### <a id="asAddressV2"></a>asAddressV2
|
|
191
|
+
|
|
192
|
+
[**@xylabs/hex**](#../README)
|
|
193
|
+
|
|
194
|
+
***
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
function asAddressV2(value, assert?): BrandedAddress | undefined;
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**`Alpha`**
|
|
201
|
+
|
|
202
|
+
## Parameters
|
|
203
|
+
|
|
204
|
+
### value
|
|
205
|
+
|
|
206
|
+
`unknown`
|
|
207
|
+
|
|
208
|
+
### assert?
|
|
209
|
+
|
|
210
|
+
`boolean` = `false`
|
|
211
|
+
|
|
212
|
+
## Returns
|
|
213
|
+
|
|
214
|
+
`BrandedAddress` \| `undefined`
|
|
215
|
+
|
|
216
|
+
### <a id="asEthAddress"></a>asEthAddress
|
|
217
|
+
|
|
218
|
+
[**@xylabs/hex**](#../README)
|
|
219
|
+
|
|
220
|
+
***
|
|
221
|
+
|
|
222
|
+
## Call Signature
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
function asEthAddress(value): EthAddress | undefined;
|
|
77
226
|
```
|
|
78
227
|
|
|
79
228
|
### Parameters
|
|
@@ -84,12 +233,12 @@ function asAddress(value): undefined | Lowercase<string>;
|
|
|
84
233
|
|
|
85
234
|
### Returns
|
|
86
235
|
|
|
87
|
-
`
|
|
236
|
+
[`EthAddress`](#../type-aliases/EthAddress) \| `undefined`
|
|
88
237
|
|
|
89
238
|
## Call Signature
|
|
90
239
|
|
|
91
240
|
```ts
|
|
92
|
-
function
|
|
241
|
+
function asEthAddress(value, assert): EthAddress;
|
|
93
242
|
```
|
|
94
243
|
|
|
95
244
|
### Parameters
|
|
@@ -104,7 +253,7 @@ function asAddress(value, assert): Lowercase<string>;
|
|
|
104
253
|
|
|
105
254
|
### Returns
|
|
106
255
|
|
|
107
|
-
`
|
|
256
|
+
[`EthAddress`](#../type-aliases/EthAddress)
|
|
108
257
|
|
|
109
258
|
### <a id="asHash"></a>asHash
|
|
110
259
|
|
|
@@ -115,7 +264,7 @@ function asAddress(value, assert): Lowercase<string>;
|
|
|
115
264
|
## Call Signature
|
|
116
265
|
|
|
117
266
|
```ts
|
|
118
|
-
function asHash(value):
|
|
267
|
+
function asHash(value): BrandedHash | undefined;
|
|
119
268
|
```
|
|
120
269
|
|
|
121
270
|
### Parameters
|
|
@@ -126,12 +275,12 @@ function asHash(value): undefined | Lowercase<string>;
|
|
|
126
275
|
|
|
127
276
|
### Returns
|
|
128
277
|
|
|
129
|
-
`
|
|
278
|
+
[`BrandedHash`](#../type-aliases/BrandedHash) \| `undefined`
|
|
130
279
|
|
|
131
280
|
## Call Signature
|
|
132
281
|
|
|
133
282
|
```ts
|
|
134
|
-
function asHash(value, assert):
|
|
283
|
+
function asHash(value, assert): BrandedHash;
|
|
135
284
|
```
|
|
136
285
|
|
|
137
286
|
### Parameters
|
|
@@ -146,7 +295,7 @@ function asHash(value, assert): Lowercase<string>;
|
|
|
146
295
|
|
|
147
296
|
### Returns
|
|
148
297
|
|
|
149
|
-
`
|
|
298
|
+
[`BrandedHash`](#../type-aliases/BrandedHash)
|
|
150
299
|
|
|
151
300
|
### <a id="asHex"></a>asHex
|
|
152
301
|
|
|
@@ -157,7 +306,7 @@ function asHash(value, assert): Lowercase<string>;
|
|
|
157
306
|
## Call Signature
|
|
158
307
|
|
|
159
308
|
```ts
|
|
160
|
-
function asHex(value):
|
|
309
|
+
function asHex(value): BrandedHex | undefined;
|
|
161
310
|
```
|
|
162
311
|
|
|
163
312
|
### Parameters
|
|
@@ -168,12 +317,12 @@ function asHex(value): undefined | Lowercase<string>;
|
|
|
168
317
|
|
|
169
318
|
### Returns
|
|
170
319
|
|
|
171
|
-
`
|
|
320
|
+
[`BrandedHex`](#../type-aliases/BrandedHex) \| `undefined`
|
|
172
321
|
|
|
173
322
|
## Call Signature
|
|
174
323
|
|
|
175
324
|
```ts
|
|
176
|
-
function asHex(value, assert):
|
|
325
|
+
function asHex(value, assert): BrandedHex;
|
|
177
326
|
```
|
|
178
327
|
|
|
179
328
|
### Parameters
|
|
@@ -188,7 +337,7 @@ function asHex(value, assert): Lowercase<string>;
|
|
|
188
337
|
|
|
189
338
|
### Returns
|
|
190
339
|
|
|
191
|
-
`
|
|
340
|
+
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
192
341
|
|
|
193
342
|
### <a id="bitsToNibbles"></a>bitsToNibbles
|
|
194
343
|
|
|
@@ -217,7 +366,7 @@ function bitsToNibbles(value): number;
|
|
|
217
366
|
***
|
|
218
367
|
|
|
219
368
|
```ts
|
|
220
|
-
function hexFrom(value, config?):
|
|
369
|
+
function hexFrom(value, config?): BrandedHex;
|
|
221
370
|
```
|
|
222
371
|
|
|
223
372
|
Takes unknown value and tries our best to convert it to a hex string
|
|
@@ -238,7 +387,7 @@ Configuration of output format and validation
|
|
|
238
387
|
|
|
239
388
|
## Returns
|
|
240
389
|
|
|
241
|
-
`
|
|
390
|
+
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
242
391
|
|
|
243
392
|
### <a id="hexFromArrayBuffer"></a>hexFromArrayBuffer
|
|
244
393
|
|
|
@@ -247,7 +396,7 @@ Configuration of output format and validation
|
|
|
247
396
|
***
|
|
248
397
|
|
|
249
398
|
```ts
|
|
250
|
-
function hexFromArrayBuffer(buffer, config?):
|
|
399
|
+
function hexFromArrayBuffer(buffer, config?): BrandedHex;
|
|
251
400
|
```
|
|
252
401
|
|
|
253
402
|
Convert an ArrayBuffer to a hex string
|
|
@@ -268,7 +417,7 @@ Configuration of output format and validation
|
|
|
268
417
|
|
|
269
418
|
## Returns
|
|
270
419
|
|
|
271
|
-
`
|
|
420
|
+
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
272
421
|
|
|
273
422
|
### <a id="hexFromBigInt"></a>hexFromBigInt
|
|
274
423
|
|
|
@@ -277,7 +426,7 @@ Configuration of output format and validation
|
|
|
277
426
|
***
|
|
278
427
|
|
|
279
428
|
```ts
|
|
280
|
-
function hexFromBigInt(value, config):
|
|
429
|
+
function hexFromBigInt(value, config?): BrandedHex;
|
|
281
430
|
```
|
|
282
431
|
|
|
283
432
|
Convert a bigint to a hex string
|
|
@@ -290,7 +439,7 @@ Convert a bigint to a hex string
|
|
|
290
439
|
|
|
291
440
|
The bigint to be converted
|
|
292
441
|
|
|
293
|
-
### config
|
|
442
|
+
### config?
|
|
294
443
|
|
|
295
444
|
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
296
445
|
|
|
@@ -298,7 +447,7 @@ Configuration of output format and validation
|
|
|
298
447
|
|
|
299
448
|
## Returns
|
|
300
449
|
|
|
301
|
-
`
|
|
450
|
+
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
302
451
|
|
|
303
452
|
### <a id="hexFromHexString"></a>hexFromHexString
|
|
304
453
|
|
|
@@ -307,7 +456,7 @@ Configuration of output format and validation
|
|
|
307
456
|
***
|
|
308
457
|
|
|
309
458
|
```ts
|
|
310
|
-
function hexFromHexString(value, config):
|
|
459
|
+
function hexFromHexString(value, config?): BrandedHex;
|
|
311
460
|
```
|
|
312
461
|
|
|
313
462
|
## Parameters
|
|
@@ -316,13 +465,13 @@ function hexFromHexString(value, config): Lowercase<string>;
|
|
|
316
465
|
|
|
317
466
|
`string`
|
|
318
467
|
|
|
319
|
-
### config
|
|
468
|
+
### config?
|
|
320
469
|
|
|
321
470
|
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
322
471
|
|
|
323
472
|
## Returns
|
|
324
473
|
|
|
325
|
-
`
|
|
474
|
+
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
326
475
|
|
|
327
476
|
### <a id="hexFromNumber"></a>hexFromNumber
|
|
328
477
|
|
|
@@ -331,7 +480,7 @@ function hexFromHexString(value, config): Lowercase<string>;
|
|
|
331
480
|
***
|
|
332
481
|
|
|
333
482
|
```ts
|
|
334
|
-
function hexFromNumber(value, config?):
|
|
483
|
+
function hexFromNumber(value, config?): BrandedHex;
|
|
335
484
|
```
|
|
336
485
|
|
|
337
486
|
## Parameters
|
|
@@ -346,7 +495,7 @@ function hexFromNumber(value, config?): Lowercase<string>;
|
|
|
346
495
|
|
|
347
496
|
## Returns
|
|
348
497
|
|
|
349
|
-
`
|
|
498
|
+
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
350
499
|
|
|
351
500
|
### <a id="hexToBigInt"></a>hexToBigInt
|
|
352
501
|
|
|
@@ -362,7 +511,7 @@ function hexToBigInt(hex): bigint;
|
|
|
362
511
|
|
|
363
512
|
### hex
|
|
364
513
|
|
|
365
|
-
`
|
|
514
|
+
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
366
515
|
|
|
367
516
|
## Returns
|
|
368
517
|
|
|
@@ -375,7 +524,7 @@ function hexToBigInt(hex): bigint;
|
|
|
375
524
|
***
|
|
376
525
|
|
|
377
526
|
```ts
|
|
378
|
-
function isAddress(value, config): value is
|
|
527
|
+
function isAddress(value, config?): value is BrandedAddress;
|
|
379
528
|
```
|
|
380
529
|
|
|
381
530
|
## Parameters
|
|
@@ -384,13 +533,59 @@ function isAddress(value, config): value is Lowercase<string>;
|
|
|
384
533
|
|
|
385
534
|
`unknown`
|
|
386
535
|
|
|
387
|
-
### config
|
|
536
|
+
### config?
|
|
388
537
|
|
|
389
538
|
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
390
539
|
|
|
391
540
|
## Returns
|
|
392
541
|
|
|
393
|
-
`value is
|
|
542
|
+
`value is BrandedAddress`
|
|
543
|
+
|
|
544
|
+
### <a id="isAddressV2"></a>isAddressV2
|
|
545
|
+
|
|
546
|
+
[**@xylabs/hex**](#../README)
|
|
547
|
+
|
|
548
|
+
***
|
|
549
|
+
|
|
550
|
+
```ts
|
|
551
|
+
function isAddressV2(value): value is BrandedAddress;
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
**`Alpha`**
|
|
555
|
+
|
|
556
|
+
## Parameters
|
|
557
|
+
|
|
558
|
+
### value
|
|
559
|
+
|
|
560
|
+
`unknown`
|
|
561
|
+
|
|
562
|
+
## Returns
|
|
563
|
+
|
|
564
|
+
`value is BrandedAddress`
|
|
565
|
+
|
|
566
|
+
### <a id="isEthAddress"></a>isEthAddress
|
|
567
|
+
|
|
568
|
+
[**@xylabs/hex**](#../README)
|
|
569
|
+
|
|
570
|
+
***
|
|
571
|
+
|
|
572
|
+
```ts
|
|
573
|
+
function isEthAddress(value, config?): value is EthAddress;
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
## Parameters
|
|
577
|
+
|
|
578
|
+
### value
|
|
579
|
+
|
|
580
|
+
`unknown`
|
|
581
|
+
|
|
582
|
+
### config?
|
|
583
|
+
|
|
584
|
+
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
585
|
+
|
|
586
|
+
## Returns
|
|
587
|
+
|
|
588
|
+
`value is EthAddress`
|
|
394
589
|
|
|
395
590
|
### <a id="isHash"></a>isHash
|
|
396
591
|
|
|
@@ -399,7 +594,7 @@ function isAddress(value, config): value is Lowercase<string>;
|
|
|
399
594
|
***
|
|
400
595
|
|
|
401
596
|
```ts
|
|
402
|
-
function isHash(value, bitLength): value is
|
|
597
|
+
function isHash(value, bitLength?): value is BrandedHash;
|
|
403
598
|
```
|
|
404
599
|
|
|
405
600
|
## Parameters
|
|
@@ -408,13 +603,13 @@ function isHash(value, bitLength): value is Lowercase<string>;
|
|
|
408
603
|
|
|
409
604
|
`unknown`
|
|
410
605
|
|
|
411
|
-
### bitLength
|
|
606
|
+
### bitLength?
|
|
412
607
|
|
|
413
608
|
[`HashBitLength`](#../type-aliases/HashBitLength) = `256`
|
|
414
609
|
|
|
415
610
|
## Returns
|
|
416
611
|
|
|
417
|
-
`value is
|
|
612
|
+
`value is BrandedHash`
|
|
418
613
|
|
|
419
614
|
### <a id="isHashBitLength"></a>isHashBitLength
|
|
420
615
|
|
|
@@ -443,7 +638,7 @@ function isHashBitLength(value): value is HashBitLength;
|
|
|
443
638
|
***
|
|
444
639
|
|
|
445
640
|
```ts
|
|
446
|
-
function isHex(value, config?): value is
|
|
641
|
+
function isHex(value, config?): value is BrandedHex;
|
|
447
642
|
```
|
|
448
643
|
|
|
449
644
|
## Parameters
|
|
@@ -458,7 +653,7 @@ function isHex(value, config?): value is Lowercase<string>;
|
|
|
458
653
|
|
|
459
654
|
## Returns
|
|
460
655
|
|
|
461
|
-
`value is
|
|
656
|
+
`value is BrandedHex`
|
|
462
657
|
|
|
463
658
|
### <a id="isHexZero"></a>isHexZero
|
|
464
659
|
|
|
@@ -467,7 +662,7 @@ function isHex(value, config?): value is Lowercase<string>;
|
|
|
467
662
|
***
|
|
468
663
|
|
|
469
664
|
```ts
|
|
470
|
-
function isHexZero(value?):
|
|
665
|
+
function isHexZero(value?): boolean | undefined;
|
|
471
666
|
```
|
|
472
667
|
|
|
473
668
|
## Parameters
|
|
@@ -478,7 +673,7 @@ function isHexZero(value?): undefined | boolean;
|
|
|
478
673
|
|
|
479
674
|
## Returns
|
|
480
675
|
|
|
481
|
-
`
|
|
676
|
+
`boolean` \| `undefined`
|
|
482
677
|
|
|
483
678
|
### <a id="nibblesToBits"></a>nibblesToBits
|
|
484
679
|
|
|
@@ -507,7 +702,57 @@ function nibblesToBits(value): number;
|
|
|
507
702
|
***
|
|
508
703
|
|
|
509
704
|
```ts
|
|
510
|
-
function toAddress(value, config):
|
|
705
|
+
function toAddress(value, config?): BrandedAddress;
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
## Parameters
|
|
709
|
+
|
|
710
|
+
### value
|
|
711
|
+
|
|
712
|
+
`string` | `number` | `bigint` | `ArrayBufferLike`
|
|
713
|
+
|
|
714
|
+
### config?
|
|
715
|
+
|
|
716
|
+
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
717
|
+
|
|
718
|
+
## Returns
|
|
719
|
+
|
|
720
|
+
`BrandedAddress`
|
|
721
|
+
|
|
722
|
+
### <a id="toAddressV2"></a>toAddressV2
|
|
723
|
+
|
|
724
|
+
[**@xylabs/hex**](#../README)
|
|
725
|
+
|
|
726
|
+
***
|
|
727
|
+
|
|
728
|
+
```ts
|
|
729
|
+
function toAddressV2(value, assert?): BrandedAddress | undefined;
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
**`Alpha`**
|
|
733
|
+
|
|
734
|
+
## Parameters
|
|
735
|
+
|
|
736
|
+
### value
|
|
737
|
+
|
|
738
|
+
`unknown`
|
|
739
|
+
|
|
740
|
+
### assert?
|
|
741
|
+
|
|
742
|
+
`boolean` = `false`
|
|
743
|
+
|
|
744
|
+
## Returns
|
|
745
|
+
|
|
746
|
+
`BrandedAddress` \| `undefined`
|
|
747
|
+
|
|
748
|
+
### <a id="toEthAddress"></a>toEthAddress
|
|
749
|
+
|
|
750
|
+
[**@xylabs/hex**](#../README)
|
|
751
|
+
|
|
752
|
+
***
|
|
753
|
+
|
|
754
|
+
```ts
|
|
755
|
+
function toEthAddress(value, config?): EthAddress;
|
|
511
756
|
```
|
|
512
757
|
|
|
513
758
|
## Parameters
|
|
@@ -516,13 +761,13 @@ function toAddress(value, config): Lowercase<string>;
|
|
|
516
761
|
|
|
517
762
|
`string` | `number` | `bigint` | `ArrayBufferLike`
|
|
518
763
|
|
|
519
|
-
### config
|
|
764
|
+
### config?
|
|
520
765
|
|
|
521
766
|
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
522
767
|
|
|
523
768
|
## Returns
|
|
524
769
|
|
|
525
|
-
`
|
|
770
|
+
[`EthAddress`](#../type-aliases/EthAddress)
|
|
526
771
|
|
|
527
772
|
### <a id="toHex"></a>toHex
|
|
528
773
|
|
|
@@ -531,7 +776,7 @@ function toAddress(value, config): Lowercase<string>;
|
|
|
531
776
|
***
|
|
532
777
|
|
|
533
778
|
```ts
|
|
534
|
-
function toHex(value, config):
|
|
779
|
+
function toHex(value, config?): BrandedHex;
|
|
535
780
|
```
|
|
536
781
|
|
|
537
782
|
takes any value and tries our best to convert it to a hex string
|
|
@@ -544,7 +789,7 @@ Supported types are string, number, bigint, and ArrayBuffer
|
|
|
544
789
|
|
|
545
790
|
`string` | `number` | `bigint` | `ArrayBufferLike`
|
|
546
791
|
|
|
547
|
-
### config
|
|
792
|
+
### config?
|
|
548
793
|
|
|
549
794
|
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
550
795
|
|
|
@@ -552,7 +797,7 @@ Configuration of output format and validation
|
|
|
552
797
|
|
|
553
798
|
## Returns
|
|
554
799
|
|
|
555
|
-
`
|
|
800
|
+
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
556
801
|
|
|
557
802
|
### <a id="toHexLegacy"></a>toHexLegacy
|
|
558
803
|
|
|
@@ -617,7 +862,63 @@ optional prefix: boolean;
|
|
|
617
862
|
***
|
|
618
863
|
|
|
619
864
|
```ts
|
|
620
|
-
type Address =
|
|
865
|
+
type Address = z.infer<typeof AddressZod>;
|
|
866
|
+
```
|
|
867
|
+
|
|
868
|
+
### <a id="AddressTransformZodType"></a>AddressTransformZodType
|
|
869
|
+
|
|
870
|
+
[**@xylabs/hex**](#../README)
|
|
871
|
+
|
|
872
|
+
***
|
|
873
|
+
|
|
874
|
+
```ts
|
|
875
|
+
type AddressTransformZodType = z.infer<typeof AddressTransformZod>;
|
|
876
|
+
```
|
|
877
|
+
|
|
878
|
+
### <a id="AddressValidationZodType"></a>AddressValidationZodType
|
|
879
|
+
|
|
880
|
+
[**@xylabs/hex**](#../README)
|
|
881
|
+
|
|
882
|
+
***
|
|
883
|
+
|
|
884
|
+
```ts
|
|
885
|
+
type AddressValidationZodType = z.infer<typeof AddressValidationZod>;
|
|
886
|
+
```
|
|
887
|
+
|
|
888
|
+
### <a id="BrandedHash"></a>BrandedHash
|
|
889
|
+
|
|
890
|
+
[**@xylabs/hex**](#../README)
|
|
891
|
+
|
|
892
|
+
***
|
|
893
|
+
|
|
894
|
+
```ts
|
|
895
|
+
type BrandedHash = Brand<Hex, {
|
|
896
|
+
__hash: true;
|
|
897
|
+
}>;
|
|
898
|
+
```
|
|
899
|
+
|
|
900
|
+
### <a id="BrandedHex"></a>BrandedHex
|
|
901
|
+
|
|
902
|
+
[**@xylabs/hex**](#../README)
|
|
903
|
+
|
|
904
|
+
***
|
|
905
|
+
|
|
906
|
+
```ts
|
|
907
|
+
type BrandedHex = Brand<Lowercase<string>, {
|
|
908
|
+
__hex: true;
|
|
909
|
+
}>;
|
|
910
|
+
```
|
|
911
|
+
|
|
912
|
+
### <a id="EthAddress"></a>EthAddress
|
|
913
|
+
|
|
914
|
+
[**@xylabs/hex**](#../README)
|
|
915
|
+
|
|
916
|
+
***
|
|
917
|
+
|
|
918
|
+
```ts
|
|
919
|
+
type EthAddress = Brand<string, {
|
|
920
|
+
__eth_address: true;
|
|
921
|
+
}>;
|
|
621
922
|
```
|
|
622
923
|
|
|
623
924
|
### <a id="Hash"></a>Hash
|
|
@@ -627,7 +928,7 @@ type Address = Exclude<Hex, "reserved-address-value">;
|
|
|
627
928
|
***
|
|
628
929
|
|
|
629
930
|
```ts
|
|
630
|
-
type Hash =
|
|
931
|
+
type Hash = z.infer<typeof HashZod>;
|
|
631
932
|
```
|
|
632
933
|
|
|
633
934
|
### <a id="HashBitLength"></a>HashBitLength
|
|
@@ -647,11 +948,159 @@ type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
|
647
948
|
***
|
|
648
949
|
|
|
649
950
|
```ts
|
|
650
|
-
type Hex =
|
|
951
|
+
type Hex = z.infer<typeof HexZod>;
|
|
651
952
|
```
|
|
652
953
|
|
|
653
954
|
### variables
|
|
654
955
|
|
|
956
|
+
### <a id="ADDRESS_LENGTH"></a>ADDRESS_LENGTH
|
|
957
|
+
|
|
958
|
+
[**@xylabs/hex**](#../README)
|
|
959
|
+
|
|
960
|
+
***
|
|
961
|
+
|
|
962
|
+
```ts
|
|
963
|
+
const ADDRESS_LENGTH: 40;
|
|
964
|
+
```
|
|
965
|
+
|
|
966
|
+
### <a id="AddressRegEx"></a>AddressRegEx
|
|
967
|
+
|
|
968
|
+
[**@xylabs/hex**](#../README)
|
|
969
|
+
|
|
970
|
+
***
|
|
971
|
+
|
|
972
|
+
```ts
|
|
973
|
+
const AddressRegEx: RegExp;
|
|
974
|
+
```
|
|
975
|
+
|
|
976
|
+
### <a id="AddressTransformZod"></a>AddressTransformZod
|
|
977
|
+
|
|
978
|
+
[**@xylabs/hex**](#../README)
|
|
979
|
+
|
|
980
|
+
***
|
|
981
|
+
|
|
982
|
+
```ts
|
|
983
|
+
const AddressTransformZod: ZodPipe<ZodPipe<ZodUnion<readonly [ZodString, ZodBigInt, ZodNumber]>, ZodTransform<string, string | number | bigint>>, ZodTransform<BrandedAddress, string>>;
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
### <a id="AddressValidationZod"></a>AddressValidationZod
|
|
987
|
+
|
|
988
|
+
[**@xylabs/hex**](#../README)
|
|
989
|
+
|
|
990
|
+
***
|
|
991
|
+
|
|
992
|
+
```ts
|
|
993
|
+
const AddressValidationZod: ZodPipe<ZodString, ZodTransform<BrandedAddress, string>>;
|
|
994
|
+
```
|
|
995
|
+
|
|
996
|
+
### <a id="AddressZod"></a>AddressZod
|
|
997
|
+
|
|
998
|
+
[**@xylabs/hex**](#../README)
|
|
999
|
+
|
|
1000
|
+
***
|
|
1001
|
+
|
|
1002
|
+
```ts
|
|
1003
|
+
const AddressZod: ZodPipe<ZodString, ZodTransform<BrandedAddress, string>>;
|
|
1004
|
+
```
|
|
1005
|
+
|
|
1006
|
+
### <a id="BigIntToJsonZod"></a>BigIntToJsonZod
|
|
1007
|
+
|
|
1008
|
+
[**@xylabs/hex**](#../README)
|
|
1009
|
+
|
|
1010
|
+
***
|
|
1011
|
+
|
|
1012
|
+
```ts
|
|
1013
|
+
const BigIntToJsonZod: ZodPipe<ZodBigInt, ZodTransform<BrandedHex, bigint>>;
|
|
1014
|
+
```
|
|
1015
|
+
|
|
1016
|
+
### <a id="ETH_ZERO_ADDRESS"></a>ETH_ZERO_ADDRESS
|
|
1017
|
+
|
|
1018
|
+
[**@xylabs/hex**](#../README)
|
|
1019
|
+
|
|
1020
|
+
***
|
|
1021
|
+
|
|
1022
|
+
```ts
|
|
1023
|
+
const ETH_ZERO_ADDRESS: EthAddress;
|
|
1024
|
+
```
|
|
1025
|
+
|
|
1026
|
+
### <a id="EthAddressFromStringSchema"></a>EthAddressFromStringSchema
|
|
1027
|
+
|
|
1028
|
+
[**@xylabs/hex**](#../README)
|
|
1029
|
+
|
|
1030
|
+
***
|
|
1031
|
+
|
|
1032
|
+
```ts
|
|
1033
|
+
const EthAddressFromStringSchema: ZodPipe<ZodString, ZodTransform<EthAddress, string>> = EthAddressFromStringZod;
|
|
1034
|
+
```
|
|
1035
|
+
|
|
1036
|
+
## Deprecated
|
|
1037
|
+
|
|
1038
|
+
use EthAddressFromStringZod
|
|
1039
|
+
|
|
1040
|
+
### <a id="EthAddressFromStringZod"></a>EthAddressFromStringZod
|
|
1041
|
+
|
|
1042
|
+
[**@xylabs/hex**](#../README)
|
|
1043
|
+
|
|
1044
|
+
***
|
|
1045
|
+
|
|
1046
|
+
```ts
|
|
1047
|
+
const EthAddressFromStringZod: ZodPipe<ZodString, ZodTransform<EthAddress, string>>;
|
|
1048
|
+
```
|
|
1049
|
+
|
|
1050
|
+
### <a id="EthAddressRegEx"></a>EthAddressRegEx
|
|
1051
|
+
|
|
1052
|
+
[**@xylabs/hex**](#../README)
|
|
1053
|
+
|
|
1054
|
+
***
|
|
1055
|
+
|
|
1056
|
+
```ts
|
|
1057
|
+
const EthAddressRegEx: RegExp;
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
### <a id="EthAddressToStringSchema"></a>EthAddressToStringSchema
|
|
1061
|
+
|
|
1062
|
+
[**@xylabs/hex**](#../README)
|
|
1063
|
+
|
|
1064
|
+
***
|
|
1065
|
+
|
|
1066
|
+
```ts
|
|
1067
|
+
const EthAddressToStringSchema: ZodString = EthAddressToStringZod;
|
|
1068
|
+
```
|
|
1069
|
+
|
|
1070
|
+
## Deprecated
|
|
1071
|
+
|
|
1072
|
+
use EthAddressToStringZod
|
|
1073
|
+
|
|
1074
|
+
### <a id="EthAddressToStringZod"></a>EthAddressToStringZod
|
|
1075
|
+
|
|
1076
|
+
[**@xylabs/hex**](#../README)
|
|
1077
|
+
|
|
1078
|
+
***
|
|
1079
|
+
|
|
1080
|
+
```ts
|
|
1081
|
+
const EthAddressToStringZod: ZodString;
|
|
1082
|
+
```
|
|
1083
|
+
|
|
1084
|
+
### <a id="EthAddressZod"></a>EthAddressZod
|
|
1085
|
+
|
|
1086
|
+
[**@xylabs/hex**](#../README)
|
|
1087
|
+
|
|
1088
|
+
***
|
|
1089
|
+
|
|
1090
|
+
```ts
|
|
1091
|
+
const EthAddressZod: ZodString & ZodType<EthAddress, string, $ZodTypeInternals<EthAddress, string>>;
|
|
1092
|
+
```
|
|
1093
|
+
|
|
1094
|
+
### <a id="HASH_LENGTH"></a>HASH_LENGTH
|
|
1095
|
+
|
|
1096
|
+
[**@xylabs/hex**](#../README)
|
|
1097
|
+
|
|
1098
|
+
***
|
|
1099
|
+
|
|
1100
|
+
```ts
|
|
1101
|
+
const HASH_LENGTH: 32;
|
|
1102
|
+
```
|
|
1103
|
+
|
|
655
1104
|
### <a id="HashBitLength"></a>HashBitLength
|
|
656
1105
|
|
|
657
1106
|
[**@xylabs/hex**](#../README)
|
|
@@ -662,44 +1111,104 @@ type Hex = Exclude<Lowercase<string>, "reserved-hex-value">;
|
|
|
662
1111
|
HashBitLength: HashBitLength[];
|
|
663
1112
|
```
|
|
664
1113
|
|
|
665
|
-
### <a id="
|
|
1114
|
+
### <a id="HashRegEx"></a>HashRegEx
|
|
666
1115
|
|
|
667
1116
|
[**@xylabs/hex**](#../README)
|
|
668
1117
|
|
|
669
1118
|
***
|
|
670
1119
|
|
|
671
1120
|
```ts
|
|
672
|
-
const
|
|
1121
|
+
const HashRegEx: RegExp;
|
|
673
1122
|
```
|
|
674
1123
|
|
|
675
|
-
### <a id="
|
|
1124
|
+
### <a id="HashToJsonZod"></a>HashToJsonZod
|
|
676
1125
|
|
|
677
1126
|
[**@xylabs/hex**](#../README)
|
|
678
1127
|
|
|
679
1128
|
***
|
|
680
1129
|
|
|
681
1130
|
```ts
|
|
682
|
-
const
|
|
1131
|
+
const HashToJsonZod: ZodPipe<ZodPipe<ZodString, ZodTransform<BrandedHash, string>>, ZodTransform<string, BrandedHash>>;
|
|
683
1132
|
```
|
|
684
1133
|
|
|
685
|
-
### <a id="
|
|
1134
|
+
### <a id="HashZod"></a>HashZod
|
|
686
1135
|
|
|
687
1136
|
[**@xylabs/hex**](#../README)
|
|
688
1137
|
|
|
689
1138
|
***
|
|
690
1139
|
|
|
691
1140
|
```ts
|
|
692
|
-
const
|
|
1141
|
+
const HashZod: ZodPipe<ZodString, ZodTransform<BrandedHash, string>>;
|
|
693
1142
|
```
|
|
694
1143
|
|
|
695
|
-
### <a id="
|
|
1144
|
+
### <a id="HexRegEx"></a>HexRegEx
|
|
1145
|
+
|
|
1146
|
+
[**@xylabs/hex**](#../README)
|
|
1147
|
+
|
|
1148
|
+
***
|
|
1149
|
+
|
|
1150
|
+
```ts
|
|
1151
|
+
const HexRegEx: RegExp;
|
|
1152
|
+
```
|
|
1153
|
+
|
|
1154
|
+
### <a id="HexRegExWithPrefix"></a>HexRegExWithPrefix
|
|
1155
|
+
|
|
1156
|
+
[**@xylabs/hex**](#../README)
|
|
1157
|
+
|
|
1158
|
+
***
|
|
1159
|
+
|
|
1160
|
+
```ts
|
|
1161
|
+
const HexRegExWithPrefix: RegExp;
|
|
1162
|
+
```
|
|
1163
|
+
|
|
1164
|
+
### <a id="HexZod"></a>HexZod
|
|
1165
|
+
|
|
1166
|
+
[**@xylabs/hex**](#../README)
|
|
1167
|
+
|
|
1168
|
+
***
|
|
1169
|
+
|
|
1170
|
+
```ts
|
|
1171
|
+
const HexZod: ZodPipe<ZodString, ZodTransform<BrandedHex, string>>;
|
|
1172
|
+
```
|
|
1173
|
+
|
|
1174
|
+
### <a id="JsonToBigIntZod"></a>JsonToBigIntZod
|
|
1175
|
+
|
|
1176
|
+
[**@xylabs/hex**](#../README)
|
|
1177
|
+
|
|
1178
|
+
***
|
|
1179
|
+
|
|
1180
|
+
```ts
|
|
1181
|
+
const JsonToBigIntZod: ZodPipe<ZodPipe<ZodString, ZodTransform<BrandedHex, string>>, ZodTransform<bigint, BrandedHex>>;
|
|
1182
|
+
```
|
|
1183
|
+
|
|
1184
|
+
### <a id="JsonToHashZod"></a>JsonToHashZod
|
|
1185
|
+
|
|
1186
|
+
[**@xylabs/hex**](#../README)
|
|
1187
|
+
|
|
1188
|
+
***
|
|
1189
|
+
|
|
1190
|
+
```ts
|
|
1191
|
+
const JsonToHashZod: ZodPipe<ZodString, ZodTransform<BrandedHash, string>>;
|
|
1192
|
+
```
|
|
1193
|
+
|
|
1194
|
+
### <a id="ZERO_ADDRESS"></a>ZERO_ADDRESS
|
|
1195
|
+
|
|
1196
|
+
[**@xylabs/hex**](#../README)
|
|
1197
|
+
|
|
1198
|
+
***
|
|
1199
|
+
|
|
1200
|
+
```ts
|
|
1201
|
+
const ZERO_ADDRESS: BrandedAddress;
|
|
1202
|
+
```
|
|
1203
|
+
|
|
1204
|
+
### <a id="ZERO_HASH"></a>ZERO_HASH
|
|
696
1205
|
|
|
697
1206
|
[**@xylabs/hex**](#../README)
|
|
698
1207
|
|
|
699
1208
|
***
|
|
700
1209
|
|
|
701
1210
|
```ts
|
|
702
|
-
const
|
|
1211
|
+
const ZERO_HASH: BrandedHash;
|
|
703
1212
|
```
|
|
704
1213
|
|
|
705
1214
|
|