-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added sig verification contract and mock api
- Loading branch information
1 parent
3aa726a
commit e577812
Showing
2,887 changed files
with
282,621 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules\ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.