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

Latest commit

 

History

History
128 lines (98 loc) · 3.84 KB

ethereumSignTypedData.md

File metadata and controls

128 lines (98 loc) · 3.84 KB

Ethereum: Sign Typed Data

Asks device to sign an EIP-712 typed data message using the private key derived by given BIP32 path.

User is asked to confirm all signing details on Trezor Model T.

ES6

const result = await TrezorConnect.ethereumSignTypedData(params);

CommonJS

TrezorConnect.ethereumSignTypedData(params).then(function(result) {

});

⚠️ Supported only by Trezor T with Firmware 2.4.3 or higher! ⚠️ Blind signing is supported only on Trezor Model 1 with Firmware 1.10.5 or higher!

Params

Optional common params

⚠️ Domain-only signing (data.primaryType = "EIP712Domain") is supported only on Trezor T with Firmware 2.4.4 or higher!

Blind signing (optional addition for Trezor Model 1 compatibility)

The Trezor Model 1 firmware currently does not support constructing EIP-712 hashes.

However, it supports signing pre-constructed hashes.

EIP-712 hashes can be constructed with the plugin function at "trezor-connect/lib/plugins/ethereum/typedData.js" (included as a plugin due to a depedency on @metamask/eth-sig-utils).

You may also wish to contruct your own hashes using a different library.

⚠️ Domain-only signing (empty message_hash) is supported only on Trezor Model 1 with Firmware 1.10.6 or higher!

  • domain_separator_hash - required string hex-encoded 32-byte hash of the EIP-712 domain.
  • message_hash - optional string hex-encoded 32-byte hash of the EIP-712 message. This is optional for the domain-only hashes where primaryType is EIP712Domain.

Example

const eip712Data = {
    types: {
        EIP712Domain: [
            {
                name: 'name',
                type: 'string',
            },
        ],
        Message: [
            {
                name: "Best Wallet",
                type: "string"
            },
            {
                name: "Number",
                type: "uint64"
            }
        ]
    },
    primaryType: 'Message',
    domain: {
        name: 'example.trezor.io',
    },
    message: {
        "Best Wallet": "Trezor Model T",
        // be careful with JavaScript numbers: MAX_SAFE_INTEGER is quite low
        "Number": `${2n ** 55n}`,
    },
};

// This functionality is separate from trezor-connect, as it requires @metamask/eth-sig-utils,
// which is a large JavaScript dependency
const transformTypedDataPlugin = require("trezor-connect/lib/plugins/ethereum/typedData.js");
const {domain_separator_hash, message_hash} = transformTypedDataPlugin(eip712Data, true);

TrezorConnect.ethereumSignTypedData({
    path: "m/44'/60'/0'",
    data: eip712Data,
    metamask_v4_compat: true,
    // These are optional, but required for Trezor Model 1 compatibility
    domain_separator_hash,
    message_hash,
});

Result

{
    success: true,
    payload: {
        address: string,
        signature: string, // hexadecimal string with "0x" prefix
    }
}

Error

{
    success: false,
    payload: {
        error: string // error message
    }
}