From 8185b2e321c771597dcaa50546a7d3c64d03bb72 Mon Sep 17 00:00:00 2001 From: hackyminer Date: Mon, 30 Jul 2018 05:39:37 +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. --- common/libs/wallet/deterministic/ledger.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/common/libs/wallet/deterministic/ledger.ts b/common/libs/wallet/deterministic/ledger.ts index fbf093deaa4..e63708a087f 100644 --- a/common/libs/wallet/deterministic/ledger.ts +++ b/common/libs/wallet/deterministic/ledger.ts @@ -45,7 +45,7 @@ export class LedgerWallet extends HardwareWallet { public async signRawTransaction(t: EthTx): Promise { const txFields = getTransactionFields(t); - t.v = Buffer.from([t._chainId]); + t.v = t._chainId; t.r = toBuffer(0); t.s = toBuffer(0); @@ -53,9 +53,21 @@ export class LedgerWallet extends HardwareWallet { const ethApp = await makeApp(); const result = await ethApp.signTransaction(this.getPath(), t.serialize().toString('hex')); + let v = result.v.toString(16); + if (t._chainId > 0) { + // EIP155 support. check/recalc signature v value. + const rv = parseInt(v, 16); + let cv = t._chainId * 2 + 35; + /* tslint:disable no-bitwise */ + if (rv !== cv && (rv & cv) !== rv) { + cv += 1; // add signature v bit. + } + v = cv.toString(16); + } + const txToSerialize: TxObj = { ...txFields, - v: addHexPrefix(result.v), + v: addHexPrefix(v), r: addHexPrefix(result.r), s: addHexPrefix(result.s) };