Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
hash (includeSignature) {
if (includeSignature === undefined) includeSignature = true
// EIP155 spec:
// when computing the hash of a transaction for purposes of signing or recovering,
// instead of hashing only the first six elements (ie. nonce, gasprice, startgas, to, value, data),
// hash nine elements, with v replaced by CHAIN_ID, r = 0 and s = 0
let items = this.clearRaw(includeSignature);
// return ethUtil.sha3(Buffer.concat(items));
return ethUtil.hashPersonalMessage(Buffer.concat(items));
}
return new Promise(resolve => {
const msgHash = hashPersonalMessage(toBuffer(msg));
const signed = ecsign(
msgHash,
hdk.derive(ETH_PATH + '/' + i).privateKey
);
resolve(
Buffer.concat([
Buffer.from(signed.r),
Buffer.from(signed.s),
Buffer.from([signed.v])
])
);
});
},
var signHashRequest = function(hash,privateKey) {
return ethUtil.ecsign(ethUtil.hashPersonalMessage(hash), privateKey);
}
export const personalSign = (privateKey, msgParams) => {
const message = ethUtil.toBuffer(msgParams.data);
const msgHash = ethUtil.hashPersonalMessage(message);
const sig = ethUtil.ecsign(msgHash, privateKey);
const serialized = ethUtil.bufferToHex(concatSig(sig.v, sig.r, sig.s));
return serialized;
};
sign(privateKeyBuffer) {
const { r, s, v } = ethUtil.ecsign(
ethUtil.hashPersonalMessage(this.creditRecord),
privateKeyBuffer
)
return bufferToHex(
Buffer.concat(
[ r, s, Buffer.from([ v ]) ]
)
)
}
}
async function sign(block) {
if (block.signature)
return block;
const _signHash = await getSignHash(block);
let msgHash = ethUtil.hashPersonalMessage(_signHash);
let key = Buffer.from(config.plasmaNodeKey, 'hex');
let sig = ethUtil.ecsign(msgHash, key);
block.signature = ethUtil.toBuffer(ethUtil.toRpcSig(sig.v, sig.r, sig.s));
return block.signature;
}
const sign = (data, privateKey) => {
const vrs = ecsign(hashPersonalMessage(data), Buffer.from(privateKey, 'hex'))
return toRpcSig(vrs.v, vrs.r, vrs.s)
}
return new Promise((resolve, reject) => {
if (!this.isPubOnly) {
const msgHash = hashPersonalMessage(Misc.toBuffer(msg));
const signed = ecsign(msgHash, this.privateKey);
resolve(
Buffer.concat([
Buffer.from(signed.r),
Buffer.from(signed.s),
Buffer.from([signed.v])
])
);
} else {
signer(msg)
.then(resolve)
.catch(reject);
}
});
}
function createSignTransaction(transaction) {
let txHash = (transaction.getHash(true))
let signature = ethUtil.ecsign(ethUtil.hashPersonalMessage(txHash),
Buffer.from(config.privateKey, 'hex'))
let rpcSig = ethUtil.toRpcSig(signature.v, signature.r, signature.s)
transaction.signature = rpcSig
return transaction
}
async signMessageMnemonic (stringMessage) {
try {
if (!this.wallet) throw new Error('no wallet present. wallet may not have been decrypted')
let msg = ethUtil.hashPersonalMessage(ethUtil.toBuffer(stringMessage))
let signed = ethUtil.ecsign(msg, this.wallet.privKey)
let combined = Buffer.concat([Buffer.from(signed.r), Buffer.from(signed.s), Buffer.from([signed.v])])
let combinedHex = combined.toString('hex')
return '0x' + combinedHex
} catch (e) {
return e
}
}