         
         let requestSigner = VSSRequestSigner(crypto: self.preferences.crypto)
         try requestSigner.selfSign(request, with: keyPair.privateKey)
+        
+        let cardId = Array(request.signatures.keys)[0]
+        
         try requestSigner.authoritySign(request, forAppId: identityCard.identifier, with: self.preferences.myPrivateKey)
         
-        return request
+        return (request, cardId)
     }
     
     fileprivate func addCards(forIdentityCard identityCard: VSSCard, includeLtcCard: Bool, numberOfOtcCards: Int, completion: @escaping (Error?)->()) throws {
-        let keys = try self.generateAndSaveKeys(numberOfOtcKeys: numberOfOtcCards, generateLtcKey: includeLtcCard)
+        var otcKeys: [VSSKeyPair] = []
+        otcKeys.reserveCapacity(numberOfOtcCards)
+        for _ in 0..<numberOfOtcCards {
+            otcKeys.append(self.preferences.crypto.generateKeyPair())
+        }
         
         var otcCardsRequests: [CreateEphemeralCardRequest] = []
+        var otcKeysNames: [String] = []
         otcCardsRequests.reserveCapacity(numberOfOtcCards)
+        otcKeysNames.reserveCapacity(numberOfOtcCards)
         for i in 0..<numberOfOtcCards {
-            let request = try self.generateRequest(forIdentityCard: identityCard, keyPair: keys[i], isLtc: false)
+            let (request, cardId) = try self.generateRequest(forIdentityCard: identityCard, keyPair: otcKeys[i], isLtc: false)
             otcCardsRequests.append(request)
-        }
-        
-        var ltcCardRequest: CreateEphemeralCardRequest?
+            otcKeysNames.append(cardId)
+        }
+        
+        let ltcKey: VSSKeyPair?
+        let ltcCardRequest: CreateEphemeralCardRequest?
+        let ltcKeyName: String?
         if includeLtcCard {
-            let request = try self.generateRequest(forIdentityCard: identityCard, keyPair: keys.last!, isLtc: false)
+            ltcKey = self.preferences.crypto.generateKeyPair()
+            let (request, cardId) = try self.generateRequest(forIdentityCard: identityCard, keyPair: ltcKey!, isLtc: false)
             ltcCardRequest = request
-        }
+            ltcKeyName = cardId
+        }
+        else {
+            ltcKey = nil
+            ltcCardRequest = nil
+            ltcKeyName = nil
+        }
+        
+        try self.saveKeys(keys: otcKeys.map({ $0.privateKey }), keyNames: otcKeysNames, ltcKey: ltcKey?.privateKey, ltcKeyName: ltcKeyName)
         
         let callback = { (error: Error?) in
             completion(error)

// MARK: Keys
extension SecureChat {
    static fileprivate let ServiceKeyName = "VIRGIL.SERVICE.INFO"
    static private let DateFormatRFC3339 = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
    static private let KeyNameFormat = "%@.%@.%@.%@"
    
    private func savePrivateKey(_ key: VSSPrivateKey, isLtc: Bool, dateStr: String) throws -> String {
        let privateKeyData = self.preferences.crypto.export(key, withPassword: nil)
        
        let keyName = String(format: SecureChat.KeyNameFormat, "VIRGIL", "OTKEY", dateStr, UUID().uuidString)
        let keyEntry = VSSKeyEntry(name: keyName, value: privateKeyData)
        
        try self.preferences.keyStorage.store(keyEntry)
        
        return keyName
    }
    
    private func savePrivateKeys(_ keys: [VSSPrivateKey], ltcKey: VSSPrivateKey?) throws -> ([String], String?) {
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = SecureChat.DateFormatRFC3339
        let dateStr = dateFormatter.string(from: Date())
        
        var keyNames: [String] = []
        keyNames.reserveCapacity(keys.count)
        
        for privateKey in keys {
            keyNames.append(try self.savePrivateKey(privateKey, isLtc: false, dateStr: dateStr))
        }
        
        let ltcKeyName: String?
        if let ltcKey = ltcKey {
            ltcKeyName = try self.savePrivateKey(ltcKey, isLtc: true, dateStr: dateStr)
        }
        else {
            ltcKeyName = nil
        }
        
        return (keyNames, ltcKeyName)
    }
    
    fileprivate func generateAndSaveKeys(numberOfOtcKeys: Int, generateLtcKey: Bool) throws -> [VSSKeyPair] {
        let serviceInfo = try self.getServiceInfoEntry()
        
        var keyPairs: [VSSKeyPair] = []
        for _ in 0..<numberOfOtcKeys {
            keyPairs.append(self.preferences.crypto.generateKeyPair())
        }
        
        let ltcKeyPair = generateLtcKey ? self.preferences.crypto.generateKeyPair() : nil
        let (otcNames, ltcName) = try self.savePrivateKeys(keyPairs.map({ return $0.privateKey }), ltcKey: ltcKeyPair?.privateKey)
        
        let newServiceInfo = ServiceInfoEntry(ltcKeyName: generateLtcKey ? ltcName! : serviceInfo.ltcKeyName, otcKeysNames: serviceInfo.otcKeysNames + otcNames)
        
        try self.updateServiceInfoEntry(newEntry: newServiceInfo)
        
        return keyPairs
    }
    
    private func updateServiceInfoEntry(newEntry: ServiceInfoEntry) throws {


// MARK: Adding cards
extension SecureChat {
    private func generateRequest(forIdentityCard identityCard: VSSCard, keyPair: VSSKeyPair, isLtc: Bool) throws -> (CreateEphemeralCardRequest, String) {
        let identity = identityCard.identity
        let identityType = identityCard.identityType
        let device = self.preferences.deviceManager.getDeviceModel()
