Support for personal message signing and EIP-712 structured data signing with full type safety. The library provides comprehensive support for different message signing standards used in Ethereum applications.
Sign arbitrary messages using the Ethereum personal message signing standard (eth_sign).
/**
* Sign a personal message using Ethereum personal message standard
* @param path - BIP32 derivation path for signing key
* @param messageHex - Message data as hex string (without 0x prefix)
* @returns Message signature with recovery ID
*/
signPersonalMessage(
path: string,
messageHex: string
): Promise<{
v: number;
s: string;
r: string;
}>;Usage Examples:
// Sign a text message
const message = "Hello Ledger";
const messageHex = Buffer.from(message, "utf8").toString("hex");
const signature = await eth.signPersonalMessage("44'/60'/0'/0/0", messageHex);
console.log(signature.r); // "0x..."
console.log(signature.s); // "0x..."
console.log(signature.v); // 27 or 28
// Sign binary data
const binaryData = new Uint8Array([0x12, 0x34, 0x56, 0x78]);
const binaryHex = Buffer.from(binaryData).toString("hex");
const signature = await eth.signPersonalMessage("44'/60'/0'/0/0", binaryHex);Sign structured data according to the EIP-712 standard with automatic type parsing and domain separation.
/**
* Sign EIP-712 structured data message
* @param path - BIP32 derivation path for signing key
* @param jsonMessage - EIP-712 structured message object
* @param fullImplem - Use full implementation for complex types (default: false)
* @returns Structured data signature with recovery ID
*/
signEIP712Message(
path: string,
jsonMessage: EIP712Message,
fullImplem?: boolean
): Promise<{
v: number;
s: string;
r: string;
}>;Usage Examples:
// Sign EIP-712 structured data
const typedMessage = {
types: {
EIP712Domain: [
{ name: "name", type: "string" },
{ name: "version", type: "string" },
{ name: "chainId", type: "uint256" },
{ name: "verifyingContract", type: "address" }
],
Person: [
{ name: "name", type: "string" },
{ name: "wallet", type: "address" }
],
Mail: [
{ name: "from", type: "Person" },
{ name: "to", type: "Person" },
{ name: "contents", type: "string" }
]
},
primaryType: "Mail",
domain: {
name: "Ether Mail",
version: "1",
chainId: 1,
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
},
message: {
from: {
name: "Alice",
wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
},
to: {
name: "Bob",
wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
},
contents: "Hello, Bob!"
}
};
const signature = await eth.signEIP712Message("44'/60'/0'/0/0", typedMessage);
// Sign with full implementation for complex types
const signature = await eth.signEIP712Message(
"44'/60'/0'/0/0",
typedMessage,
true
);Sign pre-computed EIP-712 hashes when you have already calculated the domain separator and message hash.
/**
* Sign pre-hashed EIP-712 message components
* @param path - BIP32 derivation path for signing key
* @param domainSeparatorHex - Pre-computed domain separator hash
* @param hashStructMessageHex - Pre-computed message struct hash
* @returns Structured data signature with recovery ID
*/
signEIP712HashedMessage(
path: string,
domainSeparatorHex: string,
hashStructMessageHex: string
): Promise<{
v: number;
s: string;
r: string;
}>;Usage Examples:
// Sign pre-computed EIP-712 hashes
const domainSeparator = "0x1234567890abcdef...";
const messageHash = "0xfedcba0987654321...";
const signature = await eth.signEIP712HashedMessage(
"44'/60'/0'/0/0",
domainSeparator,
messageHash
);
// Example: Using with ethers.js pre-computed hashes
import { _TypedDataEncoder } from "@ethersproject/hash";
const domainSeparator = _TypedDataEncoder.hashDomain(domain);
const messageHash = _TypedDataEncoder.hashStruct("Mail", message, types);
const signature = await eth.signEIP712HashedMessage(
"44'/60'/0'/0/0",
domainSeparator.slice(2), // Remove 0x prefix
messageHash.slice(2) // Remove 0x prefix
);Direct access to EIP-712 signing functions for advanced use cases.
/**
* Sign EIP-712 message using transport directly
* @param transport - Hardware wallet transport
* @param path - BIP32 derivation path
* @param typedMessage - EIP-712 structured message
* @param fullImplem - Use full implementation
* @param loadConfig - Service configuration for filtering
* @returns Message signature
*/
function signEIP712Message(
transport: Transport,
path: string,
typedMessage: EIP712Message,
fullImplem?: boolean,
loadConfig: LoadConfig
): Promise<{v: number; s: string; r: string}>;
/**
* Sign pre-hashed EIP-712 message using transport directly
* @param transport - Hardware wallet transport
* @param path - BIP32 derivation path
* @param domainSeparatorHex - Domain separator hash
* @param hashStructMessageHex - Message struct hash
* @returns Message signature
*/
function signEIP712HashedMessage(
transport: Transport,
path: string,
domainSeparatorHex: string,
hashStructMessageHex: string
): Promise<{v: number; s: string; r: string}>;interface EIP712Message {
/** Type definitions for all structured data types */
types: {
EIP712Domain: EIP712MessageTypesEntry[];
[additionalProperties: string]: EIP712MessageTypesEntry[];
};
/** Primary type name being signed */
primaryType: string;
/** Domain separator data */
domain: {
name?: string;
version?: string;
chainId?: number;
verifyingContract?: string;
salt?: string;
};
/** Message data conforming to primary type */
message: Record<string, any>;
}
interface EIP712MessageTypesEntry {
/** Field name */
name: string;
/** Field type (e.g., "string", "uint256", "address", "bytes32") */
type: string;
}The library includes utilities for parsing and validating EIP-712 type definitions:
/**
* Parse EIP-712 type string into components
* @param typeString - Type definition string
* @returns Parsed type components
*/
function destructTypeFromString(typeString: string): any;
/**
* Create type entry buffer for hardware wallet
* @param entry - Type entry with name and type
* @returns Buffer for device transmission
*/
function makeTypeEntryStructBuffer({name, type}: EIP712MessageTypesEntry): Buffer;Advanced filtering capabilities for customizing message display on hardware wallets:
interface FilteringInfoShowField {
/** Field path to show */
path: string;
/** Display configuration */
displayName?: string;
}
interface FilteringInfoDiscardField {
/** Field path to discard */
path: string;
}
interface FilteringInfoContractName {
/** Contract name for display */
name: string;
/** Contract signature */
signature: string;
}Usage Examples:
// Custom filtering for EIP-712 display
const filterConfig = {
showFields: [
{ path: "message.from.name", displayName: "Sender" },
{ path: "message.to.name", displayName: "Recipient" },
{ path: "message.contents", displayName: "Message" }
],
discardFields: [
{ path: "message.metadata" }
]
};