@xylabs/hex 5.0.83 → 5.0.86
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 +381 -303
- 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 +8 -2
- 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 +2 -2
- 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
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
17
17
|
|
|
18
|
+
|
|
19
|
+
|
|
18
20
|
## Reference
|
|
19
21
|
|
|
20
22
|
**@xylabs/hex**
|
|
@@ -23,77 +25,85 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
23
25
|
|
|
24
26
|
## Interfaces
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
| Interface | Description |
|
|
29
|
+
| ------ | ------ |
|
|
30
|
+
| [HexConfig](#interfaces/HexConfig) | Configuration of validation and output format |
|
|
27
31
|
|
|
28
32
|
## Type Aliases
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
| Type Alias | Description |
|
|
35
|
+
| ------ | ------ |
|
|
36
|
+
| [AddressTransformZodType](#type-aliases/AddressTransformZodType) | The output type of AddressTransformZod after parsing and transformation. |
|
|
37
|
+
| [AddressValidationZodType](#type-aliases/AddressValidationZodType) | The output type of AddressValidationZod after parsing. |
|
|
38
|
+
| [Address](#type-aliases/Address) | A validated 20-byte address string type, inferred from the AddressZod schema. |
|
|
39
|
+
| [EthAddress](#type-aliases/EthAddress) | Branded type representing a validated Ethereum address with 0x prefix. |
|
|
40
|
+
| [HashBitLength](#type-aliases/HashBitLength) | Valid bit lengths for hash values. |
|
|
41
|
+
| [BrandedHash](#type-aliases/BrandedHash) | Branded type representing a validated hash hex string. |
|
|
42
|
+
| [Hash](#type-aliases/Hash) | A validated hash string type, inferred from the HashZod schema. |
|
|
43
|
+
| [BrandedHex](#type-aliases/BrandedHex) | Branded type representing a validated lowercase hex string. |
|
|
44
|
+
| [Hex](#type-aliases/Hex) | A validated hex string type, inferred from the HexZod schema. |
|
|
39
45
|
|
|
40
46
|
## Variables
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
| Variable | Description |
|
|
49
|
+
| ------ | ------ |
|
|
50
|
+
| [HexRegEx](#variables/HexRegEx) | Regular expression matching a lowercase hex string without prefix. |
|
|
51
|
+
| [HexRegExWithPrefix](#variables/HexRegExWithPrefix) | Regular expression matching a lowercase hex string with a 0x prefix. |
|
|
52
|
+
| [AddressTransformZod](#variables/AddressTransformZod) | Zod schema that accepts a string, bigint, or number and transforms it into a validated Address. |
|
|
53
|
+
| [AddressValidationZod](#variables/AddressValidationZod) | Zod schema that validates a string is a properly formatted 40-character hex address. |
|
|
54
|
+
| [ZERO\_ADDRESS](#variables/ZERO_ADDRESS) | A 160-bit zero address constant. |
|
|
55
|
+
| [ADDRESS\_LENGTH](#variables/ADDRESS_LENGTH) | The character length of an address hex string (40 hex characters / 20 bytes). |
|
|
56
|
+
| [AddressRegEx](#variables/AddressRegEx) | Regular expression matching a 20-byte (40 hex character) address string. |
|
|
57
|
+
| [AddressZod](#variables/AddressZod) | Zod schema that validates and transforms a string into a branded Address type. |
|
|
58
|
+
| [EthAddressRegEx](#variables/EthAddressRegEx) | Regular expression matching a 20-byte Ethereum address with 0x prefix (mixed case). |
|
|
59
|
+
| [EthAddressToStringZod](#variables/EthAddressToStringZod) | Zod schema that validates a string is a properly formatted Ethereum address. |
|
|
60
|
+
| [~~EthAddressToStringSchema~~](#variables/EthAddressToStringSchema) | - |
|
|
61
|
+
| [EthAddressFromStringZod](#variables/EthAddressFromStringZod) | Zod schema that validates and transforms a string into an EthAddress type. |
|
|
62
|
+
| [~~EthAddressFromStringSchema~~](#variables/EthAddressFromStringSchema) | - |
|
|
63
|
+
| [ETH\_ZERO\_ADDRESS](#variables/ETH_ZERO_ADDRESS) | The zero Ethereum address constant (0x followed by 40 zero characters). |
|
|
64
|
+
| [EthAddressZod](#variables/EthAddressZod) | Zod schema that validates a string as a properly formatted Ethereum address using regex and type guard. |
|
|
65
|
+
| [HASH\_LENGTH](#variables/HASH_LENGTH) | The byte length of a standard hash (32 bytes / 256 bits). |
|
|
66
|
+
| [HashRegEx](#variables/HashRegEx) | Regular expression matching a 32-byte (64 hex character) hash string. |
|
|
67
|
+
| [ZERO\_HASH](#variables/ZERO_HASH) | A 256-bit zero hash constant. |
|
|
68
|
+
| [HashBitLength](#variables/HashBitLength) | Array of all valid hash bit lengths for runtime validation. |
|
|
69
|
+
| [HashZod](#variables/HashZod) | Zod schema that validates and transforms a string into a branded Hash type. |
|
|
70
|
+
| [HashToJsonZod](#variables/HashToJsonZod) | Zod schema that transforms a Hash to a plain string for JSON serialization. |
|
|
71
|
+
| [JsonToHashZod](#variables/JsonToHashZod) | Zod schema that parses a JSON string into a validated Hash, throwing on invalid input. |
|
|
72
|
+
| [HexZod](#variables/HexZod) | Zod schema that validates and transforms a string into a branded Hex type. |
|
|
73
|
+
| [BigIntToJsonZod](#variables/BigIntToJsonZod) | Zod schema that transforms a non-negative BigInt into a hex string for JSON serialization. |
|
|
74
|
+
| [JsonToBigIntZod](#variables/JsonToBigIntZod) | Zod schema that parses a JSON hex string into a BigInt. |
|
|
67
75
|
|
|
68
76
|
## Functions
|
|
69
77
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
78
|
+
| Function | Description |
|
|
79
|
+
| ------ | ------ |
|
|
80
|
+
| [HexRegExMinMax](#functions/HexRegExMinMax) | Creates a RegExp matching lowercase hex strings with a byte length in the given range. |
|
|
81
|
+
| [HexRegExMinMaxMixedCaseWithPrefix](#functions/HexRegExMinMaxMixedCaseWithPrefix) | Creates a RegExp matching mixed-case hex strings with a 0x prefix and a byte length in the given range. |
|
|
82
|
+
| [asAddress](#functions/asAddress) | Attempts to coerce a value into an Address type, returning undefined or throwing based on the assert config. |
|
|
83
|
+
| [asAddressV2](#functions/asAddressV2) | - |
|
|
84
|
+
| [isAddress](#functions/isAddress) | Type guard that checks whether a value is a valid 160-bit address. |
|
|
85
|
+
| [isAddressV2](#functions/isAddressV2) | - |
|
|
86
|
+
| [toAddress](#functions/toAddress) | Converts a value to a 160-bit Address hex string. |
|
|
87
|
+
| [toAddressV2](#functions/toAddressV2) | - |
|
|
88
|
+
| [toEthAddress](#functions/toEthAddress) | Converts a value to a 0x-prefixed Ethereum address string. |
|
|
89
|
+
| [isEthAddress](#functions/isEthAddress) | Type guard that checks whether a value is a valid 0x-prefixed Ethereum address. |
|
|
90
|
+
| [asEthAddress](#functions/asEthAddress) | Attempts to coerce a value into an EthAddress, returning undefined or throwing based on the assert config. |
|
|
91
|
+
| [asHash](#functions/asHash) | Attempts to coerce a value into a Hash type, returning undefined or throwing based on the assert config. |
|
|
92
|
+
| [isHashBitLength](#functions/isHashBitLength) | Type guard that checks whether a value is a valid hash bit length. |
|
|
93
|
+
| [isHash](#functions/isHash) | Type guard that checks whether a value is a valid hash of the specified bit length. |
|
|
94
|
+
| [asHex](#functions/asHex) | Attempts to coerce a value into a Hex type, returning undefined or throwing based on the assert config. |
|
|
95
|
+
| [hexFrom](#functions/hexFrom) | Takes unknown value and tries our best to convert it to a hex string |
|
|
96
|
+
| [hexFromArrayBuffer](#functions/hexFromArrayBuffer) | Convert an ArrayBuffer to a hex string |
|
|
97
|
+
| [hexFromBigInt](#functions/hexFromBigInt) | Convert a bigint to a hex string |
|
|
98
|
+
| [hexFromHexString](#functions/hexFromHexString) | Normalizes a hex string by stripping an optional 0x prefix, lowercasing, and padding to byte/bit boundaries. |
|
|
99
|
+
| [hexFromNumber](#functions/hexFromNumber) | Converts a number to a hex string by converting to BigInt first. |
|
|
100
|
+
| [isHex](#functions/isHex) | Type guard that checks whether a value is a valid hex string. |
|
|
101
|
+
| [isHexZero](#functions/isHexZero) | Checks whether a hex string represents a zero value. |
|
|
102
|
+
| [toHexLegacy](#functions/toHexLegacy) | Converts an ArrayBuffer to a hex string without padding or normalization. |
|
|
103
|
+
| [bitsToNibbles](#functions/bitsToNibbles) | Converts a bit count to the equivalent number of hex nibbles (4 bits each). |
|
|
104
|
+
| [nibblesToBits](#functions/nibblesToBits) | Converts a nibble count to the equivalent number of bits. |
|
|
105
|
+
| [toHex](#functions/toHex) | takes any value and tries our best to convert it to a hex string |
|
|
106
|
+
| [hexToBigInt](#functions/hexToBigInt) | Converts a Hex string to a BigInt. |
|
|
97
107
|
|
|
98
108
|
### functions
|
|
99
109
|
|
|
@@ -104,23 +114,24 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
104
114
|
***
|
|
105
115
|
|
|
106
116
|
```ts
|
|
107
|
-
function HexRegExMinMax(minBytes
|
|
117
|
+
function HexRegExMinMax(minBytes?: number, maxBytes?: number): RegExp;
|
|
108
118
|
```
|
|
109
119
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
### minBytes?
|
|
113
|
-
|
|
114
|
-
`number` = `0`
|
|
120
|
+
Creates a RegExp matching lowercase hex strings with a byte length in the given range.
|
|
115
121
|
|
|
116
|
-
|
|
122
|
+
## Parameters
|
|
117
123
|
|
|
118
|
-
|
|
124
|
+
| Parameter | Type | Default value | Description |
|
|
125
|
+
| ------ | ------ | ------ | ------ |
|
|
126
|
+
| `minBytes` | `number` | `0` | Minimum number of bytes (default 0) |
|
|
127
|
+
| `maxBytes` | `number` | `...` | Maximum number of bytes |
|
|
119
128
|
|
|
120
129
|
## Returns
|
|
121
130
|
|
|
122
131
|
`RegExp`
|
|
123
132
|
|
|
133
|
+
A RegExp for validating hex strings within the byte range
|
|
134
|
+
|
|
124
135
|
### <a id="HexRegExMinMaxMixedCaseWithPrefix"></a>HexRegExMinMaxMixedCaseWithPrefix
|
|
125
136
|
|
|
126
137
|
[**@xylabs/hex**](#../README)
|
|
@@ -128,23 +139,24 @@ function HexRegExMinMax(minBytes?, maxBytes?): RegExp;
|
|
|
128
139
|
***
|
|
129
140
|
|
|
130
141
|
```ts
|
|
131
|
-
function HexRegExMinMaxMixedCaseWithPrefix(minBytes
|
|
142
|
+
function HexRegExMinMaxMixedCaseWithPrefix(minBytes?: number, maxBytes?: number): RegExp;
|
|
132
143
|
```
|
|
133
144
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
### minBytes?
|
|
145
|
+
Creates a RegExp matching mixed-case hex strings with a 0x prefix and a byte length in the given range.
|
|
137
146
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
### maxBytes?
|
|
147
|
+
## Parameters
|
|
141
148
|
|
|
142
|
-
|
|
149
|
+
| Parameter | Type | Default value | Description |
|
|
150
|
+
| ------ | ------ | ------ | ------ |
|
|
151
|
+
| `minBytes` | `number` | `0` | Minimum number of bytes (default 0) |
|
|
152
|
+
| `maxBytes` | `number` | `...` | Maximum number of bytes |
|
|
143
153
|
|
|
144
154
|
## Returns
|
|
145
155
|
|
|
146
156
|
`RegExp`
|
|
147
157
|
|
|
158
|
+
A RegExp for validating prefixed hex strings within the byte range
|
|
159
|
+
|
|
148
160
|
### <a id="asAddress"></a>asAddress
|
|
149
161
|
|
|
150
162
|
[**@xylabs/hex**](#../README)
|
|
@@ -154,39 +166,44 @@ function HexRegExMinMaxMixedCaseWithPrefix(minBytes?, maxBytes?): RegExp;
|
|
|
154
166
|
## Call Signature
|
|
155
167
|
|
|
156
168
|
```ts
|
|
157
|
-
function asAddress(value): BrandedAddress | undefined;
|
|
169
|
+
function asAddress(value: unknown): BrandedAddress | undefined;
|
|
158
170
|
```
|
|
159
171
|
|
|
160
|
-
|
|
172
|
+
Attempts to coerce a value into an Address type, returning undefined or throwing based on the assert config.
|
|
161
173
|
|
|
162
|
-
###
|
|
174
|
+
### Parameters
|
|
163
175
|
|
|
164
|
-
|
|
176
|
+
| Parameter | Type | Description |
|
|
177
|
+
| ------ | ------ | ------ |
|
|
178
|
+
| `value` | `unknown` | The value to coerce (must be a string) |
|
|
165
179
|
|
|
166
180
|
### Returns
|
|
167
181
|
|
|
168
182
|
`BrandedAddress` \| `undefined`
|
|
169
183
|
|
|
184
|
+
The value as Address, or undefined if coercion fails and assert is not set
|
|
185
|
+
|
|
170
186
|
## Call Signature
|
|
171
187
|
|
|
172
188
|
```ts
|
|
173
|
-
function asAddress(value, assert): BrandedAddress;
|
|
189
|
+
function asAddress(value: unknown, assert: AssertConfig): BrandedAddress;
|
|
174
190
|
```
|
|
175
191
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
### value
|
|
179
|
-
|
|
180
|
-
`unknown`
|
|
192
|
+
Attempts to coerce a value into an Address type, returning undefined or throwing based on the assert config.
|
|
181
193
|
|
|
182
|
-
###
|
|
194
|
+
### Parameters
|
|
183
195
|
|
|
184
|
-
|
|
196
|
+
| Parameter | Type | Description |
|
|
197
|
+
| ------ | ------ | ------ |
|
|
198
|
+
| `value` | `unknown` | The value to coerce (must be a string) |
|
|
199
|
+
| `assert` | `AssertConfig` | If provided, throws on failure instead of returning undefined |
|
|
185
200
|
|
|
186
201
|
### Returns
|
|
187
202
|
|
|
188
203
|
`BrandedAddress`
|
|
189
204
|
|
|
205
|
+
The value as Address, or undefined if coercion fails and assert is not set
|
|
206
|
+
|
|
190
207
|
### <a id="asAddressV2"></a>asAddressV2
|
|
191
208
|
|
|
192
209
|
[**@xylabs/hex**](#../README)
|
|
@@ -194,20 +211,17 @@ function asAddress(value, assert): BrandedAddress;
|
|
|
194
211
|
***
|
|
195
212
|
|
|
196
213
|
```ts
|
|
197
|
-
function asAddressV2(value, assert
|
|
214
|
+
function asAddressV2(value: unknown, assert?: boolean): BrandedAddress | undefined;
|
|
198
215
|
```
|
|
199
216
|
|
|
200
217
|
**`Alpha`**
|
|
201
218
|
|
|
202
219
|
## Parameters
|
|
203
220
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
`unknown`
|
|
207
|
-
|
|
208
|
-
### assert?
|
|
209
|
-
|
|
210
|
-
`boolean` = `false`
|
|
221
|
+
| Parameter | Type | Default value |
|
|
222
|
+
| ------ | ------ | ------ |
|
|
223
|
+
| `value` | `unknown` | `undefined` |
|
|
224
|
+
| `assert` | `boolean` | `false` |
|
|
211
225
|
|
|
212
226
|
## Returns
|
|
213
227
|
|
|
@@ -222,39 +236,44 @@ function asAddressV2(value, assert?): BrandedAddress | undefined;
|
|
|
222
236
|
## Call Signature
|
|
223
237
|
|
|
224
238
|
```ts
|
|
225
|
-
function asEthAddress(value): EthAddress | undefined;
|
|
239
|
+
function asEthAddress(value: unknown): EthAddress | undefined;
|
|
226
240
|
```
|
|
227
241
|
|
|
228
|
-
|
|
242
|
+
Attempts to coerce a value into an EthAddress, returning undefined or throwing based on the assert config.
|
|
229
243
|
|
|
230
|
-
###
|
|
244
|
+
### Parameters
|
|
231
245
|
|
|
232
|
-
|
|
246
|
+
| Parameter | Type | Description |
|
|
247
|
+
| ------ | ------ | ------ |
|
|
248
|
+
| `value` | `unknown` | The value to coerce (must be a string) |
|
|
233
249
|
|
|
234
250
|
### Returns
|
|
235
251
|
|
|
236
252
|
[`EthAddress`](#../type-aliases/EthAddress) \| `undefined`
|
|
237
253
|
|
|
254
|
+
The value as EthAddress, or undefined if coercion fails and assert is not set
|
|
255
|
+
|
|
238
256
|
## Call Signature
|
|
239
257
|
|
|
240
258
|
```ts
|
|
241
|
-
function asEthAddress(value, assert): EthAddress;
|
|
259
|
+
function asEthAddress(value: unknown, assert: AssertConfig): EthAddress;
|
|
242
260
|
```
|
|
243
261
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
### value
|
|
247
|
-
|
|
248
|
-
`unknown`
|
|
262
|
+
Attempts to coerce a value into an EthAddress, returning undefined or throwing based on the assert config.
|
|
249
263
|
|
|
250
|
-
###
|
|
264
|
+
### Parameters
|
|
251
265
|
|
|
252
|
-
|
|
266
|
+
| Parameter | Type | Description |
|
|
267
|
+
| ------ | ------ | ------ |
|
|
268
|
+
| `value` | `unknown` | The value to coerce (must be a string) |
|
|
269
|
+
| `assert` | `AssertConfig` | If provided, throws on failure instead of returning undefined |
|
|
253
270
|
|
|
254
271
|
### Returns
|
|
255
272
|
|
|
256
273
|
[`EthAddress`](#../type-aliases/EthAddress)
|
|
257
274
|
|
|
275
|
+
The value as EthAddress, or undefined if coercion fails and assert is not set
|
|
276
|
+
|
|
258
277
|
### <a id="asHash"></a>asHash
|
|
259
278
|
|
|
260
279
|
[**@xylabs/hex**](#../README)
|
|
@@ -264,39 +283,44 @@ function asEthAddress(value, assert): EthAddress;
|
|
|
264
283
|
## Call Signature
|
|
265
284
|
|
|
266
285
|
```ts
|
|
267
|
-
function asHash(value): BrandedHash | undefined;
|
|
286
|
+
function asHash(value: unknown): BrandedHash | undefined;
|
|
268
287
|
```
|
|
269
288
|
|
|
270
|
-
|
|
289
|
+
Attempts to coerce a value into a Hash type, returning undefined or throwing based on the assert config.
|
|
271
290
|
|
|
272
|
-
###
|
|
291
|
+
### Parameters
|
|
273
292
|
|
|
274
|
-
|
|
293
|
+
| Parameter | Type | Description |
|
|
294
|
+
| ------ | ------ | ------ |
|
|
295
|
+
| `value` | `unknown` | The value to coerce (must be a string) |
|
|
275
296
|
|
|
276
297
|
### Returns
|
|
277
298
|
|
|
278
299
|
[`BrandedHash`](#../type-aliases/BrandedHash) \| `undefined`
|
|
279
300
|
|
|
301
|
+
The value as Hash, or undefined if coercion fails and assert is not set
|
|
302
|
+
|
|
280
303
|
## Call Signature
|
|
281
304
|
|
|
282
305
|
```ts
|
|
283
|
-
function asHash(value, assert): BrandedHash;
|
|
306
|
+
function asHash(value: unknown, assert: AssertConfig): BrandedHash;
|
|
284
307
|
```
|
|
285
308
|
|
|
286
|
-
|
|
309
|
+
Attempts to coerce a value into a Hash type, returning undefined or throwing based on the assert config.
|
|
287
310
|
|
|
288
|
-
###
|
|
289
|
-
|
|
290
|
-
`unknown`
|
|
291
|
-
|
|
292
|
-
### assert
|
|
311
|
+
### Parameters
|
|
293
312
|
|
|
294
|
-
|
|
313
|
+
| Parameter | Type | Description |
|
|
314
|
+
| ------ | ------ | ------ |
|
|
315
|
+
| `value` | `unknown` | The value to coerce (must be a string) |
|
|
316
|
+
| `assert` | `AssertConfig` | If provided, throws on failure instead of returning undefined |
|
|
295
317
|
|
|
296
318
|
### Returns
|
|
297
319
|
|
|
298
320
|
[`BrandedHash`](#../type-aliases/BrandedHash)
|
|
299
321
|
|
|
322
|
+
The value as Hash, or undefined if coercion fails and assert is not set
|
|
323
|
+
|
|
300
324
|
### <a id="asHex"></a>asHex
|
|
301
325
|
|
|
302
326
|
[**@xylabs/hex**](#../README)
|
|
@@ -306,39 +330,44 @@ function asHash(value, assert): BrandedHash;
|
|
|
306
330
|
## Call Signature
|
|
307
331
|
|
|
308
332
|
```ts
|
|
309
|
-
function asHex(value): BrandedHex | undefined;
|
|
333
|
+
function asHex(value: unknown): BrandedHex | undefined;
|
|
310
334
|
```
|
|
311
335
|
|
|
312
|
-
|
|
336
|
+
Attempts to coerce a value into a Hex type, returning undefined or throwing based on the assert config.
|
|
313
337
|
|
|
314
|
-
###
|
|
338
|
+
### Parameters
|
|
315
339
|
|
|
316
|
-
|
|
340
|
+
| Parameter | Type | Description |
|
|
341
|
+
| ------ | ------ | ------ |
|
|
342
|
+
| `value` | `unknown` | The value to coerce (must be a string) |
|
|
317
343
|
|
|
318
344
|
### Returns
|
|
319
345
|
|
|
320
346
|
[`BrandedHex`](#../type-aliases/BrandedHex) \| `undefined`
|
|
321
347
|
|
|
348
|
+
The value as Hex, or undefined if coercion fails and assert is not set
|
|
349
|
+
|
|
322
350
|
## Call Signature
|
|
323
351
|
|
|
324
352
|
```ts
|
|
325
|
-
function asHex(value, assert): BrandedHex;
|
|
353
|
+
function asHex(value: unknown, assert: AssertConfig): BrandedHex;
|
|
326
354
|
```
|
|
327
355
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
### value
|
|
356
|
+
Attempts to coerce a value into a Hex type, returning undefined or throwing based on the assert config.
|
|
331
357
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
### assert
|
|
358
|
+
### Parameters
|
|
335
359
|
|
|
336
|
-
|
|
360
|
+
| Parameter | Type | Description |
|
|
361
|
+
| ------ | ------ | ------ |
|
|
362
|
+
| `value` | `unknown` | The value to coerce (must be a string) |
|
|
363
|
+
| `assert` | `AssertConfig` | If provided, throws on failure instead of returning undefined |
|
|
337
364
|
|
|
338
365
|
### Returns
|
|
339
366
|
|
|
340
367
|
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
341
368
|
|
|
369
|
+
The value as Hex, or undefined if coercion fails and assert is not set
|
|
370
|
+
|
|
342
371
|
### <a id="bitsToNibbles"></a>bitsToNibbles
|
|
343
372
|
|
|
344
373
|
[**@xylabs/hex**](#../README)
|
|
@@ -346,19 +375,23 @@ function asHex(value, assert): BrandedHex;
|
|
|
346
375
|
***
|
|
347
376
|
|
|
348
377
|
```ts
|
|
349
|
-
function bitsToNibbles(value): number;
|
|
378
|
+
function bitsToNibbles(value: number): number;
|
|
350
379
|
```
|
|
351
380
|
|
|
352
|
-
|
|
381
|
+
Converts a bit count to the equivalent number of hex nibbles (4 bits each).
|
|
353
382
|
|
|
354
|
-
|
|
383
|
+
## Parameters
|
|
355
384
|
|
|
356
|
-
|
|
385
|
+
| Parameter | Type | Description |
|
|
386
|
+
| ------ | ------ | ------ |
|
|
387
|
+
| `value` | `number` | The number of bits (must be a multiple of 4) |
|
|
357
388
|
|
|
358
389
|
## Returns
|
|
359
390
|
|
|
360
391
|
`number`
|
|
361
392
|
|
|
393
|
+
The number of nibbles
|
|
394
|
+
|
|
362
395
|
### <a id="hexFrom"></a>hexFrom
|
|
363
396
|
|
|
364
397
|
[**@xylabs/hex**](#../README)
|
|
@@ -366,24 +399,17 @@ function bitsToNibbles(value): number;
|
|
|
366
399
|
***
|
|
367
400
|
|
|
368
401
|
```ts
|
|
369
|
-
function hexFrom(value, config
|
|
402
|
+
function hexFrom(value: string | number | bigint | ArrayBufferLike, config?: HexConfig): BrandedHex;
|
|
370
403
|
```
|
|
371
404
|
|
|
372
405
|
Takes unknown value and tries our best to convert it to a hex string
|
|
373
406
|
|
|
374
407
|
## Parameters
|
|
375
408
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
Supported types are string, number, bigint, and ArrayBuffer
|
|
379
|
-
|
|
380
|
-
`string` | `number` | `bigint` | `ArrayBufferLike`
|
|
381
|
-
|
|
382
|
-
### config?
|
|
383
|
-
|
|
384
|
-
[`HexConfig`](#../interfaces/HexConfig)
|
|
385
|
-
|
|
386
|
-
Configuration of output format and validation
|
|
409
|
+
| Parameter | Type | Description |
|
|
410
|
+
| ------ | ------ | ------ |
|
|
411
|
+
| `value` | `string` \| `number` \| `bigint` \| `ArrayBufferLike` | Supported types are string, number, bigint, and ArrayBuffer |
|
|
412
|
+
| `config?` | [`HexConfig`](#../interfaces/HexConfig) | Configuration of output format and validation |
|
|
387
413
|
|
|
388
414
|
## Returns
|
|
389
415
|
|
|
@@ -396,24 +422,17 @@ Configuration of output format and validation
|
|
|
396
422
|
***
|
|
397
423
|
|
|
398
424
|
```ts
|
|
399
|
-
function hexFromArrayBuffer(buffer, config
|
|
425
|
+
function hexFromArrayBuffer(buffer: ArrayBufferLike, config?: HexConfig): BrandedHex;
|
|
400
426
|
```
|
|
401
427
|
|
|
402
428
|
Convert an ArrayBuffer to a hex string
|
|
403
429
|
|
|
404
430
|
## Parameters
|
|
405
431
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
`ArrayBufferLike`
|
|
409
|
-
|
|
410
|
-
The buffer to be converted
|
|
411
|
-
|
|
412
|
-
### config?
|
|
413
|
-
|
|
414
|
-
[`HexConfig`](#../interfaces/HexConfig)
|
|
415
|
-
|
|
416
|
-
Configuration of output format and validation
|
|
432
|
+
| Parameter | Type | Description |
|
|
433
|
+
| ------ | ------ | ------ |
|
|
434
|
+
| `buffer` | `ArrayBufferLike` | The buffer to be converted |
|
|
435
|
+
| `config?` | [`HexConfig`](#../interfaces/HexConfig) | Configuration of output format and validation |
|
|
417
436
|
|
|
418
437
|
## Returns
|
|
419
438
|
|
|
@@ -426,24 +445,17 @@ Configuration of output format and validation
|
|
|
426
445
|
***
|
|
427
446
|
|
|
428
447
|
```ts
|
|
429
|
-
function hexFromBigInt(value, config
|
|
448
|
+
function hexFromBigInt(value: bigint, config?: HexConfig): BrandedHex;
|
|
430
449
|
```
|
|
431
450
|
|
|
432
451
|
Convert a bigint to a hex string
|
|
433
452
|
|
|
434
453
|
## Parameters
|
|
435
454
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
`bigint`
|
|
439
|
-
|
|
440
|
-
The bigint to be converted
|
|
441
|
-
|
|
442
|
-
### config?
|
|
443
|
-
|
|
444
|
-
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
445
|
-
|
|
446
|
-
Configuration of output format and validation
|
|
455
|
+
| Parameter | Type | Description |
|
|
456
|
+
| ------ | ------ | ------ |
|
|
457
|
+
| `value` | `bigint` | The bigint to be converted |
|
|
458
|
+
| `config` | [`HexConfig`](#../interfaces/HexConfig) | Configuration of output format and validation |
|
|
447
459
|
|
|
448
460
|
## Returns
|
|
449
461
|
|
|
@@ -456,23 +468,24 @@ Configuration of output format and validation
|
|
|
456
468
|
***
|
|
457
469
|
|
|
458
470
|
```ts
|
|
459
|
-
function hexFromHexString(value, config
|
|
471
|
+
function hexFromHexString(value: string, config?: HexConfig): BrandedHex;
|
|
460
472
|
```
|
|
461
473
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
### value
|
|
474
|
+
Normalizes a hex string by stripping an optional 0x prefix, lowercasing, and padding to byte/bit boundaries.
|
|
465
475
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
### config?
|
|
476
|
+
## Parameters
|
|
469
477
|
|
|
470
|
-
|
|
478
|
+
| Parameter | Type | Description |
|
|
479
|
+
| ------ | ------ | ------ |
|
|
480
|
+
| `value` | `string` | The hex string to normalize (with or without 0x prefix) |
|
|
481
|
+
| `config` | [`HexConfig`](#../interfaces/HexConfig) | Configuration for prefix, byteSize, and bitLength padding |
|
|
471
482
|
|
|
472
483
|
## Returns
|
|
473
484
|
|
|
474
485
|
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
475
486
|
|
|
487
|
+
The normalized Hex string
|
|
488
|
+
|
|
476
489
|
### <a id="hexFromNumber"></a>hexFromNumber
|
|
477
490
|
|
|
478
491
|
[**@xylabs/hex**](#../README)
|
|
@@ -480,23 +493,24 @@ function hexFromHexString(value, config?): BrandedHex;
|
|
|
480
493
|
***
|
|
481
494
|
|
|
482
495
|
```ts
|
|
483
|
-
function hexFromNumber(value, config
|
|
496
|
+
function hexFromNumber(value: number, config?: HexConfig): BrandedHex;
|
|
484
497
|
```
|
|
485
498
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
### value
|
|
499
|
+
Converts a number to a hex string by converting to BigInt first.
|
|
489
500
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
### config?
|
|
501
|
+
## Parameters
|
|
493
502
|
|
|
494
|
-
|
|
503
|
+
| Parameter | Type | Description |
|
|
504
|
+
| ------ | ------ | ------ |
|
|
505
|
+
| `value` | `number` | The number to convert |
|
|
506
|
+
| `config?` | [`HexConfig`](#../interfaces/HexConfig) | Optional hex output configuration |
|
|
495
507
|
|
|
496
508
|
## Returns
|
|
497
509
|
|
|
498
510
|
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
499
511
|
|
|
512
|
+
The hex string representation
|
|
513
|
+
|
|
500
514
|
### <a id="hexToBigInt"></a>hexToBigInt
|
|
501
515
|
|
|
502
516
|
[**@xylabs/hex**](#../README)
|
|
@@ -504,19 +518,23 @@ function hexFromNumber(value, config?): BrandedHex;
|
|
|
504
518
|
***
|
|
505
519
|
|
|
506
520
|
```ts
|
|
507
|
-
function hexToBigInt(hex): bigint;
|
|
521
|
+
function hexToBigInt(hex: BrandedHex): bigint;
|
|
508
522
|
```
|
|
509
523
|
|
|
524
|
+
Converts a Hex string to a BigInt.
|
|
525
|
+
|
|
510
526
|
## Parameters
|
|
511
527
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
[`BrandedHex`](#../type-aliases/BrandedHex)
|
|
528
|
+
| Parameter | Type | Description |
|
|
529
|
+
| ------ | ------ | ------ |
|
|
530
|
+
| `hex` | [`BrandedHex`](#../type-aliases/BrandedHex) | The hex string to convert |
|
|
515
531
|
|
|
516
532
|
## Returns
|
|
517
533
|
|
|
518
534
|
`bigint`
|
|
519
535
|
|
|
536
|
+
The BigInt representation of the hex value
|
|
537
|
+
|
|
520
538
|
### <a id="isAddress"></a>isAddress
|
|
521
539
|
|
|
522
540
|
[**@xylabs/hex**](#../README)
|
|
@@ -524,23 +542,24 @@ function hexToBigInt(hex): bigint;
|
|
|
524
542
|
***
|
|
525
543
|
|
|
526
544
|
```ts
|
|
527
|
-
function isAddress(value, config
|
|
545
|
+
function isAddress(value: unknown, config?: HexConfig): value is BrandedAddress;
|
|
528
546
|
```
|
|
529
547
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
### value
|
|
533
|
-
|
|
534
|
-
`unknown`
|
|
548
|
+
Type guard that checks whether a value is a valid 160-bit address.
|
|
535
549
|
|
|
536
|
-
|
|
550
|
+
## Parameters
|
|
537
551
|
|
|
538
|
-
|
|
552
|
+
| Parameter | Type | Description |
|
|
553
|
+
| ------ | ------ | ------ |
|
|
554
|
+
| `value` | `unknown` | The value to check |
|
|
555
|
+
| `config` | [`HexConfig`](#../interfaces/HexConfig) | Optional hex config (defaults to 160-bit, no prefix) |
|
|
539
556
|
|
|
540
557
|
## Returns
|
|
541
558
|
|
|
542
559
|
`value is BrandedAddress`
|
|
543
560
|
|
|
561
|
+
True if the value is a valid Address
|
|
562
|
+
|
|
544
563
|
### <a id="isAddressV2"></a>isAddressV2
|
|
545
564
|
|
|
546
565
|
[**@xylabs/hex**](#../README)
|
|
@@ -548,16 +567,16 @@ function isAddress(value, config?): value is BrandedAddress;
|
|
|
548
567
|
***
|
|
549
568
|
|
|
550
569
|
```ts
|
|
551
|
-
function isAddressV2(value): value is BrandedAddress;
|
|
570
|
+
function isAddressV2(value: unknown): value is BrandedAddress;
|
|
552
571
|
```
|
|
553
572
|
|
|
554
573
|
**`Alpha`**
|
|
555
574
|
|
|
556
575
|
## Parameters
|
|
557
576
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
`unknown`
|
|
577
|
+
| Parameter | Type |
|
|
578
|
+
| ------ | ------ |
|
|
579
|
+
| `value` | `unknown` |
|
|
561
580
|
|
|
562
581
|
## Returns
|
|
563
582
|
|
|
@@ -570,23 +589,24 @@ function isAddressV2(value): value is BrandedAddress;
|
|
|
570
589
|
***
|
|
571
590
|
|
|
572
591
|
```ts
|
|
573
|
-
function isEthAddress(value, config
|
|
592
|
+
function isEthAddress(value: unknown, config?: HexConfig): value is EthAddress;
|
|
574
593
|
```
|
|
575
594
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
### value
|
|
579
|
-
|
|
580
|
-
`unknown`
|
|
595
|
+
Type guard that checks whether a value is a valid 0x-prefixed Ethereum address.
|
|
581
596
|
|
|
582
|
-
|
|
597
|
+
## Parameters
|
|
583
598
|
|
|
584
|
-
|
|
599
|
+
| Parameter | Type | Description |
|
|
600
|
+
| ------ | ------ | ------ |
|
|
601
|
+
| `value` | `unknown` | The value to check |
|
|
602
|
+
| `config` | [`HexConfig`](#../interfaces/HexConfig) | Optional hex config (defaults to 160-bit with prefix) |
|
|
585
603
|
|
|
586
604
|
## Returns
|
|
587
605
|
|
|
588
606
|
`value is EthAddress`
|
|
589
607
|
|
|
608
|
+
True if the value is a valid EthAddress
|
|
609
|
+
|
|
590
610
|
### <a id="isHash"></a>isHash
|
|
591
611
|
|
|
592
612
|
[**@xylabs/hex**](#../README)
|
|
@@ -594,23 +614,24 @@ function isEthAddress(value, config?): value is EthAddress;
|
|
|
594
614
|
***
|
|
595
615
|
|
|
596
616
|
```ts
|
|
597
|
-
function isHash(value, bitLength
|
|
617
|
+
function isHash(value: unknown, bitLength?: HashBitLength): value is BrandedHash;
|
|
598
618
|
```
|
|
599
619
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
### value
|
|
603
|
-
|
|
604
|
-
`unknown`
|
|
620
|
+
Type guard that checks whether a value is a valid hash of the specified bit length.
|
|
605
621
|
|
|
606
|
-
|
|
622
|
+
## Parameters
|
|
607
623
|
|
|
608
|
-
|
|
624
|
+
| Parameter | Type | Default value | Description |
|
|
625
|
+
| ------ | ------ | ------ | ------ |
|
|
626
|
+
| `value` | `unknown` | `undefined` | The value to check |
|
|
627
|
+
| `bitLength` | [`HashBitLength`](#../type-aliases/HashBitLength) | `256` | The expected bit length of the hash (defaults to 256) |
|
|
609
628
|
|
|
610
629
|
## Returns
|
|
611
630
|
|
|
612
631
|
`value is BrandedHash`
|
|
613
632
|
|
|
633
|
+
True if the value is a valid Hash
|
|
634
|
+
|
|
614
635
|
### <a id="isHashBitLength"></a>isHashBitLength
|
|
615
636
|
|
|
616
637
|
[**@xylabs/hex**](#../README)
|
|
@@ -618,19 +639,23 @@ function isHash(value, bitLength?): value is BrandedHash;
|
|
|
618
639
|
***
|
|
619
640
|
|
|
620
641
|
```ts
|
|
621
|
-
function isHashBitLength(value): value is HashBitLength;
|
|
642
|
+
function isHashBitLength(value: unknown): value is HashBitLength;
|
|
622
643
|
```
|
|
623
644
|
|
|
624
|
-
|
|
645
|
+
Type guard that checks whether a value is a valid hash bit length.
|
|
625
646
|
|
|
626
|
-
|
|
647
|
+
## Parameters
|
|
627
648
|
|
|
628
|
-
|
|
649
|
+
| Parameter | Type | Description |
|
|
650
|
+
| ------ | ------ | ------ |
|
|
651
|
+
| `value` | `unknown` | The value to check |
|
|
629
652
|
|
|
630
653
|
## Returns
|
|
631
654
|
|
|
632
655
|
`value is HashBitLength`
|
|
633
656
|
|
|
657
|
+
True if the value is one of the supported HashBitLength values
|
|
658
|
+
|
|
634
659
|
### <a id="isHex"></a>isHex
|
|
635
660
|
|
|
636
661
|
[**@xylabs/hex**](#../README)
|
|
@@ -638,23 +663,24 @@ function isHashBitLength(value): value is HashBitLength;
|
|
|
638
663
|
***
|
|
639
664
|
|
|
640
665
|
```ts
|
|
641
|
-
function isHex(value, config
|
|
666
|
+
function isHex(value: unknown, config?: HexConfig): value is BrandedHex;
|
|
642
667
|
```
|
|
643
668
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
### value
|
|
669
|
+
Type guard that checks whether a value is a valid hex string.
|
|
647
670
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
### config?
|
|
671
|
+
## Parameters
|
|
651
672
|
|
|
652
|
-
|
|
673
|
+
| Parameter | Type | Description |
|
|
674
|
+
| ------ | ------ | ------ |
|
|
675
|
+
| `value` | `unknown` | The value to check |
|
|
676
|
+
| `config?` | [`HexConfig`](#../interfaces/HexConfig) | Optional configuration for prefix and bit length validation |
|
|
653
677
|
|
|
654
678
|
## Returns
|
|
655
679
|
|
|
656
680
|
`value is BrandedHex`
|
|
657
681
|
|
|
682
|
+
True if the value is a valid Hex string
|
|
683
|
+
|
|
658
684
|
### <a id="isHexZero"></a>isHexZero
|
|
659
685
|
|
|
660
686
|
[**@xylabs/hex**](#../README)
|
|
@@ -662,19 +688,23 @@ function isHex(value, config?): value is BrandedHex;
|
|
|
662
688
|
***
|
|
663
689
|
|
|
664
690
|
```ts
|
|
665
|
-
function isHexZero(value
|
|
691
|
+
function isHexZero(value?: string): boolean | undefined;
|
|
666
692
|
```
|
|
667
693
|
|
|
668
|
-
|
|
694
|
+
Checks whether a hex string represents a zero value.
|
|
669
695
|
|
|
670
|
-
|
|
696
|
+
## Parameters
|
|
671
697
|
|
|
672
|
-
|
|
698
|
+
| Parameter | Type | Description |
|
|
699
|
+
| ------ | ------ | ------ |
|
|
700
|
+
| `value?` | `string` | The hex string to check |
|
|
673
701
|
|
|
674
702
|
## Returns
|
|
675
703
|
|
|
676
704
|
`boolean` \| `undefined`
|
|
677
705
|
|
|
706
|
+
True if zero, false if non-zero, or undefined if the input is not a string
|
|
707
|
+
|
|
678
708
|
### <a id="nibblesToBits"></a>nibblesToBits
|
|
679
709
|
|
|
680
710
|
[**@xylabs/hex**](#../README)
|
|
@@ -682,19 +712,23 @@ function isHexZero(value?): boolean | undefined;
|
|
|
682
712
|
***
|
|
683
713
|
|
|
684
714
|
```ts
|
|
685
|
-
function nibblesToBits(value): number;
|
|
715
|
+
function nibblesToBits(value: number): number;
|
|
686
716
|
```
|
|
687
717
|
|
|
718
|
+
Converts a nibble count to the equivalent number of bits.
|
|
719
|
+
|
|
688
720
|
## Parameters
|
|
689
721
|
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
`number`
|
|
722
|
+
| Parameter | Type | Description |
|
|
723
|
+
| ------ | ------ | ------ |
|
|
724
|
+
| `value` | `number` | The number of nibbles |
|
|
693
725
|
|
|
694
726
|
## Returns
|
|
695
727
|
|
|
696
728
|
`number`
|
|
697
729
|
|
|
730
|
+
The number of bits
|
|
731
|
+
|
|
698
732
|
### <a id="toAddress"></a>toAddress
|
|
699
733
|
|
|
700
734
|
[**@xylabs/hex**](#../README)
|
|
@@ -702,23 +736,24 @@ function nibblesToBits(value): number;
|
|
|
702
736
|
***
|
|
703
737
|
|
|
704
738
|
```ts
|
|
705
|
-
function toAddress(value, config
|
|
739
|
+
function toAddress(value: string | number | bigint | ArrayBufferLike, config?: HexConfig): BrandedAddress;
|
|
706
740
|
```
|
|
707
741
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
### value
|
|
711
|
-
|
|
712
|
-
`string` | `number` | `bigint` | `ArrayBufferLike`
|
|
742
|
+
Converts a value to a 160-bit Address hex string.
|
|
713
743
|
|
|
714
|
-
|
|
744
|
+
## Parameters
|
|
715
745
|
|
|
716
|
-
|
|
746
|
+
| Parameter | Type | Description |
|
|
747
|
+
| ------ | ------ | ------ |
|
|
748
|
+
| `value` | `string` \| `number` \| `bigint` \| `ArrayBufferLike` | The value to convert (string, number, bigint, or ArrayBuffer) |
|
|
749
|
+
| `config` | [`HexConfig`](#../interfaces/HexConfig) | Optional hex config (defaults to 160-bit, no prefix) |
|
|
717
750
|
|
|
718
751
|
## Returns
|
|
719
752
|
|
|
720
753
|
`BrandedAddress`
|
|
721
754
|
|
|
755
|
+
The value as an Address
|
|
756
|
+
|
|
722
757
|
### <a id="toAddressV2"></a>toAddressV2
|
|
723
758
|
|
|
724
759
|
[**@xylabs/hex**](#../README)
|
|
@@ -726,20 +761,17 @@ function toAddress(value, config?): BrandedAddress;
|
|
|
726
761
|
***
|
|
727
762
|
|
|
728
763
|
```ts
|
|
729
|
-
function toAddressV2(value, assert
|
|
764
|
+
function toAddressV2(value: unknown, assert?: boolean): BrandedAddress | undefined;
|
|
730
765
|
```
|
|
731
766
|
|
|
732
767
|
**`Alpha`**
|
|
733
768
|
|
|
734
769
|
## Parameters
|
|
735
770
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
`unknown`
|
|
739
|
-
|
|
740
|
-
### assert?
|
|
741
|
-
|
|
742
|
-
`boolean` = `false`
|
|
771
|
+
| Parameter | Type | Default value |
|
|
772
|
+
| ------ | ------ | ------ |
|
|
773
|
+
| `value` | `unknown` | `undefined` |
|
|
774
|
+
| `assert` | `boolean` | `false` |
|
|
743
775
|
|
|
744
776
|
## Returns
|
|
745
777
|
|
|
@@ -752,23 +784,24 @@ function toAddressV2(value, assert?): BrandedAddress | undefined;
|
|
|
752
784
|
***
|
|
753
785
|
|
|
754
786
|
```ts
|
|
755
|
-
function toEthAddress(value, config
|
|
787
|
+
function toEthAddress(value: string | number | bigint | ArrayBufferLike, config?: HexConfig): EthAddress;
|
|
756
788
|
```
|
|
757
789
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
### value
|
|
761
|
-
|
|
762
|
-
`string` | `number` | `bigint` | `ArrayBufferLike`
|
|
790
|
+
Converts a value to a 0x-prefixed Ethereum address string.
|
|
763
791
|
|
|
764
|
-
|
|
792
|
+
## Parameters
|
|
765
793
|
|
|
766
|
-
|
|
794
|
+
| Parameter | Type | Description |
|
|
795
|
+
| ------ | ------ | ------ |
|
|
796
|
+
| `value` | `string` \| `number` \| `bigint` \| `ArrayBufferLike` | The value to convert (string, number, bigint, or ArrayBuffer) |
|
|
797
|
+
| `config` | [`HexConfig`](#../interfaces/HexConfig) | Optional hex config (defaults to 160-bit, no inner prefix) |
|
|
767
798
|
|
|
768
799
|
## Returns
|
|
769
800
|
|
|
770
801
|
[`EthAddress`](#../type-aliases/EthAddress)
|
|
771
802
|
|
|
803
|
+
The value as an EthAddress
|
|
804
|
+
|
|
772
805
|
### <a id="toHex"></a>toHex
|
|
773
806
|
|
|
774
807
|
[**@xylabs/hex**](#../README)
|
|
@@ -776,24 +809,17 @@ function toEthAddress(value, config?): EthAddress;
|
|
|
776
809
|
***
|
|
777
810
|
|
|
778
811
|
```ts
|
|
779
|
-
function toHex(value, config
|
|
812
|
+
function toHex(value: string | number | bigint | ArrayBufferLike, config?: HexConfig): BrandedHex;
|
|
780
813
|
```
|
|
781
814
|
|
|
782
815
|
takes any value and tries our best to convert it to a hex string
|
|
783
816
|
|
|
784
817
|
## Parameters
|
|
785
818
|
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
Supported types are string, number, bigint, and ArrayBuffer
|
|
789
|
-
|
|
790
|
-
`string` | `number` | `bigint` | `ArrayBufferLike`
|
|
791
|
-
|
|
792
|
-
### config?
|
|
793
|
-
|
|
794
|
-
[`HexConfig`](#../interfaces/HexConfig) = `{}`
|
|
795
|
-
|
|
796
|
-
Configuration of output format and validation
|
|
819
|
+
| Parameter | Type | Description |
|
|
820
|
+
| ------ | ------ | ------ |
|
|
821
|
+
| `value` | `string` \| `number` \| `bigint` \| `ArrayBufferLike` | Supported types are string, number, bigint, and ArrayBuffer |
|
|
822
|
+
| `config` | [`HexConfig`](#../interfaces/HexConfig) | Configuration of output format and validation |
|
|
797
823
|
|
|
798
824
|
## Returns
|
|
799
825
|
|
|
@@ -806,19 +832,23 @@ Configuration of output format and validation
|
|
|
806
832
|
***
|
|
807
833
|
|
|
808
834
|
```ts
|
|
809
|
-
function toHexLegacy(buffer): string;
|
|
835
|
+
function toHexLegacy(buffer: ArrayBuffer): string;
|
|
810
836
|
```
|
|
811
837
|
|
|
812
|
-
|
|
838
|
+
Converts an ArrayBuffer to a hex string without padding or normalization.
|
|
813
839
|
|
|
814
|
-
|
|
840
|
+
## Parameters
|
|
815
841
|
|
|
816
|
-
|
|
842
|
+
| Parameter | Type | Description |
|
|
843
|
+
| ------ | ------ | ------ |
|
|
844
|
+
| `buffer` | `ArrayBuffer` | The ArrayBuffer to convert |
|
|
817
845
|
|
|
818
846
|
## Returns
|
|
819
847
|
|
|
820
848
|
`string`
|
|
821
849
|
|
|
850
|
+
A lowercase hex string representation of the buffer
|
|
851
|
+
|
|
822
852
|
### interfaces
|
|
823
853
|
|
|
824
854
|
### <a id="HexConfig"></a>HexConfig
|
|
@@ -831,27 +861,11 @@ Configuration of validation and output format
|
|
|
831
861
|
|
|
832
862
|
## Properties
|
|
833
863
|
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
***
|
|
841
|
-
|
|
842
|
-
### byteSize?
|
|
843
|
-
|
|
844
|
-
```ts
|
|
845
|
-
optional byteSize: number;
|
|
846
|
-
```
|
|
847
|
-
|
|
848
|
-
***
|
|
849
|
-
|
|
850
|
-
### prefix?
|
|
851
|
-
|
|
852
|
-
```ts
|
|
853
|
-
optional prefix: boolean;
|
|
854
|
-
```
|
|
864
|
+
| Property | Type |
|
|
865
|
+
| ------ | ------ |
|
|
866
|
+
| <a id="bitlength"></a> `bitLength?` | `number` |
|
|
867
|
+
| <a id="bytesize"></a> `byteSize?` | `number` |
|
|
868
|
+
| <a id="prefix"></a> `prefix?` | `boolean` |
|
|
855
869
|
|
|
856
870
|
### type-aliases
|
|
857
871
|
|
|
@@ -865,6 +879,8 @@ optional prefix: boolean;
|
|
|
865
879
|
type Address = z.infer<typeof AddressZod>;
|
|
866
880
|
```
|
|
867
881
|
|
|
882
|
+
A validated 20-byte address string type, inferred from the AddressZod schema.
|
|
883
|
+
|
|
868
884
|
### <a id="AddressTransformZodType"></a>AddressTransformZodType
|
|
869
885
|
|
|
870
886
|
[**@xylabs/hex**](#../README)
|
|
@@ -875,6 +891,8 @@ type Address = z.infer<typeof AddressZod>;
|
|
|
875
891
|
type AddressTransformZodType = z.infer<typeof AddressTransformZod>;
|
|
876
892
|
```
|
|
877
893
|
|
|
894
|
+
The output type of AddressTransformZod after parsing and transformation.
|
|
895
|
+
|
|
878
896
|
### <a id="AddressValidationZodType"></a>AddressValidationZodType
|
|
879
897
|
|
|
880
898
|
[**@xylabs/hex**](#../README)
|
|
@@ -885,6 +903,8 @@ type AddressTransformZodType = z.infer<typeof AddressTransformZod>;
|
|
|
885
903
|
type AddressValidationZodType = z.infer<typeof AddressValidationZod>;
|
|
886
904
|
```
|
|
887
905
|
|
|
906
|
+
The output type of AddressValidationZod after parsing.
|
|
907
|
+
|
|
888
908
|
### <a id="BrandedHash"></a>BrandedHash
|
|
889
909
|
|
|
890
910
|
[**@xylabs/hex**](#../README)
|
|
@@ -897,6 +917,8 @@ type BrandedHash = Brand<Hex, {
|
|
|
897
917
|
}>;
|
|
898
918
|
```
|
|
899
919
|
|
|
920
|
+
Branded type representing a validated hash hex string.
|
|
921
|
+
|
|
900
922
|
### <a id="BrandedHex"></a>BrandedHex
|
|
901
923
|
|
|
902
924
|
[**@xylabs/hex**](#../README)
|
|
@@ -909,6 +931,8 @@ type BrandedHex = Brand<Lowercase<string>, {
|
|
|
909
931
|
}>;
|
|
910
932
|
```
|
|
911
933
|
|
|
934
|
+
Branded type representing a validated lowercase hex string.
|
|
935
|
+
|
|
912
936
|
### <a id="EthAddress"></a>EthAddress
|
|
913
937
|
|
|
914
938
|
[**@xylabs/hex**](#../README)
|
|
@@ -921,6 +945,8 @@ type EthAddress = Brand<string, {
|
|
|
921
945
|
}>;
|
|
922
946
|
```
|
|
923
947
|
|
|
948
|
+
Branded type representing a validated Ethereum address with 0x prefix.
|
|
949
|
+
|
|
924
950
|
### <a id="Hash"></a>Hash
|
|
925
951
|
|
|
926
952
|
[**@xylabs/hex**](#../README)
|
|
@@ -931,6 +957,8 @@ type EthAddress = Brand<string, {
|
|
|
931
957
|
type Hash = z.infer<typeof HashZod>;
|
|
932
958
|
```
|
|
933
959
|
|
|
960
|
+
A validated hash string type, inferred from the HashZod schema.
|
|
961
|
+
|
|
934
962
|
### <a id="HashBitLength"></a>HashBitLength
|
|
935
963
|
|
|
936
964
|
[**@xylabs/hex**](#../README)
|
|
@@ -941,6 +969,8 @@ type Hash = z.infer<typeof HashZod>;
|
|
|
941
969
|
type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
942
970
|
```
|
|
943
971
|
|
|
972
|
+
Valid bit lengths for hash values.
|
|
973
|
+
|
|
944
974
|
### <a id="Hex"></a>Hex
|
|
945
975
|
|
|
946
976
|
[**@xylabs/hex**](#../README)
|
|
@@ -951,6 +981,8 @@ type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
|
951
981
|
type Hex = z.infer<typeof HexZod>;
|
|
952
982
|
```
|
|
953
983
|
|
|
984
|
+
A validated hex string type, inferred from the HexZod schema.
|
|
985
|
+
|
|
954
986
|
### variables
|
|
955
987
|
|
|
956
988
|
### <a id="ADDRESS_LENGTH"></a>ADDRESS_LENGTH
|
|
@@ -963,6 +995,8 @@ type Hex = z.infer<typeof HexZod>;
|
|
|
963
995
|
const ADDRESS_LENGTH: 40;
|
|
964
996
|
```
|
|
965
997
|
|
|
998
|
+
The character length of an address hex string (40 hex characters / 20 bytes).
|
|
999
|
+
|
|
966
1000
|
### <a id="AddressRegEx"></a>AddressRegEx
|
|
967
1001
|
|
|
968
1002
|
[**@xylabs/hex**](#../README)
|
|
@@ -973,6 +1007,8 @@ const ADDRESS_LENGTH: 40;
|
|
|
973
1007
|
const AddressRegEx: RegExp;
|
|
974
1008
|
```
|
|
975
1009
|
|
|
1010
|
+
Regular expression matching a 20-byte (40 hex character) address string.
|
|
1011
|
+
|
|
976
1012
|
### <a id="AddressTransformZod"></a>AddressTransformZod
|
|
977
1013
|
|
|
978
1014
|
[**@xylabs/hex**](#../README)
|
|
@@ -983,6 +1019,8 @@ const AddressRegEx: RegExp;
|
|
|
983
1019
|
const AddressTransformZod: ZodPipe<ZodPipe<ZodUnion<readonly [ZodString, ZodBigInt, ZodNumber]>, ZodTransform<string, string | number | bigint>>, ZodTransform<BrandedAddress, string>>;
|
|
984
1020
|
```
|
|
985
1021
|
|
|
1022
|
+
Zod schema that accepts a string, bigint, or number and transforms it into a validated Address.
|
|
1023
|
+
|
|
986
1024
|
### <a id="AddressValidationZod"></a>AddressValidationZod
|
|
987
1025
|
|
|
988
1026
|
[**@xylabs/hex**](#../README)
|
|
@@ -993,6 +1031,8 @@ const AddressTransformZod: ZodPipe<ZodPipe<ZodUnion<readonly [ZodString, ZodBigI
|
|
|
993
1031
|
const AddressValidationZod: ZodPipe<ZodString, ZodTransform<BrandedAddress, string>>;
|
|
994
1032
|
```
|
|
995
1033
|
|
|
1034
|
+
Zod schema that validates a string is a properly formatted 40-character hex address.
|
|
1035
|
+
|
|
996
1036
|
### <a id="AddressZod"></a>AddressZod
|
|
997
1037
|
|
|
998
1038
|
[**@xylabs/hex**](#../README)
|
|
@@ -1003,6 +1043,8 @@ const AddressValidationZod: ZodPipe<ZodString, ZodTransform<BrandedAddress, stri
|
|
|
1003
1043
|
const AddressZod: ZodPipe<ZodString, ZodTransform<BrandedAddress, string>>;
|
|
1004
1044
|
```
|
|
1005
1045
|
|
|
1046
|
+
Zod schema that validates and transforms a string into a branded Address type.
|
|
1047
|
+
|
|
1006
1048
|
### <a id="BigIntToJsonZod"></a>BigIntToJsonZod
|
|
1007
1049
|
|
|
1008
1050
|
[**@xylabs/hex**](#../README)
|
|
@@ -1013,6 +1055,8 @@ const AddressZod: ZodPipe<ZodString, ZodTransform<BrandedAddress, string>>;
|
|
|
1013
1055
|
const BigIntToJsonZod: ZodPipe<ZodBigInt, ZodTransform<BrandedHex, bigint>>;
|
|
1014
1056
|
```
|
|
1015
1057
|
|
|
1058
|
+
Zod schema that transforms a non-negative BigInt into a hex string for JSON serialization.
|
|
1059
|
+
|
|
1016
1060
|
### <a id="ETH_ZERO_ADDRESS"></a>ETH_ZERO_ADDRESS
|
|
1017
1061
|
|
|
1018
1062
|
[**@xylabs/hex**](#../README)
|
|
@@ -1023,6 +1067,8 @@ const BigIntToJsonZod: ZodPipe<ZodBigInt, ZodTransform<BrandedHex, bigint>>;
|
|
|
1023
1067
|
const ETH_ZERO_ADDRESS: EthAddress;
|
|
1024
1068
|
```
|
|
1025
1069
|
|
|
1070
|
+
The zero Ethereum address constant (0x followed by 40 zero characters).
|
|
1071
|
+
|
|
1026
1072
|
### <a id="EthAddressFromStringSchema"></a>EthAddressFromStringSchema
|
|
1027
1073
|
|
|
1028
1074
|
[**@xylabs/hex**](#../README)
|
|
@@ -1047,6 +1093,8 @@ use EthAddressFromStringZod
|
|
|
1047
1093
|
const EthAddressFromStringZod: ZodPipe<ZodString, ZodTransform<EthAddress, string>>;
|
|
1048
1094
|
```
|
|
1049
1095
|
|
|
1096
|
+
Zod schema that validates and transforms a string into an EthAddress type.
|
|
1097
|
+
|
|
1050
1098
|
### <a id="EthAddressRegEx"></a>EthAddressRegEx
|
|
1051
1099
|
|
|
1052
1100
|
[**@xylabs/hex**](#../README)
|
|
@@ -1057,6 +1105,8 @@ const EthAddressFromStringZod: ZodPipe<ZodString, ZodTransform<EthAddress, strin
|
|
|
1057
1105
|
const EthAddressRegEx: RegExp;
|
|
1058
1106
|
```
|
|
1059
1107
|
|
|
1108
|
+
Regular expression matching a 20-byte Ethereum address with 0x prefix (mixed case).
|
|
1109
|
+
|
|
1060
1110
|
### <a id="EthAddressToStringSchema"></a>EthAddressToStringSchema
|
|
1061
1111
|
|
|
1062
1112
|
[**@xylabs/hex**](#../README)
|
|
@@ -1081,6 +1131,8 @@ use EthAddressToStringZod
|
|
|
1081
1131
|
const EthAddressToStringZod: ZodString;
|
|
1082
1132
|
```
|
|
1083
1133
|
|
|
1134
|
+
Zod schema that validates a string is a properly formatted Ethereum address.
|
|
1135
|
+
|
|
1084
1136
|
### <a id="EthAddressZod"></a>EthAddressZod
|
|
1085
1137
|
|
|
1086
1138
|
[**@xylabs/hex**](#../README)
|
|
@@ -1091,6 +1143,8 @@ const EthAddressToStringZod: ZodString;
|
|
|
1091
1143
|
const EthAddressZod: ZodString & ZodType<EthAddress, string, $ZodTypeInternals<EthAddress, string>>;
|
|
1092
1144
|
```
|
|
1093
1145
|
|
|
1146
|
+
Zod schema that validates a string as a properly formatted Ethereum address using regex and type guard.
|
|
1147
|
+
|
|
1094
1148
|
### <a id="HASH_LENGTH"></a>HASH_LENGTH
|
|
1095
1149
|
|
|
1096
1150
|
[**@xylabs/hex**](#../README)
|
|
@@ -1101,6 +1155,8 @@ const EthAddressZod: ZodString & ZodType<EthAddress, string, $ZodTypeInternals<E
|
|
|
1101
1155
|
const HASH_LENGTH: 32;
|
|
1102
1156
|
```
|
|
1103
1157
|
|
|
1158
|
+
The byte length of a standard hash (32 bytes / 256 bits).
|
|
1159
|
+
|
|
1104
1160
|
### <a id="HashBitLength"></a>HashBitLength
|
|
1105
1161
|
|
|
1106
1162
|
[**@xylabs/hex**](#../README)
|
|
@@ -1111,6 +1167,8 @@ const HASH_LENGTH: 32;
|
|
|
1111
1167
|
HashBitLength: HashBitLength[];
|
|
1112
1168
|
```
|
|
1113
1169
|
|
|
1170
|
+
Array of all valid hash bit lengths for runtime validation.
|
|
1171
|
+
|
|
1114
1172
|
### <a id="HashRegEx"></a>HashRegEx
|
|
1115
1173
|
|
|
1116
1174
|
[**@xylabs/hex**](#../README)
|
|
@@ -1121,6 +1179,8 @@ HashBitLength: HashBitLength[];
|
|
|
1121
1179
|
const HashRegEx: RegExp;
|
|
1122
1180
|
```
|
|
1123
1181
|
|
|
1182
|
+
Regular expression matching a 32-byte (64 hex character) hash string.
|
|
1183
|
+
|
|
1124
1184
|
### <a id="HashToJsonZod"></a>HashToJsonZod
|
|
1125
1185
|
|
|
1126
1186
|
[**@xylabs/hex**](#../README)
|
|
@@ -1131,6 +1191,8 @@ const HashRegEx: RegExp;
|
|
|
1131
1191
|
const HashToJsonZod: ZodPipe<ZodPipe<ZodString, ZodTransform<BrandedHash, string>>, ZodTransform<string, BrandedHash>>;
|
|
1132
1192
|
```
|
|
1133
1193
|
|
|
1194
|
+
Zod schema that transforms a Hash to a plain string for JSON serialization.
|
|
1195
|
+
|
|
1134
1196
|
### <a id="HashZod"></a>HashZod
|
|
1135
1197
|
|
|
1136
1198
|
[**@xylabs/hex**](#../README)
|
|
@@ -1141,6 +1203,8 @@ const HashToJsonZod: ZodPipe<ZodPipe<ZodString, ZodTransform<BrandedHash, string
|
|
|
1141
1203
|
const HashZod: ZodPipe<ZodString, ZodTransform<BrandedHash, string>>;
|
|
1142
1204
|
```
|
|
1143
1205
|
|
|
1206
|
+
Zod schema that validates and transforms a string into a branded Hash type.
|
|
1207
|
+
|
|
1144
1208
|
### <a id="HexRegEx"></a>HexRegEx
|
|
1145
1209
|
|
|
1146
1210
|
[**@xylabs/hex**](#../README)
|
|
@@ -1151,6 +1215,8 @@ const HashZod: ZodPipe<ZodString, ZodTransform<BrandedHash, string>>;
|
|
|
1151
1215
|
const HexRegEx: RegExp;
|
|
1152
1216
|
```
|
|
1153
1217
|
|
|
1218
|
+
Regular expression matching a lowercase hex string without prefix.
|
|
1219
|
+
|
|
1154
1220
|
### <a id="HexRegExWithPrefix"></a>HexRegExWithPrefix
|
|
1155
1221
|
|
|
1156
1222
|
[**@xylabs/hex**](#../README)
|
|
@@ -1161,6 +1227,8 @@ const HexRegEx: RegExp;
|
|
|
1161
1227
|
const HexRegExWithPrefix: RegExp;
|
|
1162
1228
|
```
|
|
1163
1229
|
|
|
1230
|
+
Regular expression matching a lowercase hex string with a 0x prefix.
|
|
1231
|
+
|
|
1164
1232
|
### <a id="HexZod"></a>HexZod
|
|
1165
1233
|
|
|
1166
1234
|
[**@xylabs/hex**](#../README)
|
|
@@ -1171,6 +1239,8 @@ const HexRegExWithPrefix: RegExp;
|
|
|
1171
1239
|
const HexZod: ZodPipe<ZodString, ZodTransform<BrandedHex, string>>;
|
|
1172
1240
|
```
|
|
1173
1241
|
|
|
1242
|
+
Zod schema that validates and transforms a string into a branded Hex type.
|
|
1243
|
+
|
|
1174
1244
|
### <a id="JsonToBigIntZod"></a>JsonToBigIntZod
|
|
1175
1245
|
|
|
1176
1246
|
[**@xylabs/hex**](#../README)
|
|
@@ -1181,6 +1251,8 @@ const HexZod: ZodPipe<ZodString, ZodTransform<BrandedHex, string>>;
|
|
|
1181
1251
|
const JsonToBigIntZod: ZodPipe<ZodPipe<ZodString, ZodTransform<BrandedHex, string>>, ZodTransform<bigint, BrandedHex>>;
|
|
1182
1252
|
```
|
|
1183
1253
|
|
|
1254
|
+
Zod schema that parses a JSON hex string into a BigInt.
|
|
1255
|
+
|
|
1184
1256
|
### <a id="JsonToHashZod"></a>JsonToHashZod
|
|
1185
1257
|
|
|
1186
1258
|
[**@xylabs/hex**](#../README)
|
|
@@ -1191,6 +1263,8 @@ const JsonToBigIntZod: ZodPipe<ZodPipe<ZodString, ZodTransform<BrandedHex, strin
|
|
|
1191
1263
|
const JsonToHashZod: ZodPipe<ZodString, ZodTransform<BrandedHash, string>>;
|
|
1192
1264
|
```
|
|
1193
1265
|
|
|
1266
|
+
Zod schema that parses a JSON string into a validated Hash, throwing on invalid input.
|
|
1267
|
+
|
|
1194
1268
|
### <a id="ZERO_ADDRESS"></a>ZERO_ADDRESS
|
|
1195
1269
|
|
|
1196
1270
|
[**@xylabs/hex**](#../README)
|
|
@@ -1201,6 +1275,8 @@ const JsonToHashZod: ZodPipe<ZodString, ZodTransform<BrandedHash, string>>;
|
|
|
1201
1275
|
const ZERO_ADDRESS: BrandedAddress;
|
|
1202
1276
|
```
|
|
1203
1277
|
|
|
1278
|
+
A 160-bit zero address constant.
|
|
1279
|
+
|
|
1204
1280
|
### <a id="ZERO_HASH"></a>ZERO_HASH
|
|
1205
1281
|
|
|
1206
1282
|
[**@xylabs/hex**](#../README)
|
|
@@ -1211,6 +1287,8 @@ const ZERO_ADDRESS: BrandedAddress;
|
|
|
1211
1287
|
const ZERO_HASH: BrandedHash;
|
|
1212
1288
|
```
|
|
1213
1289
|
|
|
1290
|
+
A 256-bit zero hash constant.
|
|
1291
|
+
|
|
1214
1292
|
|
|
1215
1293
|
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|
|
1216
1294
|
|