-
-
Notifications
You must be signed in to change notification settings - Fork 650
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
Trezor DPath Fix #196
Trezor DPath Fix #196
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,17 +4,19 @@ import type { IWallet } from './IWallet'; | |
export default class DeterministicWallet implements IWallet { | ||
address: string; | ||
dPath: string; | ||
index: number; | ||
|
||
constructor(address: string, dPath: string) { | ||
constructor(address: string, dPath: string, index: number) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chose to make this a separate param, rather than sending it all in as the dPath, to make sure people don't make the same mistake I do! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think thats fine, whoever next works on this should be able to figure out dPath is really dPath - index in that case. |
||
this.address = address; | ||
this.dPath = dPath; | ||
this.index = index; | ||
} | ||
|
||
getAddress(): Promise<string> { | ||
return Promise.resolve(this.address); | ||
} | ||
|
||
getPath(): string { | ||
return this.dPath; | ||
return `${this.dPath}/${this.index}`; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,21 +5,25 @@ import Big from 'bignumber.js'; | |
import { addHexPrefix } from 'ethereumjs-util'; | ||
import DeterministicWallet from './deterministic'; | ||
import { stripHex } from 'libs/values'; | ||
|
||
import type { RawTransaction } from 'libs/transaction'; | ||
|
||
// Identical to ethFuncs.getNakedAddress | ||
function stripAndLower(str) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason not to move into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PrivKeyWallet actually implements it on the class, but without lowercase?:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably figure out why that discrepancy exists (not that it needs to be fixed as a part of this PR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stripHex already lowercases the input export function stripHex(address: string): string {
return address.replace('0x', '').toLowerCase();
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If anything, the |
||
return stripHex(str).toLowerCase(); | ||
} | ||
|
||
export default class TrezorWallet extends DeterministicWallet { | ||
signRawTransaction(tx: RawTransaction): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
TrezorConnect.ethereumSignTx( | ||
// Args | ||
this.getPath(), | ||
stripHex(tx.nonce), | ||
stripHex(tx.gasPrice.toString()), | ||
stripHex(tx.gasLimit.toString()), | ||
stripHex(tx.to), | ||
stripHex(tx.value), | ||
stripHex(tx.data), | ||
stripAndLower(tx.nonce), | ||
stripAndLower(tx.gasPrice.toString()), | ||
stripAndLower(tx.gasLimit.toString()), | ||
stripAndLower(tx.to), | ||
stripAndLower(tx.value), | ||
stripAndLower(tx.data), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
tx.chainId, | ||
// Callback | ||
result => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find where in code this happens, but all of the transactions I generated showed the checksum'd version in v3, whereas v4 was allowing all lower / all caps versions into the raw tx.