Skip to content

Commit

Permalink
fix: issue in constructor when unnormalized addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Nov 21, 2024
1 parent 0568c29 commit 882d776
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/address/src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ export default class Address extends AbstractAddress {
constructor(address: Bech32Address | B256Address) {
super();

if (isBech32(address)) {
this.bech32Address = normalizeBech32(address as Bech32Address);
} else if (isB256(address)) {
if (isB256(address)) {
this.bech32Address = toBech32(address);
} else {
throw new FuelError(
FuelError.CODES.INVALID_BECH32_ADDRESS,
`Invalid Bech32 Address: ${address}.`
);
this.bech32Address = normalizeBech32(address as Bech32Address);

if (!isBech32(this.bech32Address)) {
throw new FuelError(
FuelError.CODES.INVALID_BECH32_ADDRESS,
`Invalid Bech32 Address: ${this.bech32Address}.`
);
}
}
}

Expand Down

0 comments on commit 882d776

Please sign in to comment.