es/utils/keystore.js
function marshal (name, derivedKey, privateKey, nonce, salt, options = {}) {
  const opt = Object.assign({}, DEFAULTS.crypto, options)
  return Object.assign(
    { name, version: 1, public_key: getAddressFromPriv(privateKey), id: uuid.v4() },
    {
      crypto: Object.assign(
        {
          secret_type: opt.secret_type,
          symmetric_alg: opt.symmetric_alg,
          ciphertext: Buffer.from(encrypt(Buffer.from(privateKey), derivedKey, nonce, opt.symmetric_alg)).toString('hex'),
          cipher_params: { nonce: Buffer.from(nonce).toString('hex') }
        },
        { kdf: opt.kdf, kdf_params: { ...opt.kdf_params, salt: Buffer.from(salt).toString('hex') } }
      )
    }
  )
}
function marshal (name, derivedKey, privateKey, nonce, salt, options = {}) {
  const opt = Object.assign({}, DEFAULTS.crypto, options)
  return Object.assign(
    { name, version: 1, public_key: getAddressFromPriv(privateKey), id: uuid.v4() },
    {
      crypto: Object.assign(
        {
          secret_type: opt.secret_type,
          symmetric_alg: opt.symmetric_alg,
          ciphertext: Buffer.from(encrypt(Buffer.from(privateKey), derivedKey, nonce, opt.symmetric_alg)).toString('hex'),
          cipher_params: { nonce: Buffer.from(nonce).toString('hex') }
        },
        { kdf: opt.kdf, kdf_params: { ...opt.kdf_params, salt: Buffer.from(salt).toString('hex') } }
      )
    }
  )
}
function marshal ( name , derivedKey , privateKey , nonce , salt , options = { } ) { const opt = Object . assign ( { } , DEFAULTS . crypto , options ) return Object . assign ( { name , version : 1 , public_key : getAddressFromPriv ( privateKey ) , id : uuid . v4 ( ) } , { crypto : Object . assign ( { secret_type : opt . secret_type , symmetric_alg : opt . symmetric_alg , ciphertext : Buffer . from ( encrypt ( Buffer . from ( privateKey ) , derivedKey , nonce , opt . symmetric_alg ) ) . toString ( 'hex' ) , cipher_params : { nonce : Buffer . from ( nonce ) . toString ( 'hex' ) } } , { kdf : opt . kdf , kdf_params : { ... opt . kdf_params , salt : Buffer . from ( salt ) . toString ( 'hex' ) } } ) } ) }
Assemble key data object in secret-storage format.
@param {buffer} name Key name.
@param {buffer} derivedKey Password-derived secret key.
@param {buffer} privateKey Private key.
@param {buffer} nonce Randomly generated 24byte nonce.
@param {buffer} salt Randomly generated 16byte salt.
@param {Object=} options Encryption parameters.
@param {string=} options.kdf Key derivation function (default: argon2id).
@param {string=} options.cipher Symmetric cipher (default: constants.cipher).
@param {Object=} options.kdf_params KDF parameters (default: constants.<kdf>).
@return {Object}
Assemble key data object in secret - storage format .