Skip to content

Commit 3f1a480

Browse files
authored
fix(nami): [LW-11782] add bech32 encoding fallback for nami mode (#1486)
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
1 parent 6b5aac4 commit 3f1a480

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

packages/nami/src/adapters/transactions.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,26 @@ const getAddressCredentials = (
128128
Wallet.Crypto.Hash28ByteBase16 | undefined,
129129
Wallet.Crypto.Hash28ByteBase16 | undefined,
130130
] => {
131-
const addr = Wallet.Cardano.Address.fromBech32(address);
132-
return [
133-
addr.getProps().paymentPart?.hash,
134-
addr.getProps().delegationPart?.hash,
135-
];
131+
try {
132+
const addr = Wallet.Cardano.Address.fromBech32(address);
133+
return [
134+
addr.getProps().paymentPart?.hash,
135+
addr.getProps().delegationPart?.hash,
136+
];
137+
} catch (error) {
138+
// try casting as byron address
139+
try {
140+
const addr = Wallet.Cardano.Address.fromBase58(address);
141+
return [
142+
addr.getProps().paymentPart?.hash,
143+
addr.getProps().delegationPart?.hash,
144+
];
145+
} catch (error) {
146+
console.error(error);
147+
}
148+
console.error(error);
149+
return [undefined, undefined];
150+
}
136151
};
137152

138153
const matchesAnyCredential = (

0 commit comments

Comments
 (0)