Skip to content

Commit

Permalink
allow invalid addresses
Browse files Browse the repository at this point in the history
Signed-off-by: bennett <[email protected]>
  • Loading branch information
bmzig committed Mar 5, 2025
1 parent 9253994 commit f6c9966
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/utils/AddressUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,17 @@ export function isValidEvmAddress(address: string): boolean {
* @returns a child `Address` type most fitting for the chain ID.
* @todo: Change this to `toAddress` once we remove the other `toAddress` function.
*/
export function toAddressType(address: string, chainId: number): EvmAddress | SvmAddress {
if (chainIsEvm(chainId)) {
return EvmAddress.from(address);
export function toAddressType(address: string, chainId: number): Address | EvmAddress | SvmAddress {
try {
if (chainIsEvm(chainId)) {
return EvmAddress.from(address);
}
return SvmAddress.from(address);
} catch {
// If we hit this block, then the validation for one of the child address classes failed. We still may want to keep this address in our state, so
// return an unchecked address type.
return new Address(utils.arrayify(address));
}
return SvmAddress.from(address);
}

// The Address class can contain any address type. It is up to the subclasses to determine how to format the address's internal representation,
Expand Down

0 comments on commit f6c9966

Please sign in to comment.