EIP712 signing script

This commit is contained in:
Oskar Thoren 2021-01-28 12:46:56 +08:00
parent 74f76d0895
commit 42c2448e59
No known key found for this signature in database
GPG Key ID: BDB55C8C0EF29911
1 changed files with 49 additions and 0 deletions

49
scripts/sign-script.js Normal file
View File

@ -0,0 +1,49 @@
const hre = require("hardhat");
const eip712 = require("ethers-eip712");
async function main() {
const typedData = {
types: {
EIP712Domain: [
{name: "name", type: "string"},
{name: "version", type: "string"},
{name: "chainId", type: "uint256"},
{name: "verifyingContract", type: "address"},
],
Person: [
{name: "name", type: "string"},
{name: "wallet", type: "address"},
]
},
// Unexpected identifier
//primaryType: 'Person' as const,
primaryType: 'Person',
domain: {
name: 'Ether Mail',
version: '1',
chainId: 1,
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
},
message: {
'name': 'Bob',
'wallet': '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB'
}
}
const digest = eip712.TypedDataUtils.encodeDigest(typedData)
const digestHex = ethers.utils.hexlify(digest)
const wallet = ethers.Wallet.createRandom()
console.log("Wallet:", wallet);
const signature = await wallet.signMessage(digest)
console.log("Signature:", signature);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});