From 4d4b03287fcab619e0d02b81b46705da939e42d0 Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 8 Mar 2023 15:17:51 +0000 Subject: [PATCH] bug: catch bech32 decoding errors --- packages/app/src/Util.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/app/src/Util.ts b/packages/app/src/Util.ts index fb206015..f4c5a331 100644 --- a/packages/app/src/Util.ts +++ b/packages/app/src/Util.ts @@ -46,9 +46,13 @@ export function parseId(id: string) { } export function bech32ToHex(str: string) { - const nKey = bech32.decode(str, 1_000); - const buff = bech32.fromWords(nKey.words); - return secp.utils.bytesToHex(Uint8Array.from(buff)); + try { + const nKey = bech32.decode(str, 1_000); + const buff = bech32.fromWords(nKey.words); + return secp.utils.bytesToHex(Uint8Array.from(buff)); + } catch { + return ""; + } } /** @@ -57,9 +61,13 @@ export function bech32ToHex(str: string) { * @returns */ export function bech32ToText(str: string) { - const decoded = bech32.decode(str, 1000); - const buf = bech32.fromWords(decoded.words); - return new TextDecoder().decode(Uint8Array.from(buf)); + try { + const decoded = bech32.decode(str, 1000); + const buf = bech32.fromWords(decoded.words); + return new TextDecoder().decode(Uint8Array.from(buf)); + } catch { + return ""; + } } /**