New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jwallet-web-keystore

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jwallet-web-keystore

Library for ethereum blockchain accounts management

0.4.1
Source
npm
Version published
Weekly downloads
2
-90.48%
Maintainers
1
Weekly downloads
 
Created
Source

jwallet-web-keystore

Library for ethereum blockchain accounts management.

NPM version NPM downloads MIT License Dependecies

About

Keystore can hold read only / full access accounts of two types:

  • Address / PrivateKey
  • Mnemonic

Also Keystore API provides several utility methods for working with mnemonics / hashes / passwords.

Get Started

npm install jwallet-web-keystore
const Keystore = require('jwallet-web-keystore')

const keystore = new Keystore(props)

Available npm scripts:

  • lint: check code-style errors
  • test: run mocha tests
  • clean: clean ./lib dir
  • compile: clean, then compile library
  • build: lint & compile & test

Account properties

PropertyTypeDescription
idStringUnique ID of account
typeStringType of account (mnemonic / address)
accountNameStringAccount name
derivationPathStringDerivation path for generating of addresses from mnemonic
isReadOnlyBooleanRead-only flag of account
addressStringAddress of account
addressIndexNumberCurrent index of address of mnemonic account
bip32XPublicKeyStringBIP32 Extended Public Key
encryptedObjectContainer of encrypted data
encrypted.privateKeyObjectEncrypted private key
encrypted.mnemonicObjectEncrypted mnemonic

Notes:

  • isReadOnly - flag means that account can be used only for balance / transactions checking
  • bip32XPublicKey - xpub... key that used for deriving of public keys (addresses)

Public API definitions

See mocha tests for examples of usage.

new Keystore(props)

Instantiates Keystore object with provided props.

Parameters
ParamTypeDefaultDescription
propsObject{}Constructor properties
props.defaultDerivationPathString"m/44'/60'/0'/0"Default derivation path for new Mnemonic accounts
props.defaultEncryptionTypeString'nacl.secretbox'Default encryption type. Currently nacl.secretbox is only one supported
props.paddedMnemonicLengthNumber120Mnemonic will be padded left with this size before encryption
props.saltByteCountNumber32Count of bytes of generated salt for password strength
props.scryptParamsObject{ N: 2 ** 18, r: 8, p: 1 }Scrypt params for key deriving
props.derivedKeyLengthString32Derived key length
props.passwordConfigObject{}Options to test password strength
Returns

New instance of Keystore class.

Example
const keystore = new Keystore({ defaultDerivationPath: "m/44'/61'/0'/0" })

Instance methods

getAccounts()
Returns

Accounts list presented in keystore.

Example
const accounts = keystore.getAccounts()
getAccount(props)
Parameters

account properties object (Account properties).

Note: all properties are optional except of id.

Returns

Accounts list presented in keystore.

Example
const accounts = keystore.getAccounts()
createAccount(props)
Parameters

account properties with except of id & encrypted (Account properties)

Returns

Unique ID of created account

Example
const accountId = keystore.createAccount({
  password: 'JHJ23jG^*DGHj667s',
  type: 'address',
  privateKey: '0x8a02a99cc7a801da6996a2dacc406ffa5190dc9c8a02a99cc7a801da6996a2da',
  accountName: 'My account',
})
removeAccount(accountId)
Parameters
ParamTypeDescription
accountIdStringUnique ID of account
Returns

true if removed, otherwise false.

Example
const result = keystore.removeAccount('110ec58a-a0f2-4ac4-8393-c977d813b8d1') // true
removeAccounts(password)
Parameters
ParamTypeDescription
passwordStringKeystore password
Example
keystore.removeAccounts('JHJ23jG^*DGHj667s') // all keystore accounts were removed
setAccountName(accountId, newName)
Parameters
ParamTypeDescription
accountIdStringUnique ID of account
newNameStringNew account name
Returns

Updated account.

Example
const updatedAccount = keystore.setAccountName('110ec58a-a0f2-4ac4-8393-c977d813b8d1', 'New account name')
getPrivateKey(password, accountId, addressIndex)
Parameters
ParamTypeDescription
passwordStringKeystore password
accountIdStringUnique ID of account
addressIndexNumberIndex of address (private key) to derive from mnemonic (default 0)
Returns

Decrypted private key.

Example
const privateKey = keystore.getPrivateKey('JHJ23jG^*DGHj667s', '110ec58a-a0f2-4ac4-8393-c977d813b8d1')
setDerivationPath(password, accountId, newDerivationPath)

Note: used only for mnemonic accounts.

Parameters
ParamTypeDescription
passwordStringKeystore password
accountIdStringUnique ID of account
newDerivationPathStringNew derivation path

Note: default derivation path that will be assigned to all new created accounts can be managed by defaultDerivationPath constructor parameter.

Returns

Updated account.

