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 signV2Order(order) {
const signature = await promisify(web3Instance.eth.sign)(
getV2OrderHash(order), order.makerAddress
);
const { v, r, s } = ethUtil.fromRpcSig(signature);
// 0x00 Illegal
// 0x01 Invalid
// 0x02 EIP712 (no prepended string)
// 0x03 EthSign (prepended "\x19Ethereum Signed Message:\n32")
// 0x04 Wallet
// 0x05 Validator
// 0x06 PreSigned
// 0x07 NSignatureTypes
const sigType = 3;
return ethUtil.bufferToHex(
Buffer.concat([
ethUtil.toBuffer(v),
r,
s,
async function recoverSigner(message, signature) {
let split = util.fromRpcSig(signature);
let publicKey = util.ecrecover(message, split.v, split.r, split.s);
let signer = util.pubToAddress(publicKey).toString("hex");
return signer;
}
verify: (web3, message, signature, cb) =>
{
try
{
message = web3.sha3(message);
const {v, r, s} = utils.fromRpcSig(signature);
let m = utils.toBuffer(message);
let pub = utils.ecrecover(m, v, r, s);
let adr = '0x' + utils.pubToAddress(pub).toString('hex');
cb(adr);
}
catch(e)
{
console.log("verify error: " + e);
}
},
function _parseSignatureHexAsRSV(signatureHex: string) {
const { v, r, s } = ethUtil.fromRpcSig(signatureHex)
const ecSignature = {
v,
r: ethUtil.bufferToHex(r),
s: ethUtil.bufferToHex(s),
}
return ecSignature
}
}
export function signatureIsValid(address: string, message: string, signature: string): boolean {
if (!address || !signature)
return false
try {
const msgHash = hashPersonalMessage(Buffer.from(message))
const signatureParams = fromRpcSig(signature)
const publicKey = ecrecover(
msgHash,
signatureParams.v,
signatureParams.r,
signatureParams.s,
)
const addressBuffer = publicToAddress(publicKey)
const addressVerified = bufferToHex(addressBuffer)
return addressVerified.toLowerCase() === address.toLowerCase()
} catch (exception) {
if (exception.message === 'Invalid signature length')
return false
else if (exception.message === 'couldn\'t recover public key from signature')
return false
else
function _parseSignatureHexAsRSV(signatureHex) {
var _a = ethUtil.fromRpcSig(signatureHex), v = _a.v, r = _a.r, s = _a.s;
var ecSignature = {
v: v,
r: ethUtil.bufferToHex(r),
s: ethUtil.bufferToHex(s),
};
return ecSignature;
}
}
export function recoverPublicKey(sig: string, hash: string): string {
const sigParams = ethUtil.fromRpcSig(sig);
const hashBuffer = ethUtil.toBuffer(hash);
const result = ethUtil.ecrecover(
hashBuffer,
sigParams.v,
sigParams.r,
sigParams.s
);
const signer = ethUtil.bufferToHex(ethUtil.publicToAddress(result));
return signer;
}
function verifyAttribute(attribute, RPCsig) {
var hash = ethUtils.sha3(attribute);
var sig = ethUtils.fromRpcSig(RPCsig);
var pubkey = ethUtils.ecrecover(hash, sig.v, sig.r, sig.s);
return '0x' + ethUtils.publicToAddress(pubkey).toString('hex');
}
async function recoverSigner(message, signature) {
let split = util.fromRpcSig(signature);
let publicKey = util.ecrecover(message, split.v, split.r, split.s);
let signer = util.pubToAddress(publicKey).toString("hex");
return signer;
}
parseSignatureHexAsRSV(signatureHex) {
const { v, r, s } = ethUtil.fromRpcSig(signatureHex)
const ecSignature = {
v,
r: ethUtil.bufferToHex(r),
s: ethUtil.bufferToHex(s),
}
return ecSignature
},
}