-
Notifications
You must be signed in to change notification settings - Fork 232
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 signTypedData #220
Merged
Merged
Fix signTypedData #220
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ae6b08a
Fix typedData chainId type
germartinez 8e155c4
Fix signTypedData signature adjustment
germartinez 5c9b107
Update package versions
germartinez e0b0eb3
Merge branch 'development' into fix-sign-typed-data
germartinez 8465a72
Add EIP-712 unit tests
germartinez 49551f6
Merge branch 'development' into fix-sign-typed-data
germartinez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { SafeTransactionData } from '@gnosis.pm/safe-core-sdk-types' | ||
import chai from 'chai' | ||
import { | ||
EIP712_DOMAIN, | ||
EIP712_DOMAIN_BEFORE_V130, | ||
generateTypedData, | ||
getEip712MessageTypes | ||
} from '../src' | ||
|
||
const safeAddress = '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1' | ||
const safeTransactionData: SafeTransactionData = { | ||
to: '0x000', | ||
value: '111', | ||
data: '0x222', | ||
operation: 333, | ||
safeTxGas: 444, | ||
baseGas: 555, | ||
gasPrice: 666, | ||
gasToken: '0x777', | ||
refundReceiver: '0x888', | ||
nonce: 999 | ||
} | ||
|
||
describe('EIP-712 sign typed data', () => { | ||
describe('getEip712MessageTypes', async () => { | ||
it('should have the domain typed as EIP712_DOMAIN_BEFORE_V130 for Safes < v1.3.0', async () => { | ||
const { EIP712Domain } = getEip712MessageTypes('1.2.0') | ||
chai.expect(EIP712Domain).to.be.eq(EIP712_DOMAIN_BEFORE_V130) | ||
}) | ||
|
||
it('should have the domain typed as EIP712_DOMAIN for Safes >= v1.3.0', async () => { | ||
const { EIP712Domain } = getEip712MessageTypes('1.3.0') | ||
chai.expect(EIP712Domain).to.be.eq(EIP712_DOMAIN) | ||
}) | ||
}) | ||
|
||
describe('generateTypedData', async () => { | ||
it('should generate the typed data for Safes < v1.3.0', async () => { | ||
const { domain } = generateTypedData({ | ||
safeAddress, | ||
safeVersion: '1.2.0', | ||
chainId: 4, | ||
safeTransactionData | ||
}) | ||
chai.expect(domain.verifyingContract).to.be.eq(safeAddress) | ||
chai.expect(domain.chainId).to.be.undefined | ||
}) | ||
|
||
it('should generate the typed data for for Safes >= v1.3.0', async () => { | ||
const chainId = 4 | ||
const { domain } = generateTypedData({ | ||
safeAddress, | ||
safeVersion: '1.3.0', | ||
chainId, | ||
safeTransactionData | ||
}) | ||
chai.expect(domain.verifyingContract).to.be.eq(safeAddress) | ||
chai.expect(domain.chainId).to.be.eq(chainId) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@gnosis.pm/safe-core-sdk", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Safe Core SDK", | ||
"main": "dist/src/index.js", | ||
"typings": "dist/src/index.d.ts", | ||
|
@@ -41,8 +41,8 @@ | |
"devDependencies": { | ||
"@gnosis.pm/safe-contracts-v1.2.0": "npm:@gnosis.pm/[email protected]", | ||
"@gnosis.pm/safe-contracts-v1.3.0": "npm:@gnosis.pm/[email protected]", | ||
"@gnosis.pm/safe-ethers-lib": "^1.2.0", | ||
"@gnosis.pm/safe-web3-lib": "^1.2.0", | ||
"@gnosis.pm/safe-ethers-lib": "^1.2.1", | ||
"@gnosis.pm/safe-web3-lib": "^1.2.1", | ||
"@nomiclabs/hardhat-ethers": "^2.0.5", | ||
"@nomiclabs/hardhat-waffle": "^2.0.3", | ||
"@nomiclabs/hardhat-web3": "^2.0.0", | ||
|
@@ -89,7 +89,7 @@ | |
}, | ||
"dependencies": { | ||
"@ethersproject/solidity": "^5.6.0", | ||
"@gnosis.pm/safe-core-sdk-types": "^1.2.0", | ||
"@gnosis.pm/safe-core-sdk-types": "^1.2.1", | ||
"@gnosis.pm/safe-deployments": "1.15.0", | ||
"ethereumjs-util": "^7.1.4", | ||
"semver": "^7.3.5", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 guess the error was caused because ethers would try to encode
undefined
instead of ignoring it if the key is present?Would it be possible to unit-test this? I feel like this is missed / refactored wrong easily.
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.
Yes, that was exactly the issue ;)
I'll add some tests to cover that