From eaf7744c08104018467b8563ee94df30844dc4b5 Mon Sep 17 00:00:00 2001 From: hackyminer Date: Mon, 30 Jul 2018 01:39:18 +0900 Subject: [PATCH] support 32bits chainId with the latest Ledger app Please see https://github.com/LedgerHQ/blue-app-eth/commit/8260268b0214810872dabd154b476f5bb859aac0 for some larger chainId cases, returned signature v should be recomputed at the client side. --- app/scripts/uiFuncs.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/scripts/uiFuncs.js b/app/scripts/uiFuncs.js index 6d09394cff..4af38e5092 100644 --- a/app/scripts/uiFuncs.js +++ b/app/scripts/uiFuncs.js @@ -56,7 +56,7 @@ uiFuncs.signTxTrezor = function(rawTx, txData, callback) { ); } uiFuncs.signTxLedger = function(app, eTx, rawTx, txData, old, callback) { - eTx.raw[6] = Buffer.from([rawTx.chainId]); + eTx.raw[6] = rawTx.chainId; eTx.raw[7] = eTx.raw[8] = 0; var toHash = old ? eTx.raw.slice(0, 6) : eTx.raw; var txToSign = ethUtil.rlp.encode(toHash); @@ -69,7 +69,17 @@ uiFuncs.signTxLedger = function(app, eTx, rawTx, txData, old, callback) { }); return; } - rawTx.v = "0x" + result['v']; + var v = result['v'].toString(16); + if (!old) { + // EIP155 support. check/recalc signature v value. + var rv = parseInt(v, 16); + var cv = rawTx.chainId * 2 + 35; + if (rv !== cv && (rv & cv) !== rv) { + cv += 1; // add signature v bit. + } + v = cv.toString(16); + } + rawTx.v = "0x" + v; rawTx.r = "0x" + result['r']; rawTx.s = "0x" + result['s']; eTx = new ethUtil.Tx(rawTx);