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

Replaced sha3 with keccak256 in EIP-712 assets #1544

Merged
merged 1 commit into from
Jan 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions assets/eip-712/Example.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function encodeType(primaryType) {
}

function typeHash(primaryType) {
return ethUtil.sha3(encodeType(primaryType));
return ethUtil.keccak256(encodeType(primaryType));
}

function encodeData(primaryType, data) {
Expand All @@ -92,11 +92,11 @@ function encodeData(primaryType, data) {
let value = data[field.name];
if (field.type == 'string' || field.type == 'bytes') {
encTypes.push('bytes32');
value = ethUtil.sha3(value);
value = ethUtil.keccak256(value);
encValues.push(value);
} else if (types[field.type] !== undefined) {
encTypes.push('bytes32');
value = ethUtil.sha3(encodeData(field.type, value));
value = ethUtil.keccak256(encodeData(field.type, value));
encValues.push(value);
} else if (field.type.lastIndexOf(']') === field.type.length - 1) {
throw 'TODO: Arrays currently unimplemented in encodeData';
Expand All @@ -110,11 +110,11 @@ function encodeData(primaryType, data) {
}

function structHash(primaryType, data) {
return ethUtil.sha3(encodeData(primaryType, data));
return ethUtil.keccak256(encodeData(primaryType, data));
}

function signHash() {
return ethUtil.sha3(
return ethUtil.keccak256(
Buffer.concat([
Buffer.from('1901', 'hex'),
structHash('EIP712Domain', typedData.domain),
Expand All @@ -123,7 +123,7 @@ function signHash() {
);
}

const privateKey = ethUtil.sha3('cow');
const privateKey = ethUtil.keccak256('cow');
const address = ethUtil.privateToAddress(privateKey);
const sig = ethUtil.ecsign(signHash(), privateKey);

Expand Down