Skip to content

Commit

Permalink
support 32bits chainid with the latest Ledger app
Browse files Browse the repository at this point in the history
Please see LedgerHQ/app-ethereum@8260268
for some larger chainId cases, returned signature v should be recomputed at the client side.
  • Loading branch information
hackmod committed Jul 29, 2018
1 parent 4830469 commit 8185b2e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions common/libs/wallet/deterministic/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,29 @@ export class LedgerWallet extends HardwareWallet {

public async signRawTransaction(t: EthTx): Promise<Buffer> {
const txFields = getTransactionFields(t);
t.v = Buffer.from([t._chainId]);
t.v = t._chainId;
t.r = toBuffer(0);
t.s = toBuffer(0);

try {
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)
};
Expand Down

0 comments on commit 8185b2e

Please sign in to comment.