Created
November 16, 2018 11:53
-
-
Save hgedia/36abeb1d8e766d5c9adadf260f02657e 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
/* | |
Ref : https://medium.com/metamask/eip712-is-coming-what-to-expect-and-how-to-use-it-bb92fd1a7a26 | |
Signature was created using the API eth_signTypedData_v3 | |
Address recovered via eth-sig-utils | |
*/ | |
const sigUtil = require('eth-sig-util') | |
const domain = [ | |
{ name: "name", type: "string" }, | |
{ name: "version", type: "string" }, | |
{ name: "chainId", type: "uint256" }, | |
{ name: "verifyingContract", type: "address" }, | |
{ name: "salt", type: "bytes32" }, | |
]; | |
const bid = [ | |
{ name: "amount", type: "uint256" }, | |
{ name: "bidder", type: "Identity" }, | |
]; | |
const identity = [ | |
{ name: "userId", type: "uint256" }, | |
{ name: "wallet", type: "address" }, | |
]; | |
const domainData = { | |
name: "My amazing dApp", | |
version: "2", | |
chainId: parseInt(1), | |
verifyingContract: "0x1C56346CD2A2Bf3202F771f50d3D14a367B48070", | |
salt: "0xf2d857f4a3edcb9b78b4d503bfe733db1e3f6cdc2b7971ee739626c97e86a558" | |
}; | |
var message = { | |
amount: 100, | |
bidder: { | |
userId: 323, | |
wallet: "0x3333333333333333333333333333333333333333" | |
} | |
}; | |
const data = { | |
types: { | |
EIP712Domain: domain, | |
Bid: bid, | |
Identity: identity, | |
}, | |
domain: domainData, | |
primaryType: "Bid", | |
message: message | |
}; | |
let signature = "0xabc0f807b4797694b4a98a271faa239c095ed6f56b45a78f81834dab66ec99666893ccc70f9ef119931775bfaf24c496c28472d28522bf606bca0cf0601f3d9d1b" | |
let messageParams = {} | |
messageParams.sig = signature; | |
messageParams.data = data | |
console.log(sigUtil.recoverTypedSignature(messageParams)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment