Created
November 27, 2019 13:28
-
-
Save ptsayli/49a9e02f97121adf3450c8da1d6d4301 to your computer and use it in GitHub Desktop.
Test eth_signTypedData
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
import signUtil from "eth-sig-util" | |
const getLoginTypedData = ({ address, timestamp, primaryType }) => ({ | |
types: { | |
EIP712Domain: [ | |
{ name: 'name', type: 'string' }, | |
{ name: 'host', type: 'string' }, | |
{ name: 'version', type: 'string' }, | |
], | |
WebLogin: [ | |
{ name: 'address', type: 'address' }, | |
{ name: 'timestamp', type: 'uint256' }, | |
], | |
}, | |
domain: { | |
name: 'Wallet web', | |
host: 'https://wallet.matic.network', | |
version: '1', | |
}, | |
primaryType, | |
message: { | |
address, | |
timestamp, | |
}, | |
}) | |
// Sign Message | |
const signedMsg = sigUtil.signTypedData(privKeybuffer, { | |
data: getLoginTypedData({ address, timestamp, primaryType: 'WebLogin' }), | |
}) | |
// recover from signedMessage | |
const recovered = signUtil.recoverTypedSignature({ | |
data: getLoginTypedData(address, timestamp), | |
sig: signedMessage | |
}) | |
if (recovered && recovered === address) { | |
console.log("valid") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment