
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
@jibrelnetwork/jwallet-web-keystore
Advanced tools
Library for ethereum blockchain accounts management
Library for ethereum blockchain wallets management.
Keystore can hold read only
/ full access
wallets of two types:
privateKey
/ address
mnemonic
/ bip32XPublicKey
Also Keystore API provides several utility methods for working with mnemonics / hashes / passwords.
npm install jwallet-web-keystore
import keystore from 'jwallet-web-keystore'
lint
: check code-style errorstest
: run mocha testsclean
: clean ./lib
dircompile
: clean
, then compile librarybuild
: lint
& compile
& test
Property | Type | Description |
---|---|---|
id | String | Unique ID of wallet |
type | String | Type of wallet (mnemonic / address ) |
name | String | Wallet name |
address | String | Address of wallet |
customType | String | User-friendly type of wallet |
isReadOnly | Boolean | Read-only flag of wallet |
bip32XPublicKey | String | BIP32 Extended Public Key |
addressIndex | Number | Current index of address of mnemonic wallet |
passwordOptions | Object | Container with options for password management |
passwordOptions.salt | String | Salt for enforcing of password |
passwordOptions.encryptionType | String | Type of encryption |
passwordOptions.saltBytesCount | Number | Number of bytes for salt parameter |
passwordOptions.derivedKeyLength | Number | Size of derived from password key |
passwordOptions.scryptParams | Object | Scrypt function params, that used for password key derivation |
passwordOptions.scryptParams.N | Number | CPU/memory cost parameter |
passwordOptions.scryptParams.r | Number | The blocksize parameter |
passwordOptions.scryptParams.p | Number | Parallelization parameter |
mnemonicOptions | Object | Container with options for mnemonic management |
mnemonicOptions.network | String | Network (e.g. 'livenet' or 'testnet') |
mnemonicOptions.passphrase | String | BIP39 passphrase |
mnemonicOptions.derivationPath | String | Path for derivation of keys from BIP32 Extended Key |
mnemonicOptions.paddedMnemonicLength | Number | Fixed mnemonic length after leftpad with spaces |
encrypted | Object | Container of encrypted data |
encrypted.mnemonic | Object | Encrypted mnemonic |
encrypted.privateKey | Object | Encrypted private key |
Notes:
isReadOnly
- flag means that wallet can be used only for balance / transactions checkingbip32XPublicKey
- xpub...
key that used for deriving of public keys (addresses)encrypted data
(mnemonic/privateKey fields) - it is object, that looks like:encrypted.mnemonic = {
data: base64 string (encrypted),
nonce: base64 string,
}
See mocha tests for examples of usage.
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
Wallet found by its ID, otherwise exception will be thrown.
const wallets = keystore.createWallet(...)
const wallet = keystore.getWallet(wallets, 'JHJ23jG^*DGHj667s')
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
props | Object | New wallet data |
props.scryptParams (optional) | Object | scrypt function params (see wallet properties) |
props.data | String | main wallet data: address/privateKey/mnemonic/bip32XPublicKey |
props.name (optional) | String | name of new wallet |
props.network (optional) | String | network |
props.passphrase (optional) | String | BIP39 passphrase |
props.derivationPath (optional) | String | derivation path |
props.encryptionType (optional) | String | encryption type |
props.saltBytesCount (optional) | Number | size of salt for password |
props.derivedKeyLength (optional) | Number | size of key, derived from password with scrypt function |
props.paddedMnemonicLength (optional) | Number | size of mnemonic phrase before encryption |
password | String | wallet password. Used only for full access wallets: mnemonic /privateKey |
List of wallets with new created one, otherwise exception will be thrown.
const password = 'JHJ23jG^*DGHj667s'
const walletsOne = keystore.createWallet(wallets, {
name: 'My privateKey wallet',
data: '0x8a02a99cc7a801da6996a2dacc406ffa5190dc9c8a02a99cc7a801da6996a2da',
}, password)
const walletsTwo = keystore.createWallet(walletsOne, {
name: 'My address wallet',
data: '0x8a02a99ee7a801da6996a2dacc406ffa5190dc9c',
}, password)
const walletsThree = keystore.createWallet(walletsTwo, {
name: 'My xpub wallet',
data: 'xpub...',
}, password)
const walletsFour = keystore.createWallet(walletsThree, {
name: 'My mnemonic wallet',
data: '<mnemonic phrase here>',
}, password)
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
List of wallets without removed one, otherwise exception will be thrown.
const walletsNew = keystore.removeWallet(wallets, '110ec58a-a0f2-4ac4-8393-c977d813b8d1')
Note: used only for read-only
mnemonic
wallets.
This method is used to extend bip32Xpub
wallet permissions (to make it full-access wallet).
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
mnemonic | String | New mnemonic for wallet (from which bip32XPublicKey was derived) |
password | String | New password for wallet |
List of wallets with updated one, otherwise exception will be thrown.
const walletsNew = keystore.addMnemonic(wallets, walletId, mnemonic, password)
Note: used only for read-only
address
wallets.
This method is used to extend address
wallet permissions (to make it full-access wallet).
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
privateKey | String | New privateKey for wallet (from which address was obtained) |
password | String | New password for wallet |
List of wallets with updated one, otherwise exception will be thrown.
const walletsNew = keystore.addPrivateKey(wallets, walletId, privateKey, password)
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
name | String | New wallet name |
List of wallets with new updated one, otherwise exception will be thrown.
const walletId = '110ec58a-a0f2-4ac4-8393-c977d813b8d1'
const name = 'New wallet name'
const walletsNew = keystore.setWalletName(wallets, walletId, name)
Note: used only for mnemonic
wallets.
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
addressIndex (optional) | Number | Index of address to derive from mnemonic / bip32XPublicKey |
List of wallets with new updated one, otherwise exception will be thrown.
const walletsNew = keystore.setAddressIndex(wallets, walletId, addressIndex)
Note: used only for full-access mnemonic
wallets.
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
password | String | Wallet password |
derivationPath | String | New derivation path |
List of wallets with new updated one, otherwise exception will be thrown.
const derivationPath = 'm/44\'/61\'/0\'/0'
const walletsNew = keystore.setDerivationPath(wallets, walletId, password, derivationPath)
Note: used only for full-access mnemonic
wallets.
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
password | String | Wallet password |
passphrase | String | BIP39 passphrase |
List of wallets with new updated one, otherwise exception will be thrown.
const passphrase = 'somepassphrase'
const walletsNew = keystore.setMnemonicPassphrase(wallets, walletId, password, passphrase)
Note: not available for read-only
wallets.
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
password | String | Wallet password |
newPassword | String | New keystore password |
List of wallets with new updated one, otherwise exception will be thrown.
const newPassword = 'Tw5E^g7djfd(29j'
const walletsNew = keystore.setPassword(wallets, walletId, password, newPassword)
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
Current address of wallet.
const address = keystore.getAddress(wallets, walletId)
Note: used only for mnemonic
wallets.
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
startIndex | Number | Start index of address to derive |
endIndex | Number | Finish index of address to derive |
List of derived addresses, otherwise exception will be thrown.
const startIndex = 3
const endIndex = 10
const addresses = keystore.getAddressesFromMnemonic(wallets, walletId, startIndex, endIndex)
Note: not available for read-only
wallets.
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
password | String | Wallet password |
Decrypted private key, otherwise exception will be thrown.
const privateKey = keystore.getPrivateKey(wallets, walletId, password)
Note: used only for full-access
mnemonic
wallets.
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
password | String | Wallet password |
Decrypted mnemonic, otherwise exception will be thrown.
const mnemonic = keystore.getMnemonic(wallets, walletId, password)
Note: password required only for full-access
wallets.
Param | Type | Description |
---|---|---|
wallets | Array | List of existed wallets |
walletId | String | Unique ID of wallet |
password | String | Wallet password |
Wallet with decrypted data, otherwise exception will be thrown.
const walletData = keystore.getWalletData(wallets, walletId, password)
Serialized keystore data for backup.
const keystoreSerializedData = keystore.serialize(wallets)
Param | Type | Description |
---|---|---|
backupData | String | Keystore serialized data |
const backupData = '{"wallets":[{"type":"mnemonic","id":"2e820ddb-a9ce-43e1-b7ec-dbed59eec7e9",...'
const keystoreDeserializedData = keystore.deserialize(backupData)
Param | Type | Description |
---|---|---|
password | String | Wallet password |
Object that contains following fields:
const result = keystore.testPassword('JHJ23jG^*DGHj667s')
Param | Type | Description |
---|---|---|
entropy (optional) | String | Entropy for mnemonic initialisation (see new Mnemonic) |
randomBufferLength (optional) | Number | Buffer length (if entropy param is used) |
Mnemonic - string with 12 English words splited by space.
const mnemonic = keystore.generateMnemonic()
Param | Type | Description |
---|---|---|
mnemonic | String | Mnemonic to check |
true
if mnemonic is valid and false
otherwise.
const mnemonic = 'come average primary sunny profit eager toy pulp struggle hazard tourist round'
const isValid = keystore.checkMnemonicValid(mnemonic) // true
Param | Type | Description |
---|---|---|
bip32XPublicKey | String | BIP32 Extended Public Key |
true
if bip32XPublicKey is valid and false
otherwise.
const isValid = keystore.checkBip32XPublicKeyValid('xpub...')
Param | Type | Description |
---|---|---|
address | String | Address to check. Accepts checksummed addresses too |
true
if address is valid and false
otherwise.
const isValid = keystore.checkAddressValid('0x8a02a99ee7a801da6996a2dacc406ffa5190dc9c')
Param | Type | Description |
---|---|---|
address | String | Address to check |
true
if address contains checksum and false
otherwise.
const isValid = keystore.checkChecksumAddressValid('0x8a02a99ee7a801da6996a2dacc406ffa5190dc9c')
Param | Type | Description |
---|---|---|
privateKey | String | Private Key to check |
true
if privateKey is valid and false
otherwise.
const pk = '0xa7fcb4efc392d2c8983cbfe64063f994f85120e60843407af95907d905d0dc9f'
const isValid = keystore.checkPrivateKeyValid(pk)
Param | Type | Description |
---|---|---|
derivationPath | String | Derivation path |
true
if derivationPath is valid and false
otherwise.
const isValid = keystore.checkDerivationPathValid("m/44'/60'/0'/0")
FAQs
Library for ethereum blockchain accounts management
We found that @jibrelnetwork/jwallet-web-keystore demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.