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

bump eth-sig-util version to 5.0.2, stop inheriting from eth-simple-keyring #70

Merged
merged 11 commits into from
Dec 6, 2022

Conversation

adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented Nov 10, 2022

  • Bumps version of eth-sig-util (now @metamask/eth-sig-util) to v5.0.2.

  • Removes inheritance of eth-simple-keyring as we want to reorganize the relationships of various keyrings. The new structure will be that all keyrings, once converted to typescript, implement a base-keyring type which indicates the required method signatures to be a valid keyring. Given that this PR disentangles eth-simple-keyring from eth-hd-keyring and the latter no longer inherits methods from the former (getAppKeyAddress , exportAccount, signTransaction, signMessage, signPersonalMessage, decryptMessage, signTypedData, removeAccount, getEncryptionPublicKey) the methods are now implemented on eth-hd-keyring now too.

index.js Outdated Show resolved Hide resolved
@adonesky1 adonesky1 changed the title bump eth-sig-util version to 5.0.1 bump eth-sig-util version to 5.0.2, stop inheriting from eth-simple-keyring & remove ethereumjs-wallet Nov 24, 2022
@adonesky1 adonesky1 force-pushed the bump-eth-sig-util branch 3 times, most recently from 1f5074e to 37dc86d Compare November 29, 2022 17:13
Copy link

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Hey @adonesky1 I know this is in draft but I was curious about a couple of things:

  • I can understand the motivation for removing the dependency on eth-simple-keyring, but what do we feel about defining some kind of interface that all Keyring classes must follow?
  • Do we plan on converting this repo to TypeScript at any point? I guess that could solve the previous point.

@adonesky1
Copy link
Contributor Author

I can understand the motivation for removing the dependency on eth-simple-keyring, but what do we feel about defining some kind of interface that all Keyring classes must follow?

yes for sure! Per my comment here, we will be creating an abstract class/type that will define base/required method signatures for all keyring types @mcmire

@mcmire
Copy link

mcmire commented Nov 29, 2022

@adonesky1 Ah sorry missed that. Makes sense!

@adonesky1 adonesky1 marked this pull request as ready for review November 29, 2022 23:44
@adonesky1 adonesky1 requested a review from a team as a code owner November 29, 2022 23:44
@adonesky1 adonesky1 changed the title bump eth-sig-util version to 5.0.2, stop inheriting from eth-simple-keyring & remove ethereumjs-wallet bump eth-sig-util version to 5.0.2, stop inheriting from eth-simple-keyring & remove ethereumjs-wallet Nov 29, 2022
@Gudahtt
Copy link
Member

Gudahtt commented Nov 30, 2022

Would it be possible to split this into 2 or 3 PRs? It does seem like three distinct changes. Maybe they're tied together in a way that isn't clear

@adonesky1
Copy link
Contributor Author

@Gudahtt no I think you're right. I let scope creep a ton here. Will break up into 2 or 3 PRs

@adonesky1 adonesky1 force-pushed the bump-eth-sig-util branch 2 times, most recently from c5f2610 to 1bd2bd3 Compare November 30, 2022 17:10
@adonesky1 adonesky1 changed the title bump eth-sig-util version to 5.0.2, stop inheriting from eth-simple-keyring & remove ethereumjs-wallet bump eth-sig-util version to 5.0.2, stop inheriting from eth-simple-keyring Nov 30, 2022
yarn.lock Outdated Show resolved Hide resolved
@adonesky1
Copy link
Contributor Author

@Gudahtt this is now just bumping eth-sig-util version and removing inheritance of eth-simple-keyring. The removal of ethereumjs-wallet will be in a separate PR.

@adonesky1
Copy link
Contributor Author

@Gudahtt and @mcmire and it's ready for review

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of this! This should make the TypeScript conversion easier.

It was a bit hard to follow how this compared to eth-simple-keyring@4.2.0 because it seems like some changes were brought from the latest version of that package, and some were from v4.2.0. For example, all of the async functions are now using async instead of returning things wrapped in Promise.resolve.

So far I've made a lot of notes of changes to document in the changelog. There are a few things I still need to review more closely, I'll try to finish this review soon.


// Options:
const hdPathString = `m/44'/60'/0'/0`;
const type = 'HD Key Tree';

class HdKeyring extends SimpleKeyring {
class HdKeyring {
Copy link
Member

Choose a reason for hiding this comment

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

We're dropping EventEmitter here as well.

Seems appropriate, we aren't using any event emitter functionality here. Just noting it for the changelog.

}

// For eth_sign, we need to sign arbitrary data:
async signMessage(address, data, opts = {}) {
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we dropped the newGethSignMessage method as well. This seems fine too, just noting for the changelog

}

// personal_signTypedData, signs data along with the schema
async signTypedData(
Copy link
Member

Choose a reason for hiding this comment

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

Looks like the signTypedData_v{1,3,4} methods have been omitted. This seems fine, just noting for the changelog.

return wallet.privateKey;
}

_getWalletForAccount(account, opts = {}) {
Copy link
Member

Choose a reason for hiding this comment

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

Noting for other reviewers, this method has changed from returning a Wallet instance to returning an object with privateKey and publicKey properties. It seems everything using this has been updated to expect this though.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like this change was what brought in the ethereum-cryptography dependency as well. Was this leftover from the ethereumjs-wallet replacement work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like this change was what brought in the ethereum-cryptography dependency as well. Was this leftover from the ethereumjs-wallet replacement work?

yes good catch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well actually we want to use ethereum-cryptography's version of keccak256 rather than ethereumjs-util's. This change was made in eth-simple-keyring here

index.js Outdated Show resolved Hide resolved
return publicKey;
}

_getPrivateKeyFor(address, opts = {}) {
Copy link
Member

Choose a reason for hiding this comment

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

Worth noting that this was renamed as well, to have an underscore

package.json Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
@adonesky1
Copy link
Contributor Author

It was a bit hard to follow how this compared to eth-simple-keyring@4.2.0 because it seems like some changes were brought from the latest version of that package, and some were from v4.2.0. For example, all of the async functions are now using async instead of returning things wrapped in Promise.resolve.

@Gudahtt Could you point out which bits you are seeing that are eth-simple-keyring v4.2.0 rather than latest. I was shooting to bring over (adapted) copies from only the latest version of eth-simple-keyring (@metamask/eth-simple-keyring v5.0.0)

@Gudahtt
Copy link
Member

Gudahtt commented Dec 1, 2022

Oh, maybe it is all from v5. I thought it was a mix because I was comparing it to v4.2.0 and noticed the order the functions matched v4.2.0 more closely than the main branch, I didn't look at v5 directly.

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@adonesky1 adonesky1 merged commit ac48b83 into main Dec 6, 2022
@adonesky1 adonesky1 deleted the bump-eth-sig-util branch December 6, 2022 17:30
@adonesky1 adonesky1 mentioned this pull request Dec 12, 2022
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