Skip to content

Commit

Permalink
fix: rectify snip-12 violation by removing extra : in enum encoding (
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI authored Jan 2, 2025
1 parent 2b69310 commit b903116
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions __tests__/utils/typedData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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\\"))"`
);
});

Expand Down Expand Up @@ -104,7 +104,7 @@ describe('typedData', () => {
);
typeHash = getTypeHash(exampleEnum.types, 'Example', TypedDataRevision.ACTIVE);
expect(typeHash).toMatchInlineSnapshot(
`"0x8eb4aeac64b707f3e843284c4258df6df1f0f7fd38dcffdd8a153a495cd351"`
`"0x393bf83422ca8626a2932696cfa0acb19dcad6de2fe84a2dd2ca7607ea5329a"`
);
});

Expand Down Expand Up @@ -326,7 +326,7 @@ describe('typedData', () => {

messageHash = getMessageHash(exampleEnum, exampleAddress);
expect(messageHash).toMatchInlineSnapshot(
`"0x416b85b18063b1b3420ab709e9d5e35cb716691d397c5841ce7c5198ee30bf"`
`"0x150a589bb56a4fbf4ee01f52e44fd5adde6af94c02b37e383413fed185321a2"`
);

expect(spyPedersen).not.toHaveBeenCalled();
Expand Down
4 changes: 2 additions & 2 deletions src/utils/typedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`;
})
Expand Down

0 comments on commit b903116

Please sign in to comment.