Use hardhat-exposed to reduce the need for mocks (#3666)

Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
Hadrien Croubois
2023-01-03 15:38:13 +01:00
committed by GitHub
parent a81b0d0b21
commit c1d9da4052
190 changed files with 2297 additions and 4311 deletions

View File

@ -1,4 +1,5 @@
const ethSigUtil = require('eth-sig-util');
const keccak256 = require('keccak256');
const EIP712Domain = [
{ name: 'name', type: 'string' },
@ -15,16 +16,35 @@ const Permit = [
{ name: 'deadline', type: 'uint256' },
];
async function domainSeparator (name, version, chainId, verifyingContract) {
return '0x' + ethSigUtil.TypedDataUtils.hashStruct(
'EIP712Domain',
{ name, version, chainId, verifyingContract },
{ EIP712Domain },
).toString('hex');
function bufferToHexString (buffer) {
return '0x' + buffer.toString('hex');
}
function hexStringToBuffer (hexstr) {
return Buffer.from(hexstr.replace(/^0x/, ''), 'hex');
}
async function domainSeparator ({ name, version, chainId, verifyingContract }) {
return bufferToHexString(
ethSigUtil.TypedDataUtils.hashStruct(
'EIP712Domain',
{ name, version, chainId, verifyingContract },
{ EIP712Domain },
),
);
}
async function hashTypedData (domain, structHash) {
return domainSeparator(domain).then(separator => bufferToHexString(keccak256(Buffer.concat([
'0x1901',
separator,
structHash,
].map(str => hexStringToBuffer(str))))));
}
module.exports = {
EIP712Domain,
Permit,
domainSeparator,
hashTypedData,
};