From 5090cd6f7139e78c6a89252b98308116e7475cf1 Mon Sep 17 00:00:00 2001 From: Jack Peterson Date: Tue, 11 Aug 2015 00:57:05 -0700 Subject: [PATCH] Renamed ethereumjs-keys -> keythereum --- .npmignore | 1 + README.md | 20 ++++++++++---------- index.js | 2 +- package.json | 12 ++++++------ test/keys.js | 35 +++++++++++++++++++---------------- 5 files changed, 37 insertions(+), 33 deletions(-) diff --git a/.npmignore b/.npmignore index 0427960..722f3a1 100644 --- a/.npmignore +++ b/.npmignore @@ -4,3 +4,4 @@ node_modules .travis.yml test coverage +keystore diff --git a/README.md b/README.md index a15729f..baadbff 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ -ethereumjs-keys -=============== +keythereum +========== -[![Build Status](https://travis-ci.org/AugurProject/ethereumjs-keys.svg?branch=master)](https://travis-ci.org/AugurProject/ethereumjs-keys) -[![Coverage Status](https://coveralls.io/repos/AugurProject/ethereumjs-keys/badge.svg?branch=master&service=github)](https://coveralls.io/github/AugurProject/ethereumjs-keys?branch=master) +[![Build Status](https://travis-ci.org/AugurProject/keythereum.svg?branch=master)](https://travis-ci.org/AugurProject/keythereum) +[![Coverage Status](https://coveralls.io/repos/AugurProject/keythereum/badge.svg?branch=master&service=github)](https://coveralls.io/github/AugurProject/keythereum?branch=master) -[![NPM](https://nodei.co/npm/ethereumjs-keys.png)](https://nodei.co/npm/ethereumjs-keys/) +[![NPM](https://nodei.co/npm/keythereum.png)](https://nodei.co/npm/keythereum/) Generate, import and export Ethereum private keys. Uses PBKDF2 or scrypt key derivation functions. Installation ------------ - $ npm install ethereumjs-keys + $ npm install keythereum Usage ----- ```javascript -var ethKeys = require("ethereumjs-keys"); +var keythereum = require("keythereum"); // User-specified password var password = "wheethereum"; @@ -26,7 +26,7 @@ var password = "wheethereum"; var kdf = "pbkdf2"; // "scrypt" to use the scrypt kdf // Generate private key and the salt and initialization vector to encrypt it -var dk = ethKeys.create(); +var dk = keythereum.create(); // dk: { privateKey: , @@ -36,7 +36,7 @@ var dk = ethKeys.create(); // Export key data to keystore "secret-storage" format: // https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition -var json = ethKeys.dump(password, dk.privateKey, dk.salt, dk.iv, kdf); +var json = keythereum.dump(password, dk.privateKey, dk.salt, dk.iv, kdf); // json: { address: '008aeeda4d805471df9b2a5b0f38a0c3bcba786b', @@ -60,7 +60,7 @@ var json = ethKeys.dump(password, dk.privateKey, dk.salt, dk.iv, kdf); } // In Node, export formatted JSON to file. -ethKeys.exportToFile(json); +keythereum.exportToFile(json); ``` After successful key export, you will see a message like: ``` diff --git a/index.js b/index.js index 883f10c..54ed35e 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ /** - * ethereumjs-keys + * keythereum: create/import/export ethereum keys * @author Jack Peterson (jack@tinybike.net) */ diff --git a/package.json b/package.json index f07ee72..1684e95 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "ethereumjs-keys", - "version": "0.0.3", - "description": "Import and export Ethereum keys", + "name": "keythereum", + "version": "0.1.0", + "description": "Create, import and export Ethereum keys", "main": "index.js", "directories": { "test": "test", @@ -13,14 +13,14 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/AugurProject/ethereumjs-keys.git" + "url": "git+https://github.com/AugurProject/keythereum.git" }, "author": "Jack Peterson ", "license": "MIT", "bugs": { - "url": "https://github.com/AugurProject/ethereumjs-keys/issues" + "url": "https://github.com/AugurProject/keythereum/issues" }, - "homepage": "https://github.com/AugurProject/ethereumjs-keys#readme", + "homepage": "https://github.com/AugurProject/keythereum#readme", "dependencies": { "crypto-browserify": "^3.9.14", "elliptic": "^5.1.0", diff --git a/test/keys.js b/test/keys.js index 5c054e2..7fc61e8 100644 --- a/test/keys.js +++ b/test/keys.js @@ -10,7 +10,7 @@ var assert = require("chai").assert; var validator = require("validator"); var pubToAddress = require("ethereumjs-util").pubToAddress; var ecdsa = new (require("elliptic").ec)("secp256k1"); -var ethKeys = require("../"); +var keythereum = require("../"); // create private key, get public key and address var privateKey = crypto.randomBytes(32); @@ -18,7 +18,7 @@ var privateKey = crypto.randomBytes(32); // timeout for asynchronous unit tests var TIMEOUT = 48000; -ethKeys.create(); +keythereum.create(); describe("Crypto", function () { @@ -43,11 +43,14 @@ describe("Crypto", function () { }); it("derive address from private key", function () { - assert.strictEqual(ethKeys.privateKeyToAddress(privateKey), "0x" + address); + assert.strictEqual( + keythereum.privateKeyToAddress(privateKey), + "0x" + address + ); }); it("generate random 256-bit private key & salt, 128-bit initialization vector", function () { - var plaintext = ethKeys.create(); + var plaintext = keythereum.create(); assert.property(plaintext, "privateKey"); assert.isNotNull(plaintext.privateKey); assert.property(plaintext, "iv"); @@ -66,7 +69,7 @@ describe("Key derivation", function () { var test = function (t) { it("[sync] " + t.input.kdf, function () { this.timeout(TIMEOUT); - var derivedKey = ethKeys.deriveKey( + var derivedKey = keythereum.deriveKey( t.input.password, t.input.salt, t.input.kdf @@ -76,7 +79,7 @@ describe("Key derivation", function () { if (t.input.kdf !== "scrypt") { it("[async] " + t.input.kdf, function (done) { this.timeout(TIMEOUT); - ethKeys.deriveKey( + keythereum.deriveKey( t.input.password, t.input.salt, t.input.kdf, @@ -119,7 +122,7 @@ describe("Message authentication code", function () { var test = function (t) { it("convert " + JSON.stringify(t.input) + " -> " + t.output, function () { - var mac = ethKeys.getMAC(t.input.derivedKey, t.input.ciphertext); + var mac = keythereum.getMAC(t.input.derivedKey, t.input.ciphertext); assert.strictEqual(mac, t.output); }); }; @@ -197,7 +200,7 @@ describe("Dump private key", function () { var test = function (t) { it(t.input.kdf, function (done) { this.timeout(TIMEOUT); - ethKeys.dump( + keythereum.dump( t.input.password, t.input.privateKey, t.input.salt, @@ -211,7 +214,7 @@ describe("Dump private key", function () { assert.strictEqual(json.address, t.expected.address); assert.strictEqual( json.Crypto.cipher, - ethKeys.constants.cipher + keythereum.constants.cipher ); assert.strictEqual( json.Crypto.cipher, @@ -240,7 +243,7 @@ describe("Dump private key", function () { ); assert.strictEqual( json.Crypto.kdfparams.n, - ethKeys.constants.scrypt.n + keythereum.constants.scrypt.n ); assert.strictEqual( json.Crypto.kdfparams.r, @@ -248,7 +251,7 @@ describe("Dump private key", function () { ); assert.strictEqual( json.Crypto.kdfparams.r, - ethKeys.constants.scrypt.r + keythereum.constants.scrypt.r ); assert.strictEqual( json.Crypto.kdfparams.p, @@ -256,7 +259,7 @@ describe("Dump private key", function () { ); assert.strictEqual( json.Crypto.kdfparams.p, - ethKeys.constants.scrypt.p + keythereum.constants.scrypt.p ); } else { assert.strictEqual( @@ -265,7 +268,7 @@ describe("Dump private key", function () { ); assert.strictEqual( json.Crypto.kdfparams.c, - ethKeys.constants.pbkdf2.c + keythereum.constants.pbkdf2.c ); assert.strictEqual( json.Crypto.kdfparams.prf, @@ -273,7 +276,7 @@ describe("Dump private key", function () { ); assert.strictEqual( json.Crypto.kdfparams.prf, - ethKeys.constants.pbkdf2.prf + keythereum.constants.pbkdf2.prf ); } assert.strictEqual( @@ -282,7 +285,7 @@ describe("Dump private key", function () { ); assert.strictEqual( json.Crypto.kdfparams.dklen, - ethKeys.constants.pbkdf2.dklen + keythereum.constants.pbkdf2.dklen ); assert.strictEqual( json.Crypto.kdfparams.salt, @@ -393,7 +396,7 @@ describe("Export to file", function () { }; it("export key to json file", function (done) { - ethKeys.exportToFile(json, function (outfile) { + keythereum.exportToFile(json, function (outfile) { assert.strictEqual(outfile.slice(0, 5), "UTC--"); assert.isAbove(outfile.indexOf(json.address), -1); done();