From 4aeea82bc2c1ab6b7049820e355cdd711d38f806 Mon Sep 17 00:00:00 2001 From: Kieran Date: Sat, 14 Jan 2023 13:11:01 +0000 Subject: [PATCH] Catch exceptions --- src/Util.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Util.js b/src/Util.js index d3ba475f3..85c806647 100644 --- a/src/Util.js +++ b/src/Util.js @@ -61,9 +61,14 @@ export function hexToBech32(hrp, hex) { if (typeof hex !== "string" || hex.length === 0 || hex.length % 2 != 0) { return ""; } - - let buf = secp.utils.hexToBytes(hex); - return bech32.encode(hrp, bech32.toWords(buf)); + + try { + let buf = secp.utils.hexToBytes(hex); + return bech32.encode(hrp, bech32.toWords(buf)); + } catch (e) { + console.warn("Invalid hex", hex, e); + return ""; + } } /**