Skip to content

Commit

Permalink
chore: refactor validateBech32Address
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuditi committed Mar 1, 2024
1 parent 60fd772 commit 830dab9
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ADDRESS_TYPE_MAP } from '@core/wallet/constants'
import { AddressType } from '@iota/sdk/out/types'

export function validateBech32Address(prefix: string, addr: string, addressType?: AddressType): void {
const addressTypeLetter = addressType ? ADDRESS_TYPE_MAP[addressType] ?? undefined : undefined
if (!addr || !addr.startsWith(prefix)) {
throw new Error(
localize('error.send.wrongAddressPrefix', {
Expand All @@ -19,6 +18,7 @@ export function validateBech32Address(prefix: string, addr: string, addressType?
throw new Error(localize('error.send.wrongAddressFormat'))
}

const addressTypeLetter = addressType === undefined ? undefined : ADDRESS_TYPE_MAP[addressType] ?? undefined
if (addressTypeLetter && !new RegExp(`^${prefix}1${addressTypeLetter}[02-9ac-hj-np-z]{58}$`).test(addr)) {
throw new Error(localize('error.address.wrongAddressType'))
}
Expand Down

0 comments on commit 830dab9

Please sign in to comment.