Giter Site home page Giter Site logo

keythereum's Introduction

keythereum

Build Status Coverage Status npm version

Keythereum is a JavaScript tool to generate, import and export Ethereum 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.

Keythereum uses the same key derivation functions (PBKDF2-SHA256 or scrypt), symmetric ciphers (AES-128-CTR or AES-128-CBC), and message authentication codes as geth. You can export your generated key to file, copy it to your data directory's keystore, and immediately start using it in your local Ethereum client.

Note: starting in version 0.5.0, keythereum's encrypt and decrypt functions both return Buffers instead of strings. This is a breaking change for anyone using these functions directly!

Installation

npm install keythereum

Usage

To use keythereum in Node.js, just require it:

var keythereum = require("keythereum");

A minified, browserified file dist/keythereum.min.js is included for use in the browser. Including this file simply attaches the keythereum object to window:

<script src="dist/keythereum.min.js" type="text/javascript"></script>

Key creation

Generate 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.

// optional private key and initialization vector sizes in bytes
// (if params is not passed to create, keythereum.constants is used by default)
var params = { keyBytes: 32, ivBytes: 16 };

// synchronous
var dk = keythereum.create(params);
// dk:
{
    privateKey: <Buffer ...>,
    iv: <Buffer ...>,
    salt: <Buffer ...>
}

// asynchronous
keythereum.create(params, function (dk) {
    // do stuff!
});

Key export

You 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.

var password = "wheethereum";
var kdf = "pbkdf2"; // or "scrypt" to use the scrypt kdf

The dump function is used to export key info to keystore "secret-storage" format. If a callback function is supplied as the sixth parameter to dump, it will run asynchronously:

// Note: if options is unspecified, the values in keythereum.constants are used.
var options = {
  kdf: "pbkdf2",
  cipher: "aes-128-ctr",
  kdfparams: {
    c: 262144,
    dklen: 32,
    prf: "hmac-sha256"
  }
};

// synchronous
var keyObject = keythereum.dump(password, dk.privateKey, dk.salt, dk.iv, options);
// keyObject:
{
  address: "008aeeda4d805471df9b2a5b0f38a0c3bcba786b",
  Crypto: {
    cipher: "aes-128-ctr",
    ciphertext: "5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46",
    cipherparams: {
      iv: "6087dab2f9fdbbfaddc31a909735c1e6"
    },
    mac: "517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2",
    kdf: "pbkdf2",
    kdfparams: {
      c: 262144,
      dklen: 32,
      prf: "hmac-sha256",
      salt: "ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"
    }
  },
  id: "e13b209c-3b2f-4327-bab0-3bef2e51630d",
  version: 3
}

// asynchronous
keythereum.dump(password, dk.privateKey, dk.salt, dk.iv, options, function (keyObject) {
  // do stuff!
});

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 geth's current file-naming convention (ISO timestamp concatenated with the key's derived Ethereum address).

keythereum.exportToFile(keyObject);

After successful key export, you will see a message like:

Saved to file:
keystore/UTC--2015-08-11T06:13:53.359Z--008aeeda4d805471df9b2a5b0f38a0c3bcba786b

To use with geth, copy this file to your Ethereum keystore folder
(usually ~/.ethereum/keystore).

Key import

Importing a key from geth's keystore can only be done on Node. The JSON file is parsed into an object with the same structure as keyObject above.

// Specify a data directory (optional; defaults to ~/.ethereum)
var datadir = "/home/jack/.ethereum-test";

// Synchronous
var keyObject = keythereum.importFromFile(address, datadir);

// Asynchronous
keythereum.importFromFile(address, datadir, function (keyObject) {
  // do stuff
});

This 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!)

To recover the plaintext private key from the key object, use keythereum.recover. The private key is returned as a Buffer.

// synchronous
var privateKey = keythereum.recover(password, keyObject);
// privateKey:
<Buffer ...>

// Asynchronous
keythereum.recover(password, keyObject, function (privateKey) {
  // do stuff
});

Hashing rounds

