@@ -3,7 +3,7 @@ import { getRandomBytesSync } from 'ethereum-cryptography/random.js'
3
3
import { bytesToHex as _bytesToUnprefixedHex } from 'ethereum-cryptography/utils.js'
4
4
5
5
import { assertIsArray , assertIsBytes , assertIsHexString } from './helpers.js'
6
- import { isHexPrefixed , isHexString , padToEven , stripHexPrefix } from './internal.js'
6
+ import { isHexString , padToEven , stripHexPrefix } from './internal.js'
7
7
8
8
import type { PrefixedHexString , TransformabletoBytes } from './types.js'
9
9
@@ -107,13 +107,14 @@ export const bytesToInt = (bytes: Uint8Array): number => {
107
107
return res
108
108
}
109
109
110
+ // TODO: Restrict the input type to only PrefixedHexString
110
111
/**
111
112
* Converts a {@link PrefixedHexString} to a {@link Uint8Array}
112
- * @param {PrefixedHexString } hex The 0x-prefixed hex string to convert
113
+ * @param {PrefixedHexString | string } hex The 0x-prefixed hex string to convert
113
114
* @returns {Uint8Array } The converted bytes
114
115
* @throws If the input is not a valid 0x-prefixed hex string
115
116
*/
116
- export const hexToBytes = ( hex : PrefixedHexString ) : Uint8Array => {
117
+ export const hexToBytes = ( hex : PrefixedHexString | string ) : Uint8Array => {
117
118
if ( typeof hex !== 'string' ) {
118
119
throw new Error ( `hex argument type ${ typeof hex } must be of type string` )
119
120
}
@@ -256,12 +257,13 @@ export const unpadArray = (a: number[]): number[] => {
256
257
return stripZeros ( a )
257
258
}
258
259
260
+ // TODO: Restrict the input type to only PrefixedHexString
259
261
/**
260
262
* Trims leading zeros from a `PrefixedHexString`.
261
- * @param {PrefixedHexString } a
263
+ * @param {PrefixedHexString | string } a
262
264
* @return {PrefixedHexString }
263
265
*/
264
- export const unpadHex = ( a : PrefixedHexString ) : PrefixedHexString => {
266
+ export const unpadHex = ( a : PrefixedHexString | string ) : PrefixedHexString => {
265
267
assertIsHexString ( a )
266
268
return `0x${ stripZeros ( stripHexPrefix ( a ) ) } `
267
269
}
@@ -353,7 +355,7 @@ export const addHexPrefix = (str: string): PrefixedHexString => {
353
355
return str
354
356
}
355
357
356
- return isHexPrefixed ( str ) ? str : `0x${ str } `
358
+ return isHexString ( str ) ? str : `0x${ str } `
357
359
}
358
360
359
361
/**
@@ -540,6 +542,7 @@ export function bigInt64ToBytes(value: bigint, littleEndian: boolean = false): U
540
542
// eslint-disable-next-line no-restricted-imports
541
543
export { bytesToUtf8 , equalsBytes , utf8ToBytes } from 'ethereum-cryptography/utils.js'
542
544
543
- export function hexToBigInt ( input : PrefixedHexString ) : bigint {
544
- return bytesToBigInt ( hexToBytes ( input ) )
545
+ // TODO: Restrict the input type to only PrefixedHexString
546
+ export function hexToBigInt ( input : PrefixedHexString | string ) : bigint {
547
+ return bytesToBigInt ( hexToBytes ( isHexString ( input ) ? input : `0x${ input } ` ) )
545
548
}
0 commit comments