{"id":20309209,"url":"https://github.com/vaporyjs/keyvapory","last_synced_at":"2025-08-03T12:08:06.532Z","repository":{"id":40797439,"uuid":"123757424","full_name":"vaporyjs/keyvapory","owner":"vaporyjs","description":"JavaScript tool to generate, import and export Vapory keys","archived":false,"fork":false,"pushed_at":"2023-01-06T18:12:05.000Z","size":3729,"stargazers_count":0,"open_issues_count":10,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-15T16:52:05.672Z","etag":null,"topics":["gvap","keystore","keyvapory"],"latest_commit_sha":null,"homepage":"https://vapory.org","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/vaporyjs.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":"2018-03-04T04:42:44.000Z","updated_at":"2021-01-15T02:44:31.000Z","dependencies_parsed_at":"2023-02-06T07:30:54.702Z","dependency_job_id":null,"html_url":"https://github.com/vaporyjs/keyvapory","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaporyjs%2Fkeyvapory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaporyjs%2Fkeyvapory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaporyjs%2Fkeyvapory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaporyjs%2Fkeyvapory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vaporyjs","download_url":"https://codeload.github.com/vaporyjs/keyvapory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241809602,"owners_count":20023786,"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":["gvap","keystore","keyvapory"],"created_at":"2024-11-14T17:26:11.537Z","updated_at":"2025-03-04T07:46:03.503Z","avatar_url":"https://github.com/vaporyjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# keyvapory\n\n[![Build Status](https://travis-ci.org/vaporyjs/keyvapory.svg?branch=master)](https://travis-ci.org/vaporyjs/keyvapory) [![Coverage Status](https://coveralls.io/repos/github/vaporyjs/keyvapory/badge.svg?branch=master)](https://coveralls.io/github/vaporyjs/keyvapory?branch=master) [![npm version](https://badge.fury.io/js/keyvapory.svg)](http://badge.fury.io/js/keyvapory)\n\nKeyvapory is a JavaScript tool to generate, import and export Vapory keys.  This provides a simple way to use the same account locally and in web wallets.  It can be used for verifiable cold storage wallets.\n\nKeyvapory uses the same key derivation functions (PBKDF2-SHA256 or scrypt), symmetric ciphers (AES-128-CTR or AES-128-CBC), and message authentication codes as [gvap](https://github.com/vapory/go-vapory).  You can export your generated key to file, copy it to your data directory's keystore, and immediately start using it in your local Vapory client.\n\n*Note: starting in version 0.5.0, keyvapory's `encrypt` and `decrypt` functions both return Buffers instead of strings.  This is a breaking change for anyone using these functions directly!*\n\n## Installation\n\n```\nnpm install keyvapory\n```\n\n## Usage\n\nTo use keyvapory in Node.js, just `require` it:\n\n```javascript\nvar keyvapory = require(\"keyvapory\");\n```\n\nA minified, browserified file `dist/keyvapory.min.js` is included for use in the browser.  Including this file simply attaches the `keyvapory` object to `window`:\n\n```html\n\u003cscript src=\"dist/keyvapory.min.js\" type=\"text/javascript\"\u003e\u003c/script\u003e\n```\n\n### Key creation\n\nGenerate a new random private key (256 bit), as well as the salt (256 bit) used by the key derivation function, and the initialization vector (128 bit) used to AES-128-CTR encrypt the key.  `create` is asynchronous if it is passed a callback function, and synchronous otherwise.\n\n```javascript\n// optional private key and initialization vector sizes in bytes\n// (if params is not passed to create, keyvapory.constants is used by default)\nvar params = { keyBytes: 32, ivBytes: 16 };\n\n// synchronous\nvar dk = keyvapory.create(params);\n// dk:\n{\n    privateKey: \u003cBuffer ...\u003e,\n    iv: \u003cBuffer ...\u003e,\n    salt: \u003cBuffer ...\u003e\n}\n\n// asynchronous\nkeyvapory.create(params, function (dk) {\n    // do stuff!\n});\n```\n\n### Key export\n\nYou will need to specify a password and (optionally) a key derivation function.  If unspecified, PBKDF2-SHA256 will be used to derive the AES secret key.\n\n```javascript\nvar password = \"whevapory\";\nvar kdf = \"pbkdf2\"; // or \"scrypt\" to use the scrypt kdf\n```\n\nThe `dump` function is used to export key info to keystore [\"secret-storage\" format](https://github.com/vapory/wiki/wiki/Web3-Secret-Storage-Definition).  If a callback function is supplied as the sixth parameter to `dump`, it will run asynchronously:\n\n```javascript\n// Note: if options is unspecified, the values in keyvapory.constants are used.\nvar options = {\n  kdf: \"pbkdf2\",\n  cipher: \"aes-128-ctr\",\n  kdfparams: {\n    c: 262144,\n    dklen: 32,\n    prf: \"hmac-sha256\"\n  }\n};\n\n// synchronous\nvar keyObject = keyvapory.dump(password, dk.privateKey, dk.salt, dk.iv, options);\n// keyObject:\n{\n  address: \"008aeeda4d805471df9b2a5b0f38a0c3bcba786b\",\n  Crypto: {\n    cipher: \"aes-128-ctr\",\n    ciphertext: \"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46\",\n    cipherparams: {\n      iv: \"6087dab2f9fdbbfaddc31a909735c1e6\"\n    },\n    mac: \"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2\",\n    kdf: \"pbkdf2\",\n    kdfparams: {\n      c: 262144,\n      dklen: 32,\n      prf: \"hmac-sha256\",\n      salt: \"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd\"\n    }\n  },\n  id: \"e13b209c-3b2f-4327-bab0-3bef2e51630d\",\n  version: 3\n}\n\n// asynchronous\nkeyvapory.dump(password, dk.privateKey, dk.salt, dk.iv, options, function (keyObject) {\n  // do stuff!\n});\n```\n\n`dump` creates an object and not a JSON string.  In Node, the `exportToFile` method provides an easy way to export this formatted key object to file.  It creates a JSON file in the `keystore` sub-directory, and uses gvap's current file-naming convention (ISO timestamp concatenated with the key's derived Vapory address).\n\n```javascript\nkeyvapory.exportToFile(keyObject);\n```\n\nAfter successful key export, you will see a message like:\n\n```\nSaved to file:\nkeystore/UTC--2015-08-11T06:13:53.359Z--008aeeda4d805471df9b2a5b0f38a0c3bcba786b\n\nTo use with gvap, copy this file to your Vapory keystore folder\n(usually ~/.vapory/keystore).\n```\n\n### Key import\n\nImporting a key from gvap's keystore can only be done on Node.  The JSON file is parsed into an object with the same structure as `keyObject` above.\n\n```javascript\n// Specify a data directory (optional; defaults to ~/.vapory)\nvar datadir = \"/home/jack/.vapory-test\";\n\n// Synchronous\nvar keyObject = keyvapory.importFromFile(address, datadir);\n\n// Asynchronous\nkeyvapory.importFromFile(address, datadir, function (keyObject) {\n  // do stuff\n});\n```\nThis has been tested with version 3 and version 1, but not version 2, keys.  (Please send me a version 2 keystore file if you have one, so I can test it!)\n\nTo recover the plaintext private key from the key object, use `keyvapory.recover`.  The private key is returned as a Buffer.\n\n```javascript\n// synchronous\nvar privateKey = keyvapory.recover(password, keyObject);\n// privateKey:\n\u003cBuffer ...\u003e\n\n// Asynchronous\nkeyvapory.recover(password, keyObject, function (privateKey) {\n  // do stuff\n});\n```\n\n### Hashing rounds\n\nBy default, keyvapory uses 65536 hashing rounds in its key derivation functions, compared to the 262144 gvap uses by default.  (Keyvapory's JSON output files are still compatible with gvap, however, since they tell gvap how many rounds to use.)  These values are user-editable: `keyvapory.constants.pbkdf2.c` is the number of rounds for PBKDF2, and `keyvapory.constants.scrypt.n` is the number of rounds for scrypt.\n\n## Tests\n\nUnit tests are in the `test` directory, and can be run with mocha:\n\n```\nnpm test\n```\n\n`test/gvap.js` is an integration test, which is run (along with `test/keys.js`) using:\n\n```\nnpm run gvap\n```\n\n`gvap.js` generates 1000 random private keys, encrypts each key using a randomly-generated passphrase, dumps the encrypted key info to a JSON file, then spawns a gvap instance and attempts to unlock each account using its passphrase and JSON file.  The passphrases are between 1 and 100 random bytes.  Each passphrase is tested in both hexadecimal and base-64 encodings, and with PBKDF2-SHA256 and scrypt key derivation functions.\n\nBy default, the flags passed to gvap are:\n\n```\ngvap --vaporbase \u003caccount\u003e --unlock \u003caccount\u003e --nodiscover --networkid \"10101\" --port 30304 --rpcport 8547 --datadir test/fixtures --password test/fixtures/.password\n```\n\n`test/fixtures/.password` is a file which contains the passphrase.  The `.password` file, as well as the JSON key files generated by `gvap.js`, are automatically deleted after the test.\n\n(Note: `gvap.js` conducts 4000 tests, each of which can take up to 5 seconds, so running this file can take up to 5.56 hours.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaporyjs%2Fkeyvapory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaporyjs%2Fkeyvapory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaporyjs%2Fkeyvapory/lists"}