By default, keythereum uses 65536 hashing rounds in its key derivation functions, compared to the 262144 geth uses by default. (Keythereum's JSON output files are still compatible with geth, however, since they tell geth how many rounds to use.) These values are user-editable: keythereum.constants.pbkdf2.c is the number of rounds for PBKDF2, and keythereum.constants.scrypt.n is the number of rounds for scrypt.

Tests

Unit tests are in the test directory, and can be run with mocha:

npm test

test/geth.js is an integration test, which is run (along with test/keys.js) using:

npm run geth

geth.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 geth 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.

By default, the flags passed to geth are:

geth --etherbase <account> --unlock <account> --nodiscover --networkid "10101" --port 30304 --rpcport 8547 --datadir test/fixtures --password test/fixtures/.password

test/fixtures/.password is a file which contains the passphrase. The .password file, as well as the JSON key files generated by geth.js, are automatically deleted after the test.

(Note: geth.js conducts 4000 tests, each of which can take up to 5 seconds, so running this file can take up to 5.56 hours.)

keythereum's People

Contributors

adetante avatar alexyangfox avatar fanatid avatar holgerd77 avatar jbaylina avatar maciejhirsz avatar makevoid avatar marcbachmann avatar paulmillr avatar ryanio avatar stephensprinkle avatar tinybike avatar whymarrh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

keythereum's Issues

Update dependency ranges

Context:

keythereum/package.json

Lines 28 to 35 in 4fc9842

"dependencies": {
"crypto-browserify": "3.12.0",
"keccak": "1.4.0",
"scrypt": "6.0.3",
"secp256k1": "3.5.0",
"sjcl": "1.0.6",
"uuid": "3.0.0"
},

All the dependencies listed in the package.json file are fixed to exact versions. Is there a particular reason why this is? For a library package, keythereum should allow minor and patch versions to be used (and allow npm to deduplicate them in consuming applications).

Error: method only available in Node.js,

I got an error "Error: method only available in Node.js", when I use a function named "keythereum.importFromFile()" by javascript. I ran successfully in node. But written in the JS file, it will prompt the error by opening the web page. My system is Ubuntu 16.04

Create several accounts

Hi there,
how can I create several accounts and import/export it? For example Mist allow to store many accounts.

deriveKey silently fails for empty passwords

deriveKey internally performs a if (password && salt) before proceeding. This works fine for most scenarios, but will fail when password is an empty string (which should still be a valid use case).

Additionally when it does fail, it does not throw an informative exception, it just returns undefined and tends to cause a confusing error somewhere down the line (calling slice of undefined and what not).

Suggested tweaks:

  • Change the password check to password != null or typeof password === 'string'.
  • When either password or salt are missing, throw an exception.

aes-128-ctr is not available

I'm getting error aes-128-ctr is not available when trying to run keythereum.recover().

I'm using web3 version ^0.19.1.

Invalid key length errors with Safari on iOS 10+

Using keythereum on Safari on iOS 10+ causes errors about keys length:

TypeError: invalid key length 32

The problem is due to the version of buffer coming with browserify^10.2.6 : the slice method doesn't return the modified buffer but the original one.
This causes errors when slicing keys (for exemple here).

The solution is to upgrade browserify on ^13.1.1 and rebuild the package.

TypeError: crypto.randomBytes is not a function

"angular/compiler-cli": "^4.2.4",
"typescript": "~2.3.3"

var dk = keythereum.create(this.params);

"scripts": [
"assets/keythereum.min.js",
"assets/keythereum.js"
],

AppComponent.html:7 ERROR TypeError: crypto.randomBytes is not a function
    at Object.create (index.js:304)
    at AppComponent.webpackJsonp.../../../../../src/app/app.component.ts.AppComponent.generateWallet (app.component.ts:24)
    at Object.eval [as handleEvent] (AppComponent.html:7)
    at handleEvent (core.es5.js:12023)
    at callWithDebugContext (core.es5.js:13493)
    at Object.debugHandleEvent [as handleEvent] (core.es5.js:13081)
    at dispatchEvent (core.es5.js:8615)
    at core.es5.js:9226
    at HTMLButtonElement.<anonymous> (platform-browser.es5.js:2651)
    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:425)

