{"action":"created","comment":{"url":"https://api.github.com/repos/NebulousLabs/Sia/pulls/comments/40980702","id":40980702,"diff_hunk":"@@ -25,26 +25,74 @@ var (\n \tErrInvalidSignature = errors.New(\"invalid signature\")\n )\n \n-// GenerateKeyPair creates a public-secret keypair that can be used to sign and\n-// verify messages.\n-func GenerateSignatureKeys() (sk SecretKey, pk PublicKey, err error) {\n-\tvar entropy [EntropySize]byte\n-\t_, err = rand.Read(entropy[:])\n+// KeyPairGenerator allows the caller to generate public-secret key pairs.\n+type KeyPairGenerator interface {\n+\tGenerate() (SecretKey, PublicKey, error)\n+\tGenerateDeterministic(entropy [EntropySize]byte) (SecretKey, PublicKey)\n+}\n+\n+// entropySource allows the caller to retrieve an array of bytes populated to\n+// random values.\n+type entropySource interface {\n+\tgetEntropy() ([EntropySize]byte, error)\n+}\n+\n+// keyDeriver allows the caller to generate a public-secret key pair based on\n+// provided entropy.\n+type keyDeriver interface {\n+\tderiveKeyPair([EntropySize]byte) (SecretKey, PublicKey)\n+}\n+\n+// stdGenerator is an implementation of KeyPairGenerator, allowing the caller\n+// to generate public-secret key pairs.\n+type stdGenerator struct {\n+\tes entropySource\n+\tkd keyDeriver\n+}\n+\n+// Generate creates a public-secret keypair that can be used to sign and verify\n+// messages.\n+func (sg stdGenerator) Generate() (sk SecretKey, pk PublicKey, err error) {\n+\tentropy, err := sg.es.getEntropy()\n \tif err != nil {\n \t\treturn\n \t}\n-\n-\tskPointer, pkPointer := ed25519.GenerateKey(entropy)\n-\treturn *skPointer, *pkPointer, nil\n+\tsk, pk = sg.kd.deriveKeyPair(entropy)\n+\treturn sk, pk, nil\n }\n \n-// DeterministicSignatureKeys generates keys deterministically using the input\n+// GenerateDeterministic generates keys deterministically using the input\n // entropy. The input entropy must be 32 bytes in length.\n-func DeterministicSignatureKeys(entropy [EntropySize]byte) (SecretKey, PublicKey) {\n+func (sg stdGenerator) GenerateDeterministic(entropy [EntropySize]byte) (SecretKey, PublicKey) {\n+\treturn sg.kd.deriveKeyPair(entropy)\n+}\n+\n+// randSource is an implementation of entropySource that uses rand.Read to\n+// generate random bytes.\n+type randSource struct{}\n+\n+// getEntropy returns an array of bytes with random values.\n+func (rs randSource) getEntropy() (entropy [EntropySize]byte, err error) {\n+\tif _, err := rand.Read(entropy[:]); err != nil {\n+\t\treturn entropy, err\n+\t}\n+\treturn entropy, nil\n+}\n+\n+// ed25519Deriver is an implementation of keyDeriver that uses\n+// ed25519.GenerateKey to derive keys.\n+type ed25519Deriver struct{}\n+\n+// deriveKeyPair derives a public-secret key pair derived from the provided\n+// array of bytes.\n+func (ed ed25519Deriver) deriveKeyPair(entropy [EntropySize]byte) (sk SecretKey, pk PublicKey) {","path":"crypto/signatures.go","position":74,"original_position":74,"commit_id":"42eb3050dc80d1c955bf3b1a63da80dd9c136b99","original_commit_id":"42eb3050dc80d1c955bf3b1a63da80dd9c136b99","user":{"login":"mtlynch","id":7783288,"avatar_url":"https://avatars.githubusercontent.com/u/7783288?v=3","gravatar_id":"","url":"https://api.github.com/users/mtlynch","html_url":"https://github.com/mtlynch","followers_url":"https://api.github.com/users/mtlynch/followers","following_url":"https://api.github.com/users/mtlynch/following{/other_user}","gists_url":"https://api.github.com/users/mtlynch/gists{/gist_id}","starred_url":"https://api.github.com/users/mtlynch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtlynch/subscriptions","organizations_url":"https://api.github.com/users/mtlynch/orgs","repos_url":"https://api.github.com/users/mtlynch/repos","events_url":"https://api.github.com/users/mtlynch/events{/privacy}","received_events_url":"https://api.github.com/users/mtlynch/received_events","type":"User","site_admin":false},"body":"Fixed","created_at":"2015-10-01T23:54:43Z","updated_at":"2015-10-01T23:54:43Z","html_url":"https://github.com/NebulousLabs/Sia/pull/800#discussion_r40980702","pull_request_url":"https://api.github.com/repos/NebulousLabs/Sia/pulls/800","_links":{"self":{"href":"https://api.github.com/repos/NebulousLabs/Sia/pulls/comments/40980702"},"html":{"href":"https://github.com/NebulousLabs/Sia/pull/800#discussion_r40980702"},"pull_request":{"href":"https://api.github.com/repos/NebulousLabs/Sia/pulls/800"}}},"pull_request":{"url":"https://api.github.com/repos/NebulousLabs/Sia/pulls/800","id":46105507,"html_url":"https://github.com/NebulousLabs/Sia/pull/800","diff_url":"https://github.com/NebulousLabs/Sia/pull/800.diff","patch_url":"https://github.com/NebulousLabs/Sia/pull/800.patch","issue_url":"https://api.github.com/repos/NebulousLabs/Sia/issues/800","number":800,"state":"open","locked":false,"title":"Refactors crypto/signatures.go to use explicit interfaces and adds unit tests","user":{"login":"mtlynch","id":7783288,"avatar_url":"https://avatars.githubusercontent.com/u/7783288?v=3","gravatar_id":"","url":"https://api.github.com/users/mtlynch","html_url":"https://github.com/mtlynch","followers_url":"https://api.github.com/users/mtlynch/followers","following_url":"https://api.github.com/users/mtlynch/following{/other_user}","gists_url":"https://api.github.com/users/mtlynch/gists{/gist_id}","starred_url":"https://api.github.com/users/mtlynch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtlynch/subscriptions","organizations_url":"https://api.github.com/users/mtlynch/orgs","repos_url":"https://api.github.com/users/mtlynch/repos","events_url":"https://api.github.com/users/mtlynch/events{/privacy}","received_events_url":"https://api.github.com/users/mtlynch/received_events","type":"User","site_admin":false},"body":"Refactors crypto.GenerateSignatureKeys and crypto.DeterministicSignatureKeys\r\nso that they now depend on explicit interfaces.\r\n\r\nAdds unit tests to exercise the new Generate and GenerateDeterministic\r\nfunctions.","created_at":"2015-09-27T18:07:06Z","updated_at":"2015-10-01T23:54:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7ed7163a4a5a2c3ef26e62e2e91bbfd126eae305","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/NebulousLabs/Sia/pulls/800/commits","review_comments_url":"https://api.github.com/repos/NebulousLabs/Sia/pulls/800/comments","review_comment_url":"https://api.github.com/repos/NebulousLabs/Sia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/NebulousLabs/Sia/issues/800/comments","statuses_url":"https://api.github.com/repos/NebulousLabs/Sia/statuses/42eb3050dc80d1c955bf3b1a63da80dd9c136b99","head":{"label":"mtlynch:crypto-refactor","ref":"crypto-refactor","sha":"42eb3050dc80d1c955bf3b1a63da80dd9c136b99","user":{"login":"mtlynch","id":7783288,"avatar_url":"https://avatars.githubusercontent.com/u/7783288?v=3","gravatar_id":"","url":"https://api.github.com/users/mtlynch","html_url":"https://github.com/mtlynch","followers_url":"https://api.github.com/users/mtlynch/followers","following_url":"https://api.github.com/users/mtlynch/following{/other_user}","gists_url":"https://api.github.com/users/mtlynch/gists{/gist_id}","starred_url":"https://api.github.com/users/mtlynch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtlynch/subscriptions","organizations_url":"https://api.github.com/users/mtlynch/orgs","repos_url":"https://api.github.com/users/mtlynch/repos","events_url":"https://api.github.com/users/mtlynch/events{/privacy}","received_events_url":"https://api.github.com/users/mtlynch/received_events","type":"User","site_admin":false},"repo":{"id":41731429,"name":"Sia","full_name":"mtlynch/Sia","owner":{"login":"mtlynch","id":7783288,"avatar_url":"https://avatars.githubusercontent.com/u/7783288?v=3","gravatar_id":"","url":"https://api.github.com/users/mtlynch","html_url":"https://github.com/mtlynch","followers_url":"https://api.github.com/users/mtlynch/followers","following_url":"https://api.github.com/users/mtlynch/following{/other_user}","gists_url":"https://api.github.com/users/mtlynch/gists{/gist_id}","starred_url":"https://api.github.com/users/mtlynch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtlynch/subscriptions","organizations_url":"https://api.github.com/users/mtlynch/orgs","repos_url":"https://api.github.com/users/mtlynch/repos","events_url":"https://api.github.com/users/mtlynch/events{/privacy}","received_events_url":"https://api.github.com/users/mtlynch/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mtlynch/Sia","description":"Blockchain-based marketplace for file storage","fork":true,"url":"https://api.github.com/repos/mtlynch/Sia","forks_url":"https://api.github.com/repos/mtlynch/Sia/forks","keys_url":"https://api.github.com/repos/mtlynch/Sia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mtlynch/Sia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mtlynch/Sia/teams","hooks_url":"https://api.github.com/repos/mtlynch/Sia/hooks","issue_events_url":"https://api.github.com/repos/mtlynch/Sia/issues/events{/number}","events_url":"https://api.github.com/repos/mtlynch/Sia/events","assignees_url":"https://api.github.com/repos/mtlynch/Sia/assignees{/user}","branches_url":"https://api.github.com/repos/mtlynch/Sia/branches{/branch}","tags_url":"https://api.github.com/repos/mtlynch/Sia/tags","blobs_url":"https://api.github.com/repos/mtlynch/Sia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mtlynch/Sia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mtlynch/Sia/git/refs{/sha}","trees_url":"https://api.github.com/repos/mtlynch/Sia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mtlynch/Sia/statuses/{sha}","languages_url":"https://api.github.com/repos/mtlynch/Sia/languages","stargazers_url":"https://api.github.com/repos/mtlynch/Sia/stargazers","contributors_url":"https://api.github.com/repos/mtlynch/Sia/contributors","subscribers_url":"https://api.github.com/repos/mtlynch/Sia/subscribers","subscription_url":"https://api.github.com/repos/mtlynch/Sia/subscription","commits_url":"https://api.github.com/repos/mtlynch/Sia/commits{/sha}","git_commits_url":"https://api.github.com/repos/mtlynch/Sia/git/commits{/sha}","comments_url":"https://api.github.com/repos/mtlynch/Sia/comments{/number}","issue_comment_url":"https://api.github.com/repos/mtlynch/Sia/issues/comments{/number}","contents_url":"https://api.github.com/repos/mtlynch/Sia/contents/{+path}","compare_url":"https://api.github.com/repos/mtlynch/Sia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mtlynch/Sia/merges","archive_url":"https://api.github.com/repos/mtlynch/Sia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mtlynch/Sia/downloads","issues_url":"https://api.github.com/repos/mtlynch/Sia/issues{/number}","pulls_url":"https://api.github.com/repos/mtlynch/Sia/pulls{/number}","milestones_url":"https://api.github.com/repos/mtlynch/Sia/milestones{/number}","notifications_url":"https://api.github.com/repos/mtlynch/Sia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mtlynch/Sia/labels{/name}","releases_url":"https://api.github.com/repos/mtlynch/Sia/releases{/id}","created_at":"2015-09-01T10:10:44Z","updated_at":"2015-09-01T10:10:45Z","pushed_at":"2015-10-01T02:18:00Z","git_url":"git://github.com/mtlynch/Sia.git","ssh_url":"git@github.com:mtlynch/Sia.git","clone_url":"https://github.com/mtlynch/Sia.git","svn_url":"https://github.com/mtlynch/Sia","homepage":"http://siacoin.com","size":5108,"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":"master"}},"base":{"label":"NebulousLabs:master","ref":"master","sha":"0f434118ade023cf104faf3ac68d9e694c3164f9","user":{"login":"NebulousLabs","id":7471422,"avatar_url":"https://avatars.githubusercontent.com/u/7471422?v=3","gravatar_id":"","url":"https://api.github.com/users/NebulousLabs","html_url":"https://github.com/NebulousLabs","followers_url":"https://api.github.com/users/NebulousLabs/followers","following_url":"https://api.github.com/users/NebulousLabs/following{/other_user}","gists_url":"https://api.github.com/users/NebulousLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/NebulousLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NebulousLabs/subscriptions","organizations_url":"https://api.github.com/users/NebulousLabs/orgs","repos_url":"https://api.github.com/users/NebulousLabs/repos","events_url":"https://api.github.com/users/NebulousLabs/events{/privacy}","received_events_url":"https://api.github.com/users/NebulousLabs/received_events","type":"Organization","site_admin":false},"repo":{"id":25370072,"name":"Sia","full_name":"NebulousLabs/Sia","owner":{"login":"NebulousLabs","id":7471422,"avatar_url":"https://avatars.githubusercontent.com/u/7471422?v=3","gravatar_id":"","url":"https://api.github.com/users/NebulousLabs","html_url":"https://github.com/NebulousLabs","followers_url":"https://api.github.com/users/NebulousLabs/followers","following_url":"https://api.github.com/users/NebulousLabs/following{/other_user}","gists_url":"https://api.github.com/users/NebulousLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/NebulousLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NebulousLabs/subscriptions","organizations_url":"https://api.github.com/users/NebulousLabs/orgs","repos_url":"https://api.github.com/users/NebulousLabs/repos","events_url":"https://api.github.com/users/NebulousLabs/events{/privacy}","received_events_url":"https://api.github.com/users/NebulousLabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NebulousLabs/Sia","description":"Blockchain-based marketplace for file storage","fork":false,"url":"https://api.github.com/repos/NebulousLabs/Sia","forks_url":"https://api.github.com/repos/NebulousLabs/Sia/forks","keys_url":"https://api.github.com/repos/NebulousLabs/Sia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NebulousLabs/Sia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NebulousLabs/Sia/teams","hooks_url":"https://api.github.com/repos/NebulousLabs/Sia/hooks","issue_events_url":"https://api.github.com/repos/NebulousLabs/Sia/issues/events{/number}","events_url":"https://api.github.com/repos/NebulousLabs/Sia/events","assignees_url":"https://api.github.com/repos/NebulousLabs/Sia/assignees{/user}","branches_url":"https://api.github.com/repos/NebulousLabs/Sia/branches{/branch}","tags_url":"https://api.github.com/repos/NebulousLabs/Sia/tags","blobs_url":"https://api.github.com/repos/NebulousLabs/Sia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NebulousLabs/Sia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NebulousLabs/Sia/git/refs{/sha}","trees_url":"https://api.github.com/repos/NebulousLabs/Sia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NebulousLabs/Sia/statuses/{sha}","languages_url":"https://api.github.com/repos/NebulousLabs/Sia/languages","stargazers_url":"https://api.github.com/repos/NebulousLabs/Sia/stargazers","contributors_url":"https://api.github.com/repos/NebulousLabs/Sia/contributors","subscribers_url":"https://api.github.com/repos/NebulousLabs/Sia/subscribers","subscription_url":"https://api.github.com/repos/NebulousLabs/Sia/subscription","commits_url":"https://api.github.com/repos/NebulousLabs/Sia/commits{/sha}","git_commits_url":"https://api.github.com/repos/NebulousLabs/Sia/git/commits{/sha}","comments_url":"https://api.github.com/repos/NebulousLabs/Sia/comments{/number}","issue_comment_url":"https://api.github.com/repos/NebulousLabs/Sia/issues/comments{/number}","contents_url":"https://api.github.com/repos/NebulousLabs/Sia/contents/{+path}","compare_url":"https://api.github.com/repos/NebulousLabs/Sia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NebulousLabs/Sia/merges","archive_url":"https://api.github.com/repos/NebulousLabs/Sia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NebulousLabs/Sia/downloads","issues_url":"https://api.github.com/repos/NebulousLabs/Sia/issues{/number}","pulls_url":"https://api.github.com/repos/NebulousLabs/Sia/pulls{/number}","milestones_url":"https://api.github.com/repos/NebulousLabs/Sia/milestones{/number}","notifications_url":"https://api.github.com/repos/NebulousLabs/Sia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NebulousLabs/Sia/labels{/name}","releases_url":"https://api.github.com/repos/NebulousLabs/Sia/releases{/id}","created_at":"2014-10-17T17:50:25Z","updated_at":"2015-09-26T12:02:52Z","pushed_at":"2015-10-01T20:30:30Z","git_url":"git://github.com/NebulousLabs/Sia.git","ssh_url":"git@github.com:NebulousLabs/Sia.git","clone_url":"https://github.com/NebulousLabs/Sia.git","svn_url":"https://github.com/NebulousLabs/Sia","homepage":"http://siacoin.com","size":31752,"stargazers_count":96,"watchers_count":96,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":35,"forks":16,"open_issues":35,"watchers":96,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/NebulousLabs/Sia/pulls/800"},"html":{"href":"https://github.com/NebulousLabs/Sia/pull/800"},"issue":{"href":"https://api.github.com/repos/NebulousLabs/Sia/issues/800"},"comments":{"href":"https://api.github.com/repos/NebulousLabs/Sia/issues/800/comments"},"review_comments":{"href":"https://api.github.com/repos/NebulousLabs/Sia/pulls/800/comments"},"review_comment":{"href":"https://api.github.com/repos/NebulousLabs/Sia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/NebulousLabs/Sia/pulls/800/commits"},"statuses":{"href":"https://api.github.com/repos/NebulousLabs/Sia/statuses/42eb3050dc80d1c955bf3b1a63da80dd9c136b99"}}}}