contaminate/src/checksum.js

19 lines
413 B
JavaScript

const crypto = require('crypto');
module.exports = {};
/**
* Create a SHA256 checksum (hex encoded) of the given object
*
* Any non-string objects will be JSON encoded before checksumming
*/
module.exports.sha256sum = (obj) => {
let buffer = obj;
if (!obj instanceof String) {
buffer = JSON.stringify(obj);
}
return crypto.createHash('sha256')
.update(buffer, 'utf8')
.digest('hex');
}