Closed adeora7 closed 6 years ago
@lhartikk Please look !
Hi
I was not able to reproduce the problem you described. The calculateHash
function will output different hash, if the timestamp changes:
var CryptoJS = require("crypto-js");
var calculateHash = (index, previousHash, timestamp, data) => {
return CryptoJS.SHA256(index + previousHash + timestamp + data).toString();
};
var hash1 = calculateHash(1, "816534932c2b7154836da6afc367695e6337db8a921823784c14378abed4f7d7", 1465154705, {});
var hash2 = calculateHash(1, "816534932c2b7154836da6afc367695e6337db8a921823784c14378abed4f7d7", 1465154706, {});
console.log(hash1);
console.log(hash2);
output:
b5d0ef20b1b334599a1f6f1474d6e341d3356d5db0f13075664693a670d0f334
7c81ee6c156924933bb5cc299dab7b00bb066f09f180d712131c0e73164b0963
My bad, read it completely wrong.
On 07-Dec-2017 11:23 pm, "Lauri Hartikka" notifications@github.com wrote:
Hi
I was not able to reproduce the problem you described. The calculateHash function will output different hash, if the timestamp changes:
var CryptoJS = require("crypto-js");
var calculateHash = (index, previousHash, timestamp, data) => { return CryptoJS.SHA256(index + previousHash + timestamp + data).toString(); };
var hash1 = calculateHash(1, "816534932c2b7154836da6afc367695e6337db8a921823784c14378abed4f7d7", 1465154705, {}); var hash2 = calculateHash(1, "816534932c2b7154836da6afc367695e6337db8a921823784c14378abed4f7d7", 1465154706, {});
console.log(hash1); console.log(hash2);
output:
b5d0ef20b1b334599a1f6f1474d6e341d3356d5db0f13075664693a670d0f334 7c81ee6c156924933bb5cc299dab7b00bb066f09f180d712131c0e73164b0963
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lhartikk/naivechain/issues/16#issuecomment-350044530, or mute the thread https://github.com/notifications/unsubscribe-auth/AJMSw2h7CC1Es9YrlhHX451_C5-rdVawks5s-CYOgaJpZM4QjKrK .
The function
getHash()
is not dependent on timestamp. Infact, it is only giving the result on basis of the first argument passed to it that too if it is a string. You can verify the same by creating two block chains. The genesis block in both of them will have different timestamps however the hash value is same. This can be corrected by giving a single argument i.e. concatenation of all the arguments in string data type.