       setter    : (api) -> api.setFhePrivateKey
       stage     : AuthenticationStage.FHE_KEYGEN
       encrypt   : true
+      id        : 'FHE_PRIVATE_KEY'
     }
     SEARCH_PRIVATE_KEY : {
       generator : (clientKeys) -> clientKeys.searchPrivateKey

      setter    : (api) -> api.setClientHashFunction
      stage     : AuthenticationStage.CLIENT_HASH_GEN
      encrypt   : false
    }
  }

  serializeKey = ({ credentialType, uint8Key, searchKeySerializer }) ->
    if _.isEmpty(uint8Key)
      return uint8Key
    else if credentialType.encrypt
      return searchKeySerializer.encrypt(uint8Key)
    else
      return uint8Key

  deserializeKey = ({ credentialType, uint8Key, searchKeySerializer }) ->
    if _.isEmpty(uint8Key)
      return uint8Key
    else if credentialType.encrypt
      return searchKeySerializer.decrypt(uint8Key)
    else
      return uint8Key


  'kryptnostic.crypto-key-storage-api'
  'kryptnostic.credential-loader'
  'kryptnostic.search-key-serializer'
  'kryptnostic.crypto-service-loader'
  'kryptnostic.aes-crypto-service'
  'kryptnostic.block-ciphertext'
], (require) ->

  _                   = require 'lodash'
  Promise             = require 'bluebird'
  Logger              = require 'kryptnostic.logger'
  AuthenticationStage = require 'kryptnostic.authentication-stage'
  CredentialLoader    = require 'kryptnostic.credential-loader'
  CryptoKeyStorageApi = require 'kryptnostic.crypto-key-storage-api'
  SearchKeySerializer = require 'kryptnostic.search-key-serializer'
  SearchKeyGenerator  = require 'kryptnostic.search-key-generator'
  CryptoServiceLoader = require 'kryptnostic.crypto-service-loader'
  AesCryptoService    = require 'kryptnostic.aes-crypto-service'
  BlockCiphertext     = require 'kryptnostic.block-ciphertext'

  log = Logger.get('SearchCredentialService')

