Skip to content

Commit

Permalink
Migrate getPermitParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
kronosapiens committed Dec 7, 2023
1 parent f2f16ba commit 65ec64b
Show file tree
Hide file tree
Showing 5 changed files with 3,821 additions and 1,085 deletions.
9 changes: 6 additions & 3 deletions helpers/test-data-generator.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* globals artifacts */

const BN = require("bn.js");
const { signTypedData_v4: signTypedData } = require("eth-sig-util");

const { UINT256_MAX, MANAGER_PAYOUT, EVALUATOR_PAYOUT, WORKER_PAYOUT, INITIAL_FUNDING, SLOT0, SLOT1, SLOT2, ADDRESS_ZERO } = require("./constants");

const { getTokenArgs, web3GetAccounts, getChildSkillIndex, web3SignTypedData } = require("./test-helper");
const { getTokenArgs, web3GetAccounts, getChildSkillIndex } = require("./test-helper");

const IColony = artifacts.require("IColony");
const IMetaColony = artifacts.require("IMetaColony");
Expand Down Expand Up @@ -323,7 +325,7 @@ exports.getMetaTransactionParameters = async function getMetaTransactionParamete
return { r, s, v };
};

exports.getPermitParameters = async function getPermitParameters(owner, spender, amount, deadline, targetAddress) {
exports.getPermitParameters = async function getPermitParameters(owner, privateKey, spender, amount, deadline, targetAddress) {
const contract = await MetaTxToken.at(targetAddress);
const nonce = await contract.nonces(owner);
const multichain = await MultiChain.new();
Expand Down Expand Up @@ -389,7 +391,8 @@ exports.getPermitParameters = async function getPermitParameters(owner, spender,
},
};

const sig = await web3SignTypedData(owner, sigObject);
const privateKeyArray = new Uint8Array(Buffer.from(privateKey.slice(2), "hex"));
const sig = signTypedData(privateKeyArray, { data: sigObject });

const r = `0x${sig.substring(2, 66)}`;
const s = `0x${sig.substring(66, 130)}`;
Expand Down
16 changes: 0 additions & 16 deletions helpers/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,6 @@ exports.web3GetChainId = async function web3GetChainId() {
});
};

exports.web3SignTypedData = function web3SignTypedData(address, typedData) {
const packet = {
jsonrpc: "2.0",
method: "eth_signTypedData",
params: [address, typedData],
id: new Date().getTime(),
};

return new Promise((resolve, reject) => {
web3.currentProvider.send(packet, (err, res) => {
if (err !== null) return reject(err);
return resolve(res.result);
});
});
};

exports.web3GetRawCall = function web3GetRawCall(params, blockTag) {
const packet = {
jsonrpc: "2.0",
Expand Down
Loading

0 comments on commit 65ec64b

Please sign in to comment.