{"id":16252002,"url":"https://github.com/samuelmaddock/dat-social-chat","last_synced_at":"2025-03-19T20:31:11.626Z","repository":{"id":146072963,"uuid":"109551972","full_name":"samuelmaddock/dat-social-chat","owner":"samuelmaddock","description":"💬 Simple prototype distributed P2P chat app using Dat via hyperdrive for social profiles and authentication","archived":false,"fork":false,"pushed_at":"2018-02-19T20:21:39.000Z","size":126,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-17T10:51:32.943Z","etag":null,"topics":["dat","hyperdrive","p2p"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samuelmaddock.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-05T04:35:00.000Z","updated_at":"2022-01-11T15:14:27.000Z","dependencies_parsed_at":"2023-05-11T08:30:25.691Z","dependency_job_id":null,"html_url":"https://github.com/samuelmaddock/dat-social-chat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samuelmaddock%2Fdat-social-chat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samuelmaddock%2Fdat-social-chat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samuelmaddock%2Fdat-social-chat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samuelmaddock%2Fdat-social-chat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samuelmaddock","download_url":"https://codeload.github.com/samuelmaddock/dat-social-chat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244501273,"owners_count":20462834,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dat","hyperdrive","p2p"],"created_at":"2024-10-10T15:12:05.109Z","updated_at":"2025-03-19T20:31:11.614Z","avatar_url":"https://github.com/samuelmaddock.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dat Social Chat\n\nA small prototype P2P chat application built using [Electron](https://electronjs.org/) and [Dat](https://datproject.org/).\n\n![screenshot](screenshot.png)\n\n## Todo\n\n- [x] Encrypt WebRTC signaling communication\n- [x] Figure out whether UDP hole punching is needed for [discovery-swarm](https://github.com/mafintosh/discovery-swarm/issues/16)'s DHT connections\n- [ ] Fix profile name resolution in chat\n- [ ] Add [_dat.json_](https://github.com/datprotocol/dat.json) file to archive\n- [ ] Move hyperdrive into Electron's main process\n- [ ] Possibly replace `DatSocialArchive` class with [WebDB](https://github.com/beakerbrowser/webdb)\n- [ ] Support multiple chat DM threads\n- [ ] Detect online/offline status of friends\n- [ ] Don't reuse Dat key pair for authentication ([see notes](https://download.libsodium.org/doc/advanced/ed25519-curve25519.html))\n\n## Install\n```bash\nnpm install # or yarn\nnpm start\n```\n\n## Peer profiles using Dat\n\nDat is peer to peer (p2p) protocol for building distributed apps. [Hyperdrive](https://github.com/mafintosh/hyperdrive), built ontop of Dat, provides a distributed file system which peers use to upload their profile to peers.\n\nA hyperdrive archive provides its own public key which peers can use to find each other. It's a 64-character hex encoded string (e.g. `'1899b1f0a006cd0419545cb13c7f2ddc46c650e9512213a0899e5947a6a4d819'`). This means peers are hidden by default unless they distribute their public key.\n\n### profile.json\n\nThis file exists in a peer's hyperdrive archive as a way to provide public information about a peer. In this case, a peer's name.\n\n```json\n{\n    \"name\": \"Sam\"\n}\n```\n\nThis file is downloaded by peers to display a more friendly name.\n\n### friends.json\n\nEach peer maintains a list of their friend keys. Currently this is only used locally.\n\n## Chatting with WebRTC\n\nTo chat with peers, a WebRTC data channel connection is created to provide low latency, encrypted communication.\n\n### Connection overview\n\nEach local peer creates a network swarm, using [discovery-swarm](https://github.com/mafintosh/discovery-swarm), which acts as a lobby for other peers to initiate a connection. A simple challenge-response authentication process is used to verify each peer's identity. Following authentication, peers perform WebRTC signalling to create a WebRTC connection.\n\n### Authentication\n\nWhen a peer wants to connect to another peer, they need to verify each others' identity so they can be sure they're talking to the right person. This is accomplished using elliptic-curve cryptography via [libsodium](https://libsodium.org).\n\nEach peer's hyperdrive key pair is [converted from Ed25519 to Curve25519](https://download.libsodium.org/doc/advanced/ed25519-curve25519.html) to perform authenticated encryption.\n\n_See [network.js](network.js) for implementation._\n\n#### Peer (Bob) connecting to host (Alice)\n\nWhen Bob wants to connect to Alice, Bob will know Alice's public key ahead of time.\n\n1. Bob sends his public key to Alice encrypted with her public key.\n1. Alice uses her private key to decrypt Bob's public key. Alice [creates a shared key](https://download.libsodium.org/doc/key_exchange/#purpose) using Bob's public key and her private key to send an encrypted nonce to Bob.\n1. Bob creates his own shared key using Alice's public key and his private key. Bob uses the shared key to decrypt the nonce and send it back encrypted.\n1. Alice decrypts the nonce with the shared key and verifies it's the same nonce originally sent. Alice sends an authentication success message to Bob.\n\nFollowing authentication, Bob performs WebRTC signalling  over the same connection using the [steps defined in the Simple Peer library](https://github.com/feross/simple-peer#data-channels).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuelmaddock%2Fdat-social-chat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamuelmaddock%2Fdat-social-chat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuelmaddock%2Fdat-social-chat/lists"}