Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/utils/typedData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ describe('typedData', () => {

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

expect(spyPedersen).not.toHaveBeenCalled();
Expand Down
8 changes: 5 additions & 3 deletions src/utils/typedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,13 @@ 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 enumType = types[(parentType as StarknetEnumType).contains];
const parentType = types[ctx.parent as string].find((t) => t.name === ctx.key)!;
const enumName = (parentType as StarknetEnumType).contains;
const enumType = types[enumName];
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(',')
Expand All @@ -372,7 +374,7 @@ export function encodeValue(
});
return [
type,
revisionConfiguration[revision].hashMethod([variantIndex, ...encodedSubtypes]),
revisionConfiguration[revision].hashMethod([typeHash, variantIndex, ...encodedSubtypes]),
];
} // else fall through to default
return [type, getHex(data as string)];
Expand Down
Loading