bug: catch bech32 decoding errors
This commit is contained in:
parent
667a58ac1d
commit
4d4b03287f
@ -46,9 +46,13 @@ export function parseId(id: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function bech32ToHex(str: string) {
|
export function bech32ToHex(str: string) {
|
||||||
const nKey = bech32.decode(str, 1_000);
|
try {
|
||||||
const buff = bech32.fromWords(nKey.words);
|
const nKey = bech32.decode(str, 1_000);
|
||||||
return secp.utils.bytesToHex(Uint8Array.from(buff));
|
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
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function bech32ToText(str: string) {
|
export function bech32ToText(str: string) {
|
||||||
const decoded = bech32.decode(str, 1000);
|
try {
|
||||||
const buf = bech32.fromWords(decoded.words);
|
const decoded = bech32.decode(str, 1000);
|
||||||
return new TextDecoder().decode(Uint8Array.from(buf));
|
const buf = bech32.fromWords(decoded.words);
|
||||||
|
return new TextDecoder().decode(Uint8Array.from(buf));
|
||||||
|
} catch {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user