From 81237ab7cfc58896c2999fcd5a3f2bb745f1246f Mon Sep 17 00:00:00 2001 From: Mikhala Date: Mon, 1 Jul 2024 12:26:11 +0800 Subject: [PATCH] readd length check with test added --- packages/passport/sdk/src/utils/string.test.ts | 5 +++++ packages/passport/sdk/src/utils/string.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/passport/sdk/src/utils/string.test.ts b/packages/passport/sdk/src/utils/string.test.ts index 7bf836251b..39ba17b99c 100644 --- a/packages/passport/sdk/src/utils/string.test.ts +++ b/packages/passport/sdk/src/utils/string.test.ts @@ -33,5 +33,10 @@ describe('string', () => { expect(hexToString(hex)).toEqual(hex); }); + + it('should return hex if length is 32', () => { + const hex = `0x${'12'.repeat(32)}`; // 32 non-zero bytes + expect(hexToString(hex)).toEqual(hex); + }); }); }); diff --git a/packages/passport/sdk/src/utils/string.ts b/packages/passport/sdk/src/utils/string.ts index 9dbe8ba48a..432ce368ee 100644 --- a/packages/passport/sdk/src/utils/string.ts +++ b/packages/passport/sdk/src/utils/string.ts @@ -5,7 +5,7 @@ export const hexToString = (hex: string) => { try { const stripped = utils.stripZeros(utils.arrayify(hex)); - return utils.toUtf8String(stripped); + return stripped.length === 32 ? hex : utils.toUtf8String(stripped); } catch (e) { return hex; }