Keystore

Keystore is a specification to store private keys in a secure way. Please see Aergo documentation for format specification.

Generating keystore from private key (encryption)

keystoreFromPrivateKey(key, password, kdfParams)

Encrypt private key and return keystore data.

import { keystoreFromPrivateKey, createIdentity } from '@herajs/crypto';
const identity = createIdentity();
const keystore = await keystoreFromPrivateKey(identity.privateKey, 'password');
console.log(JSON.stringify(keystore, null, 2));
Arguments:
  • key (Buffer) –
  • password (string) –
  • kdfParams (Partial<keystore.ScryptParams>) –
Returns:

Promise<keystore.Keystore>

Reading private key from keystore (decryption)

identityFromKeystore(keystore, password)

Decrypt keystore and return identity information.

import { identityFromKeystore } from '@herajs/crypto';
const keystore = JSON.parse('keystore file contents');
const identity = await identityFromKeystore(keystore, 'password');
console.log(identity);
Arguments:
  • keystore (keystore.Keystore) –
  • password (string) –
Returns:

Promise<keys.Identity>

class Keystore()

interface

Keystore.aergo_address

type: string

Keystore.cipher

type: keystore.KeystoreCipher

Keystore.kdf

type: keystore.KeystoreKdf

Keystore.ks_version

type: keystore.Version

class KeystoreCipher()

interface

KeystoreCipher.algorithm

type: keystore.CipherAlgorithm

KeystoreCipher.ciphertext

type: keystore.HexString

KeystoreCipher.params

type: keystore.CipherParams

class CipherParams()

interface

CipherParams.iv

type: keystore.HexString

class KeystoreKdf()

interface

KeystoreKdf.algorithm

type: “scrypt”

KeystoreKdf.mac

type: keystore.HexString

KeystoreKdf.params

type: keystore.ScryptParams

class ScryptParams()

interface

ScryptParams.dklen

type: number

ScryptParams.n

type: number

ScryptParams.p

type: number

ScryptParams.r

type: number

ScryptParams.salt

type: keystore.HexString