{"action":"created","comment":{"url":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls/comments/202343461","pull_request_review_id":137028016,"id":202343461,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMjM0MzQ2MQ==","diff_hunk":"@@ -0,0 +1,191 @@\n+package chat\n+\n+import (\n+\t\"encoding/hex\"\n+\t\"errors\"\n+\t\"fmt\"\n+\n+\tprekey \"github.com/Bit-Nation/panthalassa/chat/prekey\"\n+\tdb \"github.com/Bit-Nation/panthalassa/db\"\n+\tbpb \"github.com/Bit-Nation/protobuffers\"\n+\tx3dh \"github.com/Bit-Nation/x3dh\"\n+\tproto \"github.com/golang/protobuf/proto\"\n+\tdr \"github.com/tiabc/doubleratchet\"\n+\ted25519 \"golang.org/x/crypto/ed25519\"\n+)\n+\n+// send a message\n+func (c *Chat) SendMessage(receiver ed25519.PublicKey, msg bpb.PlainChatMessage) error {\n+\n+\tvar handleSendError = func(err error) error {\n+\t\tupdateError := c.messageDB.UpdateStatus(receiver, msg.MessageID, db.StatusFailedToSend)\n+\t\tif updateError != nil {\n+\t\t\treturn errors.New(fmt.Sprintf(\"failed to update status with error: %s - original error: %s\", updateError, err))\n+\t\t}\n+\t\treturn err\n+\t}\n+\n+\tvar fetchSignedPreKey = func(userIDPubKey ed25519.PublicKey) (prekey.PreKey, error) {\n+\t\tsignedPreKey, err := c.userStorage.GetSignedPreKey(receiver)\n+\t\tif err != nil {\n+\t\t\treturn prekey.PreKey{}, handleSendError(err)\n+\t\t}\n+\n+\t\t// validate signature of signed pre key\n+\t\tvalidSignature, err := signedPreKey.VerifySignature(userIDPubKey)\n+\t\tif err != nil {\n+\t\t\treturn prekey.PreKey{}, handleSendError(err)\n+\t\t}\n+\t\tif !validSignature {\n+\t\t\treturn prekey.PreKey{}, handleSendError(errors.New(\"received invalid signature for pre key bundle\"))\n+\t\t}\n+\t\treturn signedPreKey, nil\n+\t}\n+\n+\t// marshal message\n+\trawPlainMessage, err := proto.Marshal(&msg)\n+\tif err != nil {\n+\t\treturn handleSendError(err)\n+\t}\n+\n+\t// check if there is a shared secret for the receiver\n+\texist, err := c.sharedSecStorage.HasAny(receiver)\n+\tif err != nil {\n+\t\treturn handleSendError(err)\n+\t}\n+\n+\t// if we don't have a shared secret we create one\n+\tif !exist {\n+\t\t// fetch pre key bundle\n+\t\tpreKeyBundle, err := c.backend.FetchPreKeyBundle(receiver)\n+\t\tif err != nil {\n+\t\t\treturn handleSendError(err)\n+\t\t}\n+\t\t// run key agreement\n+\t\tinitializedProtocol, err := c.x3dh.CalculateSecret(preKeyBundle)\n+\t\tif err != nil {\n+\t\t\treturn handleSendError(err)\n+\t\t}\n+\t\t// persist shared secret\n+\t\tif err := c.sharedSecStorage.Put(receiver, initializedProtocol); err != nil {\n+\t\t\treturn handleSendError(err)\n+\t\t}\n+\t}\n+\n+\t// fetch shared secret\n+\tss, err := c.sharedSecStorage.GetYoungest(receiver)\n+\tif err != nil {\n+\t\treturn handleSendError(err)\n+\t}\n+\n+\thasSignedPreKey, err := c.userStorage.HasSignedPreKey(receiver)\n+\tif err != nil {\n+\t\treturn handleSendError(err)\n+\t}\n+\n+\t// fetch signed pre key of chat partner if we don't have it locally\n+\tif !hasSignedPreKey {\n+\t\terr = c.refreshSignedPreKey(receiver)\n+\t\tif err != nil {\n+\t\t\treturn handleSendError(err)\n+\t\t}\n+\t}\n+\n+\t// fetch signed pre key from storage\n+\tsignedPreKey, err := fetchSignedPreKey(receiver)\n+\tif err != nil {\n+\t\treturn handleSendError(err)\n+\t}\n+\n+\t// check if signed pre key expired\n+\texpired := signedPreKey.OlderThen(SignedPreKeyValidTimeFrame)","path":"chat/send_message.go","position":101,"original_position":101,"commit_id":"c3d5be4fe26c1387561dabea47f25555a27d252e","original_commit_id":"c3d5be4fe26c1387561dabea47f25555a27d252e","user":{"login":"borjantrajanoski","id":21329111,"node_id":"MDQ6VXNlcjIxMzI5MTEx","avatar_url":"https://avatars0.githubusercontent.com/u/21329111?v=4","gravatar_id":"","url":"https://api.github.com/users/borjantrajanoski","html_url":"https://github.com/borjantrajanoski","followers_url":"https://api.github.com/users/borjantrajanoski/followers","following_url":"https://api.github.com/users/borjantrajanoski/following{/other_user}","gists_url":"https://api.github.com/users/borjantrajanoski/gists{/gist_id}","starred_url":"https://api.github.com/users/borjantrajanoski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/borjantrajanoski/subscriptions","organizations_url":"https://api.github.com/users/borjantrajanoski/orgs","repos_url":"https://api.github.com/users/borjantrajanoski/repos","events_url":"https://api.github.com/users/borjantrajanoski/events{/privacy}","received_events_url":"https://api.github.com/users/borjantrajanoski/received_events","type":"User","site_admin":false},"body":"OlderThen should be renamed to OlderThan to be grammatically correct.","created_at":"2018-07-13T13:08:55Z","updated_at":"2018-07-13T13:08:55Z","html_url":"https://github.com/Bit-Nation/panthalassa/pull/50#discussion_r202343461","pull_request_url":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls/50","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls/comments/202343461"},"html":{"href":"https://github.com/Bit-Nation/panthalassa/pull/50#discussion_r202343461"},"pull_request":{"href":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls/50"}}},"pull_request":{"url":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls/50","id":201269205,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAxMjY5MjA1","html_url":"https://github.com/Bit-Nation/panthalassa/pull/50","diff_url":"https://github.com/Bit-Nation/panthalassa/pull/50.diff","patch_url":"https://github.com/Bit-Nation/panthalassa/pull/50.patch","issue_url":"https://api.github.com/repos/Bit-Nation/panthalassa/issues/50","number":50,"state":"open","locked":false,"title":"[chat] - send message","user":{"login":"florianlenz","id":16626192,"node_id":"MDQ6VXNlcjE2NjI2MTky","avatar_url":"https://avatars2.githubusercontent.com/u/16626192?v=4","gravatar_id":"","url":"https://api.github.com/users/florianlenz","html_url":"https://github.com/florianlenz","followers_url":"https://api.github.com/users/florianlenz/followers","following_url":"https://api.github.com/users/florianlenz/following{/other_user}","gists_url":"https://api.github.com/users/florianlenz/gists{/gist_id}","starred_url":"https://api.github.com/users/florianlenz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/florianlenz/subscriptions","organizations_url":"https://api.github.com/users/florianlenz/orgs","repos_url":"https://api.github.com/users/florianlenz/repos","events_url":"https://api.github.com/users/florianlenz/events{/privacy}","received_events_url":"https://api.github.com/users/florianlenz/received_events","type":"User","site_admin":false},"body":"added logic to send chat message","created_at":"2018-07-13T11:53:11Z","updated_at":"2018-07-13T13:08:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5d8ce04ac9f2ab830fa67e9e73fc69e21f227c87","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls/50/commits","review_comments_url":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls/50/comments","review_comment_url":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Bit-Nation/panthalassa/issues/50/comments","statuses_url":"https://api.github.com/repos/Bit-Nation/panthalassa/statuses/c3d5be4fe26c1387561dabea47f25555a27d252e","head":{"label":"Bit-Nation:feature/new_chat","ref":"feature/new_chat","sha":"c3d5be4fe26c1387561dabea47f25555a27d252e","user":{"login":"Bit-Nation","id":8449745,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0NDk3NDU=","avatar_url":"https://avatars3.githubusercontent.com/u/8449745?v=4","gravatar_id":"","url":"https://api.github.com/users/Bit-Nation","html_url":"https://github.com/Bit-Nation","followers_url":"https://api.github.com/users/Bit-Nation/followers","following_url":"https://api.github.com/users/Bit-Nation/following{/other_user}","gists_url":"https://api.github.com/users/Bit-Nation/gists{/gist_id}","starred_url":"https://api.github.com/users/Bit-Nation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bit-Nation/subscriptions","organizations_url":"https://api.github.com/users/Bit-Nation/orgs","repos_url":"https://api.github.com/users/Bit-Nation/repos","events_url":"https://api.github.com/users/Bit-Nation/events{/privacy}","received_events_url":"https://api.github.com/users/Bit-Nation/received_events","type":"Organization","site_admin":false},"repo":{"id":118786663,"node_id":"MDEwOlJlcG9zaXRvcnkxMTg3ODY2NjM=","name":"panthalassa","full_name":"Bit-Nation/panthalassa","owner":{"login":"Bit-Nation","id":8449745,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0NDk3NDU=","avatar_url":"https://avatars3.githubusercontent.com/u/8449745?v=4","gravatar_id":"","url":"https://api.github.com/users/Bit-Nation","html_url":"https://github.com/Bit-Nation","followers_url":"https://api.github.com/users/Bit-Nation/followers","following_url":"https://api.github.com/users/Bit-Nation/following{/other_user}","gists_url":"https://api.github.com/users/Bit-Nation/gists{/gist_id}","starred_url":"https://api.github.com/users/Bit-Nation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bit-Nation/subscriptions","organizations_url":"https://api.github.com/users/Bit-Nation/orgs","repos_url":"https://api.github.com/users/Bit-Nation/repos","events_url":"https://api.github.com/users/Bit-Nation/events{/privacy}","received_events_url":"https://api.github.com/users/Bit-Nation/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Bit-Nation/panthalassa","description":"Bitnation's Jurisdiction p2p-network backend, plus utils.","fork":false,"url":"https://api.github.com/repos/Bit-Nation/panthalassa","forks_url":"https://api.github.com/repos/Bit-Nation/panthalassa/forks","keys_url":"https://api.github.com/repos/Bit-Nation/panthalassa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Bit-Nation/panthalassa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Bit-Nation/panthalassa/teams","hooks_url":"https://api.github.com/repos/Bit-Nation/panthalassa/hooks","issue_events_url":"https://api.github.com/repos/Bit-Nation/panthalassa/issues/events{/number}","events_url":"https://api.github.com/repos/Bit-Nation/panthalassa/events","assignees_url":"https://api.github.com/repos/Bit-Nation/panthalassa/assignees{/user}","branches_url":"https://api.github.com/repos/Bit-Nation/panthalassa/branches{/branch}","tags_url":"https://api.github.com/repos/Bit-Nation/panthalassa/tags","blobs_url":"https://api.github.com/repos/Bit-Nation/panthalassa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Bit-Nation/panthalassa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Bit-Nation/panthalassa/git/refs{/sha}","trees_url":"https://api.github.com/repos/Bit-Nation/panthalassa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Bit-Nation/panthalassa/statuses/{sha}","languages_url":"https://api.github.com/repos/Bit-Nation/panthalassa/languages","stargazers_url":"https://api.github.com/repos/Bit-Nation/panthalassa/stargazers","contributors_url":"https://api.github.com/repos/Bit-Nation/panthalassa/contributors","subscribers_url":"https://api.github.com/repos/Bit-Nation/panthalassa/subscribers","subscription_url":"https://api.github.com/repos/Bit-Nation/panthalassa/subscription","commits_url":"https://api.github.com/repos/Bit-Nation/panthalassa/commits{/sha}","git_commits_url":"https://api.github.com/repos/Bit-Nation/panthalassa/git/commits{/sha}","comments_url":"https://api.github.com/repos/Bit-Nation/panthalassa/comments{/number}","issue_comment_url":"https://api.github.com/repos/Bit-Nation/panthalassa/issues/comments{/number}","contents_url":"https://api.github.com/repos/Bit-Nation/panthalassa/contents/{+path}","compare_url":"https://api.github.com/repos/Bit-Nation/panthalassa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Bit-Nation/panthalassa/merges","archive_url":"https://api.github.com/repos/Bit-Nation/panthalassa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Bit-Nation/panthalassa/downloads","issues_url":"https://api.github.com/repos/Bit-Nation/panthalassa/issues{/number}","pulls_url":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls{/number}","milestones_url":"https://api.github.com/repos/Bit-Nation/panthalassa/milestones{/number}","notifications_url":"https://api.github.com/repos/Bit-Nation/panthalassa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Bit-Nation/panthalassa/labels{/name}","releases_url":"https://api.github.com/repos/Bit-Nation/panthalassa/releases{/id}","deployments_url":"https://api.github.com/repos/Bit-Nation/panthalassa/deployments","created_at":"2018-01-24T15:51:44Z","updated_at":"2018-07-13T08:03:37Z","pushed_at":"2018-07-13T12:25:54Z","git_url":"git://github.com/Bit-Nation/panthalassa.git","ssh_url":"git@github.com:Bit-Nation/panthalassa.git","clone_url":"https://github.com/Bit-Nation/panthalassa.git","svn_url":"https://github.com/Bit-Nation/panthalassa","homepage":"","size":3088,"stargazers_count":5,"watchers_count":5,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"archived":false,"open_issues_count":5,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":4,"open_issues":5,"watchers":5,"default_branch":"develop"}},"base":{"label":"Bit-Nation:system_update","ref":"system_update","sha":"d02bde04bece2351ddf10cafd09594064fe6ae5e","user":{"login":"Bit-Nation","id":8449745,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0NDk3NDU=","avatar_url":"https://avatars3.githubusercontent.com/u/8449745?v=4","gravatar_id":"","url":"https://api.github.com/users/Bit-Nation","html_url":"https://github.com/Bit-Nation","followers_url":"https://api.github.com/users/Bit-Nation/followers","following_url":"https://api.github.com/users/Bit-Nation/following{/other_user}","gists_url":"https://api.github.com/users/Bit-Nation/gists{/gist_id}","starred_url":"https://api.github.com/users/Bit-Nation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bit-Nation/subscriptions","organizations_url":"https://api.github.com/users/Bit-Nation/orgs","repos_url":"https://api.github.com/users/Bit-Nation/repos","events_url":"https://api.github.com/users/Bit-Nation/events{/privacy}","received_events_url":"https://api.github.com/users/Bit-Nation/received_events","type":"Organization","site_admin":false},"repo":{"id":118786663,"node_id":"MDEwOlJlcG9zaXRvcnkxMTg3ODY2NjM=","name":"panthalassa","full_name":"Bit-Nation/panthalassa","owner":{"login":"Bit-Nation","id":8449745,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0NDk3NDU=","avatar_url":"https://avatars3.githubusercontent.com/u/8449745?v=4","gravatar_id":"","url":"https://api.github.com/users/Bit-Nation","html_url":"https://github.com/Bit-Nation","followers_url":"https://api.github.com/users/Bit-Nation/followers","following_url":"https://api.github.com/users/Bit-Nation/following{/other_user}","gists_url":"https://api.github.com/users/Bit-Nation/gists{/gist_id}","starred_url":"https://api.github.com/users/Bit-Nation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bit-Nation/subscriptions","organizations_url":"https://api.github.com/users/Bit-Nation/orgs","repos_url":"https://api.github.com/users/Bit-Nation/repos","events_url":"https://api.github.com/users/Bit-Nation/events{/privacy}","received_events_url":"https://api.github.com/users/Bit-Nation/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Bit-Nation/panthalassa","description":"Bitnation's Jurisdiction p2p-network backend, plus utils.","fork":false,"url":"https://api.github.com/repos/Bit-Nation/panthalassa","forks_url":"https://api.github.com/repos/Bit-Nation/panthalassa/forks","keys_url":"https://api.github.com/repos/Bit-Nation/panthalassa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Bit-Nation/panthalassa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Bit-Nation/panthalassa/teams","hooks_url":"https://api.github.com/repos/Bit-Nation/panthalassa/hooks","issue_events_url":"https://api.github.com/repos/Bit-Nation/panthalassa/issues/events{/number}","events_url":"https://api.github.com/repos/Bit-Nation/panthalassa/events","assignees_url":"https://api.github.com/repos/Bit-Nation/panthalassa/assignees{/user}","branches_url":"https://api.github.com/repos/Bit-Nation/panthalassa/branches{/branch}","tags_url":"https://api.github.com/repos/Bit-Nation/panthalassa/tags","blobs_url":"https://api.github.com/repos/Bit-Nation/panthalassa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Bit-Nation/panthalassa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Bit-Nation/panthalassa/git/refs{/sha}","trees_url":"https://api.github.com/repos/Bit-Nation/panthalassa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Bit-Nation/panthalassa/statuses/{sha}","languages_url":"https://api.github.com/repos/Bit-Nation/panthalassa/languages","stargazers_url":"https://api.github.com/repos/Bit-Nation/panthalassa/stargazers","contributors_url":"https://api.github.com/repos/Bit-Nation/panthalassa/contributors","subscribers_url":"https://api.github.com/repos/Bit-Nation/panthalassa/subscribers","subscription_url":"https://api.github.com/repos/Bit-Nation/panthalassa/subscription","commits_url":"https://api.github.com/repos/Bit-Nation/panthalassa/commits{/sha}","git_commits_url":"https://api.github.com/repos/Bit-Nation/panthalassa/git/commits{/sha}","comments_url":"https://api.github.com/repos/Bit-Nation/panthalassa/comments{/number}","issue_comment_url":"https://api.github.com/repos/Bit-Nation/panthalassa/issues/comments{/number}","contents_url":"https://api.github.com/repos/Bit-Nation/panthalassa/contents/{+path}","compare_url":"https://api.github.com/repos/Bit-Nation/panthalassa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Bit-Nation/panthalassa/merges","archive_url":"https://api.github.com/repos/Bit-Nation/panthalassa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Bit-Nation/panthalassa/downloads","issues_url":"https://api.github.com/repos/Bit-Nation/panthalassa/issues{/number}","pulls_url":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls{/number}","milestones_url":"https://api.github.com/repos/Bit-Nation/panthalassa/milestones{/number}","notifications_url":"https://api.github.com/repos/Bit-Nation/panthalassa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Bit-Nation/panthalassa/labels{/name}","releases_url":"https://api.github.com/repos/Bit-Nation/panthalassa/releases{/id}","deployments_url":"https://api.github.com/repos/Bit-Nation/panthalassa/deployments","created_at":"2018-01-24T15:51:44Z","updated_at":"2018-07-13T08:03:37Z","pushed_at":"2018-07-13T12:25:54Z","git_url":"git://github.com/Bit-Nation/panthalassa.git","ssh_url":"git@github.com:Bit-Nation/panthalassa.git","clone_url":"https://github.com/Bit-Nation/panthalassa.git","svn_url":"https://github.com/Bit-Nation/panthalassa","homepage":"","size":3088,"stargazers_count":5,"watchers_count":5,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"archived":false,"open_issues_count":5,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":4,"open_issues":5,"watchers":5,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls/50"},"html":{"href":"https://github.com/Bit-Nation/panthalassa/pull/50"},"issue":{"href":"https://api.github.com/repos/Bit-Nation/panthalassa/issues/50"},"comments":{"href":"https://api.github.com/repos/Bit-Nation/panthalassa/issues/50/comments"},"review_comments":{"href":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls/50/comments"},"review_comment":{"href":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Bit-Nation/panthalassa/pulls/50/commits"},"statuses":{"href":"https://api.github.com/repos/Bit-Nation/panthalassa/statuses/c3d5be4fe26c1387561dabea47f25555a27d252e"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"borjantrajanoski"}}