Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
value = 4 * 10 ** decimals;
from = newAccount.address;
// to = strangerAccount;
// from = account1;
to = web3m.eth.accounts.create().address;
delegate = dreamTeamAccount;
fee = 2 * 10 ** decimals - 1;
deadline = (await web3m.eth.getBlock(`latest`)).timestamp + 60 * 60 * 24 * 7; // +7 days
usedSigId = sigId++;
const dataToSign = getTypedDataToSign();
await token.transfer(from, 4 * (value + fee), { from: dreamTeamAccount });
const balanceFrom = +(await token.balanceOf.call(from));
assert.equal(balanceFrom, 4 * (value + fee), "Account balance must be refilled");
const balanceTo = +(await token.balanceOf.call(to));
const balanceDelegate = +(await token.balanceOf.call(delegate));
signature = sigUtils.signTypedData(
Buffer.from(newAccount.privateKey.slice(2), "hex"),
{ data: dataToSign }
);
const tx = await token.transferViaSignature(
from, to, value, fee, delegate, deadline, usedSigId, signature, SIG_STANDARD_TYPED, { from: delegate }
);
infoLog(`TX (transferViaSignature) gas usage: ${ getUsedGas(tx) }`);
assert.equal(+(await token.balanceOf(from)), balanceFrom - value - fee, "Must subtract balance");
assert.equal(+(await token.balanceOf(to)), balanceTo + value, "Must add balance to recipient");
assert.equal(+(await token.balanceOf(delegate)), balanceDelegate + fee, "Must pay fee to delegate");
});
function getSignature() {
return ethSigUtil.signTypedData(privateKey, {
data: {
types: {
EIP712Domain: domainType,
Auction: auctionType
},
domain: getDomainData(),
primaryType: 'Auction',
message: getAuctionData()
}
});
}
verifyingContract: contractAddress
},
message: {
from: from || signingAcount.address,
to,
amount,
data,
nonce,
gasPrice,
txGas,
gasLimit,
tokenGasPrice,
relayer
}
};
return sigUtil.signTypedData(privateKeyAsBuffer, {data: data712});
}
signData(data) {
const privateKey = toBuffer(this.wallet.privateKey)
const sig = sigUtil.signTypedData(privateKey, { data })
return {
data,
sig,
}
}
function generateSignature(privateKey: string, data: any) {
let pk = ethJsUtil.toBuffer(privateKey)
return sigUtil.signTypedData(pk, {
data,
})
}
async ethSignTypedData(signer, data) {
this._validateSigner(signer);
if (!data) throw new Error('Data to sign cannot be null');
return sigUtil.signTypedData(this.wallet.getPrivateKey(), { data });
}
function generateSignature(privateKey: string, data: any) {
let pk = ethJsUtil.toBuffer(privateKey)
return sigUtil.signTypedData(pk, {
data,
})
}