Skip to content
This repository was archived by the owner on Nov 23, 2023. It is now read-only.

Commit 36d1201

Browse files
committed
fixup! feat: Support Ethereum EIP-712 Sign Typed Data
Add test for nested arrays. Not supported in Trezor Model T as of 2.4.3, but might be added in the future.
1 parent a7d3656 commit 36d1201

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/js/core/methods/helpers/__fixtures__/ethereumSignTypedData.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ export const parseArrayType = [
1919
arraySize: null,
2020
},
2121
},
22+
{
23+
// Decode last [] first
24+
// Can't find an official source, but this is what Metamask's signTypedData_v4 does:
25+
// https://github.com/MetaMask/eth-sig-util/blob/5f2259463990050606cd58b43e64e4bffcb715f4/src/sign-typed-data.ts#L202-L211
26+
description: 'should parse nested arrays',
27+
input: 'int32[5][12]',
28+
output: {
29+
entryTypeName: 'int32[5]',
30+
arraySize: 12,
31+
},
32+
},
2233
{
2334
description: 'should throw error for non-array type',
2435
input: 'bytes',
@@ -121,6 +132,26 @@ export const getFieldType = [
121132
},
122133
},
123134
},
135+
{
136+
// Unsupported in Trezor firmware as of v2.4.3
137+
description: 'should parse nested arrays',
138+
input: {
139+
typeName: 'int32[5][12]',
140+
types: {},
141+
},
142+
output: {
143+
data_type: Enum_EthereumDataType.ARRAY,
144+
size: 12,
145+
entry_type: {
146+
data_type: Enum_EthereumDataType.ARRAY,
147+
size: 5,
148+
entry_type: {
149+
data_type: Enum_EthereumDataType.INT,
150+
size: 4,
151+
},
152+
},
153+
},
154+
},
124155
{
125156
description: `should parse Struct types`,
126157
input: {

src/js/core/methods/helpers/ethereumSignTypedData.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ export function getFieldType(
146146
if (arrayMatch) {
147147
const [_, arrayItemTypeName, arraySize] = arrayMatch;
148148
const entryType = getFieldType(arrayItemTypeName, types);
149-
if (entryType.data_type === Enum_EthereumDataType.ARRAY) {
150-
throw ERRORS.TypedError('Method_InvalidParameter', 'Nested arrays are not supported');
151-
}
152149
return {
153150
data_type: Enum_EthereumDataType.ARRAY,
154151
size: parseInt(arraySize, 10) || undefined,

0 commit comments

Comments
 (0)