evmSignTypedData

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 OneKey device.

const result = await HardwareSDK.evmSignTypedData(connectId, deviceId, params);

Params

Optional common params

  • pathrequired string | Array<number> minimum length is 3. read more

  • data - required Object type of EthereumSignTypedDataMessage`. A JSON Schema definition can be found in the EIP-712 spec.

  • metamaskV4Compat - required boolean set to true for compatibility with MetaMask's signTypedData_v4.

  • chainId - optional number The ChainId in ETH is a unique identifier for a specific Ethereum network, used to distinguish different versions of the blockchain. Reference.

Blind signing

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

  • domainHash - required string hex-encoded 32-byte hash of the EIP-712 domain.

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

When is the blind signing

  • Use Mini or Classic.

  • There are arrays nested in data.

  • Firmware version is less than 4.4.0, and the data size is greater than 1KB.

  • Firmware version is greater than or equal to 4.4.0 and the data size is greater than 1.5KB.

Example

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

const {domainHash, messageHash} = transformTypedDataPlugin(eip712Data, true);

HardwareSDK.evmSignTypedData(connectId, deviceId, {
    path: "m/44'/60'/0'",
    data: eip712Data,
    metamaskV4Compat: true,
    domainHash,
    messageHash,
    chainId: 1
});

Result

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

Error

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

Last updated