Example
const updatedAccount = keystore.setDerivationPath('JHJ23jG^*DGHj667s', '110ec58a-a0f2-4ac4-8393-c977d813b8d1', "m/44'/61'/0'/0")
getMnemonic(password, accountId)

Note: used only for mnemonic accounts.

Parameters
ParamTypeDescription
passwordStringKeystore password
accountIdStringUnique ID of account
Returns

Decrypted mnemonic.

Example
const mnemonic = keystore.getMnemonic('JHJ23jG^*DGHj667s', '110ec58a-a0f2-4ac4-8393-c977d813b8d1')
getAddressesFromMnemonic(accountId, iteration, limit)

Note: used only for mnemonic accounts.

Parameters
ParamTypeDescription
accountIdStringUnique ID of account
iterationNumberIteration index (aka page for pagination) to generate bunch of addresses
limitNumberCount of addresses to generate from mnemonic per one page / iteration
Returns

List of generated addresses.

Example
const addresses = keystore.getAddressesFromMnemonic('110ec58a-a0f2-4ac4-8393-c977d813b8d1', 3, 10)
setAddressIndex(accountId, addressIndex)

Note: used only for mnemonic accounts.

Parameters
ParamTypeDescription
accountIdStringUnique ID of account
addressIndexStringIndex of address to derive from mnemonic / bip32XPublicKey
Returns

Updated account.

Example
const updatedAccount = keystore.setAddress('110ec58a-a0f2-4ac4-8393-c977d813b8d1', 5)
serialize()
Returns

Serialized keystore data for backup.

Example
const keystoreSerializedData = keystore.serialize()
deserialize(backupData)
Parameters
ParamTypeDescription
backupDataStringKeystore serialized data
Returns

Deserialized keystore data for restoring of backup.

Example
const backupData = '{"accounts":[{"type":"mnemonic","id":"2e820ddb-a9ce-43e1-b7ec-dbed59eec7e9",...'
const keystoreDeserializedData = keystore.deserialize(backupData)
getDecryptedAccounts(password)
Parameters
ParamTypeDescription
passwordStringKeystore password
Returns

Accounts with decrypted data.

Example
const decryptedAccounts = keystore.getDecryptedAccounts('JHJ23jG^*DGHj667s')
setPassword(password, newPassword)
Parameters
ParamTypeDescription
passwordStringKeystore password
newPasswordStringNew keystore password
Example
keystore.setPassword('JHJ23jG^*DGHj667s', 'Tw5E^g7djfd(29j')

Static methods

generateMnemonic(entropy, randomBufferLength)
ParamTypeDescription
entropyStringEntropy for mnemonic initialisation (see new Mnemonic)
randomBufferLengthNumberBuffer length (if entropy param is used)
Returns

Mnemonic - 12 English words splited by space.

Example
const mnemonic = Keystore.generateMnemonic()
isMnemonicValid(mnemonic)
Parameters
ParamTypeDescription
mnemonicStringMnemonic to check
Returns

true if mnemonic is valid and false otherwise.

Example
const mnemonic = 'come average primary sunny profit eager toy pulp struggle hazard tourist round'
const isValid = Keystore.isMnemonicValid(mnemonic) // true
isBip32XPublicKeyValid(bip32XPublicKey)
ParamTypeDescription
bip32XPublicKeyStringBIP32 Extended Public Key
Returns

true if bip32XPublicKey is valid and false otherwise.

Example
const isValid = Keystore.isBip32XPublicKeyValid('xpub...')
isValidAddress(address)
ParamTypeDescription
addressStringAddress to check. Accepts checksummed addresses too
Returns

true if address is valid and false otherwise.

Example
const isValid = Keystore.isValidAddress('0x8a02a99ee7a801da6996a2dacc406ffa5190dc9c')
isValidPrivateKey(privateKey)
ParamTypeDescription
privateKeyStringPrivate Key to check
Returns

true if privateKey is valid and false otherwise.

Example
const pk = '0xa7fcb4efc392d2c8983cbfe64063f994f85120e60843407af95907d905d0dc9f'
const isValid = Keystore.isValidPrivateKey(pk)
isDerivationPathValid(derivationPath)
ParamTypeDescription
derivationPathStringDerivation path
Returns

true if derivationPath is valid and false otherwise.

Example
const isValid = Keystore.isDerivationPathValid("m/44'/60'/0'/0")
testPassword(password, passwordConfig)
ParamTypeDefaultDescription
passwordStringKeystore password
passwordConfigObject{}Password options container
passwordConfig.minLengthNumber10Min length for password
passwordConfig.minLengthNumber128Max length for password
Returns

Object that contains following fields:

  • errors - error messages array
  • failedTests - failed test names array
  • passedTests - passed test names array
Example
const result = Keystore.testPassword('JHJ23jG^*DGHj667s')

Keywords

jibrel

FAQs

Package last updated on 26 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts