From 37c33854faca28f6249ccf5cbf29918b1c00d293 Mon Sep 17 00:00:00 2001 From: ALPAC-4 Date: Wed, 21 Feb 2024 15:48:28 +0900 Subject: [PATCH 1/3] fix: trim address --- src/core/bech32.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/bech32.ts b/src/core/bech32.ts index 52bce2b..3288dd2 100644 --- a/src/core/bech32.ts +++ b/src/core/bech32.ts @@ -67,7 +67,7 @@ export namespace AccAddress { * @param hexAddress hex address */ export function fromHex(hexAddress: string): AccAddress { - const hex = hexAddress.startsWith('0x') ? hexAddress.slice(2) : hexAddress; + const hex = hexAddress.replace(/^0x0+|^0+(?!x)/, '0x'); // That moudule address reach here is nearly impossible if (hex.length <= 40) { return bech32.encode( From 3d2210018ea5882fe5cf1e24cda1c604552e6914 Mon Sep 17 00:00:00 2001 From: ALPAC-4 Date: Wed, 21 Feb 2024 15:51:31 +0900 Subject: [PATCH 2/3] fix: remove 0x --- src/core/bech32.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/bech32.ts b/src/core/bech32.ts index 3288dd2..6b52fa6 100644 --- a/src/core/bech32.ts +++ b/src/core/bech32.ts @@ -67,7 +67,7 @@ export namespace AccAddress { * @param hexAddress hex address */ export function fromHex(hexAddress: string): AccAddress { - const hex = hexAddress.replace(/^0x0+|^0+(?!x)/, '0x'); + const hex = hexAddress.replace(/^0x0+|^0+(?!x)/, ''); // That moudule address reach here is nearly impossible if (hex.length <= 40) { return bech32.encode( From 28d1a8dc12a66907f3717d15938cbc8ab427c0d0 Mon Sep 17 00:00:00 2001 From: ALPAC-4 Date: Wed, 21 Feb 2024 16:05:11 +0900 Subject: [PATCH 3/3] fix: handle addr start with 0x(?!0) --- src/core/bech32.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/bech32.ts b/src/core/bech32.ts index 6b52fa6..9e68583 100644 --- a/src/core/bech32.ts +++ b/src/core/bech32.ts @@ -67,7 +67,7 @@ export namespace AccAddress { * @param hexAddress hex address */ export function fromHex(hexAddress: string): AccAddress { - const hex = hexAddress.replace(/^0x0+|^0+(?!x)/, ''); + const hex = hexAddress.replace(/^0x0+|^0x|^0+(?!x)/, ''); // That moudule address reach here is nearly impossible if (hex.length <= 40) { return bech32.encode(