Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
let ret
let shash
if (params.method == "eth_signTypedData_v3")
{
const data = JSON.parse(params.data)
const pkey = this.getCurrentWeb3Account().privateKey
const sig = ethUtil.ecsign(TypedDataUtils.sign(data), ethUtil.toBuffer(pkey))
const result = ethUtil.bufferToHex(concatSig(sig.v, sig.r, sig.s))
shash = result.slice(2, 6)
ret = {result}
} else {
const msg = params.msg
const post_phrase_prefix = params.post_phrase_prefix
console.log("signing message:", msg)
const signature = this.getCurrentWeb3Account().sign(msg).signature
shash = result.slice(2, 6)
ret = {msg, signature, account:this.state.ethAddress}
if (post_phrase_prefix)
{
const sig_key = signature.substring(0, 66)
const temp_account = web3.eth.accounts.privateKeyToAccount(sig_key)
const rawOffer = await adapter.call('offers', [listingID, offerIndex])
const payout = web3.utils
.toBN(rawOffer.value)
.sub(web3.utils.toBN(rawOffer.refund))
.toString()
const verifyFee = '100'
const data = await origin.contractService.getSignFinalizeData(
listingID,
offerID,
ipfsBytes,
payout,
verifyFee
)
const sig = ethUtil.ecsign(
TypedDataUtils.sign(data),
ethUtil.toBuffer(HOT_WALLET_PK)
)
const signature = ethUtil.bufferToHex(concatSig(sig.v, sig.r, sig.s))
console.log(
'Signing:',
data,
' signature',
signature,
' payout:',
payout,
' verifyFee:',
verifyFee
)
console.log('raw Offer:', rawOffer)
return { signature, ipfsBytes, payout, verifyFee }
}