Skip to content

Commit b992446

Browse files
committed
fix: expand encoding type for preset types
1 parent 6cd35aa commit b992446

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

__tests__/utils/typedData.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('typedData', () => {
4747
);
4848
encoded = encodeType(examplePresetTypes.types, 'Example', TypedDataRevision.Active);
4949
expect(encoded).toMatchInlineSnapshot(
50-
`"\\"Example\\"(\\"n0\\":\\"TokenAmount\\",\\"n1\\":\\"NftId\\")"`
50+
`"\\"Example\\"(\\"n0\\":\\"TokenAmount\\",\\"n1\\":\\"NftId\\")\\"NftId\\"(\\"collection_address\\":\\"ContractAddress\\",\\"token_id\\":\\"u256\\")\\"TokenAmount\\"(\\"token_address\\":\\"ContractAddress\\",\\"amount\\":\\"u256\\")\\"u256\\"(\\"low\\":\\"u128\\",\\"high\\":\\"u128\\")"`
5151
);
5252
encoded = encodeType(exampleEnum.types, 'Example', TypedDataRevision.Active);
5353
expect(encoded).toMatchInlineSnapshot(
@@ -87,7 +87,7 @@ describe('typedData', () => {
8787
);
8888
typeHash = getTypeHash(examplePresetTypes.types, 'Example', TypedDataRevision.Active);
8989
expect(typeHash).toMatchInlineSnapshot(
90-
`"0x155de33c6a0cc7f2b8926afc7a71fc2ac31ffc26726aee5da0570c5d517a763"`
90+
`"0x1a25a8bb84b761090b1fadaebe762c4b679b0d8883d2bedda695ea340839a55"`
9191
);
9292
typeHash = getTypeHash(exampleEnum.types, 'Example', TypedDataRevision.Active);
9393
expect(typeHash).toMatchInlineSnapshot(
@@ -279,7 +279,7 @@ describe('typedData', () => {
279279

280280
messageHash = getMessageHash(examplePresetTypes, exampleAddress);
281281
expect(messageHash).toMatchInlineSnapshot(
282-
`"0x26e7b8cedfa63cdbed14e7e51b60ee53ac82bdf26724eb1e3f0710cb8987522"`
282+
`"0x185b339d5c566a883561a88fb36da301051e2c0225deb325c91bb7aa2f3473a"`
283283
);
284284

285285
messageHash = getMessageHash(exampleEnum, exampleAddress);

src/utils/typedData.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,24 @@ export function encodeType(
188188
type: string,
189189
revision: Revision = Revision.Legacy
190190
): string {
191-
const [primary, ...dependencies] = getDependencies(types, type, undefined, undefined, revision);
191+
const allTypes =
192+
revision === Revision.Active
193+
? { ...types, ...revisionConfiguration[revision].presetTypes }
194+
: types;
195+
const [primary, ...dependencies] = getDependencies(
196+
allTypes,
197+
type,
198+
undefined,
199+
undefined,
200+
revision
201+
);
192202
const newTypes = !primary ? [] : [primary, ...dependencies.sort()];
193203

194204
const esc = revisionConfiguration[revision].escapeTypeString;
195205

196206
return newTypes
197207
.map((dependency) => {
198-
const dependencyElements = types[dependency].map((t) => {
208+
const dependencyElements = allTypes[dependency].map((t) => {
199209
const targetType =
200210
t.type === 'enum' && revision === Revision.Active
201211
? (t as StarkNetEnumType).contains

0 commit comments

Comments
 (0)