Import Key dependency on NodeJS

Just wondering why key import only runs on Node? I was hoping to be able to upload a key file or at least paste in the json into a text box and have keythereum import it.

TypeError: crypto.randomBytes is not a function TypeError: crypto.randomBytes is not a function

Hello! Good day!.

, I tried the below link for login authentication :
https://auth0.com/docs/quickstart/native/ionic3/01-login.

I am facing the crypto issue “TypeError: crypto.randomBytes is not a function
TypeError: crypto.randomBytes is not a function”.
Then, I try to solve the issue with following link :slight_smile:https://stackoverflow.com/questions/47486774/crypto-randombytes-is-not-a-function-in-angular

But, I am stuck on the console error such as below :
Error: ENOENT: no such file or directory, open ‘C:\Users\username\Documents\ionic\Cabling\cabling2\node_modules[PACKAGE_ERROR][FILE_ERROR]’
errno: -4058,
code: ‘ENOENT’,
syscall: ‘open’,
path: ‘C:\Users\username\Documents\ionic\Cabling\cabling2\node_modules[PACKAGE_ERROR][FILE_ERROR]’ }

My node version is 8.11.2
Angular CLI: 7.3.9

Could you please help me?
Thank you so much.

key length is invalid with any key

I have exception Uncaught Exception...RangeError: private key length is invalid from

exports.isBufferLength = function (buffer, length, message) {
  if (buffer.length !== length) throw RangeError(message)
}

<Buffer 83 8b f2 6b d6 35 85 cd 25 b7 c7 8c 3c 7d ed fe 29 b7 de 72 d7 6c 8c c2 ca 76 b9 72 ff c7 44 2e>
Code:

    let privateKey = "838bf26bd63585cd25b7c78c3c7dedfe29b7de72d76c8cc2ca76b972ffc7442e";
    var params = { keyBytes: 32, ivBytes: 16 };
    let password = "1";
    var options = {
    kdf: "scrypt",
    cipher: "aes-128-ctr",
    kdfparams: {
        n: 262144,
        dklen: 32,
        p:1,
        r:8
    }
    };
    var dk = keythereum.create(params);
    //var nullBuff = new Buffer ([0x00]);
    //dk.privateKey = Buffer.concat([nullBuff, privateKey]);
    dk.privateKey = new Buffer(privateKey);
    keythereum.dump(password, dk.privateKey, dk.salt, dk.iv, options, function (keyObject) {
        keythereum.exportToFile(keyObject);
    });

In case when I empty if blocks in RangeError in assert.js, I getting privatekey is incorrect. I tried with like 5 private keys already.

Is there a sign and a verify function ?

i found the encrypt and decrypt functions but no sign and verify functions ? i could be an useful improvement. Should we use ethereumjs-util to do theses operations.
Best regards

Distribute ES6/CommonJS module

Hey, any plans to provide Keythereum as an ES6/CommonJS module for compatibility with JavaScript module bundlers (like Webpack)? Generally, the JS ecosystem has moved beyond inclusion via script tag so it'd be great to see this support added to this very useful library!

Appreciate there would be a lot of work involved in this so just starting off discussion by checking if it had been thought about already.

Thanks!

Is it secure to use with ethereumjs-tx?

Hello,

I would like to use this module with https://github.com/ethereumjs/ethereumjs-tx, so that I can sign directly transactions from my browser, and I don't know if it is really secure. Maybe it is not the right place to ask, so please tell me if it isn't.

I would like to store the keystore file on a server, load it in a webapp in my (regular, not mist) browser, unlock the account using keythereum, sign the transactions I want to make with ethereumjs-tx and finally send them to a remote node using the eth_sendrawtransaction of the RPC API.

Let's suppose for this paragraph that the browser environment is safe.
If the https connection is MITMed, and the keystore file is intercepted, is it a problem?

Is the browser environment really safe?

import key from string

Is it possible to import a keystore file from a string ?
For example, I would like to be able to drop my keystore file in the browser to use it, but I haven't seen a function to read the account from a string.

recover very slow

The recover function of keythereum runs more than 7 times slower than unlockAccount in geth.

