diff --git a/__tests__/utils/typedData.test.ts b/__tests__/utils/typedData.test.ts index 891e1aa3a..945f12075 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( - `"0x393bf83422ca8626a2932696cfa0acb19dcad6de2fe84a2dd2ca7607ea5329a"` + `"0x8eb4aeac64b707f3e843284c4258df6df1f0f7fd38dcffdd8a153a495cd351"` ); }); @@ -326,7 +326,7 @@ describe('typedData', () => { messageHash = getMessageHash(exampleEnum, exampleAddress); expect(messageHash).toMatchInlineSnapshot( - `"0x150a589bb56a4fbf4ee01f52e44fd5adde6af94c02b37e383413fed185321a2"` + `"0x6e61abaf480b1370bbf231f54e298c5f4872f40a6d2dd409ff30accee5bbd1e"` ); expect(spyPedersen).not.toHaveBeenCalled(); diff --git a/src/utils/typedData.ts b/src/utils/typedData.ts index 6a579dbd3..1d462283a 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})`; }) @@ -357,13 +357,11 @@ export function encodeValue( if (revision === Revision.ACTIVE) { const [variantKey, variantData] = Object.entries(data as TypedData['message'])[0]; - const parentType = types[ctx.parent as string].find((t) => t.name === ctx.key)!; - const enumName = (parentType as StarknetEnumType).contains; - const enumType = types[enumName]; + const parentType = types[ctx.parent as string].find((t) => t.name === ctx.key); + const enumType = types[(parentType as StarknetEnumType).contains]; const variantType = enumType.find((t) => t.name === variantKey) as StarknetType; const variantIndex = enumType.indexOf(variantType); - const typeHash = getTypeHash(types, enumName, revision); const encodedSubtypes = variantType.type .slice(1, -1) .split(',') @@ -374,7 +372,7 @@ export function encodeValue( }); return [ type, - revisionConfiguration[revision].hashMethod([typeHash, variantIndex, ...encodedSubtypes]), + revisionConfiguration[revision].hashMethod([variantIndex, ...encodedSubtypes]), ]; } // else fall through to default return [type, getHex(data as string)];