{"action":"created","comment":{"url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/comments/23572027","id":23572027,"diff_hunk":"@@ -0,0 +1,99 @@\n+/*\n+\tThis file is part of go-ethereum\n+\n+\tgo-ethereum is free software: you can redistribute it and/or modify\n+\tit under the terms of the GNU Lesser General Public License as published by\n+\tthe Free Software Foundation, either version 3 of the License, or\n+\t(at your option) any later version.\n+\n+\tgo-ethereum is distributed in the hope that it will be useful,\n+\tbut WITHOUT ANY WARRANTY; without even the implied warranty of\n+\tMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+\tGNU General Public License for more details.\n+\n+\tYou should have received a copy of the GNU Lesser General Public License\n+\talong with go-ethereum.  If not, see <http://www.gnu.org/licenses/>.\n+*/\n+/**\n+ * @authors\n+ * \tGustav Simonsson <gustav.simonsson@gmail.com>\n+ * @date 2015\n+ *\n+ */\n+/*\n+\n+This abstracts part of a user's interaction with an account she controls.\n+It's not an abstraction of core Ethereum accounts data type / logic -\n+for that see the core processing code of blocks / txs.\n+\n+Currently this is pretty much a passthrough to the KeyStore2 interface,\n+and accounts persistence is derived from stored keys' addresses\n+\n+*/\n+package accounts\n+\n+import (\n+\tcrand \"crypto/rand\"\n+\t\"github.com/ethereum/go-ethereum/crypto\"\n+\t\"github.com/ethereum/go-ethereum/crypto/secp256k1\"\n+)\n+\n+// TODO: better name for this struct?\n+type UserAccount struct {\n+\tAddr []byte\n+}\n+\n+type AccountManager struct {\n+\tkeyStore crypto.KeyStore2\n+}\n+\n+// TODO: get key by addr - modify KeyStore2 GetKey to work with addr\n+\n+// TODO: pass through passphrase for APIs which require access to private key?\n+func NewAccountManager(keyStore crypto.KeyStore2) AccountManager {\n+\tam := &AccountManager{\n+\t\tkeyStore: keyStore,\n+\t}\n+\treturn *am\n+}\n+\n+func (am *AccountManager) Sign(fromAddr []byte, keyAuth string, toSign []byte) (signature []byte, err error) {\n+\tkey, err := am.keyStore.GetKey(fromAddr, keyAuth)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tprivKey := crypto.FromECDSA(key.PrivateKey)\n+\t// TODO: what is second value?\n+\tsignature, err = secp256k1.Sign(toSign, privKey)\n+\treturn signature, err\n+}\n+\n+func (am AccountManager) NewAccount(auth string) (*UserAccount, error) {\n+\tkey, err := am.keyStore.GenerateNewKey(crand.Reader, auth)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tua := &UserAccount{\n+\t\tAddr: key.Address,\n+\t}\n+\treturn ua, err\n+}\n+\n+// set of accounts == set of keys in given key store\n+// TODO: do we need persistence of accounts as well?\n+func (am *AccountManager) Accounts() ([]UserAccount, error) {\n+\taddresses, err := am.keyStore.GetKeyAddresses()\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\taccounts := make([]UserAccount, len(addresses))\n+\n+\tfor i, addr := range addresses {\n+\t\tua := &UserAccount{\n+\t\t\tAddr: addr,\n+\t\t}\n+\t\taccounts[i] = *ua","path":"accounts/account_manager.go","position":96,"original_position":96,"commit_id":"512ffa2bf4308b44aa6f43f25238b375b58d7dbc","original_commit_id":"512ffa2bf4308b44aa6f43f25238b375b58d7dbc","user":{"login":"obscuren","id":6264126,"avatar_url":"https://avatars.githubusercontent.com/u/6264126?v=3","gravatar_id":"","url":"https://api.github.com/users/obscuren","html_url":"https://github.com/obscuren","followers_url":"https://api.github.com/users/obscuren/followers","following_url":"https://api.github.com/users/obscuren/following{/other_user}","gists_url":"https://api.github.com/users/obscuren/gists{/gist_id}","starred_url":"https://api.github.com/users/obscuren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/obscuren/subscriptions","organizations_url":"https://api.github.com/users/obscuren/orgs","repos_url":"https://api.github.com/users/obscuren/repos","events_url":"https://api.github.com/users/obscuren/events{/privacy}","received_events_url":"https://api.github.com/users/obscuren/received_events","type":"User","site_admin":false},"body":"??? assign a non ptr directly to the `accounts[i]` instead of dereferencing the ptr ","created_at":"2015-01-26T22:51:44Z","updated_at":"2015-01-26T22:51:44Z","html_url":"https://github.com/ethereum/go-ethereum/pull/273#discussion_r23572027","pull_request_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/273","_links":{"self":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/comments/23572027"},"html":{"href":"https://github.com/ethereum/go-ethereum/pull/273#discussion_r23572027"},"pull_request":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/273"}}},"pull_request":{"url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/273","id":28065944,"html_url":"https://github.com/ethereum/go-ethereum/pull/273","diff_url":"https://github.com/ethereum/go-ethereum/pull/273.diff","patch_url":"https://github.com/ethereum/go-ethereum/pull/273.patch","issue_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/273","number":273,"state":"open","locked":false,"title":" Add accounts package and refactor key stores","user":{"login":"Gustav-Simonsson","id":293096,"avatar_url":"https://avatars.githubusercontent.com/u/293096?v=3","gravatar_id":"","url":"https://api.github.com/users/Gustav-Simonsson","html_url":"https://github.com/Gustav-Simonsson","followers_url":"https://api.github.com/users/Gustav-Simonsson/followers","following_url":"https://api.github.com/users/Gustav-Simonsson/following{/other_user}","gists_url":"https://api.github.com/users/Gustav-Simonsson/gists{/gist_id}","starred_url":"https://api.github.com/users/Gustav-Simonsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gustav-Simonsson/subscriptions","organizations_url":"https://api.github.com/users/Gustav-Simonsson/orgs","repos_url":"https://api.github.com/users/Gustav-Simonsson/repos","events_url":"https://api.github.com/users/Gustav-Simonsson/events{/privacy}","received_events_url":"https://api.github.com/users/Gustav-Simonsson/received_events","type":"User","site_admin":false},"body":"* Add initial UserAccount and AccountManager structs\r\n* Add NewAccount, Sign and Accounts functions\r\n* Refactor key stores to use key address as main identifier\r\n  while keeping the UUID.\r\n* Use key address as file/dir names instead of UUID","created_at":"2015-01-26T22:24:27Z","updated_at":"2015-01-26T22:51:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0ac128feab179baa4d91a5bd4598142844c4e417","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/273/commits","review_comments_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/273/comments","review_comment_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/273/comments","statuses_url":"https://api.github.com/repos/ethereum/go-ethereum/statuses/512ffa2bf4308b44aa6f43f25238b375b58d7dbc","head":{"label":"Gustav-Simonsson:key_store_and_accounts_integration","ref":"key_store_and_accounts_integration","sha":"512ffa2bf4308b44aa6f43f25238b375b58d7dbc","user":{"login":"Gustav-Simonsson","id":293096,"avatar_url":"https://avatars.githubusercontent.com/u/293096?v=3","gravatar_id":"","url":"https://api.github.com/users/Gustav-Simonsson","html_url":"https://github.com/Gustav-Simonsson","followers_url":"https://api.github.com/users/Gustav-Simonsson/followers","following_url":"https://api.github.com/users/Gustav-Simonsson/following{/other_user}","gists_url":"https://api.github.com/users/Gustav-Simonsson/gists{/gist_id}","starred_url":"https://api.github.com/users/Gustav-Simonsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gustav-Simonsson/subscriptions","organizations_url":"https://api.github.com/users/Gustav-Simonsson/orgs","repos_url":"https://api.github.com/users/Gustav-Simonsson/repos","events_url":"https://api.github.com/users/Gustav-Simonsson/events{/privacy}","received_events_url":"https://api.github.com/users/Gustav-Simonsson/received_events","type":"User","site_admin":false},"repo":{"id":27963592,"name":"go-ethereum","full_name":"Gustav-Simonsson/go-ethereum","owner":{"login":"Gustav-Simonsson","id":293096,"avatar_url":"https://avatars.githubusercontent.com/u/293096?v=3","gravatar_id":"","url":"https://api.github.com/users/Gustav-Simonsson","html_url":"https://github.com/Gustav-Simonsson","followers_url":"https://api.github.com/users/Gustav-Simonsson/followers","following_url":"https://api.github.com/users/Gustav-Simonsson/following{/other_user}","gists_url":"https://api.github.com/users/Gustav-Simonsson/gists{/gist_id}","starred_url":"https://api.github.com/users/Gustav-Simonsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gustav-Simonsson/subscriptions","organizations_url":"https://api.github.com/users/Gustav-Simonsson/orgs","repos_url":"https://api.github.com/users/Gustav-Simonsson/repos","events_url":"https://api.github.com/users/Gustav-Simonsson/events{/privacy}","received_events_url":"https://api.github.com/users/Gustav-Simonsson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Gustav-Simonsson/go-ethereum","description":"Ethereum Go - Mist (Ether Browser)","fork":true,"url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum","forks_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/forks","keys_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/teams","hooks_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/hooks","issue_events_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/issues/events{/number}","events_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/events","assignees_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/assignees{/user}","branches_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/branches{/branch}","tags_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/tags","blobs_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/git/refs{/sha}","trees_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/statuses/{sha}","languages_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/languages","stargazers_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/stargazers","contributors_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/contributors","subscribers_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/subscribers","subscription_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/subscription","commits_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/commits{/sha}","git_commits_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/git/commits{/sha}","comments_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/comments{/number}","issue_comment_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/issues/comments/{number}","contents_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/contents/{+path}","compare_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/merges","archive_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/downloads","issues_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/issues{/number}","pulls_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/pulls{/number}","milestones_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/milestones{/number}","notifications_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/labels{/name}","releases_url":"https://api.github.com/repos/Gustav-Simonsson/go-ethereum/releases{/id}","created_at":"2014-12-13T14:48:30Z","updated_at":"2015-01-19T23:50:05Z","pushed_at":"2015-01-26T22:23:07Z","git_url":"git://github.com/Gustav-Simonsson/go-ethereum.git","ssh_url":"git@github.com:Gustav-Simonsson/go-ethereum.git","clone_url":"https://github.com/Gustav-Simonsson/go-ethereum.git","svn_url":"https://github.com/Gustav-Simonsson/go-ethereum","homepage":"","size":13523,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"ethereum:develop","ref":"develop","sha":"48083608b513d97d9db10bbfdabb6e5f8830f08a","user":{"login":"ethereum","id":6250754,"avatar_url":"https://avatars.githubusercontent.com/u/6250754?v=3","gravatar_id":"","url":"https://api.github.com/users/ethereum","html_url":"https://github.com/ethereum","followers_url":"https://api.github.com/users/ethereum/followers","following_url":"https://api.github.com/users/ethereum/following{/other_user}","gists_url":"https://api.github.com/users/ethereum/gists{/gist_id}","starred_url":"https://api.github.com/users/ethereum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethereum/subscriptions","organizations_url":"https://api.github.com/users/ethereum/orgs","repos_url":"https://api.github.com/users/ethereum/repos","events_url":"https://api.github.com/users/ethereum/events{/privacy}","received_events_url":"https://api.github.com/users/ethereum/received_events","type":"Organization","site_admin":false},"repo":{"id":15452919,"name":"go-ethereum","full_name":"ethereum/go-ethereum","owner":{"login":"ethereum","id":6250754,"avatar_url":"https://avatars.githubusercontent.com/u/6250754?v=3","gravatar_id":"","url":"https://api.github.com/users/ethereum","html_url":"https://github.com/ethereum","followers_url":"https://api.github.com/users/ethereum/followers","following_url":"https://api.github.com/users/ethereum/following{/other_user}","gists_url":"https://api.github.com/users/ethereum/gists{/gist_id}","starred_url":"https://api.github.com/users/ethereum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethereum/subscriptions","organizations_url":"https://api.github.com/users/ethereum/orgs","repos_url":"https://api.github.com/users/ethereum/repos","events_url":"https://api.github.com/users/ethereum/events{/privacy}","received_events_url":"https://api.github.com/users/ethereum/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ethereum/go-ethereum","description":"Jeffrey Wilcke's Go implementation of the Ethereum y/w paper","fork":false,"url":"https://api.github.com/repos/ethereum/go-ethereum","forks_url":"https://api.github.com/repos/ethereum/go-ethereum/forks","keys_url":"https://api.github.com/repos/ethereum/go-ethereum/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ethereum/go-ethereum/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ethereum/go-ethereum/teams","hooks_url":"https://api.github.com/repos/ethereum/go-ethereum/hooks","issue_events_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/events{/number}","events_url":"https://api.github.com/repos/ethereum/go-ethereum/events","assignees_url":"https://api.github.com/repos/ethereum/go-ethereum/assignees{/user}","branches_url":"https://api.github.com/repos/ethereum/go-ethereum/branches{/branch}","tags_url":"https://api.github.com/repos/ethereum/go-ethereum/tags","blobs_url":"https://api.github.com/repos/ethereum/go-ethereum/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ethereum/go-ethereum/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ethereum/go-ethereum/git/refs{/sha}","trees_url":"https://api.github.com/repos/ethereum/go-ethereum/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ethereum/go-ethereum/statuses/{sha}","languages_url":"https://api.github.com/repos/ethereum/go-ethereum/languages","stargazers_url":"https://api.github.com/repos/ethereum/go-ethereum/stargazers","contributors_url":"https://api.github.com/repos/ethereum/go-ethereum/contributors","subscribers_url":"https://api.github.com/repos/ethereum/go-ethereum/subscribers","subscription_url":"https://api.github.com/repos/ethereum/go-ethereum/subscription","commits_url":"https://api.github.com/repos/ethereum/go-ethereum/commits{/sha}","git_commits_url":"https://api.github.com/repos/ethereum/go-ethereum/git/commits{/sha}","comments_url":"https://api.github.com/repos/ethereum/go-ethereum/comments{/number}","issue_comment_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/comments/{number}","contents_url":"https://api.github.com/repos/ethereum/go-ethereum/contents/{+path}","compare_url":"https://api.github.com/repos/ethereum/go-ethereum/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ethereum/go-ethereum/merges","archive_url":"https://api.github.com/repos/ethereum/go-ethereum/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ethereum/go-ethereum/downloads","issues_url":"https://api.github.com/repos/ethereum/go-ethereum/issues{/number}","pulls_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls{/number}","milestones_url":"https://api.github.com/repos/ethereum/go-ethereum/milestones{/number}","notifications_url":"https://api.github.com/repos/ethereum/go-ethereum/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ethereum/go-ethereum/labels{/name}","releases_url":"https://api.github.com/repos/ethereum/go-ethereum/releases{/id}","created_at":"2013-12-26T13:05:46Z","updated_at":"2015-01-25T15:52:52Z","pushed_at":"2015-01-24T18:09:33Z","git_url":"git://github.com/ethereum/go-ethereum.git","ssh_url":"git@github.com:ethereum/go-ethereum.git","clone_url":"https://github.com/ethereum/go-ethereum.git","svn_url":"https://github.com/ethereum/go-ethereum","homepage":"","size":18296,"stargazers_count":306,"watchers_count":306,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":83,"mirror_url":null,"open_issues_count":37,"forks":83,"open_issues":37,"watchers":306,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/273"},"html":{"href":"https://github.com/ethereum/go-ethereum/pull/273"},"issue":{"href":"https://api.github.com/repos/ethereum/go-ethereum/issues/273"},"comments":{"href":"https://api.github.com/repos/ethereum/go-ethereum/issues/273/comments"},"review_comments":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/273/comments"},"review_comment":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/273/commits"},"statuses":{"href":"https://api.github.com/repos/ethereum/go-ethereum/statuses/512ffa2bf4308b44aa6f43f25238b375b58d7dbc"}}}}