// setup code omitted
(async()=>{
  const tm1 = Date.now();
  await web3.eth.personal.unlockAccount(acct, passwd);
  const tm2 = Date.now();
  console.log(tm2 - tm1);
  var keyObject = keythereum.importFromFile(acct, datadir);
  const tm3 = Date.now();
  var privateKey = keythereum.recover(passwd, keyObject);
  const tm4 = Date.now();
  console.log(tm4 - tm3);
})()

Prints

766
5697

Why is that? Can it be improved?

I have to use geth-generated accounts, and specifying fewer hashing rounds is not an option.

Fail in exportToFile under windows

The source is very simple

keythereum.exportToFile(keyObject, './blockchain/keystore');

The cause is the use of the character ':' in the filename. There is a list of invalid characters in filenames under Windows Naming conventions.

The workaround used by geth is to replace ':' with '-'.

Otherwise the code works without problems under linux.

fs.js:640
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open 'D:\demo\blockchain\keystore\UTC--2017-02-24T20:32:07.469Z--acafe503ff60fd6b7ae0a48ca7c6f70a8f88dada'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.writeFileSync (fs.js:1333:33)
    at Object.exportToFile (D:\demo\node_modules\keythereum\index.js:566:16)
    at async.eachOfLimit.accounts.admin (D:\demo\blockchain.js:126:22)
    at replenish (D:\demo\node_modules\async\dist\async.js:881:17)
    at D:\demo\node_modules\async\dist\async.js:885:9
    at Object.eachOfLimit (D:\demo\node_modules\async\dist\async.js:912:22)
    at D:\demo\blockchain.js:118:15
    at nextTask (D:\demo\node_modules\async\dist\async.js:5070:14)

TypeError: Cannot read properties of undefined (reading 'iv')

Getting the following error:

/key/node_modules/keythereum/index.js:411
    iv = this.str2buf(keyObjectCrypto.cipherparams.iv);
                                                   ^

