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
22 changes: 22 additions & 0 deletions contracts/utils/cryptography/EIP712.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,26 @@ abstract contract EIP712 is IERC5267 {
new uint256[](0)
);
}

/**
* @dev The name parameter for the EIP712 domain.
*
* NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
Amxx marked this conversation as resolved.
Show resolved Hide resolved
* are a concern.
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Name() internal view virtual returns (string memory) {
return ShortStrings.toStringWithFallback(_name, _nameFallback);
RenanSouza2 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @dev The version parameter for the EIP712 domain.
*
* NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
* are a concern.
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Version() internal view virtual returns (string memory) {
return ShortStrings.toStringWithFallback(_version, _versionFallback);
RenanSouza2 marked this conversation as resolved.
Show resolved Hide resolved
}
}
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);
});
});
}
});