{"id":13629961,"url":"https://github.com/dchest/ed2curve-js","last_synced_at":"2025-06-10T10:34:45.276Z","repository":{"id":19343327,"uuid":"22582406","full_name":"dchest/ed2curve-js","owner":"dchest","description":"Convert Ed25519 signing keys into Curve25519 Diffie-Hellman keys","archived":false,"fork":false,"pushed_at":"2021-08-11T21:50:17.000Z","size":41,"stargazers_count":58,"open_issues_count":4,"forks_count":19,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-10T22:52:50.603Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dchest.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":"2014-08-03T19:56:35.000Z","updated_at":"2025-02-21T02:22:20.000Z","dependencies_parsed_at":"2022-08-28T03:21:25.845Z","dependency_job_id":null,"html_url":"https://github.com/dchest/ed2curve-js","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dchest%2Fed2curve-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dchest%2Fed2curve-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dchest%2Fed2curve-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dchest%2Fed2curve-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dchest","download_url":"https://codeload.github.com/dchest/ed2curve-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253492615,"owners_count":21916964,"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":[],"created_at":"2024-08-01T22:01:25.641Z","updated_at":"2025-05-10T22:52:56.546Z","avatar_url":"https://github.com/dchest.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"ed2curve.js\n===========\n\nConvert Ed25519 signing key pair into Curve25519 key pair suitable for\nDiffie-Hellman key exchange. This means that by exchanging only 32-byte\nEd25519 public keys users can both sign and encrypt with NaCl.\n\nNote that there's currently [no proof](http://crypto.stackexchange.com/a/3311/291)\nthat this is safe to do. It is safer to share both Ed25519 and Curve25519\npublic keys (their concatenation is 64 bytes long).\n\nWritten by Dmitry Chestnykh in 2014-2016, using public domain code from\n[TweetNaCl.js](https://github.com/dchest/tweetnacl-js). Public domain.\nNo warranty.\n\nThanks to [@CodesInChaos](https://github.com/CodesInChaos) and\n[@nightcracker](https://github.com/nightcracker) for showing how to\nconvert Edwards coordinates to Montgomery coordinates.\n\n[![Build Status](https://travis-ci.org/dchest/ed2curve-js.svg?branch=master)\n](https://travis-ci.org/dchest/ed2curve-js)\n\n\nInstallation\n------------\n\nVia NPM:\n\n    $ npm install ed2curve\n\nor just download `ed2curve.js` or `ed2curve.min.js` and include it after\n[TweetNaCl.js](https://github.com/dchest/tweetnacl-js):\n\n```html\n\u003cscript src=\"nacl.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"ed2curve.min.js\"\u003e\u003c/script\u003e\n```\n\nUsage\n-----\n\n### ed2curve.convertKeyPair(keyPair) -\u003e convertedKeyPair | null\n\nConverts the given key pair as generated by\n[TweetNaCl.js](https://github.com/dchest/tweetnacl-js)'s `nacl.sign.keyPair`\ninto a key pair suitable for operations which accept key pairs generated by\n`nacl.box.keyPair`. This function is a combination of `convertPublicKey`\nand `convertSecretKey`.\n\nReturns `null` if the public key in the given key pair is not a valid\nEd25519 public key.\n\n### ed2curve.convertPublicKey(edPublicKey) -\u003e curvePublicKey | null\n\nConverts a 32-byte Ed25519 public key into a 32-byte Curve25519 public key\nand returns it.\n\nReturns `null` if the given public key in not a valid Ed25519 public key.\n\n### ed2curve.convertSecretKey(edSecretKey) -\u003e curveSecretKey\n\nConverts a 64-byte Ed25519 secret key (or just the first 32-byte part of it,\nwhich is the secret value) into a 32-byte Curve25519 secret key and returns it.\n\n\nExample\n-------\n\n(Note: example uses [tweetnacl-util](https://github.com/dchest/tweetnacl-util-js)\nto convert bytes)\n\n```javascript\n// Generate new sign key pair.\nvar myKeyPair = nacl.sign.keyPair();\n\n// Share public key with a peer.\nconsole.log(myKeyPair.publicKey);\n\n// Receive peer's public key.\nvar theirPublicKey = // ... receive\n\n// Sign a message.\nvar message = nacl.util.decodeUTF8('Hello!');\nvar signedMessage = nacl.sign(message, myKeyPair.secretKey);\n\n// Send message to peer. They can now verify it using\n// the previously shared public key (myKeyPair.publicKey).\n// ...\n\n// Receive a signed message from peer and verify it using their public key.\nvar theirSignedMessage = // ... receive\nvar theirMessage = nacl.sign.open(theirSignedMessage, theirPublicKey);\nif (theirMessage) {\n  // ... we got the message ...\n}\n\n// Encrypt a message to their public key.\n// But first, we need to convert our secret key and their public key\n// from Ed25519 into the format accepted by Curve25519.\n//\n// Note that peers are not involved in this conversion -- all they need\n// to know is the signing public key that we already shared with them.\n\nvar theirDHPublicKey = ed2curve.convertPublicKey(theirPublicKey);\nvar myDHSecretKey = ed2curve.convertSecretKey(myKeyPair.secretKey);\n\nvar anotherMessage = nacl.util.decodeUTF8('Keep silence');\nvar encryptedMessage = nacl.box(anotherMessage, nonce, theirDHPublicKey, myDHSecretKey);\n\n// When we receive encrypted messages from peers,\n// we need to use converted keys to open them.\n\nvar theirEncryptedMessage = // ... receive\nvar decryptedMessage = nacl.box.open(theirEncryptedMessage, nonce, theirDHPublicKey, myDHSecretKey);\n```\n\nRequirements\n------------\n\n* Requires [TweetNaCl.js](https://github.com/dchest/tweetnacl-js)\n* Works in the same enviroments as it.\n\n\nOther libraries\n---------------\n\nSome other libraries that can use a single Ed/Curve25519 key:\n\n* [agl/../extra25519](https://github.com/agl/ed25519/blob/master/extra25519/extra25519.go) - Go\n  (compatible with ed2curve)\n* [CodesInChaos/../MontgomeryCurve25519](https://github.com/CodesInChaos/Chaos.NaCl/blob/master/Chaos.NaCl/MontgomeryCurve25519.cs) - C#\n  (compatible with ed2curve)\n* [nightcracker/ed25519](https://github.com/nightcracker/ed25519/blob/master/src/key_exchange.c) - C\n  (compatible with ed2curve)\n* [libsodium](https://github.com/jedisct1/libsodium) - C\n  (compatible with ed2curve)\n* [trevp/../curve_sigs](https://github.com/trevp/ref10_extract/blob/master/ed25519/additions/curve_sigs.c) - C\n  (incompatible, as it converts the opposite way, and stores a sign bit of signing public key in a signature)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdchest%2Fed2curve-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdchest%2Fed2curve-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdchest%2Fed2curve-js/lists"}