TypeError: Cannot read properties of undefined (reading 'iv')
    at Object.recover (/Users/jawestlu/Downloads/key/node_modules/keythereum/index.js:411:52)
    at Object.<anonymous> (/Users/jawestlu/Downloads/key/test.js:8:31)
    at Module._compile (node:internal/modules/cjs/loader:1246:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1300:10)
    at Module.load (node:internal/modules/cjs/loader:1103:32)
    at Module._load (node:internal/modules/cjs/loader:942:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47

Node.js v19.5.0

Executing using this code:

const fs = require("fs");
const keythereum = require("keythereum");

const KEYSTORE = "/key/key.json";
const PASSWORD = "*****";

const keyObject = JSON.parse(fs.readFileSync(KEYSTORE, {encoding: "utf8"}));
const privateKey = keythereum.recover(PASSWORD, keyObject).toString("hex");
console.log(`0x${keyObject.address}: 0x${privateKey}`);

These are the keys in the json:

"crypto":
"kdf":
"function":
"params":
"dklen":
"salt":
"n":
"r":
"p":
"message":
"checksum":
"function":
"params":
"message":
"cipher":
"function":
"params":
"iv":
"message":
"description":
"pubkey":
"path":
"uuid":
"version":

Dependecy on deprecated node-scrypt

The packge depends on "node-scrypt" package which is deprecated:

#WARNING!!! This module is deprecated. Instead, use https://nodejs.org/api/crypto.html#crypto_crypto_scrypt_password_salt_keylen_options_callback

The package fails to build in last released version and it prevents to npm install projects having that or THIS package in dependencies:
web3/web3.js#3408 (comment)
(I had the same build issue on Fedora Linux in app with keythereum dependency - the scrypt was failing to build.)

The fix for this is merged, but the package maintainer is unable to release fixed version:
barrysteyn/node-scrypt#197 (comment)

The only solution is to use version from git:

npm install github:barrysteyn/node-scrypt#fb60a8d3c158fe115a624b5ffa7480f3a24b03fb

But that is pretty complicated if your package depends indirectly, like through keythereum.
You need to hack it using npm-shrinkwrap and lock all your dependencies on specified versions. (Which is not usable for libraries.)

Also the package author recommends to not use node-scrypt:

Sorry guys, I was having a bit of trouble updating things. I do intend to publish soon though.
Quick question for anyone out there: I was under the impression that Node provides Scrypt encryption in it's own core libraries. If so, why are people still using this?

Are there any plans to remove or replace this dependency?
Thanks!

Incorrect scrypt kdf defaults?

Should the defaults for scrypt kdf be

p = 1
r = 8

instead of

p = 8
r = 1

Just looking at my own keystore, these defaults looked flipped.

How to make browser using faster

I use keythereum.js(without nodejs) in a browser. It works good, but not each time. Almost always the first time the site down and after refreshing the second time keys are created in 10 seconds. For encrypting I use default options. Is it possible to do browser version faster by change default options, like number of cycles or type of coding?

keythereum.recover() take long time on iPhone with JavaScriptCore.

Using keythereum to recover plaintext private key with jSON string,when the hash round in key derivation is 1<<18,it spends about 20 minutes to recover,is it nomal?
Here is the implementation.

https://github.com/NedColin/Web3jsDemo/blob/master/Web3jsDemo/web3jsDemo/Web3SecretStore.m

//hash times 16, cost few seconds
NSString * p1 = [[Web3SecretStore sharedInstance] recovery:@"{\"address\":\"7daa0942447a2b6f6a749a2e3591178571cec52c\",\"crypto\":{\"cipher\":\"aes-128-ctr\",\"ciphertext\":\"376148c453bede9949db2089e24dd4b4b683f00f151aaad9b17802b435ad0f64\",\"cipherparams\":{\"iv\":\"427ad6ebb106f463746f78cc7680d4fe\"},\"mac\":\"9cfe0ac9e5dbf6913bbbcbd38932f5a17c97b970bdb7578f7d17c6e34e5f5fa2\",\"kdf\":\"scrypt\",\"kdfparams\":{\"dklen\":32,\"n\":16,\"r\":8,\"p\":1,\"salt\":\"14b081b2affed113a8639a2ef93a0e0fb82cdd7a1ffe04fb547b921ac65376e9\"}},\"id\":\"d7bae128-05e9-4975-98c7-e6c6dc7d2422\",\"version\":3}" password:@"1111"];

//hash times 262144 cost about 20 minitus
NSString * p2 =[[Web3SecretStore sharedInstance] recovery:@"{\"address\":\"a3b8b5b4b1efd9d52b6ecfe2d1802ffe397fee9a\",\"crypto\":{\"cipher\":\"aes-128-ctr\",\"ciphertext\":\"875aeaccf8799027bd3fdb6f41f92ca822987db4d53e4eb6d900f5ff9cb3b733\",\"cipherparams\":{\"iv\":\"6d14d4bbbb6e3c62bf28ddffba547bf5\"},\"mac\":\"92f37ef9359ebd2932a1adaa644013b1fef3fcd3d093e3569c8b4371b937522b\",\"kdf\":\"scrypt\",\"kdfparams\":{\"dklen\":32,\"n\":262144,\"r\":8,\"p\":1,\"salt\":\"eb2079cc1d4b1d4a05cb23b79c032edc376461b92b5f33144b5c66889107f865\"}},\"id\":\"e357f84f-3eb0-4e17-bd93-29f7044f41d7\",\"version\":3}" password:@"9999"];

A way to handle error and log

Is there a way to disable logs like path where address data is saved after creation?
Also I cannot catch error, it just logs it in console which is a bit annoying.

keythereum.js:421 
Uncaught Error: message authentication code mismatch
    at verifyAndDecrypt (keythereum.js:421)
    at keythereum.js:445
    at keythereum.js:278
    at keythereum.js:30847
    at Item.run (keythereum.js:31226)
    at drainQueue (keythereum.js:31196)

and

Saved to file:
/home/user/parity/keys/chain/UTC--2018-03-01T15:32:02.766Z--c7a168b127181d4b8750aa4015058ff530b8c8b6
To use with geth, copy this file to your Ethereum keystore folder (usually ~/.ethereum/keystore).

I guess that console.log() and console.error() are used and I think it's not a good idea.

error while trying to "recover" a key

$ node unlock.js 
/Users/megatv/CODE/ETHEREUM/unlock-acc/node_modules/keythereum/index.js:471
        var iv = keyObject.Crypto.cipherparams.iv;
                                 ^

TypeError: Cannot read property 'cipherparams' of undefined
    at Object.module.exports.recover (/Users/megatv/CODE/ETHEREUM/unlock-acc/node_modules/keythereum/index.js:471:34)
    at Object.<anonymous> (/Users/megatv/CODE/ETHEREUM/unlock-acc/unlock.js:4:13)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:138:18)
    at node.js:974:3
