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

Add EIP-712 name and version getters #4303

Merged
merged 15 commits into from
Jun 14, 2023
Merged
5 changes: 5 additions & 0 deletions .changeset/little-falcons-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

Add internal name and version getters for EIP712
Amxx marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 24 additions & 2 deletions contracts/utils/cryptography/EIP712.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,34 @@ abstract contract EIP712 is IERC5267 {
{
return (
hex"0f", // 01111
_name.toStringWithFallback(_nameFallback),
_version.toStringWithFallback(_versionFallback),
_EIP712Name(),
_EIP712Version(),
block.chainid,
address(this),
bytes32(0),
new uint256[](0)
);
}

/**
* @dev The name parameter for the EIP712 domain.
*
* NOTE: By default this function reads _name which is an immutable value.
* It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Name() internal view returns (string memory) {
return _name.toStringWithFallback(_nameFallback);
}

/**
* @dev The name parameter for the EIP712 domain.
Amxx marked this conversation as resolved.
Show resolved Hide resolved
*
* NOTE: By default this function reads _version which is an immutable value.
* It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Version() internal view returns (string memory) {
return _version.toStringWithFallback(_versionFallback);
}
}
8 changes: 8 additions & 0 deletions test/utils/cryptography/EIP712.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ contract('EIP712', function (accounts) {

await this.eip712.verify(signature, wallet.getAddressString(), message.to, message.contents);
});

it('name', async function () {
expect(await this.eip712.$_EIP712Name()).to.be.equal(name);
});

it('version', async function () {
expect(await this.eip712.$_EIP712Version()).to.be.equal(version);
});
});
}
});