{"id":22355526,"url":"https://github.com/zbo14/triple-double","last_synced_at":"2025-07-30T10:31:50.282Z","repository":{"id":57379987,"uuid":"298055402","full_name":"zbo14/triple-double","owner":"zbo14","description":"Create e2ee WebSocket channels with X3DH and Double Ratchet.","archived":false,"fork":false,"pushed_at":"2020-09-28T21:25:30.000Z","size":118,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-18T02:53:57.573Z","etag":null,"topics":["axolotl","diffie-hellman","double-ratchet","e2ee","encryption","end-to-end-encryption","https","https-server","signal","websocket-server","websockets","x3dh"],"latest_commit_sha":null,"homepage":"https://zachh.me/blog/ratcheting-up-double-ratchet/","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/zbo14.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}},"created_at":"2020-09-23T18:10:16.000Z","updated_at":"2023-12-24T23:30:40.000Z","dependencies_parsed_at":"2022-09-05T14:30:45.369Z","dependency_job_id":null,"html_url":"https://github.com/zbo14/triple-double","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/zbo14%2Ftriple-double","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Ftriple-double/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Ftriple-double/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Ftriple-double/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zbo14","download_url":"https://codeload.github.com/zbo14/triple-double/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227679595,"owners_count":17803119,"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":["axolotl","diffie-hellman","double-ratchet","e2ee","encryption","end-to-end-encryption","https","https-server","signal","websocket-server","websockets","x3dh"],"created_at":"2024-12-04T14:07:05.513Z","updated_at":"2024-12-04T14:07:06.113Z","avatar_url":"https://github.com/zbo14.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# triple-double\n\nCreate end-to-end encrypted WebSocket channels!\n\nThis package implements secret negotation via Extended Triple Diffie-Hellman (X3DH), allowing two peers to establish a WebSocket channel encrypted end-to-end with the [Double Ratchet Algorithm](https://en.wikipedia.org/wiki/Double_Ratchet_Algorithm) and [header encryption](https://signal.org/docs/specifications/doubleratchet/#double-ratchet-with-header-encryption).\n\n**WARNING:** this library has NOT received a formal security audit, use at your own risk.\n\n## Install\n\n`npm i triple-double`\n\n## Usage\n\n### Server\n\n#### Generate TLS certificate\n\n`npm run cert`\n\nThis generates a private key and self-signed certificate and writes them to `private/`.\n\n**Note:** the client will need the certificate to connect to the server.\n\n#### Start server\n\n`[host=] [port=] npm start`\n\n### Client\n\n#### Example\n\nThe following code snippets assume top-level `async/await` for readability purposes.\n\nA secure, out-of-band channel is needed to communicate public keys and session IDs between peers.\n\nFind the complete code in `./example.js` and run it with `npm run example`.\n\n##### Alice publishes bundle\n\nAlice only has to perform this step if:\n\n* She hasn't published her bundle yet\n* She runs out of one-time prekeys\n* She wants to publish a new signed prekey\n\nWe'll assume she hasn't published her bundle yet.\n\nSee [here](https://signal.org/docs/specifications/x3dh/#publishing-keys) for more details.\n\n```js\n// Alice's code\nconst fs = require('fs')\nconst { Client } = require('triple-double')\n\nconst ca = fs.readFileSync('/path/to/cert')\nconst host = '1.2.3.4'\nconst port = 8888\n\nconst alice = new Client({ ca, host, port })\n\nconst pubKey = await alice.publishBundle()\n\n// Send public key to Bob out-of-band\n```\n\n##### Bob sends initial message\n\nSee [here](https://signal.org/docs/specifications/x3dh/#sending-the-initial-message) for more details.\n\n```js\n// Bob's code\nconst fs = require('fs')\nconst { Client } = require('triple-double')\n\nconst ca = fs.readFileSync('/path/to/cert')\nconst host = '1.2.3.4'\nconst port = 8888\n\nconst bob = new Client({ ca, host, port })\n\nconst peerKey = Buffer.from(/* alice's public key */)\nconst plaintext = 'intial plaintext'\n\nconst sid = await bob.sendInitMessage(peerKey, plaintext)\n\n// Send session ID to alice out-of-band\n```\n\n##### Alice receives initial message\n\nSee [here](https://signal.org/docs/specifications/x3dh/#receiving-the-initial-message) for more details.\n\n```js\n// Alice's code continued\nconst plaintext = await alice.recvInitMessage('\u003csession ID from Bob\u003e')\n```\n\n##### Connect\n\nAt this point, the peers can establish a secure WebSocket channel.\n\nThis operation won't complete until *both* peers are connected.\n\n```js\n// Alice's code continued\nawait alice.connect('\u003csession ID\u003e')\n```\n\n```js\n// Bob's code continued\nawait bob.connect('\u003csession ID\u003e')\n```\n\n##### Send/receive messages\n\nAfter connecting, the peers can send messages to each other!\n\nThese messages are encrypted with Double Ratchet (including header encryption).\n\n```js\n// Alice's code continued\nalice.on('message', ({ sid, plaintext }) =\u003e {\n  if (sid === '\u003csession ID\u003e') {\n    // handle Bob's plaintext\n  }\n})\n\nalice.send('\u003csession ID\u003e', 'hello \"bob\"')\n```\n\n```js\n// Bob's code continued\nbob.on('message', ({ sid, plaintext }) =\u003e {\n  if (sid === '\u003csession ID\u003e') {\n    // handle Alice's plaintext\n  }\n})\n\nbob.send('\u003csession ID\u003e', 'hello \"alice\"')\n```\n\nAlice and Bob can establish secure channels to other peers, if they so choose.\n\n##### Disconnect\n\nOnce a peer calls `disconnect()` with the session ID, the channel closes and *both* peers receive \"disconnect\" events.\n\n```js\n// Alice's code continued\nalice.on('disconnect', sid =\u003e {\n  if (sid === '\u003csession ID\u003e') {\n    // Disconnected from Bob\n  }\n})\n\nalice.disconnect('\u003csession ID\u003e')\n```\n\n```js\n// Bob's code continued\nbob.on('disconnect', sid =\u003e {\n  if (sid === '\u003csession ID\u003e') {\n    // Disconnected from Alice\n  }\n})\n```\n\n## Docs\n\n`npm run doc`\n\nThis generates the documentation and writes it to `out/`.\n\nThen you can open `out/index.html` in your browser.\n\n## Test\n\n`npm test`\n\n## Lint\n\n`npm run lint`\n\n## Contributing\n\nGo for it! Whether it's code cleanup, a bugfix, or feature request, your input is seriously appreciated.\n\nUnsure where to start? Take a look at the code or [open an issue](https://github.com/zbo14/triple-double/issues/new).\n\n## References\n* [The Double Ratchet Algorithm](https://signal.org/docs/specifications/doubleratchet/)\n* [The X3DH Key Agreement Protocol](https://signal.org/docs/specifications/x3dh/)\n* [The XEdDSA and VXEdDSA Signature Schemes](https://signal.org/docs/specifications/xeddsa/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbo14%2Ftriple-double","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzbo14%2Ftriple-double","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbo14%2Ftriple-double/lists"}