Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let checksum;
// Append byte to checksum
if (isPrivate) {
checksum = "4e5459" + hashing.signedVersion;
} else {
checksum = "4e5459" + hashing.version;
}
// Build the apostille hash
if (hashing.name === "MD5") {
return checksum + CryptoJS.MD5(data);
} else if (hashing.name === "SHA1") {
return checksum + CryptoJS.SHA1(data);
} else if (hashing.name === "SHA256") {
return checksum + CryptoJS.SHA256(data);
} else if (hashing.name === "SHA3-256") {
return checksum + CryptoJS.SHA3(data, {
outputLength: 256
});
} else {
return checksum + CryptoJS.SHA3(data, {
outputLength: 512
});
}
};
function key_derive(shared, salt, sk, pk) {
nacl.lowlevel.crypto_shared_key_hash(shared, pk, sk, hashfunc);
for (let i = 0; i < salt.length; i++) {
shared[i] ^= salt[i];
}
let hash = CryptoJS.SHA3(convert.ua2words(shared, 32), {
outputLength: 256
});
return hash;
}
static encodeFunctionTxData(functionName, types, args) {
let fullName = functionName + '(' + types.join() + ')';
let signature = CryptoJS.SHA3(fullName, { outputLength: 256 }).toString(CryptoJS.enc.Hex).slice(0, 8);
return signature + util.stripHexPrefix(web3.eth.abi.encodeParameters(types, args));
};
const hashPassword = (password) => {
let hashedPassword = SHA3(password, {outputLength: 224})
return hashedPassword.toString(enc.Base64)
}
const encodeMethodCall = (methodName, args) => {
const methodAbi = RevokeAndPublishAbi.filter(obj => obj.name === methodName)[0]
const types = methodAbi.inputs.map(o => o.type)
const fullName = methodName + '(' + types.join() + ')'
const signature = CryptoJS.SHA3(fullName, { outputLength: 256 }).toString(CryptoJS.enc.Hex).slice(0, 8)
return '0x' + signature + coder.encodeParams(types, args)
}
function hashfunc(dest, data, dataLength) {
let convertedData = convert.ua2words(data, dataLength);
let hash = CryptoJS.SHA3(convertedData, {
outputLength: 512
});
convert.words2ua(dest, hash);
}