Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support 32bits chainid with the latest Ledger app #2094

Merged
Merged
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
21 changes: 19 additions & 2 deletions common/libs/wallet/deterministic/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,34 @@ export class LedgerWallet extends HardwareWallet {

public async signRawTransaction(t: EthTx): Promise<Buffer> {
const txFields = getTransactionFields(t);
t.v = Buffer.from([t._chainId]);
t.v = toBuffer(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;
hackmod marked this conversation as resolved.
Show resolved Hide resolved
if (t._chainId > 0) {
// EIP155 support. check/recalc signature v value.
// Please see https://github.com/LedgerHQ/blue-app-eth/commit/8260268b0214810872dabd154b476f5bb859aac0
// currently, ledger returns only 1-byte truncated signatur_v
const rv = parseInt(v, 16);
let cv = t._chainId * 2 + 35; // calculated signature v, without signature bit.
/* tslint:disable no-bitwise */
if (rv !== cv && (rv & cv) !== rv) {
// (rv !== cv) : for v is truncated byte case
// (rv & cv): make cv to truncated byte
// (rv & cv) !== rv: signature v bit needed
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