- Clone this gist and
cd
into the directory. yarn
node genTypedData.js
to print the JSON payload- Paste a signature into
verifyTypedData.js
node verifyTypedData.js
to print the signer address for the pasted signature
Last active
December 27, 2021 21:20
-
-
Save yondonfu/1a895bbbe3d8c2ff0dec9b7fb633c3a0 to your computer and use it in GitHub Desktop.
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
const { genTypedData } = require('./utils') | |
const main = async () => { | |
const payload = genTypedData() | |
console.log(JSON.stringify(payload, null, 2)) | |
} | |
main() |
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
{ | |
"name": "typed-data-encoder-example", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"dependencies": { | |
"ethers": "^5.5.2" | |
} | |
} |
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
const ethers = require('ethers') | |
const params = { | |
// Replace with the chainId of the chain that the L1Migrator is deployed on | |
chainId: 1, | |
// Replace with the address of the L1Migrator | |
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC', | |
// Replace with the address that is migrating from L1 | |
l1Addr: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC', | |
// Replace with the address to use on L2 | |
l2Addr: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC' | |
} | |
const domain = { | |
name: 'Livepeer L1Migrator', | |
version: '1', | |
chainId: params.chainId, | |
verifyingContract: params.verifyingContract | |
} | |
const types = { | |
MigrateDelegator: [ | |
{ name: 'l1Addr', type: 'address' }, | |
{ name: 'l2Addr', type: 'address' } | |
] | |
} | |
const value = { | |
l1Addr: params.l1Addr, | |
l2Addr: params.l2Addr | |
} | |
const genTypedData = () => { | |
const payload = ethers.utils._TypedDataEncoder.getPayload(domain, types, value) | |
return payload | |
} | |
module.exports = { | |
genTypedData, | |
domain, | |
types, | |
value | |
} |
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
const ethers = require('ethers') | |
const { domain, types, value } = require('./utils') | |
const main = async () => { | |
// Replace with actual signature | |
const sig = "" | |
const signer = ethers.utils.verifyTypedData(domain, types, value, sig) | |
// If l1Addr is the address signing, then the following should be equal to l1Addr after calling verifyTypedData | |
console.log(signer) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment