From b903116e629af5bc375151deb3635cdbe23cc317 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Thu, 2 Jan 2025 20:06:55 +0800 Subject: [PATCH] fix: rectify snip-12 violation by removing extra `:` in enum encoding (#1288) --- __tests__/utils/typedData.test.ts | 6 +++--- src/utils/typedData.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/__tests__/utils/typedData.test.ts b/__tests__/utils/typedData.test.ts index ccbdc3dc1..891e1aa3a 100644 --- a/__tests__/utils/typedData.test.ts +++ b/__tests__/utils/typedData.test.ts @@ -64,7 +64,7 @@ describe('typedData', () => { ); encoded = encodeType(exampleEnum.types, 'Example', TypedDataRevision.ACTIVE); expect(encoded).toMatchInlineSnapshot( - `"\\"Example\\"(\\"someEnum1\\":\\"EnumA\\",\\"someEnum2\\":\\"EnumB\\")\\"EnumA\\"(\\"Variant 1\\":(),\\"Variant 2\\":(\\"u128\\",\\"u128*\\"),\\"Variant 3\\":(\\"u128\\"))\\"EnumB\\"(\\"Variant 1\\":(),\\"Variant 2\\":(\\"u128\\"))"` + `"\\"Example\\"(\\"someEnum1\\":\\"EnumA\\",\\"someEnum2\\":\\"EnumB\\")\\"EnumA\\"(\\"Variant 1\\"(),\\"Variant 2\\"(\\"u128\\",\\"u128*\\"),\\"Variant 3\\"(\\"u128\\"))\\"EnumB\\"(\\"Variant 1\\"(),\\"Variant 2\\"(\\"u128\\"))"` ); }); @@ -104,7 +104,7 @@ describe('typedData', () => { ); typeHash = getTypeHash(exampleEnum.types, 'Example', TypedDataRevision.ACTIVE); expect(typeHash).toMatchInlineSnapshot( - `"0x8eb4aeac64b707f3e843284c4258df6df1f0f7fd38dcffdd8a153a495cd351"` + `"0x393bf83422ca8626a2932696cfa0acb19dcad6de2fe84a2dd2ca7607ea5329a"` ); }); @@ -326,7 +326,7 @@ describe('typedData', () => { messageHash = getMessageHash(exampleEnum, exampleAddress); expect(messageHash).toMatchInlineSnapshot( - `"0x416b85b18063b1b3420ab709e9d5e35cb716691d397c5841ce7c5198ee30bf"` + `"0x150a589bb56a4fbf4ee01f52e44fd5adde6af94c02b37e383413fed185321a2"` ); expect(spyPedersen).not.toHaveBeenCalled(); diff --git a/src/utils/typedData.ts b/src/utils/typedData.ts index fc9407c6c..6a579dbd3 100644 --- a/src/utils/typedData.ts +++ b/src/utils/typedData.ts @@ -266,8 +266,8 @@ export function encodeType( .split(',') .map((e) => (e ? esc(e) : e)) .join(',')})` - : esc(targetType); - return `${esc(t.name)}:${typeString}`; + : `:${esc(targetType)}`; + return `${esc(t.name)}${typeString}`; }); return `${esc(dependency)}(${dependencyElements})`; })