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

Fix signMessage and test against ganache #26

Merged
merged 13 commits into from
May 18, 2021
Merged

Fix signMessage and test against ganache #26

merged 13 commits into from
May 18, 2021

Conversation

germartinez
Copy link
Member

@germartinez germartinez commented May 13, 2021

  • After generating a signature with signMessage it checks if the message had a prefix or not to adjust the v value accordingly
  • Add script yarn test:ganache to run the tests against ganache optionally
  • Refactor tests to work with acounts from ganache or hardhat
  • Update README file

@germartinez germartinez changed the title Fix signMassage and test against ganache Fix signMessage and test against ganache May 13, 2021
@github-actions
Copy link

CLA Assistant Lite All Contributors have signed the CLA.

Copy link
Member

@rmeissner rmeissner left a comment

Choose a reason for hiding this comment

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

Looks like a good base to further improve the handling of the signatures in the future.

E.g. check also if it is a contract signature (would be part of EIP-1271 issue)

const recoveredAddress = bufferToHex(pubToAddress(recoveredData))
hasPrefix = !sameString(recoveredAddress, ownerAddress)
} catch (e) {
hasPrefix = true
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it make more sense to throw? E.g. if we cannot recover it, something is probably wrong

v: parseInt(signature.slice(130, 132), 16)
}
const recoveredData = ecrecover(
Buffer.from(txHash.slice(2), 'hex'),
Copy link
Member

Choose a reason for hiding this comment

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

Should we check this also for the prefixed hash and then throw if it matches neither? In the future we could this way also properly handle contract signatures

@@ -11,6 +11,7 @@
],
"scripts": {
"build": "yarn rimraf dist && hardhat compile && tsc",
"test:ganache": "export TEST_NETWORK=ganache && hardhat --network localhost deploy && nyc hardhat --network localhost test",
Copy link
Member

Choose a reason for hiding this comment

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

Should we run this in the CI?


async function getGanacheAccounts(): Promise<Account[]> {
const web3 = new Web3('http://localhost:8545')
const provider = new ethers.providers.Web3Provider(web3.currentProvider as any)
Copy link
Member

Choose a reason for hiding this comment

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

why any?

const provider = new ethers.providers.Web3Provider(web3.currentProvider as any)
const accounts: Account[] = []
for (let i = 0; i < 10; i++) {
const signer: Signer = provider.getSigner(i)
Copy link
Member

Choose a reason for hiding this comment

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

aren't types inherited?

@germartinez germartinez merged commit e81e679 into main May 18, 2021
@germartinez germartinez deleted the ganache-test branch May 18, 2021 15:13
@github-actions github-actions bot locked and limited conversation to collaborators May 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants