Skip to content

Commit

Permalink
readd length check with test added
Browse files Browse the repository at this point in the history
  • Loading branch information
imx-mikhala committed Jul 1, 2024
1 parent 60a2995 commit 81237ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/passport/sdk/src/utils/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
2 changes: 1 addition & 1 deletion packages/passport/sdk/src/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 81237ab

Please sign in to comment.