$ cat unlock.js 
var key = require("./key.json"),
    keyethereum = require("keythereum");

keyethereum.recover("password", key);

osx, keyethereum version 0.2.1

Withdraw ETH from Keythereum wallets

So I was using keythereum to generate public and private keys.

const dk = ethereum.create();
parameters.address = ethereum.privateKeyToAddress(dk.privateKey);
parameters.pKey = dk.privateKey.toString('hex');

Now I have send some ETH to the generated wallet and it worked. The challenge I am facing is with withdrawal.

Anyone knows how I can withdraw the ETH from the generated wallet, I tried searching with no luck.

I know for BTC we can use blockchain.info to import the private keys. Is there a similar service for ETH too.

Thank you so much

Add support for async/await in addition to callbacks

Currently, I have to write my own await/async wrapper for the async functions in the library. Would it be possible to promisify those async functions (e.g. exportToFile, importFromFile)? It could be using the
fairly standard pattern - if cb is specified, then use callback; otherwise return a promise.

keythereum.recover() doesn't give me the private key

Maybe im wrong but I try to generate private key in order to be able to import them in metamask.
So I create:

var dk = keythereum.create();
var keyObject = keythereum.dump(password, dk.privateKey, dk.salt, dk.iv)

then I try to export private key in plain text by using recover:

var privateKey = keythereum.recover(password, keyObject);
var readablePrivKey = privateKey.toString('base64');
console.log(readablePrivKey);
> R4TKRCemmMaY8NtIipcrVKIQ+RumXvOOyg5VIG/lXuY=

I got this result which is not corresponding with the ethereum private key adress, so maybe i do something wrong but I try to understand.
Regards

RangeError: Array Buffer allocation failed

I am trying to export key with password passed to the keyethereum module. Code is as below:

params = {
keyBytes: 32,
ivBytes: 16
};
options = {
kdf: "scrypt",
cipher: "aes-128-ctr",
kdfparams: {
dklen: 32,
n: 262144,
p: 1,
r: 8
}
};
keythereum.create(params, function (dk) {
keythereum.dump(password, dk.privateKey, dk.salt, dk.iv, options, function (keyObject) {
keythereum.exportToFile(keyObject, config.get('Application.envConfig.serverFileLocation'), function (response) {
log.info("successfully created new account:" + response);
def.resolve({error: undefined, response: response});
});
}, function (err) {
log.error("error occured while creating address:" + err);
def.reject({error: err.stack, response: undefined });
});
}, function (err) {
log.error("error occured while creating address:" + err);
def.reject({error: err.stack, response: undefined});
});

But I am facing:

"RangeError: Array buffer allocation failed",
" at new ArrayBuffer ()",
" at module.exports (/home/ubuntu/v3/v2-node-latest/node_modules/keythereum/lib/scrypt.js:357:11)",
" at Object.deriveKey (/home/ubuntu/v3/v2-node-latest/node_modules/keythereum/index.js:207:18)",
" at Object.dump (/home/ubuntu/v3/v2-node-latest/node_modules/keythereum/index.js:394:10)",

I keep getting an initialization error on require("keythereum")

I already did npm install with keythereum="^0.2.5" in the packages (even removed all node_modules and reinstalled)
In code I simply do the following which generates the error:
var keythereum = require('keythereum');

module initialization error: Error at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) at require (module.js:380:17) at Object. (/var/task/node_modules/ethereumjs-util/index.js:1:76) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17)

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.