diff --git a/packages/hdwallet-core/src/ethereum.ts b/packages/hdwallet-core/src/ethereum.ts index 213b9565..5204d82f 100644 --- a/packages/hdwallet-core/src/ethereum.ts +++ b/packages/hdwallet-core/src/ethereum.ts @@ -103,6 +103,10 @@ export interface ETHSignedTx { s: string; /** big-endian hex, prefixed with '0x' */ serialized: string; + /** KeepKey-only: keccak256 pre-image the firmware actually signed (32-byte hex). + * Optional — older firmware doesn't populate it. Useful for diagnostics where + * the caller needs to verify which bytes the device hashed. */ + deviceSignedHash?: string; } export interface ETHSignMessage { diff --git a/packages/hdwallet-keepkey/src/ethereum.ts b/packages/hdwallet-keepkey/src/ethereum.ts index 051a2fef..68a7c5bd 100644 --- a/packages/hdwallet-keepkey/src/ethereum.ts +++ b/packages/hdwallet-keepkey/src/ethereum.ts @@ -386,6 +386,20 @@ export async function ethSignTx(transport: Transport, msg: core.ETHSignTx): Prom const v = core.mustBeDefined(response.getSignatureV()); const v2 = "0x" + v.toString(16); + // Capture the firmware-reported pre-image hash (KeepKey custom field). + // Older firmware doesn't populate this; absence is non-fatal. + let deviceSignedHash: string | undefined; + try { + if (response.hasHash && response.hasHash() && response.getHash_asU8) { + const h = response.getHash_asU8(); + if (h && h.length === 32) { + deviceSignedHash = "0x" + core.toHexString(h); + } + } + } catch { + // ignore — older firmware/proto may not support `hash` + } + const common = Common.custom({ chainId: msg.chainId }); const tx = msg.maxFeePerGas ? FeeMarketEIP1559Transaction.fromTxData({ @@ -398,12 +412,14 @@ export async function ethSignTx(transport: Transport, msg: core.ETHSignTx): Prom }) : Transaction.fromTxData({ ...utxBase, gasPrice: msg.gasPrice, r: r, s: s, v: v2 }, { common }); - return { + const result: core.ETHSignedTx = { r, s, v, serialized: "0x" + core.toHexString(tx.serialize()), }; + if (deviceSignedHash) result.deviceSignedHash = deviceSignedHash; + return result; }); }