ethereum-keystore

0.0.3 • Public • Published

ethereum-keystore

Ethereum keystore generator and reader

License NPM version

Demo

https://lab.miguelmota.com/ethereum-keystore

Install

npm install ethereum-keystore

Getting started

Generate random keystore, encrypted with passphrase:

const { generateKeystore } = require('ethereum-keystore')
 
const keystore = await generateKeystore(null, 'mysecret')
console.log(keystore)

Generate keystore from private key, encrypted with passphrase:

const { generateKeystore } = require('ethereum-keystore')
 
const keystore = await generateKeystore('4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d', 'mysecret')
console.log(keystore)

Generate keystore with custom parameters:

const { generateKeystore } = require('ethereum-keystore')
 
const keystore = await generateKeystore(null, 'mysecret', {
  kdf: 'pbkdf2',
  kdfparams: {
    c: 100000,
    dklen: 32,
    prf: 'hmac-sha256'
  },
  cipher: 'aes-128-ctr'
})
console.log(keystore)

Recover private key from encrypted keystore:

const { recoverKeystore } = require('ethereum-keystore')
 
const keystoreJson = require('./keystore.json')
const privateKey = await recoverKeystore(keystoreJson, 'mysecret')
console.log(privateKey)

CLI

Install:

npm install -g ethereum-keystore

Help

$ ethereum-keystore --help
 
  Usage
    $ ethereum-keystore [input] [options]
 
  Options
    --generate, -g      Generate keystore
    --recover, -r       Recover keystore
    --private-key, -k   Private key
    --passphrase, -p    Passphrase
    --outfile, -o       Output file

Generate random keystore, encrypted with passphrase:

$ ethereum-keystore -g -p mysecret
{"address":"281fe82d16e0ba4036a49074af87b313cc5844c5", ... }

Output keystore to file:

$ ethereum-keystore -g -p mysecret -o keystore.json

Generate keystore from private key, encrypted with passphrase:

$ ethereum-keystore -g -k 4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d -p mysecret

Recover private key from encrypted keystore file:

$ ethereum-keystore -r keystore.json -p mysecret
4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d

Recover private key from piped encrypted keystore:

$ cat keystore | ethereum-keystore -r -p mysecret
4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d

Test

npm test

License

MIT

Package Sidebar

Install

npm i ethereum-keystore

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

1.26 MB

Total Files

10

Last publish

Collaborators

  • miguelmota