{"_id":"ed2curve-esm","_rev":"4579981","name":"ed2curve-esm","description":"ESM version of dchest/ed2curve Convert Ed25519 signing keys into Curve25519 Diffie-Hellman keys.","dist-tags":{"latest":"0.3.0-alpha-1"},"maintainers":[{"name":"pelleb","email":""}],"time":{"modified":"2026-04-10T15:56:45.000Z","created":"2019-03-31T19:45:14.775Z","0.3.0-alpha-1":"2019-03-31T19:45:14.775Z"},"users":{},"repository":{"type":"git","url":"git+https://github.com/pelle/ed2curve-esm.git"},"versions":{"0.3.0-alpha-1":{"name":"ed2curve-esm","description":"ESM version of dchest/ed2curve Convert Ed25519 signing keys into Curve25519 Diffie-Hellman keys.","version":"0.3.0-alpha-1","license":"Unlicense","esnext":"dist-src/index.js","main":"dist-node/index.js","module":"dist-web/index.js","types":"dist-types/index.d.ts","pika":true,"sideEffects":false,"keywords":["ed25519","curve25519","djb","crypto","public","keys","edwards","montgomery","elliptic"],"homepage":"https://github.com/dchest/ed2curve-js","bugs":{"url":"https://github.com/dchest/ed2curve-js/issues"},"repository":{"type":"git","url":"git+https://github.com/pelle/ed2curve-esm.git"},"dependencies":{"tweetnacl":"^1.0.1"},"devDependencies":{"@pika/pack":"^0.3.6","@pika/plugin-build-node":"^0.3.14","@pika/plugin-build-types":"^0.3.14","@pika/plugin-build-web":"^0.3.14","@pika/plugin-standard-pkg":"^0.3.14","faucet":"0.x.x","tape":"^4.10.1","tweetnacl-util":"^0.15.0"},"_id":"ed2curve-esm@0.3.0-alpha-1","_nodeVersion":"11.12.0","_npmVersion":"6.9.0","dist":{"shasum":"67a5722ea97976c3310aeaf0990a2b58ee383aef","size":5152,"noattachment":false,"key":"/ed2curve-esm/-/ed2curve-esm-0.3.0-alpha-1.tgz","tarball":"http://registry.cnpm.dingdandao.com/ed2curve-esm/download/ed2curve-esm-0.3.0-alpha-1.tgz"},"maintainers":[{"name":"pelleb","email":""}],"_npmUser":{"name":"pelleb","email":"pelleb@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ed2curve-esm_0.3.0-alpha-1_1554061514563_0.23793010424122873"},"_hasShrinkwrap":false,"publish_time":1554061514775,"_cnpm_publish_time":1554061514775,"_cnpmcore_publish_time":"2021-12-16T19:20:18.624Z"}},"readme":"ed2curve.js (ESM compatible version)\n===========\n\n*note:* This fork is an attempt to make a treeshakeable, typescript typed version of [ed2curve](/dchest/ed2curve-js)\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 --save ed2curve-esm\n\n```js\nimport { convertKeyPair } from 'ed2curve-esm'\n```\n\nUsage\n-----\n\n### ed2curve.convertKeyPair(keyPair) -> 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) -> 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) -> 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\nimport nacl from 'tweetnacl'\nimport naclutil from 'tweetnacl-util'\nimport * as ed2curve from 'ed2curve-esm'\n\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","_attachments":{},"homepage":"https://github.com/dchest/ed2curve-js","bugs":{"url":"https://github.com/dchest/ed2curve-js/issues"},"license":"Unlicense"}