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

Trezor DPath Fix #196

Merged
merged 3 commits into from
Sep 14, 2017
Merged

Trezor DPath Fix #196

merged 3 commits into from
Sep 14, 2017

Conversation

wbobeirne
Copy link
Contributor

This fixes Trezor (And any deterministic wallet that extends that class) to use the index of the wallet as a part of the dpath. This was causing Trezor sends to fail.

In the process of debugging, I also trued up a few spots in the send process to better match v3. I'll drop notes linking to where they exist in v3.

@@ -137,7 +137,7 @@ export async function generateCompleteTransactionFromRawTransaction(
nonce: cleanHex(nonce),
gasPrice: cleanHex(gasPrice.toString(16)),
gasLimit: cleanHex(gasLimit.toString(16)),
to: cleanHex(to),
to: toChecksumAddress(cleanHex(to)),
Copy link
Contributor Author

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.

stripAndLower(tx.gasLimit.toString()),
stripAndLower(tx.to),
stripAndLower(tx.value),
stripAndLower(tx.data),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


constructor(address: string, dPath: string) {
constructor(address: string, dPath: string, index: number) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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!

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

import type { RawTransaction } from 'libs/transaction';

// Identical to ethFuncs.getNakedAddress
function stripAndLower(str) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to move into libs/values? Seems like this would be useful outside of just trezor.

Copy link
Contributor

@dternyak dternyak Sep 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PrivKeyWallet actually implements it on the class, but without lowercase?:

export default class PrivKeyWallet implements IWallet {
...

  getNakedAddress(): Promise<string> {
    return new Promise(resolve => {
      this.getAddress().then(address => {
        resolve(stripHex(address));
      });
    });
  }
...
}

Copy link
Contributor

Choose a reason for hiding this comment

The 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)

Choose a reason for hiding this comment

The 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();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anything, the stripHex in /libs/values.js should be renamed to stripHexAndLower since thats what it actually does

Copy link
Contributor

@dternyak dternyak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was successfully able to broadcast a trezor signed tx.

One adjustment was recommended, and this PR also made me discover that PrivKeyWallet does not lowercase in their getNakedAddress method, however your stripAndLower is supposed to be equivalent to getNakedAddress. More investigation needed to understand why this discrepancy exists.

Copy link

@HenryNguyen5 HenryNguyen5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

@dternyak dternyak merged commit 98156e4 into wallet-decrypt-mnemonic Sep 14, 2017
@dternyak dternyak deleted the trezor-dpath-fix branch September 14, 2017 22:51
dternyak pushed a commit that referenced this pull request Sep 15, 2017
* add 'bip39' package

* add mnemonic decrypt, wallet wrapper

* add mnemonic path config

* add mnemonic support to deterministic components

* add mnemonic support

* accomodate for ledger ETH path

* remove comments

* update comments regarding path length

* rename modal open handler

* make several props optional

* add basic tests for mnemonic decrypt

* make flow happy, add user error notifications

* convert dpaths to js file, update references

* add ledger path to test

* Trezor DPath Fix (#196)

* Match v3 more closely.

* Require wallet index on deterministic wallets, update trezor to send index.

* remove redundent stripAndLower function and rename existing stripHex to stripHexPrefixAndLower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants