@@ -328,25 +328,20 @@ function toChecksumHexAddressUnmemoized(address: unknown) {
328328/**
329329 * Convert an address to a checksummed hexadecimal address.
330330 *
331- * @param address - The address to convert.
332- * @returns The address in 0x-prefixed hexadecimal checksummed form if it is valid.
331+ * @param address - The address to convert. For backward compatibility reasons,
332+ * this can be anything, even a non-hex string with an 0x prefix, but that usage
333+ * is deprecated. Please use a valid hex string (with or without the `0x`
334+ * prefix).
335+ * @returns A 0x-prefixed checksummed version of `address` if it is a valid hex
336+ * string, or the address as given otherwise.
333337 */
334338export const toChecksumHexAddress : {
335339 ( address : string ) : string ;
336340 < T > ( address : T ) : T ;
337341} = memoize ( toChecksumHexAddressUnmemoized ) ;
338342
339- /**
340- * Validates that the input is a hex address. This utility method is a thin
341- * wrapper around @metamask/utils.isValidHexAddress, with the exception that it
342- * by default will return true for hex strings that are otherwise valid
343- * hex addresses, but are not prefixed with `0x`.
344- *
345- * @param possibleAddress - Input parameter to check against.
346- * @param options - The validation options.
347- * @param options.allowNonPrefixed - If true will allow addresses without `0x` prefix.`
348- * @returns Whether or not the input is a valid hex address.
349- */
343+ // JSDoc is only used for memoized version of this function that is exported
344+ // eslint-disable-next-line jsdoc/require-jsdoc
350345function isValidHexAddressUnmemoized (
351346 possibleAddress : string ,
352347 { allowNonPrefixed = true } = { } ,
@@ -361,12 +356,25 @@ function isValidHexAddressUnmemoized(
361356 return isHexChecksumAddress ( addressToCheck ) ;
362357}
363358
359+ /**
360+ * Validates that the input is a hex address. This utility method is a thin
361+ * wrapper around `isValidHexAddress` from `@metamask/utils`, with the exception
362+ * that it may return true for non-0x-prefixed hex strings (depending on the
363+ * option below).
364+ *
365+ * @param possibleAddress - Input parameter to check against.
366+ * @param options - The validation options.
367+ * @param options.allowNonPrefixed - If true will regard addresses without a
368+ * `0x` prefix as valid.
369+ * @returns Whether or not the input is a valid hex address.
370+ */
364371export const isValidHexAddress : (
365- address : string ,
372+ possibleAddress : string ,
366373 options ?: { allowNonPrefixed ?: boolean } ,
367374) => boolean = memoize (
368375 isValidHexAddressUnmemoized ,
369- ( address , options ) => `${ address } -${ options ?. allowNonPrefixed } ` ,
376+ ( possibleAddress , options ) =>
377+ `${ possibleAddress } -${ options ?. allowNonPrefixed } ` ,
370378) ;
371379
372380/**
0 commit comments