Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/hdwallet-core/src/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 17 additions & 1 deletion packages/hdwallet-keepkey/src/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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;
});
}

Expand Down
Loading