@govtechsg/open-attestation
Version:
25 lines (24 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.digestCredential = void 0;
var lodash_1 = require("lodash");
var js_sha3_1 = require("js-sha3");
/**
* @deprecated will be removed in the next major release in favour of OpenAttestation v4.0 (more info: https://github.com/Open-Attestation/open-attestation/tree/alpha)
*/
var digestCredential = function (document, salts, obfuscatedData) {
// Prepare array of hashes from visible data
var hashedUnhashedDataArray = salts
// Explictly allow falsy values (e.g. false, 0, etc.) as they can exist in the document
.filter(function (salt) { return (0, lodash_1.get)(document, salt.path) !== undefined; })
.map(function (salt) {
var _a;
return (0, js_sha3_1.keccak256)(JSON.stringify((_a = {}, _a[salt.path] = "".concat(salt.value, ":").concat((0, lodash_1.get)(document, salt.path)), _a)));
});
// Combine both array and sort them to ensure determinism
var combinedHashes = obfuscatedData.concat(hashedUnhashedDataArray);
var sortedHashes = (0, lodash_1.sortBy)(combinedHashes);
// Finally, return the digest of the entire set of data
return (0, js_sha3_1.keccak256)(JSON.stringify(sortedHashes));
};
exports.digestCredential = digestCredential;