Skip to content

Instantly share code, notes, and snippets.

@rasom
Last active June 29, 2017 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rasom/877378fe34e113ef762d526329f25111 to your computer and use it in GitHub Desktop.
Save rasom/877378fe34e113ef762d526329f25111 to your computer and use it in GitHub Desktop.

Key type asym (asymmetric) means that asymmetric key will be used on whisper side to encrypt message before sending, in our case it's always user's public key, this means that currently messages with asym key type are supposed to be sent from UserA to UserB directly, but not to any group of users.

Key type sym (symmetric) means that symmetric key will be used to encrypt message. Currently all symkeys are generated from passwords which are hardcoded or are groups' ids, so this is not secure and must be changed.

Type Description Key type
:message 1-1 chat message asym
:group-message group message sym (group's id)
:public-group-message public group message sym (group's id)
:ack confirms message delivery asym
:seen confirms that message was seen asym
:clock-value-request when you send a message and you’re offline,
we send :clock-value-request to obtain the information
about the :clock-value from sender
to make sure that it’s the same
asym
:clock-value ? asym
:group-invitation is sent by admin asym
:update-group currently this message is sent when some user
is removed from group, in result group's keypair is updated
asym
:add-group-identity is sent when a new user is added to group sym (group's id)
:remove-group-identity is sent when some user is removed from group (by admin),
after that :update-group with new keypair is sent
sym (group's id)
:leave-group is sent when user leaves group sym (group's id)
:contact-request - asym
:discover sym
:discoveries-request sym
:discoveries-response sym
:profile sym
:update-keys sym
:online sym

:message

{:message-id    "1498723691404-7711c1b3-411c-5e4b-a64b-dc0ab2317c5a",
 :requires-ack? true,
 :type          :message,
 :timestamp     1498723691404,
 :content       "123",
 :content-type  "text/plain",
 :clock-value   1,
 :show?         true}

:group-message

{:message-id    "1498724252836-24753a20-b67e-50ae-8fcd-95b22a1ee78b",
 :group-id      "1498723975430-5a3f18f5-189e-5966-b159-bdf837d47e58",
 :content       "{\"iv\":[2071556246,-1120403611,-1962404966,921696242],\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":[-1840979203,1955718739,-1431291835,8794767622144],\"tag\":\"75b9b052a2c2835d8ae9525bd6ae3245e879f4b4b8b510fca22b4ad142a2f10913a83c6ff87e80ef766e194d5017cd1eca6c27fb41611cf9c8d8cf3a5df8980b6959d6d66bbfc9e4cf8a6af27decc1663f60a9e201992236a9ea21b2ccab7284\"}",
 :username      nil,
 :type          :group-message,
 :show?         true,
 :clock-value   1,
 :requires-ack? true,
 :content-type  "text/plain",
 :timestamp     1498724252865}

:public-group-message

{:message-id    "1498724827175-9c097aa0-d859-5ddd-bdd1-0c83e52d930e",
 :group-id      "wow",
 :content       "123",
 :username      "Name",
 :type          :public-group-message,
 :show?         true,
 :clock-value   1,
 :requires-ack? false,
 :content-type  "text/plain",
 :timestamp     1498724827202}

:contact-request

{:message-id    "1498723171063-c3ecb16a-b3fd-5ee1-99f0-783ef7a1070c",
 :requires-ack? true,
 :type          :contact-request,
 :contact       {:name          "Yearly Onerlooked Westafricanantelope",
                 :profile-image "..."},
 ;; public key is used by UserA (who sends this request) for broadcasting changes of his profile to UserB 
 ;; (and other contacts) 
 :keypair       {:public  "..",
                 :private ".."},
 :content       nil}

:online

{:message-id    "1498723263025-a83a4fe0-eff6-518d-9348-2570d1494067",
 :requires-ack? false,
 :type          :online,
 :content       "{\"iv\":[1966114636,-1876596685,-393541684,-299376444],\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":[-1468463324,357257435,1338099857,1642960690,-1068289456,705936716,-1541701378,-565102533,26389113252352],\"tag\":\"3151bd11093fdeb90ccdf311b660386b2edb959a5c52d9ed63095fb9ac9bf3d9bdb7ce3841dce1d2820c04d43ca2548c171c4049e06e498b35e6bea3e210afd8dfb32437663e1497a8d3ed7772b72160edc69f124e69e2385ca19cfc5692c7f9\"}"}

:profile

{:message-id "1498723799459-6642807d-2b32-58cd-98d6-19359ad3d8da",
 :type       :profile,
 :timestamp  1498723799465,
 :content    "encrypted content: username, status, photo etc"}

:group-invitation

{:group-admin   "0x04e40d8b966a6644bb8ef2a5c1e170c7c0ef9ba83e8d0cb2e2f07930d092af51cdec3aab1c97b1c451460d0e3525fd5b079ab32ba1ff179fc0db2f047ddb71a703",
:message-id    "1498723975437-09f7ca06-2ffe-5067-87d0-a65d128efb31",
:contacts      ["0x0428c9d6c1aaaa8369a7c63819684f30e34396dc0907d49afeac85a0a774ccb919b3482097d992e66bcc538e7a0c6acf874c77748f396f53c0a102e10d1a37765b"
                "0x04e40d8b966a6644bb8ef2a5c1e170c7c0ef9ba83e8d0cb2e2f07930d092af51cdec3aab1c97b1c451460d0e3525fd5b079ab32ba1ff179fc0db2f047ddb71a703"],
:group-id      "1498723975430-5a3f18f5-189e-5966-b159-bdf837d47e58",
:content       nil,
:type          :group-invitation,
:requires-ack? true,
:group-name    "T",
;; this keypair is used for sending messages to all group members, so that any user could encrypt/decrypt message
:keypair       {:public  "..",
                :private ".."},
:timestamp     1498723975439}

:discoveries-request

{:message-id "1498724283011-65da6bd7-1cb0-566f-a055-27d66cbd04e4",
:type       :discoveries-request,
:content    nil}

:remove-group-dentity

{:message-id    "1498724483015-0d468376-69f5-551c-a6c1-3762f7cb9651",
:requires-ack? true,
:type          :remove-group-identity,
:identity      "0x0428c9d6c1aaaa8369a7c63819684f30e34396dc0907d49afeac85a0a774ccb919b3482097d992e66bcc538e7a0c6acf874c77748f396f53c0a102e10d1a37765b",
:group-id      "1498723975430-5a3f18f5-189e-5966-b159-bdf837d47e58",
:username      nil,
:timestamp     1498724483015,
:content       nil}

:update-group

{:group-admin   "0x04e40d8b966a6644bb8ef2a5c1e170c7c0ef9ba83e8d0cb2e2f07930d092af51cdec3aab1c97b1c451460d0e3525fd5b079ab32ba1ff179fc0db2f047ddb71a703",
:message-id    "1498725030208-c44f66bb-4d9c-5022-b992-eb663511792a",
:contacts      ("0x04e40d8b966a6644bb8ef2a5c1e170c7c0ef9ba83e8d0cb2e2f07930d092af51cdec3aab1c97b1c451460d0e3525fd5b079ab32ba1ff179fc0db2f047ddb71a703"
                 "0x0428c9d6c1aaaa8369a7c63819684f30e34396dc0907d49afeac85a0a774ccb919b3482097d992e66bcc538e7a0c6acf874c77748f396f53c0a102e10d1a37765b"),
:group-id      "1498723975430-5a3f18f5-189e-5966-b159-bdf837d47e58",
:content       nil,
:type          :update-group,
:requires-ack? true,
:group-name    "T",
:keypair       {:private "..",
                :public  ".."},
:timestamp     1498725030220}

:add-group-identity

{:message-id    "1498725030221-3a4f2890-3897-546b-8819-c240d99089a3",
:requires-ack? true,
:type          :add-group-identity,
:identity      "0x0428c9d6c1aaaa8369a7c63819684f30e34396dc0907d49afeac85a0a774ccb919b3482097d992e66bcc538e7a0c6acf874c77748f396f53c0a102e10d1a37765b", :group-id "1498723975430-5a3f18f5-189e-5966-b159-bdf837d47e58",
:username      nil,
:timestamp     1498725030222,
:content       nil}

:seen

{:message-id    "1498724483032-ef9f6889-5699-5603-9ffd-05bee945f146",
:requires-ack? false,
:type          :seen,
:group-id      "1498723975430-5a3f18f5-189e-5966-b159-bdf837d47e58",
:content       nil}

{:message-id    "1498725866330-4a77d7d9-5d18-5628-8cf4-1f7d862f5122",
:requires-ack? false,
:type          :seen,
:group-id      nil,
:content       nil}

:leave-group

{:message-id    "1498725404895-36369ea8-1403-5554-b921-c58aaa8d1e0a",
:requires-ack? true,
:type          :leave-group,
:group-id      "1498723975430-5a3f18f5-189e-5966-b159-bdf837d47e58",
:username      nil,
:timestamp     1498725404895,
:content       nil}

:discover

{:message-id "1498725562980-10a58c17-b994-5dd3-87b1-cbdc30533df0",
:type       :discover,
:status     "the #life we're given is on a thread, so wear it well",
:hashtags   ["life"],
:profile    {:name          "Name",
             :profile-image "data:image/png;base64,..."},
:content    nil}

:discoveries-response

{:message-id "1498725718717-2c483805-da99-568b-8958-1e9a54d30630",
:type       :discoveries-response,
:data       [{:message-id "1498725562980-10a58c17-b994-5dd3-87b1-cbdc30533df0",
              :name       "Name",
              :status     "the #life we're given is on a thread, so wear it well",
              :whisper-id "0x04e40d8b966a6644bb8ef2a5c1e170c7c0ef9ba83e8d0cb2e2f07930d092af51cdec3aab1c97b1c451460d0e3525fd5b079ab32ba1ff179fc0db2f047ddb71a703",
              :photo-path "data:image/png;base64,...",
              :tags       ({:name  "life",
                            :count 1}),
              :created-at 1498725562990}],
:content    nil}

:ack

{:message-id     "1498725867070-78e60ec0-266e-5dba-a9f6-e53a333f38c7",
:type           :message,
:ack?           true,
:ack-of-message "1498725866330-4a77d7d9-5d18-5628-8cf4-1f7d862f5122",
:group-id       nil,
:content        nil}

1-1 chat

  1. User can share their public key by copying it from their profile
  2. When UserB has pubkey of UserA he can send :contact-request mewssage
  3. :message is used for communication in 1-1 chat, message's content is not encrypted on clent side atm

group chat

  1. User can create a new group chat and add contacts there
  2. All contacts receive :group-invitation message which currently contains keypair (both public and private keys) so that all users can send/receive messages using this keypair (this defenetily should be changed!)
  3. :group-message is used for communication in group-chat, content is encrypted using keypair from ivitation
  4. :update-group message is sent in order to update group's keypair (currently only when any user is removed from group)
  5. :add-group-identity, :remove-group-identity,:leave-group are used to notify group members about corresponding events
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment