evmSignTypedData
Ethereum: sign typed data
Asks the device to sign an EIP-712 typed data message using the private key derived from the given BIP32 path.
User is asked to confirm all signing details on Ukey Wallet device.
- Supports EIP-712 (v3 and v4)
- Use
evmSignTypedDatafor signing typed structured data - Not for EIP-191 typed data signing
- For EIP-191
personal_sign, use evmSignMessage
const result = await HardwareSDK.evmSignTypedData(connectId, deviceId, params);
Params
path- requiredstring | Array<number>minimum length is3. read moredata- requiredObjecttype ofEthereumSignTypedDataMessage. A JSON Schema definition can be found in the EIP-712 spec.metamaskV4Compat- requiredbooleanset totruefor compatibility with MetaMask's signTypedData_v4.chainId- optionalnumberidentifies the target Ethereum network and helps distinguish different chain configurations. Reference.
Blind signing
You may also wish to construct your own hashes using a different library.
domainHash- requiredstringhex-encoded 32-byte hash of the EIP-712 domain.messageHash- optionalstringhex-encoded 32-byte hash of the EIP-712 message. This is optional for the domain-only hashes whereprimaryTypeisEIP712Domain.
When blind signing is used
- Use UKey Lite 24, UKey Lite 25, or UKey Core 26.
- 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: "Wallet Name",
type: "string",
},
{
name: "Amount",
type: "uint64",
},
],
},
primaryType: "Message",
domain: {
name: "example.ukey.io",
},
message: {
"Wallet Name": "UKey Wallet",
// be careful with JavaScript numbers: MAX_SAFE_INTEGER is quite low
Amount: `${2n ** 54n}`,
},
};
const { domainHash, messageHash } = transformTypedDataPlugin(eip712Data, true);
HardwareSDK.evmSignTypedData(connectId, deviceId, {
path: "m/44'/60'/0'/0/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
}
}