Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
hashResult = crypto.createHash('sha384').update(hashResult).digest();
break;
case 'sha-512':
hashResult = crypto.createHash('sha512').update(hashResult).digest();
break;
case 'sha3-224':
hashResult = new Buffer(sha3_224.array(hashResult));
break;
case 'sha3-256':
hashResult = new Buffer(sha3_256.array(hashResult));
break;
case 'sha3-384':
hashResult = new Buffer(sha3_384.array(hashResult));
break;
case 'sha3-512':
hashResult = new Buffer(sha3_512.array(hashResult));
break;
}
return operationCallback();
} else if (_.has(operation, 'anchors')) {
if (!_.isArray(operation.anchors)) return operationCallback('Invalid anchors operation - ' + operation.anchors);
if (operation.anchors.length === 0) return operationCallback('Invalid anchors operation - ' + operation.anchors);
// Validate each anchor item contents
for (var x = 0; x < operation.anchors.length; x++) {
var anchorType = operation.anchors[x].type || operation.anchors[x]['@type'];
if (!anchorType) return operationCallback('Missing anchor type');
if (_.indexOf(CHAINPOINTv2_VALID_ANCHORTYPES, anchorType) == -1) return operationCallback('Invalid anchor type - ' + anchorType);
var sourceId = operation.anchors[x].sourceId;
if (!sourceId) return operationCallback('Missing sourceId');
var hashFunction = function (value) {
switch (hashType) {
case 'SHA3-224':
return Buffer.from(sha3224.array(value))
case 'SHA3-256':
return Buffer.from(sha3256.array(value))
case 'SHA3-384':
return Buffer.from(sha3384.array(value))
case 'SHA3-512':
return Buffer.from(sha3512.array(value))
default:
return crypto.createHash(hashType).update(value).digest()
}
}
var hashFunction = function (value) {
switch (hashType) {
case 'SHA3-224':
return new Buffer(sha3224.array(value))
case 'SHA3-256':
return new Buffer(sha3256.array(value))
case 'SHA3-384':
return new Buffer(sha3384.array(value))
case 'SHA3-512':
return new Buffer(sha3512.array(value))
case 'sha3':
return ethUtil.sha3(value, 256)
default:
return crypto.createHash(hashType).update(value).digest()
}
}