{"action":"created","comment":{"url":"https://api.github.com/repos/status-im/status-go/pulls/comments/228495795","pull_request_review_id":168783690,"id":228495795,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyODQ5NTc5NQ==","diff_hunk":"@@ -0,0 +1,51 @@\n+package typeddata\n+\n+import (\n+\t\"crypto/ecdsa\"\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"math/big\"\n+\n+\t\"github.com/ethereum/go-ethereum/common\"\n+\t\"github.com/ethereum/go-ethereum/crypto\"\n+)\n+\n+const (\n+\tchainIDKey = \"chainId\"\n+)\n+\n+var (\n+\t// x19 to avoid collision with rlp encode. x01 version byte defined in EIP-191\n+\tmessagePadding = []byte{0x19, 0x01}\n+)\n+\n+func hashToSign(typed TypedData) (rst common.Hash, err error) {","path":"services/typeddata/sign.go","position":22,"original_position":22,"commit_id":"fc54f85bd6264b21d0d4a94e4df7bc3b2c46211c","original_commit_id":"fc54f85bd6264b21d0d4a94e4df7bc3b2c46211c","user":{"login":"divan","id":880202,"node_id":"MDQ6VXNlcjg4MDIwMg==","avatar_url":"https://avatars2.githubusercontent.com/u/880202?v=4","gravatar_id":"","url":"https://api.github.com/users/divan","html_url":"https://github.com/divan","followers_url":"https://api.github.com/users/divan/followers","following_url":"https://api.github.com/users/divan/following{/other_user}","gists_url":"https://api.github.com/users/divan/gists{/gist_id}","starred_url":"https://api.github.com/users/divan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/divan/subscriptions","organizations_url":"https://api.github.com/users/divan/orgs","repos_url":"https://api.github.com/users/divan/repos","events_url":"https://api.github.com/users/divan/events{/privacy}","received_events_url":"https://api.github.com/users/divan/received_events","type":"User","site_admin":false},"body":"I found it a bit hard to map this function to the EIP doc, and confused at the beginning with `hashStruct`. Seems like `hashToSign` is what described in spec as\r\n\r\n```\r\nencode(domainSeparator : 𝔹²⁵⁶, message : 𝕊) = \"\\x19\\x01\" ‖ domainSeparator ‖ hashStruct(message)\r\n```\r\n\r\nSo maybe it can be renamed to `encode`, and, even better, be a method of `TypedData`? So the usage is:\r\n\r\n```go\r\nhash, err := typed.encode()\r\n```","created_at":"2018-10-26T11:39:48Z","updated_at":"2018-10-26T11:58:04Z","html_url":"https://github.com/status-im/status-go/pull/1250#discussion_r228495795","pull_request_url":"https://api.github.com/repos/status-im/status-go/pulls/1250","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/status-im/status-go/pulls/comments/228495795"},"html":{"href":"https://github.com/status-im/status-go/pull/1250#discussion_r228495795"},"pull_request":{"href":"https://api.github.com/repos/status-im/status-go/pulls/1250"}}},"pull_request":{"url":"https://api.github.com/repos/status-im/status-go/pulls/1250","id":224187042,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI0MTg3MDQy","html_url":"https://github.com/status-im/status-go/pull/1250","diff_url":"https://github.com/status-im/status-go/pull/1250.diff","patch_url":"https://github.com/status-im/status-go/pull/1250.patch","issue_url":"https://api.github.com/repos/status-im/status-go/issues/1250","number":1250,"state":"open","locked":false,"title":"Sign typed data implementation","user":{"login":"dshulyak","id":1964576,"node_id":"MDQ6VXNlcjE5NjQ1NzY=","avatar_url":"https://avatars2.githubusercontent.com/u/1964576?v=4","gravatar_id":"","url":"https://api.github.com/users/dshulyak","html_url":"https://github.com/dshulyak","followers_url":"https://api.github.com/users/dshulyak/followers","following_url":"https://api.github.com/users/dshulyak/following{/other_user}","gists_url":"https://api.github.com/users/dshulyak/gists{/gist_id}","starred_url":"https://api.github.com/users/dshulyak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dshulyak/subscriptions","organizations_url":"https://api.github.com/users/dshulyak/orgs","repos_url":"https://api.github.com/users/dshulyak/repos","events_url":"https://api.github.com/users/dshulyak/events{/privacy}","received_events_url":"https://api.github.com/users/dshulyak/received_events","type":"User","site_admin":false},"body":"Below is a short explanation how signing works, for more details please see original EIP https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md.\r\n\r\nHash that will be signed with account private key is prepared in a following way:\r\n\r\n`m = H(padding || domainSeparator || encodedPrimaryType)`\r\n\r\nkeccak256 is used for hashing as in every other ethereum component.\r\n\r\ntwo bytes are used for padding:\r\n0x19 - to avoid collision with rlp encoded data\r\n0x01 - version byte for structured data (defined in https://github.com/ethereum/EIPs/blob/master/EIPS/eip-191.md)\r\n\r\n`domainSeparator = H(abi.Pack(typeString(EIP712Domain), domainValues..))`\r\n\r\ntypeString(EIP712Domain) is a hash from concatenated fields of the domain. In the code it is constructed from fields that are passed to type with key EIP712Domain. Example: `EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)`.\r\n\r\ndomainValues are derived from `domain` part of the typed data in the order of fields in types \r\n\r\n`encodedPrimaryType = H(typeString(primary), primaryTypeValues...)`\r\n\r\ntypeString(primary) is hash from concatenated fields of the primary type with dependencies. Dependencies are other complex types that are a part of this typed data. For example in `Mail(Person from,Person to,string contents)Person(string name,address wallet)` - Person type is used in Mail type.\r\n\r\nstring and bytes values are hashed and the result is used as bytes32 type in place of the original value.\r\n\r\nabi in golang expects 20 bytes array for address types, to make it readable hex string used as an address value across all examples. so we just cast decode hex into 20 bytes array before abi packing.\r\n\r\nintegers (both signed/unsigned) bigger than 64 bits must be decoded into big.Int. therefore we try to cast it to string as json must encode big ints as string, and if failed fallback to integers.\r\nsmaller integers (<64) have to be casted to a concrete type, based on the size. but every integer unmarshalled as regular `int` in golang, so we cast to `int` and then cast to int with size based on the solidity type defined in fields.\r\n\r\ncloses: https://github.com/status-im/status-go/issues/1219\r\n","created_at":"2018-10-19T06:52:13Z","updated_at":"2018-10-26T11:58:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9bbeb598d901db8bfccb7fcf2d8ee8a569866d1d","assignee":null,"assignees":[],"requested_reviewers":[{"login":"pilu","id":1059,"node_id":"MDQ6VXNlcjEwNTk=","avatar_url":"https://avatars1.githubusercontent.com/u/1059?v=4","gravatar_id":"","url":"https://api.github.com/users/pilu","html_url":"https://github.com/pilu","followers_url":"https://api.github.com/users/pilu/followers","following_url":"https://api.github.com/users/pilu/following{/other_user}","gists_url":"https://api.github.com/users/pilu/gists{/gist_id}","starred_url":"https://api.github.com/users/pilu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pilu/subscriptions","organizations_url":"https://api.github.com/users/pilu/orgs","repos_url":"https://api.github.com/users/pilu/repos","events_url":"https://api.github.com/users/pilu/events{/privacy}","received_events_url":"https://api.github.com/users/pilu/received_events","type":"User","site_admin":false},{"login":"PombeirP","id":138074,"node_id":"MDQ6VXNlcjEzODA3NA==","avatar_url":"https://avatars1.githubusercontent.com/u/138074?v=4","gravatar_id":"","url":"https://api.github.com/users/PombeirP","html_url":"https://github.com/PombeirP","followers_url":"https://api.github.com/users/PombeirP/followers","following_url":"https://api.github.com/users/PombeirP/following{/other_user}","gists_url":"https://api.github.com/users/PombeirP/gists{/gist_id}","starred_url":"https://api.github.com/users/PombeirP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PombeirP/subscriptions","organizations_url":"https://api.github.com/users/PombeirP/orgs","repos_url":"https://api.github.com/users/PombeirP/repos","events_url":"https://api.github.com/users/PombeirP/events{/privacy}","received_events_url":"https://api.github.com/users/PombeirP/received_events","type":"User","site_admin":false},{"login":"adambabik","id":277870,"node_id":"MDQ6VXNlcjI3Nzg3MA==","avatar_url":"https://avatars1.githubusercontent.com/u/277870?v=4","gravatar_id":"","url":"https://api.github.com/users/adambabik","html_url":"https://github.com/adambabik","followers_url":"https://api.github.com/users/adambabik/followers","following_url":"https://api.github.com/users/adambabik/following{/other_user}","gists_url":"https://api.github.com/users/adambabik/gists{/gist_id}","starred_url":"https://api.github.com/users/adambabik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adambabik/subscriptions","organizations_url":"https://api.github.com/users/adambabik/orgs","repos_url":"https://api.github.com/users/adambabik/repos","events_url":"https://api.github.com/users/adambabik/events{/privacy}","received_events_url":"https://api.github.com/users/adambabik/received_events","type":"User","site_admin":false},{"login":"mandrigin","id":466427,"node_id":"MDQ6VXNlcjQ2NjQyNw==","avatar_url":"https://avatars0.githubusercontent.com/u/466427?v=4","gravatar_id":"","url":"https://api.github.com/users/mandrigin","html_url":"https://github.com/mandrigin","followers_url":"https://api.github.com/users/mandrigin/followers","following_url":"https://api.github.com/users/mandrigin/following{/other_user}","gists_url":"https://api.github.com/users/mandrigin/gists{/gist_id}","starred_url":"https://api.github.com/users/mandrigin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mandrigin/subscriptions","organizations_url":"https://api.github.com/users/mandrigin/orgs","repos_url":"https://api.github.com/users/mandrigin/repos","events_url":"https://api.github.com/users/mandrigin/events{/privacy}","received_events_url":"https://api.github.com/users/mandrigin/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/status-im/status-go/pulls/1250/commits","review_comments_url":"https://api.github.com/repos/status-im/status-go/pulls/1250/comments","review_comment_url":"https://api.github.com/repos/status-im/status-go/pulls/comments{/number}","comments_url":"https://api.github.com/repos/status-im/status-go/issues/1250/comments","statuses_url":"https://api.github.com/repos/status-im/status-go/statuses/fc54f85bd6264b21d0d4a94e4df7bc3b2c46211c","head":{"label":"status-im:eip712","ref":"eip712","sha":"fc54f85bd6264b21d0d4a94e4df7bc3b2c46211c","user":{"login":"status-im","id":11767950,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNzY3OTUw","avatar_url":"https://avatars1.githubusercontent.com/u/11767950?v=4","gravatar_id":"","url":"https://api.github.com/users/status-im","html_url":"https://github.com/status-im","followers_url":"https://api.github.com/users/status-im/followers","following_url":"https://api.github.com/users/status-im/following{/other_user}","gists_url":"https://api.github.com/users/status-im/gists{/gist_id}","starred_url":"https://api.github.com/users/status-im/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/status-im/subscriptions","organizations_url":"https://api.github.com/users/status-im/orgs","repos_url":"https://api.github.com/users/status-im/repos","events_url":"https://api.github.com/users/status-im/events{/privacy}","received_events_url":"https://api.github.com/users/status-im/received_events","type":"Organization","site_admin":false},"repo":{"id":61047867,"node_id":"MDEwOlJlcG9zaXRvcnk2MTA0Nzg2Nw==","name":"status-go","full_name":"status-im/status-go","private":false,"owner":{"login":"status-im","id":11767950,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNzY3OTUw","avatar_url":"https://avatars1.githubusercontent.com/u/11767950?v=4","gravatar_id":"","url":"https://api.github.com/users/status-im","html_url":"https://github.com/status-im","followers_url":"https://api.github.com/users/status-im/followers","following_url":"https://api.github.com/users/status-im/following{/other_user}","gists_url":"https://api.github.com/users/status-im/gists{/gist_id}","starred_url":"https://api.github.com/users/status-im/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/status-im/subscriptions","organizations_url":"https://api.github.com/users/status-im/orgs","repos_url":"https://api.github.com/users/status-im/repos","events_url":"https://api.github.com/users/status-im/events{/privacy}","received_events_url":"https://api.github.com/users/status-im/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/status-im/status-go","description":"The Status module that consumes go-ethereum","fork":false,"url":"https://api.github.com/repos/status-im/status-go","forks_url":"https://api.github.com/repos/status-im/status-go/forks","keys_url":"https://api.github.com/repos/status-im/status-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/status-im/status-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/status-im/status-go/teams","hooks_url":"https://api.github.com/repos/status-im/status-go/hooks","issue_events_url":"https://api.github.com/repos/status-im/status-go/issues/events{/number}","events_url":"https://api.github.com/repos/status-im/status-go/events","assignees_url":"https://api.github.com/repos/status-im/status-go/assignees{/user}","branches_url":"https://api.github.com/repos/status-im/status-go/branches{/branch}","tags_url":"https://api.github.com/repos/status-im/status-go/tags","blobs_url":"https://api.github.com/repos/status-im/status-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/status-im/status-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/status-im/status-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/status-im/status-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/status-im/status-go/statuses/{sha}","languages_url":"https://api.github.com/repos/status-im/status-go/languages","stargazers_url":"https://api.github.com/repos/status-im/status-go/stargazers","contributors_url":"https://api.github.com/repos/status-im/status-go/contributors","subscribers_url":"https://api.github.com/repos/status-im/status-go/subscribers","subscription_url":"https://api.github.com/repos/status-im/status-go/subscription","commits_url":"https://api.github.com/repos/status-im/status-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/status-im/status-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/status-im/status-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/status-im/status-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/status-im/status-go/contents/{+path}","compare_url":"https://api.github.com/repos/status-im/status-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/status-im/status-go/merges","archive_url":"https://api.github.com/repos/status-im/status-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/status-im/status-go/downloads","issues_url":"https://api.github.com/repos/status-im/status-go/issues{/number}","pulls_url":"https://api.github.com/repos/status-im/status-go/pulls{/number}","milestones_url":"https://api.github.com/repos/status-im/status-go/milestones{/number}","notifications_url":"https://api.github.com/repos/status-im/status-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/status-im/status-go/labels{/name}","releases_url":"https://api.github.com/repos/status-im/status-go/releases{/id}","deployments_url":"https://api.github.com/repos/status-im/status-go/deployments","created_at":"2016-06-13T15:32:03Z","updated_at":"2018-10-26T08:44:14Z","pushed_at":"2018-10-26T08:44:11Z","git_url":"git://github.com/status-im/status-go.git","ssh_url":"git@github.com:status-im/status-go.git","clone_url":"https://github.com/status-im/status-go.git","svn_url":"https://github.com/status-im/status-go","homepage":"https://status.im","size":44595,"stargazers_count":459,"watchers_count":459,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":138,"mirror_url":null,"archived":false,"open_issues_count":41,"license":{"key":"mpl-2.0","name":"Mozilla Public License 2.0","spdx_id":"MPL-2.0","url":"https://api.github.com/licenses/mpl-2.0","node_id":"MDc6TGljZW5zZTE0"},"forks":138,"open_issues":41,"watchers":459,"default_branch":"develop"}},"base":{"label":"status-im:develop","ref":"develop","sha":"29b55bd44517d78f6e697de805348ee1a5b6c6e2","user":{"login":"status-im","id":11767950,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNzY3OTUw","avatar_url":"https://avatars1.githubusercontent.com/u/11767950?v=4","gravatar_id":"","url":"https://api.github.com/users/status-im","html_url":"https://github.com/status-im","followers_url":"https://api.github.com/users/status-im/followers","following_url":"https://api.github.com/users/status-im/following{/other_user}","gists_url":"https://api.github.com/users/status-im/gists{/gist_id}","starred_url":"https://api.github.com/users/status-im/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/status-im/subscriptions","organizations_url":"https://api.github.com/users/status-im/orgs","repos_url":"https://api.github.com/users/status-im/repos","events_url":"https://api.github.com/users/status-im/events{/privacy}","received_events_url":"https://api.github.com/users/status-im/received_events","type":"Organization","site_admin":false},"repo":{"id":61047867,"node_id":"MDEwOlJlcG9zaXRvcnk2MTA0Nzg2Nw==","name":"status-go","full_name":"status-im/status-go","private":false,"owner":{"login":"status-im","id":11767950,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNzY3OTUw","avatar_url":"https://avatars1.githubusercontent.com/u/11767950?v=4","gravatar_id":"","url":"https://api.github.com/users/status-im","html_url":"https://github.com/status-im","followers_url":"https://api.github.com/users/status-im/followers","following_url":"https://api.github.com/users/status-im/following{/other_user}","gists_url":"https://api.github.com/users/status-im/gists{/gist_id}","starred_url":"https://api.github.com/users/status-im/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/status-im/subscriptions","organizations_url":"https://api.github.com/users/status-im/orgs","repos_url":"https://api.github.com/users/status-im/repos","events_url":"https://api.github.com/users/status-im/events{/privacy}","received_events_url":"https://api.github.com/users/status-im/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/status-im/status-go","description":"The Status module that consumes go-ethereum","fork":false,"url":"https://api.github.com/repos/status-im/status-go","forks_url":"https://api.github.com/repos/status-im/status-go/forks","keys_url":"https://api.github.com/repos/status-im/status-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/status-im/status-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/status-im/status-go/teams","hooks_url":"https://api.github.com/repos/status-im/status-go/hooks","issue_events_url":"https://api.github.com/repos/status-im/status-go/issues/events{/number}","events_url":"https://api.github.com/repos/status-im/status-go/events","assignees_url":"https://api.github.com/repos/status-im/status-go/assignees{/user}","branches_url":"https://api.github.com/repos/status-im/status-go/branches{/branch}","tags_url":"https://api.github.com/repos/status-im/status-go/tags","blobs_url":"https://api.github.com/repos/status-im/status-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/status-im/status-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/status-im/status-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/status-im/status-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/status-im/status-go/statuses/{sha}","languages_url":"https://api.github.com/repos/status-im/status-go/languages","stargazers_url":"https://api.github.com/repos/status-im/status-go/stargazers","contributors_url":"https://api.github.com/repos/status-im/status-go/contributors","subscribers_url":"https://api.github.com/repos/status-im/status-go/subscribers","subscription_url":"https://api.github.com/repos/status-im/status-go/subscription","commits_url":"https://api.github.com/repos/status-im/status-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/status-im/status-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/status-im/status-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/status-im/status-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/status-im/status-go/contents/{+path}","compare_url":"https://api.github.com/repos/status-im/status-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/status-im/status-go/merges","archive_url":"https://api.github.com/repos/status-im/status-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/status-im/status-go/downloads","issues_url":"https://api.github.com/repos/status-im/status-go/issues{/number}","pulls_url":"https://api.github.com/repos/status-im/status-go/pulls{/number}","milestones_url":"https://api.github.com/repos/status-im/status-go/milestones{/number}","notifications_url":"https://api.github.com/repos/status-im/status-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/status-im/status-go/labels{/name}","releases_url":"https://api.github.com/repos/status-im/status-go/releases{/id}","deployments_url":"https://api.github.com/repos/status-im/status-go/deployments","created_at":"2016-06-13T15:32:03Z","updated_at":"2018-10-26T08:44:14Z","pushed_at":"2018-10-26T08:44:11Z","git_url":"git://github.com/status-im/status-go.git","ssh_url":"git@github.com:status-im/status-go.git","clone_url":"https://github.com/status-im/status-go.git","svn_url":"https://github.com/status-im/status-go","homepage":"https://status.im","size":44595,"stargazers_count":459,"watchers_count":459,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":138,"mirror_url":null,"archived":false,"open_issues_count":41,"license":{"key":"mpl-2.0","name":"Mozilla Public License 2.0","spdx_id":"MPL-2.0","url":"https://api.github.com/licenses/mpl-2.0","node_id":"MDc6TGljZW5zZTE0"},"forks":138,"open_issues":41,"watchers":459,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/status-im/status-go/pulls/1250"},"html":{"href":"https://github.com/status-im/status-go/pull/1250"},"issue":{"href":"https://api.github.com/repos/status-im/status-go/issues/1250"},"comments":{"href":"https://api.github.com/repos/status-im/status-go/issues/1250/comments"},"review_comments":{"href":"https://api.github.com/repos/status-im/status-go/pulls/1250/comments"},"review_comment":{"href":"https://api.github.com/repos/status-im/status-go/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/status-im/status-go/pulls/1250/commits"},"statuses":{"href":"https://api.github.com/repos/status-im/status-go/statuses/fc54f85bd6264b21d0d4a94e4df7bc3b2c46211c"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"divan"}}