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

Commit

Permalink
fixup! refactor(ethSignTypedData)!: Improve docs & types
Browse files Browse the repository at this point in the history
Renames flow-type EthereumSignTypedHashOrData
to EthereumSignTypedHashAndData.

Adds the identical EthereumSignTypedHashAndData
to typescript definitions.
  • Loading branch information
aloisklink committed Feb 4, 2022
1 parent 2fbfc67 commit 7139d79
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/js/core/methods/EthereumSignTypedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import type { MessageResponse, EthereumTypedDataStructAck } from '../../types/tr
import { ERRORS } from '../../constants';
import type {
EthereumSignTypedData as EthereumSignTypedDataParams,
EthereumSignTypedHashOrData as EthereumSignTypedHashOrDataParams,
EthereumSignTypedHashAndData as EthereumSignTypedHashAndDataParams,
} from '../../types/networks/ethereum';
import { getFieldType, parseArrayType, encodeData } from './helpers/ethereumSignTypedData';
import { messageToHex } from '../../utils/formatUtils';

type Params = $Diff<
{
address_n: number[],
...$Exact<EthereumSignTypedDataParams> | $Exact<EthereumSignTypedHashOrDataParams>,
...$Exact<EthereumSignTypedDataParams> | $Exact<EthereumSignTypedHashAndDataParams>,
},
{ path: any }, // removes the "path" variable from this.params
>;
Expand Down Expand Up @@ -104,7 +104,7 @@ export default class EthereumSignTypedData extends AbstractMethod<'ethereumSignT

const { domain_separator_hash, message_hash } =
// $FlowIssue validateParams() confirms that these hashes exist
(this.params: EthereumSignTypedHashOrDataParams);
(this.params: EthereumSignTypedHashAndDataParams);

// For Model 1 we use EthereumSignTypedHash
const response = await cmd.typedCall(
Expand Down
2 changes: 1 addition & 1 deletion src/js/types/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export type API = {
ethereumSignTransaction: Method<Ethereum.EthereumSignTransaction, Ethereum.EthereumSignedTx>,
ethereumSignMessage: Method<Ethereum.EthereumSignMessage, Protobuf.EthereumMessageSignature>,
ethereumSignTypedData: Method<
Ethereum.EthereumSignTypedData | Ethereum.EthereumSignTypedHashOrData,
Ethereum.EthereumSignTypedData | Ethereum.EthereumSignTypedHashAndData,
Protobuf.EthereumTypedDataSignature,
>,

Expand Down
2 changes: 1 addition & 1 deletion src/js/types/networks/ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export type EthereumSignTypedHash = {
* Used for full EIP-712 signing or blind signing.
* Supports both Trezor Model T and Trezor Model 1
*/
export type EthereumSignTypedHashOrData = {
export type EthereumSignTypedHashAndData = {
...$Exact<EthereumSignTypedData>,
...$Exact<EthereumSignTypedHash>,
};
Expand Down
5 changes: 1 addition & 4 deletions src/ts/types/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,7 @@ export namespace TrezorConnect {
*/
function ethereumSignTypedData<T extends Ethereum.EthereumSignTypedDataTypes>(
params: P.CommonParams &
(
| Ethereum.EthereumSignTypedData<T>
| (Ethereum.EthereumSignTypedData<T> & Ethereum.EthereumSignTypedHash)
),
(Ethereum.EthereumSignTypedData<T> | Ethereum.EthereumSignTypedHashAndData<T>),
): P.Response<Protobuf.EthereumTypedDataSignature>;
function ethereumVerifyMessage(
params: P.CommonParams & Ethereum.EthereumVerifyMessage,
Expand Down
7 changes: 7 additions & 0 deletions src/ts/types/networks/ethereum.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ export interface EthereumSignTypedHash {
message_hash?: string;
}

/**
* Used for full EIP-712 signing or blind signing.
* Supports both Trezor Model T and Trezor Model 1.
*/
export type EthereumSignTypedHashAndData<T extends EthereumSignTypedDataTypes> =
EthereumSignTypedData<T> & EthereumSignTypedHash;

// verify message

export interface EthereumVerifyMessage {
Expand Down

0 comments on commit 7139d79

Please sign in to comment.