weijiekoh / eip712-signing-demo Goto Github PK
View Code? Open in Web Editor NEWDemonstrates MetaMask's eip_signTypedData_v3 feature
Home Page: https://weijiekoh.github.io/eip712-signing-demo/index.html
License: The Unlicense
Demonstrates MetaMask's eip_signTypedData_v3 feature
Home Page: https://weijiekoh.github.io/eip712-signing-demo/index.html
License: The Unlicense
Console shows RPC error.
Can be reproduced by installing both extensions and switching between them, each time reloading the site.
https://medium.com/metamask/eip712-is-coming-what-to-expect-and-how-to-use-it-bb92fd1a7a26 There is no explanation of what exactly happens in the contract. I created data for my situation. In Javascript, the signature is created correctly and checked correctly, there are no problems with it. But in the contract, I always get FALSE. Can anyone explain me, what wrong in contract?
My JS data structure for tests:
`const domain = [{
name: "name",
type: "string"
}, {
name: "version",
type: "string"
}, {
name: "chainId",
type: "uint256"
}];
const userscore = [{
name: "user",
type: "address"
}, {
name: "score",
type: "uint256"
}, {
name: "id",
type: "uint256"
}, {
name: "expire",
type: "uint256"
}];
// Data
const domainData = {
name: "Simple Dapp",
version: "1",
chainId: 1,
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
};
var message = {
user: "0xe0428E45F41ae8a46284A9B64AB27e0B15A2eAF7",
score: 20,
id: 1,
expire: 20
};
let msgParams = JSON.stringify({
types: {
EIP712Domain: domain,
UserScore: userscore
},
domain: domainData,
primaryType: "UserScore",
message: message
})`
And my contract code, with correct address, r, s, v and another things.
`pragma experimental ABIEncoderV2;
pragma solidity ^0.5.0;
contract Verifier {
uint256 constant chainId = 1;
string private constant EIP712_DOMAIN = "EIP712Domain(string name,string version,uint256 chainId)";
string private constant USERSCORE_TYPE = "UserScore(address user,uint256 score,uint256 id,uint256 time)";
bytes32 private constant EIP712_DOMAIN_TYPEHASH = keccak256(abi.encodePacked(EIP712_DOMAIN));
bytes32 private constant USERSCORE_TYPEHASH = keccak256(abi.encodePacked(USERSCORE_TYPE));
bytes32 private constant DOMAIN_SEPARATOR = keccak256(abi.encode(
EIP712_DOMAIN_TYPEHASH,
keccak256("Simple Dapp"),
keccak256("1"),
chainId
));
struct UserScore {
address user;
uint256 score;
uint256 id;
uint256 time;
}
function hashUserScore(UserScore memory userscore) private pure returns (bytes32){
return keccak256(abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
keccak256(abi.encode(
USERSCORE_TYPEHASH,
userscore.user,
userscore.score,
userscore.id,
userscore.time
))
));
}
function verify() public pure returns (bool) {
UserScore memory userscore = UserScore({
user: 0xe0428E45F41ae8a46284A9B64AB27e0B15A2eAF7,
score: 20,
id: 1,
time: 20
});
bytes32 sigR = 0x1443eafac538e7a767cbc1308e34ef088734b7e59dcd25baedace361a4356be1;
bytes32 sigS = 0x2fd582b765b7cf85c3137c06dbfbfb58f02a2a891cc8c78bb4f781888d5a2a7e;
uint8 sigV = 28;
address signer = 0xe0428E45F41ae8a46284A9B64AB27e0B15A2eAF7;
return signer == ecrecover(hashUserScore(userscore), sigV, sigR, sigS);
}
}`
The sample is working with 4.14 at least, probably also newer versions, would be nice to have this mentioned in the README.
The example is very useful.
It would be very useful to also have a function which verifies the validity of the signature in Javascript.
The sample is working with 4.14 at least, probably also newer versions, would be nice to have this mentioned in the README, currently it recommends 4.10 still.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.