{"id":26121807,"url":"https://github.com/ipfs-shipyard/js-human-crypto-keys","last_synced_at":"2026-02-28T07:06:23.914Z","repository":{"id":34632872,"uuid":"175467204","full_name":"ipfs-shipyard/js-human-crypto-keys","owner":"ipfs-shipyard","description":"Generate and import human-friendly cryptographic keys using mnemonics, QR codes and other methods","archived":false,"fork":false,"pushed_at":"2024-06-13T04:12:15.000Z","size":1614,"stargazers_count":33,"open_issues_count":20,"forks_count":9,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-13T13:05:16.768Z","etag":null,"topics":["crypto","human","key","mnemonic","paper-key","qr-code"],"latest_commit_sha":null,"homepage":"","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/ipfs-shipyard.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-03-13T17:21:47.000Z","updated_at":"2024-12-26T13:01:24.000Z","dependencies_parsed_at":"2023-01-15T08:11:21.281Z","dependency_job_id":null,"html_url":"https://github.com/ipfs-shipyard/js-human-crypto-keys","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-shipyard%2Fjs-human-crypto-keys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-shipyard%2Fjs-human-crypto-keys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-shipyard%2Fjs-human-crypto-keys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-shipyard%2Fjs-human-crypto-keys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipfs-shipyard","download_url":"https://codeload.github.com/ipfs-shipyard/js-human-crypto-keys/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717242,"owners_count":21150389,"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":["crypto","human","key","mnemonic","paper-key","qr-code"],"created_at":"2025-03-10T14:36:42.229Z","updated_at":"2026-02-28T07:06:18.897Z","avatar_url":"https://github.com/ipfs-shipyard.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# human-crypto-keys\n\n[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][codecov-image]][codecov-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url]\n\n[npm-url]:https://npmjs.org/package/human-crypto-keys\n[downloads-image]:http://img.shields.io/npm/dm/human-crypto-keys.svg\n[npm-image]:http://img.shields.io/npm/v/human-crypto-keys.svg\n[travis-url]:https://travis-ci.org/ipfs-shipyard/js-human-crypto-keys\n[travis-image]:http://img.shields.io/travis/ipfs-shipyard/js-human-crypto-keys/master.svg\n[codecov-url]:https://codecov.io/gh/ipfs-shipyard/js-human-crypto-keys\n[codecov-image]:https://img.shields.io/codecov/c/github/ipfs-shipyard/js-human-crypto-keys/master.svg\n[david-dm-url]:https://david-dm.org/ipfs-shipyard/js-human-crypto-keys\n[david-dm-image]:https://img.shields.io/david/ipfs-shipyard/js-human-crypto-keys.svg\n[david-dm-dev-url]:https://david-dm.org/ipfs-shipyard/js-human-crypto-keys?type=dev\n[david-dm-dev-image]:https://img.shields.io/david/dev/ipfs-shipyard/js-human-crypto-keys.svg\n\nGenerate and import human-friendly cryptographic keys using mnemonics or seeds.\n\n\n## Installation\n\n```sh\n$ npm install human-crypto-keys\n```\n\nThis library is written in modern JavaScript and is published in both CommonJS and ES module transpiled variants. If you target older browsers please make sure to transpile accordingly.\n\n\n## Usage\n\n```js\nimport { generateKeyPair, getKeyPairFromMnemonic, getKeyPairFromSeed } from 'human-crypto-keys';\n\nconst keyPair = await generateKeyPair('rsa');\n// =\u003e Generates a key pair with rsa encryption and provides information for recovery.\n\nconst keyPairFromMnemonic = await getKeyPairFromMnemonic(keyPair.mnemonic, keyPair.algorithm);\n// =\u003e Generates the same key pair based on the mnemonic.\n\nconst keyPairFromSeed = await getKeyPairFromSeed(keyPair.seed, keyPair.algorithm);\n// =\u003e Generates the same key pair based on the seed.\n```\n\n\u003e ⚠️ human-crypto-keys depends on cryptographic modules that can increase the bundle size of your projects significantly. You might want to break big bundles in smaller pieces with the help of [dynamic imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports).\n\n## API\n\n### generateKeyPair(algorithm, [options])\n\nGenerates a key pair based on the specified algorithm.\n\nReturns an object with the following:\n```js\n{\n    algorithm,  // An object with the algorithm identifier and respective parameters that were used during generation.\n    mnemonic,   // The mnemonic used to create a seed for generation.\n    seed,       // The seed used for generation (Uint8Array).\n    privateKey, // The generated private key composed in a specific format.\n    publicKey,  // The generated public key composed in a specific format.\n}\n```\n\n#### algorithm\n\nType: `Object` or `String`\n\nThe algorithm identifier and the respective parameters to generate a key pair. Please read the [algorithm](#algorithm-3) section for more information.\n\n#### options\n\nType: `Object`\n\nOptions to be used while composing keys. Please read the [options](#options-3) section for more information.\n\n### getKeyPairFromMnemonic(mnemonic, algorithm, [options])\n\nGenerates a key pair based on the specified mnemonic and algorithm.\n\nReturns an object with the following:\n```js\n{\n    privateKey, // The generated private key composed in a specific format.\n    publicKey,  // The generated public key composed in a specific format.\n}\n```\n\n#### mnemonic\n\nType: `String`\n\nThe mnemonic provided as one of the recovery methods for a key pair.\n\n#### algorithm\n\nType: `Object` or `String`\n\nThe algorithm identifier and the respective parameters to generate a key pair. Please read the [algorithm](#algorithm-3) section for more information.\n\n#### options\n\nType: `Object`\n\nOptions to be used while composing keys. Please read the [options](#options-3) section for more information.\n\n### getKeyPairFromSeed(seed, algorithm, [options])\n\nGenerates a key pair based on the specified seed and algorithm.\n\nReturns an object with the following:\n```js\n{\n    privateKey, // The generated private key composed in a specific format.\n    publicKey,  // The generated public key composed in a specific format.\n}\n```\n\n#### seed\n\nType: `Uint8Array`\n\nThe seed provided as one of the recovery methods for a key pair.\n\n#### algorithm\n\nType: `Object` or `String`\n\nThe algorithm identifier and the respective parameters to generate a key pair. Please read the [algorithms](#algorithm-3) section for more information.\n\n#### options\n\nType: `Object`\n\nOptions to be used while composing keys. Please read the [options](#options-3) section for more information.\n\n### Common Parameters\n\n#### algorithm\n\nType: `Object` or `String`\n\nThe algorithm identifier and the respective parameters to generate a key pair.\n\nIt can be specified as an `Object` or a `String`. Using an `Object` will provide freedom to override default algorithm parameters in relation to its type. On the other hand, a `String` presents a useful and quick approach if the default parameters are suitable.\n\nThe default parameters are different for each algorithm type. Currently only 2 types are supported:\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eRSA\u003c/strong\u003e\u003c/summary\u003e\n\nDefault Parameters:\n```js\n{\n\tmodulusLength: 2048\t\t    // Number\n\tpublicExponent: 65537\t\t// Number\n\tmethod: 'PRIMEINC'\t\t    // String\n}\n```\n\nYou can override only the parameters that you need, all the other ones remain with default values.\n\n\u003e ⚠️ Please make sure that values follow the same type as default ones. Also, parameters that are not available as default are not supported.\n\nExample `Object`:\n```js\nconst algorithm = { id: 'rsa', modulusLength: 4096 };\n```\n\nExample `String`:\n```js\nconst algorithm = 'rsa';\n```\n\nIn the examples above we are using an alias for RSA encryption. Although this is possible, the full list of supported RSA key algorithms can be found in the [RSA Keys Section](https://github.com/ipfs-shipyard/js-crypto-key-composer/tree/initial-impl#key-algorithms) of [crypto-key-composer](https://github.com/ipfs-shipyard/js-crypto-key-composer) package.\n\n##### Generation\n\nThe following steps detail how the generation of a RSA key pair is being done:\n1. Create a Pseudorandom Number Generator, `prng` for short, with [HMAC-DRBG](https://github.com/indutny/hmac-drbg) using a `seed` as its generation entropy. This seed is directly provided when using `getKeyFromSeed` or inferred from a mnemonic passed in `getKeyFromMnemonic`. If neither the seed nor the mnemonic are available they can both be generated, as done in `generateKeyPair`. The generation of a mnemonic and its derived seed are done with [bip39](https://github.com/bitcoinjs/bip39), a well established method used in bitcoin wallets.\n2. Generate a key pair, using [Node Forge RSA](https://github.com/digitalbazaar/forge#rsa) generation method, with all necessary algorithm parameters and the `prng` created previously.\n3. Compose both keys with the defined formats.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eED25519\u003c/strong\u003e\u003c/summary\u003e\n\nThis algorithm doesn't have any default parameters since it just relies on 32 bytes randomly generated.\n\nExample `Object`:\n```js\nconst algorithm = { id: 'ed25519' };\n```\n\nExample `String`:\n```js\nconst algorithm = 'ed25519';\n```\n\n##### Generation\n\nThe following steps detail how the generation of a ED25519 key pair is being done:\n1. Generate a key pair, using [Node Forge ED25519](https://github.com/digitalbazaar/forge#ed25519) generation method, with a 32 bytes `seed`. If the seed is bigger than the necessary size, only the first 32 bytes will be used. This seed is directly provided when using `getKeyFromSeed` or inferred from a mnemonic passed in `getKeyFromMnemonic`. If neither the seed nor the mnemonic are available they can both be generated, as done in `generateKeyPair`. The generation of a mnemonic and its derived seed are done with [bip39](https://github.com/bitcoinjs/bip39), a well established method used in bitcoin wallets. \n2. Compose both keys with the defined formats.\n\n\u003c/details\u003e\n\n#### options\n\nType: `Object`\n\nThe current options allow you to decide both private and public key formats, the private key encryption and the password to use to encrypt the key.\n\nAvailable options:\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eprivateKeyFormat\u003c/strong\u003e\u003c/summary\u003e\n\nType: `String`\n\nDefault: `pkcs8-pem`\n\nThe format in which the private key will be composed.\n\nKeys can be composed in different formats and vary by algorithm. All formats available are described in the [Formats Section](https://github.com/ipfs-shipyard/js-crypto-key-composer/tree/initial-impl#formats) of [crypto-key-composer](https://github.com/ipfs-shipyard/js-crypto-key-composer) package.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003epublicKeyFormat\u003c/strong\u003e\u003c/summary\u003e\n\nType: `String`\n\nDefault: `spki-pem`\n\nThe format in which the public key will be composed.\n\nKeys can be composed in different formats and vary by algorithm. All formats available are described in the [Formats Section](https://github.com/ipfs-shipyard/js-crypto-key-composer/tree/initial-impl#formats) of [crypto-key-composer](https://github.com/ipfs-shipyard/js-crypto-key-composer) package.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eencryptionAlgorithm\u003c/strong\u003e\u003c/summary\u003e\n\nType: `Object`\n\nThe encryption algorithm that will be used to encrypt the private key.\n\nFor more information please read the [Encryption Algorithms Section](https://github.com/ipfs-shipyard/js-crypto-key-composer/tree/initial-impl#encryption-algorithms) of [crypto-key-composer](https://github.com/ipfs-shipyard/js-crypto-key-composer) package.\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003epassword\u003c/strong\u003e\u003c/summary\u003e\n\nType: `String`\n\nThe password to be used on the encryption of the private key.\n\u003c/details\u003e\n\n## Tests\n\n```sh\n$ npm test\n$ npm test -- --watch # during development\n```\n\n## License\n\nReleased under the [MIT License](http://www.opensource.org/licenses/mit-license.php).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs-shipyard%2Fjs-human-crypto-keys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipfs-shipyard%2Fjs-human-crypto-keys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs-shipyard%2Fjs-human-crypto-keys/lists"}