Catch exceptions

This commit is contained in:
Kieran 2023-01-14 13:11:01 +00:00
parent b43f01ff4a
commit 4aeea82bc2
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941

View File

@ -61,9 +61,14 @@ export function hexToBech32(hrp, hex) {
if (typeof hex !== "string" || hex.length === 0 || hex.length % 2 != 0) { if (typeof hex !== "string" || hex.length === 0 || hex.length % 2 != 0) {
return ""; return "";
} }
let buf = secp.utils.hexToBytes(hex); try {
return bech32.encode(hrp, bech32.toWords(buf)); let buf = secp.utils.hexToBytes(hex);
return bech32.encode(hrp, bech32.toWords(buf));
} catch (e) {
console.warn("Invalid hex", hex, e);
return "";
}
} }
/** /**