Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function signData(identity, signer, key, data) {
const nonce = await didReg.nonce(signer);
const paddedNonce = leftPad(Buffer.from([nonce], 64).toString("hex"));
const dataToSign =
"1900" +
stripHexPrefix(didReg.address) +
paddedNonce +
stripHexPrefix(identity) +
data;
const hash = Buffer.from(sha3.buffer(Buffer.from(dataToSign, "hex")));
const signature = ethutil.ecsign(hash, key);
const publicKey = ethutil.ecrecover(
hash,
signature.v,
signature.r,
signature.s
);
return {
r: "0x" + signature.r.toString("hex"),
s: "0x" + signature.s.toString("hex"),
v: signature.v
};
}
export function keccak (data) {
return Buffer.from(keccak_256.buffer(data))
}