     constructor : ->
       @cryptoServiceLoader  = new CryptoServiceLoader()
       @documentSearchKeyApi = new DocumentSearchKeyApi()
-      @kryptnosticEngine    = new MockKryptnosticEngine()
+      @engine               = new MockKryptnosticEngine()
       @metadataApi          = new MetadataApi()
       @metadataMapper       = new MetadataMapper()
       @objectIndexer        = new ObjectIndexer()

        return Promise.resolve()

      { body } = storageRequest
      { objectAddressFunction, objectSearchKey, objectConversionMatrix } = {}

      uintId = BinaryUtils.stringToUint8(id)

      Promise.props({
        _objectAddressFunction  : @kryptnosticEngine.getObjectAddressFunction(uintId)
        _objectSearchKey        : @kryptnosticEngine.getObjectSearchKey(uintId)
        _objectConversionMatrix : @kryptnosticEngine.getObjectConversionMatrix(uintId)
      })
      .then ({ _objectAddressFunction, _objectSearchKey, _objectConversionMatrix }) =>
        objectAddressFunction  = _objectAddressFunction
        objectSearchKey        = _objectSearchKey
        objectConversionMatrix = _objectConversionMatrix

        encryptedAddressFunction = @searchKeySerializer.encrypt(objectAddressFunction)
        @documentSearchKeyApi.uploadAddressFunction(id, encryptedAddressFunction)
      .then =>
        @documentSearchKeyApi.uploadSharingPair(id, { objectSearchKey, objectConversionMatrix })
      .then =>
        @objectIndexer.index(id, body)
      .then (metadata) =>
        @prepareMetadataRequest({ id, metadata, objectAddressFunction, objectSearchKey })
      .then (metadataRequest) =>
        @metadataApi.uploadMetadata( metadataRequest )

    # currently produces a single request, batch later if needed.
    prepareMetadataRequest: ({ id, metadata, objectAddressFunction, objectSearchKey }) ->
      Promise.resolve()
      .then =>
        @cryptoServiceLoader.getObjectCryptoService(id, { expectMiss : false })


  Promise               = require 'bluebird'

  CryptoServiceLoader   = require 'kryptnostic.crypto-service-loader'
  DocumentSearchKeyApi  = require 'kryptnostic.document-search-key-api'
  IndexedMetadata       = require 'kryptnostic.indexed-metadata'
