{"_id":"@accesschains/eccrypto","name":"@accesschains/eccrypto","dist-tags":{"latest":"1.1.8"},"versions":{"1.1.8":{"name":"@accesschains/eccrypto","version":"1.1.8","description":"JavaScript Elliptic curve cryptography library, includes fix to browser.js so that encrypt/decrypt works","main":"index.js","browser":"browser.js","types":"types.d.ts","scripts":{"install":"node-gyp rebuild || exit 0","test":"ECCRYPTO_NO_FALLBACK=1 mocha && xvfb-run -a karma start && jshint .","m":"mocha","k":"xvfb-run -a karma start","kc":"xvfb-run -a karma start --browsers Chromium","kf":"xvfb-run -a karma start --browsers Firefox","j":"jshint ."},"repository":{"type":"git","url":"git+https://github.com/AccessChains/eccrypto.git"},"keywords":["ecc","ecdsa","ecdh","ecies","crypto","cryptography","secp256k1","K-256","elliptic","curve"],"author":{"name":"Torus Labs"},"license":"CC0-1.0","bugs":{"url":"https://github.com/AccessChains/eccrypto/issues"},"homepage":"https://github.com/AccessChains/eccrypto","devDependencies":{"browserify":"^17.0.0","buffer-equal":"^1.0.0","chai":"^4.3.4","jshint":"^2.13.0","karma":"^6.3.4","karma-browserify":"^8.0.0","karma-chrome-launcher":"^3.1.0","karma-cli":"^2.0.0","karma-firefox-launcher":"^2.1.1","karma-mocha":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha":"^9.0.2"},"dependencies":{"acorn":"^8.4.1","elliptic":"^6.5.4","es6-promise":"^4.2.8","nan":"^2.14.2","secp256k1":"^3.8.0"},"optionalDependencies":{"secp256k1":"^3.8.0"},"gitHead":"dac58b378e3610853972961e02adf1dc652bb39a","_id":"@accesschains/eccrypto@1.1.8","_nodeVersion":"18.14.0","_npmVersion":"9.3.1","dist":{"integrity":"sha512-qKRKrgw6Ohse0iT+ejMK7lwHepx/xcdJBVPR/XaamhrZh6YL0mKpUKiuZ2jqTOUrv6zhOYDI9f21dUCgxb/3rA==","shasum":"5605962c068e831173c1acc5908c2afc2305bbff","tarball":"https://registry.npmjs.org/@accesschains/eccrypto/-/eccrypto-1.1.8.tgz","fileCount":9,"unpackedSize":50803,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGON6gWTgD7r4HwPLoJI/PjhXk4Bqcw5IjH4LSrjuMcAAiEA7T42QH7nb6K9Y4+Ex0ybpWBGRY1o51yPwJ/CiGDZM/o="}]},"_npmUser":{"name":"nvkhiem2016","email":"nvkhiem2016@gmail.com"},"directories":{},"maintainers":[{"name":"nvkhiem2016","email":"nvkhiem2016@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/eccrypto_1.1.8_1690790444735_0.04670602110132327"},"_hasShrinkwrap":false}},"time":{"created":"2023-07-31T08:00:44.647Z","1.1.8":"2023-07-31T08:00:44.896Z","modified":"2023-07-31T08:00:45.103Z"},"maintainers":[{"name":"nvkhiem2016","email":"nvkhiem2016@gmail.com"}],"description":"JavaScript Elliptic curve cryptography library, includes fix to browser.js so that encrypt/decrypt works","homepage":"https://github.com/AccessChains/eccrypto","keywords":["ecc","ecdsa","ecdh","ecies","crypto","cryptography","secp256k1","K-256","elliptic","curve"],"repository":{"type":"git","url":"git+https://github.com/AccessChains/eccrypto.git"},"author":{"name":"Torus Labs"},"bugs":{"url":"https://github.com/AccessChains/eccrypto/issues"},"license":"CC0-1.0","readme":"# eccrypto [![Build Status](https://travis-ci.org/bitchan/eccrypto.svg?branch=master)](https://travis-ci.org/bitchan/eccrypto)\n\n[![NPM](https://nodei.co/npm/eccrypto.png)](https://www.npmjs.com/package/eccrypto)\n\nJavaScript Elliptic curve cryptography library for both browserify and node.\n\n## Motivation\n\nThere is currently no any isomorphic ECC library which provides ECDSA, ECDH and ECIES for both Node.js and Browser and uses the fastest implementation available (e.g. [secp256k1-node](https://github.com/wanderer/secp256k1-node) is much faster than other libraries but can be used only on Node.js). So `eccrypto` is an attempt to create one.\n\n## Implementation details\n\nWith the help of browserify `eccrypto` provides different implementations for Browser and Node.js with the same API. Because WebCryptoAPI defines asynchronous promise-driven API, implementation for Node needs to use promises too.\n\n* Use Node.js crypto module/library bindings where possible\n* Use WebCryptoAPI where possible\n* Promise-driven API\n* Only secp256k1 curve, only SHA-512 (KDF), HMAC-SHA-256 (HMAC) and AES-256-CBC for ECIES\n* Compressed key support\n\n### Native crypto API limitations\n\n#### crypto\n\nECDH only works in Node 0.11+ (see https://github.com/joyent/node/pull/5854), ECDSA only supports keys in PEM format (see https://github.com/joyent/node/issues/6904) and ECIES is not supported at all.\n\n#### WebCryptoAPI\n\nECDSA and ECDH are supported in Chrome [only on Windows](https://sites.google.com/a/chromium.org/dev/blink/webcrypto#TOC-Supported-algorithms-as-of-Chrome-41-) (see also [bug 338883](https://code.google.com/p/chromium/issues/detail?id=338883)), aren't supported by Firefox (fixed only in 36.0+, see [bug 1034854](https://bugzilla.mozilla.org/show_bug.cgi?id=1034854); see also [feature matrix](https://docs.google.com/spreadsheet/ccc?key=0AiAcidBZRLxndE9LWEs2R1oxZ0xidUVoU3FQbFFobkE#gid=1)) and ECIES is not defined at all in WebCryptoAPI draft. Also WebCryptoAPI [currently defines](http://www.w3.org/TR/WebCryptoAPI/#EcKeyGenParams-dictionary) only curves recommended by NIST meaning that secp256k1 (K-256) curve is not supported (see also: [[1]](http://lists.w3.org/Archives/Public/public-webcrypto-comments/2013Dec/0001.html), [[2]](https://bugzilla.mozilla.org/show_bug.cgi?id=1051509)).\n\nSo we use [seck256k1](https://www.npmjs.com/package/secp256k1) library in Node for ECDSA, [elliptic](https://www.npmjs.com/package/elliptic) in Browser for ECDSA and ECDH and implement ECIES manually with the help of native crypto API.\n\n## Possible future goals\n\n* Support other curves/KDF/MAC/symmetric encryption schemes\n\n## Usage\n\n### ECDSA\n\n```js\nvar crypto = require(\"crypto\");\nvar eccrypto = require(\"eccrypto\");\n\n// A new random 32-byte private key.\nvar privateKey = eccrypto.generatePrivate();\n// Corresponding uncompressed (65-byte) public key.\nvar publicKey = eccrypto.getPublic(privateKey);\n\nvar str = \"message to sign\";\n// Always hash you message to sign!\nvar msg = crypto.createHash(\"sha256\").update(str).digest();\n\neccrypto.sign(privateKey, msg).then(function(sig) {\n  console.log(\"Signature in DER format:\", sig);\n  eccrypto.verify(publicKey, msg, sig).then(function() {\n    console.log(\"Signature is OK\");\n  }).catch(function() {\n    console.log(\"Signature is BAD\");\n  });\n});\n```\n\n### ECDH\n\n```js\nvar eccrypto = require(\"eccrypto\");\n\nvar privateKeyA = eccrypto.generatePrivate();\nvar publicKeyA = eccrypto.getPublic(privateKeyA);\nvar privateKeyB = eccrypto.generatePrivate();\nvar publicKeyB = eccrypto.getPublic(privateKeyB);\n\neccrypto.derive(privateKeyA, publicKeyB).then(function(sharedKey1) {\n  eccrypto.derive(privateKeyB, publicKeyA).then(function(sharedKey2) {\n    console.log(\"Both shared keys are equal:\", sharedKey1, sharedKey2);\n  });\n});\n```\n\n### ECIES\n\n```js\nvar eccrypto = require(\"eccrypto\");\n\nvar privateKeyA = eccrypto.generatePrivate();\nvar publicKeyA = eccrypto.getPublic(privateKeyA);\nvar privateKeyB = eccrypto.generatePrivate();\nvar publicKeyB = eccrypto.getPublic(privateKeyB);\n\n// Encrypting the message for B.\neccrypto.encrypt(publicKeyB, Buffer.from(\"msg to b\")).then(function(encrypted) {\n  // B decrypting the message.\n  eccrypto.decrypt(privateKeyB, encrypted).then(function(plaintext) {\n    console.log(\"Message to part B:\", plaintext.toString());\n  });\n});\n\n// Encrypting the message for A.\neccrypto.encrypt(publicKeyA, Buffer.from(\"msg to a\")).then(function(encrypted) {\n  // A decrypting the message.\n  eccrypto.decrypt(privateKeyA, encrypted).then(function(plaintext) {\n    console.log(\"Message to part A:\", plaintext.toString());\n  });\n});\n```\n\n## License\n\neccrypto - JavaScript Elliptic curve cryptography library\n\nWritten in 2014-2015 by Kagami Hiiragi <kagami@genshiken.org>\n\nTo the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.\n\nYou should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.\n","readmeFilename":"README.md"}