{"id":20102310,"url":"https://github.com/isakruas/js-ecutils","last_synced_at":"2026-02-11T03:33:18.072Z","repository":{"id":237575585,"uuid":"792573858","full_name":"isakruas/js-ecutils","owner":"isakruas","description":"JavaScript Library for Elliptic Curve Cryptography: key exchanges (Diffie-Hellman, Massey-Omura), ECDSA signatures, and Koblitz encoding. Suitable for crypto education and secure systems.","archived":false,"fork":false,"pushed_at":"2024-10-27T19:39:45.000Z","size":231,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-04T10:57:45.512Z","etag":null,"topics":["cryptographic-algorithms","diffie-hellman-key-exchange","digital-signatures","ecc-based-protocols","ecdsa","elliptic-curve-cryptography","elliptic-curve-operations","javascript-cryptography","koblitz-encoding","massey-omura-protocol","message-encoding-and-decoding","public-key-cryptography","secure-communication"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/js-ecutils","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/isakruas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-04-27T00:56:49.000Z","updated_at":"2025-01-10T15:01:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"91fe9e78-9718-4d2a-b6d8-346a98b5eab4","html_url":"https://github.com/isakruas/js-ecutils","commit_stats":null,"previous_names":["isakruas/js-ecutils"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/isakruas/js-ecutils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isakruas%2Fjs-ecutils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isakruas%2Fjs-ecutils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isakruas%2Fjs-ecutils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isakruas%2Fjs-ecutils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isakruas","download_url":"https://codeload.github.com/isakruas/js-ecutils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isakruas%2Fjs-ecutils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29326189,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T02:08:56.257Z","status":"ssl_error","status_checked_at":"2026-02-11T02:08:51.338Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cryptographic-algorithms","diffie-hellman-key-exchange","digital-signatures","ecc-based-protocols","ecdsa","elliptic-curve-cryptography","elliptic-curve-operations","javascript-cryptography","koblitz-encoding","massey-omura-protocol","message-encoding-and-decoding","public-key-cryptography","secure-communication"],"created_at":"2024-11-13T17:29:43.116Z","updated_at":"2026-02-11T03:33:18.055Z","avatar_url":"https://github.com/isakruas.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# js-ecutils\n\n**JavaScript Library for Elliptic Curve Cryptography**\n\n[![Latest Version](https://img.shields.io/npm/v/js-ecutils.svg?style=flat)](https://www.npmjs.com/package/js-ecutils)\n[![Downloads](https://img.shields.io/npm/dt/js-ecutils.svg)](https://www.npmjs.com/package/js-ecutils)\n[![Downloads](https://img.shields.io/npm/dm/js-ecutils.svg)](https://www.npmjs.com/package/js-ecutils)\n[![Downloads](https://img.shields.io/npm/dw/js-ecutils.svg)](https://www.npmjs.com/package/js-ecutils)\n[![codecov](https://codecov.io/gh/isakruas/js-ecutils/branch/master/graph/badge.svg)](https://codecov.io/gh/isakruas/js-ecutils)\n\n`js-ecutils` is a JavaScript library designed for implementing Elliptic Curve Cryptography (ECC) algorithms, including key exchanges (Diffie-Hellman, Massey-Omura), ECDSA signatures, and Koblitz encoding. This library is suitable for educational purposes in cryptography and for use in secure systems.\n\n## Features\n\n- ECDSA signatures\n- Key exchange protocols (Diffie-Hellman and Massey-Omura)\n- Koblitz encoding\n- Support for elliptic curve operations\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [API Documentation](#api-documentation)\n- [Examples](#examples)\n- [Contributing](#contributing)\n- [License](#license)\n- [Language-Specific Libraries for Elliptic Curve Cryptography](#language-specific-libraries-for-elliptic-curve-cryptography)\n\n## Installation\n\nTo install `js-ecutils`, you can use npm or include the script directly in your web application:\n\n**Using npm:**\n\n```bash\nnpm install js-ecutils\n```\n\n**Or, for web usage:**  \nInclude the following script in your HTML:\n\n```html\n\u003cscript src=\"https://unpkg.com/js-ecutils@latest/dist/web/min.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\nAfter installing the `js-ecutils` library, you can import it into your JavaScript project or use it directly in a browser. Below are the steps for using the library in both environments.\n\n### Using in Node.js\n\nTo use the library in a Node.js project, import the required modules as shown below:\n\n```javascript\n// Importing necessary classes\nconst { core: { Point, EllipticCurve } } = require('js-ecutils');\n\n// Defining parameters for the elliptic curve\nconst p = 23n;  // The prime number defining the finite field's order\nconst a = 1n;   // The 'a' coefficient in the curve equation\nconst b = 1n;   // The 'b' coefficient in the curve equation\nconst G = new Point(0n, 1n);  // Generator point\nconst n = 28n;  // Order of the point\nconst h = 1n;   // Cofactor\n\n// Creating an instance of the elliptic curve\nconst curve = new EllipticCurve(p=p, a=a, b=b, G=G, n=n, h=h);\n\n// Defining points on the curve\nconst point1 = new Point(6n, 19n);\nconst point2 = new Point(3n, 13n);\n\n// Adding the points\nconst sum_point = curve.add_points(point1, point2);\nconsole.log(`The sum of the points is (${sum_point.x}, ${sum_point.y}).`);\n```\n\n### Using in Browsers\n\nTo use the library in a browser, include the JavaScript file in your HTML and utilize the classes available in the global `ecutils` object. Add the script as shown below:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n    \u003ctitle\u003eElliptic Curve Cryptography Example\u003c/title\u003e\n    \u003cscript src=\"https://unpkg.com/js-ecutils@latest/dist/web/min.js\"\u003e\u003c/script\u003e\n    \u003cscript\u003e\n        window.onload = function() {\n            // Importing necessary classes from the global object\n            const Point = window.ecutils.core.Point;\n            const EllipticCurve = window.ecutils.core.EllipticCurve;\n\n            // Defining parameters for the elliptic curve\n            const p = 23n;\n            const a = 1n;\n            const b = 1n;\n            const G = new Point(0n, 1n);\n            const n = 28n;\n            const h = 1n;\n\n            // Creating an instance of the elliptic curve\n            const curve = new EllipticCurve(p, a, b, G, n, h);\n\n            // Defining points on the curve\n            const point1 = new Point(6n, 19n);\n            const point2 = new Point(3n, 13n);\n\n            // Adding the points\n            const sum_point = curve.add_points(point1, point2);\n            console.log(`The sum of the points is (${sum_point.x}, ${sum_point.y}).`);\n        };\n    \u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003ch1\u003eExample using js-ecutils Library\u003c/h1\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## API Documentation\n\n### Classes and Methods\n\n#### Class: `DigitalSignature`\n\n##### Constructor\n- **`new DigitalSignature(private_key, curve_name = 'secp192k1')`**\n  - Creates a new instance of the `DigitalSignature` class for performing ECDSA (Elliptic Curve Digital Signature Algorithm) operations.\n  - **Parameters**:\n    - `private_key`: The private key used for generating a signature.\n    - `curve_name`: (Optional) The name of the elliptic curve to use. Defaults to `'secp192k1'`.\n\n##### Methods\n\n- **`generate_signature(message_hash)`**\n  - Generates an ECDSA signature for a given message hash using the private key.\n  - **Parameters**:\n    - `message_hash`: The hash of the message to be signed.\n  - **Returns**: An array with two integers `[r, s]` representing the signature.\n\n- **`verify_signature(public_key, message_hash, r, s)`**\n  - Verifies the authenticity of an ECDSA signature.\n  - **Parameters**:\n    - `public_key`: The public key corresponding to the private key of the signer.\n    - `message_hash`: The hash of the message that was signed.\n    - `r`: The first component (r) of the signature.\n    - `s`: The second component (s) of the signature.\n  - **Returns**: `true` if the signature is valid, `false` otherwise.\n\n##### Attributes\n\n- **`curve`**: Lazily retrieves the elliptic curve associated with the signature scheme based on the `curve_name`.\n  \n- **`public_key`**: Computes and returns the public key from the private key.\n\n---\n\n#### Class: `Koblitz`\n\n##### Constructor\n\n- **`new Koblitz(curve_name = 'secp521r1')`**\n  - Creates a new instance of the `Koblitz` encoding/decoding class.\n  - **Parameters**:\n    - `curve_name`: (Optional) The name of the elliptic curve. Defaults to `'secp521r1'`.\n\n##### Methods\n\n- **`encode(message, alphabet_size = 256n)`**\n  - Encodes a textual message into a point on the elliptic curve using the Koblitz method.\n  - **Parameters**:\n    - `message`: The message to encode.\n    - `alphabet_size`: (Optional) The size of the alphabet. Defaults to `256n`.\n  - **Returns**: A tuple `[Point, j]` where `Point` is the encoded curve point and `j` is an auxiliary value.\n\n- **`decode(point, j, alphabet_size = 256n)`**\n  - Decodes a point on the elliptic curve back into a textual message.\n  - **Parameters**:\n    - `point`: The `Point` on the elliptic curve that represents the encoded message.\n    - `j`: The auxiliary value `j` used in encoding.\n    - `alphabet_size`: (Optional) The size of the alphabet. Defaults to `256n`.\n  - **Returns**: The decoded message as a string.\n\n- **`serialize(points)`**\n  - Serializes points and the corresponding `j` values into a JSON-friendly format.\n  - **Parameters**:\n    - `points`: An array of tuples `[Point, j]` where `Point` is the encoded curve point.\n  - **Returns**: An array of objects in the format `{x, y, j}` representing the serialized points.\n\n- **`deserialize(serializedPoints)`**\n  - Deserializes the JSON format back to an array of tuples `[Point, j]`.\n  - **Parameters**:\n    - `serializedPoints`: An array of objects `{x, y, j}`.\n  - **Returns**: An array of tuples `[Point, j]`.\n\n##### Attributes\n\n- **`curve`**: Lazily retrieves the elliptic curve for message encoding/decoding.\n\n---\n\n#### Class: `DiffieHellman`\n\n##### Constructor\n\n- **`new DiffieHellman(private_key, curve_name = 'secp192k1')`**\n  - Creates an instance of the `DiffieHellman` class for performing Diffie-Hellman key exchange using elliptic curves.\n  - **Parameters**:\n    - `private_key`: The private key to use during the key exchange.\n    - `curve_name`: (Optional) The name of the elliptic curve. Defaults to `'secp192k1'`.\n\n##### Methods\n\n- **`compute_shared_secret(other_public_key)`**\n  - Computes the shared secret using the private key and the other party's public key.\n  - **Parameters**:\n    - `other_public_key`: The other party's public key (as a `Point`).\n  - **Returns**: A point representing the shared secret on the elliptic curve.\n\n##### Attributes\n\n- **`curve`**: Retrieves the elliptic curve associated with the Diffie-Hellman exchange.\n  \n- **`public_key`**: Computes the Diffie-Hellman public key from the private key.\n\n---\n\n#### Class: `MasseyOmura`\n\n##### Constructor\n\n- **`new MasseyOmura(private_key, curve_name = 'secp192k1')`**\n  - Creates an instance of the `MasseyOmura` class for performing Massey-Omura key exchange using elliptic curves.\n  - **Parameters**:\n    - `private_key`: The private key to use during the key exchange.\n    - `curve_name`: (Optional) The name of the elliptic curve. Defaults to `'secp192k1'`.\n\n##### Methods\n\n- **`first_encryption_step(message)`**\n  - Encrypts a message with the sender's private key.\n  - **Parameters**:\n    - `message`: The message (as a point) to encrypt.\n  - **Returns**: The encrypted message (as a `Point`).\n\n- **`second_encryption_step(encrypted_message)`**\n  - Applies the receiver's private key to complete encryption steps. Used in the key exchange process.\n  - **Parameters**:\n    - `encrypted_message`: The encrypted message (as a `Point`).\n  - **Returns**: The resulting encrypted message.\n\n- **`partial_decryption_step(encrypted_message)`**\n  - Partially decrypts a message using the inverse of the sender's private key.\n  - **Parameters**:\n    - `encrypted_message`: The encrypted message (as a `Point`).\n  - **Returns**: The decrypted message (as a `Point`).\n\n##### Attributes\n\n- **`curve`**: Retrieves the elliptic curve associated with the Massey-Omura exchange.\n  \n- **`public_key`**: Computes and returns the Massey-Omura public key from the private key.\n\n---\n\n#### Class: `EllipticCurve`\n\n- **This is an internal class representing an elliptic curve and offering operations on points and scalar multiplications.**\n\n##### Constructor\n\n- **`new EllipticCurve(p, a, b, G, n, h)`**\n  - Initializes an elliptic curve instance.\n  - **Parameters**:\n    - `p`: The prime modulus of the field.\n    - `a`: The `'a'` coefficient of the curve equation.\n    - `b`: The `'b'` coefficient of the curve equation.\n    - `G`: The base point (generator) on the curve.\n    - `n`: The order of the base point.\n    - `h`: The cofactor of the curve.\n  \n##### Methods\n\n- **`add_points(P, Q)`**\n  - Adds two points `P` and `Q` on the elliptic curve.\n  - **Parameters**:\n    - `P`: The first point.\n    - `Q`: The second point.\n  - **Returns**: The resulting point `R = P + Q`.\n\n- **`multiply_point(k, P)`**\n  - Multiplies a point `P` with a scalar `k`.\n  - **Parameters**:\n    - `k`: Scalar (integer) to multiply.\n    - `P`: The point to be multiplied.\n  - **Returns**: Point `kP`.\n\n- **`is_point_on_curve(p)`**\n  - Verifies if a point is on the elliptic curve.\n  - **Parameters**:\n    - `p`: The point to evaluate.\n  - **Returns**: `true` if the point is on the curve, otherwise `false`.\n\n---\n\n## Examples\n\nHere are some examples of using the key exchange protocols and other features of `js-ecutils`.\n\n### Encoding and Decoding Messages with Koblitz\n\n```js\n// Importing necessary classes\nconst { algorithms: { Koblitz } } = require('js-ecutils');\n\n// Initialize Koblitz with a specific curve\nconst koblitz = new Koblitz('secp521r1');\n\n// Encode a message to a curve point\nconst [point, j] = koblitz.encode('Hello, EC!', 2n ** 8n);\n\n// Decode the curve point back to a message\nconst decoded_message = koblitz.decode(point, j, 2n ** 8n);\n\nconsole.log(decoded_message);\n```\n\n### Digital Signatures with ECDSA\n\n```js\n// Importing necessary classes\nconst { algorithms: { DigitalSignature } } = require('js-ecutils');\n\n// Create a DigitalSignature instance with your private key\nconst privateKey = BigInt(123456);\nconst ds = new DigitalSignature(privateKey);\n\n// Hash of your message\nconst messageHash = BigInt(545454445644654n);\n\n// Generate signature\nconst [r, s] = ds.generate_signature(messageHash);\n\n// Verify signature (typically on the receiver's side)\nconst isValid = ds.verify_signature(ds.public_key, messageHash, r, s);\n\nconsole.log(`Is the signature valid? ${isValid}`);\n```\n\n### Diffie-Hellman Key Exchange\n\n```js\n// Importing necessary classes\nconst { protocols: { DiffieHellman } } = require('js-ecutils');\n\n// Alice's side\nconst alice = new DiffieHellman(12345n);\n\n// Bob's side\nconst bob = new DiffieHellman(67890n);\n\n// Alice computes her shared secret with Bob's public key\nconst aliceSharedSecret = alice.compute_shared_secret(bob.public_key);\n\n// Bob computes his shared secret with Alice's public key\nconst bobSharedSecret = bob.compute_shared_secret(alice.public_key);\n\n// Check if aliceSharedSecret is equal to bobSharedSecret\nconst isSharedSecretEqual = aliceSharedSecret.x === bobSharedSecret.x \u0026\u0026 aliceSharedSecret.y === bobSharedSecret.y;\n\nconsole.log(`Are the shared secrets equal? ${isSharedSecretEqual}`);\n```\n\n### Massey-Omura Key Exchange\n\n```js\n// Importing necessary classes\nconst { algorithms: { Koblitz }, protocols: { MasseyOmura } } = require('js-ecutils');\n\n// Initialize the Koblitz instance for the elliptic curve 'secp192k1'\nconst koblitz = new Koblitz('secp192k1');\n\n// Sender's side\n// -------------\nconst privateKeySender = BigInt(\"70604135\");\n// Initialize Massey-Omura protocol with the sender's private key\nconst moSender = new MasseyOmura(privateKeySender);\n\n// Encode the message using the Koblitz method\n// `j` is used to handle the ambiguity in the decoding process\nconst [message, j] = koblitz.encode(\"Hello, world!\");\n\n// Perform the first encryption step with Massey-Omura protocol\nconst encryptedMsgSender = moSender.first_encryption_step(message);\n\n// The encoded message is now sent to the receiver...\n// (transmission of encryptedMsgSender)\n\n// Receiver's side\n// ---------------\nconst privateKeyReceiver = BigInt(\"48239108668\");\n// Initialize Massey-Omura protocol with the receiver's private key\nconst moReceiver = new MasseyOmura(privateKeyReceiver);\n\n// Perform the second encryption step with Massey-Omura protocol\nconst encryptedMsgReceiver = moReceiver.second_encryption_step(encryptedMsgSender);\n\n// The double-encrypted message is sent back to the sender...\n// (transmission of encryptedMsgReceiver)\n\n// Sender's side again\n// -------------------\nconst partialDecryptedMsg = moSender.partial_decryption_step(encryptedMsgReceiver);\n\n// The partially decrypted message is sent back to the receiver...\n// (transmission of partialDecryptedMsg)\n\n// Receiver's final decryption\n// ---------------------------\nconst originalMessage = moReceiver.partial_decryption_step(partialDecryptedMsg);\n\n// Decode the message using the Koblitz method\n// `j` is used to resolve the mapping from the elliptic curve point back to the message\nconst decodedMessage = koblitz.decode(originalMessage, j);\n\nconsole.log(decodedMessage);\n```\n\n## Contributing\n\nContributions are welcome! If you’d like to contribute to `js-ecutils`, please follow these steps:\n\n1. Fork the repository.\n2. Create a new branch for your feature or bug fix.\n3. Make your changes and commit them.\n4. Push your branch and open a pull request.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. \n\n## Language-Specific Libraries for Elliptic Curve Cryptography\n\nIn addition to the JavaScript module, there are other language-specific libraries available for elliptic curve cryptography:\n\n- **Python Library for Elliptic Curve Cryptography**: The `ecutils` package provides elliptic curve functionalities tailored for Python developers. You can find it on [GitHub](https://github.com/isakruas/ecutils).\n\n- **Go Library for Elliptic Curve Cryptography**: The `go-ecutils` library offers similar elliptic curve utilities for Go developers. More information and documentation can be found on [GitHub](https://github.com/isakruas/go-ecutils).\n\nThese libraries enable developers to utilize elliptic curve cryptography in their preferred programming environments, ensuring flexibility and ease of integration.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisakruas%2Fjs-ecutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisakruas%2Fjs-ecutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisakruas%2Fjs-ecutils/lists"}