From 5b2db686e5113e1c6a2cd91c12d837d176947c97 Mon Sep 17 00:00:00 2001 From: hackyminer Date: Wed, 17 Apr 2019 00:03:46 +0900 Subject: [PATCH] fix ledger hardware wallet to support 32bits chainId See also https://github.com/kvhnuke/etherwallet/pull/1979 --- src/wallets/hardware/ledger/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/wallets/hardware/ledger/index.js b/src/wallets/hardware/ledger/index.js index 1d8c150ea22..bbfa68be1b7 100644 --- a/src/wallets/hardware/ledger/index.js +++ b/src/wallets/hardware/ledger/index.js @@ -58,7 +58,7 @@ class ledgerWallet { const txSigner = async tx => { tx = new ethTx(tx); const networkId = tx._chainId; - tx.raw[6] = Buffer.from([networkId]); + tx.raw[6] = networkId; tx.raw[7] = Buffer.from([]); tx.raw[8] = Buffer.from([]); const tokenInfo = byContractAddress('0x' + tx.to.toString('hex')); @@ -67,7 +67,17 @@ class ledgerWallet { accountPath, tx.serialize().toString('hex') ); - tx.v = getBufferFromHex(result.v); + + // EIP155 support. check/recalc signature v value. + let v = result.v; + const rv = parseInt(v, 16); + let cv = networkId * 2 + 35; + if (rv !== cv && (rv & cv) !== rv) { + cv += 1; // add signature v bit. + } + v = cv.toString(16); + + tx.v = getBufferFromHex(v); tx.r = getBufferFromHex(result.r); tx.s = getBufferFromHex(result.s); const signedChainId = calculateChainIdFromV(tx.v);