Skip to content

Commit

Permalink
fix(nami): [LW-11782] add bech32 encoding fallback for nami mode (#1486)
Browse files Browse the repository at this point in the history
implement try/catch with undefined fallback
prevents nami crashing if bech32 or base8 decode fails, or
throws due to:
- invalid string length
- mixed formatting
- any other issue related to encoding
  • Loading branch information
mchappell authored Oct 29, 2024
1 parent 6b5aac4 commit 3f1a480
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions packages/nami/src/adapters/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,26 @@ const getAddressCredentials = (
Wallet.Crypto.Hash28ByteBase16 | undefined,
Wallet.Crypto.Hash28ByteBase16 | undefined,
] => {
const addr = Wallet.Cardano.Address.fromBech32(address);
return [
addr.getProps().paymentPart?.hash,
addr.getProps().delegationPart?.hash,
];
try {
const addr = Wallet.Cardano.Address.fromBech32(address);
return [
addr.getProps().paymentPart?.hash,
addr.getProps().delegationPart?.hash,
];
} catch (error) {
// try casting as byron address
try {
const addr = Wallet.Cardano.Address.fromBase58(address);
return [
addr.getProps().paymentPart?.hash,
addr.getProps().delegationPart?.hash,
];
} catch (error) {
console.error(error);
}
console.error(error);
return [undefined, undefined];
}
};

const matchesAnyCredential = (
Expand Down

0 comments on commit 3f1a480

Please sign in to comment.