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

Commit

Permalink
fixup! feat: Add EIP-712 support for T1
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed Jan 13, 2022
1 parent 5428094 commit 8ea81d9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/js/core/methods/EthereumSignTypedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class EthereumSignTypedData extends AbstractMethod<'ethereumSignT
// validate incoming parameters
validateParams(payload, [
{ name: 'path', required: true },
{ name: 'metamask_v4_compat', type: 'boolean', required: true },
{ name: 'metamask_v4_compat', type: 'boolean' },
// model T
{ name: 'data', type: 'object' },
// model One
Expand All @@ -45,8 +45,9 @@ export default class EthereumSignTypedData extends AbstractMethod<'ethereumSignT
this.info = getNetworkLabel('Sign #NETWORK typed data', network);

this.params = {
...payload,
path,
address_n: path,
metamask_v4_compat: payload.metamask_v4_compat,
domain_separator_hash: payload.domain_separator_hash || '',
message_hash: payload.message_hash || '',
data: payload.data || undefined,
Expand All @@ -55,7 +56,7 @@ export default class EthereumSignTypedData extends AbstractMethod<'ethereumSignT

async run() {
const cmd = this.device.getCommands();
const { address_n, metamask_v4_compat } = this.params;
const { address_n } = this.params;

if (this.device.features.model === '1') {
validateParams(this.params, [
Expand Down Expand Up @@ -84,7 +85,7 @@ export default class EthereumSignTypedData extends AbstractMethod<'ethereumSignT
}

validateParams(this.params, [{ name: 'data', type: 'object', required: true }]);
const { data } = this.params;
const { data, metamask_v4_compat } = this.params;
// $FlowIssue
const { types, primaryType, domain, message } = data;

Expand Down
2 changes: 1 addition & 1 deletion src/js/plugins/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
"scripts": {
"test:unit": "jest"
}
}
}
6 changes: 6 additions & 0 deletions src/js/types/__tests__/ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,10 @@ export const signTypedData = async () => {
(payload.signature: string);
(payload.network: string);
}

await TrezorConnect.ethereumSignTypedData({
path: 'm/44',
message_hash: '0x',
domain_separator_hash: '0x',
});
};
2 changes: 1 addition & 1 deletion src/js/types/networks/ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export type EthereumSignTypedData = {

export type EthereumSignTypedHash = {
path: string | number[],
metamask_v4_compat: boolean,
metamask_v4_compat?: typeof undefined,
data?: typeof undefined,
domain_separator_hash: string,
message_hash: string,
Expand Down
6 changes: 6 additions & 0 deletions src/ts/types/__tests__/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,10 @@ export const signTypedData = async () => {
payload.address;
payload.signature;
}

await TrezorConnect.ethereumSignTypedData({
path: 'm/44',
message_hash: '0x',
domain_separator_hash: '0x',
});
};
3 changes: 1 addition & 2 deletions src/ts/types/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,9 @@ export namespace TrezorConnect {
function ethereumSignTypedData<T extends Ethereum.EthereumSignTypedDataTypes>(
params: P.CommonParams & Ethereum.EthereumSignTypedData<T>,
): P.Response<Protobuf.EthereumTypedDataSignature>;
function ethereumSignTypedHash(
function ethereumSignTypedData(
params: P.CommonParams & Ethereum.EthereumSignTypedHash,
): P.Response<Protobuf.EthereumTypedDataSignature>;

function ethereumVerifyMessage(
params: P.CommonParams & Ethereum.EthereumVerifyMessage,
): P.Response<P.DefaultMessage>;
Expand Down

0 comments on commit 8ea81d9

Please sign in to comment.