Skip to content

Commit

Permalink
added sig verification contract and mock api
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAnotherDevv committed Nov 15, 2024
1 parent 3aa726a commit e577812
Show file tree
Hide file tree
Showing 2,887 changed files with 282,621 additions and 0 deletions.
2 changes: 2 additions & 0 deletions solver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules\
.env
71 changes: 71 additions & 0 deletions solver/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require("dotenv").config();
const ethers = require("ethers");
const fs = require("fs");

async function main() {
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL, {
chainId: 31337,
name: "anvil-local",
ensAddress: null,
});

await provider.ready;
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
const contractJson = JSON.parse(
fs.readFileSync(
"../contracts/out/MessageVerification.sol/MessageVerification.json",
"utf8"
)
);
const contract = new ethers.Contract(
process.env.CONTRACT_ADDRESS,
contractJson.abi,
wallet
);

const prefix = "RENEW_NAME";
const messages = ["test1", "test2", "test3"];
const value = ethers.BigNumber.from("123456789");

try {
const messageHash = ethers.utils.keccak256(
ethers.utils.defaultAbiCoder.encode(
["string", "string[]", "uint256"],
[prefix, messages, value]
)
);
const signature = await wallet.signMessage(
ethers.utils.arrayify(messageHash)
);
console.log("Messages:", messages);
console.log("Value:", value.toString());
console.log("Signature:", signature);

const tx = await contract.verifyAndStoreMessage(messages, value, signature);
console.log("Transaction hash:", tx.hash);
await tx.wait();
console.log("Messages stored successfully!");

const count = await contract.getUserMessageCount(wallet.address);
console.log("Message count:", count.toString());

const [storedMessages, storedValue] = await contract.getUserMessage(
wallet.address,
count.sub(1)
);
console.log("Stored messages:", storedMessages);
console.log("Stored value:", storedValue.toString());
} catch (error) {
console.error("Error:", error);
if (error.error) {
console.error("Error details:", error.error);
}
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
1 change: 1 addition & 0 deletions solver/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e577812

Please sign in to comment.